diff options
author | Karl Schimpf <kschimpf@google.com> | 2013-08-02 13:32:27 -0700 |
---|---|---|
committer | Karl Schimpf <kschimpf@google.com> | 2013-08-02 13:32:27 -0700 |
commit | 39bd1f66ebd83185944cf08903d8abf80321c17d (patch) | |
tree | f24f67d037a3f3a989b822f9413bcf1e5ef56c86 /lib/Bitcode | |
parent | 0fdd44084de8589343b099a4d1908f221e7bdc37 (diff) |
Remove unnecessary pointer casts on store instructions.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3544
R=mseaborn@chromium.org
Review URL: https://codereview.chromium.org/21964002
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 6 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp | 21 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp | 5 |
3 files changed, 26 insertions, 6 deletions
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp index ede06b2457..33ad03a246 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp +++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp @@ -1663,19 +1663,21 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) { return Error("Invalid type for load instruction"); Op = ConvertOpToType(Op, T->getPointerTo(), CurBB); if (Op == 0) return true; + break; } } I = new LoadInst(Op, "", Record[OpNum+1], (1 << Record[OpNum]) >> 1); break; } - case naclbitc::FUNC_CODE_INST_STORE: { // STORE2:[ptr, val, align, vol] + case naclbitc::FUNC_CODE_INST_STORE: { // STORE: [ptr, val, align, vol] unsigned OpNum = 0; Value *Val, *Ptr; if (popValue(Record, &OpNum, NextValueNo, &Ptr) || popValue(Record, &OpNum, NextValueNo, &Val) || OpNum+2 != Record.size()) return Error("Invalid STORE record"); - + // Note: In version 1, the following statement is a noop. + Ptr = ConvertOpToType(Ptr, Val->getType()->getPointerTo(), CurBB); I = new StoreInst(Val, Ptr, Record[OpNum+1], (1 << Record[OpNum]) >> 1); break; } diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp index ac2a6a0acf..9152879ff1 100644 --- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp @@ -91,7 +91,8 @@ enum { FUNCTION_INST_RET_VAL_ABBREV, FUNCTION_INST_UNREACHABLE_ABBREV, FUNCTION_INST_FORWARDTYPEREF_ABBREV, - FUNCTION_INST_MAX_ABBREV = FUNCTION_INST_FORWARDTYPEREF_ABBREV, + FUNCTION_INST_STORE_ABBREV, + FUNCTION_INST_MAX_ABBREV = FUNCTION_INST_STORE_ABBREV, // TYPE_BLOCK_ID_NEW abbrev id's. TYPE_POINTER_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, @@ -1016,10 +1017,11 @@ static bool WriteInstruction(const Instruction &I, unsigned InstID, Vals.push_back(VE.getTypeID(I.getType())); } break; - case Instruction::Store: + case Instruction::Store: // STORE: [ptr, val, align, vol] Code = naclbitc::FUNC_CODE_INST_STORE; - pushValue(I.getOperand(1), InstID, Vals, VE, Stream); // ptrty + ptr - pushValue(I.getOperand(0), InstID, Vals, VE, Stream); // val. + AbbrevToUse = FUNCTION_INST_STORE_ABBREV; + pushValue(I.getOperand(1), InstID, Vals, VE, Stream); + pushValue(I.getOperand(0), InstID, Vals, VE, Stream); Vals.push_back(Log2_32(cast<StoreInst>(I).getAlignment())+1); Vals.push_back(cast<StoreInst>(I).isVolatile()); break; @@ -1315,6 +1317,17 @@ static void WriteBlockInfo(const NaClValueEnumerator &VE, Abbv) != FUNCTION_INST_FORWARDTYPEREF_ABBREV) llvm_unreachable("Unexpected abbrev ordering!"); } + { // INST_STORE abbrev for FUNCTION_BLOCK. + NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); + Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_STORE)); + Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // Ptr + Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // Value + Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 4)); // Align + Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // volatile + if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, + Abbv) != FUNCTION_INST_STORE_ABBREV) + llvm_unreachable("Unexpected abbrev ordering!"); + } { // VAR abbrev for GLOBALVAR_BLOCK. NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp index 11e1161bf8..34f4f2bbe9 100644 --- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp @@ -443,7 +443,12 @@ static bool AllowsNormalizedPtr(const Value *V, const Instruction *Arg) { default: return false; case Instruction::Load: + // Verify it is the ptr argument of the load. Note: This check is + // not really necessary in that a load only has one argument. return I->getOperand(0) == Arg; + case Instruction::Store: + // Verify it is the ptr argument of the store. + return I->getOperand(1) == Arg; } } |