2012-07-04 02:09:54 +02:00
|
|
|
//===-- EarlyIfConversion.cpp - If-conversion on SSA form machine code ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Early if-conversion is for out-of-order CPUs that don't have a lot of
|
|
|
|
// predicable instructions. The goal is to eliminate conditional branches that
|
|
|
|
// may mispredict.
|
|
|
|
//
|
|
|
|
// Instructions from both sides of the branch are executed specutatively, and a
|
|
|
|
// cmov instruction selects the result.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "early-ifcvt"
|
|
|
|
#include "llvm/ADT/BitVector.h"
|
2012-07-11 00:18:23 +02:00
|
|
|
#include "llvm/ADT/PostOrderIterator.h"
|
2012-07-04 02:09:54 +02:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/ADT/SparseSet.h"
|
2012-08-13 23:03:27 +02:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2012-07-04 02:09:54 +02:00
|
|
|
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
2012-07-11 00:18:23 +02:00
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
2012-07-04 02:09:54 +02:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2012-07-11 00:39:56 +02:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2012-07-04 02:09:54 +02:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2013-01-17 02:06:04 +01:00
|
|
|
#include "llvm/CodeGen/MachineTraceMetrics.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2012-07-04 02:09:54 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2012-07-04 02:09:54 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Absolute maximum number of instructions allowed per speculated block.
|
|
|
|
// This bypasses all other heuristics, so it should be set fairly high.
|
|
|
|
static cl::opt<unsigned>
|
|
|
|
BlockInstrLimit("early-ifcvt-limit", cl::init(30), cl::Hidden,
|
|
|
|
cl::desc("Maximum number of instructions per speculated block."));
|
|
|
|
|
|
|
|
// Stress testing mode - disable heuristics.
|
|
|
|
static cl::opt<bool> Stress("stress-early-ifcvt", cl::Hidden,
|
|
|
|
cl::desc("Turn all knobs to 11"));
|
|
|
|
|
2012-08-13 23:03:27 +02:00
|
|
|
STATISTIC(NumDiamondsSeen, "Number of diamonds");
|
|
|
|
STATISTIC(NumDiamondsConv, "Number of diamonds converted");
|
|
|
|
STATISTIC(NumTrianglesSeen, "Number of triangles");
|
|
|
|
STATISTIC(NumTrianglesConv, "Number of triangles converted");
|
|
|
|
|
2012-07-04 02:09:54 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SSAIfConv
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The SSAIfConv class performs if-conversion on SSA form machine code after
|
2012-07-04 03:09:45 +02:00
|
|
|
// determining if it is possible. The class contains no heuristics; external
|
2012-07-04 02:09:54 +02:00
|
|
|
// code should be used to determine when if-conversion is a good idea.
|
|
|
|
//
|
2012-07-04 03:09:45 +02:00
|
|
|
// SSAIfConv can convert both triangles and diamonds:
|
2012-07-04 02:09:54 +02:00
|
|
|
//
|
|
|
|
// Triangle: Head Diamond: Head
|
2012-07-04 03:09:45 +02:00
|
|
|
// | \ / \_
|
|
|
|
// | \ / |
|
2012-07-04 02:09:54 +02:00
|
|
|
// | [TF]BB FBB TBB
|
|
|
|
// | / \ /
|
|
|
|
// | / \ /
|
|
|
|
// Tail Tail
|
|
|
|
//
|
|
|
|
// Instructions in the conditional blocks TBB and/or FBB are spliced into the
|
2012-07-04 03:09:45 +02:00
|
|
|
// Head block, and phis in the Tail block are converted to select instructions.
|
2012-07-04 02:09:54 +02:00
|
|
|
//
|
|
|
|
namespace {
|
|
|
|
class SSAIfConv {
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
MachineRegisterInfo *MRI;
|
|
|
|
|
2012-07-11 00:18:23 +02:00
|
|
|
public:
|
2012-07-04 02:09:54 +02:00
|
|
|
/// The block containing the conditional branch.
|
|
|
|
MachineBasicBlock *Head;
|
|
|
|
|
|
|
|
/// The block containing phis after the if-then-else.
|
|
|
|
MachineBasicBlock *Tail;
|
|
|
|
|
|
|
|
/// The 'true' conditional block as determined by AnalyzeBranch.
|
|
|
|
MachineBasicBlock *TBB;
|
|
|
|
|
|
|
|
/// The 'false' conditional block as determined by AnalyzeBranch.
|
|
|
|
MachineBasicBlock *FBB;
|
|
|
|
|
|
|
|
/// isTriangle - When there is no 'else' block, either TBB or FBB will be
|
|
|
|
/// equal to Tail.
|
|
|
|
bool isTriangle() const { return TBB == Tail || FBB == Tail; }
|
|
|
|
|
2012-08-10 22:19:17 +02:00
|
|
|
/// Returns the Tail predecessor for the True side.
|
|
|
|
MachineBasicBlock *getTPred() const { return TBB == Tail ? Head : TBB; }
|
|
|
|
|
|
|
|
/// Returns the Tail predecessor for the False side.
|
|
|
|
MachineBasicBlock *getFPred() const { return FBB == Tail ? Head : FBB; }
|
|
|
|
|
2012-07-04 02:09:54 +02:00
|
|
|
/// Information about each phi in the Tail block.
|
|
|
|
struct PHIInfo {
|
|
|
|
MachineInstr *PHI;
|
|
|
|
unsigned TReg, FReg;
|
|
|
|
// Latencies from Cond+Branch, TReg, and FReg to DstReg.
|
|
|
|
int CondCycles, TCycles, FCycles;
|
|
|
|
|
|
|
|
PHIInfo(MachineInstr *phi)
|
|
|
|
: PHI(phi), TReg(0), FReg(0), CondCycles(0), TCycles(0), FCycles(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SmallVector<PHIInfo, 8> PHIs;
|
|
|
|
|
2012-07-11 00:18:23 +02:00
|
|
|
private:
|
|
|
|
/// The branch condition determined by AnalyzeBranch.
|
|
|
|
SmallVector<MachineOperand, 4> Cond;
|
|
|
|
|
2012-07-04 02:09:54 +02:00
|
|
|
/// Instructions in Head that define values used by the conditional blocks.
|
|
|
|
/// The hoisted instructions must be inserted after these instructions.
|
|
|
|
SmallPtrSet<MachineInstr*, 8> InsertAfter;
|
|
|
|
|
|
|
|
/// Register units clobbered by the conditional blocks.
|
|
|
|
BitVector ClobberedRegUnits;
|
|
|
|
|
|
|
|
// Scratch pad for findInsertionPoint.
|
|
|
|
SparseSet<unsigned> LiveRegUnits;
|
|
|
|
|
|
|
|
/// Insertion point in Head for speculatively executed instructions form TBB
|
|
|
|
/// and FBB.
|
|
|
|
MachineBasicBlock::iterator InsertionPoint;
|
|
|
|
|
|
|
|
/// Return true if all non-terminator instructions in MBB can be safely
|
|
|
|
/// speculated.
|
|
|
|
bool canSpeculateInstrs(MachineBasicBlock *MBB);
|
|
|
|
|
|
|
|
/// Find a valid insertion point in Head.
|
|
|
|
bool findInsertionPoint();
|
|
|
|
|
2012-08-13 22:49:04 +02:00
|
|
|
/// Replace PHI instructions in Tail with selects.
|
|
|
|
void replacePHIInstrs();
|
|
|
|
|
|
|
|
/// Insert selects and rewrite PHI operands to use them.
|
|
|
|
void rewritePHIOperands();
|
|
|
|
|
2012-07-04 02:09:54 +02:00
|
|
|
public:
|
|
|
|
/// runOnMachineFunction - Initialize per-function data structures.
|
|
|
|
void runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
TII = MF.getTarget().getInstrInfo();
|
|
|
|
TRI = MF.getTarget().getRegisterInfo();
|
|
|
|
MRI = &MF.getRegInfo();
|
|
|
|
LiveRegUnits.clear();
|
|
|
|
LiveRegUnits.setUniverse(TRI->getNumRegUnits());
|
|
|
|
ClobberedRegUnits.clear();
|
|
|
|
ClobberedRegUnits.resize(TRI->getNumRegUnits());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// canConvertIf - If the sub-CFG headed by MBB can be if-converted,
|
|
|
|
/// initialize the internal state, and return true.
|
|
|
|
bool canConvertIf(MachineBasicBlock *MBB);
|
|
|
|
|
|
|
|
/// convertIf - If-convert the last block passed to canConvertIf(), assuming
|
2012-07-11 00:18:23 +02:00
|
|
|
/// it is possible. Add any erased blocks to RemovedBlocks.
|
|
|
|
void convertIf(SmallVectorImpl<MachineBasicBlock*> &RemovedBlocks);
|
2012-07-04 02:09:54 +02:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
/// canSpeculateInstrs - Returns true if all the instructions in MBB can safely
|
|
|
|
/// be speculated. The terminators are not considered.
|
|
|
|
///
|
|
|
|
/// If instructions use any values that are defined in the head basic block,
|
|
|
|
/// the defining instructions are added to InsertAfter.
|
|
|
|
///
|
|
|
|
/// Any clobbered regunits are added to ClobberedRegUnits.
|
|
|
|
///
|
|
|
|
bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {
|
|
|
|
// Reject any live-in physregs. It's probably CPSR/EFLAGS, and very hard to
|
|
|
|
// get right.
|
|
|
|
if (!MBB->livein_empty()) {
|
|
|
|
DEBUG(dbgs() << "BB#" << MBB->getNumber() << " has live-ins.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned InstrCount = 0;
|
2012-07-06 04:31:22 +02:00
|
|
|
|
|
|
|
// Check all instructions, except the terminators. It is assumed that
|
|
|
|
// terminators never have side effects or define any used register values.
|
2012-07-04 02:09:54 +02:00
|
|
|
for (MachineBasicBlock::iterator I = MBB->begin(),
|
|
|
|
E = MBB->getFirstTerminator(); I != E; ++I) {
|
|
|
|
if (I->isDebugValue())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (++InstrCount > BlockInstrLimit && !Stress) {
|
|
|
|
DEBUG(dbgs() << "BB#" << MBB->getNumber() << " has more than "
|
|
|
|
<< BlockInstrLimit << " instructions.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There shouldn't normally be any phis in a single-predecessor block.
|
|
|
|
if (I->isPHI()) {
|
|
|
|
DEBUG(dbgs() << "Can't hoist: " << *I);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't speculate loads. Note that it may be possible and desirable to
|
|
|
|
// speculate GOT or constant pool loads that are guaranteed not to trap,
|
|
|
|
// but we don't support that for now.
|
|
|
|
if (I->mayLoad()) {
|
|
|
|
DEBUG(dbgs() << "Won't speculate load: " << *I);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We never speculate stores, so an AA pointer isn't necessary.
|
|
|
|
bool DontMoveAcrossStore = true;
|
|
|
|
if (!I->isSafeToMove(TII, 0, DontMoveAcrossStore)) {
|
|
|
|
DEBUG(dbgs() << "Can't speculate: " << *I);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for any dependencies on Head instructions.
|
|
|
|
for (MIOperands MO(I); MO.isValid(); ++MO) {
|
|
|
|
if (MO->isRegMask()) {
|
|
|
|
DEBUG(dbgs() << "Won't speculate regmask: " << *I);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!MO->isReg())
|
|
|
|
continue;
|
|
|
|
unsigned Reg = MO->getReg();
|
|
|
|
|
|
|
|
// Remember clobbered regunits.
|
|
|
|
if (MO->isDef() && TargetRegisterInfo::isPhysicalRegister(Reg))
|
|
|
|
for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
|
|
|
|
ClobberedRegUnits.set(*Units);
|
|
|
|
|
|
|
|
if (!MO->readsReg() || !TargetRegisterInfo::isVirtualRegister(Reg))
|
|
|
|
continue;
|
|
|
|
MachineInstr *DefMI = MRI->getVRegDef(Reg);
|
|
|
|
if (!DefMI || DefMI->getParent() != Head)
|
|
|
|
continue;
|
|
|
|
if (InsertAfter.insert(DefMI))
|
|
|
|
DEBUG(dbgs() << "BB#" << MBB->getNumber() << " depends on " << *DefMI);
|
|
|
|
if (DefMI->isTerminator()) {
|
|
|
|
DEBUG(dbgs() << "Can't insert instructions below terminator.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Find an insertion point in Head for the speculated instructions. The
|
|
|
|
/// insertion point must be:
|
|
|
|
///
|
|
|
|
/// 1. Before any terminators.
|
|
|
|
/// 2. After any instructions in InsertAfter.
|
|
|
|
/// 3. Not have any clobbered regunits live.
|
|
|
|
///
|
|
|
|
/// This function sets InsertionPoint and returns true when successful, it
|
|
|
|
/// returns false if no valid insertion point could be found.
|
|
|
|
///
|
|
|
|
bool SSAIfConv::findInsertionPoint() {
|
|
|
|
// Keep track of live regunits before the current position.
|
|
|
|
// Only track RegUnits that are also in ClobberedRegUnits.
|
|
|
|
LiveRegUnits.clear();
|
|
|
|
SmallVector<unsigned, 8> Reads;
|
|
|
|
MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
|
|
|
|
MachineBasicBlock::iterator I = Head->end();
|
|
|
|
MachineBasicBlock::iterator B = Head->begin();
|
|
|
|
while (I != B) {
|
|
|
|
--I;
|
|
|
|
// Some of the conditional code depends in I.
|
|
|
|
if (InsertAfter.count(I)) {
|
|
|
|
DEBUG(dbgs() << "Can't insert code after " << *I);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update live regunits.
|
|
|
|
for (MIOperands MO(I); MO.isValid(); ++MO) {
|
|
|
|
// We're ignoring regmask operands. That is conservatively correct.
|
|
|
|
if (!MO->isReg())
|
|
|
|
continue;
|
|
|
|
unsigned Reg = MO->getReg();
|
|
|
|
if (!TargetRegisterInfo::isPhysicalRegister(Reg))
|
|
|
|
continue;
|
|
|
|
// I clobbers Reg, so it isn't live before I.
|
|
|
|
if (MO->isDef())
|
|
|
|
for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
|
|
|
|
LiveRegUnits.erase(*Units);
|
|
|
|
// Unless I reads Reg.
|
|
|
|
if (MO->readsReg())
|
|
|
|
Reads.push_back(Reg);
|
|
|
|
}
|
|
|
|
// Anything read by I is live before I.
|
|
|
|
while (!Reads.empty())
|
|
|
|
for (MCRegUnitIterator Units(Reads.pop_back_val(), TRI); Units.isValid();
|
|
|
|
++Units)
|
|
|
|
if (ClobberedRegUnits.test(*Units))
|
|
|
|
LiveRegUnits.insert(*Units);
|
|
|
|
|
|
|
|
// We can't insert before a terminator.
|
|
|
|
if (I != FirstTerm && I->isTerminator())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Some of the clobbered registers are live before I, not a valid insertion
|
|
|
|
// point.
|
|
|
|
if (!LiveRegUnits.empty()) {
|
|
|
|
DEBUG({
|
|
|
|
dbgs() << "Would clobber";
|
|
|
|
for (SparseSet<unsigned>::const_iterator
|
|
|
|
i = LiveRegUnits.begin(), e = LiveRegUnits.end(); i != e; ++i)
|
|
|
|
dbgs() << ' ' << PrintRegUnit(*i, TRI);
|
|
|
|
dbgs() << " live before " << *I;
|
|
|
|
});
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a valid insertion point.
|
|
|
|
InsertionPoint = I;
|
|
|
|
DEBUG(dbgs() << "Can insert before " << *I);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
DEBUG(dbgs() << "No legal insertion point found.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// canConvertIf - analyze the sub-cfg rooted in MBB, and return true if it is
|
|
|
|
/// a potential candidate for if-conversion. Fill out the internal state.
|
|
|
|
///
|
|
|
|
bool SSAIfConv::canConvertIf(MachineBasicBlock *MBB) {
|
|
|
|
Head = MBB;
|
|
|
|
TBB = FBB = Tail = 0;
|
|
|
|
|
|
|
|
if (Head->succ_size() != 2)
|
|
|
|
return false;
|
|
|
|
MachineBasicBlock *Succ0 = Head->succ_begin()[0];
|
|
|
|
MachineBasicBlock *Succ1 = Head->succ_begin()[1];
|
|
|
|
|
|
|
|
// Canonicalize so Succ0 has MBB as its single predecessor.
|
|
|
|
if (Succ0->pred_size() != 1)
|
|
|
|
std::swap(Succ0, Succ1);
|
|
|
|
|
|
|
|
if (Succ0->pred_size() != 1 || Succ0->succ_size() != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Tail = Succ0->succ_begin()[0];
|
|
|
|
|
|
|
|
// This is not a triangle.
|
|
|
|
if (Tail != Succ1) {
|
|
|
|
// Check for a diamond. We won't deal with any critical edges.
|
|
|
|
if (Succ1->pred_size() != 1 || Succ1->succ_size() != 1 ||
|
|
|
|
Succ1->succ_begin()[0] != Tail)
|
|
|
|
return false;
|
|
|
|
DEBUG(dbgs() << "\nDiamond: BB#" << Head->getNumber()
|
|
|
|
<< " -> BB#" << Succ0->getNumber()
|
|
|
|
<< "/BB#" << Succ1->getNumber()
|
|
|
|
<< " -> BB#" << Tail->getNumber() << '\n');
|
|
|
|
|
|
|
|
// Live-in physregs are tricky to get right when speculating code.
|
|
|
|
if (!Tail->livein_empty()) {
|
|
|
|
DEBUG(dbgs() << "Tail has live-ins.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DEBUG(dbgs() << "\nTriangle: BB#" << Head->getNumber()
|
|
|
|
<< " -> BB#" << Succ0->getNumber()
|
|
|
|
<< " -> BB#" << Tail->getNumber() << '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a triangle or a diamond.
|
|
|
|
// If Tail doesn't have any phis, there must be side effects.
|
|
|
|
if (Tail->empty() || !Tail->front().isPHI()) {
|
|
|
|
DEBUG(dbgs() << "No phis in tail.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The branch we're looking to eliminate must be analyzable.
|
|
|
|
Cond.clear();
|
|
|
|
if (TII->AnalyzeBranch(*Head, TBB, FBB, Cond)) {
|
|
|
|
DEBUG(dbgs() << "Branch not analyzable.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is weird, probably some sort of degenerate CFG.
|
|
|
|
if (!TBB) {
|
|
|
|
DEBUG(dbgs() << "AnalyzeBranch didn't find conditional branch.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnalyzeBranch doesn't set FBB on a fall-through branch.
|
|
|
|
// Make sure it is always set.
|
|
|
|
FBB = TBB == Succ0 ? Succ1 : Succ0;
|
|
|
|
|
|
|
|
// Any phis in the tail block must be convertible to selects.
|
|
|
|
PHIs.clear();
|
2012-08-10 22:19:17 +02:00
|
|
|
MachineBasicBlock *TPred = getTPred();
|
|
|
|
MachineBasicBlock *FPred = getFPred();
|
2012-07-04 02:09:54 +02:00
|
|
|
for (MachineBasicBlock::iterator I = Tail->begin(), E = Tail->end();
|
|
|
|
I != E && I->isPHI(); ++I) {
|
|
|
|
PHIs.push_back(&*I);
|
|
|
|
PHIInfo &PI = PHIs.back();
|
|
|
|
// Find PHI operands corresponding to TPred and FPred.
|
|
|
|
for (unsigned i = 1; i != PI.PHI->getNumOperands(); i += 2) {
|
|
|
|
if (PI.PHI->getOperand(i+1).getMBB() == TPred)
|
|
|
|
PI.TReg = PI.PHI->getOperand(i).getReg();
|
|
|
|
if (PI.PHI->getOperand(i+1).getMBB() == FPred)
|
|
|
|
PI.FReg = PI.PHI->getOperand(i).getReg();
|
|
|
|
}
|
|
|
|
assert(TargetRegisterInfo::isVirtualRegister(PI.TReg) && "Bad PHI");
|
|
|
|
assert(TargetRegisterInfo::isVirtualRegister(PI.FReg) && "Bad PHI");
|
|
|
|
|
|
|
|
// Get target information.
|
|
|
|
if (!TII->canInsertSelect(*Head, Cond, PI.TReg, PI.FReg,
|
|
|
|
PI.CondCycles, PI.TCycles, PI.FCycles)) {
|
|
|
|
DEBUG(dbgs() << "Can't convert: " << *PI.PHI);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the conditional instructions can be speculated.
|
|
|
|
InsertAfter.clear();
|
|
|
|
ClobberedRegUnits.reset();
|
|
|
|
if (TBB != Tail && !canSpeculateInstrs(TBB))
|
|
|
|
return false;
|
|
|
|
if (FBB != Tail && !canSpeculateInstrs(FBB))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Try to find a valid insertion point for the speculated instructions in the
|
|
|
|
// head basic block.
|
|
|
|
if (!findInsertionPoint())
|
|
|
|
return false;
|
|
|
|
|
2012-08-13 23:03:27 +02:00
|
|
|
if (isTriangle())
|
|
|
|
++NumTrianglesSeen;
|
|
|
|
else
|
|
|
|
++NumDiamondsSeen;
|
2012-07-04 02:09:54 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-13 22:49:04 +02:00
|
|
|
/// replacePHIInstrs - Completely replace PHI instructions with selects.
|
|
|
|
/// This is possible when the only Tail predecessors are the if-converted
|
|
|
|
/// blocks.
|
|
|
|
void SSAIfConv::replacePHIInstrs() {
|
|
|
|
assert(Tail->pred_size() == 2 && "Cannot replace PHIs");
|
2012-07-04 02:09:54 +02:00
|
|
|
MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
|
|
|
|
assert(FirstTerm != Head->end() && "No terminators");
|
|
|
|
DebugLoc HeadDL = FirstTerm->getDebugLoc();
|
|
|
|
|
|
|
|
// Convert all PHIs to select instructions inserted before FirstTerm.
|
|
|
|
for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
|
|
|
|
PHIInfo &PI = PHIs[i];
|
|
|
|
DEBUG(dbgs() << "If-converting " << *PI.PHI);
|
|
|
|
unsigned DstReg = PI.PHI->getOperand(0).getReg();
|
|
|
|
TII->insertSelect(*Head, FirstTerm, HeadDL, DstReg, Cond, PI.TReg, PI.FReg);
|
|
|
|
DEBUG(dbgs() << " --> " << *llvm::prior(FirstTerm));
|
|
|
|
PI.PHI->eraseFromParent();
|
|
|
|
PI.PHI = 0;
|
|
|
|
}
|
2012-08-13 22:49:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// rewritePHIOperands - When there are additional Tail predecessors, insert
|
|
|
|
/// select instructions in Head and rewrite PHI operands to use the selects.
|
|
|
|
/// Keep the PHI instructions in Tail to handle the other predecessors.
|
|
|
|
void SSAIfConv::rewritePHIOperands() {
|
|
|
|
MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
|
|
|
|
assert(FirstTerm != Head->end() && "No terminators");
|
|
|
|
DebugLoc HeadDL = FirstTerm->getDebugLoc();
|
|
|
|
|
|
|
|
// Convert all PHIs to select instructions inserted before FirstTerm.
|
|
|
|
for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
|
|
|
|
PHIInfo &PI = PHIs[i];
|
|
|
|
DEBUG(dbgs() << "If-converting " << *PI.PHI);
|
|
|
|
unsigned PHIDst = PI.PHI->getOperand(0).getReg();
|
|
|
|
unsigned DstReg = MRI->createVirtualRegister(MRI->getRegClass(PHIDst));
|
|
|
|
TII->insertSelect(*Head, FirstTerm, HeadDL, DstReg, Cond, PI.TReg, PI.FReg);
|
|
|
|
DEBUG(dbgs() << " --> " << *llvm::prior(FirstTerm));
|
|
|
|
|
|
|
|
// Rewrite PHI operands TPred -> (DstReg, Head), remove FPred.
|
|
|
|
for (unsigned i = PI.PHI->getNumOperands(); i != 1; i -= 2) {
|
|
|
|
MachineBasicBlock *MBB = PI.PHI->getOperand(i-1).getMBB();
|
|
|
|
if (MBB == getTPred()) {
|
|
|
|
PI.PHI->getOperand(i-1).setMBB(Head);
|
|
|
|
PI.PHI->getOperand(i-2).setReg(DstReg);
|
|
|
|
} else if (MBB == getFPred()) {
|
|
|
|
PI.PHI->RemoveOperand(i-1);
|
|
|
|
PI.PHI->RemoveOperand(i-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEBUG(dbgs() << " --> " << *PI.PHI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// convertIf - Execute the if conversion after canConvertIf has determined the
|
|
|
|
/// feasibility.
|
|
|
|
///
|
|
|
|
/// Any basic blocks erased will be added to RemovedBlocks.
|
|
|
|
///
|
|
|
|
void SSAIfConv::convertIf(SmallVectorImpl<MachineBasicBlock*> &RemovedBlocks) {
|
|
|
|
assert(Head && Tail && TBB && FBB && "Call canConvertIf first.");
|
|
|
|
|
2012-08-13 23:03:27 +02:00
|
|
|
// Update statistics.
|
|
|
|
if (isTriangle())
|
|
|
|
++NumTrianglesConv;
|
|
|
|
else
|
|
|
|
++NumDiamondsConv;
|
|
|
|
|
2012-08-13 22:49:04 +02:00
|
|
|
// Move all instructions into Head, except for the terminators.
|
|
|
|
if (TBB != Tail)
|
|
|
|
Head->splice(InsertionPoint, TBB, TBB->begin(), TBB->getFirstTerminator());
|
|
|
|
if (FBB != Tail)
|
|
|
|
Head->splice(InsertionPoint, FBB, FBB->begin(), FBB->getFirstTerminator());
|
|
|
|
|
|
|
|
// Are there extra Tail predecessors?
|
|
|
|
bool ExtraPreds = Tail->pred_size() != 2;
|
|
|
|
if (ExtraPreds)
|
|
|
|
rewritePHIOperands();
|
|
|
|
else
|
|
|
|
replacePHIInstrs();
|
2012-07-04 02:09:54 +02:00
|
|
|
|
|
|
|
// Fix up the CFG, temporarily leave Head without any successors.
|
|
|
|
Head->removeSuccessor(TBB);
|
|
|
|
Head->removeSuccessor(FBB);
|
|
|
|
if (TBB != Tail)
|
|
|
|
TBB->removeSuccessor(Tail);
|
|
|
|
if (FBB != Tail)
|
|
|
|
FBB->removeSuccessor(Tail);
|
|
|
|
|
|
|
|
// Fix up Head's terminators.
|
|
|
|
// It should become a single branch or a fallthrough.
|
2012-08-13 22:49:04 +02:00
|
|
|
DebugLoc HeadDL = Head->getFirstTerminator()->getDebugLoc();
|
2012-07-04 02:09:54 +02:00
|
|
|
TII->RemoveBranch(*Head);
|
|
|
|
|
|
|
|
// Erase the now empty conditional blocks. It is likely that Head can fall
|
|
|
|
// through to Tail, and we can join the two blocks.
|
2012-07-11 00:18:23 +02:00
|
|
|
if (TBB != Tail) {
|
|
|
|
RemovedBlocks.push_back(TBB);
|
|
|
|
TBB->eraseFromParent();
|
|
|
|
}
|
|
|
|
if (FBB != Tail) {
|
|
|
|
RemovedBlocks.push_back(FBB);
|
|
|
|
FBB->eraseFromParent();
|
|
|
|
}
|
2012-07-04 02:09:54 +02:00
|
|
|
|
|
|
|
assert(Head->succ_empty() && "Additional head successors?");
|
2012-08-13 22:49:04 +02:00
|
|
|
if (!ExtraPreds && Head->isLayoutSuccessor(Tail)) {
|
2012-07-04 02:09:54 +02:00
|
|
|
// Splice Tail onto the end of Head.
|
|
|
|
DEBUG(dbgs() << "Joining tail BB#" << Tail->getNumber()
|
|
|
|
<< " into head BB#" << Head->getNumber() << '\n');
|
|
|
|
Head->splice(Head->end(), Tail,
|
|
|
|
Tail->begin(), Tail->end());
|
|
|
|
Head->transferSuccessorsAndUpdatePHIs(Tail);
|
2012-07-11 00:18:23 +02:00
|
|
|
RemovedBlocks.push_back(Tail);
|
|
|
|
Tail->eraseFromParent();
|
2012-07-04 02:09:54 +02:00
|
|
|
} else {
|
|
|
|
// We need a branch to Tail, let code placement work it out later.
|
|
|
|
DEBUG(dbgs() << "Converting to unconditional branch.\n");
|
|
|
|
SmallVector<MachineOperand, 0> EmptyCond;
|
|
|
|
TII->InsertBranch(*Head, Tail, 0, EmptyCond, HeadDL);
|
|
|
|
Head->addSuccessor(Tail);
|
|
|
|
}
|
|
|
|
DEBUG(dbgs() << *Head);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// EarlyIfConverter Pass
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class EarlyIfConverter : public MachineFunctionPass {
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
const TargetRegisterInfo *TRI;
|
2012-08-08 20:19:58 +02:00
|
|
|
const MCSchedModel *SchedModel;
|
2012-07-04 02:09:54 +02:00
|
|
|
MachineRegisterInfo *MRI;
|
2012-07-11 00:18:23 +02:00
|
|
|
MachineDominatorTree *DomTree;
|
2012-07-11 00:39:56 +02:00
|
|
|
MachineLoopInfo *Loops;
|
2012-07-26 20:38:11 +02:00
|
|
|
MachineTraceMetrics *Traces;
|
|
|
|
MachineTraceMetrics::Ensemble *MinInstr;
|
2012-07-04 02:09:54 +02:00
|
|
|
SSAIfConv IfConv;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
EarlyIfConverter() : MachineFunctionPass(ID) {}
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF);
|
2013-03-08 00:55:51 +01:00
|
|
|
const char *getPassName() const { return "Early If-Conversion"; }
|
2012-07-04 02:09:54 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool tryConvertIf(MachineBasicBlock*);
|
2012-07-11 00:18:23 +02:00
|
|
|
void updateDomTree(ArrayRef<MachineBasicBlock*> Removed);
|
2012-07-11 00:39:56 +02:00
|
|
|
void updateLoops(ArrayRef<MachineBasicBlock*> Removed);
|
2012-07-26 20:38:11 +02:00
|
|
|
void invalidateTraces();
|
|
|
|
bool shouldConvertIf();
|
2012-07-04 02:09:54 +02:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char EarlyIfConverter::ID = 0;
|
|
|
|
char &llvm::EarlyIfConverterID = EarlyIfConverter::ID;
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(EarlyIfConverter,
|
|
|
|
"early-ifcvt", "Early If Converter", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
|
2012-07-11 00:18:23 +02:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
|
2012-07-26 20:38:11 +02:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineTraceMetrics)
|
2012-07-04 02:09:54 +02:00
|
|
|
INITIALIZE_PASS_END(EarlyIfConverter,
|
|
|
|
"early-ifcvt", "Early If Converter", false, false)
|
|
|
|
|
|
|
|
void EarlyIfConverter::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<MachineBranchProbabilityInfo>();
|
2012-07-11 00:18:23 +02:00
|
|
|
AU.addRequired<MachineDominatorTree>();
|
|
|
|
AU.addPreserved<MachineDominatorTree>();
|
2012-07-11 00:39:56 +02:00
|
|
|
AU.addRequired<MachineLoopInfo>();
|
|
|
|
AU.addPreserved<MachineLoopInfo>();
|
2012-07-26 20:38:11 +02:00
|
|
|
AU.addRequired<MachineTraceMetrics>();
|
|
|
|
AU.addPreserved<MachineTraceMetrics>();
|
2012-07-04 02:09:54 +02:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2012-07-11 00:18:23 +02:00
|
|
|
/// Update the dominator tree after if-conversion erased some blocks.
|
|
|
|
void EarlyIfConverter::updateDomTree(ArrayRef<MachineBasicBlock*> Removed) {
|
|
|
|
// convertIf can remove TBB, FBB, and Tail can be merged into Head.
|
|
|
|
// TBB and FBB should not dominate any blocks.
|
|
|
|
// Tail children should be transferred to Head.
|
|
|
|
MachineDomTreeNode *HeadNode = DomTree->getNode(IfConv.Head);
|
|
|
|
for (unsigned i = 0, e = Removed.size(); i != e; ++i) {
|
|
|
|
MachineDomTreeNode *Node = DomTree->getNode(Removed[i]);
|
|
|
|
assert(Node != HeadNode && "Cannot erase the head node");
|
|
|
|
while (Node->getNumChildren()) {
|
|
|
|
assert(Node->getBlock() == IfConv.Tail && "Unexpected children");
|
|
|
|
DomTree->changeImmediateDominator(Node->getChildren().back(), HeadNode);
|
|
|
|
}
|
|
|
|
DomTree->eraseNode(Removed[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-11 00:39:56 +02:00
|
|
|
/// Update LoopInfo after if-conversion.
|
|
|
|
void EarlyIfConverter::updateLoops(ArrayRef<MachineBasicBlock*> Removed) {
|
|
|
|
if (!Loops)
|
|
|
|
return;
|
|
|
|
// If-conversion doesn't change loop structure, and it doesn't mess with back
|
|
|
|
// edges, so updating LoopInfo is simply removing the dead blocks.
|
|
|
|
for (unsigned i = 0, e = Removed.size(); i != e; ++i)
|
|
|
|
Loops->removeBlock(Removed[i]);
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:38:11 +02:00
|
|
|
/// Invalidate MachineTraceMetrics before if-conversion.
|
|
|
|
void EarlyIfConverter::invalidateTraces() {
|
2012-07-30 22:57:50 +02:00
|
|
|
Traces->verifyAnalysis();
|
2012-07-26 20:38:11 +02:00
|
|
|
Traces->invalidate(IfConv.Head);
|
|
|
|
Traces->invalidate(IfConv.Tail);
|
|
|
|
Traces->invalidate(IfConv.TBB);
|
|
|
|
Traces->invalidate(IfConv.FBB);
|
2012-07-30 22:57:50 +02:00
|
|
|
Traces->verifyAnalysis();
|
2012-07-26 20:38:11 +02:00
|
|
|
}
|
|
|
|
|
2012-08-11 00:27:31 +02:00
|
|
|
// Adjust cycles with downward saturation.
|
|
|
|
static unsigned adjCycles(unsigned Cyc, int Delta) {
|
|
|
|
if (Delta < 0 && Cyc + Delta > Cyc)
|
|
|
|
return 0;
|
|
|
|
return Cyc + Delta;
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:38:11 +02:00
|
|
|
/// Apply cost model and heuristics to the if-conversion in IfConv.
|
|
|
|
/// Return true if the conversion is a good idea.
|
|
|
|
///
|
|
|
|
bool EarlyIfConverter::shouldConvertIf() {
|
2012-08-08 20:24:23 +02:00
|
|
|
// Stress testing mode disables all cost considerations.
|
|
|
|
if (Stress)
|
|
|
|
return true;
|
|
|
|
|
2012-07-26 20:38:11 +02:00
|
|
|
if (!MinInstr)
|
|
|
|
MinInstr = Traces->getEnsemble(MachineTraceMetrics::TS_MinInstrCount);
|
2012-08-07 20:02:19 +02:00
|
|
|
|
2012-08-11 00:27:31 +02:00
|
|
|
MachineTraceMetrics::Trace TBBTrace = MinInstr->getTrace(IfConv.getTPred());
|
|
|
|
MachineTraceMetrics::Trace FBBTrace = MinInstr->getTrace(IfConv.getFPred());
|
2012-08-07 20:02:19 +02:00
|
|
|
DEBUG(dbgs() << "TBB: " << TBBTrace << "FBB: " << FBBTrace);
|
2012-08-11 00:27:31 +02:00
|
|
|
unsigned MinCrit = std::min(TBBTrace.getCriticalPath(),
|
|
|
|
FBBTrace.getCriticalPath());
|
|
|
|
|
|
|
|
// Set a somewhat arbitrary limit on the critical path extension we accept.
|
|
|
|
unsigned CritLimit = SchedModel->MispredictPenalty/2;
|
|
|
|
|
|
|
|
// If-conversion only makes sense when there is unexploited ILP. Compute the
|
|
|
|
// maximum-ILP resource length of the trace after if-conversion. Compare it
|
|
|
|
// to the shortest critical path.
|
|
|
|
SmallVector<const MachineBasicBlock*, 1> ExtraBlocks;
|
|
|
|
if (IfConv.TBB != IfConv.Tail)
|
|
|
|
ExtraBlocks.push_back(IfConv.TBB);
|
|
|
|
unsigned ResLength = FBBTrace.getResourceLength(ExtraBlocks);
|
|
|
|
DEBUG(dbgs() << "Resource length " << ResLength
|
|
|
|
<< ", minimal critical path " << MinCrit << '\n');
|
|
|
|
if (ResLength > MinCrit + CritLimit) {
|
|
|
|
DEBUG(dbgs() << "Not enough available ILP.\n");
|
2012-08-07 20:02:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-11 00:27:31 +02:00
|
|
|
|
|
|
|
// Assume that the depth of the first head terminator will also be the depth
|
|
|
|
// of the select instruction inserted, as determined by the flag dependency.
|
|
|
|
// TBB / FBB data dependencies may delay the select even more.
|
|
|
|
MachineTraceMetrics::Trace HeadTrace = MinInstr->getTrace(IfConv.Head);
|
|
|
|
unsigned BranchDepth =
|
|
|
|
HeadTrace.getInstrCycles(IfConv.Head->getFirstTerminator()).Depth;
|
|
|
|
DEBUG(dbgs() << "Branch depth: " << BranchDepth << '\n');
|
|
|
|
|
|
|
|
// Look at all the tail phis, and compute the critical path extension caused
|
|
|
|
// by inserting select instructions.
|
|
|
|
MachineTraceMetrics::Trace TailTrace = MinInstr->getTrace(IfConv.Tail);
|
|
|
|
for (unsigned i = 0, e = IfConv.PHIs.size(); i != e; ++i) {
|
|
|
|
SSAIfConv::PHIInfo &PI = IfConv.PHIs[i];
|
|
|
|
unsigned Slack = TailTrace.getInstrSlack(PI.PHI);
|
|
|
|
unsigned MaxDepth = Slack + TailTrace.getInstrCycles(PI.PHI).Depth;
|
|
|
|
DEBUG(dbgs() << "Slack " << Slack << ":\t" << *PI.PHI);
|
|
|
|
|
|
|
|
// The condition is pulled into the critical path.
|
|
|
|
unsigned CondDepth = adjCycles(BranchDepth, PI.CondCycles);
|
|
|
|
if (CondDepth > MaxDepth) {
|
|
|
|
unsigned Extra = CondDepth - MaxDepth;
|
|
|
|
DEBUG(dbgs() << "Condition adds " << Extra << " cycles.\n");
|
|
|
|
if (Extra > CritLimit) {
|
|
|
|
DEBUG(dbgs() << "Exceeds limit of " << CritLimit << '\n');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The TBB value is pulled into the critical path.
|
|
|
|
unsigned TDepth = adjCycles(TBBTrace.getPHIDepth(PI.PHI), PI.TCycles);
|
|
|
|
if (TDepth > MaxDepth) {
|
|
|
|
unsigned Extra = TDepth - MaxDepth;
|
|
|
|
DEBUG(dbgs() << "TBB data adds " << Extra << " cycles.\n");
|
|
|
|
if (Extra > CritLimit) {
|
|
|
|
DEBUG(dbgs() << "Exceeds limit of " << CritLimit << '\n');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The FBB value is pulled into the critical path.
|
|
|
|
unsigned FDepth = adjCycles(FBBTrace.getPHIDepth(PI.PHI), PI.FCycles);
|
|
|
|
if (FDepth > MaxDepth) {
|
|
|
|
unsigned Extra = FDepth - MaxDepth;
|
|
|
|
DEBUG(dbgs() << "FBB data adds " << Extra << " cycles.\n");
|
|
|
|
if (Extra > CritLimit) {
|
|
|
|
DEBUG(dbgs() << "Exceeds limit of " << CritLimit << '\n');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 20:38:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-04 02:09:54 +02:00
|
|
|
/// Attempt repeated if-conversion on MBB, return true if successful.
|
|
|
|
///
|
|
|
|
bool EarlyIfConverter::tryConvertIf(MachineBasicBlock *MBB) {
|
2012-07-11 00:18:23 +02:00
|
|
|
bool Changed = false;
|
2012-07-26 20:38:11 +02:00
|
|
|
while (IfConv.canConvertIf(MBB) && shouldConvertIf()) {
|
2012-07-11 00:18:23 +02:00
|
|
|
// If-convert MBB and update analyses.
|
2012-07-26 20:38:11 +02:00
|
|
|
invalidateTraces();
|
2012-07-11 00:18:23 +02:00
|
|
|
SmallVector<MachineBasicBlock*, 4> RemovedBlocks;
|
|
|
|
IfConv.convertIf(RemovedBlocks);
|
|
|
|
Changed = true;
|
|
|
|
updateDomTree(RemovedBlocks);
|
2012-07-11 00:39:56 +02:00
|
|
|
updateLoops(RemovedBlocks);
|
2012-07-11 00:18:23 +02:00
|
|
|
}
|
|
|
|
return Changed;
|
2012-07-04 02:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
DEBUG(dbgs() << "********** EARLY IF-CONVERSION **********\n"
|
2012-08-22 19:18:53 +02:00
|
|
|
<< "********** Function: " << MF.getName() << '\n');
|
2012-07-04 02:09:54 +02:00
|
|
|
TII = MF.getTarget().getInstrInfo();
|
|
|
|
TRI = MF.getTarget().getRegisterInfo();
|
2012-10-04 19:30:43 +02:00
|
|
|
SchedModel =
|
|
|
|
MF.getTarget().getSubtarget<TargetSubtargetInfo>().getSchedModel();
|
2012-07-04 02:09:54 +02:00
|
|
|
MRI = &MF.getRegInfo();
|
2012-07-11 00:18:23 +02:00
|
|
|
DomTree = &getAnalysis<MachineDominatorTree>();
|
2012-07-11 00:39:56 +02:00
|
|
|
Loops = getAnalysisIfAvailable<MachineLoopInfo>();
|
2012-07-26 20:38:11 +02:00
|
|
|
Traces = &getAnalysis<MachineTraceMetrics>();
|
|
|
|
MinInstr = 0;
|
2012-07-04 02:09:54 +02:00
|
|
|
|
|
|
|
bool Changed = false;
|
|
|
|
IfConv.runOnMachineFunction(MF);
|
|
|
|
|
2012-07-11 00:18:23 +02:00
|
|
|
// Visit blocks in dominator tree post-order. The post-order enables nested
|
|
|
|
// if-conversion in a single pass. The tryConvertIf() function may erase
|
|
|
|
// blocks, but only blocks dominated by the head block. This makes it safe to
|
|
|
|
// update the dominator tree while the post-order iterator is still active.
|
|
|
|
for (po_iterator<MachineDominatorTree*>
|
|
|
|
I = po_begin(DomTree), E = po_end(DomTree); I != E; ++I)
|
|
|
|
if (tryConvertIf(I->getBlock()))
|
2012-07-04 02:09:54 +02:00
|
|
|
Changed = true;
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|