aboutsummaryrefslogtreecommitdiff
path: root/lib/Bitcode/NaCl/Writer
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-09-06 14:56:16 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-09-06 14:56:16 -0700
commit68cb3f7eca7536d85301f92314dbb5db6757cd94 (patch)
tree85cfa713f9f2304e419a744eaa11fd5f519034d9 /lib/Bitcode/NaCl/Writer
parent45f9be95ab8e334e7e4b4328ee297d032e64b788 (diff)
PNaCl bitcode: Strip pointer types from intrinsic declarations' parameters
Change the writer to strip pointer types from intrinsics' argument and return types, replacing them with i32. This simplifies the PNaCl bitcode format so that pointer types don't need to be represented here. Change the reader to restore the pointer types so that the intrinsic declarations pass the LLVM and PNaCl verifiers. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3671 TEST=intrinsic tests in call-elide.ll + intrinsic-pointer-args.ll + run small_tests with bitcode v2 enabled Review URL: https://codereview.chromium.org/23793005
Diffstat (limited to 'lib/Bitcode/NaCl/Writer')
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp20
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h5
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
index 64d7661415..42f78baa2a 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
@@ -298,7 +298,27 @@ void NaClValueEnumerator::EnumerateValue(const Value *VIn) {
}
+Type *NaClValueEnumerator::NormalizeParamType(Type *Ty) const {
+ // Strip pointer types.
+ if (Ty->isPointerTy() && PNaClVersion >= 2)
+ Ty = IntPtrType;
+ return Ty;
+}
+
+Type *NaClValueEnumerator::NormalizeType(Type *Ty) const {
+ if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
+ SmallVector<Type *, 8> ArgTypes;
+ for (unsigned I = 0, E = FTy->getNumParams(); I < E; ++I)
+ ArgTypes.push_back(NormalizeParamType(FTy->getParamType(I)));
+ Ty = FunctionType::get(NormalizeParamType(FTy->getReturnType()),
+ ArgTypes, false);
+ }
+ return Ty;
+}
+
void NaClValueEnumerator::EnumerateType(Type *Ty, bool InsideOptimizeTypes) {
+ Ty = NormalizeType(Ty);
+
// The label type does not need to be given a type ID.
if (Ty->isLabelTy())
return;
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
index 71638dd4eb..5f25039e30 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
@@ -106,7 +106,7 @@ public:
unsigned getValueID(const Value *V) const;
unsigned getTypeID(Type *T) const {
- TypeMapType::const_iterator I = TypeMap.find(T);
+ TypeMapType::const_iterator I = TypeMap.find(NormalizeType(T));
assert(I != TypeMap.end() && "Type not in NaClValueEnumerator!");
return I->second-1;
}
@@ -158,6 +158,9 @@ private:
void OptimizeTypes(const Module *M);
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
+ Type *NormalizeParamType(Type *Ty) const;
+ Type *NormalizeType(Type *Ty) const;
+
void EnumerateValue(const Value *V);
void EnumerateType(Type *T, bool InsideOptimizeTypes=false);
void EnumerateOperandType(const Value *V);