aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Schimpf <kschimpf@google.com>2013-08-30 08:52:20 -0700
committerKarl Schimpf <kschimpf@google.com>2013-08-30 08:52:20 -0700
commit2302e5d39e2302962d1a0e45d60e00ed47b9b061 (patch)
tree1a121361ee62714d76c916ac4e203a091a747601
parent215d7de42d1ada5ca44bd6bc03789b2ea81ce865 (diff)
Remove generating STRUCT_ANON records in PNaCl bitcode files.
Don't generate types for elided cast instructions, since they are never put into the bitcode file. In addition, do not generate a type id for the types of global variables, because they are never needed. Don't allow and STRUCT records in bitcode files when PNaClVersion==2. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3648 R=mseaborn@chromium.org Review URL: https://codereview.chromium.org/23431008
-rw-r--r--include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h5
-rw-r--r--lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp4
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp29
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp9
-rw-r--r--test/NaCl/Bitcode/no-structs.ll38
-rw-r--r--test/NaCl/Bitcode/ptrtoint-elide.ll32
6 files changed, 73 insertions, 44 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
index b9c358f271..50182667b5 100644
--- a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
+++ b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
@@ -105,7 +105,10 @@ namespace naclbitc {
TYPE_CODE_X86_MMX = 17, // Not used in PNaCl.
- TYPE_CODE_STRUCT_ANON = 18, // STRUCT_ANON: [ispacked, eltty x N]
+ TYPE_CODE_STRUCT_ANON = 18, // PNaCl version 1 (early versions only)
+ // STRUCT_ANON: [ispacked, eltty x N]
+ // Not used in PNaCl otherwise (i.e.
+ // PNaCl versions 1+).
TYPE_CODE_STRUCT_NAME = 19, // Not used in PNaCl.
TYPE_CODE_STRUCT_NAMED = 20,// Not used in PNaCl.
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
index 9e8c398172..3bd1e2f783 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
@@ -489,6 +489,10 @@ bool NaClBitcodeReader::ParseTypeTableBody() {
break;
}
case naclbitc::TYPE_CODE_STRUCT_ANON: { // STRUCT: [ispacked, eltty x N]
+ // Deprecated. Only exists in early PNaCl version 1 bitcode files.
+ // TODO(kschimpf) Remove this as soon as is feasible.
+ if (GetPNaClVersion() >= 2)
+ return Error("Struct types not supported in PNaCl bitcode");
if (Record.size() < 1)
return Error("Invalid STRUCT type record");
SmallVector<Type*, 8> EltTys;
diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
index 41a2501266..80bf60f2ce 100644
--- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
@@ -94,7 +94,6 @@ enum {
// TYPE_BLOCK_ID_NEW abbrev id's.
TYPE_POINTER_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV,
TYPE_FUNCTION_ABBREV,
- TYPE_STRUCT_ANON_ABBREV,
TYPE_ARRAY_ABBREV,
TYPE_MAX_ABBREV = TYPE_ARRAY_ABBREV
};
@@ -201,15 +200,6 @@ static void WriteTypeTable(const NaClValueEnumerator &VE,
if (TYPE_FUNCTION_ABBREV != Stream.EmitAbbrev(Abbv))
llvm_unreachable("Unexpected abbrev ordering!");
- // Abbrev for TYPE_CODE_STRUCT_ANON.
- Abbv = new NaClBitCodeAbbrev();
- Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_ANON));
- Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked
- Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array));
- Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits));
- if (TYPE_STRUCT_ANON_ABBREV != Stream.EmitAbbrev(Abbv))
- llvm_unreachable("Unexpected abbrev ordering!");
-
// Abbrev for TYPE_CODE_ARRAY.
Abbv = new NaClBitCodeAbbrev();
Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_ARRAY));
@@ -261,23 +251,8 @@ static void WriteTypeTable(const NaClValueEnumerator &VE,
AbbrevToUse = TYPE_FUNCTION_ABBREV;
break;
}
- case Type::StructTyID: {
- StructType *ST = cast<StructType>(T);
- // STRUCT: [ispacked, eltty x N]
- TypeVals.push_back(ST->isPacked());
- // Output all of the element types.
- for (StructType::element_iterator I = ST->element_begin(),
- E = ST->element_end(); I != E; ++I)
- TypeVals.push_back(VE.getTypeID(*I));
-
- if (ST->isLiteral()) {
- Code = naclbitc::TYPE_CODE_STRUCT_ANON;
- AbbrevToUse = TYPE_STRUCT_ANON_ABBREV;
- } else {
- report_fatal_error("Non-anon structs not supported in PNaCl bitcode");
- }
- break;
- }
+ case Type::StructTyID:
+ report_fatal_error("Struct types are not supported in PNaCl bitcode");
case Type::ArrayTyID: {
ArrayType *AT = cast<ArrayType>(T);
// ARRAY: [numelts, eltty]
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
index 8cfdf13240..8e35f59909 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
@@ -89,6 +89,10 @@ NaClValueEnumerator::NaClValueEnumerator(const Module *M, uint32_t PNaClVersion)
for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
+ // Don't generate types for elided pointer casts!
+ if (I == ElideCasts(I))
+ continue;
+
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
OI != E; ++OI) {
EnumerateOperandType(*OI);
@@ -356,6 +360,11 @@ void NaClValueEnumerator::EnumerateType(Type *Ty, bool InsideOptimizeTypes) {
// Enumerate the types for the specified value. If the value is a constant,
// walk through it, enumerating the types of the constant.
void NaClValueEnumerator::EnumerateOperandType(const Value *V) {
+ // Note: We intentionally don't create a type id for global variables,
+ // since the type is automatically generated by the reader before any
+ // use of the global variable.
+ if (isa<GlobalVariable>(V)) return;
+
EnumerateType(V->getType());
if (const Constant *C = dyn_cast<Constant>(V)) {
diff --git a/test/NaCl/Bitcode/no-structs.ll b/test/NaCl/Bitcode/no-structs.ll
new file mode 100644
index 0000000000..1f9b1279fe
--- /dev/null
+++ b/test/NaCl/Bitcode/no-structs.ll
@@ -0,0 +1,38 @@
+; Tests that even though global variables can define structured types,
+; they types are not put into the bitcode file.
+
+; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=1 \
+; RUN: | pnacl-bcanalyzer -dump-records \
+; RUN: | FileCheck %s
+
+; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=2 \
+; RUN: | pnacl-bcanalyzer -dump-records \
+; RUN: | FileCheck %s
+
+declare void @func()
+
+@compound = internal global <{ [4 x i8], i32 }>
+ <{ [4 x i8] c"home", i32 ptrtoint (void ()* @func to i32) }>
+
+define void @CheckBitcastGlobal() {
+ %1 = bitcast <{ [4 x i8], i32}>* @compound to i32*
+ %2 = load i32* %1, align 4
+ ret void
+}
+
+define void @CheckPtrToIntGlobal() {
+ %1 = ptrtoint <{ [4 x i8], i32 }>* @compound to i32
+ %2 = add i32 %1, 0
+ ret void
+}
+
+; 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>
diff --git a/test/NaCl/Bitcode/ptrtoint-elide.ll b/test/NaCl/Bitcode/ptrtoint-elide.ll
index eba451c289..3ef7909fe7 100644
--- a/test/NaCl/Bitcode/ptrtoint-elide.ll
+++ b/test/NaCl/Bitcode/ptrtoint-elide.ll
@@ -638,14 +638,14 @@ define void @TestCasts() {
; PF1-NEXT: <INST_CAST op0=1 op1=0 op2=9/>
; PF1-NEXT: <INST_CAST op0=6 op1=2 op2=0/>
; PF1-NEXT: <INST_CAST op0=2 op1=2 op2=0/>
-; PF1-NEXT: <INST_CAST op0=8 op1=13 op2=1/>
-; PF1-NEXT: <INST_CAST op0=4 op1=13 op2=1/>
-; PF1-NEXT: <INST_CAST op0=9 op1=13 op2=2/>
-; PF1-NEXT: <INST_CAST op0=6 op1=13 op2=2/>
-; PF1-NEXT: <INST_CAST op0=9 op1=14 op2=5/>
-; PF1-NEXT: <INST_CAST op0=8 op1=14 op2=5/>
-; PF1-NEXT: <INST_CAST op0=13 op1=14 op2=6/>
-; PF1-NEXT: <INST_CAST op0=10 op1=14 op2=6/>
+; PF1-NEXT: <INST_CAST op0=8 op1=11 op2=1/>
+; PF1-NEXT: <INST_CAST op0=4 op1=11 op2=1/>
+; PF1-NEXT: <INST_CAST op0=9 op1=11 op2=2/>
+; PF1-NEXT: <INST_CAST op0=6 op1=11 op2=2/>
+; PF1-NEXT: <INST_CAST op0=9 op1=12 op2=5/>
+; PF1-NEXT: <INST_CAST op0=8 op1=12 op2=5/>
+; PF1-NEXT: <INST_CAST op0=13 op1=12 op2=6/>
+; PF1-NEXT: <INST_CAST op0=10 op1=12 op2=6/>
; PF1-NEXT: <INST_RET/>
; PF1-NEXT: </FUNCTION_BLOCK>
@@ -670,14 +670,14 @@ define void @TestCasts() {
; PF2-NEXT: <INST_ALLOCA op0=2 op1=4/>
; PF2-NEXT: <INST_CAST op0=5 op1=2 op2=0/>
; PF2-NEXT: <INST_CAST op0=2 op1=2 op2=0/>
-; PF2-NEXT: <INST_CAST op0=7 op1=13 op2=1/>
-; PF2-NEXT: <INST_CAST op0=4 op1=13 op2=1/>
-; PF2-NEXT: <INST_CAST op0=8 op1=13 op2=2/>
-; PF2-NEXT: <INST_CAST op0=6 op1=13 op2=2/>
-; PF2-NEXT: <INST_CAST op0=8 op1=14 op2=5/>
-; PF2-NEXT: <INST_CAST op0=8 op1=14 op2=5/>
-; PF2-NEXT: <INST_CAST op0=12 op1=14 op2=6/>
-; PF2-NEXT: <INST_CAST op0=10 op1=14 op2=6/>
+; PF2-NEXT: <INST_CAST op0=7 op1=11 op2=1/>
+; PF2-NEXT: <INST_CAST op0=4 op1=11 op2=1/>
+; PF2-NEXT: <INST_CAST op0=8 op1=11 op2=2/>
+; PF2-NEXT: <INST_CAST op0=6 op1=11 op2=2/>
+; PF2-NEXT: <INST_CAST op0=8 op1=12 op2=5/>
+; PF2-NEXT: <INST_CAST op0=8 op1=12 op2=5/>
+; PF2-NEXT: <INST_CAST op0=12 op1=12 op2=6/>
+; PF2-NEXT: <INST_CAST op0=10 op1=12 op2=6/>
; PF2-NEXT: <INST_RET/>
; PF2-NEXT: </FUNCTION_BLOCK>