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

Unified Diff: src/IceGlobalContext.cpp

Issue 460233002: Subzero: Randomize immediates by constant blinding or pooling. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Formatting Created 6 years, 4 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 5f9b620121aac0e7185d26235a57c0d01174ba97..74350b6bbc97c29b4ff8bcc28ede3d0370d2ed0a 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -25,6 +25,22 @@
namespace Ice {
+namespace {
+
+template <class MapTy, class ListTy>
+ListTy makeListOfValues(const MapTy &Pool) {
+ ListTy Values;
+ Values.reserve(Pool.size());
+ // TODO: replace the loop with std::transform + lambdas.
+ for (typename MapTy::const_iterator I = Pool.begin(), E = Pool.end();
+ I != E; ++I) {
+ Values.push_back(I->second);
+ }
+ return Values;
+}
+
+} // end anonymous namespace
Jim Stichnoth 2014/08/13 23:30:25 "end of anonymous namespace" has more votes. :)
wala 2014/08/16 00:07:12 Done.
+
// TypePool maps constants of type KeyType (e.g. float) to pointers to
// type ValueType (e.g. ConstantFloat). KeyType values are compared
// using memcmp() because of potential NaN values in KeyType values.
@@ -49,15 +65,7 @@ public:
return Result;
}
ConstantList getConstantPool() const {
- ConstantList Constants;
- Constants.reserve(Pool.size());
- // TODO: replace the loop with std::transform + lambdas.
- for (typename ContainerType::const_iterator I = Pool.begin(),
- E = Pool.end();
- I != E; ++I) {
- Constants.push_back(I->second);
- }
- return Constants;
+ return makeListOfValues<ContainerType, ConstantList>(Pool);
}
private:
@@ -76,6 +84,26 @@ private:
uint32_t NextPoolID;
};
+// ImmediatePool maps strings to immediates, which can be constants of
+// any type.
Jim Stichnoth 2014/08/13 23:30:25 Can you clarify in the comment that the string is
wala 2014/08/16 00:07:12 I don't know exactly what you mean, but I've clari
+class ImmediatePool {
+ ImmediatePool(const ImmediatePool &) LLVM_DELETED_FUNCTION;
+ ImmediatePool &operator=(const ImmediatePool &) LLVM_DELETED_FUNCTION;
+public:
+ ImmediatePool() {}
+
+ void add(IceString Name, Constant *Value) {
+ Pool[Name] = Value;
+ }
+ ConstantList getConstantPool() const {
+ return makeListOfValues<ContainerType, ConstantList>(Pool);
+ }
+
+private:
+ typedef std::map<IceString, Constant *> ContainerType;
+ ContainerType Pool;
+};
+
// UndefPool maps ICE types to the corresponding ConstantUndef values.
class UndefPool {
UndefPool(const UndefPool &) LLVM_DELETED_FUNCTION;
@@ -111,6 +139,7 @@ public:
TypePool<double, ConstantDouble, true> Doubles;
TypePool<uint64_t, ConstantInteger> Integers;
TypePool<RelocatableTuple, ConstantRelocatable> Relocatables;
+ ImmediatePool Immediates;
UndefPool Undefs;
};
@@ -343,6 +372,11 @@ Constant *GlobalContext::getConstantZero(Type Ty) {
llvm_unreachable("Unknown type");
}
+void GlobalContext::addConstantPooledImmediate(IceString Name,
+ Constant *Immediate) {
+ ConstPool->Immediates.add(Name, Immediate);
+}
+
ConstantList GlobalContext::getConstantPool(Type Ty) const {
switch (Ty) {
case IceType_i1:
@@ -374,6 +408,10 @@ ConstantList GlobalContext::getConstantPool(Type Ty) const {
llvm_unreachable("Unknown type");
}
+ConstantList GlobalContext::getImmediatePool() const {
+ return ConstPool->Immediates.getConstantPool();
+}
+
void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const {
if (Ctx->isVerbose(IceV_Timing)) {
// Prefixing with '#' allows timing strings to be included

Powered by Google App Engine
This is Rietveld 408576698