From 6cdfe29d8efaa6987fe708963d65096689f72b14 Mon Sep 17 00:00:00 2001 From: Amara Emerson Date: Wed, 1 Aug 2018 02:17:42 +0000 Subject: [GlobalISel][IRTranslator] Use RPO traversal when visiting blocks to translate. Previously we were just visiting the blocks in the function in IR order, which is rather arbitrary. Therefore we wouldn't always visit defs before uses, but the translation code relies on this assumption in some places. Only codegen change seen in tests is an elision of a redundant copy. Fixes PR38396 llvm-svn: 338476 --- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp') diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index e76c40f8d93..80da50562d3 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/GlobalISel/IRTranslator.h" +#include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallSet.h" @@ -33,6 +34,7 @@ #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" @@ -1613,19 +1615,20 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { ArgIt++; } - // And translate the function! - for (const BasicBlock &BB : F) { - MachineBasicBlock &MBB = getMBB(BB); + // Need to visit defs before uses when translating instructions. + ReversePostOrderTraversal RPOT(&F); + for (const BasicBlock *BB : RPOT) { + MachineBasicBlock &MBB = getMBB(*BB); // Set the insertion point of all the following translations to // the end of this basic block. CurBuilder.setMBB(MBB); - for (const Instruction &Inst : BB) { + for (const Instruction &Inst : *BB) { if (translate(Inst)) continue; OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure", - Inst.getDebugLoc(), &BB); + Inst.getDebugLoc(), BB); R << "unable to translate instruction: " << ore::NV("Opcode", &Inst); if (ORE->allowExtraAnalysis("gisel-irtranslator")) { -- cgit v1.2.3