aboutsummaryrefslogtreecommitdiff
path: root/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp')
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
index 7da01f005e..11e1161bf8 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
@@ -450,7 +450,7 @@ static bool AllowsNormalizedPtr(const Value *V, const Instruction *Arg) {
// Returns true if the bitcode reader and writer can assume that the
// uses of the given inttotpr I2P allow normalized pointers (as
// defined in llvm/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp).
-static bool IntToPtrUsesAllowEliding(const Instruction *I2P) {
+static bool AllUsesAllowNormalizedPtr(const Instruction *I2P) {
for (Value::const_use_iterator u = I2P->use_begin(), e = I2P->use_end();
u != e; ++u) {
if (!AllowsNormalizedPtr(cast<Value>(*u), I2P)) return false;
@@ -461,6 +461,12 @@ static bool IntToPtrUsesAllowEliding(const Instruction *I2P) {
return true;
}
+// Returns true if the value is an InherentPtr (as defined in
+// llvm/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp).
+static inline bool IsInherentPtr(const Value *V) {
+ return isa<AllocaInst>(V) || isa<GlobalValue>(V);
+}
+
// Note: This function is based on the comments in
// llvm/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp.
const Value *NaClValueEnumerator::ElideCasts(const Value *V) {
@@ -470,10 +476,18 @@ const Value *NaClValueEnumerator::ElideCasts(const Value *V) {
switch (I->getOpcode()) {
default:
break;
+ case Instruction::BitCast:
+ if (I->getType()->isPointerTy() &&
+ AllUsesAllowNormalizedPtr(I) &&
+ IsInherentPtr(I->getOperand(0))) {
+ return ElideCasts(I->getOperand(0));
+ }
+ break;
case Instruction::IntToPtr:
- if (IntToPtrUsesAllowEliding(I)) {
+ if (AllUsesAllowNormalizedPtr(I)) {
return ElideCasts(I->getOperand(0));
}
+ break;
}
}
return V;