From db53d99d025acb2737e4248cddfe909b5ecfc478 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 17 Aug 2016 00:06:43 +0000 Subject: [PATCH] AMDGPU: Avoid looking for the DebugLoc in end() The end() iterator isn't a safe thing to dereference. Pass the DebugLoc into EmitFetchClause and EmitALUClause to avoid it. llvm-svn: 278873 --- .../lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp b/llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp index 53f30f8..65dae23 100644 --- a/llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp +++ b/llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp @@ -450,27 +450,24 @@ private: return ClauseFile(&ClauseHead, std::move(ClauseContent)); } - void - EmitFetchClause(MachineBasicBlock::iterator InsertPos, ClauseFile &Clause, - unsigned &CfCount) { + void EmitFetchClause(MachineBasicBlock::iterator InsertPos, + const DebugLoc &DL, ClauseFile &Clause, + unsigned &CfCount) { CounterPropagateAddr(*Clause.first, CfCount); MachineBasicBlock *BB = Clause.first->getParent(); - BuildMI(BB, InsertPos->getDebugLoc(), TII->get(AMDGPU::FETCH_CLAUSE)) - .addImm(CfCount); + BuildMI(BB, DL, TII->get(AMDGPU::FETCH_CLAUSE)).addImm(CfCount); for (unsigned i = 0, e = Clause.second.size(); i < e; ++i) { BB->splice(InsertPos, BB, Clause.second[i]); } CfCount += 2 * Clause.second.size(); } - void - EmitALUClause(MachineBasicBlock::iterator InsertPos, ClauseFile &Clause, - unsigned &CfCount) { + void EmitALUClause(MachineBasicBlock::iterator InsertPos, const DebugLoc &DL, + ClauseFile &Clause, unsigned &CfCount) { Clause.first->getOperand(0).setImm(0); CounterPropagateAddr(*Clause.first, CfCount); MachineBasicBlock *BB = Clause.first->getParent(); - BuildMI(BB, InsertPos->getDebugLoc(), TII->get(AMDGPU::ALU_CLAUSE)) - .addImm(CfCount); + BuildMI(BB, DL, TII->get(AMDGPU::ALU_CLAUSE)).addImm(CfCount); for (unsigned i = 0, e = Clause.second.size(); i < e; ++i) { BB->splice(InsertPos, BB, Clause.second[i]); } @@ -644,17 +641,18 @@ public: break; } case AMDGPU::RETURN: { - BuildMI(MBB, MI, MBB.findDebugLoc(MI), getHWInstrDesc(CF_END)); + DebugLoc DL = MBB.findDebugLoc(MI); + BuildMI(MBB, MI, DL, getHWInstrDesc(CF_END)); CfCount++; if (CfCount % 2) { - BuildMI(MBB, I, MBB.findDebugLoc(MI), TII->get(AMDGPU::PAD)); + BuildMI(MBB, I, DL, TII->get(AMDGPU::PAD)); CfCount++; } MI->eraseFromParent(); for (unsigned i = 0, e = FetchClauses.size(); i < e; i++) - EmitFetchClause(I, FetchClauses[i], CfCount); + EmitFetchClause(I, DL, FetchClauses[i], CfCount); for (unsigned i = 0, e = AluClauses.size(); i < e; i++) - EmitALUClause(I, AluClauses[i], CfCount); + EmitALUClause(I, DL, AluClauses[i], CfCount); break; } default: -- 2.7.4