From 52d0f16e1b1e35d97d3b0f49f9b75ba4db000d1e Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 9 Jan 2015 02:51:45 +0000 Subject: [PATCH] Bitcode: Share logic for last instruction, NFC Share logic for getting the last instruction emitted. llvm-svn: 225499 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 24 ++++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 9c6a3d33a9b9..9a8ec63e059d 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 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);