llvm.org GIT mirror llvm / fe2cce6
Removed trailing whitespace. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65196 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 11 years ago
22 changed file(s) with 221 addition(s) and 221 deletion(s). Raw diff Collapse all Expand all
1515 #define LLVM_SUPPORT_ALIGNOF_H
1616
1717 namespace llvm {
18
18
1919 template
2020 struct AlignmentCalcImpl {
2121 char x;
2323 private:
2424 AlignmentCalcImpl() {} // Never instantiate.
2525 };
26
26
2727 /// AlignOf - A templated class that contains an enum value representing
2828 /// the alignment of the template argument. For example,
2929 /// AlignOf::Alignment represents the alignment of type "int". The
4040 enum { Alignment_GreaterEqual_4Bytes = Alignment >= 4 ? 1 : 0 };
4141 enum { Alignment_GreaterEqual_8Bytes = Alignment >= 8 ? 1 : 0 };
4242 enum { Alignment_GreaterEqual_16Bytes = Alignment >= 16 ? 1 : 0 };
43
43
4444 enum { Alignment_LessEqual_2Bytes = Alignment <= 2 ? 1 : 0 };
45 enum { Alignment_LessEqual_4Bytes = Alignment <= 4 ? 1 : 0 };
45 enum { Alignment_LessEqual_4Bytes = Alignment <= 4 ? 1 : 0 };
4646 enum { Alignment_LessEqual_8Bytes = Alignment <= 8 ? 1 : 0 };
4747 enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 };
4848
5454 /// alignof() returns the alignment of an int.
5555 template
5656 static inline unsigned alignof() { return AlignOf::Alignment; }
57
57
5858 } // end namespace llvm
5959 #endif
1717 #include
1818
1919 namespace llvm {
20
20
2121 class MallocAllocator {
2222 public:
2323 MallocAllocator() {}
2424 ~MallocAllocator() {}
25
25
2626 void Reset() {}
2727
2828 void *Allocate(size_t Size, size_t /*Alignment*/) { return malloc(Size); }
29
29
3030 template
3131 T *Allocate() { return static_cast(malloc(sizeof(T))); }
32
32
3333 template
34 T *Allocate(size_t Num) {
34 T *Allocate(size_t Num) {
3535 return static_cast(malloc(sizeof(T)*Num));
3636 }
37
37
3838 void Deallocate(const void *Ptr) { free(const_cast(Ptr)); }
3939
4040 void PrintStats() const {}
5252 public:
5353 BumpPtrAllocator();
5454 ~BumpPtrAllocator();
55
55
5656 void Reset();
5757
5858 void *Allocate(size_t Size, size_t Alignment);
6060 /// Allocate space, but do not construct, one object.
6161 ///
6262 template
63 T *Allocate() {
63 T *Allocate() {
6464 return static_cast(Allocate(sizeof(T),AlignOf::Alignment));
6565 }
66
66
6767 /// Allocate space for an array of objects. This does not construct the
6868 /// objects though.
6969 template
70 T *Allocate(size_t Num) {
70 T *Allocate(size_t Num) {
7171 return static_cast(Allocate(Num * sizeof(T), AlignOf::Alignment));
7272 }
73
73
7474 /// Allocate space for a specific count of elements and with a specified
7575 /// alignment.
7676 template
77 T *Allocate(size_t Num, unsigned Alignment) {
77 T *Allocate(size_t Num, unsigned Alignment) {
7878 // Round EltSize up to the specified alignment.
7979 unsigned EltSize = (sizeof(T)+Alignment-1)&~Alignment;
8080 return static_cast(Allocate(Num * EltSize, Alignment));
5858
5959 /// getUpper - Return the upper value for this range...
6060 ///
61 const APInt &getUpper() const { return Upper; }
61 const APInt &getUpper() const { return Upper; }
6262
6363 /// getBitWidth - get the bit width of this ConstantRange
6464 ///
5353 static std::string getNodeLabel(const void *Node, const GraphType& Graph) {
5454 return "";
5555 }
56
56
5757 /// hasNodeAddressLabel - If this method returns true, the address of the node
5858 /// is added to the label of the node.
5959 template
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This file defines specializations of GraphTraits that allows Use-Def and
9 // This file defines specializations of GraphTraits that allows Use-Def and
1010 // Def-Use relations to be treated as proper graphs for generic algorithms.
1111 //===----------------------------------------------------------------------===//
1212
1919 namespace llvm {
2020
2121 //===----------------------------------------------------------------------===//
22 // Provide specializations of GraphTraits to be able to treat def-use/use-def
22 // Provide specializations of GraphTraits to be able to treat def-use/use-def
2323 // chains as graphs
2424
2525 template <> struct GraphTraits {
6363 /// getErrorOutputStream - Returns the error output stream (std::cerr). This
6464 /// places the std::c* I/O streams into one .cpp file and relieves the whole
6565 /// program from having to have hundreds of static c'tor/d'tors for them.
66 ///
66 ///
6767 OStream &getErrorOutputStream(const char *DebugType);
6868
6969 #ifdef NDEBUG
99 // This file contains constants used for implementing Dwarf debug support. For
1010 // Details on the Dwarf 3 specfication see DWARF Debugging Information Format
1111 // V.3 reference manual http://dwarf.freestandards.org ,
12 //
12 //
1313 //===----------------------------------------------------------------------===//
1414
1515 #ifndef LLVM_SUPPORT_DWARF_H
4141 enum llvm_dwarf_constants {
4242 // llvm mock tags
4343 DW_TAG_invalid = ~0U, // Tag for invalid results.
44
44
4545 DW_TAG_anchor = 0, // Tag for descriptor anchors.
4646 DW_TAG_auto_variable = 0x100, // Tag for local (auto) variables.
4747 DW_TAG_arg_variable = 0x101, // Tag for argument variables.
4848 DW_TAG_return_variable = 0x102, // Tag for return variables.
49
49
5050 DW_TAG_vector_type = 0x103, // Tag for vector types.
51
51
5252 DW_TAG_user_base = 0x1000, // Recommended base for user tags.
53
53
5454 DW_CIE_VERSION = 1, // Common frame information version.
5555 DW_CIE_ID = 0xffffffff // Common frame information mark.
5656 };
5757
5858 enum dwarf_constants {
5959 DWARF_VERSION = 2,
60
60
6161 // Tags
6262 DW_TAG_array_type = 0x01,
6363 DW_TAG_class_type = 0x02,
356356 DW_ACCESS_protected = 0x02,
357357 DW_ACCESS_private = 0x03,
358358
359 // Visibility codes
359 // Visibility codes
360360 DW_VIS_local = 0x01,
361361 DW_VIS_exported = 0x02,
362362 DW_VIS_qualified = 0x03,
365365 DW_VIRTUALITY_none = 0x00,
366366 DW_VIRTUALITY_virtual = 0x01,
367367 DW_VIRTUALITY_pure_virtual = 0x02,
368
368
369369 // Language names
370370 DW_LANG_C89 = 0x0001,
371371 DW_LANG_C = 0x0002,
388388 DW_LANG_D = 0x0013,
389389 DW_LANG_lo_user = 0x8000,
390390 DW_LANG_hi_user = 0xffff,
391
391
392392 // Identifier case codes
393393 DW_ID_case_sensitive = 0x00,
394394 DW_ID_up_case = 0x01,
408408 DW_INL_declared_not_inlined = 0x02,
409409 DW_INL_declared_inlined = 0x03,
410410
411 // Array ordering
411 // Array ordering
412412 DW_ORD_row_major = 0x00,
413413 DW_ORD_col_major = 0x01,
414414
564564 /// LNStandardString - Return the string for the specified line number standard.
565565 ///
566566 const char *LNStandardString(unsigned Standard);
567
567
568568 /// LNExtendedString - Return the string for the specified line number extended
569569 /// opcode encodings.
570570 const char *LNExtendedString(unsigned Encoding);
2525 /// option, it will set the string to an error message if an error occurs, or
2626 /// if the files are different.
2727 ///
28 int DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
28 int DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
2929 const sys::PathWithStatus &FileB,
3030 double AbsTol, double RelTol,
3131 std::string *Error = 0);
3838 public:
3939 format_object_base(const char *fmt) : Fmt(fmt) {}
4040 virtual ~format_object_base() {}
41
41
4242 /// print - Format the object into the specified buffer. On success, this
4343 /// returns the length of the formatted string. If the buffer is too small,
4444 /// this returns a length to retry with, which will be larger than BufferSize.
5656 format_object1(const char *fmt, const T &val)
5757 : format_object_base(fmt), Val(val) {
5858 }
59
59
6060 /// print - Format the object into the specified buffer. On success, this
6161 /// returns the length of the formatted string. If the buffer is too small,
6262 /// this returns a length to retry with, which will be larger than BufferSize.
7070 return N;
7171 }
7272 };
73
73
7474 /// format_object2 - This is a templated helper class used by the format
7575 /// function that captures the object to be formated and the format string. When
7676 /// actually printed, this synthesizes the string into a temporary buffer
8383 format_object2(const char *fmt, const T1 &val1, const T2 &val2)
8484 : format_object_base(fmt), Val1(val1), Val2(val2) {
8585 }
86
86
8787 /// print - Format the object into the specified buffer. On success, this
8888 /// returns the length of the formatted string. If the buffer is too small,
8989 /// this returns a length to retry with, which will be larger than BufferSize.
111111 format_object3(const char *fmt, const T1 &val1, const T2 &val2,const T3 &val3)
112112 : format_object_base(fmt), Val1(val1), Val2(val2), Val3(val3) {
113113 }
114
114
115115 /// print - Format the object into the specified buffer. On success, this
116116 /// returns the length of the formatted string. If the buffer is too small,
117117 /// this returns a length to retry with, which will be larger than BufferSize.
148148 const T2 &Val2, const T3 &Val3) {
149149 return format_object3(Fmt, Val1, Val2, Val3);
150150 }
151
151
152152 } // end namespace llvm
153153
154154 #endif
6666 }
6767
6868 void DisplayGraph(const sys::Path& Filename);
69
69
7070 template
7171 class GraphWriter {
7272 std::ostream &O;
112112 I != E; ++I)
113113 writeNode(*I);
114114 }
115
115
116116 void writeNode(NodeType& Node) {
117117 writeNode(&Node);
118118 }
270270
271271 template
272272 sys::Path WriteGraph(const GraphType &G,
273 const std::string& Name,
273 const std::string& Name,
274274 const std::string& Title = "") {
275275 std::string ErrMsg;
276276 sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
285285 }
286286
287287 cerr << "Writing '" << Filename << "'... ";
288
288
289289 std::ofstream O(Filename.c_str());
290290
291291 if (O.good()) {
297297 cerr << "error opening file for writing!\n";
298298 Filename.clear();
299299 }
300
300
301301 return Filename;
302302 }
303
303
304304 /// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
305305 /// then cleanup. For use from the debugger.
306306 ///
307307 template
308 void ViewGraph(const GraphType& G,
309 const std::string& Name,
308 void ViewGraph(const GraphType& G,
309 const std::string& Name,
310310 const std::string& Title = "") {
311311 sys::Path Filename = WriteGraph(G, Name, Title);
312312
313313 if (Filename.isEmpty()) {
314314 return;
315315 }
316
316
317317 DisplayGraph(Filename);
318318 }
319319
634634
635635 /// CreateIsNull - Return an i1 value testing if \arg Arg is null.
636636 Value *CreateIsNull(Value *Arg, const char *Name = "") {
637 return CreateICmpEQ(Arg, llvm::Constant::getNullValue(Arg->getType()),
637 return CreateICmpEQ(Arg, llvm::Constant::getNullValue(Arg->getType()),
638638 Name);
639639 }
640640
641641 /// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
642642 Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
643 return CreateICmpNE(Arg, llvm::Constant::getNullValue(Arg->getType()),
643 return CreateICmpNE(Arg, llvm::Constant::getNullValue(Arg->getType()),
644644 Name);
645645 }
646
646
647647 };
648648
649649 }
3030 /// @brief Base class for instruction visitors
3131 ///
3232 /// Instruction visitors are used when you want to perform different action for
33 /// different kinds of instruction without without having to use lots of casts
34 /// and a big switch statement (in your code that is).
33 /// different kinds of instruction without without having to use lots of casts
34 /// and a big switch statement (in your code that is).
3535 ///
3636 /// To define your own visitor, inherit from this class, specifying your
3737 /// new type for the 'SubClass' template parameter, and "override" visitXXX
38 /// functions in your class. I say "overriding" because this class is defined
39 /// in terms of statically resolved overloading, not virtual functions.
40 ///
41 /// For example, here is a visitor that counts the number of malloc
38 /// functions in your class. I say "overriding" because this class is defined
39 /// in terms of statically resolved overloading, not virtual functions.
40 ///
41 /// For example, here is a visitor that counts the number of malloc
4242 /// instructions processed:
4343 ///
4444 /// /// Declare the class. Note that we derive from InstVisitor instantiated
6464 /// if instructions are added in the future, they will be automatically
6565 /// supported, if you handle on of their superclasses.
6666 ///
67 /// The optional second template argument specifies the type that instruction
68 /// visitation functions should return. If you specify this, you *MUST* provide
67 /// The optional second template argument specifies the type that instruction
68 /// visitation functions should return. If you specify this, you *MUST* provide
6969 /// an implementation of visitInstruction though!.
7070 ///
7171 /// Note that this class is specifically designed as a template to avoid
3030 mutable void *Ptr;
3131 mutable void (*DeleterFn)(void*);
3232 mutable const ManagedStaticBase *Next;
33
33
3434 void RegisterManagedStatic(void *ObjPtr, void (*deleter)(void*)) const;
3535 public:
36 /// isConstructed - Return true if this object has not been created yet.
36 /// isConstructed - Return true if this object has not been created yet.
3737 bool isConstructed() const { return Ptr != 0; }
38
38
3939 void destroy() const;
4040 };
4141
4747 template
4848 class ManagedStatic : public ManagedStaticBase {
4949 public:
50
50
5151 // Accessors.
5252 C &operator*() {
5353 if (!Ptr) LazyInit();
6565 if (!Ptr) LazyInit();
6666 return static_cast(Ptr);
6767 }
68
68
6969 public:
7070 void LazyInit() const {
7171 RegisterManagedStatic(new C(), object_deleter);
8282 /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
8383 void llvm_shutdown();
8484
85
85
8686 /// llvm_shutdown_obj - This is a simple helper class that calls
8787 /// llvm_shutdown() when it is destroyed.
8888 struct llvm_shutdown_obj {
8989 llvm_shutdown_obj() {}
9090 ~llvm_shutdown_obj() { llvm_shutdown(); }
9191 };
92
92
9393 }
9494
9595 #endif
2727 /// Prefix - This string is added to each symbol that is emitted, unless the
2828 /// symbol is marked as not needing this prefix.
2929 const char *Prefix;
30
30
3131 const char *PrivatePrefix;
32 /// UseQuotes - If this is set, the target accepts global names in quotes,
32 /// UseQuotes - If this is set, the target accepts global names in quotes,
3333 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
3434 /// the space character. By default, this is false.
3535 bool UseQuotes;
36
36
3737 /// PreserveAsmNames - If this is set, the asm escape character is not removed
38 /// from names with 'asm' specifiers.
38 /// from names with 'asm' specifiers.
3939 bool PreserveAsmNames;
40
40
4141 /// Memo - This is used to remember the name that we assign a value.
4242 ///
4343 DenseMap Memo;
4545 /// Count - This simple counter is used to unique value names.
4646 ///
4747 unsigned Count;
48
48
4949 /// TypeMap - If the client wants us to unique types, this keeps track of the
5050 /// current assignments and TypeCounter keeps track of the next id to assign.
5151 DenseMap TypeMap;
6363 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
6464 /// strings for assembler labels.
6565 void setUseQuotes(bool Val) { UseQuotes = Val; }
66
66
6767 /// setPreserveAsmNames - If the mangler should not strip off the asm name
6868 /// @verbatim identifier (\001), this should be set. @endverbatim
6969 void setPreserveAsmNames(bool Val) { PreserveAsmNames = Val; }
70
70
7171 /// Acceptable Characters - This allows the target to specify which characters
7272 /// are acceptable to the assembler without being mangled. By default we
7373 /// allow letters, numbers, '_', '$', and '.', which is what GAS accepts.
8080 bool isCharAcceptable(unsigned char X) const {
8181 return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
8282 }
83
83
8484 /// getValueName - Returns the mangled name of V, an LLVM Value,
8585 /// in the current module.
8686 ///
1717
1818 namespace llvm {
1919
20 // NOTE: The following support functions use the _32/_64 extensions instead of
20 // NOTE: The following support functions use the _32/_64 extensions instead of
2121 // type overloading so that signed and unsigned integers can be used without
2222 // ambiguity.
2323
3232 }
3333
3434 /// is?Type - these functions produce optimal testing for integer data types.
35 inline bool isInt8 (int64_t Value) {
36 return static_cast(Value) == Value;
37 }
38 inline bool isUInt8 (int64_t Value) {
39 return static_cast(Value) == Value;
40 }
41 inline bool isInt16 (int64_t Value) {
42 return static_cast(Value) == Value;
43 }
44 inline bool isUInt16(int64_t Value) {
45 return static_cast(Value) == Value;
46 }
47 inline bool isInt32 (int64_t Value) {
48 return static_cast(Value) == Value;
49 }
50 inline bool isUInt32(int64_t Value) {
51 return static_cast(Value) == Value;
35 inline bool isInt8 (int64_t Value) {
36 return static_cast(Value) == Value;
37 }
38 inline bool isUInt8 (int64_t Value) {
39 return static_cast(Value) == Value;
40 }
41 inline bool isInt16 (int64_t Value) {
42 return static_cast(Value) == Value;
43 }
44 inline bool isUInt16(int64_t Value) {
45 return static_cast(Value) == Value;
46 }
47 inline bool isInt32 (int64_t Value) {
48 return static_cast(Value) == Value;
49 }
50 inline bool isUInt32(int64_t Value) {
51 return static_cast(Value) == Value;
5252 }
5353
5454 /// isMask_32 - This function returns true if the argument is a sequence of ones
6565 return Value && ((Value + 1) & Value) == 0;
6666 }
6767
68 /// isShiftedMask_32 - This function returns true if the argument contains a
68 /// isShiftedMask_32 - This function returns true if the argument contains a
6969 /// sequence of ones with the remainder zero (32 bit version.)
7070 /// Ex. isShiftedMask_32(0x0000FF00U) == true.
7171 inline bool isShiftedMask_32(uint32_t Value) {
7272 return isMask_32((Value - 1) | Value);
7373 }
7474
75 /// isShiftedMask_64 - This function returns true if the argument contains a
75 /// isShiftedMask_64 - This function returns true if the argument contains a
7676 /// sequence of ones with the remainder zero (64 bit version.)
7777 inline bool isShiftedMask_64(uint64_t Value) {
7878 return isMask_64((Value - 1) | Value);
7979 }
8080
81 /// isPowerOf2_32 - This function returns true if the argument is a power of
81 /// isPowerOf2_32 - This function returns true if the argument is a power of
8282 /// two > 0. Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.)
8383 inline bool isPowerOf2_32(uint32_t Value) {
8484 return Value && !(Value & (Value - 1));
171171 }
172172
173173 /// CountLeadingZeros_64 - This function performs the platform optimal form
174 /// of counting the number of zeros from the most significant bit to the first
174 /// of counting the number of zeros from the most significant bit to the first
175175 /// one bit (64 bit edition.)
176176 /// Returns 64 if the word is zero.
177177 inline unsigned CountLeadingZeros_64(uint64_t Value) {
215215 }
216216
217217 /// CountLeadingOnes_64 - This function performs the operation
218 /// of counting the number of ones from the most significant bit to the first
218 /// of counting the number of ones from the most significant bit to the first
219219 /// zero bit (64 bit edition.)
220220 /// Returns 64 if the word is all ones.
221221 inline unsigned CountLeadingOnes_64(uint64_t Value) {
248248 }
249249
250250 /// CountTrailingZeros_64 - This function performs the platform optimal form
251 /// of counting the number of zeros from the least significant bit to the first
251 /// of counting the number of zeros from the least significant bit to the first
252252 /// one bit (64 bit edition.)
253253 /// Returns 64 if the word is zero.
254254 inline unsigned CountTrailingZeros_64(uint64_t Value) {
267267 }
268268
269269 /// CountTrailingOnes_64 - This function performs the operation
270 /// of counting the number of ones from the least significant bit to the first
270 /// of counting the number of ones from the least significant bit to the first
271271 /// zero bit (64 bit edition.)
272272 /// Returns 64 if the word is all ones.
273273 inline unsigned CountTrailingOnes_64(uint64_t Value) {
300300 #endif
301301 }
302302
303 /// Log2_32 - This function returns the floor log base 2 of the specified value,
303 /// Log2_32 - This function returns the floor log base 2 of the specified value,
304304 /// -1 if the value is zero. (32 bit edition.)
305305 /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2
306306 inline unsigned Log2_32(uint32_t Value) {
307307 return 31 - CountLeadingZeros_32(Value);
308308 }
309309
310 /// Log2_64 - This function returns the floor log base 2 of the specified value,
310 /// Log2_64 - This function returns the floor log base 2 of the specified value,
311311 /// -1 if the value is zero. (64 bit edition.)
312312 inline unsigned Log2_64(uint64_t Value) {
313313 return 63 - CountLeadingZeros_64(Value);
320320 return 32-CountLeadingZeros_32(Value-1);
321321 }
322322
323 /// Log2_64 - This function returns the ceil log base 2 of the specified value,
323 /// Log2_64 - This function returns the ceil log base 2 of the specified value,
324324 /// 64 if the value is zero. (64 bit edition.)
325325 inline unsigned Log2_64_Ceil(uint64_t Value) {
326326 return 64-CountLeadingZeros_64(Value-1);
336336 }
337337 return A;
338338 }
339
339
340340 /// BitsToDouble - This function takes a 64-bit integer and returns the bit
341341 /// equivalent double.
342342 inline double BitsToDouble(uint64_t Bits) {
423423 inline uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align) {
424424 return ((Value + Align - 1) / Align) * Align;
425425 }
426
426
427427 } // End llvm namespace
428428
429429 #endif
3636 void initCopyOf(const char *BufStart, const char *BufEnd);
3737 public:
3838 virtual ~MemoryBuffer();
39
39
4040 const char *getBufferStart() const { return BufferStart; }
4141 const char *getBufferEnd() const { return BufferEnd; }
4242 size_t getBufferSize() const { return BufferEnd-BufferStart; }
43
43
4444 /// getBufferIdentifier - Return an identifier for this buffer, typically the
4545 /// filename it was read from.
4646 virtual const char *getBufferIdentifier() const {
5959 /// that EndPtr[0] must be a null byte and be accessible!
6060 static MemoryBuffer *getMemBuffer(const char *StartPtr, const char *EndPtr,
6161 const char *BufferName = "");
62
62
6363 /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
6464 /// copying the contents and taking ownership of it. This has no requirements
6565 /// on EndPtr[0].
6666 static MemoryBuffer *getMemBufferCopy(const char *StartPtr,const char *EndPtr,
6767 const char *BufferName = "");
68
68
6969 /// getNewMemBuffer - Allocate a new MemoryBuffer of the specified size that
7070 /// is completely initialized to zeros. Note that the caller should
7171 /// initialize the memory allocated by this method. The memory is owned by
7272 /// the MemoryBuffer object.
7373 static MemoryBuffer *getNewMemBuffer(size_t Size,
7474 const char *BufferName = "");
75
75
7676 /// getNewUninitMemBuffer - Allocate a new MemoryBuffer of the specified size
7777 /// that is not initialized. Note that the caller should initialize the
7878 /// memory allocated by this method. The memory is owned by the MemoryBuffer
7979 /// object.
8080 static MemoryBuffer *getNewUninitMemBuffer(size_t Size,
8181 const char *BufferName = "");
82
82
8383 /// getSTDIN - Read all of stdin into a file buffer, and return it. This
8484 /// returns null if stdin is empty.
8585 static MemoryBuffer *getSTDIN();
86
87
86
87
8888 /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
8989 /// if the Filename is "-". If an error occurs, this returns null and fills
9090 /// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
9292 static MemoryBuffer *getFileOrSTDIN(const char *Filename,
9393 std::string *ErrStr = 0,
9494 int64_t FileSize = -1);
95
95
9696 /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
9797 /// if the Filename is "-". If an error occurs, this returns null and fills
9898 /// in *ErrStr with a reason.
1717 #include
1818
1919 namespace llvm {
20
20
2121 class OutputBuffer {
2222 /// Output buffer.
2323 std::vector &Output;
3636 assert(Boundary && (Boundary & (Boundary - 1)) == 0 &&
3737 "Must align to 2^k boundary");
3838 size_t Size = Output.size();
39
39
4040 if (Size & (Boundary - 1)) {
4141 // Add padding to get alignment to the correct place.
4242 size_t Pad = Boundary - (Size & (Boundary - 1));
110110 ? static_cast(S.length()) : Length;
111111 unsigned len_to_fill = static_cast(S.length()) < Length
112112 ? Length - static_cast(S.length()) : 0;
113
113
114114 for (unsigned i = 0; i < len_to_copy; ++i)
115115 outbyte(S[i]);
116
116
117117 for (unsigned i = 0; i < len_to_fill; ++i)
118118 outbyte(0);
119119 }
147147 return Output[Index];
148148 }
149149 };
150
150
151151 } // end llvm namespace
152152
153153 #endif // LLVM_SUPPORT_OUTPUTBUFFER_H
107107
108108 /// m_ConstantInt - Match a ConstantInt, capturing the value if we match.
109109 inline bind_ty m_ConstantInt(ConstantInt *&CI) { return CI; }
110
110
111111 /// specificval_ty - Match a specified Value*.
112112 struct specificval_ty {
113113 const Value *Val;
114114 specificval_ty(const Value *V) : Val(V) {}
115
115
116116 template
117117 bool match(ITy *V) {
118118 return V == Val;
119119 }
120120 };
121
121
122122 /// m_Specific - Match if we have a specific specified value.
123123 inline specificval_ty m_Specific(const Value *V) { return V; }
124
124
125125
126126 //===----------------------------------------------------------------------===//
127127 // Matchers for specific binary operators.
128128 //
129129
130 template
130 template
131131 unsigned Opcode, typename ConcreteTy = BinaryOperator>
132132 struct BinaryOp_match {
133133 LHS_t L;
222222 }
223223
224224 template
225 inline BinaryOp_match m_Shl(const LHS &L,
225 inline BinaryOp_match m_Shl(const LHS &L,
226226 const RHS &R) {
227227 return BinaryOp_match(L, R);
228228 }
229229
230230 template
231 inline BinaryOp_match m_LShr(const LHS &L,
231 inline BinaryOp_match m_LShr(const LHS &L,
232232 const RHS &R) {
233233 return BinaryOp_match(L, R);
234234 }
235235
236236 template
237 inline BinaryOp_match m_AShr(const LHS &L,
237 inline BinaryOp_match m_AShr(const LHS &L,
238238 const RHS &R) {
239239 return BinaryOp_match(L, R);
240240 }
309309 template
310310 inline BinaryOpClass_match
311311 m_Shift(Instruction::BinaryOps &Op, const LHS &L, const RHS &R) {
312 return BinaryOpClass_match
312 return BinaryOpClass_match
313313 BinaryOperator, Instruction::BinaryOps>(Op, L, R);
314314 }
315315
316316 template
317317 inline BinaryOpClass_match
318318 m_Shift(const LHS &L, const RHS &R) {
319 return BinaryOpClass_match
319 return BinaryOpClass_match
320320 BinaryOperator, Instruction::BinaryOps>(L, R);
321321 }
322322
394394 template
395395 inline SelectClass_match, constantint_ty >
396396 m_SelectCst(const Cond &C) {
397 return SelectClass_match,
397 return SelectClass_match,
398398 constantint_ty >(C, m_ConstantInt(),
399399 m_ConstantInt());
400400 }
407407 template
408408 struct CastClass_match {
409409 Op_t Op;
410
410
411411 CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
412
412
413413 template
414414 bool match(OpTy *V) {
415415 if (Class *I = dyn_cast(V))
423423 return CastClass_match(Op);
424424 }
425425
426
426
427427 //===----------------------------------------------------------------------===//
428428 // Matchers for unary operators
429429 //
467467 template
468468 struct neg_match {
469469 LHS_t L;
470
470
471471 neg_match(const LHS_t &LHS) : L(LHS) {}
472
472
473473 template
474474 bool match(OpTy *V) {
475475 if (Instruction *I = dyn_cast(V))
3030 /// Memory - This is the space that holds cached preds.
3131 BumpPtrAllocator Memory;
3232 public:
33
33
3434 /// GetPreds - Get a cached list for the null-terminated predecessor list of
3535 /// the specified block. This can be used in a loop like this:
3636 /// for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI)
4040 BasicBlock **GetPreds(BasicBlock *BB) {
4141 BasicBlock **&Entry = BlockToPredsMap[BB];
4242 if (Entry) return Entry;
43
43
4444 SmallVector PredCache(pred_begin(BB), pred_end(BB));
4545 PredCache.push_back(0); // null terminator.
46
46
4747 Entry = Memory.Allocate(PredCache.size());
4848 std::copy(PredCache.begin(), PredCache.end(), Entry);
4949 return Entry;
5050 }
51
51
5252 /// clear - Remove all information.
5353 void clear() {
5454 BlockToPredsMap.clear();
2323
2424 /// BaseStream - Acts like the STL streams. It's a wrapper for the std::cerr,
2525 /// std::cout, std::cin, etc. streams. However, it doesn't require #including
26 /// @verbatim @endverbatm in every file (doing so increases static
26 /// @verbatim @endverbatm in every file (doing so increases static
2727 /// c'tors & d'tors in the object code).
28 ///
28 ///
2929 template
3030 class BaseStream {
3131 StreamTy *Stream;
6868 if (Stream) Stream->write(A, N);
6969 return *this;
7070 }
71
71
7272 operator StreamTy* () { return Stream; }
7373
7474 bool operator == (const StreamTy &S) { return &S == Stream; }
88 //
99 // This file declares an interned string pool, which helps reduce the cost of
1010 // strings by using the same storage for identical strings.
11 //
11 //
1212 // To intern a string:
13 //
13 //
1414 // StringPool Pool;
1515 // PooledStringPtr Str = Pool.intern("wakka wakka");
16 //
16 //
1717 // To use the value of an interned string, use operator bool and operator*:
18 //
18 //
1919 // if (Str)
2020 // cerr << "the string is" << *Str << "\n";
21 //
21 //
2222 // Pooled strings are immutable, but you can change a PooledStringPtr to point
2323 // to another instance. So that interned strings can eventually be freed,
2424 // strings in the string pool are reference-counted (automatically).
25 //
25 //
2626 //===----------------------------------------------------------------------===//
2727
2828 #ifndef LLVM_SUPPORT_STRINGPOOL_H
4545 struct PooledString {
4646 StringPool *Pool; ///< So the string can remove itself.
4747 unsigned Refcount; ///< Number of referencing PooledStringPtrs.
48
48
4949 public:
5050 PooledString() : Pool(0), Refcount(0) { }
5151 };
52
52
5353 friend class PooledStringPtr;
54
54
5555 typedef StringMap table_t;
5656 typedef StringMapEntry entry_t;
5757 table_t InternTable;
58
58
5959 public:
6060 StringPool();
6161 ~StringPool();
62
62
6363 /// intern - Adds a string to the pool and returns a reference-counted
6464 /// pointer to it. No additional memory is allocated if the string already
6565 /// exists in the pool.
6666 PooledStringPtr intern(const char *Begin, const char *End);
67
67
6868 /// intern - Adds a null-terminated string to the pool and returns a
6969 /// reference-counted pointer to it. No additional memory is allocated if
7070 /// the string already exists in the pool.
7171 inline PooledStringPtr intern(const char *Str);
72
72
7373 /// empty - Checks whether the pool is empty. Returns true if so.
74 ///
74 ///
7575 inline bool empty() const { return InternTable.empty(); }
7676 };
77
77
7878 /// PooledStringPtr - A pointer to an interned string. Use operator bool to
7979 /// test whether the pointer is valid, and operator * to get the string if so.
8080 /// This is a lightweight value class with storage requirements equivalent to
8383 class PooledStringPtr {
8484 typedef StringPool::entry_t entry_t;
8585 entry_t *S;
86
86
8787 public:
8888 PooledStringPtr() : S(0) {}
89
89
9090 explicit PooledStringPtr(entry_t *E) : S(E) {
9191 if (S) ++S->getValue().Refcount;
9292 }
93
93
9494 PooledStringPtr(const PooledStringPtr &That) : S(That.S) {
9595 if (S) ++S->getValue().Refcount;
9696 }
97
97
9898 PooledStringPtr &operator=(const PooledStringPtr &That) {
9999 if (S != That.S) {
100100 clear();
103103 }
104104 return *this;
105105 }
106
106
107107 void clear() {
108108 if (!S)
109109 return;
113113 }
114114 S = 0;
115115 }
116
116
117117 ~PooledStringPtr() { clear(); }
118
118
119119 inline const char *begin() const {
120120 assert(*this && "Attempt to dereference empty PooledStringPtr!");
121121 return S->getKeyData();
122122 }
123
123
124124 inline const char *end() const {
125125 assert(*this && "Attempt to dereference empty PooledStringPtr!");
126126 return S->getKeyData() + S->getKeyLength();
127127 }
128
128
129129 inline unsigned size() const {
130130 assert(*this && "Attempt to dereference empty PooledStringPtr!");
131131 return S->getKeyLength();
132132 }
133
133
134134 inline const char *operator*() const { return begin(); }
135135 inline operator bool() const { return S != 0; }
136
136
137137 inline bool operator==(const PooledStringPtr &That) { return S == That.S; }
138138 inline bool operator!=(const PooledStringPtr &That) { return S != That.S; }
139139 };
140
140
141141 PooledStringPtr StringPool::intern(const char *Str) {
142142 return intern(Str, Str + strlen(Str));
143143 }
2323 class format_object_base;
2424 template
2525 class SmallVectorImpl;
26
26
2727 /// raw_ostream - This class implements an extremely fast bulk output stream
2828 /// that can *only* output to a stream. It does not support seeking, reopening,
2929 /// rewinding, line buffered disciplines etc. It is a simple buffer that outputs
4040 virtual ~raw_ostream() {
4141 delete [] OutBufStart;
4242 }
43
43
4444 //===--------------------------------------------------------------------===//
4545 // Configuration Interface
4646 //===--------------------------------------------------------------------===//
47
47
4848 /// SetBufferSize - Set the internal buffer size to the specified amount
4949 /// instead of the default.
5050 void SetBufferSize(unsigned Size) {
5151 assert(Size >= 64 &&
5252 "Buffer size must be somewhat large for invariants to hold");
5353 flush();
54
54
5555 delete [] OutBufStart;
5656 OutBufStart = new char[Size];
5757 OutBufEnd = OutBufStart+Size;
5858 OutBufCur = OutBufStart;
5959 }
60
60
6161 //===--------------------------------------------------------------------===//
6262 // Data Output Interface
6363 //===--------------------------------------------------------------------===//
64
64
6565 void flush() {
6666 if (OutBufCur != OutBufStart)
6767 flush_impl();
6868 }
69
69
7070 raw_ostream &operator<<(char C) {
7171 if (OutBufCur >= OutBufEnd)
7272 flush_impl();
7373 *OutBufCur++ = C;
7474 return *this;
7575 }
76
76
7777 raw_ostream &operator<<(unsigned char C) {
7878 if (OutBufCur >= OutBufEnd)
7979 flush_impl();
8080 *OutBufCur++ = C;
8181 return *this;
8282 }
83
83
8484 raw_ostream &operator<<(signed char C) {
8585 if (OutBufCur >= OutBufEnd)
8686 flush_impl();
8787 *OutBufCur++ = C;
8888 return *this;
8989 }
90
90
9191 raw_ostream &operator<<(const char *Str) {
9292 return write(Str, strlen(Str));
9393 }
94
94
9595 raw_ostream &operator<<(const std::string& Str) {
9696 return write(Str.data(), Str.length());
9797 }
98
98
9999 raw_ostream &operator<<(unsigned long N);
100100 raw_ostream &operator<<(long N);
101101 raw_ostream &operator<<(unsigned long long N);
104104 raw_ostream &operator<<(unsigned int N) {
105105 return this->operator<<(static_cast(N));
106106 }
107
107
108108 raw_ostream &operator<<(int N) {
109109 return this->operator<<(static_cast(N));
110110 }
112112 raw_ostream &operator<<(double N) {
113113 return this->operator<<(ftostr(N));
114114 }
115
115
116116 raw_ostream &write(const char *Ptr, unsigned Size);
117
117
118118 // Formatted output, see the format() function in Support/Format.h.
119119 raw_ostream &operator<<(const format_object_base &Fmt);
120
120
121121 //===--------------------------------------------------------------------===//
122122 // Subclass Interface
123123 //===--------------------------------------------------------------------===//
124124
125125 protected:
126
126
127127 /// flush_impl - The is the piece of the class that is implemented by
128128 /// subclasses. This outputs the currently buffered data and resets the
129129 /// buffer to empty.
130130 virtual void flush_impl() = 0;
131
131
132132 /// HandleFlush - A stream's implementation of flush should call this after
133133 /// emitting the bytes to the data sink.
134134 void HandleFlush() {
140140 // An out of line virtual method to provide a home for the class vtable.
141141 virtual void handle();
142142 };
143
143
144144 //===----------------------------------------------------------------------===//
145145 // File Output Streams
146146 //===----------------------------------------------------------------------===//
147
147
148148 /// raw_fd_ostream - A raw_ostream that writes to a file descriptor.
149149 ///
150150 class raw_fd_ostream : public raw_ostream {
162162 /// \param Binary - The file should be opened in binary mode on
163163 /// platforms that support this distinction.
164164 raw_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo);
165
165
166166 /// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
167 /// ShouldClose is true, this closes the file when
167 /// ShouldClose is true, this closes the file when
168168 raw_fd_ostream(int fd, bool shouldClose) : FD(fd), ShouldClose(shouldClose) {}
169
169
170170 ~raw_fd_ostream();
171
172 /// flush_impl - The is the piece of the class that is implemented by
173 /// subclasses. This outputs the currently buffered data and resets the
174 /// buffer to empty.
175 virtual void flush_impl();
176
171
172 /// flush_impl - The is the piece of the class that is implemented by
173 /// subclasses. This outputs the currently buffered data and resets the
174 /// buffer to empty.
175 virtual void flush_impl();
176
177177 /// close - Manually flush the stream and close the file.
178178 void close();
179
179
180180 /// tell - Return the current offset with the file.
181181 uint64_t tell() {
182182 return pos + (OutBufCur - OutBufStart);
183183 }
184
184
185185 /// seek - Flushes the stream and repositions the underlying file descriptor
186186 /// positition to the offset specified from the beginning of the file.
187187 uint64_t seek(uint64_t off);
188188 };
189
189
190190 /// raw_stdout_ostream - This is a stream that always prints to stdout.
191191 ///
192192 class raw_stdout_ostream : public raw_fd_ostream {
204204 public:
205205 raw_stderr_ostream();
206206 };
207
207
208208 /// outs() - This returns a reference to a raw_ostream for standard output.
209209 /// Use it like: outs() << "foo" << "bar";
210210 raw_ostream &outs();
212212 /// errs() - This returns a reference to a raw_ostream for standard error.
213213 /// Use it like: errs() << "foo" << "bar";
214214 raw_ostream &errs();
215
216
215
216
217217 //===----------------------------------------------------------------------===//
218218 // Output Stream Adaptors
219219 //===----------------------------------------------------------------------===//
220
220
221221 /// raw_os_ostream - A raw_ostream that writes to an std::ostream. This is a
222222 /// simple adaptor class.
223223 class raw_os_ostream : public raw_ostream {
239239 public:
240240 raw_string_ostream(std::string &O) : OS(O) {}
241241 ~raw_string_ostream();
242
242
243243 /// str - Flushes the stream contents to the target string and returns
244244 /// the string's reference.
245245 std::string& str() {
246246 flush();
247247 return OS;
248248 }
249
250 /// flush_impl - The is the piece of the class that is implemented by
251 /// subclasses. This outputs the currently buffered data and resets the
252 /// buffer to empty.
253 virtual void flush_impl();
254 };
255
249
250 /// flush_impl - The is the piece of the class that is implemented by
251 /// subclasses. This outputs the currently buffered data and resets the
252 /// buffer to empty.
253 virtual void flush_impl();
254 };
255
256256 /// raw_svector_ostream - A raw_ostream that writes to an SmallVector or
257257 /// SmallString. This is a simple adaptor class.
258258 class raw_svector_ostream : public raw_ostream {
260260 public:
261261 raw_svector_ostream(SmallVectorImpl &O) : OS(O) {}
262262 ~raw_svector_ostream();
263
264 /// flush_impl - The is the piece of the class that is implemented by
265 /// subclasses. This outputs the currently buffered data and resets the
266 /// buffer to empty.
267 virtual void flush_impl();
268 };
269
263
264 /// flush_impl - The is the piece of the class that is implemented by
265 /// subclasses. This outputs the currently buffered data and resets the
266 /// buffer to empty.
267 virtual void flush_impl();
268 };
269
270270 } // end llvm namespace
271271
272272 #endif