Bitcode: Share logic for last instruction, NFC

Share logic for getting the last instruction emitted.

llvm-svn: 225499
This commit is contained in:
Duncan P. N. Exon Smith 2015-01-09 02:51:45 +00:00
parent 11fae74ae5
commit 52d0f16e1b
1 changed files with 10 additions and 14 deletions

View File

@ -2453,6 +2453,14 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
unsigned CurBBNo = 0; unsigned CurBBNo = 0;
DebugLoc LastLoc; 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. // Read all the records.
SmallVector<uint64_t, 64> Record; 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 case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: // DEBUG_LOC_AGAIN
// This record indicates that the last instruction is at the same // This record indicates that the last instruction is at the same
// location as the previous instruction with a location. // location as the previous instruction with a location.
I = nullptr; I = getLastInstruction();
// 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();
if (!I) if (!I)
return Error(BitcodeError::InvalidRecord); return Error(BitcodeError::InvalidRecord);
@ -2561,12 +2562,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
continue; continue;
case bitc::FUNC_CODE_DEBUG_LOC_OLD: { // DEBUG_LOC_OLD: [line,col,scope,ia] case bitc::FUNC_CODE_DEBUG_LOC_OLD: { // DEBUG_LOC_OLD: [line,col,scope,ia]
I = nullptr; // Get the last instruction emitted. I = getLastInstruction();
if (CurBB && !CurBB->empty())
I = &CurBB->back();
else if (CurBBNo && FunctionBBs[CurBBNo-1] &&
!FunctionBBs[CurBBNo-1]->empty())
I = &FunctionBBs[CurBBNo-1]->back();
if (!I || Record.size() < 4) if (!I || Record.size() < 4)
return Error(BitcodeError::InvalidRecord); return Error(BitcodeError::InvalidRecord);