OLD | NEW |
1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file declares aspects of the compilation that persist across | 10 // This file declares aspects of the compilation that persist across |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 #include "IceDefs.h" | 22 #include "IceDefs.h" |
23 #include "IceIntrinsics.h" | 23 #include "IceIntrinsics.h" |
24 #include "IceRNG.h" | 24 #include "IceRNG.h" |
25 #include "IceTypes.h" | 25 #include "IceTypes.h" |
26 | 26 |
27 namespace Ice { | 27 namespace Ice { |
28 | 28 |
29 class ClFlags; | 29 class ClFlags; |
30 | 30 |
| 31 // This class collects rudimentary statistics during translation. |
| 32 class CodeStats { |
| 33 public: |
| 34 CodeStats() |
| 35 : InstructionsEmitted(0), RegistersSaved(0), FrameBytes(0), Spills(0), |
| 36 Fills(0) {} |
| 37 void reset() { *this = CodeStats(); } |
| 38 void updateEmitted(uint32_t InstCount) { InstructionsEmitted += InstCount; } |
| 39 void updateRegistersSaved(uint32_t Num) { RegistersSaved += Num; } |
| 40 void updateFrameBytes(uint32_t Bytes) { FrameBytes += Bytes; } |
| 41 void updateSpills() { ++Spills; } |
| 42 void updateFills() { ++Fills; } |
| 43 void dump(const IceString &Name, Ostream &Str) { |
| 44 Str << "|" << Name << "|Inst Count |" << InstructionsEmitted << "\n"; |
| 45 Str << "|" << Name << "|Regs Saved |" << RegistersSaved << "\n"; |
| 46 Str << "|" << Name << "|Frame Bytes |" << FrameBytes << "\n"; |
| 47 Str << "|" << Name << "|Spills |" << Spills << "\n"; |
| 48 Str << "|" << Name << "|Fills |" << Fills << "\n"; |
| 49 Str << "|" << Name << "|Spills+Fills|" << Spills + Fills << "\n"; |
| 50 } |
| 51 |
| 52 private: |
| 53 uint32_t InstructionsEmitted; |
| 54 uint32_t RegistersSaved; |
| 55 uint32_t FrameBytes; |
| 56 uint32_t Spills; |
| 57 uint32_t Fills; |
| 58 }; |
| 59 |
31 // TODO: Accesses to all non-const fields of GlobalContext need to | 60 // TODO: Accesses to all non-const fields of GlobalContext need to |
32 // be synchronized, especially the constant pool, the allocator, and | 61 // be synchronized, especially the constant pool, the allocator, and |
33 // the output streams. | 62 // the output streams. |
34 class GlobalContext { | 63 class GlobalContext { |
35 public: | 64 public: |
36 GlobalContext(llvm::raw_ostream *OsDump, llvm::raw_ostream *OsEmit, | 65 GlobalContext(llvm::raw_ostream *OsDump, llvm::raw_ostream *OsEmit, |
37 VerboseMask Mask, TargetArch Arch, OptLevel Opt, | 66 VerboseMask Mask, TargetArch Arch, OptLevel Opt, |
38 IceString TestPrefix, const ClFlags &Flags); | 67 IceString TestPrefix, const ClFlags &Flags); |
39 ~GlobalContext(); | 68 ~GlobalContext(); |
40 | 69 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 122 |
94 // Allocate data of type T using the global allocator. | 123 // Allocate data of type T using the global allocator. |
95 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } | 124 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } |
96 | 125 |
97 const Intrinsics &getIntrinsicsInfo() const { return IntrinsicsInfo; } | 126 const Intrinsics &getIntrinsicsInfo() const { return IntrinsicsInfo; } |
98 | 127 |
99 // TODO(wala,stichnot): Make the RNG play nicely with multithreaded | 128 // TODO(wala,stichnot): Make the RNG play nicely with multithreaded |
100 // translation. | 129 // translation. |
101 RandomNumberGenerator &getRNG() { return RNG; } | 130 RandomNumberGenerator &getRNG() { return RNG; } |
102 | 131 |
| 132 // Reset stats at the beginning of a function. |
| 133 void resetStats() { StatsFunction.reset(); } |
| 134 void dumpStats(const IceString &Name); |
| 135 void statsUpdateEmitted(uint32_t InstCount) { |
| 136 StatsFunction.updateEmitted(InstCount); |
| 137 StatsCumulative.updateEmitted(InstCount); |
| 138 } |
| 139 void statsUpdateRegistersSaved(uint32_t Num) { |
| 140 StatsFunction.updateRegistersSaved(Num); |
| 141 StatsCumulative.updateRegistersSaved(Num); |
| 142 } |
| 143 void statsUpdateFrameBytes(uint32_t Bytes) { |
| 144 StatsFunction.updateFrameBytes(Bytes); |
| 145 StatsCumulative.updateFrameBytes(Bytes); |
| 146 } |
| 147 void statsUpdateSpills() { |
| 148 StatsFunction.updateSpills(); |
| 149 StatsCumulative.updateSpills(); |
| 150 } |
| 151 void statsUpdateFills() { |
| 152 StatsFunction.updateFills(); |
| 153 StatsCumulative.updateFills(); |
| 154 } |
| 155 |
103 private: | 156 private: |
104 Ostream *StrDump; // Stream for dumping / diagnostics | 157 Ostream *StrDump; // Stream for dumping / diagnostics |
105 Ostream *StrEmit; // Stream for code emission | 158 Ostream *StrEmit; // Stream for code emission |
106 | 159 |
107 llvm::BumpPtrAllocator Allocator; | 160 llvm::BumpPtrAllocator Allocator; |
108 VerboseMask VMask; | 161 VerboseMask VMask; |
109 llvm::OwningPtr<class ConstantPool> ConstPool; | 162 llvm::OwningPtr<class ConstantPool> ConstPool; |
110 Intrinsics IntrinsicsInfo; | 163 Intrinsics IntrinsicsInfo; |
111 const TargetArch Arch; | 164 const TargetArch Arch; |
112 const OptLevel Opt; | 165 const OptLevel Opt; |
113 const IceString TestPrefix; | 166 const IceString TestPrefix; |
114 const ClFlags &Flags; | 167 const ClFlags &Flags; |
115 bool HasEmittedFirstMethod; | 168 bool HasEmittedFirstMethod; |
116 RandomNumberGenerator RNG; | 169 RandomNumberGenerator RNG; |
| 170 CodeStats StatsFunction; |
| 171 CodeStats StatsCumulative; |
117 GlobalContext(const GlobalContext &) LLVM_DELETED_FUNCTION; | 172 GlobalContext(const GlobalContext &) LLVM_DELETED_FUNCTION; |
118 GlobalContext &operator=(const GlobalContext &) LLVM_DELETED_FUNCTION; | 173 GlobalContext &operator=(const GlobalContext &) LLVM_DELETED_FUNCTION; |
119 | 174 |
120 // Private helpers for mangleName() | 175 // Private helpers for mangleName() |
121 typedef llvm::SmallVector<char, 32> ManglerVector; | 176 typedef llvm::SmallVector<char, 32> ManglerVector; |
122 void incrementSubstitutions(ManglerVector &OldName) const; | 177 void incrementSubstitutions(ManglerVector &OldName) const; |
123 }; | 178 }; |
124 | 179 |
125 } // end of namespace Ice | 180 } // end of namespace Ice |
126 | 181 |
127 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 182 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
OLD | NEW |