aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-09-09 10:32:47 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-09-09 10:32:47 -0700
commitb63e4bfe73188f7d68065f5b274e169491e593d2 (patch)
treeac29183c92f4d361752d478435e6b31e68910ca4
parent1c0cea6c1fc807794f0d785392e05b19d0c70210 (diff)
PNaCl bitcode: Remove TYPE_CODE_POINTER entries from type table
There are now no uses of pointer type IDs in PNaCl bitcode, so we can stop outputting pointer types into the type table. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3671 TEST=test/NaCl/Bitcode/*.ll Review URL: https://codereview.chromium.org/23600013
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp4
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp22
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h4
-rw-r--r--test/NaCl/Bitcode/no-structs.ll27
-rw-r--r--test/NaCl/Bitcode/switch.ll24
5 files changed, 48 insertions, 33 deletions
diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
index 923d0b2c1e..cd4a894ef0 100644
--- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
@@ -227,6 +227,8 @@ static void WriteTypeTable(const NaClValueEnumerator &VE,
TypeVals.push_back(cast<IntegerType>(T)->getBitWidth());
break;
case Type::PointerTyID: {
+ if (PNaClVersion >= 2)
+ report_fatal_error("Pointer types are not supported in PNaCl bitcode");
PointerType *PTy = cast<PointerType>(T);
// POINTER: [pointee type, address space]
Code = naclbitc::TYPE_CODE_POINTER;
@@ -550,7 +552,7 @@ static void EmitFnForwardTypeRef(const Value *V,
VE.InsertFnForwardTypeRef(ValID)) {
SmallVector<unsigned, 2> Vals;
Vals.push_back(ValID);
- Vals.push_back(VE.getTypeID(VE.NormalizeScalarType(V->getType())));
+ Vals.push_back(VE.getTypeID(VE.NormalizeType(V->getType())));
Stream.EmitRecord(naclbitc::FUNC_CODE_INST_FORWARDTYPEREF, Vals,
FUNCTION_INST_FORWARDTYPEREF_ABBREV);
}
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
index cabdc420c6..f1ae2584e1 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
@@ -298,25 +298,27 @@ void NaClValueEnumerator::EnumerateValue(const Value *VIn) {
}
-Type *NaClValueEnumerator::NormalizeScalarType(Type *Ty) const {
- // Strip pointer types.
- if (Ty->isPointerTy() && PNaClVersion >= 2)
- Ty = IntPtrType;
- return Ty;
-}
-
Type *NaClValueEnumerator::NormalizeType(Type *Ty) const {
+ if (PNaClVersion == 1)
+ return Ty;
+
+ if (Ty->isPointerTy())
+ return IntPtrType;
if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
SmallVector<Type *, 8> ArgTypes;
for (unsigned I = 0, E = FTy->getNumParams(); I < E; ++I)
- ArgTypes.push_back(NormalizeScalarType(FTy->getParamType(I)));
- Ty = FunctionType::get(NormalizeScalarType(FTy->getReturnType()),
- ArgTypes, false);
+ ArgTypes.push_back(NormalizeType(FTy->getParamType(I)));
+ return FunctionType::get(NormalizeType(FTy->getReturnType()),
+ ArgTypes, false);
}
return Ty;
}
void NaClValueEnumerator::EnumerateType(Type *Ty, bool InsideOptimizeTypes) {
+ // Pointer types do not need to be given type IDs.
+ if (Ty->isPointerTy() && PNaClVersion >= 2)
+ Ty = Ty->getPointerElementType();
+
Ty = NormalizeType(Ty);
// The label type does not need to be given a type ID.
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
index e756beb2f2..cc43c7a1e2 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
@@ -154,14 +154,12 @@ public:
return T == IntPtrType;
}
- Type *NormalizeScalarType(Type *Ty) const;
+ Type *NormalizeType(Type *Ty) const;
private:
void OptimizeTypes(const Module *M);
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
- Type *NormalizeType(Type *Ty) const;
-
void EnumerateValue(const Value *V);
void EnumerateType(Type *T, bool InsideOptimizeTypes=false);
void EnumerateOperandType(const Value *V);
diff --git a/test/NaCl/Bitcode/no-structs.ll b/test/NaCl/Bitcode/no-structs.ll
index 1f9b1279fe..6ca17c0634 100644
--- a/test/NaCl/Bitcode/no-structs.ll
+++ b/test/NaCl/Bitcode/no-structs.ll
@@ -3,11 +3,11 @@
; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=1 \
; RUN: | pnacl-bcanalyzer -dump-records \
-; RUN: | FileCheck %s
+; RUN: | FileCheck %s -check-prefix=PF1
; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=2 \
; RUN: | pnacl-bcanalyzer -dump-records \
-; RUN: | FileCheck %s
+; RUN: | FileCheck %s -check-prefix=PF2
declare void @func()
@@ -28,11 +28,18 @@ define void @CheckPtrToIntGlobal() {
; Note that neither pnacl-version defines a struct type.
-; CHECK: <TYPE_BLOCK_ID>
-; CHECK-NEXT: <NUMENTRY op0=5/>
-; CHECK-NEXT: <INTEGER op0=32/>
-; CHECK-NEXT: <VOID/>
-; CHECK-NEXT: <FUNCTION op0=0 op1=1/>
-; CHECK-NEXT: <POINTER op0=2 op1=0/>
-; CHECK-NEXT: <POINTER op0=0 op1=0/>
-; CHECK-NEXT: </TYPE_BLOCK_ID>
+; PF1: <TYPE_BLOCK_ID>
+; PF1-NEXT: <NUMENTRY op0=5/>
+; PF1-NEXT: <INTEGER op0=32/>
+; PF1-NEXT: <VOID/>
+; PF1-NEXT: <FUNCTION op0=0 op1=1/>
+; PF1-NEXT: <POINTER op0=2 op1=0/>
+; PF1-NEXT: <POINTER op0=0 op1=0/>
+; PF1-NEXT: </TYPE_BLOCK_ID>
+
+; PF2: <TYPE_BLOCK_ID>
+; PF2-NEXT: <NUMENTRY op0=3/>
+; PF2-NEXT: <INTEGER op0=32/>
+; PF2-NEXT: <VOID/>
+; PF2-NEXT: <FUNCTION op0=0 op1=1/>
+; PF2-NEXT: </TYPE_BLOCK_ID>
diff --git a/test/NaCl/Bitcode/switch.ll b/test/NaCl/Bitcode/switch.ll
index f15001f504..3fd5e68483 100644
--- a/test/NaCl/Bitcode/switch.ll
+++ b/test/NaCl/Bitcode/switch.ll
@@ -3,11 +3,11 @@
; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=1 \
; RUN: | pnacl-bcanalyzer -dump-records \
-; RUN: | FileCheck %s
+; RUN: | FileCheck %s -check-prefix=PF1
; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=2 \
; RUN: | pnacl-bcanalyzer -dump-records \
-; RUN: | FileCheck %s
+; RUN: | FileCheck %s -check-prefix=PF2
; Test case where we switch on a variable.
define void @SwitchVariable(i32) {
@@ -47,11 +47,17 @@ end:
ret void
}
-; CHECK: <TYPE_BLOCK_ID>
-; CHECK-NEXT: <NUMENTRY op0=4/>
-; CHECK-NEXT: <VOID/>
-; CHECK-NEXT: <INTEGER op0=32/>
-; CHECK-NEXT: <FUNCTION op0={{.*}} op1={{.*}} op2={{.*}}/>
-; CHECK-NEXT: <POINTER op0={{.*}} op1={{.*}}/>
-; CHECK-NEXT: </TYPE_BLOCK_ID>
+; PF1: <TYPE_BLOCK_ID>
+; PF1-NEXT: <NUMENTRY op0=4/>
+; PF1-NEXT: <VOID/>
+; PF1-NEXT: <INTEGER op0=32/>
+; PF1-NEXT: <FUNCTION op0={{.*}} op1={{.*}} op2={{.*}}/>
+; PF1-NEXT: <POINTER op0={{.*}} op1={{.*}}/>
+; PF1-NEXT: </TYPE_BLOCK_ID>
+; PF2: <TYPE_BLOCK_ID>
+; PF2-NEXT: <NUMENTRY op0=3/>
+; PF2-NEXT: <VOID/>
+; PF2-NEXT: <INTEGER op0=32/>
+; PF2-NEXT: <FUNCTION op0={{.*}} op1={{.*}} op2={{.*}}/>
+; PF2-NEXT: </TYPE_BLOCK_ID>