Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: src/IceGlobalContext.cpp

Issue 339783002: Add support for undef values in ICE IR. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Comment about uninitialized registers Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceOperand.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceGlobalContext.cpp
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index c3060c3b72d61719b8de3d553cdf45281df72600..7e89a41dad133960ff7cacc24735b61fc25f6e28 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,
@@ -192,6 +216,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:
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceOperand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698