Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- 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 various useful types and classes that have |
| 11 | // widespread use across Subzero. Every Subzero source file is |
| 12 | // expected to include IceDefs.h. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICEDEFS_H |
| 17 | #define SUBZERO_SRC_ICEDEFS_H |
| 18 | |
| 19 | #include <stdint.h> // TODO: <cstdint> with C++11 |
| 20 | |
| 21 | #include <cassert> |
| 22 | #include <cstdio> // snprintf |
| 23 | #include <functional> // std::less |
| 24 | #include <list> |
| 25 | #include <map> |
| 26 | #include <set> |
| 27 | #include <string> |
| 28 | #include <vector> |
| 29 | |
| 30 | #include "llvm/ADT/BitVector.h" |
| 31 | #include "llvm/ADT/SmallBitVector.h" |
| 32 | #include "llvm/ADT/STLExtras.h" |
| 33 | #include "llvm/Support/Casting.h" |
| 34 | #include "llvm/Support/Compiler.h" // LLVM_STATIC_ASSERT |
| 35 | #include "llvm/Support/raw_ostream.h" |
| 36 | #include "llvm/Support/Timer.h" |
| 37 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 38 | // Roll our own static_assert<> in the absence of C++11. TODO: change |
| 39 | // to static_assert<> with C++11. |
| 40 | template <bool> struct staticAssert; |
| 41 | template <> struct staticAssert<true> {}; // only true is defined |
| 42 | #define STATIC_ASSERT(x) staticAssert<(x)>() |
| 43 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 44 | namespace Ice { |
| 45 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 46 | class Cfg; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 47 | class CfgNode; |
| 48 | class Constant; |
| 49 | class GlobalContext; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 50 | class Inst; |
| 51 | class InstPhi; |
| 52 | class InstTarget; |
| 53 | class Operand; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 54 | class TargetLowering; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 55 | class Variable; |
| 56 | |
| 57 | // TODO: Switch over to LLVM's ADT container classes. |
| 58 | // http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task |
| 59 | typedef std::string IceString; |
| 60 | typedef std::list<Inst *> InstList; |
| 61 | typedef std::list<InstPhi *> PhiList; |
| 62 | typedef std::vector<Variable *> VarList; |
| 63 | typedef std::vector<CfgNode *> NodeList; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame^] | 64 | typedef std::vector<Constant *> ConstantList; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 65 | |
| 66 | // SizeT is for holding small-ish limits like number of source |
| 67 | // operands in an instruction. It is used instead of size_t (which |
| 68 | // may be 64-bits wide) when we want to save space. |
| 69 | typedef uint32_t SizeT; |
| 70 | |
| 71 | enum VerboseItem { |
| 72 | IceV_None = 0, |
| 73 | IceV_Instructions = 1 << 0, |
| 74 | IceV_Deleted = 1 << 1, |
| 75 | IceV_InstNumbers = 1 << 2, |
| 76 | IceV_Preds = 1 << 3, |
| 77 | IceV_Succs = 1 << 4, |
| 78 | IceV_Liveness = 1 << 5, |
| 79 | IceV_RegManager = 1 << 6, |
| 80 | IceV_RegOrigins = 1 << 7, |
| 81 | IceV_LinearScan = 1 << 8, |
| 82 | IceV_Frame = 1 << 9, |
| 83 | IceV_Timing = 1 << 10, |
| 84 | IceV_All = ~IceV_None |
| 85 | }; |
| 86 | typedef uint32_t VerboseMask; |
| 87 | |
| 88 | // The Ostream class wraps an output stream and a Cfg pointer, so |
| 89 | // that dump routines have access to the Cfg object and can print |
| 90 | // labels and variable names. |
| 91 | |
| 92 | class Ostream { |
| 93 | public: |
| 94 | Ostream(llvm::raw_ostream *Stream) : Stream(Stream) {} |
| 95 | |
| 96 | llvm::raw_ostream *Stream; |
| 97 | |
| 98 | private: |
| 99 | Ostream(const Ostream &) LLVM_DELETED_FUNCTION; |
| 100 | Ostream &operator=(const Ostream &) LLVM_DELETED_FUNCTION; |
| 101 | }; |
| 102 | |
| 103 | template <typename T> inline Ostream &operator<<(Ostream &Str, const T &Val) { |
| 104 | if (Str.Stream) |
| 105 | (*Str.Stream) << Val; |
| 106 | return Str; |
| 107 | } |
| 108 | |
| 109 | // TODO: Implement in terms of std::chrono after switching to C++11. |
| 110 | class Timer { |
| 111 | public: |
| 112 | Timer() : Start(llvm::TimeRecord::getCurrentTime(false)) {} |
| 113 | uint64_t getElapsedNs() const { return getElapsedSec() * 1000 * 1000 * 1000; } |
| 114 | uint64_t getElapsedUs() const { return getElapsedSec() * 1000 * 1000; } |
| 115 | uint64_t getElapsedMs() const { return getElapsedSec() * 1000; } |
| 116 | double getElapsedSec() const { |
| 117 | llvm::TimeRecord End = llvm::TimeRecord::getCurrentTime(false); |
| 118 | return End.getWallTime() - Start.getWallTime(); |
| 119 | } |
| 120 | void printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const; |
| 121 | |
| 122 | private: |
| 123 | const llvm::TimeRecord Start; |
| 124 | Timer(const Timer &) LLVM_DELETED_FUNCTION; |
| 125 | Timer &operator=(const Timer &) LLVM_DELETED_FUNCTION; |
| 126 | }; |
| 127 | |
| 128 | } // end of namespace Ice |
| 129 | |
| 130 | #endif // SUBZERO_SRC_ICEDEFS_H |