Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 <cassert> | |
| 20 #include <stdint.h> | |
| 21 #include <cstdio> // snprintf | |
| 22 | |
| 23 #include <list> | |
| 24 #include <map> | |
| 25 #include <set> | |
| 26 #include <string> | |
| 27 #include <vector> | |
| 28 | |
| 29 #include "llvm/ADT/BitVector.h" | |
| 30 #include "llvm/ADT/SmallBitVector.h" | |
| 31 #include "llvm/Support/Casting.h" | |
| 32 #include "llvm/Support/raw_ostream.h" | |
| 33 #include "llvm/Support/Timer.h" | |
| 34 | |
| 35 namespace Ice { | |
| 36 | |
| 37 class CfgNode; | |
| 38 class Constant; | |
| 39 class GlobalContext; | |
| 40 class IceCfg; | |
|
JF
2014/04/23 03:51:28
Why not shed the Ice (or melt?) for Cfg and the ot
Jim Stichnoth
2014/04/26 15:02:11
Done. Except I'd prefer to keep IceString, since
| |
| 41 class Inst; | |
| 42 class InstPhi; | |
| 43 class InstTarget; | |
| 44 class Operand; | |
| 45 class Variable; | |
| 46 | |
| 47 // TODO: Switch over to LLVM's ADT container classes. | |
| 48 // http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure- for-a-task | |
| 49 typedef std::string IceString; | |
| 50 typedef std::list<Inst *> InstList; | |
| 51 typedef std::list<InstPhi *> PhiList; | |
| 52 typedef std::vector<Variable *> VarList; | |
| 53 typedef std::vector<CfgNode *> NodeList; | |
| 54 | |
| 55 // IceSize_t is for holding small-ish limits like number of source | |
| 56 // operands in an instruction. It is used instead of size_t (which | |
| 57 // may be 64-bits wide) when we want to save space. | |
| 58 typedef uint32_t IceSize_t; | |
|
JF
2014/04/23 03:51:28
Names ending in _t are reserved by POSIX. Why not
Jim Stichnoth
2014/04/26 15:02:11
Can we compromise on SizeT? :)
| |
| 59 | |
| 60 // This is a convenience templated class that provides a mapping | |
| 61 // between a parameterized type and small unsigned integers. | |
| 62 template <typename T, typename Cmp = std::less<T> > class ValueTranslation { | |
|
JF
2014/04/23 03:51:28
You need to #include <functional> to use std::less
Jim Stichnoth
2014/04/26 15:02:11
Done.
| |
| 63 public: | |
| 64 typedef typename std::map<const T, IceSize_t, Cmp> ContainerType; | |
|
JF
2014/04/23 03:51:28
Just to restore my template sanity, could you use
Jim Stichnoth
2014/04/26 15:02:11
Done (sort of). Sadly, static_assert and is_float
| |
| 65 ValueTranslation() {} | |
| 66 void clear() { Entries.clear(); } | |
| 67 IceSize_t translate(const T &Value) { | |
| 68 typename ContainerType::const_iterator Iter = Entries.find(Value); | |
| 69 if (Iter != Entries.end()) | |
| 70 return Iter->second; | |
| 71 IceSize_t Index = Entries.size(); | |
| 72 Entries[Value] = Index; | |
| 73 return Index; | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 ContainerType Entries; | |
| 78 ValueTranslation(const ValueTranslation &) LLVM_DELETED_FUNCTION; | |
| 79 ValueTranslation &operator=(const ValueTranslation &) LLVM_DELETED_FUNCTION; | |
| 80 }; | |
| 81 | |
| 82 enum IceVerbose { | |
| 83 IceV_None = 0, | |
| 84 IceV_Instructions = 1 << 0, | |
| 85 IceV_Deleted = 1 << 1, | |
| 86 IceV_InstNumbers = 1 << 2, | |
| 87 IceV_Preds = 1 << 3, | |
| 88 IceV_Succs = 1 << 4, | |
| 89 IceV_Liveness = 1 << 5, | |
| 90 IceV_RegManager = 1 << 6, | |
| 91 IceV_RegOrigins = 1 << 7, | |
| 92 IceV_LinearScan = 1 << 8, | |
| 93 IceV_Frame = 1 << 9, | |
| 94 IceV_Timing = 1 << 10, | |
| 95 IceV_All = ~IceV_None | |
| 96 }; | |
| 97 typedef uint32_t IceVerboseMask; | |
| 98 | |
| 99 // The IceOstream class wraps an output stream and an IceCfg pointer, | |
| 100 // so that dump routines have access to the IceCfg object and can | |
| 101 // print labels and variable names. | |
| 102 | |
| 103 class IceOstream { | |
| 104 public: | |
| 105 IceOstream(llvm::raw_ostream *Stream) : Stream(Stream) {} | |
| 106 | |
| 107 llvm::raw_ostream *Stream; | |
| 108 | |
| 109 private: | |
| 110 IceOstream(const IceOstream &) LLVM_DELETED_FUNCTION; | |
| 111 IceOstream &operator=(const IceOstream &) LLVM_DELETED_FUNCTION; | |
| 112 }; | |
| 113 | |
| 114 template <typename T> | |
| 115 inline IceOstream &operator<<(IceOstream &Str, const T &Val) { | |
| 116 if (Str.Stream) | |
| 117 (*Str.Stream) << Val; | |
| 118 return Str; | |
| 119 } | |
| 120 | |
| 121 // TODO: Implement in terms of std::chrono after switching to C++11. | |
| 122 class IceTimer { | |
| 123 public: | |
| 124 IceTimer() : Start(llvm::TimeRecord::getCurrentTime(false)) {} | |
| 125 uint64_t getElapsedNs() const { return getElapsedSec() * 1000 * 1000 * 1000; } | |
| 126 uint64_t getElapsedUs() const { return getElapsedSec() * 1000 * 1000; } | |
| 127 uint64_t getElapsedMs() const { return getElapsedSec() * 1000; } | |
| 128 double getElapsedSec() const { | |
| 129 llvm::TimeRecord End = llvm::TimeRecord::getCurrentTime(false); | |
| 130 return End.getWallTime() - Start.getWallTime(); | |
| 131 } | |
| 132 void printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const; | |
| 133 | |
| 134 private: | |
| 135 const llvm::TimeRecord Start; | |
| 136 IceTimer(const IceTimer &) LLVM_DELETED_FUNCTION; | |
| 137 IceTimer &operator=(const IceTimer &) LLVM_DELETED_FUNCTION; | |
| 138 }; | |
| 139 | |
| 140 } // end of namespace Ice | |
| 141 | |
| 142 #endif // SUBZERO_SRC_ICEDEFS_H | |
| OLD | NEW |