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

Unified Diff: src/IceGlobalContext.cpp

Issue 1775253003: Cache common constants before lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 4 years, 9 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
Index: src/IceGlobalContext.cpp
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index 505ce497b2514090cecacf7dd14597d2caf07c3c..a29d932c35be3a94deb57f70589cd4c366f13f33 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -25,6 +25,7 @@
#include "IceOperand.h"
#include "IceTargetLowering.h"
#include "IceTimerTree.h"
+#include "IceTypes.def"
#include "IceTypes.h"
#ifdef __clang__
@@ -291,6 +292,18 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
case FT_Iasm:
break;
}
+// Cache up front common constants.
+#define X(tag, sizeLog2, align, elts, elty, str, rcstr) \
+ ConstZeroForType[IceType_##tag] = installConstantZero(IceType_##tag);
+ ICETYPE_TABLE;
+#undef X
+ ConstantTrue = installConstantInt1(1);
+ // Define runtime helper functions.
+ {
Jim Stichnoth 2016/03/17 00:14:52 Is this set of braces necessary?
Karl 2016/03/17 16:40:53 Removed.
+#define X(Tag, Name) RuntimeHelperFunc[H_##Tag] = getConstantExternSym(Name);
+ RUNTIME_HELPER_FUNCTIONS_TABLE
+#undef X
+ }
TargetLowering::staticInit(this);
}
@@ -657,24 +670,24 @@ Constant *GlobalContext::getConstantInt(Type Ty, int64_t Value) {
return nullptr;
}
-Constant *GlobalContext::getConstantInt1(int8_t ConstantInt1) {
+Constant *GlobalContext::installConstantInt1(int8_t ConstantInt1) {
Jim Stichnoth 2016/03/17 00:14:52 Bikeshed time. I kinda don't like the "install" p
Karl 2016/03/17 16:40:53 Done.
ConstantInt1 &= INT8_C(1);
return getConstPool()->Integers1.getOrAdd(this, ConstantInt1);
}
-Constant *GlobalContext::getConstantInt8(int8_t ConstantInt8) {
+Constant *GlobalContext::installConstantInt8(int8_t ConstantInt8) {
return getConstPool()->Integers8.getOrAdd(this, ConstantInt8);
}
-Constant *GlobalContext::getConstantInt16(int16_t ConstantInt16) {
+Constant *GlobalContext::installConstantInt16(int16_t ConstantInt16) {
return getConstPool()->Integers16.getOrAdd(this, ConstantInt16);
}
-Constant *GlobalContext::getConstantInt32(int32_t ConstantInt32) {
+Constant *GlobalContext::installConstantInt32(int32_t ConstantInt32) {
return getConstPool()->Integers32.getOrAdd(this, ConstantInt32);
}
-Constant *GlobalContext::getConstantInt64(int64_t ConstantInt64) {
+Constant *GlobalContext::installConstantInt64(int64_t ConstantInt64) {
return getConstPool()->Integers64.getOrAdd(this, ConstantInt64);
}
@@ -711,39 +724,32 @@ Constant *GlobalContext::getConstantUndef(Type Ty) {
}
// All locking is done by the getConstant*() target function.
-Constant *GlobalContext::getConstantZero(Type Ty) {
+Constant *GlobalContext::installConstantZero(Type Ty) {
switch (Ty) {
case IceType_i1:
- return getConstantInt1(0);
+ return installConstantInt1(0);
+ break;
Jim Stichnoth 2016/03/17 00:14:52 You don't need all these "break" statements after
Karl 2016/03/17 16:40:53 Done.
case IceType_i8:
- return getConstantInt8(0);
+ return installConstantInt8(0);
+ break;
case IceType_i16:
- return getConstantInt16(0);
+ return installConstantInt16(0);
+ break;
case IceType_i32:
- return getConstantInt32(0);
+ return installConstantInt32(0);
+ break;
case IceType_i64:
- return getConstantInt64(0);
+ return installConstantInt64(0);
+ break;
case IceType_f32:
return getConstantFloat(0);
+ break;
case IceType_f64:
return getConstantDouble(0);
- case IceType_v4i1:
- case IceType_v8i1:
- case IceType_v16i1:
- case IceType_v16i8:
- case IceType_v8i16:
- case IceType_v4i32:
- case IceType_v4f32: {
- IceString Str;
- llvm::raw_string_ostream BaseOS(Str);
- BaseOS << "Unsupported constant type: " << Ty;
- llvm_unreachable(BaseOS.str().c_str());
- } break;
- case IceType_void:
- case IceType_NUM:
break;
+ default:
+ return nullptr;
Jim Stichnoth 2016/03/17 00:14:52 I kind of like the previous behavior where it give
John 2016/03/17 14:31:33 I also like the previous behavior better, but I am
Karl 2016/03/17 16:40:53 Followed John's advice.
}
- llvm_unreachable("Unknown type");
}
ConstantList GlobalContext::getConstantPool(Type Ty) {

Powered by Google App Engine
This is Rietveld 408576698