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

Unified Diff: src/IceGlobalContext.h

Issue 1775253003: Cache common constants before lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Make RuntimeHelper an enum class. 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
« no previous file with comments | « no previous file | src/IceGlobalContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceGlobalContext.h
diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
index f01ac856eecb5284f3fcff9eac5f55b0e6351e60..164543ab65ef912fcce9095f6a2c48f3eba306f1 100644
--- a/src/IceGlobalContext.h
+++ b/src/IceGlobalContext.h
@@ -21,12 +21,14 @@
#include "IceIntrinsics.h"
#include "IceRNG.h"
#include "IceSwitchLowering.h"
+#include "IceTargetLowering.def"
#include "IceThreading.h"
#include "IceTimerTree.h"
#include "IceTypes.h"
#include "IceUtils.h"
#include <array>
+#include <cassert>
#include <functional>
#include <memory>
#include <mutex>
@@ -42,6 +44,15 @@ class ConstantPool;
class EmitterWorkItem;
class FuncSigType;
+// Runtime helper function IDs
+
+enum class RuntimeHelper {
+#define X(Tag, Name) H_##Tag,
+ RUNTIME_HELPER_FUNCTIONS_TABLE
+#undef X
+ H_Num
+};
+
/// LockedPtr is a way to provide automatically locked access to some object.
template <typename T> class LockedPtr {
LockedPtr() = delete;
@@ -189,11 +200,50 @@ public:
// getConstant*() functions are not const because they might add something to
// the constant pool.
Constant *getConstantInt(Type Ty, int64_t Value);
- Constant *getConstantInt1(int8_t ConstantInt1);
- Constant *getConstantInt8(int8_t ConstantInt8);
- Constant *getConstantInt16(int16_t ConstantInt16);
- Constant *getConstantInt32(int32_t ConstantInt32);
- Constant *getConstantInt64(int64_t ConstantInt64);
+ Constant *getConstantInt1(int8_t ConstantInt1) {
+ ConstantInt1 &= INT8_C(1);
+ switch (ConstantInt1) {
+ case 0:
+ return getConstantZero(IceType_i1);
+ case 1:
+ return ConstantTrue;
+ default:
+ assert(false && "getConstantInt1 not on true/false");
+ return getConstantInt1Internal(ConstantInt1);
+ }
+ }
+ Constant *getConstantInt8(int8_t ConstantInt8) {
+ switch (ConstantInt8) {
+ case 0:
+ return getConstantZero(IceType_i8);
+ default:
+ return getConstantInt8Internal(ConstantInt8);
+ }
+ }
+ Constant *getConstantInt16(int16_t ConstantInt16) {
+ switch (ConstantInt16) {
+ case 0:
+ return getConstantZero(IceType_i16);
+ default:
+ return getConstantInt16Internal(ConstantInt16);
+ }
+ }
+ Constant *getConstantInt32(int32_t ConstantInt32) {
+ switch (ConstantInt32) {
+ case 0:
+ return getConstantZero(IceType_i32);
+ default:
+ return getConstantInt32Internal(ConstantInt32);
+ }
+ }
+ Constant *getConstantInt64(int64_t ConstantInt64) {
+ switch (ConstantInt64) {
+ case 0:
+ return getConstantZero(IceType_i64);
+ default:
+ return getConstantInt64Internal(ConstantInt64);
+ }
+ }
Constant *getConstantFloat(float Value);
Constant *getConstantDouble(double Value);
/// Returns a symbolic constant.
@@ -212,6 +262,12 @@ public:
/// Returns a copy of the list of external symbols.
ConstantList getConstantExternSyms();
/// @}
+ Constant *getRuntimeHelperFunc(RuntimeHelper FuncID) const {
+ assert(FuncID < RuntimeHelper::H_Num);
+ 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
+ assert(Result != nullptr && "No such runtime helper function");
+ return Result;
+ }
/// Return a locked pointer to the registered jump tables.
JumpTableDataList getJumpTables();
@@ -524,7 +580,18 @@ private:
/// Indicates if global variable declarations can be disposed of right after
/// lowering.
bool DisposeGlobalVariablesAfterLowering = true;
-
+ Constant *ConstZeroForType[IceType_NUM];
+ Constant *ConstantTrue;
+ // Holds the constants representing each runtime helper function.
+ Constant *RuntimeHelperFunc[static_cast<size_t>(RuntimeHelper::H_Num)];
+
+ Constant *getConstantZeroInternal(Type Ty);
+ Constant *getConstantIntInternal(Type Ty, int64_t Value);
+ Constant *getConstantInt1Internal(int8_t ConstantInt1);
+ Constant *getConstantInt8Internal(int8_t ConstantInt8);
+ Constant *getConstantInt16Internal(int16_t ConstantInt16);
+ Constant *getConstantInt32Internal(int32_t ConstantInt32);
+ Constant *getConstantInt64Internal(int64_t ConstantInt64);
LockedPtr<ArenaAllocator> getAllocator() {
return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock);
}
« no previous file with comments | « no previous file | src/IceGlobalContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698