Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 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 declares aspects of the compilation that persist across |
| 11 | // multiple functions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| 16 | #define SUBZERO_SRC_ICEGLOBALCONTEXT_H |
| 17 | |
| 18 | #include "llvm/ADT/OwningPtr.h" |
| 19 | #include "llvm/Support/Allocator.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | |
| 22 | #include "IceDefs.h" |
| 23 | #include "IceTypes.h" |
| 24 | |
| 25 | namespace Ice { |
| 26 | |
| 27 | // TODO: Accesses to all non-const fields of GlobalContext need to |
| 28 | // be synchronized, especially the constant pool, the allocator, and |
| 29 | // the output streams. |
| 30 | class GlobalContext { |
| 31 | public: |
| 32 | GlobalContext(llvm::raw_ostream *OsDump, llvm::raw_ostream *OsEmit, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame^] | 33 | VerboseMask Mask, TargetArch Arch, OptLevel Opt, |
| 34 | IceString TestPrefix); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 35 | ~GlobalContext(); |
| 36 | |
| 37 | // Returns true if any of the specified options in the verbose mask |
| 38 | // are set. If the argument is omitted, it checks if any verbose |
| 39 | // options at all are set. IceV_Timing is treated specially, so |
| 40 | // that running with just IceV_Timing verbosity doesn't trigger an |
| 41 | // avalanche of extra output. |
| 42 | bool isVerbose(VerboseMask Mask = (IceV_All & ~IceV_Timing)) const { |
| 43 | return VMask & Mask; |
| 44 | } |
| 45 | void setVerbose(VerboseMask Mask) { VMask = Mask; } |
| 46 | void addVerbose(VerboseMask Mask) { VMask |= Mask; } |
| 47 | void subVerbose(VerboseMask Mask) { VMask &= ~Mask; } |
| 48 | |
| 49 | Ostream &getStrDump() { return StrDump; } |
| 50 | Ostream &getStrEmit() { return StrEmit; } |
| 51 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame^] | 52 | TargetArch getTargetArch() const { return Arch; } |
| 53 | OptLevel getOptLevel() const { return Opt; } |
| 54 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 55 | // When emitting assembly, we allow a string to be prepended to |
| 56 | // names of translated functions. This makes it easier to create an |
| 57 | // execution test against a reference translator like llc, with both |
| 58 | // translators using the same bitcode as input. |
| 59 | IceString getTestPrefix() const { return TestPrefix; } |
| 60 | IceString mangleName(const IceString &Name) const; |
| 61 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame^] | 62 | // The purpose of HasEmitted is to add a header comment at the |
| 63 | // beginning of assembly code emission, doing it once per file |
| 64 | // rather than once per function. |
| 65 | bool testAndSetHasEmittedFirstMethod() { |
| 66 | bool HasEmitted = HasEmittedFirstMethod; |
| 67 | HasEmittedFirstMethod = true; |
| 68 | return HasEmitted; |
| 69 | } |
| 70 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 71 | // Manage Constants. |
| 72 | // getConstant*() functions are not const because they might add |
| 73 | // something to the constant pool. |
| 74 | Constant *getConstantInt(Type Ty, uint64_t ConstantInt64); |
| 75 | Constant *getConstantFloat(float Value); |
| 76 | Constant *getConstantDouble(double Value); |
| 77 | // Returns a symbolic constant. |
| 78 | Constant *getConstantSym(Type Ty, int64_t Offset, const IceString &Name = "", |
| 79 | bool SuppressMangling = false); |
| 80 | |
| 81 | // Allocate data of type T using the global allocator. |
| 82 | template <typename T> T *allocate() { return Allocator.Allocate<T>(); } |
| 83 | |
| 84 | private: |
| 85 | Ostream StrDump; // Stream for dumping / diagnostics |
| 86 | Ostream StrEmit; // Stream for code emission |
| 87 | |
| 88 | llvm::BumpPtrAllocator Allocator; |
| 89 | VerboseMask VMask; |
| 90 | llvm::OwningPtr<class ConstantPool> ConstPool; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame^] | 91 | const TargetArch Arch; |
| 92 | const OptLevel Opt; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 93 | const IceString TestPrefix; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame^] | 94 | bool HasEmittedFirstMethod; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 95 | GlobalContext(const GlobalContext &) LLVM_DELETED_FUNCTION; |
| 96 | GlobalContext &operator=(const GlobalContext &) LLVM_DELETED_FUNCTION; |
| 97 | }; |
| 98 | |
| 99 | } // end of namespace Ice |
| 100 | |
| 101 | #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |