aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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, 44 insertions, 73 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
index 50182667b5..b9c358f271 100644
--- a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
+++ b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
@@ -105,10 +105,7 @@ namespace naclbitc {
TYPE_CODE_X86_MMX = 17, // Not used in PNaCl.
- 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_ANON = 18, // STRUCT_ANON: [ispacked, eltty x N]
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 3bd1e2f783..9e8c398172 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
@@ -489,10 +489,6 @@ 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 80bf60f2ce..41a2501266 100644
--- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
@@ -94,6 +94,7 @@ 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
};
@@ -200,6 +201,15 @@ 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));
@@ -251,8 +261,23 @@ static void WriteTypeTable(const NaClValueEnumerator &VE,
AbbrevToUse = TYPE_FUNCTION_ABBREV;
break;
}
- case Type::StructTyID:
- report_fatal_error("Struct types are not supported in PNaCl bitcode");
+ 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::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 8e35f59909..8cfdf13240 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
@@ -89,10 +89,6 @@ 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);
@@ -360,11 +356,6 @@ 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
deleted file mode 100644
index 1f9b1279fe..0000000000
--- a/test/NaCl/Bitcode/no-structs.ll
+++ /dev/null
@@ -1,38 +0,0 @@
-; 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 3ef7909fe7..eba451c289 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=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_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_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=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_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_RET/>
; PF2-NEXT: </FUNCTION_BLOCK>