| Index: src/IceGlobalContext.cpp
|
| diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
|
| index d77a5ddb554c4e1f3ec68232da712a6cc72152d3..97250783160027d6fe0d932fd6348955b884a58e 100644
|
| --- a/src/IceGlobalContext.cpp
|
| +++ b/src/IceGlobalContext.cpp
|
| @@ -74,6 +74,29 @@ private:
|
| uint32_t NextPoolID;
|
| };
|
|
|
| +// UndefPool maps ICE types to the corresponding ConstantUndef values.
|
| +class UndefPool {
|
| + UndefPool(const UndefPool &) LLVM_DELETED_FUNCTION;
|
| + UndefPool &operator=(const UndefPool &) LLVM_DELETED_FUNCTION;
|
| +
|
| +public:
|
| + UndefPool() : NextPoolID(0) {}
|
| +
|
| + ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) {
|
| + ContainerType::iterator I = Pool.find(Ty);
|
| + if (I != Pool.end())
|
| + return I->second;
|
| + ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++);
|
| + Pool[Ty] = Undef;
|
| + return Undef;
|
| + }
|
| +
|
| +private:
|
| + uint32_t NextPoolID;
|
| + typedef std::map<Type, ConstantUndef *> ContainerType;
|
| + ContainerType Pool;
|
| +};
|
| +
|
| // The global constant pool bundles individual pools of each type of
|
| // interest.
|
| class ConstantPool {
|
| @@ -86,6 +109,7 @@ public:
|
| TypePool<double, ConstantDouble, true> Doubles;
|
| TypePool<uint64_t, ConstantInteger> Integers;
|
| TypePool<RelocatableTuple, ConstantRelocatable> Relocatables;
|
| + UndefPool Undefs;
|
| };
|
|
|
| GlobalContext::GlobalContext(llvm::raw_ostream *OsDump,
|
| @@ -191,6 +215,29 @@ Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset,
|
| this, Ty, RelocatableTuple(Offset, Name, SuppressMangling));
|
| }
|
|
|
| +Constant *GlobalContext::getConstantUndef(Type Ty) {
|
| + return ConstPool->Undefs.getOrAdd(this, Ty);
|
| +}
|
| +
|
| +Constant *GlobalContext::getConstantZero(Type Ty) {
|
| + switch (Ty) {
|
| + case IceType_i1:
|
| + case IceType_i8:
|
| + case IceType_i16:
|
| + case IceType_i32:
|
| + case IceType_i64:
|
| + return getConstantInt(Ty, 0);
|
| + case IceType_f32:
|
| + return getConstantFloat(0);
|
| + case IceType_f64:
|
| + return getConstantDouble(0);
|
| + case IceType_void:
|
| + case IceType_NUM:
|
| + break;
|
| + }
|
| + llvm_unreachable("Unknown type");
|
| +}
|
| +
|
| ConstantList GlobalContext::getConstantPool(Type Ty) const {
|
| switch (Ty) {
|
| case IceType_i1:
|
|
|