Go to the documentation of this file.
15 #include "llvm/Config/config.h"
32 #if defined(HAVE_FCNTL_H)
36 #if defined(HAVE_UNISTD_H)
40 #if defined(__CYGWIN__)
47 # define STDIN_FILENO 0
50 # define STDOUT_FILENO 1
53 # define STDERR_FILENO 2
78 assert(OutBufCur == OutBufStart &&
79 "raw_ostream destructor called with non-empty buffer!");
81 if (BufferMode == BufferKind::InternalBuffer)
82 delete [] OutBufStart;
99 void raw_ostream::SetBufferAndMode(
char *BufferStart,
size_t Size,
101 assert(((
Mode == BufferKind::Unbuffered && !BufferStart && Size == 0) ||
102 (
Mode != BufferKind::Unbuffered && BufferStart && Size != 0)) &&
103 "stream must be unbuffered or have at least one byte");
108 if (BufferMode == BufferKind::InternalBuffer)
109 delete [] OutBufStart;
110 OutBufStart = BufferStart;
111 OutBufEnd = OutBufStart+Size;
112 OutBufCur = OutBufStart;
115 assert(OutBufStart <= OutBufEnd &&
"Invalid size!");
152 for (
int Idx = 0; Idx < 16; ++Idx) {
154 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
162 bool UseHexEscapes) {
163 for (
unsigned char c : Str) {
166 *
this <<
'\\' <<
'\\';
169 *
this <<
'\\' <<
't';
172 *
this <<
'\\' <<
'n';
175 *
this <<
'\\' <<
'"';
185 *
this <<
'\\' <<
'x';
186 *
this << hexdigit((
c >> 4) & 0xF);
187 *
this << hexdigit((
c >> 0) & 0xF);
191 *
this << char(
'0' + ((
c >> 6) & 7));
192 *
this << char(
'0' + ((
c >> 3) & 7));
193 *
this << char(
'0' + ((
c >> 0) & 7));
211 void raw_ostream::flush_nonempty() {
212 assert(OutBufCur > OutBufStart &&
"Invalid call to flush_nonempty.");
213 size_t Length = OutBufCur - OutBufStart;
214 OutBufCur = OutBufStart;
215 flush_tied_then_write(OutBufStart,
Length);
222 if (BufferMode == BufferKind::Unbuffered) {
223 flush_tied_then_write(
reinterpret_cast<char *
>(&
C), 1);
242 if (BufferMode == BufferKind::Unbuffered) {
243 flush_tied_then_write(
Ptr, Size);
251 size_t NumBytes = OutBufEnd - OutBufCur;
257 assert(NumBytes != 0 &&
"undefined behavior");
258 size_t BytesToWrite = Size - (Size % NumBytes);
259 flush_tied_then_write(
Ptr, BytesToWrite);
260 size_t BytesRemaining = Size - BytesToWrite;
261 if (BytesRemaining >
size_t(OutBufEnd - OutBufCur)) {
263 return write(
Ptr + BytesToWrite, BytesRemaining);
265 copy_to_buffer(
Ptr + BytesToWrite, BytesRemaining);
271 copy_to_buffer(
Ptr, NumBytes);
273 return write(
Ptr + NumBytes, Size - NumBytes);
276 copy_to_buffer(
Ptr, Size);
281 void raw_ostream::copy_to_buffer(
const char *
Ptr,
size_t Size) {
282 assert(Size <=
size_t(OutBufEnd - OutBufCur) &&
"Buffer overrun!");
287 case 4: OutBufCur[3] =
Ptr[3]; [[fallthrough]];
288 case 3: OutBufCur[2] =
Ptr[2]; [[fallthrough]];
289 case 2: OutBufCur[1] =
Ptr[1]; [[fallthrough]];
290 case 1: OutBufCur[0] =
Ptr[0]; [[fallthrough]];
300 void raw_ostream::flush_tied_then_write(
const char *
Ptr,
size_t Size) {
303 write_impl(
Ptr, Size);
310 size_t NextBufferSize = 127;
311 size_t BufferBytesLeft = OutBufEnd - OutBufCur;
312 if (BufferBytesLeft > 3) {
313 size_t BytesUsed = Fmt.
print(OutBufCur, BufferBytesLeft);
316 if (BytesUsed <= BufferBytesLeft) {
317 OutBufCur += BytesUsed;
323 NextBufferSize = BytesUsed;
335 size_t BytesUsed = Fmt.
print(V.data(), NextBufferSize);
338 if (BytesUsed <= NextBufferSize)
339 return write(V.data(), BytesUsed);
342 assert(BytesUsed > NextBufferSize &&
"Didn't grow buffer!?");
343 NextBufferSize = BytesUsed;
353 unsigned LeftIndent = 0;
354 unsigned RightIndent = 0;
355 const ssize_t Difference =
FS.Width -
FS.Str.size();
356 if (Difference > 0) {
357 switch (
FS.Justify) {
361 RightIndent = Difference;
364 LeftIndent = Difference;
367 LeftIndent = Difference / 2;
368 RightIndent = Difference - LeftIndent;
381 if (FN.Upper && FN.HexPrefix)
383 else if (FN.Upper && !FN.HexPrefix)
385 else if (!FN.Upper && FN.HexPrefix)
394 if (Buffer.size() < FN.Width)
395 indent(FN.Width - Buffer.size());
402 if (FB.Bytes.
empty())
405 size_t LineIndex = 0;
406 auto Bytes = FB.Bytes;
407 const size_t Size = Bytes.size();
410 if (FB.FirstByteOffset) {
414 size_t Lines = Size / FB.NumPerLine;
415 uint64_t MaxOffset = *FB.FirstByteOffset + Lines * FB.NumPerLine;
419 OffsetWidth = std::max<uint64_t>(4,
llvm::alignTo(Power, 4) / 4);
423 unsigned NumByteGroups =
424 alignTo(FB.NumPerLine, FB.ByteGroupSize) / FB.ByteGroupSize;
425 unsigned BlockCharWidth = FB.NumPerLine * 2 + NumByteGroups - 1;
427 while (!Bytes.empty()) {
430 if (FB.FirstByteOffset) {
436 auto Line = Bytes.take_front(FB.NumPerLine);
438 size_t CharsPrinted = 0;
440 for (
size_t I = 0;
I < Line.size(); ++
I, CharsPrinted += 2) {
441 if (
I && (
I % FB.ByteGroupSize) == 0) {
451 assert(BlockCharWidth >= CharsPrinted);
452 indent(BlockCharWidth - CharsPrinted + 2);
456 for (uint8_t Byte : Line) {
458 *this << static_cast<char>(Byte);
465 Bytes = Bytes.drop_front(Line.size());
466 LineIndex += Line.size();
467 if (LineIndex < Size)
475 static const char Chars[] = {
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
476 C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
477 C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
478 C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
479 C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C,
C};
483 return OS.
write(Chars, NumChars);
487 OS.
write(Chars, NumToWrite);
488 NumChars -= NumToWrite;
495 return write_padding<' '>(*
this, NumSpaces);
500 return write_padding<'\0'>(*
this, NumZeros);
503 bool raw_ostream::prepare_colors() {
520 if (!prepare_colors())
523 const char *colorcode =
528 write(colorcode, strlen(colorcode));
533 if (!prepare_colors())
537 write(colorcode, strlen(colorcode));
542 if (!prepare_colors())
546 write(colorcode, strlen(colorcode));
550 void raw_ostream::anchor() {}
568 "Cannot make a raw_ostream from a read-only descriptor!");
572 if (Filename ==
"-") {
573 EC = std::error_code();
576 return STDOUT_FILENO;
632 if (FD <= STDERR_FILENO)
638 ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
642 off_t loc = ::lseek(FD, 0, SEEK_CUR);
648 SupportsSeeking = !EC && IsRegularFile;
650 SupportsSeeking = !EC && loc != (off_t)-1;
652 if (!SupportsSeeking)
704 if (
auto EC = sys::windows::UTF8ToUTF16(
Data, WideText))
709 size_t MaxWriteSize = WideText.size();
711 MaxWriteSize = 32767;
713 size_t WCharsWritten = 0;
715 size_t WCharsToWrite =
716 std::min(MaxWriteSize, WideText.size() - WCharsWritten);
717 DWORD ActuallyWritten;
719 ::WriteConsoleW((HANDLE)::_get_osfhandle(FD), &WideText[WCharsWritten],
720 WCharsToWrite, &ActuallyWritten,
729 WCharsWritten += ActuallyWritten;
730 }
while (WCharsWritten != WideText.size());
735 void raw_fd_ostream::write_impl(
const char *
Ptr,
size_t Size) {
736 assert(FD >= 0 &&
"File already closed.");
742 if (IsWindowsConsole)
750 size_t MaxWriteSize = INT32_MAX;
752 #if defined(__linux__)
755 MaxWriteSize = 1024 * 1024 * 1024;
759 size_t ChunkSize =
std::min(Size, MaxWriteSize);
771 if (errno == EINTR || errno == EAGAIN
773 || errno == EWOULDBLOCK
801 assert(SupportsSeeking &&
"Stream does not support seeking!");
804 pos = ::_lseeki64(FD, off, SEEK_SET);
805 #elif defined(HAVE_LSEEK64)
806 pos = ::lseek64(FD, off, SEEK_SET);
808 pos = ::lseek(FD, off, SEEK_SET);
815 void raw_fd_ostream::pwrite_impl(
const char *
Ptr,
size_t Size,
823 size_t raw_fd_ostream::preferred_buffer_size()
const {
830 if (IsWindowsConsole)
833 #elif !defined(__minix)
835 assert(FD >= 0 &&
"File not yet open!");
837 if (fstat(FD, &statbuf) != 0)
846 return statbuf.st_blksize;
877 void raw_fd_ostream::anchor() {}
937 void raw_string_ostream::write_impl(
const char *
Ptr,
size_t Size) {
945 uint64_t raw_svector_ostream::current_pos()
const {
return OS.size(); }
947 void raw_svector_ostream::write_impl(
const char *
Ptr,
size_t Size) {
951 void raw_svector_ostream::pwrite_impl(
const char *
Ptr,
size_t Size,
969 void raw_null_ostream::write_impl(
const char *
Ptr,
size_t Size) {
972 uint64_t raw_null_ostream::current_pos()
const {
976 void raw_null_ostream::pwrite_impl(
const char *
Ptr,
size_t Size,
979 void raw_pwrite_stream::anchor() {}
981 void buffer_ostream::anchor() {}
983 void buffer_unique_ostream::anchor() {}
987 if (OutputFileName ==
"-")
988 return Write(
outs());
990 if (OutputFileName ==
"/dev/null") {
1003 if (
Error E = Write(Out)) {
1004 if (
Error DiscardError = Temp->discard())
1010 return Temp->keep(OutputFileName);
bool RunningWindows8OrGreater()
Determines if the program is running on Windows 8 or newer.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uint64_t tell() const
tell - Return the current offset with the file.
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
This is an optimization pass for GlobalISel generic memory operations.
void close()
Manually flush the stream and close the file.
void SetBuffered()
Set the stream to be buffered, with an automatically determined buffer size.
void SetUnbuffered()
Set the stream to be unbuffered.
OStreamKind get_kind() const
std::error_code ChangeStdoutMode(fs::OpenFlags Flags)
virtual bool is_displayed() const
This function determines if this stream is connected to a "tty" or "console" window.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
raw_fd_ostream(StringRef Filename, std::error_code &EC)
Open the specified file for writing.
static constexpr Colors GREEN
to esp esp setne al movzbw ax esp setg cl movzbw cx cmove cx cl jne LBB1_2 esp ret(also really horrible code on ppc). This is due to the expand code for 64-bit compares. GCC produces multiple branches
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static constexpr Colors RED
Tagged union holding either a T or a Error.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
Expected< sys::fs::FileLocker > tryLockFor(Duration const &Timeout)
Tries to lock the underlying file within the specified period.
__FakeVCSRevision h endif() endif() set(generated_files "$
bool empty() const
empty - Check if the array is empty.
bool has_colors() const override
This function determines if this stream is displayed and supports colors.
static constexpr Colors MAGENTA
static bool classof(const raw_ostream *OS)
Check if OS is a pointer of type raw_fd_stream*.
virtual raw_ostream & changeColor(enum Colors Color, bool Bold=false, bool BG=false)
Changes the foreground color of text that will be output from this point forward.
virtual size_t preferred_buffer_size() const
Return an efficient buffer size for the underlying output mechanism.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
static int getFD(StringRef Filename, std::error_code &EC, sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags)
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void inc_pos(uint64_t Delta)
int get_fd() const
Return the file descriptor.
Error writeToOutput(StringRef OutputFileName, std::function< Error(raw_ostream &)> Write)
This helper creates an output stream and then passes it to Write.
(vector float) vec_cmpeq(*A, *B) C
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
static raw_ostream & write_padding(raw_ostream &OS, unsigned NumChars)
~raw_null_ostream() override
void write_double(raw_ostream &S, double D, FloatStyle Style, std::optional< size_t > Precision=std::nullopt)
raw_ostream & write(unsigned char C)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class implements an extremely fast bulk output stream that can only output to a stream.
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
size_t GetNumBytesInBuffer() const
void error_detected(std::error_code EC)
Set the flag indicating that an output error has been encountered.
RAII class that facilitates file locking.
static constexpr Colors WHITE
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
virtual void enable_colors(bool enable)
static const char * OutputBold(bool bg)
Same as OutputColor, but only enables the bold attribute.
static std::error_code SafelyCloseFileDescriptor(int FD)
Represents the result of a call to sys::fs::status().
static bool FileDescriptorHasColors(int fd)
This function determines if the given file descriptor is displayd and supports colors.
static const char * ResetColor()
Resets the terminals colors, or returns an escape sequence to do so.
std::error_code lockFile(int FD)
Lock the file.
An abstract base class for streams implementations that also support a pwrite operation.
std::chrono::milliseconds getDuration() const
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
static const char * OutputColor(char c, bool bold, bool bg)
This function returns the colorcode escape sequences.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
ssize_t read(char *Ptr, size_t Size)
This reads the Size bytes into a buffer pointed by Ptr.
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
message(STATUS "Targeting ${t}") add_subdirectory($
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
print Print MemDeps of function
std::pair< llvm::MachO::Target, std::string > UUID
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
static constexpr Colors CYAN
A raw_ostream that discards all output.
void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::optional< size_t > Width=std::nullopt)
virtual raw_ostream & reverseColor()
Reverses the foreground and background colors.
std::error_code error() const
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
StringRef - Represent a constant reference to a string, i.e.
bool is_displayed() const override
This function determines if this stream is connected to a "tty" or "console" window.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
A raw_ostream that writes to a file descriptor.
raw_ostream & operator<<(char C)
static const char * OutputReverse()
This function returns the escape sequence to reverse forground and background colors.
std::error_code make_error_code(BitcodeError E)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static constexpr Colors RESET
Lightweight error class with error context and mandatory checking.
static bool FileDescriptorIsDisplayed(int fd)
This function determines if the given file descriptor is connected to a "tty" or "console" window.
static constexpr Colors SAVEDCOLOR
~raw_fd_ostream() override
void write_integer(raw_ostream &S, unsigned int N, size_t MinDigits, IntegerStyle Style)
Expected< sys::fs::FileLocker > lock()
Locks the underlying file.
raw_fd_stream(StringRef Filename, std::error_code &EC)
Open the specified file for reading/writing/seeking.
static bool ColorNeedsFlush()
Whether changing colors requires the output to be flushed.
void SetBufferSize(size_t Size)
Set the stream to be buffered, using the specified buffer size.
Error takeError()
Take ownership of the stored error.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
static constexpr Colors BLACK
A raw_ostream that writes to an SmallVector or SmallString.
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
static constexpr Colors BLUE
uint8_t[16] uuid_t
Output a formatted UUID with dash separators.
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
static constexpr Colors YELLOW
#define LLVM_UNLIKELY(EXPR)
bool isRegularFile() const
raw_ostream & write_uuid(const uuid_t UUID)
std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
Try to locks the file during the specified time.
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.