2008-12-08 17:50:35 +00:00
|
|
|
//===---- ScheduleDAGInstrs.cpp - MachineInstr Rescheduling ---------------===//
|
2008-11-19 23:18:57 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-12-08 17:50:35 +00:00
|
|
|
// This implements the ScheduleDAGInstrs class, which implements re-scheduling
|
|
|
|
// of MachineInstrs.
|
2008-11-19 23:18:57 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "sched-instrs"
|
2009-07-17 20:58:59 +00:00
|
|
|
#include "llvm/Operator.h"
|
2009-01-30 02:49:14 +00:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2010-12-15 20:02:24 +00:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2012-02-22 06:08:11 +00:00
|
|
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
2008-12-16 03:25:46 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2009-09-25 20:36:54 +00:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2008-12-16 03:25:46 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2008-12-04 01:35:46 +00:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2012-06-06 19:47:35 +00:00
|
|
|
#include "llvm/CodeGen/RegisterPressure.h"
|
2012-03-07 23:01:06 +00:00
|
|
|
#include "llvm/CodeGen/ScheduleDAGInstrs.h"
|
2011-06-29 01:14:12 +00:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2008-11-19 23:18:57 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2011-07-01 21:01:15 +00:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2012-05-15 18:59:41 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2008-11-19 23:18:57 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-12-16 03:25:46 +00:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2012-05-15 18:59:41 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2008-11-19 23:18:57 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2012-05-15 18:59:41 +00:00
|
|
|
static cl::opt<bool> EnableAASchedMI("enable-aa-sched-mi", cl::Hidden,
|
|
|
|
cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Enable use of AA during MI GAD construction"));
|
|
|
|
|
2009-01-15 19:20:50 +00:00
|
|
|
ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf,
|
2008-12-16 03:25:46 +00:00
|
|
|
const MachineLoopInfo &mli,
|
2012-01-14 02:17:12 +00:00
|
|
|
const MachineDominatorTree &mdt,
|
2012-02-22 06:08:11 +00:00
|
|
|
bool IsPostRAFlag,
|
|
|
|
LiveIntervals *lis)
|
2010-09-10 01:29:16 +00:00
|
|
|
: ScheduleDAG(mf), MLI(mli), MDT(mdt), MFI(mf.getFrameInfo()),
|
2012-03-07 23:00:59 +00:00
|
|
|
InstrItins(mf.getTarget().getInstrItineraryData()), LIS(lis),
|
2012-04-13 23:29:54 +00:00
|
|
|
IsPostRA(IsPostRAFlag), UnitLatencies(false), CanHandleTerminators(false),
|
2012-06-06 18:25:08 +00:00
|
|
|
LoopRegs(MDT), FirstDbgValue(0) {
|
2012-02-22 06:08:11 +00:00
|
|
|
assert((IsPostRA || LIS) && "PreRA scheduling requires LiveIntervals");
|
2011-06-02 20:07:12 +00:00
|
|
|
DbgValues.clear();
|
2012-02-22 06:08:13 +00:00
|
|
|
assert(!(IsPostRA && MRI.getNumVirtRegs()) &&
|
2012-02-21 04:51:23 +00:00
|
|
|
"Virtual registers must be removed prior to PostRA scheduling");
|
2009-10-18 19:58:47 +00:00
|
|
|
}
|
2008-11-19 23:18:57 +00:00
|
|
|
|
2009-01-30 02:49:14 +00:00
|
|
|
/// getUnderlyingObjectFromInt - This is the function that does the work of
|
|
|
|
/// looking through basic ptrtoint+arithmetic+inttoptr sequences.
|
|
|
|
static const Value *getUnderlyingObjectFromInt(const Value *V) {
|
|
|
|
do {
|
2009-07-17 20:58:59 +00:00
|
|
|
if (const Operator *U = dyn_cast<Operator>(V)) {
|
2009-01-30 02:49:14 +00:00
|
|
|
// If we find a ptrtoint, we can transfer control back to the
|
|
|
|
// regular getUnderlyingObjectFromInt.
|
2009-07-17 20:58:59 +00:00
|
|
|
if (U->getOpcode() == Instruction::PtrToInt)
|
2009-01-30 02:49:14 +00:00
|
|
|
return U->getOperand(0);
|
|
|
|
// If we find an add of a constant or a multiplied value, it's
|
|
|
|
// likely that the other operand will lead us to the base
|
|
|
|
// object. We don't have to worry about the case where the
|
2009-08-07 01:26:06 +00:00
|
|
|
// object address is somehow being computed by the multiply,
|
2009-01-30 02:49:14 +00:00
|
|
|
// because our callers only care when the result is an
|
|
|
|
// identifibale object.
|
2009-07-17 20:58:59 +00:00
|
|
|
if (U->getOpcode() != Instruction::Add ||
|
2009-01-30 02:49:14 +00:00
|
|
|
(!isa<ConstantInt>(U->getOperand(1)) &&
|
2009-07-17 20:58:59 +00:00
|
|
|
Operator::getOpcode(U->getOperand(1)) != Instruction::Mul))
|
2009-01-30 02:49:14 +00:00
|
|
|
return V;
|
|
|
|
V = U->getOperand(0);
|
|
|
|
} else {
|
|
|
|
return V;
|
|
|
|
}
|
2010-02-16 11:11:14 +00:00
|
|
|
assert(V->getType()->isIntegerTy() && "Unexpected operand type!");
|
2009-01-30 02:49:14 +00:00
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2010-12-15 20:02:24 +00:00
|
|
|
/// getUnderlyingObject - This is a wrapper around GetUnderlyingObject
|
2009-01-30 02:49:14 +00:00
|
|
|
/// and adds support for basic ptrtoint+arithmetic+inttoptr sequences.
|
|
|
|
static const Value *getUnderlyingObject(const Value *V) {
|
|
|
|
// First just call Value::getUnderlyingObject to let it do what it does.
|
|
|
|
do {
|
2010-12-15 20:02:24 +00:00
|
|
|
V = GetUnderlyingObject(V);
|
2009-01-30 02:49:14 +00:00
|
|
|
// If it found an inttoptr, use special code to continue climing.
|
2009-07-17 20:58:59 +00:00
|
|
|
if (Operator::getOpcode(V) != Instruction::IntToPtr)
|
2009-01-30 02:49:14 +00:00
|
|
|
break;
|
|
|
|
const Value *O = getUnderlyingObjectFromInt(cast<User>(V)->getOperand(0));
|
|
|
|
// If that succeeded in finding a pointer, continue the search.
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!O->getType()->isPointerTy())
|
2009-01-30 02:49:14 +00:00
|
|
|
break;
|
|
|
|
V = O;
|
|
|
|
} while (1);
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getUnderlyingObjectForInstr - If this machine instr has memory reference
|
|
|
|
/// information and it can be tracked to a normal reference to a known
|
|
|
|
/// object, return the Value for that object. Otherwise return null.
|
2009-10-18 19:58:47 +00:00
|
|
|
static const Value *getUnderlyingObjectForInstr(const MachineInstr *MI,
|
2009-11-03 20:15:00 +00:00
|
|
|
const MachineFrameInfo *MFI,
|
|
|
|
bool &MayAlias) {
|
|
|
|
MayAlias = true;
|
2009-01-30 02:49:14 +00:00
|
|
|
if (!MI->hasOneMemOperand() ||
|
2009-09-25 20:36:54 +00:00
|
|
|
!(*MI->memoperands_begin())->getValue() ||
|
|
|
|
(*MI->memoperands_begin())->isVolatile())
|
2009-01-30 02:49:14 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-09-25 20:36:54 +00:00
|
|
|
const Value *V = (*MI->memoperands_begin())->getValue();
|
2009-01-30 02:49:14 +00:00
|
|
|
if (!V)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
V = getUnderlyingObject(V);
|
2009-10-18 18:16:27 +00:00
|
|
|
if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
|
|
|
|
// For now, ignore PseudoSourceValues which may alias LLVM IR values
|
|
|
|
// because the code that uses this function has no way to cope with
|
|
|
|
// such aliases.
|
2009-10-18 19:58:47 +00:00
|
|
|
if (PSV->isAliased(MFI))
|
2009-10-18 18:16:27 +00:00
|
|
|
return 0;
|
2011-05-05 19:24:06 +00:00
|
|
|
|
2009-11-09 19:22:17 +00:00
|
|
|
MayAlias = PSV->mayAlias(MFI);
|
2009-10-18 18:16:27 +00:00
|
|
|
return V;
|
|
|
|
}
|
2009-01-30 02:49:14 +00:00
|
|
|
|
2009-10-18 18:16:27 +00:00
|
|
|
if (isIdentifiedObject(V))
|
|
|
|
return V;
|
|
|
|
|
|
|
|
return 0;
|
2009-01-30 02:49:14 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 20:05:21 +00:00
|
|
|
void ScheduleDAGInstrs::startBlock(MachineBasicBlock *bb) {
|
|
|
|
BB = bb;
|
2011-10-07 06:33:09 +00:00
|
|
|
LoopRegs.Deps.clear();
|
2009-02-10 23:27:53 +00:00
|
|
|
if (MachineLoop *ML = MLI.getLoopFor(BB))
|
2012-01-07 03:02:36 +00:00
|
|
|
if (BB == ML->getLoopLatch())
|
2009-02-10 23:27:53 +00:00
|
|
|
LoopRegs.VisitLoop(ML);
|
|
|
|
}
|
|
|
|
|
2012-03-07 23:00:49 +00:00
|
|
|
void ScheduleDAGInstrs::finishBlock() {
|
2012-04-20 20:24:33 +00:00
|
|
|
// Subclasses should no longer refer to the old block.
|
2012-04-20 20:05:21 +00:00
|
|
|
BB = 0;
|
2012-03-07 05:21:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 07:04:55 +00:00
|
|
|
/// Initialize the map with the number of registers.
|
2012-03-07 23:00:57 +00:00
|
|
|
void Reg2SUnitsMap::setRegLimit(unsigned Limit) {
|
2012-02-24 07:04:55 +00:00
|
|
|
PhysRegSet.setUniverse(Limit);
|
|
|
|
SUnits.resize(Limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Clear the map without deallocating storage.
|
2012-03-07 23:00:57 +00:00
|
|
|
void Reg2SUnitsMap::clear() {
|
2012-02-24 07:04:55 +00:00
|
|
|
for (const_iterator I = reg_begin(), E = reg_end(); I != E; ++I) {
|
|
|
|
SUnits[*I].clear();
|
|
|
|
}
|
|
|
|
PhysRegSet.clear();
|
|
|
|
}
|
|
|
|
|
2012-03-07 05:21:52 +00:00
|
|
|
/// Initialize the DAG and common scheduler state for the current scheduling
|
|
|
|
/// region. This does not actually create the DAG, only clears it. The
|
|
|
|
/// scheduling driver may call BuildSchedGraph multiple times per scheduling
|
|
|
|
/// region.
|
|
|
|
void ScheduleDAGInstrs::enterRegion(MachineBasicBlock *bb,
|
|
|
|
MachineBasicBlock::iterator begin,
|
|
|
|
MachineBasicBlock::iterator end,
|
|
|
|
unsigned endcount) {
|
2012-04-20 20:05:21 +00:00
|
|
|
assert(bb == BB && "startBlock should set BB");
|
2012-03-09 04:29:02 +00:00
|
|
|
RegionBegin = begin;
|
|
|
|
RegionEnd = end;
|
2012-03-07 23:00:52 +00:00
|
|
|
EndIndex = endcount;
|
2012-03-14 04:00:41 +00:00
|
|
|
MISUnitMap.clear();
|
2012-03-07 05:21:52 +00:00
|
|
|
|
|
|
|
// Check to see if the scheduler cares about latencies.
|
2012-03-07 23:00:49 +00:00
|
|
|
UnitLatencies = forceUnitLatencies();
|
2012-03-07 05:21:52 +00:00
|
|
|
|
|
|
|
ScheduleDAG::clearDAG();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Close the current scheduling region. Don't clear any state in case the
|
|
|
|
/// driver wants to refer to the previous scheduling region.
|
|
|
|
void ScheduleDAGInstrs::exitRegion() {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
2012-03-07 23:00:49 +00:00
|
|
|
/// addSchedBarrierDeps - Add dependencies from instructions in the current
|
2010-10-23 02:10:46 +00:00
|
|
|
/// list of instructions being scheduled to scheduling barrier by adding
|
|
|
|
/// the exit SU to the register defs and use list. This is because we want to
|
|
|
|
/// make sure instructions which define registers that are either used by
|
|
|
|
/// the terminator or are live-out are properly scheduled. This is
|
|
|
|
/// especially important when the definition latency of the return value(s)
|
|
|
|
/// are too high to be hidden by the branch or when the liveout registers
|
|
|
|
/// used by instructions in the fallthrough block.
|
2012-03-07 23:00:49 +00:00
|
|
|
void ScheduleDAGInstrs::addSchedBarrierDeps() {
|
2012-03-09 04:29:02 +00:00
|
|
|
MachineInstr *ExitMI = RegionEnd != BB->end() ? &*RegionEnd : 0;
|
2010-10-23 02:10:46 +00:00
|
|
|
ExitSU.setInstr(ExitMI);
|
|
|
|
bool AllDepKnown = ExitMI &&
|
2011-12-07 07:15:52 +00:00
|
|
|
(ExitMI->isCall() || ExitMI->isBarrier());
|
2010-10-23 02:10:46 +00:00
|
|
|
if (ExitMI && AllDepKnown) {
|
|
|
|
// If it's a call or a barrier, add dependencies on the defs and uses of
|
|
|
|
// instruction.
|
|
|
|
for (unsigned i = 0, e = ExitMI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = ExitMI->getOperand(i);
|
|
|
|
if (!MO.isReg() || MO.isDef()) continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Reg == 0) continue;
|
|
|
|
|
2012-01-14 02:17:18 +00:00
|
|
|
if (TRI->isPhysicalRegister(Reg))
|
2012-02-24 07:04:55 +00:00
|
|
|
Uses[Reg].push_back(&ExitSU);
|
2012-03-16 05:04:25 +00:00
|
|
|
else {
|
2012-01-14 02:17:18 +00:00
|
|
|
assert(!IsPostRA && "Virtual register encountered after regalloc.");
|
2012-03-16 05:04:25 +00:00
|
|
|
addVRegUseDeps(&ExitSU, i);
|
|
|
|
}
|
2010-10-23 02:10:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For others, e.g. fallthrough, conditional branch, assume the exit
|
2010-10-27 23:17:17 +00:00
|
|
|
// uses all the registers that are livein to the successor blocks.
|
2012-03-16 17:38:19 +00:00
|
|
|
assert(Uses.empty() && "Uses in set before adding deps?");
|
2010-10-27 23:17:17 +00:00
|
|
|
for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
|
|
|
|
SE = BB->succ_end(); SI != SE; ++SI)
|
|
|
|
for (MachineBasicBlock::livein_iterator I = (*SI)->livein_begin(),
|
2011-05-05 19:24:06 +00:00
|
|
|
E = (*SI)->livein_end(); I != E; ++I) {
|
2010-10-27 23:17:17 +00:00
|
|
|
unsigned Reg = *I;
|
2012-03-16 17:38:19 +00:00
|
|
|
if (!Uses.contains(Reg))
|
2012-02-24 07:04:55 +00:00
|
|
|
Uses[Reg].push_back(&ExitSU);
|
2010-10-27 23:17:17 +00:00
|
|
|
}
|
2010-10-23 02:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-23 01:52:38 +00:00
|
|
|
/// MO is an operand of SU's instruction that defines a physical register. Add
|
|
|
|
/// data dependencies from SU to any uses of the physical register.
|
|
|
|
void ScheduleDAGInstrs::addPhysRegDataDeps(SUnit *SU,
|
|
|
|
const MachineOperand &MO) {
|
|
|
|
assert(MO.isDef() && "expect physreg def");
|
2012-01-14 02:17:15 +00:00
|
|
|
|
|
|
|
// Ask the target if address-backscheduling is desirable, and if so how much.
|
|
|
|
const TargetSubtargetInfo &ST = TM.getSubtarget<TargetSubtargetInfo>();
|
|
|
|
unsigned SpecialAddressLatency = ST.getSpecialAddressLatency();
|
2012-02-23 01:52:38 +00:00
|
|
|
unsigned DataLatency = SU->Latency;
|
2012-01-14 02:17:15 +00:00
|
|
|
|
2012-06-01 23:28:30 +00:00
|
|
|
for (MCRegAliasIterator Alias(MO.getReg(), TRI, true);
|
|
|
|
Alias.isValid(); ++Alias) {
|
2012-02-24 07:04:55 +00:00
|
|
|
if (!Uses.contains(*Alias))
|
2012-02-23 01:52:38 +00:00
|
|
|
continue;
|
2012-02-24 07:04:55 +00:00
|
|
|
std::vector<SUnit*> &UseList = Uses[*Alias];
|
2012-01-14 02:17:15 +00:00
|
|
|
for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
|
|
|
|
SUnit *UseSU = UseList[i];
|
|
|
|
if (UseSU == SU)
|
|
|
|
continue;
|
|
|
|
unsigned LDataLatency = DataLatency;
|
|
|
|
// Optionally add in a special extra latency for nodes that
|
|
|
|
// feed addresses.
|
|
|
|
// TODO: Perhaps we should get rid of
|
|
|
|
// SpecialAddressLatency and just move this into
|
|
|
|
// adjustSchedDependency for the targets that care about it.
|
|
|
|
if (SpecialAddressLatency != 0 && !UnitLatencies &&
|
|
|
|
UseSU != &ExitSU) {
|
|
|
|
MachineInstr *UseMI = UseSU->getInstr();
|
|
|
|
const MCInstrDesc &UseMCID = UseMI->getDesc();
|
2012-02-23 01:52:38 +00:00
|
|
|
int RegUseIndex = UseMI->findRegisterUseOperandIdx(*Alias);
|
|
|
|
assert(RegUseIndex >= 0 && "UseMI doesn't use register!");
|
2012-01-14 02:17:15 +00:00
|
|
|
if (RegUseIndex >= 0 &&
|
|
|
|
(UseMI->mayLoad() || UseMI->mayStore()) &&
|
|
|
|
(unsigned)RegUseIndex < UseMCID.getNumOperands() &&
|
|
|
|
UseMCID.OpInfo[RegUseIndex].isLookupPtrRegClass())
|
|
|
|
LDataLatency += SpecialAddressLatency;
|
|
|
|
}
|
|
|
|
// Adjust the dependence latency using operand def/use
|
|
|
|
// information (if any), and then allow the target to
|
|
|
|
// perform its own adjustments.
|
2012-06-05 21:11:27 +00:00
|
|
|
SDep dep(SU, SDep::Data, LDataLatency, *Alias);
|
2012-01-14 02:17:15 +00:00
|
|
|
if (!UnitLatencies) {
|
2012-06-05 21:11:27 +00:00
|
|
|
unsigned Latency = computeOperandLatency(SU, UseSU, dep);
|
|
|
|
dep.setLatency(Latency);
|
|
|
|
|
|
|
|
ST.adjustSchedDependency(SU, UseSU, dep);
|
2012-01-14 02:17:15 +00:00
|
|
|
}
|
|
|
|
UseSU->addPred(dep);
|
|
|
|
}
|
2012-02-23 01:52:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addPhysRegDeps - Add register dependencies (data, anti, and output) from
|
|
|
|
/// this SUnit to following instructions in the same scheduling region that
|
|
|
|
/// depend the physical register referenced at OperIdx.
|
|
|
|
void ScheduleDAGInstrs::addPhysRegDeps(SUnit *SU, unsigned OperIdx) {
|
|
|
|
const MachineInstr *MI = SU->getInstr();
|
|
|
|
const MachineOperand &MO = MI->getOperand(OperIdx);
|
|
|
|
|
|
|
|
// Optionally add output and anti dependencies. For anti
|
|
|
|
// dependencies we use a latency of 0 because for a multi-issue
|
|
|
|
// target we want to allow the defining instruction to issue
|
|
|
|
// in the same cycle as the using instruction.
|
|
|
|
// TODO: Using a latency of 1 here for output dependencies assumes
|
|
|
|
// there's no cost for reusing registers.
|
|
|
|
SDep::Kind Kind = MO.isUse() ? SDep::Anti : SDep::Output;
|
2012-06-01 23:28:30 +00:00
|
|
|
for (MCRegAliasIterator Alias(MO.getReg(), TRI, true);
|
|
|
|
Alias.isValid(); ++Alias) {
|
2012-02-24 07:04:55 +00:00
|
|
|
if (!Defs.contains(*Alias))
|
2012-02-23 01:52:38 +00:00
|
|
|
continue;
|
2012-02-24 07:04:55 +00:00
|
|
|
std::vector<SUnit *> &DefList = Defs[*Alias];
|
2012-02-23 01:52:38 +00:00
|
|
|
for (unsigned i = 0, e = DefList.size(); i != e; ++i) {
|
|
|
|
SUnit *DefSU = DefList[i];
|
|
|
|
if (DefSU == &ExitSU)
|
|
|
|
continue;
|
|
|
|
if (DefSU != SU &&
|
|
|
|
(Kind != SDep::Output || !MO.isDead() ||
|
|
|
|
!DefSU->getInstr()->registerDefIsDead(*Alias))) {
|
|
|
|
if (Kind == SDep::Anti)
|
|
|
|
DefSU->addPred(SDep(SU, Kind, 0, /*Reg=*/*Alias));
|
|
|
|
else {
|
|
|
|
unsigned AOLat = TII->getOutputLatency(InstrItins, MI, OperIdx,
|
|
|
|
DefSU->getInstr());
|
|
|
|
DefSU->addPred(SDep(SU, Kind, AOLat, /*Reg=*/*Alias));
|
2012-01-14 02:17:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-23 01:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!MO.isDef()) {
|
|
|
|
// Either insert a new Reg2SUnits entry with an empty SUnits list, or
|
|
|
|
// retrieve the existing SUnits list for this register's uses.
|
|
|
|
// Push this SUnit on the use list.
|
2012-02-24 07:04:55 +00:00
|
|
|
Uses[MO.getReg()].push_back(SU);
|
2012-02-23 01:52:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPhysRegDataDeps(SU, MO);
|
|
|
|
|
|
|
|
// Either insert a new Reg2SUnits entry with an empty SUnits list, or
|
|
|
|
// retrieve the existing SUnits list for this register's defs.
|
2012-02-24 07:04:55 +00:00
|
|
|
std::vector<SUnit *> &DefList = Defs[MO.getReg()];
|
2012-01-14 02:17:15 +00:00
|
|
|
|
|
|
|
// If a def is going to wrap back around to the top of the loop,
|
|
|
|
// backschedule it.
|
|
|
|
if (!UnitLatencies && DefList.empty()) {
|
2012-02-23 01:52:38 +00:00
|
|
|
LoopDependencies::LoopDeps::iterator I = LoopRegs.Deps.find(MO.getReg());
|
2012-01-14 02:17:15 +00:00
|
|
|
if (I != LoopRegs.Deps.end()) {
|
|
|
|
const MachineOperand *UseMO = I->second.first;
|
|
|
|
unsigned Count = I->second.second;
|
|
|
|
const MachineInstr *UseMI = UseMO->getParent();
|
|
|
|
unsigned UseMOIdx = UseMO - &UseMI->getOperand(0);
|
|
|
|
const MCInstrDesc &UseMCID = UseMI->getDesc();
|
2012-02-23 01:52:38 +00:00
|
|
|
const TargetSubtargetInfo &ST =
|
|
|
|
TM.getSubtarget<TargetSubtargetInfo>();
|
|
|
|
unsigned SpecialAddressLatency = ST.getSpecialAddressLatency();
|
2012-01-14 02:17:15 +00:00
|
|
|
// TODO: If we knew the total depth of the region here, we could
|
|
|
|
// handle the case where the whole loop is inside the region but
|
|
|
|
// is large enough that the isScheduleHigh trick isn't needed.
|
|
|
|
if (UseMOIdx < UseMCID.getNumOperands()) {
|
|
|
|
// Currently, we only support scheduling regions consisting of
|
|
|
|
// single basic blocks. Check to see if the instruction is in
|
|
|
|
// the same region by checking to see if it has the same parent.
|
|
|
|
if (UseMI->getParent() != MI->getParent()) {
|
|
|
|
unsigned Latency = SU->Latency;
|
|
|
|
if (UseMCID.OpInfo[UseMOIdx].isLookupPtrRegClass())
|
|
|
|
Latency += SpecialAddressLatency;
|
|
|
|
// This is a wild guess as to the portion of the latency which
|
|
|
|
// will be overlapped by work done outside the current
|
|
|
|
// scheduling region.
|
|
|
|
Latency -= std::min(Latency, Count);
|
|
|
|
// Add the artificial edge.
|
|
|
|
ExitSU.addPred(SDep(SU, SDep::Order, Latency,
|
|
|
|
/*Reg=*/0, /*isNormalMemory=*/false,
|
|
|
|
/*isMustAlias=*/false,
|
|
|
|
/*isArtificial=*/true));
|
|
|
|
} else if (SpecialAddressLatency > 0 &&
|
|
|
|
UseMCID.OpInfo[UseMOIdx].isLookupPtrRegClass()) {
|
|
|
|
// The entire loop body is within the current scheduling region
|
|
|
|
// and the latency of this operation is assumed to be greater
|
|
|
|
// than the latency of the loop.
|
|
|
|
// TODO: Recursively mark data-edge predecessors as
|
|
|
|
// isScheduleHigh too.
|
|
|
|
SU->isScheduleHigh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LoopRegs.Deps.erase(I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-23 01:52:38 +00:00
|
|
|
// clear this register's use list
|
2012-02-24 07:04:55 +00:00
|
|
|
if (Uses.contains(MO.getReg()))
|
|
|
|
Uses[MO.getReg()].clear();
|
2012-02-23 01:52:38 +00:00
|
|
|
|
2012-01-14 02:17:15 +00:00
|
|
|
if (!MO.isDead())
|
|
|
|
DefList.clear();
|
|
|
|
|
|
|
|
// Calls will not be reordered because of chain dependencies (see
|
|
|
|
// below). Since call operands are dead, calls may continue to be added
|
|
|
|
// to the DefList making dependence checking quadratic in the size of
|
|
|
|
// the block. Instead, we leave only one call at the back of the
|
|
|
|
// DefList.
|
|
|
|
if (SU->isCall) {
|
|
|
|
while (!DefList.empty() && DefList.back()->isCall)
|
|
|
|
DefList.pop_back();
|
|
|
|
}
|
2012-02-23 01:52:38 +00:00
|
|
|
// Defs are pushed in the order they are visited and never reordered.
|
2012-01-14 02:17:15 +00:00
|
|
|
DefList.push_back(SU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 02:17:18 +00:00
|
|
|
/// addVRegDefDeps - Add register output and data dependencies from this SUnit
|
|
|
|
/// to instructions that occur later in the same scheduling region if they read
|
|
|
|
/// from or write to the virtual register defined at OperIdx.
|
|
|
|
///
|
|
|
|
/// TODO: Hoist loop induction variable increments. This has to be
|
|
|
|
/// reevaluated. Generally, IV scheduling should be done before coalescing.
|
|
|
|
void ScheduleDAGInstrs::addVRegDefDeps(SUnit *SU, unsigned OperIdx) {
|
|
|
|
const MachineInstr *MI = SU->getInstr();
|
|
|
|
unsigned Reg = MI->getOperand(OperIdx).getReg();
|
|
|
|
|
2012-02-22 06:08:13 +00:00
|
|
|
// SSA defs do not have output/anti dependencies.
|
2012-02-22 18:34:49 +00:00
|
|
|
// The current operand is a def, so we have at least one.
|
2012-02-22 06:08:13 +00:00
|
|
|
if (llvm::next(MRI.def_begin(Reg)) == MRI.def_end())
|
|
|
|
return;
|
|
|
|
|
2012-01-14 02:17:18 +00:00
|
|
|
// Add output dependence to the next nearest def of this vreg.
|
|
|
|
//
|
|
|
|
// Unless this definition is dead, the output dependence should be
|
|
|
|
// transitively redundant with antidependencies from this definition's
|
|
|
|
// uses. We're conservative for now until we have a way to guarantee the uses
|
|
|
|
// are not eliminated sometime during scheduling. The output dependence edge
|
|
|
|
// is also useful if output latency exceeds def-use latency.
|
2012-04-20 20:05:28 +00:00
|
|
|
VReg2SUnitMap::iterator DefI = VRegDefs.find(Reg);
|
2012-02-22 21:59:00 +00:00
|
|
|
if (DefI == VRegDefs.end())
|
|
|
|
VRegDefs.insert(VReg2SUnit(Reg, SU));
|
|
|
|
else {
|
|
|
|
SUnit *DefSU = DefI->SU;
|
|
|
|
if (DefSU != SU && DefSU != &ExitSU) {
|
|
|
|
unsigned OutLatency = TII->getOutputLatency(InstrItins, MI, OperIdx,
|
|
|
|
DefSU->getInstr());
|
|
|
|
DefSU->addPred(SDep(SU, SDep::Output, OutLatency, Reg));
|
|
|
|
}
|
|
|
|
DefI->SU = SU;
|
2012-01-14 02:17:18 +00:00
|
|
|
}
|
2012-02-22 06:08:11 +00:00
|
|
|
}
|
2012-01-14 02:17:18 +00:00
|
|
|
|
2012-02-22 06:08:11 +00:00
|
|
|
/// addVRegUseDeps - Add a register data dependency if the instruction that
|
|
|
|
/// defines the virtual register used at OperIdx is mapped to an SUnit. Add a
|
|
|
|
/// register antidependency from this SUnit to instructions that occur later in
|
|
|
|
/// the same scheduling region if they write the virtual register.
|
|
|
|
///
|
|
|
|
/// TODO: Handle ExitSU "uses" properly.
|
|
|
|
void ScheduleDAGInstrs::addVRegUseDeps(SUnit *SU, unsigned OperIdx) {
|
|
|
|
MachineInstr *MI = SU->getInstr();
|
|
|
|
unsigned Reg = MI->getOperand(OperIdx).getReg();
|
|
|
|
|
|
|
|
// Lookup this operand's reaching definition.
|
|
|
|
assert(LIS && "vreg dependencies requires LiveIntervals");
|
2012-05-20 02:44:38 +00:00
|
|
|
LiveRangeQuery LRQ(LIS->getInterval(Reg), LIS->getInstructionIndex(MI));
|
|
|
|
VNInfo *VNI = LRQ.valueIn();
|
2012-04-24 18:04:41 +00:00
|
|
|
|
2012-02-23 03:16:24 +00:00
|
|
|
// VNI will be valid because MachineOperand::readsReg() is checked by caller.
|
2012-05-20 02:44:38 +00:00
|
|
|
assert(VNI && "No value to read by operand");
|
2012-02-22 06:08:11 +00:00
|
|
|
MachineInstr *Def = LIS->getInstructionFromIndex(VNI->def);
|
2012-02-23 03:16:24 +00:00
|
|
|
// Phis and other noninstructions (after coalescing) have a NULL Def.
|
2012-02-22 06:08:11 +00:00
|
|
|
if (Def) {
|
|
|
|
SUnit *DefSU = getSUnit(Def);
|
|
|
|
if (DefSU) {
|
|
|
|
// The reaching Def lives within this scheduling region.
|
|
|
|
// Create a data dependence.
|
|
|
|
//
|
|
|
|
// TODO: Handle "special" address latencies cleanly.
|
2012-06-05 21:11:27 +00:00
|
|
|
SDep dep(DefSU, SDep::Data, DefSU->Latency, Reg);
|
2012-02-22 06:08:11 +00:00
|
|
|
if (!UnitLatencies) {
|
|
|
|
// Adjust the dependence latency using operand def/use information, then
|
|
|
|
// allow the target to perform its own adjustments.
|
2012-06-05 21:11:27 +00:00
|
|
|
unsigned Latency = computeOperandLatency(DefSU, SU, const_cast<SDep &>(dep));
|
|
|
|
dep.setLatency(Latency);
|
|
|
|
|
2012-02-22 06:08:11 +00:00
|
|
|
const TargetSubtargetInfo &ST = TM.getSubtarget<TargetSubtargetInfo>();
|
|
|
|
ST.adjustSchedDependency(DefSU, SU, const_cast<SDep &>(dep));
|
|
|
|
}
|
|
|
|
SU->addPred(dep);
|
2012-01-14 02:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-22 06:08:11 +00:00
|
|
|
|
|
|
|
// Add antidependence to the following def of the vreg it uses.
|
2012-04-20 20:05:28 +00:00
|
|
|
VReg2SUnitMap::iterator DefI = VRegDefs.find(Reg);
|
2012-02-22 21:59:00 +00:00
|
|
|
if (DefI != VRegDefs.end() && DefI->SU != SU)
|
|
|
|
DefI->SU->addPred(SDep(SU, SDep::Anti, 0, Reg));
|
2012-01-14 02:17:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 18:59:41 +00:00
|
|
|
/// Return true if MI is an instruction we are unable to reason about
|
|
|
|
/// (like a call or something with unmodeled side effects).
|
|
|
|
static inline bool isGlobalMemoryObject(AliasAnalysis *AA, MachineInstr *MI) {
|
|
|
|
if (MI->isCall() || MI->hasUnmodeledSideEffects() ||
|
|
|
|
(MI->hasVolatileMemoryRef() &&
|
|
|
|
(!MI->mayLoad() || !MI->isInvariantLoad(AA))))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This MI might have either incomplete info, or known to be unsafe
|
|
|
|
// to deal with (i.e. volatile object).
|
|
|
|
static inline bool isUnsafeMemoryObject(MachineInstr *MI,
|
|
|
|
const MachineFrameInfo *MFI) {
|
|
|
|
if (!MI || MI->memoperands_empty())
|
|
|
|
return true;
|
|
|
|
// We purposefully do no check for hasOneMemOperand() here
|
|
|
|
// in hope to trigger an assert downstream in order to
|
|
|
|
// finish implementation.
|
|
|
|
if ((*MI->memoperands_begin())->isVolatile() ||
|
|
|
|
MI->hasUnmodeledSideEffects())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const Value *V = (*MI->memoperands_begin())->getValue();
|
|
|
|
if (!V)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
V = getUnderlyingObject(V);
|
|
|
|
if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
|
|
|
|
// Similarly to getUnderlyingObjectForInstr:
|
|
|
|
// For now, ignore PseudoSourceValues which may alias LLVM IR values
|
|
|
|
// because the code that uses this function has no way to cope with
|
|
|
|
// such aliases.
|
|
|
|
if (PSV->isAliased(MFI))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Does this pointer refer to a distinct and identifiable object?
|
|
|
|
if (!isIdentifiedObject(V))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This returns true if the two MIs need a chain edge betwee them.
|
|
|
|
/// If these are not even memory operations, we still may need
|
|
|
|
/// chain deps between them. The question really is - could
|
|
|
|
/// these two MIs be reordered during scheduling from memory dependency
|
|
|
|
/// point of view.
|
|
|
|
static bool MIsNeedChainEdge(AliasAnalysis *AA, const MachineFrameInfo *MFI,
|
|
|
|
MachineInstr *MIa,
|
|
|
|
MachineInstr *MIb) {
|
|
|
|
// Cover a trivial case - no edge is need to itself.
|
|
|
|
if (MIa == MIb)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isUnsafeMemoryObject(MIa, MFI) || isUnsafeMemoryObject(MIb, MFI))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If we are dealing with two "normal" loads, we do not need an edge
|
|
|
|
// between them - they could be reordered.
|
|
|
|
if (!MIa->mayStore() && !MIb->mayStore())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// To this point analysis is generic. From here on we do need AA.
|
|
|
|
if (!AA)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
MachineMemOperand *MMOa = *MIa->memoperands_begin();
|
|
|
|
MachineMemOperand *MMOb = *MIb->memoperands_begin();
|
|
|
|
|
|
|
|
// FIXME: Need to handle multiple memory operands to support all targets.
|
|
|
|
if (!MIa->hasOneMemOperand() || !MIb->hasOneMemOperand())
|
|
|
|
llvm_unreachable("Multiple memory operands.");
|
|
|
|
|
|
|
|
// The following interface to AA is fashioned after DAGCombiner::isAlias
|
|
|
|
// and operates with MachineMemOperand offset with some important
|
|
|
|
// assumptions:
|
|
|
|
// - LLVM fundamentally assumes flat address spaces.
|
|
|
|
// - MachineOperand offset can *only* result from legalization and
|
|
|
|
// cannot affect queries other than the trivial case of overlap
|
|
|
|
// checking.
|
|
|
|
// - These offsets never wrap and never step outside
|
|
|
|
// of allocated objects.
|
|
|
|
// - There should never be any negative offsets here.
|
|
|
|
//
|
|
|
|
// FIXME: Modify API to hide this math from "user"
|
|
|
|
// FIXME: Even before we go to AA we can reason locally about some
|
|
|
|
// memory objects. It can save compile time, and possibly catch some
|
|
|
|
// corner cases not currently covered.
|
|
|
|
|
|
|
|
assert ((MMOa->getOffset() >= 0) && "Negative MachineMemOperand offset");
|
|
|
|
assert ((MMOb->getOffset() >= 0) && "Negative MachineMemOperand offset");
|
|
|
|
|
|
|
|
int64_t MinOffset = std::min(MMOa->getOffset(), MMOb->getOffset());
|
|
|
|
int64_t Overlapa = MMOa->getSize() + MMOa->getOffset() - MinOffset;
|
|
|
|
int64_t Overlapb = MMOb->getSize() + MMOb->getOffset() - MinOffset;
|
|
|
|
|
|
|
|
AliasAnalysis::AliasResult AAResult = AA->alias(
|
|
|
|
AliasAnalysis::Location(MMOa->getValue(), Overlapa,
|
|
|
|
MMOa->getTBAAInfo()),
|
|
|
|
AliasAnalysis::Location(MMOb->getValue(), Overlapb,
|
|
|
|
MMOb->getTBAAInfo()));
|
|
|
|
|
|
|
|
return (AAResult != AliasAnalysis::NoAlias);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This recursive function iterates over chain deps of SUb looking for
|
|
|
|
/// "latest" node that needs a chain edge to SUa.
|
|
|
|
static unsigned
|
|
|
|
iterateChainSucc(AliasAnalysis *AA, const MachineFrameInfo *MFI,
|
|
|
|
SUnit *SUa, SUnit *SUb, SUnit *ExitSU, unsigned *Depth,
|
|
|
|
SmallPtrSet<const SUnit*, 16> &Visited) {
|
|
|
|
if (!SUa || !SUb || SUb == ExitSU)
|
|
|
|
return *Depth;
|
|
|
|
|
|
|
|
// Remember visited nodes.
|
|
|
|
if (!Visited.insert(SUb))
|
|
|
|
return *Depth;
|
|
|
|
// If there is _some_ dependency already in place, do not
|
|
|
|
// descend any further.
|
|
|
|
// TODO: Need to make sure that if that dependency got eliminated or ignored
|
|
|
|
// for any reason in the future, we would not violate DAG topology.
|
|
|
|
// Currently it does not happen, but makes an implicit assumption about
|
|
|
|
// future implementation.
|
|
|
|
//
|
|
|
|
// Independently, if we encounter node that is some sort of global
|
|
|
|
// object (like a call) we already have full set of dependencies to it
|
|
|
|
// and we can stop descending.
|
|
|
|
if (SUa->isSucc(SUb) ||
|
|
|
|
isGlobalMemoryObject(AA, SUb->getInstr()))
|
|
|
|
return *Depth;
|
|
|
|
|
|
|
|
// If we do need an edge, or we have exceeded depth budget,
|
|
|
|
// add that edge to the predecessors chain of SUb,
|
|
|
|
// and stop descending.
|
|
|
|
if (*Depth > 200 ||
|
|
|
|
MIsNeedChainEdge(AA, MFI, SUa->getInstr(), SUb->getInstr())) {
|
|
|
|
SUb->addPred(SDep(SUa, SDep::Order, /*Latency=*/0, /*Reg=*/0,
|
|
|
|
/*isNormalMemory=*/true));
|
|
|
|
return *Depth;
|
|
|
|
}
|
|
|
|
// Track current depth.
|
|
|
|
(*Depth)++;
|
|
|
|
// Iterate over chain dependencies only.
|
|
|
|
for (SUnit::const_succ_iterator I = SUb->Succs.begin(), E = SUb->Succs.end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (I->isCtrl())
|
|
|
|
iterateChainSucc (AA, MFI, SUa, I->getSUnit(), ExitSU, Depth, Visited);
|
|
|
|
return *Depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function assumes that "downward" from SU there exist
|
|
|
|
/// tail/leaf of already constructed DAG. It iterates downward and
|
|
|
|
/// checks whether SU can be aliasing any node dominated
|
|
|
|
/// by it.
|
|
|
|
static void adjustChainDeps(AliasAnalysis *AA, const MachineFrameInfo *MFI,
|
|
|
|
SUnit *SU, SUnit *ExitSU, std::set<SUnit *> &CheckList) {
|
|
|
|
if (!SU)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SmallPtrSet<const SUnit*, 16> Visited;
|
|
|
|
unsigned Depth = 0;
|
|
|
|
|
|
|
|
for (std::set<SUnit *>::iterator I = CheckList.begin(), IE = CheckList.end();
|
|
|
|
I != IE; ++I) {
|
|
|
|
if (SU == *I)
|
|
|
|
continue;
|
|
|
|
if (MIsNeedChainEdge(AA, MFI, SU->getInstr(), (*I)->getInstr()))
|
|
|
|
(*I)->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0,
|
|
|
|
/*isNormalMemory=*/true));
|
|
|
|
// Now go through all the chain successors and iterate from them.
|
|
|
|
// Keep track of visited nodes.
|
|
|
|
for (SUnit::const_succ_iterator J = (*I)->Succs.begin(),
|
|
|
|
JE = (*I)->Succs.end(); J != JE; ++J)
|
|
|
|
if (J->isCtrl())
|
|
|
|
iterateChainSucc (AA, MFI, SU, J->getSUnit(),
|
|
|
|
ExitSU, &Depth, Visited);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check whether two objects need a chain edge, if so, add it
|
|
|
|
/// otherwise remember the rejected SU.
|
|
|
|
static inline
|
|
|
|
void addChainDependency (AliasAnalysis *AA, const MachineFrameInfo *MFI,
|
|
|
|
SUnit *SUa, SUnit *SUb,
|
|
|
|
std::set<SUnit *> &RejectList,
|
|
|
|
unsigned TrueMemOrderLatency = 0,
|
|
|
|
bool isNormalMemory = false) {
|
|
|
|
// If this is a false dependency,
|
|
|
|
// do not add the edge, but rememeber the rejected node.
|
|
|
|
if (!EnableAASchedMI ||
|
|
|
|
MIsNeedChainEdge(AA, MFI, SUa->getInstr(), SUb->getInstr()))
|
|
|
|
SUb->addPred(SDep(SUa, SDep::Order, TrueMemOrderLatency, /*Reg=*/0,
|
|
|
|
isNormalMemory));
|
|
|
|
else {
|
|
|
|
// Duplicate entries should be ignored.
|
|
|
|
RejectList.insert(SUb);
|
|
|
|
DEBUG(dbgs() << "\tReject chain dep between SU("
|
|
|
|
<< SUa->NodeNum << ") and SU("
|
|
|
|
<< SUb->NodeNum << ")\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-22 06:08:11 +00:00
|
|
|
/// Create an SUnit for each real instruction, numbered in top-down toplological
|
|
|
|
/// order. The instruction order A < B, implies that no edge exists from B to A.
|
|
|
|
///
|
|
|
|
/// Map each real instruction to its SUnit.
|
|
|
|
///
|
2012-03-14 04:00:41 +00:00
|
|
|
/// After initSUnits, the SUnits vector cannot be resized and the scheduler may
|
|
|
|
/// hang onto SUnit pointers. We may relax this in the future by using SUnit IDs
|
|
|
|
/// instead of pointers.
|
|
|
|
///
|
|
|
|
/// MachineScheduler relies on initSUnits numbering the nodes by their order in
|
|
|
|
/// the original instruction list.
|
2012-02-22 06:08:11 +00:00
|
|
|
void ScheduleDAGInstrs::initSUnits() {
|
|
|
|
// We'll be allocating one SUnit for each real instruction in the region,
|
|
|
|
// which is contained within a basic block.
|
|
|
|
SUnits.reserve(BB->size());
|
2012-01-14 02:17:18 +00:00
|
|
|
|
2012-03-09 04:29:02 +00:00
|
|
|
for (MachineBasicBlock::iterator I = RegionBegin; I != RegionEnd; ++I) {
|
2012-02-22 06:08:11 +00:00
|
|
|
MachineInstr *MI = I;
|
|
|
|
if (MI->isDebugValue())
|
|
|
|
continue;
|
2012-01-14 02:17:18 +00:00
|
|
|
|
2012-03-07 23:00:49 +00:00
|
|
|
SUnit *SU = newSUnit(MI);
|
2012-02-22 06:08:11 +00:00
|
|
|
MISUnitMap[MI] = SU;
|
|
|
|
|
|
|
|
SU->isCall = MI->isCall();
|
|
|
|
SU->isCommutable = MI->isCommutable();
|
|
|
|
|
|
|
|
// Assign the Latency field of SU using target-provided information.
|
|
|
|
if (UnitLatencies)
|
|
|
|
SU->Latency = 1;
|
|
|
|
else
|
2012-03-07 23:00:49 +00:00
|
|
|
computeLatency(SU);
|
2012-02-22 06:08:11 +00:00
|
|
|
}
|
2012-01-14 02:17:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 17:56:43 +00:00
|
|
|
/// If RegPressure is non null, compute register pressure as a side effect. The
|
|
|
|
/// DAG builder is an efficient place to do it because it already visits
|
|
|
|
/// operands.
|
|
|
|
void ScheduleDAGInstrs::buildSchedGraph(AliasAnalysis *AA,
|
|
|
|
RegPressureTracker *RPTracker) {
|
2012-02-22 06:08:11 +00:00
|
|
|
// Create an SUnit for each real instruction.
|
|
|
|
initSUnits();
|
2008-11-19 23:18:57 +00:00
|
|
|
|
2008-12-04 01:35:46 +00:00
|
|
|
// We build scheduling units by walking a block's instruction list from bottom
|
|
|
|
// to top.
|
|
|
|
|
2009-11-09 19:22:17 +00:00
|
|
|
// Remember where a generic side-effecting instruction is as we procede.
|
|
|
|
SUnit *BarrierChain = 0, *AliasChain = 0;
|
2008-12-04 01:35:46 +00:00
|
|
|
|
2009-11-09 19:22:17 +00:00
|
|
|
// Memory references to specific known memory locations are tracked
|
|
|
|
// so that they can be given more precise dependencies. We track
|
|
|
|
// separately the known memory locations that may alias and those
|
|
|
|
// that are known not to alias
|
|
|
|
std::map<const Value *, SUnit *> AliasMemDefs, NonAliasMemDefs;
|
|
|
|
std::map<const Value *, std::vector<SUnit *> > AliasMemUses, NonAliasMemUses;
|
2012-05-15 18:59:41 +00:00
|
|
|
std::set<SUnit*> RejectMemNodes;
|
2008-12-04 01:35:46 +00:00
|
|
|
|
2010-03-10 22:13:47 +00:00
|
|
|
// Remove any stale debug info; sometimes BuildSchedGraph is called again
|
|
|
|
// without emitting the info from the previous call.
|
2011-06-02 20:07:12 +00:00
|
|
|
DbgValues.clear();
|
|
|
|
FirstDbgValue = NULL;
|
2010-03-10 22:13:47 +00:00
|
|
|
|
2012-02-23 01:52:38 +00:00
|
|
|
assert(Defs.empty() && Uses.empty() &&
|
|
|
|
"Only BuildGraph should update Defs/Uses");
|
2012-02-24 07:04:55 +00:00
|
|
|
Defs.setRegLimit(TRI->getNumRegs());
|
|
|
|
Uses.setRegLimit(TRI->getNumRegs());
|
2011-05-06 21:52:52 +00:00
|
|
|
|
2012-02-22 21:59:00 +00:00
|
|
|
assert(VRegDefs.empty() && "Only BuildSchedGraph may access VRegDefs");
|
|
|
|
// FIXME: Allow SparseSet to reserve space for the creation of virtual
|
|
|
|
// registers during scheduling. Don't artificially inflate the Universe
|
|
|
|
// because we want to assert that vregs are not created during DAG building.
|
|
|
|
VRegDefs.setUniverse(MRI.getNumVirtRegs());
|
2012-01-14 02:17:18 +00:00
|
|
|
|
2012-02-23 01:52:38 +00:00
|
|
|
// Model data dependencies between instructions being scheduled and the
|
|
|
|
// ExitSU.
|
2012-03-07 23:00:49 +00:00
|
|
|
addSchedBarrierDeps();
|
2012-02-23 01:52:38 +00:00
|
|
|
|
2009-02-10 23:27:53 +00:00
|
|
|
// Walk the list of instructions, from bottom moving up.
|
2011-06-02 20:07:12 +00:00
|
|
|
MachineInstr *PrevMI = NULL;
|
2012-03-09 04:29:02 +00:00
|
|
|
for (MachineBasicBlock::iterator MII = RegionEnd, MIE = RegionBegin;
|
2008-11-19 23:18:57 +00:00
|
|
|
MII != MIE; --MII) {
|
|
|
|
MachineInstr *MI = prior(MII);
|
2011-06-02 20:07:12 +00:00
|
|
|
if (MI && PrevMI) {
|
|
|
|
DbgValues.push_back(std::make_pair(PrevMI, MI));
|
|
|
|
PrevMI = NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-10 22:13:47 +00:00
|
|
|
if (MI->isDebugValue()) {
|
2011-06-02 20:07:12 +00:00
|
|
|
PrevMI = MI;
|
2010-03-10 22:13:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-04-24 17:56:43 +00:00
|
|
|
if (RPTracker) {
|
|
|
|
RPTracker->recede();
|
|
|
|
assert(RPTracker->getPos() == prior(MII) && "RPTracker can't find MI");
|
|
|
|
}
|
2011-06-02 20:07:12 +00:00
|
|
|
|
2012-04-13 23:29:54 +00:00
|
|
|
assert((!MI->isTerminator() || CanHandleTerminators) && !MI->isLabel() &&
|
2009-02-10 23:27:53 +00:00
|
|
|
"Cannot schedule terminators or labels!");
|
2008-11-19 23:18:57 +00:00
|
|
|
|
2012-02-22 06:08:11 +00:00
|
|
|
SUnit *SU = MISUnitMap[MI];
|
|
|
|
assert(SU && "No SUnit mapped to this MI");
|
2008-12-09 22:54:47 +00:00
|
|
|
|
2008-12-04 01:35:46 +00:00
|
|
|
// Add register-based dependencies (data, anti, and output).
|
2008-11-19 23:18:57 +00:00
|
|
|
for (unsigned j = 0, n = MI->getNumOperands(); j != n; ++j) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(j);
|
|
|
|
if (!MO.isReg()) continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Reg == 0) continue;
|
|
|
|
|
2012-01-14 02:17:15 +00:00
|
|
|
if (TRI->isPhysicalRegister(Reg))
|
|
|
|
addPhysRegDeps(SU, j);
|
|
|
|
else {
|
|
|
|
assert(!IsPostRA && "Virtual register encountered!");
|
2012-01-14 02:17:18 +00:00
|
|
|
if (MO.isDef())
|
|
|
|
addVRegDefDeps(SU, j);
|
2012-02-23 03:16:24 +00:00
|
|
|
else if (MO.readsReg()) // ignore undef operands
|
2012-01-14 02:17:18 +00:00
|
|
|
addVRegUseDeps(SU, j);
|
2008-11-19 23:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-04 01:35:46 +00:00
|
|
|
|
|
|
|
// Add chain dependencies.
|
2009-11-02 17:06:28 +00:00
|
|
|
// Chain dependencies used to enforce memory order should have
|
|
|
|
// latency of 0 (except for true dependency of Store followed by
|
|
|
|
// aliased Load... we estimate that with a single cycle of latency
|
|
|
|
// assuming the hardware will bypass)
|
2008-12-04 01:35:46 +00:00
|
|
|
// Note that isStoreToStackSlot and isLoadFromStackSLot are not usable
|
|
|
|
// after stack slots are lowered to actual addresses.
|
|
|
|
// TODO: Use an AliasAnalysis and do real alias-analysis queries, and
|
|
|
|
// produce more precise dependence information.
|
2009-11-02 17:06:28 +00:00
|
|
|
#define STORE_LOAD_LATENCY 1
|
|
|
|
unsigned TrueMemOrderLatency = 0;
|
2012-05-15 18:59:41 +00:00
|
|
|
if (isGlobalMemoryObject(AA, MI)) {
|
2009-11-09 19:22:17 +00:00
|
|
|
// Be conservative with these and add dependencies on all memory
|
|
|
|
// references, even those that are known to not alias.
|
2011-05-05 19:24:06 +00:00
|
|
|
for (std::map<const Value *, SUnit *>::iterator I =
|
2009-11-09 19:22:17 +00:00
|
|
|
NonAliasMemDefs.begin(), E = NonAliasMemDefs.end(); I != E; ++I) {
|
|
|
|
I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
|
|
|
|
}
|
|
|
|
for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
|
|
|
|
NonAliasMemUses.begin(), E = NonAliasMemUses.end(); I != E; ++I) {
|
|
|
|
for (unsigned i = 0, e = I->second.size(); i != e; ++i)
|
|
|
|
I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
|
|
|
|
}
|
|
|
|
// Add SU to the barrier chain.
|
|
|
|
if (BarrierChain)
|
|
|
|
BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
|
|
|
|
BarrierChain = SU;
|
2012-05-15 18:59:41 +00:00
|
|
|
// This is a barrier event that acts as a pivotal node in the DAG,
|
|
|
|
// so it is safe to clear list of exposed nodes.
|
|
|
|
adjustChainDeps(AA, MFI, SU, &ExitSU, RejectMemNodes);
|
|
|
|
RejectMemNodes.clear();
|
|
|
|
NonAliasMemDefs.clear();
|
|
|
|
NonAliasMemUses.clear();
|
2009-11-09 19:22:17 +00:00
|
|
|
|
|
|
|
// fall-through
|
|
|
|
new_alias_chain:
|
|
|
|
// Chain all possibly aliasing memory references though SU.
|
|
|
|
if (AliasChain)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, AliasChain, RejectMemNodes);
|
2009-11-09 19:22:17 +00:00
|
|
|
AliasChain = SU;
|
2008-11-19 23:18:57 +00:00
|
|
|
for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, PendingLoads[k], RejectMemNodes,
|
|
|
|
TrueMemOrderLatency);
|
2009-11-09 19:22:17 +00:00
|
|
|
for (std::map<const Value *, SUnit *>::iterator I = AliasMemDefs.begin(),
|
2012-05-15 18:59:41 +00:00
|
|
|
E = AliasMemDefs.end(); I != E; ++I)
|
|
|
|
addChainDependency(AA, MFI, SU, I->second, RejectMemNodes);
|
2008-12-04 01:35:46 +00:00
|
|
|
for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
|
2009-11-09 19:22:17 +00:00
|
|
|
AliasMemUses.begin(), E = AliasMemUses.end(); I != E; ++I) {
|
2008-12-04 01:35:46 +00:00
|
|
|
for (unsigned i = 0, e = I->second.size(); i != e; ++i)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, I->second[i], RejectMemNodes,
|
|
|
|
TrueMemOrderLatency);
|
2008-12-04 01:35:46 +00:00
|
|
|
}
|
2012-05-15 18:59:41 +00:00
|
|
|
adjustChainDeps(AA, MFI, SU, &ExitSU, RejectMemNodes);
|
2009-11-09 19:22:17 +00:00
|
|
|
PendingLoads.clear();
|
|
|
|
AliasMemDefs.clear();
|
|
|
|
AliasMemUses.clear();
|
2011-12-07 07:15:52 +00:00
|
|
|
} else if (MI->mayStore()) {
|
2009-11-03 20:15:00 +00:00
|
|
|
bool MayAlias = true;
|
2009-11-02 17:06:28 +00:00
|
|
|
TrueMemOrderLatency = STORE_LOAD_LATENCY;
|
2009-11-03 20:15:00 +00:00
|
|
|
if (const Value *V = getUnderlyingObjectForInstr(MI, MFI, MayAlias)) {
|
2008-12-04 01:35:46 +00:00
|
|
|
// A store to a specific PseudoSourceValue. Add precise dependencies.
|
2009-11-09 19:22:17 +00:00
|
|
|
// Record the def in MemDefs, first adding a dep if there is
|
|
|
|
// an existing def.
|
2011-05-05 19:24:06 +00:00
|
|
|
std::map<const Value *, SUnit *>::iterator I =
|
2009-11-09 19:22:17 +00:00
|
|
|
((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V));
|
2011-05-05 19:24:06 +00:00
|
|
|
std::map<const Value *, SUnit *>::iterator IE =
|
2009-11-09 19:22:17 +00:00
|
|
|
((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end());
|
|
|
|
if (I != IE) {
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, I->second, RejectMemNodes,
|
|
|
|
0, true);
|
2008-12-04 01:35:46 +00:00
|
|
|
I->second = SU;
|
|
|
|
} else {
|
2009-11-09 19:22:17 +00:00
|
|
|
if (MayAlias)
|
|
|
|
AliasMemDefs[V] = SU;
|
|
|
|
else
|
|
|
|
NonAliasMemDefs[V] = SU;
|
2008-12-04 01:35:46 +00:00
|
|
|
}
|
|
|
|
// Handle the uses in MemUses, if there are any.
|
2008-12-08 17:50:35 +00:00
|
|
|
std::map<const Value *, std::vector<SUnit *> >::iterator J =
|
2009-11-09 19:22:17 +00:00
|
|
|
((MayAlias) ? AliasMemUses.find(V) : NonAliasMemUses.find(V));
|
|
|
|
std::map<const Value *, std::vector<SUnit *> >::iterator JE =
|
|
|
|
((MayAlias) ? AliasMemUses.end() : NonAliasMemUses.end());
|
|
|
|
if (J != JE) {
|
2008-12-04 01:35:46 +00:00
|
|
|
for (unsigned i = 0, e = J->second.size(); i != e; ++i)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, J->second[i], RejectMemNodes,
|
|
|
|
TrueMemOrderLatency, true);
|
2008-12-04 01:35:46 +00:00
|
|
|
J->second.clear();
|
|
|
|
}
|
2009-11-03 20:15:00 +00:00
|
|
|
if (MayAlias) {
|
2009-11-09 19:22:17 +00:00
|
|
|
// Add dependencies from all the PendingLoads, i.e. loads
|
|
|
|
// with no underlying object.
|
2009-11-03 20:15:00 +00:00
|
|
|
for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, PendingLoads[k], RejectMemNodes,
|
|
|
|
TrueMemOrderLatency);
|
2009-11-09 19:22:17 +00:00
|
|
|
// Add dependence on alias chain, if needed.
|
|
|
|
if (AliasChain)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, AliasChain, RejectMemNodes);
|
|
|
|
// But we also should check dependent instructions for the
|
|
|
|
// SU in question.
|
|
|
|
adjustChainDeps(AA, MFI, SU, &ExitSU, RejectMemNodes);
|
2009-11-03 20:15:00 +00:00
|
|
|
}
|
2009-11-09 19:22:17 +00:00
|
|
|
// Add dependence on barrier chain, if needed.
|
2012-05-15 18:59:41 +00:00
|
|
|
// There is no point to check aliasing on barrier event. Even if
|
|
|
|
// SU and barrier _could_ be reordered, they should not. In addition,
|
|
|
|
// we have lost all RejectMemNodes below barrier.
|
2009-11-09 19:22:17 +00:00
|
|
|
if (BarrierChain)
|
|
|
|
BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
|
2009-11-05 00:16:44 +00:00
|
|
|
} else {
|
2008-12-04 01:35:46 +00:00
|
|
|
// Treat all other stores conservatively.
|
2009-11-09 19:22:17 +00:00
|
|
|
goto new_alias_chain;
|
2009-11-02 17:06:28 +00:00
|
|
|
}
|
2010-10-23 02:10:46 +00:00
|
|
|
|
|
|
|
if (!ExitSU.isPred(SU))
|
|
|
|
// Push store's up a bit to avoid them getting in between cmp
|
|
|
|
// and branches.
|
|
|
|
ExitSU.addPred(SDep(SU, SDep::Order, 0,
|
|
|
|
/*Reg=*/0, /*isNormalMemory=*/false,
|
|
|
|
/*isMustAlias=*/false,
|
|
|
|
/*isArtificial=*/true));
|
2011-12-07 07:15:52 +00:00
|
|
|
} else if (MI->mayLoad()) {
|
2009-11-03 20:15:00 +00:00
|
|
|
bool MayAlias = true;
|
2009-11-02 17:06:28 +00:00
|
|
|
TrueMemOrderLatency = 0;
|
2009-10-09 23:27:56 +00:00
|
|
|
if (MI->isInvariantLoad(AA)) {
|
2008-12-04 01:35:46 +00:00
|
|
|
// Invariant load, no chain dependencies needed!
|
2009-11-05 00:16:44 +00:00
|
|
|
} else {
|
2011-05-05 19:24:06 +00:00
|
|
|
if (const Value *V =
|
2009-11-09 19:22:17 +00:00
|
|
|
getUnderlyingObjectForInstr(MI, MFI, MayAlias)) {
|
|
|
|
// A load from a specific PseudoSourceValue. Add precise dependencies.
|
2011-05-05 19:24:06 +00:00
|
|
|
std::map<const Value *, SUnit *>::iterator I =
|
2009-11-09 19:22:17 +00:00
|
|
|
((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V));
|
2011-05-05 19:24:06 +00:00
|
|
|
std::map<const Value *, SUnit *>::iterator IE =
|
2009-11-09 19:22:17 +00:00
|
|
|
((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end());
|
|
|
|
if (I != IE)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, I->second, RejectMemNodes, 0, true);
|
2009-11-09 19:22:17 +00:00
|
|
|
if (MayAlias)
|
|
|
|
AliasMemUses[V].push_back(SU);
|
2011-05-05 19:24:06 +00:00
|
|
|
else
|
2009-11-09 19:22:17 +00:00
|
|
|
NonAliasMemUses[V].push_back(SU);
|
|
|
|
} else {
|
|
|
|
// A load with no underlying object. Depend on all
|
|
|
|
// potentially aliasing stores.
|
2011-05-05 19:24:06 +00:00
|
|
|
for (std::map<const Value *, SUnit *>::iterator I =
|
2009-11-09 19:22:17 +00:00
|
|
|
AliasMemDefs.begin(), E = AliasMemDefs.end(); I != E; ++I)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, I->second, RejectMemNodes);
|
2011-05-05 19:24:06 +00:00
|
|
|
|
2009-11-09 19:22:17 +00:00
|
|
|
PendingLoads.push_back(SU);
|
|
|
|
MayAlias = true;
|
2009-11-03 20:15:00 +00:00
|
|
|
}
|
2012-05-15 18:59:41 +00:00
|
|
|
if (MayAlias)
|
|
|
|
adjustChainDeps(AA, MFI, SU, &ExitSU, RejectMemNodes);
|
2009-11-09 19:22:17 +00:00
|
|
|
// Add dependencies on alias and barrier chains, if needed.
|
|
|
|
if (MayAlias && AliasChain)
|
2012-05-15 18:59:41 +00:00
|
|
|
addChainDependency(AA, MFI, SU, AliasChain, RejectMemNodes);
|
2009-11-09 19:22:17 +00:00
|
|
|
if (BarrierChain)
|
|
|
|
BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
|
2011-05-05 19:24:06 +00:00
|
|
|
}
|
2008-11-19 23:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-02 20:07:12 +00:00
|
|
|
if (PrevMI)
|
|
|
|
FirstDbgValue = PrevMI;
|
2009-01-15 19:20:50 +00:00
|
|
|
|
2012-02-23 01:52:38 +00:00
|
|
|
Defs.clear();
|
|
|
|
Uses.clear();
|
2012-01-14 02:17:18 +00:00
|
|
|
VRegDefs.clear();
|
2009-01-15 19:20:50 +00:00
|
|
|
PendingLoads.clear();
|
2008-11-19 23:18:57 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 23:00:49 +00:00
|
|
|
void ScheduleDAGInstrs::computeLatency(SUnit *SU) {
|
2012-06-05 21:11:27 +00:00
|
|
|
// Compute the latency for the node. We only provide a default for missing
|
|
|
|
// itineraries. Empty itineraries still have latency properties.
|
|
|
|
if (!InstrItins) {
|
2010-09-10 01:29:16 +00:00
|
|
|
SU->Latency = 1;
|
2008-12-16 02:38:22 +00:00
|
|
|
|
2010-09-10 01:29:16 +00:00
|
|
|
// Simplistic target-independent heuristic: assume that loads take
|
|
|
|
// extra time.
|
2011-12-07 07:15:52 +00:00
|
|
|
if (SU->getInstr()->mayLoad())
|
2008-12-16 02:38:22 +00:00
|
|
|
SU->Latency += 2;
|
2010-11-03 00:45:17 +00:00
|
|
|
} else {
|
|
|
|
SU->Latency = TII->getInstrLatency(InstrItins, SU->getInstr());
|
|
|
|
}
|
2008-11-21 00:12:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 21:11:27 +00:00
|
|
|
unsigned ScheduleDAGInstrs::computeOperandLatency(SUnit *Def, SUnit *Use,
|
|
|
|
const SDep& dep,
|
|
|
|
bool FindMin) const {
|
2009-08-19 16:08:58 +00:00
|
|
|
// For a data dependency with a known register...
|
|
|
|
if ((dep.getKind() != SDep::Data) || (dep.getReg() == 0))
|
2012-06-05 21:11:27 +00:00
|
|
|
return 1;
|
2009-08-19 16:08:58 +00:00
|
|
|
|
2012-06-05 21:11:27 +00:00
|
|
|
return TII->computeOperandLatency(InstrItins, TRI, Def->getInstr(),
|
|
|
|
Use->getInstr(), dep.getReg(), FindMin);
|
2009-08-19 16:08:58 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 23:18:57 +00:00
|
|
|
void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const {
|
|
|
|
SU->getInstr()->dump();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
|
|
|
|
std::string s;
|
|
|
|
raw_string_ostream oss(s);
|
2009-02-10 23:27:53 +00:00
|
|
|
if (SU == &EntrySU)
|
|
|
|
oss << "<entry>";
|
|
|
|
else if (SU == &ExitSU)
|
|
|
|
oss << "<exit>";
|
|
|
|
else
|
|
|
|
SU->getInstr()->print(oss);
|
2008-11-19 23:18:57 +00:00
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
2012-03-07 00:18:22 +00:00
|
|
|
/// Return the basic block label. It is not necessarilly unique because a block
|
|
|
|
/// contains multiple scheduling regions. But it is fine for visualization.
|
|
|
|
std::string ScheduleDAGInstrs::getDAGName() const {
|
|
|
|
return "dag." + BB->getFullName();
|
|
|
|
}
|