X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FMachineSink.cpp;h=0e18fa742f5b327cc61dfe170b0d5cbf9ac74552;hb=e7800be8f08da88e9916020bb770e22c0d98625b;hp=b4e72fed28db8c793b6a627b417ad87a27d56315;hpb=844731a7f1909f55935e3514c9e713a62d67662e;p=oota-llvm.git diff --git a/lib/CodeGen/MachineSink.cpp b/lib/CodeGen/MachineSink.cpp index b4e72fed28d..0e18fa742f5 100644 --- a/lib/CodeGen/MachineSink.cpp +++ b/lib/CodeGen/MachineSink.cpp @@ -18,7 +18,6 @@ #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" @@ -36,7 +35,7 @@ namespace { public: static char ID; // Pass identification - MachineSinking() : MachineFunctionPass((intptr_t)&ID) {} + MachineSinking() : MachineFunctionPass(&ID) {} virtual bool runOnMachineFunction(MachineFunction &MF); @@ -112,20 +111,29 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) { } bool MachineSinking::ProcessBlock(MachineBasicBlock &MBB) { - bool MadeChange = false; - // Can't sink anything out of a block that has less than two successors. - if (MBB.succ_size() <= 1) return false; - + if (MBB.succ_size() <= 1 || MBB.empty()) return false; + + bool MadeChange = false; + // Walk the basic block bottom-up. Remember if we saw a store. - bool SawStore = false; - for (MachineBasicBlock::iterator I = MBB.end(); I != MBB.begin(); ){ - MachineBasicBlock::iterator LastIt = I; - if (SinkInstruction(--I, SawStore)) { - I = LastIt; - ++NumSunk; - } - } + MachineBasicBlock::iterator I = MBB.end(); + --I; + bool ProcessedBegin, SawStore = false; + do { + MachineInstr *MI = I; // The instruction to sink. + + // Predecrement I (if it's not begin) so that it isn't invalidated by + // sinking. + ProcessedBegin = I == MBB.begin(); + if (!ProcessedBegin) + --I; + + if (SinkInstruction(MI, SawStore)) + ++NumSunk, MadeChange = true; + + // If we just processed the first instruction in the block, we're done. + } while (!ProcessedBegin); return MadeChange; } @@ -168,6 +176,10 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { } else { // Virtual register uses are always safe to sink. if (MO.isUse()) continue; + + // If it's not safe to move defs of the register class, then abort. + if (!TII->isSafeToMoveRegClassDefs(RegInfo->getRegClass(Reg))) + return false; // FIXME: This picks a successor to sink into based on having one // successor that dominates all the uses. However, there are cases where @@ -209,6 +221,16 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { // If there are no outputs, it must have side-effects. if (SuccToSinkTo == 0) return false; + + // It's not safe to sink instructions to EH landing pad. Control flow into + // landing pad is implicitly defined. + if (SuccToSinkTo->isLandingPad()) + return false; + + // If is not possible to sink an instruction into its own block. This can + // happen with loops. + if (MI->getParent() == SuccToSinkTo) + return false; DEBUG(cerr << "Sink instr " << *MI); DEBUG(cerr << "to block " << *SuccToSinkTo);