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 /// \file | 10 /// \file |
11 /// \brief Declares aspects of the compilation that persist across multiple | 11 /// \brief Declares aspects of the compilation that persist across multiple |
12 /// functions. | 12 /// functions. |
13 /// | 13 /// |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef SUBZERO_SRC_ICEGLOBALCONTEXT_H | 16 #ifndef SUBZERO_SRC_ICEGLOBALCONTEXT_H |
17 #define SUBZERO_SRC_ICEGLOBALCONTEXT_H | 17 #define SUBZERO_SRC_ICEGLOBALCONTEXT_H |
18 | 18 |
19 #include "IceDefs.h" | 19 #include "IceDefs.h" |
20 #include "IceClFlags.h" | 20 #include "IceClFlags.h" |
21 #include "IceIntrinsics.h" | 21 #include "IceIntrinsics.h" |
22 #include "IceRNG.h" | 22 #include "IceRNG.h" |
23 #include "IceSwitchLowering.h" | 23 #include "IceSwitchLowering.h" |
24 #include "IceTargetLowering.def" | |
24 #include "IceThreading.h" | 25 #include "IceThreading.h" |
25 #include "IceTimerTree.h" | 26 #include "IceTimerTree.h" |
26 #include "IceTypes.h" | 27 #include "IceTypes.h" |
27 #include "IceUtils.h" | 28 #include "IceUtils.h" |
28 | 29 |
29 #include <array> | 30 #include <array> |
31 #include <cassert> | |
30 #include <functional> | 32 #include <functional> |
31 #include <memory> | 33 #include <memory> |
32 #include <mutex> | 34 #include <mutex> |
33 #include <thread> | 35 #include <thread> |
34 #include <type_traits> | 36 #include <type_traits> |
35 #include <utility> | 37 #include <utility> |
36 #include <vector> | 38 #include <vector> |
37 | 39 |
38 namespace Ice { | 40 namespace Ice { |
39 | 41 |
40 class ClFlags; | 42 class ClFlags; |
41 class ConstantPool; | 43 class ConstantPool; |
42 class EmitterWorkItem; | 44 class EmitterWorkItem; |
43 class FuncSigType; | 45 class FuncSigType; |
44 | 46 |
47 // Runtime helper function IDs | |
48 | |
49 enum class RuntimeHelper { | |
50 #define X(Tag, Name) H_##Tag, | |
51 RUNTIME_HELPER_FUNCTIONS_TABLE | |
52 #undef X | |
53 H_Num | |
54 }; | |
55 | |
45 /// LockedPtr is a way to provide automatically locked access to some object. | 56 /// LockedPtr is a way to provide automatically locked access to some object. |
46 template <typename T> class LockedPtr { | 57 template <typename T> class LockedPtr { |
47 LockedPtr() = delete; | 58 LockedPtr() = delete; |
48 LockedPtr(const LockedPtr &) = delete; | 59 LockedPtr(const LockedPtr &) = delete; |
49 LockedPtr &operator=(const LockedPtr &) = delete; | 60 LockedPtr &operator=(const LockedPtr &) = delete; |
50 | 61 |
51 public: | 62 public: |
52 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { | 63 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { |
53 Lock->lock(); | 64 Lock->lock(); |
54 } | 65 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 193 |
183 LockedPtr<ErrorCode> getErrorStatus() { | 194 LockedPtr<ErrorCode> getErrorStatus() { |
184 return LockedPtr<ErrorCode>(&ErrorStatus, &ErrorStatusLock); | 195 return LockedPtr<ErrorCode>(&ErrorStatus, &ErrorStatusLock); |
185 } | 196 } |
186 | 197 |
187 /// \name Manage Constants. | 198 /// \name Manage Constants. |
188 /// @{ | 199 /// @{ |
189 // getConstant*() functions are not const because they might add something to | 200 // getConstant*() functions are not const because they might add something to |
190 // the constant pool. | 201 // the constant pool. |
191 Constant *getConstantInt(Type Ty, int64_t Value); | 202 Constant *getConstantInt(Type Ty, int64_t Value); |
192 Constant *getConstantInt1(int8_t ConstantInt1); | 203 Constant *getConstantInt1(int8_t ConstantInt1) { |
193 Constant *getConstantInt8(int8_t ConstantInt8); | 204 ConstantInt1 &= INT8_C(1); |
194 Constant *getConstantInt16(int16_t ConstantInt16); | 205 switch (ConstantInt1) { |
195 Constant *getConstantInt32(int32_t ConstantInt32); | 206 case 0: |
196 Constant *getConstantInt64(int64_t ConstantInt64); | 207 return getConstantZero(IceType_i1); |
208 case 1: | |
209 return ConstantTrue; | |
210 default: | |
211 assert(false && "getConstantInt1 not on true/false"); | |
212 return getConstantInt1Internal(ConstantInt1); | |
213 } | |
214 } | |
215 Constant *getConstantInt8(int8_t ConstantInt8) { | |
216 switch (ConstantInt8) { | |
217 case 0: | |
218 return getConstantZero(IceType_i8); | |
219 default: | |
220 return getConstantInt8Internal(ConstantInt8); | |
221 } | |
222 } | |
223 Constant *getConstantInt16(int16_t ConstantInt16) { | |
224 switch (ConstantInt16) { | |
225 case 0: | |
226 return getConstantZero(IceType_i16); | |
227 default: | |
228 return getConstantInt16Internal(ConstantInt16); | |
229 } | |
230 } | |
231 Constant *getConstantInt32(int32_t ConstantInt32) { | |
232 switch (ConstantInt32) { | |
233 case 0: | |
234 return getConstantZero(IceType_i32); | |
235 default: | |
236 return getConstantInt32Internal(ConstantInt32); | |
237 } | |
238 } | |
239 Constant *getConstantInt64(int64_t ConstantInt64) { | |
240 switch (ConstantInt64) { | |
241 case 0: | |
242 return getConstantZero(IceType_i64); | |
243 default: | |
244 return getConstantInt64Internal(ConstantInt64); | |
245 } | |
246 } | |
197 Constant *getConstantFloat(float Value); | 247 Constant *getConstantFloat(float Value); |
198 Constant *getConstantDouble(double Value); | 248 Constant *getConstantDouble(double Value); |
199 /// Returns a symbolic constant. | 249 /// Returns a symbolic constant. |
200 Constant *getConstantSym(const RelocOffsetT Offset, | 250 Constant *getConstantSym(const RelocOffsetT Offset, |
201 const RelocOffsetArray &OffsetExpr, | 251 const RelocOffsetArray &OffsetExpr, |
202 const IceString &Name, const IceString &EmitString); | 252 const IceString &Name, const IceString &EmitString); |
203 Constant *getConstantSym(RelocOffsetT Offset, const IceString &Name); | 253 Constant *getConstantSym(RelocOffsetT Offset, const IceString &Name); |
204 Constant *getConstantExternSym(const IceString &Name); | 254 Constant *getConstantExternSym(const IceString &Name); |
205 /// Returns an undef. | 255 /// Returns an undef. |
206 Constant *getConstantUndef(Type Ty); | 256 Constant *getConstantUndef(Type Ty); |
207 /// Returns a zero value. | 257 /// Returns a zero value. |
208 Constant *getConstantZero(Type Ty); | 258 Constant *getConstantZero(Type Ty); |
209 /// getConstantPool() returns a copy of the constant pool for constants of a | 259 /// getConstantPool() returns a copy of the constant pool for constants of a |
210 /// given type. | 260 /// given type. |
211 ConstantList getConstantPool(Type Ty); | 261 ConstantList getConstantPool(Type Ty); |
212 /// Returns a copy of the list of external symbols. | 262 /// Returns a copy of the list of external symbols. |
213 ConstantList getConstantExternSyms(); | 263 ConstantList getConstantExternSyms(); |
214 /// @} | 264 /// @} |
265 Constant *getRuntimeHelperFunc(RuntimeHelper FuncID) const { | |
266 assert(FuncID < RuntimeHelper::H_Num); | |
267 Constant *Result = RuntimeHelperFunc[static_cast<size_t>(FuncID)]; | |
Jim Stichnoth
2016/03/17 20:12:22
Can you can use the enum value directly without th
John
2016/03/17 20:22:57
yup, he needs the cast -- class enums are just lik
| |
268 assert(Result != nullptr && "No such runtime helper function"); | |
269 return Result; | |
270 } | |
215 | 271 |
216 /// Return a locked pointer to the registered jump tables. | 272 /// Return a locked pointer to the registered jump tables. |
217 JumpTableDataList getJumpTables(); | 273 JumpTableDataList getJumpTables(); |
218 /// Create a new jump table entry and return a reference to it. | 274 /// Create a new jump table entry and return a reference to it. |
219 JumpTableData &addJumpTable(const IceString &FuncName, SizeT Id, | 275 JumpTableData &addJumpTable(const IceString &FuncName, SizeT Id, |
220 const JumpTableData::TargetList &TargetList); | 276 const JumpTableData::TargetList &TargetList); |
221 | 277 |
222 static const ClFlags &getFlags() { return Flags; } | 278 static const ClFlags &getFlags() { return Flags; } |
223 | 279 |
224 /// Allocate data of type T using the global allocator. We allow entities | 280 /// Allocate data of type T using the global allocator. We allow entities |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" | 573 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" |
518 /// program global variables) until the first code WorkItem is seen. | 574 /// program global variables) until the first code WorkItem is seen. |
519 // TODO(jpp): move to EmitterContext. | 575 // TODO(jpp): move to EmitterContext. |
520 bool HasSeenCode = false; | 576 bool HasSeenCode = false; |
521 // TODO(jpp): move to EmitterContext. | 577 // TODO(jpp): move to EmitterContext. |
522 VariableDeclaration *ProfileBlockInfoVarDecl = nullptr; | 578 VariableDeclaration *ProfileBlockInfoVarDecl = nullptr; |
523 std::vector<VariableDeclaration *> ProfileBlockInfos; | 579 std::vector<VariableDeclaration *> ProfileBlockInfos; |
524 /// Indicates if global variable declarations can be disposed of right after | 580 /// Indicates if global variable declarations can be disposed of right after |
525 /// lowering. | 581 /// lowering. |
526 bool DisposeGlobalVariablesAfterLowering = true; | 582 bool DisposeGlobalVariablesAfterLowering = true; |
583 Constant *ConstZeroForType[IceType_NUM]; | |
584 Constant *ConstantTrue; | |
585 // Holds the constants representing each runtime helper function. | |
586 Constant *RuntimeHelperFunc[static_cast<size_t>(RuntimeHelper::H_Num)]; | |
527 | 587 |
588 Constant *getConstantZeroInternal(Type Ty); | |
589 Constant *getConstantIntInternal(Type Ty, int64_t Value); | |
590 Constant *getConstantInt1Internal(int8_t ConstantInt1); | |
591 Constant *getConstantInt8Internal(int8_t ConstantInt8); | |
592 Constant *getConstantInt16Internal(int16_t ConstantInt16); | |
593 Constant *getConstantInt32Internal(int32_t ConstantInt32); | |
594 Constant *getConstantInt64Internal(int64_t ConstantInt64); | |
528 LockedPtr<ArenaAllocator> getAllocator() { | 595 LockedPtr<ArenaAllocator> getAllocator() { |
529 return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock); | 596 return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock); |
530 } | 597 } |
531 LockedPtr<VariableDeclarationList> getInitializerAllocator() { | 598 LockedPtr<VariableDeclarationList> getInitializerAllocator() { |
532 return LockedPtr<VariableDeclarationList>(&Globals, &InitAllocLock); | 599 return LockedPtr<VariableDeclarationList>(&Globals, &InitAllocLock); |
533 } | 600 } |
534 LockedPtr<ConstantPool> getConstPool() { | 601 LockedPtr<ConstantPool> getConstPool() { |
535 return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock); | 602 return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock); |
536 } | 603 } |
537 LockedPtr<JumpTableDataList> getJumpTableList() { | 604 LockedPtr<JumpTableDataList> getJumpTableList() { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 698 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
632 ~OstreamLocker() { Ctx->unlockStr(); } | 699 ~OstreamLocker() { Ctx->unlockStr(); } |
633 | 700 |
634 private: | 701 private: |
635 GlobalContext *const Ctx; | 702 GlobalContext *const Ctx; |
636 }; | 703 }; |
637 | 704 |
638 } // end of namespace Ice | 705 } // end of namespace Ice |
639 | 706 |
640 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 707 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
OLD | NEW |