diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-09 02:51:45 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-09 02:51:45 +0000 |
commit | 52d0f16e1b1e35d97d3b0f49f9b75ba4db000d1e (patch) | |
tree | c8177b30e0cb862839dcdfdfc9875f71e0f42ff9 /llvm/lib/Bitcode/Reader | |
parent | 11fae74ae57a45ad9fbe5386f5ee37bcd3e49059 (diff) | |
download | bcm5719-llvm-52d0f16e1b1e35d97d3b0f49f9b75ba4db000d1e.tar.gz bcm5719-llvm-52d0f16e1b1e35d97d3b0f49f9b75ba4db000d1e.zip |
Bitcode: Share logic for last instruction, NFC
Share logic for getting the last instruction emitted.
llvm-svn: 225499
Diffstat (limited to 'llvm/lib/Bitcode/Reader')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 9c6a3d33a9b..9a8ec63e059 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2453,6 +2453,14 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { unsigned CurBBNo = 0; DebugLoc LastLoc; + auto getLastInstruction = [&]() -> Instruction * { + if (CurBB && !CurBB->empty()) + return &CurBB->back(); + else if (CurBBNo && FunctionBBs[CurBBNo - 1] && + !FunctionBBs[CurBBNo - 1]->empty()) + return &FunctionBBs[CurBBNo - 1]->back(); + return nullptr; + }; // Read all the records. SmallVector<uint64_t, 64> Record; @@ -2545,14 +2553,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: // DEBUG_LOC_AGAIN // This record indicates that the last instruction is at the same // location as the previous instruction with a location. - I = nullptr; - - // Get the last instruction emitted. - if (CurBB && !CurBB->empty()) - I = &CurBB->back(); - else if (CurBBNo && FunctionBBs[CurBBNo-1] && - !FunctionBBs[CurBBNo-1]->empty()) - I = &FunctionBBs[CurBBNo-1]->back(); + I = getLastInstruction(); if (!I) return Error(BitcodeError::InvalidRecord); @@ -2561,12 +2562,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { continue; case bitc::FUNC_CODE_DEBUG_LOC_OLD: { // DEBUG_LOC_OLD: [line,col,scope,ia] - I = nullptr; // Get the last instruction emitted. - if (CurBB && !CurBB->empty()) - I = &CurBB->back(); - else if (CurBBNo && FunctionBBs[CurBBNo-1] && - !FunctionBBs[CurBBNo-1]->empty()) - I = &FunctionBBs[CurBBNo-1]->back(); + I = getLastInstruction(); if (!I || Record.size() < 4) return Error(BitcodeError::InvalidRecord); |