diff options
author | Karl Schimpf <kschimpf@google.com> | 2013-09-03 13:49:56 -0700 |
---|---|---|
committer | Karl Schimpf <kschimpf@google.com> | 2013-09-03 13:49:56 -0700 |
commit | 264065105b2b9be73662b3c7e5a66c9d70d26a2c (patch) | |
tree | 5a8db9b525e9cdf08d69d0abc255cdfaf5d6bf96 /lib/Bitcode | |
parent | 0dc171568f4981102c284b461b9acb5b4ef44749 (diff) |
Allow PNaCl bitcode versions to be automatically extendable.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3656
R=mseaborn@chromium.org
Review URL: https://codereview.chromium.org/23496022
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 39 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp | 19 |
2 files changed, 23 insertions, 35 deletions
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, |