aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h6
-rw-r--r--lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp39
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp19
3 files changed, 26 insertions, 38 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
index 90d482afaf..76367ff34a 100644
--- a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
+++ b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
@@ -287,14 +287,14 @@ namespace naclbitc {
FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [op, align]
FUNC_CODE_INST_LOAD = 20, // PNaCl version 1:
// LOAD: [op, align, vol]
- // PNaCl version 2:
+ // PNaCl version 2+:
// LOAD: [op, align, ty]
// 21 is unused.
// 22 is unused.
FUNC_CODE_INST_VAARG = 23, // Not used in PNaCl.
FUNC_CODE_INST_STORE = 24, // PNaCl version 1:
// STORE: [ptr, val, align, vol]
- // PNaCl version 2:
+ // PNaCl version 2+:
// Store: [ptr, val, align]
// 25 is unused.
FUNC_CODE_INST_EXTRACTVAL = 26, // Not used in PNaCl.
@@ -320,7 +320,7 @@ namespace naclbitc {
FUNC_CODE_INST_LOADATOMIC = 41, // Not used in PNaCl.
FUNC_CODE_INST_STOREATOMIC = 42, // Not used in PNaCl.
FUNC_CODE_INST_FORWARDTYPEREF = 43, // TYPE: [opval, ty]
- // PNaCl version 2: CALL_INDIRECT: [cc, fnid, fnty, args...]
+ // PNaCl version 2+: CALL_INDIRECT: [cc, fnid, fnty, args...]
FUNC_CODE_INST_CALL_INDIRECT = 44
};
} // End naclbitc namespace
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
index 87eab106a0..994bf712ae 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
@@ -1352,7 +1352,7 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) {
if (Opc == -1 || ResTy == 0)
return Error("Invalid CAST record");
- if (GetPNaClVersion() == 2) {
+ if (GetPNaClVersion() >= 2) {
// If a ptrtoint cast was elided on the argument of the cast,
// add it back. Note: The casts allowed here should match the
// casts in NaClValueEnumerator::ExpectsScalarValue.
@@ -1526,7 +1526,7 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) {
unsigned BBIndex = Record[2+i];
BasicBlock *BB = getBasicBlock(BBIndex);
if (!V || !BB) return Error("Invalid PHI record");
- if (GetPNaClVersion() == 2 && Ty == IntPtrType) {
+ if (GetPNaClVersion() >= 2 && Ty == IntPtrType) {
// Delay installing scalar casts until all instructions of
// the function are rendered. This guarantees that we insert
// the conversion just before the incoming edge (or use an
@@ -1558,51 +1558,44 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) {
if (popValue(Record, &OpNum, NextValueNo, &Op) ||
Record.size() != 3)
return Error("Invalid LOAD record");
- switch (GetPNaClVersion()) {
- case 1:
- I = new LoadInst(Op, "", Record[OpNum+1], (1 << Record[OpNum]) >> 1);
- break;
- case 2: {
- // Add pointer cast to op.
- Type *T = getTypeByID(Record[2]);
- if (T == 0)
- return Error("Invalid type for load instruction");
- Op = ConvertOpToType(Op, T->getPointerTo(), CurBBNo);
- if (Op == 0) return true;
- I = new LoadInst(Op, "", false, (1 << Record[OpNum]) >> 1);
- break;
- }
+ if (GetPNaClVersion() == 1) {
+ I = new LoadInst(Op, "", Record[OpNum+1], (1 << Record[OpNum]) >> 1);
+ } else {
+ // Add pointer cast to op.
+ Type *T = getTypeByID(Record[2]);
+ if (T == 0)
+ return Error("Invalid type for load instruction");
+ Op = ConvertOpToType(Op, T->getPointerTo(), CurBBNo);
+ if (Op == 0) return true;
+ I = new LoadInst(Op, "", false, (1 << Record[OpNum]) >> 1);
}
break;
}
case naclbitc::FUNC_CODE_INST_STORE: {
// PNaCl version 1: STORE: [ptr, val, align, vol]
- // PNaCl version 2: STORE: [ptr, val, align]
+ // PNaCl version 2+: STORE: [ptr, val, align]
unsigned OpNum = 0;
Value *Val, *Ptr;
if (popValue(Record, &OpNum, NextValueNo, &Ptr) ||
popValue(Record, &OpNum, NextValueNo, &Val))
return Error("Invalid STORE record");
- switch (GetPNaClVersion()) {
- case 1:
+ if (GetPNaClVersion() == 1) {
if (OpNum+2 != Record.size())
return Error("Invalid STORE record");
I = new StoreInst(Val, Ptr, Record[OpNum+1], (1 << Record[OpNum]) >> 1);
- break;
- case 2:
+ } else {
if (OpNum+1 != Record.size())
return Error("Invalid STORE record");
Val = ConvertOpToScalar(Val, CurBBNo);
Ptr = ConvertOpToType(Ptr, Val->getType()->getPointerTo(), CurBBNo);
I = new StoreInst(Val, Ptr, false, (1 << Record[OpNum]) >> 1);
- break;
}
break;
}
case naclbitc::FUNC_CODE_INST_CALL:
case naclbitc::FUNC_CODE_INST_CALL_INDIRECT: {
// CALL: [cc, fnid, arg0, arg1...]
- // PNaCl version 2: CALL_INDIRECT: [cc, fnid, fnty, args...]
+ // PNaCl version 2+: CALL_INDIRECT: [cc, fnid, fnty, args...]
if ((Record.size() < 2) ||
(BitCode == naclbitc::FUNC_CODE_INST_CALL_INDIRECT &&
Record.size() < 3))
diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
index 41a2501266..ea5e9cde54 100644
--- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
@@ -865,7 +865,7 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID,
break;
case Instruction::Load:
// PNaCl Version 1: LOAD: [op, align, vol]
- // PNaCl Version 2: LOAD: [op, align, ty]
+ // PNaCl Version 2+: LOAD: [op, align, ty]
Code = naclbitc::FUNC_CODE_INST_LOAD;
pushValue(I.getOperand(0), InstID, Vals, VE, Stream);
AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
@@ -875,14 +875,13 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID,
// we must add a value to the record for version 1, since the
// reader for version 1 has already been released.
Vals.push_back(0);
- }
- if (PNaClVersion == 2) {
+ } else {
Vals.push_back(VE.getTypeID(I.getType()));
}
break;
case Instruction::Store:
// PNaCl version 1: STORE: [ptr, val, align, vol]
- // PNaCl version 2: STORE: [ptr, val, align]
+ // PNaCl version 2+: STORE: [ptr, val, align]
Code = naclbitc::FUNC_CODE_INST_STORE;
AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
pushValue(I.getOperand(1), InstID, Vals, VE, Stream);
@@ -897,7 +896,7 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID,
break;
case Instruction::Call: {
// CALL: [cc, fnid, args...]
- // PNaCl version 2: CALL_INDIRECT: [cc, fnid, fnty, args...]
+ // PNaCl version 2+: CALL_INDIRECT: [cc, fnid, fnty, args...]
const CallInst &Call = cast<CallInst>(I);
const Value* Callee = Call.getCalledValue();
@@ -906,11 +905,9 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID,
pushValue(Callee, InstID, Vals, VE, Stream);
- switch (PNaClVersion) {
- case 1:
+ if (PNaClVersion == 1) {
Code = naclbitc::FUNC_CODE_INST_CALL;
- break;
- case 2:
+ } else {
if (Callee == VE.ElideCasts(Callee)) {
// Since the call pointer has not been elided, we know that
// the call pointer has the type signature of the called
@@ -932,7 +929,6 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID,
cast<FunctionType>(FcnPtrType->getElementType());
Vals.push_back(VE.getTypeID(FcnType));
}
- break;
}
for (unsigned I = 0, E = Call.getNumArgOperands(); I < E; ++I) {
@@ -1135,8 +1131,7 @@ static void WriteBlockInfo(const NaClValueEnumerator &VE,
// reader for version 1 has already been released. By using a constant,
// we at least avoid wasting space in the bitcode file.
Abbv->Add(NaClBitCodeAbbrevOp(0));
- }
- if (PNaClVersion == 2) {
+ } else {
Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 4)); // Typecast
}
if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID,