diff options
Diffstat (limited to 'contrib/llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r-- | contrib/llvm/lib/CodeGen/MachineSink.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/contrib/llvm/lib/CodeGen/MachineSink.cpp b/contrib/llvm/lib/CodeGen/MachineSink.cpp index 8337793..aed0e50 100644 --- a/contrib/llvm/lib/CodeGen/MachineSink.cpp +++ b/contrib/llvm/lib/CodeGen/MachineSink.cpp @@ -19,6 +19,7 @@ #include "llvm/CodeGen/Passes.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SparseBitVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" @@ -70,6 +71,8 @@ namespace { // will be split. SetVector<std::pair<MachineBasicBlock*,MachineBasicBlock*> > ToSplit; + SparseBitVector<> RegsToClearKillFlags; + public: static char ID; // Pass identification MachineSinking() : MachineFunctionPass(ID) { @@ -287,6 +290,12 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) { if (!MadeChange) break; EverMadeChange = true; } + + // Now clear any kill flags for recorded registers. + for (auto I : RegsToClearKillFlags) + MRI->clearKillFlags(I); + RegsToClearKillFlags.clear(); + return EverMadeChange; } @@ -643,7 +652,11 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { return false; // Check if it's safe to move the instruction. - if (!MI->isSafeToMove(TII, AA, SawStore)) + if (!MI->isSafeToMove(AA, SawStore)) + return false; + + // Convergent operations may only be moved to control equivalent locations. + if (MI->isConvergent()) return false; // FIXME: This should include support for sinking instructions within the @@ -656,7 +669,8 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { bool BreakPHIEdge = false; MachineBasicBlock *ParentBlock = MI->getParent(); - MachineBasicBlock *SuccToSinkTo = FindSuccToSinkTo(MI, ParentBlock, BreakPHIEdge); + MachineBasicBlock *SuccToSinkTo = FindSuccToSinkTo(MI, ParentBlock, + BreakPHIEdge); // If there are no outputs, it must have side-effects. if (!SuccToSinkTo) @@ -684,7 +698,7 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { // other code paths. bool TryBreak = false; bool store = true; - if (!MI->isSafeToMove(TII, AA, store)) { + if (!MI->isSafeToMove(AA, store)) { DEBUG(dbgs() << " *** NOTE: Won't sink load along critical edge.\n"); TryBreak = true; } @@ -755,7 +769,13 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { // Conservatively, clear any kill flags, since it's possible that they are no // longer correct. - MI->clearKillInfo(); + // Note that we have to clear the kill flags for any register this instruction + // uses as we may sink over another instruction which currently kills the + // used registers. + for (MachineOperand &MO : MI->operands()) { + if (MO.isReg() && MO.isUse()) + RegsToClearKillFlags.set(MO.getReg()); // Remember to clear kill flags. + } return true; } |