LLVM  7.0.0svn
MemoryBuffer.cpp
Go to the documentation of this file.
1 //===--- MemoryBuffer.cpp - Memory Buffer implementation ------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the MemoryBuffer interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/Config/config.h"
17 #include "llvm/Support/Errc.h"
18 #include "llvm/Support/Errno.h"
21 #include "llvm/Support/Path.h"
22 #include "llvm/Support/Process.h"
23 #include "llvm/Support/Program.h"
24 #include <cassert>
25 #include <cerrno>
26 #include <cstring>
27 #include <new>
28 #include <sys/types.h>
29 #include <system_error>
30 #if !defined(_MSC_VER) && !defined(__MINGW32__)
31 #include <unistd.h>
32 #else
33 #include <io.h>
34 #endif
35 using namespace llvm;
36 
37 //===----------------------------------------------------------------------===//
38 // MemoryBuffer implementation itself.
39 //===----------------------------------------------------------------------===//
40 
42 
43 /// init - Initialize this MemoryBuffer as a reference to externally allocated
44 /// memory, memory that we know is already null terminated.
45 void MemoryBuffer::init(const char *BufStart, const char *BufEnd,
46  bool RequiresNullTerminator) {
47  assert((!RequiresNullTerminator || BufEnd[0] == 0) &&
48  "Buffer is not null terminated!");
49  BufferStart = BufStart;
50  BufferEnd = BufEnd;
51 }
52 
53 //===----------------------------------------------------------------------===//
54 // MemoryBufferMem implementation.
55 //===----------------------------------------------------------------------===//
56 
57 /// CopyStringRef - Copies contents of a StringRef into a block of memory and
58 /// null-terminates it.
59 static void CopyStringRef(char *Memory, StringRef Data) {
60  if (!Data.empty())
61  memcpy(Memory, Data.data(), Data.size());
62  Memory[Data.size()] = 0; // Null terminate string.
63 }
64 
65 namespace {
66 struct NamedBufferAlloc {
67  const Twine &Name;
68  NamedBufferAlloc(const Twine &Name) : Name(Name) {}
69 };
70 }
71 
72 void *operator new(size_t N, const NamedBufferAlloc &Alloc) {
73  SmallString<256> NameBuf;
74  StringRef NameRef = Alloc.Name.toStringRef(NameBuf);
75 
76  char *Mem = static_cast<char *>(operator new(N + NameRef.size() + 1));
77  CopyStringRef(Mem + N, NameRef);
78  return Mem;
79 }
80 
81 namespace {
82 /// MemoryBufferMem - Named MemoryBuffer pointing to a block of memory.
83 template<typename MB>
84 class MemoryBufferMem : public MB {
85 public:
86  MemoryBufferMem(StringRef InputData, bool RequiresNullTerminator) {
87  MemoryBuffer::init(InputData.begin(), InputData.end(),
88  RequiresNullTerminator);
89  }
90 
91  /// Disable sized deallocation for MemoryBufferMem, because it has
92  /// tail-allocated data.
93  void operator delete(void *p) { ::operator delete(p); }
94 
95  StringRef getBufferIdentifier() const override {
96  // The name is stored after the class itself.
97  return StringRef(reinterpret_cast<const char *>(this + 1));
98  }
99 
100  MemoryBuffer::BufferKind getBufferKind() const override {
102  }
103 };
104 }
105 
106 template <typename MB>
108 getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize,
109  uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile);
110 
111 std::unique_ptr<MemoryBuffer>
113  bool RequiresNullTerminator) {
114  auto *Ret = new (NamedBufferAlloc(BufferName))
115  MemoryBufferMem<MemoryBuffer>(InputData, RequiresNullTerminator);
116  return std::unique_ptr<MemoryBuffer>(Ret);
117 }
118 
119 std::unique_ptr<MemoryBuffer>
120 MemoryBuffer::getMemBuffer(MemoryBufferRef Ref, bool RequiresNullTerminator) {
121  return std::unique_ptr<MemoryBuffer>(getMemBuffer(
122  Ref.getBuffer(), Ref.getBufferIdentifier(), RequiresNullTerminator));
123 }
124 
126 getMemBufferCopyImpl(StringRef InputData, const Twine &BufferName) {
127  auto Buf = WritableMemoryBuffer::getNewUninitMemBuffer(InputData.size(), BufferName);
128  if (!Buf)
130  memcpy(Buf->getBufferStart(), InputData.data(), InputData.size());
131  return std::move(Buf);
132 }
133 
134 std::unique_ptr<MemoryBuffer>
135 MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) {
136  auto Buf = getMemBufferCopyImpl(InputData, BufferName);
137  if (Buf)
138  return std::move(*Buf);
139  return nullptr;
140 }
141 
143 MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize,
144  bool RequiresNullTerminator) {
145  SmallString<256> NameBuf;
146  StringRef NameRef = Filename.toStringRef(NameBuf);
147 
148  if (NameRef == "-")
149  return getSTDIN();
150  return getFile(Filename, FileSize, RequiresNullTerminator);
151 }
152 
154 MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize,
155  uint64_t Offset, bool IsVolatile) {
156  return getFileAux<MemoryBuffer>(FilePath, -1, MapSize, Offset, false,
157  IsVolatile);
158 }
159 
160 //===----------------------------------------------------------------------===//
161 // MemoryBuffer::getFile implementation.
162 //===----------------------------------------------------------------------===//
163 
164 namespace {
165 /// \brief Memory maps a file descriptor using sys::fs::mapped_file_region.
166 ///
167 /// This handles converting the offset into a legal offset on the platform.
168 template<typename MB>
169 class MemoryBufferMMapFile : public MB {
171 
172  static uint64_t getLegalMapOffset(uint64_t Offset) {
173  return Offset & ~(sys::fs::mapped_file_region::alignment() - 1);
174  }
175 
176  static uint64_t getLegalMapSize(uint64_t Len, uint64_t Offset) {
177  return Len + (Offset - getLegalMapOffset(Offset));
178  }
179 
180  const char *getStart(uint64_t Len, uint64_t Offset) {
181  return MFR.const_data() + (Offset - getLegalMapOffset(Offset));
182  }
183 
184 public:
185  MemoryBufferMMapFile(bool RequiresNullTerminator, int FD, uint64_t Len,
186  uint64_t Offset, std::error_code &EC)
187  : MFR(FD,
188  MB::Writable ? sys::fs::mapped_file_region::priv
190  getLegalMapSize(Len, Offset), getLegalMapOffset(Offset), EC) {
191  if (!EC) {
192  const char *Start = getStart(Len, Offset);
193  MemoryBuffer::init(Start, Start + Len, RequiresNullTerminator);
194  }
195  }
196 
197  /// Disable sized deallocation for MemoryBufferMMapFile, because it has
198  /// tail-allocated data.
199  void operator delete(void *p) { ::operator delete(p); }
200 
201  StringRef getBufferIdentifier() const override {
202  // The name is stored after the class itself.
203  return StringRef(reinterpret_cast<const char *>(this + 1));
204  }
205 
206  MemoryBuffer::BufferKind getBufferKind() const override {
208  }
209 };
210 }
211 
213 getMemoryBufferForStream(int FD, const Twine &BufferName) {
214  const ssize_t ChunkSize = 4096*4;
215  SmallString<ChunkSize> Buffer;
216  ssize_t ReadBytes;
217  // Read into Buffer until we hit EOF.
218  do {
219  Buffer.reserve(Buffer.size() + ChunkSize);
220  ReadBytes = sys::RetryAfterSignal(-1, read, FD, Buffer.end(), ChunkSize);
221  if (ReadBytes == -1)
222  return std::error_code(errno, std::generic_category());
223  Buffer.set_size(Buffer.size() + ReadBytes);
224  } while (ReadBytes != 0);
225 
226  return getMemBufferCopyImpl(Buffer, BufferName);
227 }
228 
229 
231 MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize,
232  bool RequiresNullTerminator, bool IsVolatile) {
233  return getFileAux<MemoryBuffer>(Filename, FileSize, FileSize, 0,
234  RequiresNullTerminator, IsVolatile);
235 }
236 
237 template <typename MB>
239 getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize,
240  uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
241  bool IsVolatile);
242 
243 template <typename MB>
245 getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize,
246  uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile) {
247  int FD;
248  std::error_code EC = sys::fs::openFileForRead(Filename, FD);
249 
250  if (EC)
251  return EC;
252 
253  auto Ret = getOpenFileImpl<MB>(FD, Filename, FileSize, MapSize, Offset,
254  RequiresNullTerminator, IsVolatile);
255  close(FD);
256  return Ret;
257 }
258 
260 WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize,
261  bool IsVolatile) {
262  return getFileAux<WritableMemoryBuffer>(Filename, FileSize, FileSize, 0,
263  /*RequiresNullTerminator*/ false,
264  IsVolatile);
265 }
266 
268 WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
269  uint64_t Offset, bool IsVolatile) {
270  return getFileAux<WritableMemoryBuffer>(Filename, -1, MapSize, Offset, false,
271  IsVolatile);
272 }
273 
274 std::unique_ptr<WritableMemoryBuffer>
276  using MemBuffer = MemoryBufferMem<WritableMemoryBuffer>;
277  // Allocate space for the MemoryBuffer, the data and the name. It is important
278  // that MemoryBuffer and data are aligned so PointerIntPair works with them.
279  // TODO: Is 16-byte alignment enough? We copy small object files with large
280  // alignment expectations into this buffer.
281  SmallString<256> NameBuf;
282  StringRef NameRef = BufferName.toStringRef(NameBuf);
283  size_t AlignedStringLen = alignTo(sizeof(MemBuffer) + NameRef.size() + 1, 16);
284  size_t RealLen = AlignedStringLen + Size + 1;
285  char *Mem = static_cast<char*>(operator new(RealLen, std::nothrow));
286  if (!Mem)
287  return nullptr;
288 
289  // The name is stored after the class itself.
290  CopyStringRef(Mem + sizeof(MemBuffer), NameRef);
291 
292  // The buffer begins after the name and must be aligned.
293  char *Buf = Mem + AlignedStringLen;
294  Buf[Size] = 0; // Null terminate buffer.
295 
296  auto *Ret = new (Mem) MemBuffer(StringRef(Buf, Size), true);
297  return std::unique_ptr<WritableMemoryBuffer>(Ret);
298 }
299 
300 std::unique_ptr<WritableMemoryBuffer>
302  auto SB = WritableMemoryBuffer::getNewUninitMemBuffer(Size, BufferName);
303  if (!SB)
304  return nullptr;
305  memset(SB->getBufferStart(), 0, Size);
306  return SB;
307 }
308 
309 static bool shouldUseMmap(int FD,
310  size_t FileSize,
311  size_t MapSize,
312  off_t Offset,
313  bool RequiresNullTerminator,
314  int PageSize,
315  bool IsVolatile) {
316  // mmap may leave the buffer without null terminator if the file size changed
317  // by the time the last page is mapped in, so avoid it if the file size is
318  // likely to change.
319  if (IsVolatile)
320  return false;
321 
322  // We don't use mmap for small files because this can severely fragment our
323  // address space.
324  if (MapSize < 4 * 4096 || MapSize < (unsigned)PageSize)
325  return false;
326 
327  if (!RequiresNullTerminator)
328  return true;
329 
330  // If we don't know the file size, use fstat to find out. fstat on an open
331  // file descriptor is cheaper than stat on a random path.
332  // FIXME: this chunk of code is duplicated, but it avoids a fstat when
333  // RequiresNullTerminator = false and MapSize != -1.
334  if (FileSize == size_t(-1)) {
335  sys::fs::file_status Status;
336  if (sys::fs::status(FD, Status))
337  return false;
338  FileSize = Status.getSize();
339  }
340 
341  // If we need a null terminator and the end of the map is inside the file,
342  // we cannot use mmap.
343  size_t End = Offset + MapSize;
344  assert(End <= FileSize);
345  if (End != FileSize)
346  return false;
347 
348  // Don't try to map files that are exactly a multiple of the system page size
349  // if we need a null terminator.
350  if ((FileSize & (PageSize -1)) == 0)
351  return false;
352 
353 #if defined(__CYGWIN__)
354  // Don't try to map files that are exactly a multiple of the physical page size
355  // if we need a null terminator.
356  // FIXME: We should reorganize again getPageSize() on Win32.
357  if ((FileSize & (4096 - 1)) == 0)
358  return false;
359 #endif
360 
361  return true;
362 }
363 
364 template <typename MB>
366 getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize,
367  uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
368  bool IsVolatile) {
369  static int PageSize = sys::Process::getPageSize();
370 
371  // Default is to map the full file.
372  if (MapSize == uint64_t(-1)) {
373  // If we don't know the file size, use fstat to find out. fstat on an open
374  // file descriptor is cheaper than stat on a random path.
375  if (FileSize == uint64_t(-1)) {
376  sys::fs::file_status Status;
377  std::error_code EC = sys::fs::status(FD, Status);
378  if (EC)
379  return EC;
380 
381  // If this not a file or a block device (e.g. it's a named pipe
382  // or character device), we can't trust the size. Create the memory
383  // buffer by copying off the stream.
384  sys::fs::file_type Type = Status.type();
385  if (Type != sys::fs::file_type::regular_file &&
387  return getMemoryBufferForStream(FD, Filename);
388 
389  FileSize = Status.getSize();
390  }
391  MapSize = FileSize;
392  }
393 
394  if (shouldUseMmap(FD, FileSize, MapSize, Offset, RequiresNullTerminator,
395  PageSize, IsVolatile)) {
396  std::error_code EC;
397  std::unique_ptr<MB> Result(
398  new (NamedBufferAlloc(Filename)) MemoryBufferMMapFile<MB>(
399  RequiresNullTerminator, FD, MapSize, Offset, EC));
400  if (!EC)
401  return std::move(Result);
402  }
403 
404  auto Buf = WritableMemoryBuffer::getNewUninitMemBuffer(MapSize, Filename);
405  if (!Buf) {
406  // Failed to create a buffer. The only way it can fail is if
407  // new(std::nothrow) returns 0.
409  }
410 
411  char *BufPtr = Buf.get()->getBufferStart();
412 
413  size_t BytesLeft = MapSize;
414 #ifndef HAVE_PREAD
415  if (lseek(FD, Offset, SEEK_SET) == -1)
416  return std::error_code(errno, std::generic_category());
417 #endif
418 
419  while (BytesLeft) {
420 #ifdef HAVE_PREAD
421  ssize_t NumRead = sys::RetryAfterSignal(-1, ::pread, FD, BufPtr, BytesLeft,
422  MapSize - BytesLeft + Offset);
423 #else
424  ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, BufPtr, BytesLeft);
425 #endif
426  if (NumRead == -1) {
427  // Error while reading.
428  return std::error_code(errno, std::generic_category());
429  }
430  if (NumRead == 0) {
431  memset(BufPtr, 0, BytesLeft); // zero-initialize rest of the buffer.
432  break;
433  }
434  BytesLeft -= NumRead;
435  BufPtr += NumRead;
436  }
437 
438  return std::move(Buf);
439 }
440 
442 MemoryBuffer::getOpenFile(int FD, const Twine &Filename, uint64_t FileSize,
443  bool RequiresNullTerminator, bool IsVolatile) {
444  return getOpenFileImpl<MemoryBuffer>(FD, Filename, FileSize, FileSize, 0,
445  RequiresNullTerminator, IsVolatile);
446 }
447 
449 MemoryBuffer::getOpenFileSlice(int FD, const Twine &Filename, uint64_t MapSize,
450  int64_t Offset, bool IsVolatile) {
451  assert(MapSize != uint64_t(-1));
452  return getOpenFileImpl<MemoryBuffer>(FD, Filename, -1, MapSize, Offset, false,
453  IsVolatile);
454 }
455 
457  // Read in all of the data from stdin, we cannot mmap stdin.
458  //
459  // FIXME: That isn't necessarily true, we should try to mmap stdin and
460  // fallback if it fails.
462 
463  return getMemoryBufferForStream(0, "<stdin>");
464 }
465 
468  int FD;
469  std::error_code EC = sys::fs::openFileForRead(Filename, FD);
470  if (EC)
471  return EC;
473  getMemoryBufferForStream(FD, Filename);
474  close(FD);
475  return Ret;
476 }
477 
481  return MemoryBufferRef(Data, Identifier);
482 }
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:69
void init(const char *BufStart, const char *BufEnd, bool RequiresNullTerminator)
init - Initialize this MemoryBuffer as a reference to externally allocated memory, memory that we know is already null terminated.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFileSlice(int FD, const Twine &Filename, uint64_t MapSize, int64_t Offset, bool IsVolatile=false)
Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
Represents either an error or a value T.
Definition: ErrorOr.h:69
StringRef getBuffer() const
Definition: MemoryBuffer.h:63
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
static ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false)
Map a subrange of the specified file as a WritableMemoryBuffer.
This class provides various memory handling functions that manipulate MemoryBlock instances...
Definition: Memory.h:46
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:453
This class represents a memory mapped file.
Definition: FileSystem.h:810
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
void reserve(size_type N)
Definition: SmallVector.h:378
Represents the result of a call to sys::fs::status().
Definition: FileSystem.h:219
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
const char * const_data() const
Get a const view of the data.
virtual BufferKind getBufferKind() const =0
Return information on the memory mechanism used to support the MemoryBuffer.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
StringRef getBuffer() const
Definition: MemoryBuffer.h:223
static ErrorOr< std::unique_ptr< MB > > getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize, uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator, bool IsVolatile)
std::error_code make_error_code(BitcodeError E)
static ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool IsVolatile=false)
static ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getMemoryBufferForStream(int FD, const Twine &BufferName)
May only access map via const_data as read only.
Definition: FileSystem.h:813
static std::unique_ptr< WritableMemoryBuffer > getNewMemBuffer(size_t Size, const Twine &BufferName="")
Allocate a new zero-initialized MemoryBuffer of the specified size.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
static ErrorOr< std::unique_ptr< MB > > getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile)
static void CopyStringRef(char *Memory, StringRef Data)
CopyStringRef - Copies contents of a StringRef into a block of memory and null-terminates it...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static std::unique_ptr< WritableMemoryBuffer > getNewUninitMemBuffer(size_t Size, const Twine &BufferName="")
Allocate a new MemoryBuffer of the specified size that is not initialized.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
static const unsigned End
auto RetryAfterSignal(const FailT &Fail, const Fun &F, const Args &... As) -> decltype(F(As...))
Definition: Errno.h:34
static unsigned getPageSize()
MemoryBufferRef getMemBufferRef() const
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
static bool shouldUseMmap(int FD, size_t FileSize, size_t MapSize, off_t Offset, bool RequiresNullTerminator, int PageSize, bool IsVolatile)
StringRef getBufferIdentifier() const
Definition: MemoryBuffer.h:225
iterator begin() const
Definition: StringRef.h:106
May modify via data, but changes are lost on destruction.
Definition: FileSystem.h:815
std::error_code ChangeStdinToBinary()
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false)
Map a subrange of the specified file as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static ErrorOr< std::unique_ptr< WritableMemoryBuffer > > getMemBufferCopyImpl(StringRef InputData, const Twine &BufferName)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
void set_size(size_type N)
Set the array size to N, which the current array must have enough capacity for.
Definition: SmallVector.h:687
Provides a library for accessing information about this process and other processes on the operating ...
file_type
An enumeration for the file system&#39;s view of the type.
Definition: FileSystem.h:57
virtual ~MemoryBuffer()
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:66
#define N
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileAsStream(const Twine &Filename)
Read all of the specified file into a MemoryBuffer as a stream (i.e.
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition: MemoryBuffer.h:139
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
The access may reference the value stored in memory.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(int FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
iterator end() const
Definition: StringRef.h:108