diff --git a/hpvm/projects/hetero-c++/lib/HCCVerifier.cpp b/hpvm/projects/hetero-c++/lib/HCCVerifier.cpp index b2acc2caa86069ad5282ace5bbe5b6a8d5f2cd4d..34ddce6793934698ca7e6af49e681f8141409a15 100644 --- a/hpvm/projects/hetero-c++/lib/HCCVerifier.cpp +++ b/hpvm/projects/hetero-c++/lib/HCCVerifier.cpp @@ -460,15 +460,19 @@ static Instruction* getFirstNonDebug(BasicBlock* block) { return inst; } +// Finds the first instruction in the basic block which is not a marker and no +// instruction after it in the block is either Instruction* HCCVerifier::getFirstNonMarker(BasicBlock* block) { - Instruction* result = block->getFirstNonPHIOrDbg(); - while (!result->isTerminator()) { - CallInst* call = dyn_cast<CallInst>(result); - if (!call) break; - if (markerFunctions.find(call->getCalledFunction()) - != markerFunctions.end()) { - result = result->getNextNonDebugInstruction(); + // Traverse from the end, stopping when we encounter a marker + Instruction* current = block->getTerminator(); + Instruction* result = current; + while (current) { + if (CallInst* call = dyn_cast<CallInst>(current)) { + if (markerFunctions.find(call->getCalledFunction()) + != markerFunctions.end()) break; } + result = current; + current = current->getPrevNonDebugInstruction(); } return result; }