2007-07-14 01:31:29 +08:00
|
|
|
//===----- SchedulePostRAList.cpp - list scheduler ------------------------===//
|
2007-07-14 01:13:54 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-14 01:13:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements a top-down list scheduler, using standard algorithms.
|
|
|
|
// The basic approach uses a priority queue of available nodes to schedule.
|
|
|
|
// One at a time, nodes are taken from the priority queue (thus in priority
|
|
|
|
// order), checked for legality to schedule, and emitted if legal.
|
|
|
|
//
|
|
|
|
// Nodes may not be legal to schedule either due to structural hazards (e.g.
|
|
|
|
// pipeline or resource constraints) or because an input to the instruction has
|
|
|
|
// not completed execution.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "post-RA-sched"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2009-10-27 03:32:42 +08:00
|
|
|
#include "AggressiveAntiDepBreaker.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "AntiDepBreaker.h"
|
2009-10-27 00:59:04 +08:00
|
|
|
#include "CriticalAntiDepBreaker.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2008-11-20 07:18:57 +08:00
|
|
|
#include "llvm/CodeGen/LatencyPriorityQueue.h"
|
2008-12-16 11:25:46 +08:00
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
2009-10-02 03:45:32 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2007-07-14 01:13:54 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2012-12-21 02:08:06 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2008-12-16 11:25:46 +08:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2008-11-25 08:52:40 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-06-07 04:29:31 +08:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2012-03-08 07:01:06 +08:00
|
|
|
#include "llvm/CodeGen/ScheduleDAGInstrs.h"
|
2009-01-16 09:33:36 +08:00
|
|
|
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/SchedulerRegistry.h"
|
2009-10-27 06:31:16 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2007-07-14 01:13:54 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-11 09:44:26 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2007-07-14 01:13:54 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-01-16 09:33:36 +08:00
|
|
|
STATISTIC(NumNoops, "Number of noops inserted");
|
2008-11-20 07:18:57 +08:00
|
|
|
STATISTIC(NumStalls, "Number of pipeline stalls");
|
2009-10-27 00:59:04 +08:00
|
|
|
STATISTIC(NumFixedAnti, "Number of fixed anti-dependencies");
|
2008-11-20 07:18:57 +08:00
|
|
|
|
2009-10-02 05:46:35 +08:00
|
|
|
// Post-RA scheduling is enabled with
|
2011-07-02 05:01:15 +08:00
|
|
|
// TargetSubtargetInfo.enablePostRAScheduler(). This flag can be used to
|
2009-10-02 05:46:35 +08:00
|
|
|
// override the target.
|
|
|
|
static cl::opt<bool>
|
|
|
|
EnablePostRAScheduler("post-RA-scheduler",
|
|
|
|
cl::desc("Enable scheduling after register allocation"),
|
2009-10-02 06:19:57 +08:00
|
|
|
cl::init(false), cl::Hidden);
|
2009-10-27 00:59:04 +08:00
|
|
|
static cl::opt<std::string>
|
2008-11-25 08:52:40 +08:00
|
|
|
EnableAntiDepBreaking("break-anti-dependencies",
|
2009-10-27 00:59:04 +08:00
|
|
|
cl::desc("Break post-RA scheduling anti-dependencies: "
|
|
|
|
"\"critical\", \"all\", or \"none\""),
|
|
|
|
cl::init("none"), cl::Hidden);
|
2009-01-16 09:33:36 +08:00
|
|
|
|
2009-09-02 02:34:03 +08:00
|
|
|
// If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
|
|
|
|
static cl::opt<int>
|
|
|
|
DebugDiv("postra-sched-debugdiv",
|
|
|
|
cl::desc("Debug control MBBs that are scheduled"),
|
|
|
|
cl::init(0), cl::Hidden);
|
|
|
|
static cl::opt<int>
|
|
|
|
DebugMod("postra-sched-debugmod",
|
|
|
|
cl::desc("Debug control MBBs that are scheduled"),
|
|
|
|
cl::init(0), cl::Hidden);
|
|
|
|
|
2009-10-27 03:41:00 +08:00
|
|
|
AntiDepBreaker::~AntiDepBreaker() { }
|
|
|
|
|
2007-07-14 01:13:54 +08:00
|
|
|
namespace {
|
2009-10-25 14:33:48 +08:00
|
|
|
class PostRAScheduler : public MachineFunctionPass {
|
2010-06-19 07:09:54 +08:00
|
|
|
const TargetInstrInfo *TII;
|
2011-06-17 05:56:21 +08:00
|
|
|
RegisterClassInfo RegClassInfo;
|
2009-10-10 07:27:56 +08:00
|
|
|
|
2007-07-14 01:13:54 +08:00
|
|
|
public:
|
|
|
|
static char ID;
|
2012-02-09 05:22:53 +08:00
|
|
|
PostRAScheduler() : MachineFunctionPass(ID) {}
|
2008-11-25 08:52:40 +08:00
|
|
|
|
2008-12-16 11:25:46 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const {
|
2009-08-01 07:37:33 +08:00
|
|
|
AU.setPreservesCFG();
|
2009-10-10 07:27:56 +08:00
|
|
|
AU.addRequired<AliasAnalysis>();
|
2012-02-09 05:22:53 +08:00
|
|
|
AU.addRequired<TargetPassConfig>();
|
2008-12-16 11:25:46 +08:00
|
|
|
AU.addRequired<MachineDominatorTree>();
|
|
|
|
AU.addPreserved<MachineDominatorTree>();
|
|
|
|
AU.addRequired<MachineLoopInfo>();
|
|
|
|
AU.addPreserved<MachineLoopInfo>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn);
|
|
|
|
};
|
|
|
|
char PostRAScheduler::ID = 0;
|
|
|
|
|
2009-10-25 14:33:48 +08:00
|
|
|
class SchedulePostRATDList : public ScheduleDAGInstrs {
|
2008-11-20 07:18:57 +08:00
|
|
|
/// AvailableQueue - The priority queue to use for the available SUnits.
|
2009-10-21 09:44:44 +08:00
|
|
|
///
|
2008-11-20 07:18:57 +08:00
|
|
|
LatencyPriorityQueue AvailableQueue;
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
/// PendingQueue - This contains all of the instructions whose operands have
|
|
|
|
/// been issued, but their results are not ready yet (due to the latency of
|
|
|
|
/// the operation). Once the operands becomes available, the instruction is
|
|
|
|
/// added to the AvailableQueue.
|
|
|
|
std::vector<SUnit*> PendingQueue;
|
|
|
|
|
2009-10-21 09:44:44 +08:00
|
|
|
/// HazardRec - The hazard recognizer to use.
|
|
|
|
ScheduleHazardRecognizer *HazardRec;
|
|
|
|
|
2009-10-27 00:59:04 +08:00
|
|
|
/// AntiDepBreak - Anti-dependence breaking object, or NULL if none
|
|
|
|
AntiDepBreaker *AntiDepBreak;
|
|
|
|
|
2009-10-21 09:44:44 +08:00
|
|
|
/// AA - AliasAnalysis for making memory reference queries.
|
|
|
|
AliasAnalysis *AA;
|
2009-10-21 03:54:44 +08:00
|
|
|
|
2012-02-24 03:15:40 +08:00
|
|
|
/// LiveRegs - true if the register is live.
|
|
|
|
BitVector LiveRegs;
|
2009-02-11 07:27:53 +08:00
|
|
|
|
2012-03-07 13:21:52 +08:00
|
|
|
/// The schedule. Null SUnit*'s represent noop instructions.
|
|
|
|
std::vector<SUnit*> Sequence;
|
|
|
|
|
2008-11-25 08:52:40 +08:00
|
|
|
public:
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
SchedulePostRATDList(
|
|
|
|
MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
|
2011-06-17 05:56:21 +08:00
|
|
|
AliasAnalysis *AA, const RegisterClassInfo&,
|
2011-07-02 05:01:15 +08:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
|
2012-02-22 13:59:10 +08:00
|
|
|
SmallVectorImpl<const TargetRegisterClass*> &CriticalPathRCs);
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
|
|
|
|
~SchedulePostRATDList();
|
2008-11-20 07:18:57 +08:00
|
|
|
|
2012-03-08 07:00:49 +08:00
|
|
|
/// startBlock - Initialize register live-range state for scheduling in
|
2009-02-11 07:27:53 +08:00
|
|
|
/// this block.
|
|
|
|
///
|
2012-03-08 07:00:49 +08:00
|
|
|
void startBlock(MachineBasicBlock *BB);
|
2009-02-11 07:27:53 +08:00
|
|
|
|
2012-03-07 13:21:52 +08:00
|
|
|
/// Initialize the scheduler state for the next scheduling region.
|
|
|
|
virtual void enterRegion(MachineBasicBlock *bb,
|
|
|
|
MachineBasicBlock::iterator begin,
|
|
|
|
MachineBasicBlock::iterator end,
|
|
|
|
unsigned endcount);
|
|
|
|
|
|
|
|
/// Notify that the scheduler has finished scheduling the current region.
|
|
|
|
virtual void exitRegion();
|
|
|
|
|
2009-10-21 03:54:44 +08:00
|
|
|
/// Schedule - Schedule the instruction range using list scheduling.
|
2009-02-11 07:27:53 +08:00
|
|
|
///
|
2012-03-08 07:00:49 +08:00
|
|
|
void schedule();
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2012-03-07 13:21:44 +08:00
|
|
|
void EmitSchedule();
|
|
|
|
|
2009-10-21 09:44:44 +08:00
|
|
|
/// Observe - Update liveness information to account for the current
|
|
|
|
/// instruction, which will not be scheduled.
|
|
|
|
///
|
|
|
|
void Observe(MachineInstr *MI, unsigned Count);
|
2009-10-21 03:54:44 +08:00
|
|
|
|
2012-03-08 07:00:49 +08:00
|
|
|
/// finishBlock - Clean up register live-range state.
|
2009-10-21 09:44:44 +08:00
|
|
|
///
|
2012-03-08 07:00:49 +08:00
|
|
|
void finishBlock();
|
2009-10-21 03:54:44 +08:00
|
|
|
|
2009-10-27 00:59:04 +08:00
|
|
|
/// FixupKills - Fix register kill flags that have been made
|
|
|
|
/// invalid due to scheduling
|
|
|
|
///
|
|
|
|
void FixupKills(MachineBasicBlock *MBB);
|
|
|
|
|
2009-10-21 09:44:44 +08:00
|
|
|
private:
|
2009-11-21 03:32:48 +08:00
|
|
|
void ReleaseSucc(SUnit *SU, SDep *SuccEdge);
|
|
|
|
void ReleaseSuccessors(SUnit *SU);
|
|
|
|
void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle);
|
|
|
|
void ListScheduleTopDown();
|
2009-09-04 06:15:25 +08:00
|
|
|
void StartBlockForKills(MachineBasicBlock *BB);
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-09-24 00:35:25 +08:00
|
|
|
// ToggleKillFlag - Toggle a register operand kill flag. Other
|
|
|
|
// adjustments may be made to the instruction if necessary. Return
|
|
|
|
// true if the operand has been deleted, false if not.
|
|
|
|
bool ToggleKillFlag(MachineInstr *MI, MachineOperand &MO);
|
2012-03-07 13:21:40 +08:00
|
|
|
|
|
|
|
void dumpSchedule() const;
|
2007-07-14 01:13:54 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-02-09 05:23:13 +08:00
|
|
|
char &llvm::PostRASchedulerID = PostRAScheduler::ID;
|
|
|
|
|
|
|
|
INITIALIZE_PASS(PostRAScheduler, "post-RA-sched",
|
|
|
|
"Post RA top-down list latency scheduler", false, false)
|
|
|
|
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
SchedulePostRATDList::SchedulePostRATDList(
|
|
|
|
MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
|
2011-06-17 05:56:21 +08:00
|
|
|
AliasAnalysis *AA, const RegisterClassInfo &RCI,
|
2011-07-02 05:01:15 +08:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
|
2012-02-22 13:59:10 +08:00
|
|
|
SmallVectorImpl<const TargetRegisterClass*> &CriticalPathRCs)
|
2012-11-13 03:28:57 +08:00
|
|
|
: ScheduleDAGInstrs(MF, MLI, MDT, /*IsPostRA=*/true), AA(AA),
|
2012-02-24 03:15:40 +08:00
|
|
|
LiveRegs(TRI->getNumRegs())
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
{
|
|
|
|
const TargetMachine &TM = MF.getTarget();
|
|
|
|
const InstrItineraryData *InstrItins = TM.getInstrItineraryData();
|
|
|
|
HazardRec =
|
|
|
|
TM.getInstrInfo()->CreateTargetPostRAHazardRecognizer(InstrItins, this);
|
2012-04-24 05:39:35 +08:00
|
|
|
|
|
|
|
assert((AntiDepMode == TargetSubtargetInfo::ANTIDEP_NONE ||
|
|
|
|
MRI.tracksLiveness()) &&
|
|
|
|
"Live-ins must be accurate for anti-dependency breaking");
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
AntiDepBreak =
|
2011-07-02 05:01:15 +08:00
|
|
|
((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL) ?
|
2011-06-17 05:56:21 +08:00
|
|
|
(AntiDepBreaker *)new AggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs) :
|
2011-07-02 05:01:15 +08:00
|
|
|
((AntiDepMode == TargetSubtargetInfo::ANTIDEP_CRITICAL) ?
|
2011-06-17 05:56:21 +08:00
|
|
|
(AntiDepBreaker *)new CriticalAntiDepBreaker(MF, RCI) : NULL));
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SchedulePostRATDList::~SchedulePostRATDList() {
|
|
|
|
delete HazardRec;
|
|
|
|
delete AntiDepBreak;
|
|
|
|
}
|
|
|
|
|
2012-03-07 13:21:52 +08:00
|
|
|
/// Initialize state associated with the next scheduling region.
|
|
|
|
void SchedulePostRATDList::enterRegion(MachineBasicBlock *bb,
|
|
|
|
MachineBasicBlock::iterator begin,
|
|
|
|
MachineBasicBlock::iterator end,
|
|
|
|
unsigned endcount) {
|
|
|
|
ScheduleDAGInstrs::enterRegion(bb, begin, end, endcount);
|
|
|
|
Sequence.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print the schedule before exiting the region.
|
|
|
|
void SchedulePostRATDList::exitRegion() {
|
|
|
|
DEBUG({
|
|
|
|
dbgs() << "*** Final schedule ***\n";
|
|
|
|
dumpSchedule();
|
|
|
|
dbgs() << '\n';
|
|
|
|
});
|
|
|
|
ScheduleDAGInstrs::exitRegion();
|
|
|
|
}
|
|
|
|
|
2012-09-12 06:23:19 +08:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2012-03-07 13:21:40 +08:00
|
|
|
/// dumpSchedule - dump the scheduled Sequence.
|
|
|
|
void SchedulePostRATDList::dumpSchedule() const {
|
|
|
|
for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
|
|
|
|
if (SUnit *SU = Sequence[i])
|
|
|
|
SU->dump(this);
|
|
|
|
else
|
|
|
|
dbgs() << "**** NOOP ****\n";
|
|
|
|
}
|
|
|
|
}
|
2012-09-07 03:06:06 +08:00
|
|
|
#endif
|
2012-03-07 13:21:40 +08:00
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) {
|
2010-06-19 07:09:54 +08:00
|
|
|
TII = Fn.getTarget().getInstrInfo();
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
|
|
|
|
MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
|
|
|
|
AliasAnalysis *AA = &getAnalysis<AliasAnalysis>();
|
2012-02-09 05:22:53 +08:00
|
|
|
TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>();
|
|
|
|
|
2011-06-17 05:56:21 +08:00
|
|
|
RegClassInfo.runOnMachineFunction(Fn);
|
2009-10-10 08:15:38 +08:00
|
|
|
|
2009-10-02 05:46:35 +08:00
|
|
|
// Check for explicit enable/disable of post-ra scheduling.
|
2011-12-14 10:11:42 +08:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode =
|
|
|
|
TargetSubtargetInfo::ANTIDEP_NONE;
|
2012-02-22 13:59:10 +08:00
|
|
|
SmallVector<const TargetRegisterClass*, 4> CriticalPathRCs;
|
2009-10-02 05:46:35 +08:00
|
|
|
if (EnablePostRAScheduler.getPosition() > 0) {
|
|
|
|
if (!EnablePostRAScheduler)
|
2009-10-16 14:10:34 +08:00
|
|
|
return false;
|
2009-10-02 05:46:35 +08:00
|
|
|
} else {
|
2009-10-16 14:10:34 +08:00
|
|
|
// Check that post-RA scheduling is enabled for this target.
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
// This may upgrade the AntiDepMode.
|
2011-07-02 05:01:15 +08:00
|
|
|
const TargetSubtargetInfo &ST = Fn.getTarget().getSubtarget<TargetSubtargetInfo>();
|
2012-02-09 05:22:53 +08:00
|
|
|
if (!ST.enablePostRAScheduler(PassConfig->getOptLevel(), AntiDepMode,
|
|
|
|
CriticalPathRCs))
|
2009-10-16 14:10:34 +08:00
|
|
|
return false;
|
2009-10-02 05:46:35 +08:00
|
|
|
}
|
2009-09-30 08:10:16 +08:00
|
|
|
|
2009-10-23 07:19:17 +08:00
|
|
|
// Check for antidep breaking override...
|
|
|
|
if (EnableAntiDepBreaking.getPosition() > 0) {
|
2011-07-02 05:01:15 +08:00
|
|
|
AntiDepMode = (EnableAntiDepBreaking == "all")
|
|
|
|
? TargetSubtargetInfo::ANTIDEP_ALL
|
|
|
|
: ((EnableAntiDepBreaking == "critical")
|
|
|
|
? TargetSubtargetInfo::ANTIDEP_CRITICAL
|
|
|
|
: TargetSubtargetInfo::ANTIDEP_NONE);
|
2009-10-23 07:19:17 +08:00
|
|
|
}
|
|
|
|
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "PostRAScheduler\n");
|
2007-07-14 01:13:54 +08:00
|
|
|
|
2011-06-17 05:56:21 +08:00
|
|
|
SchedulePostRATDList Scheduler(Fn, MLI, MDT, AA, RegClassInfo, AntiDepMode,
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
CriticalPathRCs);
|
2009-01-16 03:20:50 +08:00
|
|
|
|
2007-07-14 01:13:54 +08:00
|
|
|
// Loop over all of the basic blocks
|
|
|
|
for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
|
2008-11-20 07:18:57 +08:00
|
|
|
MBB != MBBe; ++MBB) {
|
2009-09-02 02:34:03 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
|
|
|
|
if (DebugDiv > 0) {
|
|
|
|
static int bbcnt = 0;
|
|
|
|
if (bbcnt++ % DebugDiv != DebugMod)
|
|
|
|
continue;
|
2012-08-22 14:07:19 +08:00
|
|
|
dbgs() << "*** DEBUG scheduling " << Fn.getName()
|
2011-11-16 00:27:03 +08:00
|
|
|
<< ":BB#" << MBB->getNumber() << " ***\n";
|
2009-09-02 02:34:03 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
// Initialize register live-range state for scheduling in this block.
|
2012-03-08 07:00:49 +08:00
|
|
|
Scheduler.startBlock(MBB);
|
2009-02-11 07:27:53 +08:00
|
|
|
|
2009-01-17 06:10:20 +08:00
|
|
|
// Schedule each sequence of instructions not interrupted by a label
|
|
|
|
// or anything else that effectively needs to shut down scheduling.
|
2009-02-11 07:27:53 +08:00
|
|
|
MachineBasicBlock::iterator Current = MBB->end();
|
2009-02-11 12:27:20 +08:00
|
|
|
unsigned Count = MBB->size(), CurrentCount = Count;
|
2009-02-11 07:27:53 +08:00
|
|
|
for (MachineBasicBlock::iterator I = Current; I != MBB->begin(); ) {
|
2010-06-19 07:09:54 +08:00
|
|
|
MachineInstr *MI = llvm::prior(I);
|
Make calls scheduling boundaries post-ra.
Before register allocation, instructions can be moved across calls in
order to reduce register pressure. After register allocation, we don't
gain a lot by moving callee-saved defs across calls. In fact, since the
scheduler doesn't have a good idea how registers are used in the callee,
it can't really make good scheduling decisions.
This changes the schedule in two ways: 1. Latencies to call uses and
defs are no longer accounted for, causing some random shuffling around
calls. This isn't really a problem since those uses and defs are
inaccurate proxies for what happens inside the callee. They don't
represent registers used by the call instruction itself.
2. Instructions are no longer moved across calls. This didn't happen
very often, and the scheduling decision was made on dubious information
anyway.
As with any scheduling change, benchmark numbers shift around a bit,
but there is no positive or negative trend from this change.
This makes the post-ra scheduler 5% faster for ARM targets.
The secret motivation for this patch is the introduction of register
mask operands representing call clobbers. The most efficient way of
handling regmasks in ScheduleDAGInstrs is to model them as barriers for
physreg live ranges, but not for virtreg live ranges. That's fine
pre-ra, but post-ra it would have the same effect as this patch.
llvm-svn: 151265
2012-02-24 01:54:21 +08:00
|
|
|
// Calls are not scheduling boundaries before register allocation, but
|
|
|
|
// post-ra we don't gain anything by scheduling across calls since we
|
|
|
|
// don't need to worry about register pressure.
|
|
|
|
if (MI->isCall() || TII->isSchedulingBoundary(MI, MBB, Fn)) {
|
2012-03-07 13:21:52 +08:00
|
|
|
Scheduler.enterRegion(MBB, I, Current, CurrentCount);
|
2012-03-08 07:00:49 +08:00
|
|
|
Scheduler.schedule();
|
2012-03-07 13:21:52 +08:00
|
|
|
Scheduler.exitRegion();
|
2010-05-01 08:01:06 +08:00
|
|
|
Scheduler.EmitSchedule();
|
2009-02-11 07:27:53 +08:00
|
|
|
Current = MI;
|
2009-02-11 12:27:20 +08:00
|
|
|
CurrentCount = Count - 1;
|
2009-03-11 02:10:43 +08:00
|
|
|
Scheduler.Observe(MI, CurrentCount);
|
2009-01-17 06:10:20 +08:00
|
|
|
}
|
2009-02-11 07:27:53 +08:00
|
|
|
I = MI;
|
2009-02-11 12:27:20 +08:00
|
|
|
--Count;
|
2011-12-14 10:11:42 +08:00
|
|
|
if (MI->isBundle())
|
|
|
|
Count -= MI->getBundleSize();
|
2009-02-11 12:27:20 +08:00
|
|
|
}
|
|
|
|
assert(Count == 0 && "Instruction count mismatch!");
|
2009-03-11 17:04:34 +08:00
|
|
|
assert((MBB->begin() == Current || CurrentCount != 0) &&
|
2009-03-11 02:10:43 +08:00
|
|
|
"Instruction count mismatch!");
|
2012-03-07 13:21:52 +08:00
|
|
|
Scheduler.enterRegion(MBB, MBB->begin(), Current, CurrentCount);
|
2012-03-08 07:00:49 +08:00
|
|
|
Scheduler.schedule();
|
2012-03-07 13:21:52 +08:00
|
|
|
Scheduler.exitRegion();
|
2010-05-01 08:01:06 +08:00
|
|
|
Scheduler.EmitSchedule();
|
2009-02-11 07:27:53 +08:00
|
|
|
|
|
|
|
// Clean up register live-range state.
|
2012-03-08 07:00:49 +08:00
|
|
|
Scheduler.finishBlock();
|
2009-08-26 01:03:05 +08:00
|
|
|
|
2009-09-04 06:15:25 +08:00
|
|
|
// Update register kills
|
2009-08-26 01:03:05 +08:00
|
|
|
Scheduler.FixupKills(MBB);
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
2007-07-14 01:13:54 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
/// StartBlock - Initialize register live-range state for scheduling in
|
|
|
|
/// this block.
|
|
|
|
///
|
2012-03-08 07:00:49 +08:00
|
|
|
void SchedulePostRATDList::startBlock(MachineBasicBlock *BB) {
|
2009-02-11 07:27:53 +08:00
|
|
|
// Call the superclass.
|
2012-03-08 07:00:49 +08:00
|
|
|
ScheduleDAGInstrs::startBlock(BB);
|
2009-02-11 07:27:53 +08:00
|
|
|
|
2009-10-27 00:59:04 +08:00
|
|
|
// Reset the hazard recognizer and anti-dep breaker.
|
2009-08-10 23:55:25 +08:00
|
|
|
HazardRec->Reset();
|
2009-10-27 00:59:04 +08:00
|
|
|
if (AntiDepBreak != NULL)
|
|
|
|
AntiDepBreak->StartBlock(BB);
|
2009-02-11 07:27:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Schedule - Schedule the instruction range using list scheduling.
|
|
|
|
///
|
2012-03-08 07:00:49 +08:00
|
|
|
void SchedulePostRATDList::schedule() {
|
2008-12-24 02:36:58 +08:00
|
|
|
// Build the scheduling graph.
|
2012-03-08 07:00:49 +08:00
|
|
|
buildSchedGraph(AA);
|
2008-11-20 07:18:57 +08:00
|
|
|
|
2009-10-27 00:59:04 +08:00
|
|
|
if (AntiDepBreak != NULL) {
|
2010-05-15 05:19:48 +08:00
|
|
|
unsigned Broken =
|
2012-03-09 12:29:02 +08:00
|
|
|
AntiDepBreak->BreakAntiDependencies(SUnits, RegionBegin, RegionEnd,
|
|
|
|
EndIndex, DbgValues);
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-11-21 03:32:48 +08:00
|
|
|
if (Broken != 0) {
|
2008-11-25 08:52:40 +08:00
|
|
|
// We made changes. Update the dependency graph.
|
|
|
|
// Theoretically we could update the graph in place:
|
|
|
|
// When a live range is changed to use a different register, remove
|
|
|
|
// the def's anti-dependence *and* output-dependence edges due to
|
|
|
|
// that register, and add new anti-dependence and output-dependence
|
|
|
|
// edges based on the next live range of the register.
|
2012-03-07 13:21:52 +08:00
|
|
|
ScheduleDAG::clearDAG();
|
2012-03-08 07:00:49 +08:00
|
|
|
buildSchedGraph(AA);
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-10-27 00:59:04 +08:00
|
|
|
NumFixedAnti += Broken;
|
2008-11-25 08:52:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "********** List Scheduling **********\n");
|
2009-08-10 23:55:25 +08:00
|
|
|
DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
|
|
|
|
SUnits[su].dumpAll(this));
|
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
AvailableQueue.initNodes(SUnits);
|
2009-11-21 03:32:48 +08:00
|
|
|
ListScheduleTopDown();
|
2008-11-20 07:18:57 +08:00
|
|
|
AvailableQueue.releaseState();
|
|
|
|
}
|
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
/// Observe - Update liveness information to account for the current
|
|
|
|
/// instruction, which will not be scheduled.
|
|
|
|
///
|
2009-02-11 12:27:20 +08:00
|
|
|
void SchedulePostRATDList::Observe(MachineInstr *MI, unsigned Count) {
|
2009-10-27 00:59:04 +08:00
|
|
|
if (AntiDepBreak != NULL)
|
2012-03-08 07:00:52 +08:00
|
|
|
AntiDepBreak->Observe(MI, Count, EndIndex);
|
2009-02-11 07:27:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// FinishBlock - Clean up register live-range state.
|
|
|
|
///
|
2012-03-08 07:00:49 +08:00
|
|
|
void SchedulePostRATDList::finishBlock() {
|
2009-10-27 00:59:04 +08:00
|
|
|
if (AntiDepBreak != NULL)
|
|
|
|
AntiDepBreak->FinishBlock();
|
2009-02-11 07:27:53 +08:00
|
|
|
|
|
|
|
// Call the superclass.
|
2012-03-08 07:00:49 +08:00
|
|
|
ScheduleDAGInstrs::finishBlock();
|
2009-02-11 07:27:53 +08:00
|
|
|
}
|
|
|
|
|
2009-09-04 06:15:25 +08:00
|
|
|
/// StartBlockForKills - Initialize register live-range state for updating kills
|
|
|
|
///
|
|
|
|
void SchedulePostRATDList::StartBlockForKills(MachineBasicBlock *BB) {
|
2012-02-24 03:15:40 +08:00
|
|
|
// Start with no live registers.
|
|
|
|
LiveRegs.reset();
|
2009-09-04 06:15:25 +08:00
|
|
|
|
2013-02-06 02:21:52 +08:00
|
|
|
// Examine the live-in regs of all successors.
|
|
|
|
for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
|
|
|
|
SE = BB->succ_end(); SI != SE; ++SI) {
|
|
|
|
for (MachineBasicBlock::livein_iterator I = (*SI)->livein_begin(),
|
|
|
|
E = (*SI)->livein_end(); I != E; ++I) {
|
2009-09-04 06:15:25 +08:00
|
|
|
unsigned Reg = *I;
|
2013-05-23 07:17:36 +08:00
|
|
|
// Repeat, for reg and all subregs.
|
|
|
|
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
|
|
|
|
SubRegs.isValid(); ++SubRegs)
|
2012-06-02 07:28:30 +08:00
|
|
|
LiveRegs.set(*SubRegs);
|
2009-09-04 06:15:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 00:35:25 +08:00
|
|
|
bool SchedulePostRATDList::ToggleKillFlag(MachineInstr *MI,
|
|
|
|
MachineOperand &MO) {
|
|
|
|
// Setting kill flag...
|
|
|
|
if (!MO.isKill()) {
|
|
|
|
MO.setIsKill(true);
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-09-24 00:35:25 +08:00
|
|
|
// If MO itself is live, clear the kill flag...
|
2012-02-24 03:15:40 +08:00
|
|
|
if (LiveRegs.test(MO.getReg())) {
|
2009-09-24 00:35:25 +08:00
|
|
|
MO.setIsKill(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If any subreg of MO is live, then create an imp-def for that
|
|
|
|
// subreg and keep MO marked as killed.
|
2009-10-02 23:59:52 +08:00
|
|
|
MO.setIsKill(false);
|
2009-09-24 00:35:25 +08:00
|
|
|
bool AllDead = true;
|
|
|
|
const unsigned SuperReg = MO.getReg();
|
2012-12-21 02:08:06 +08:00
|
|
|
MachineInstrBuilder MIB(MF, MI);
|
2012-06-02 07:28:30 +08:00
|
|
|
for (MCSubRegIterator SubRegs(SuperReg, TRI); SubRegs.isValid(); ++SubRegs) {
|
|
|
|
if (LiveRegs.test(*SubRegs)) {
|
2012-12-21 02:08:06 +08:00
|
|
|
MIB.addReg(*SubRegs, RegState::ImplicitDefine);
|
2009-09-24 00:35:25 +08:00
|
|
|
AllDead = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 09:44:44 +08:00
|
|
|
if(AllDead)
|
2009-10-02 23:59:52 +08:00
|
|
|
MO.setIsKill(true);
|
2009-09-24 00:35:25 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-26 01:03:05 +08:00
|
|
|
/// FixupKills - Fix the register kill flags, they may have been made
|
|
|
|
/// incorrect by instruction reordering.
|
|
|
|
///
|
|
|
|
void SchedulePostRATDList::FixupKills(MachineBasicBlock *MBB) {
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "Fixup kills for BB#" << MBB->getNumber() << '\n');
|
2009-08-26 01:03:05 +08:00
|
|
|
|
2012-02-24 02:28:32 +08:00
|
|
|
BitVector killedRegs(TRI->getNumRegs());
|
2009-09-04 06:15:25 +08:00
|
|
|
|
|
|
|
StartBlockForKills(MBB);
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-08-29 08:11:13 +08:00
|
|
|
// Examine block from end to start...
|
2009-08-26 01:03:05 +08:00
|
|
|
unsigned Count = MBB->size();
|
|
|
|
for (MachineBasicBlock::iterator I = MBB->end(), E = MBB->begin();
|
|
|
|
I != E; --Count) {
|
|
|
|
MachineInstr *MI = --I;
|
2010-03-05 08:02:59 +08:00
|
|
|
if (MI->isDebugValue())
|
|
|
|
continue;
|
2009-08-26 01:03:05 +08:00
|
|
|
|
2009-08-29 08:11:13 +08:00
|
|
|
// Update liveness. Registers that are defed but not used in this
|
|
|
|
// instruction are now dead. Mark register and all subregs as they
|
|
|
|
// are completely defined.
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = MI->getOperand(i);
|
2012-02-23 09:22:15 +08:00
|
|
|
if (MO.isRegMask())
|
2012-02-24 03:29:25 +08:00
|
|
|
LiveRegs.clearBitsNotInMask(MO.getRegMask());
|
2009-08-29 08:11:13 +08:00
|
|
|
if (!MO.isReg()) continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Reg == 0) continue;
|
|
|
|
if (!MO.isDef()) continue;
|
|
|
|
// Ignore two-addr defs.
|
|
|
|
if (MI->isRegTiedToUseOperand(i)) continue;
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2013-05-23 07:17:36 +08:00
|
|
|
// Repeat for reg and all subregs.
|
|
|
|
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
|
|
|
|
SubRegs.isValid(); ++SubRegs)
|
2012-06-02 07:28:30 +08:00
|
|
|
LiveRegs.reset(*SubRegs);
|
2009-08-29 08:11:13 +08:00
|
|
|
}
|
2009-08-26 01:03:05 +08:00
|
|
|
|
2009-09-24 00:35:25 +08:00
|
|
|
// Examine all used registers and set/clear kill flag. When a
|
|
|
|
// register is used multiple times we only set the kill flag on
|
|
|
|
// the first use.
|
2012-02-24 02:28:32 +08:00
|
|
|
killedRegs.reset();
|
2009-08-26 01:03:05 +08:00
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = MI->getOperand(i);
|
|
|
|
if (!MO.isReg() || !MO.isUse()) continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
2012-10-16 05:57:41 +08:00
|
|
|
if ((Reg == 0) || MRI.isReserved(Reg)) continue;
|
2009-08-26 01:03:05 +08:00
|
|
|
|
2009-08-29 08:11:13 +08:00
|
|
|
bool kill = false;
|
2012-02-24 02:28:32 +08:00
|
|
|
if (!killedRegs.test(Reg)) {
|
2009-08-29 08:11:13 +08:00
|
|
|
kill = true;
|
|
|
|
// A register is not killed if any subregs are live...
|
2012-06-02 07:28:30 +08:00
|
|
|
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
|
|
|
|
if (LiveRegs.test(*SubRegs)) {
|
2009-08-29 08:11:13 +08:00
|
|
|
kill = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If subreg is not live, then register is killed if it became
|
|
|
|
// live in this instruction
|
|
|
|
if (kill)
|
2012-02-24 03:15:40 +08:00
|
|
|
kill = !LiveRegs.test(Reg);
|
2009-08-29 08:11:13 +08:00
|
|
|
}
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-08-26 01:03:05 +08:00
|
|
|
if (MO.isKill() != kill) {
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "Fixing " << MO << " in ");
|
2009-12-03 09:49:56 +08:00
|
|
|
// Warning: ToggleKillFlag may invalidate MO.
|
|
|
|
ToggleKillFlag(MI, MO);
|
2009-08-26 01:03:05 +08:00
|
|
|
DEBUG(MI->dump());
|
|
|
|
}
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2012-02-24 02:28:32 +08:00
|
|
|
killedRegs.set(Reg);
|
2009-08-26 01:03:05 +08:00
|
|
|
}
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-09-01 04:47:02 +08:00
|
|
|
// Mark any used register (that is not using undef) and subregs as
|
|
|
|
// now live...
|
2009-08-29 08:11:13 +08:00
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = MI->getOperand(i);
|
2009-09-01 04:47:02 +08:00
|
|
|
if (!MO.isReg() || !MO.isUse() || MO.isUndef()) continue;
|
2009-08-29 08:11:13 +08:00
|
|
|
unsigned Reg = MO.getReg();
|
2012-10-16 05:57:41 +08:00
|
|
|
if ((Reg == 0) || MRI.isReserved(Reg)) continue;
|
2009-08-29 08:11:13 +08:00
|
|
|
|
2013-05-23 07:17:36 +08:00
|
|
|
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
|
|
|
|
SubRegs.isValid(); ++SubRegs)
|
2012-06-02 07:28:30 +08:00
|
|
|
LiveRegs.set(*SubRegs);
|
2009-08-29 08:11:13 +08:00
|
|
|
}
|
2009-08-26 01:03:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-Down Scheduling
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
|
2012-11-13 03:28:57 +08:00
|
|
|
/// the PendingQueue if the count reaches zero.
|
2009-11-21 03:32:48 +08:00
|
|
|
void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
|
2008-12-10 06:54:47 +08:00
|
|
|
SUnit *SuccSU = SuccEdge->getSUnit();
|
2009-10-01 04:15:38 +08:00
|
|
|
|
2012-11-13 10:35:06 +08:00
|
|
|
if (SuccEdge->isWeak()) {
|
2012-11-13 03:28:57 +08:00
|
|
|
--SuccSU->WeakPredsLeft;
|
|
|
|
return;
|
|
|
|
}
|
2008-11-20 07:18:57 +08:00
|
|
|
#ifndef NDEBUG
|
2009-10-01 04:15:38 +08:00
|
|
|
if (SuccSU->NumPredsLeft == 0) {
|
2010-01-05 09:26:01 +08:00
|
|
|
dbgs() << "*** Scheduling failed! ***\n";
|
2008-11-20 07:18:57 +08:00
|
|
|
SuccSU->dump(this);
|
2010-01-05 09:26:01 +08:00
|
|
|
dbgs() << " has been released too many times!\n";
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable(0);
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
|
|
|
#endif
|
2009-10-01 04:15:38 +08:00
|
|
|
--SuccSU->NumPredsLeft;
|
|
|
|
|
2011-05-07 02:14:32 +08:00
|
|
|
// Standard scheduler algorithms will recompute the depth of the successor
|
2011-05-07 01:09:08 +08:00
|
|
|
// here as such:
|
|
|
|
// SuccSU->setDepthToAtLeast(SU->getDepth() + SuccEdge->getLatency());
|
|
|
|
//
|
|
|
|
// However, we lazily compute node depth instead. Note that
|
|
|
|
// ScheduleNodeTopDown has already updated the depth of this node which causes
|
|
|
|
// all descendents to be marked dirty. Setting the successor depth explicitly
|
|
|
|
// here would cause depth to be recomputed for all its ancestors. If the
|
|
|
|
// successor is not yet ready (because of a transitively redundant edge) then
|
|
|
|
// this causes depth computation to be quadratic in the size of the DAG.
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
// If all the node's predecessors are scheduled, this node is ready
|
|
|
|
// to be scheduled. Ignore the special ExitSU node.
|
|
|
|
if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU)
|
2008-11-20 07:18:57 +08:00
|
|
|
PendingQueue.push_back(SuccSU);
|
2009-02-11 07:27:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ReleaseSuccessors - Call ReleaseSucc on each of SU's successors.
|
2009-11-21 03:32:48 +08:00
|
|
|
void SchedulePostRATDList::ReleaseSuccessors(SUnit *SU) {
|
2009-02-11 07:27:53 +08:00
|
|
|
for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
|
2009-11-04 04:57:50 +08:00
|
|
|
I != E; ++I) {
|
2009-11-21 03:32:48 +08:00
|
|
|
ReleaseSucc(SU, &*I);
|
2009-11-04 04:57:50 +08:00
|
|
|
}
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
|
|
|
|
/// count of its successors. If a successor pending count is zero, add it to
|
|
|
|
/// the Available queue.
|
2009-11-21 03:32:48 +08:00
|
|
|
void SchedulePostRATDList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: ");
|
2008-11-20 07:18:57 +08:00
|
|
|
DEBUG(SU->dump(this));
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
Sequence.push_back(SU);
|
2010-05-15 05:19:48 +08:00
|
|
|
assert(CurCycle >= SU->getDepth() &&
|
2009-11-04 04:57:50 +08:00
|
|
|
"Node scheduled above its depth!");
|
2009-11-21 03:32:48 +08:00
|
|
|
SU->setDepthToAtLeast(CurCycle);
|
2008-11-20 07:18:57 +08:00
|
|
|
|
2009-11-21 03:32:48 +08:00
|
|
|
ReleaseSuccessors(SU);
|
2008-11-20 07:18:57 +08:00
|
|
|
SU->isScheduled = true;
|
2012-03-08 07:00:49 +08:00
|
|
|
AvailableQueue.scheduledNode(SU);
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ListScheduleTopDown - The main loop of list scheduling for top-down
|
|
|
|
/// schedulers.
|
2009-11-21 03:32:48 +08:00
|
|
|
void SchedulePostRATDList::ListScheduleTopDown() {
|
2008-11-20 07:18:57 +08:00
|
|
|
unsigned CurCycle = 0;
|
2010-05-15 05:19:48 +08:00
|
|
|
|
2009-11-04 04:57:50 +08:00
|
|
|
// We're scheduling top-down but we're visiting the regions in
|
|
|
|
// bottom-up order, so we don't know the hazards at the start of a
|
|
|
|
// region. So assume no hazards (this should usually be ok as most
|
|
|
|
// blocks are a single region).
|
|
|
|
HazardRec->Reset();
|
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
// Release any successors of the special Entry node.
|
2009-11-21 03:32:48 +08:00
|
|
|
ReleaseSuccessors(&EntrySU);
|
2009-02-11 07:27:53 +08:00
|
|
|
|
2009-11-21 03:32:48 +08:00
|
|
|
// Add all leaves to Available queue.
|
2008-11-20 07:18:57 +08:00
|
|
|
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
|
|
|
|
// It is available if it has no predecessors.
|
2012-11-13 03:28:57 +08:00
|
|
|
if (!SUnits[i].NumPredsLeft && !SUnits[i].isAvailable) {
|
2008-11-20 07:18:57 +08:00
|
|
|
AvailableQueue.push(&SUnits[i]);
|
|
|
|
SUnits[i].isAvailable = true;
|
|
|
|
}
|
|
|
|
}
|
2009-02-11 07:27:53 +08:00
|
|
|
|
2009-08-13 05:47:46 +08:00
|
|
|
// In any cycle where we can't schedule any instructions, we must
|
|
|
|
// stall or emit a noop, depending on the target.
|
2009-09-06 20:10:17 +08:00
|
|
|
bool CycleHasInsts = false;
|
2009-08-13 05:47:46 +08:00
|
|
|
|
2008-11-20 07:18:57 +08:00
|
|
|
// While Available queue is not empty, grab the node with the highest
|
|
|
|
// priority. If it is not ready put it back. Schedule the node.
|
2009-01-16 09:33:36 +08:00
|
|
|
std::vector<SUnit*> NotReady;
|
2008-11-20 07:18:57 +08:00
|
|
|
Sequence.reserve(SUnits.size());
|
|
|
|
while (!AvailableQueue.empty() || !PendingQueue.empty()) {
|
|
|
|
// Check to see if any of the pending instructions are ready to issue. If
|
|
|
|
// so, add them to the available queue.
|
2008-12-16 11:25:46 +08:00
|
|
|
unsigned MinDepth = ~0u;
|
2008-11-20 07:18:57 +08:00
|
|
|
for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
|
2009-11-21 03:32:48 +08:00
|
|
|
if (PendingQueue[i]->getDepth() <= CurCycle) {
|
2008-11-20 07:18:57 +08:00
|
|
|
AvailableQueue.push(PendingQueue[i]);
|
|
|
|
PendingQueue[i]->isAvailable = true;
|
|
|
|
PendingQueue[i] = PendingQueue.back();
|
|
|
|
PendingQueue.pop_back();
|
|
|
|
--i; --e;
|
2009-11-21 03:32:48 +08:00
|
|
|
} else if (PendingQueue[i]->getDepth() < MinDepth)
|
|
|
|
MinDepth = PendingQueue[i]->getDepth();
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
2009-08-12 01:35:23 +08:00
|
|
|
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
DEBUG(dbgs() << "\n*** Examining Available\n"; AvailableQueue.dump(this));
|
2009-08-12 01:35:23 +08:00
|
|
|
|
2009-01-16 09:33:36 +08:00
|
|
|
SUnit *FoundSUnit = 0;
|
|
|
|
bool HasNoopHazards = false;
|
|
|
|
while (!AvailableQueue.empty()) {
|
|
|
|
SUnit *CurSUnit = AvailableQueue.pop();
|
|
|
|
|
|
|
|
ScheduleHazardRecognizer::HazardType HT =
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
llvm-svn: 122541
2010-12-24 13:03:26 +08:00
|
|
|
HazardRec->getHazardType(CurSUnit, 0/*no stalls*/);
|
2009-01-16 09:33:36 +08:00
|
|
|
if (HT == ScheduleHazardRecognizer::NoHazard) {
|
|
|
|
FoundSUnit = CurSUnit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember if this is a noop hazard.
|
|
|
|
HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard;
|
|
|
|
|
|
|
|
NotReady.push_back(CurSUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the nodes that aren't ready back onto the available list.
|
|
|
|
if (!NotReady.empty()) {
|
|
|
|
AvailableQueue.push_all(NotReady);
|
|
|
|
NotReady.clear();
|
|
|
|
}
|
|
|
|
|
2009-11-04 04:57:50 +08:00
|
|
|
// If we found a node to schedule...
|
2008-11-20 07:18:57 +08:00
|
|
|
if (FoundSUnit) {
|
2009-11-04 04:57:50 +08:00
|
|
|
// ... schedule the node...
|
2009-11-21 03:32:48 +08:00
|
|
|
ScheduleNodeTopDown(FoundSUnit, CurCycle);
|
2009-01-16 09:33:36 +08:00
|
|
|
HazardRec->EmitInstruction(FoundSUnit);
|
2009-09-06 20:10:17 +08:00
|
|
|
CycleHasInsts = true;
|
2011-06-01 11:27:56 +08:00
|
|
|
if (HazardRec->atIssueLimit()) {
|
|
|
|
DEBUG(dbgs() << "*** Max instructions per cycle " << CurCycle << '\n');
|
|
|
|
HazardRec->AdvanceCycle();
|
|
|
|
++CurCycle;
|
|
|
|
CycleHasInsts = false;
|
|
|
|
}
|
2009-01-16 09:33:36 +08:00
|
|
|
} else {
|
2009-09-06 20:10:17 +08:00
|
|
|
if (CycleHasInsts) {
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "*** Finished cycle " << CurCycle << '\n');
|
2009-08-13 05:47:46 +08:00
|
|
|
HazardRec->AdvanceCycle();
|
|
|
|
} else if (!HasNoopHazards) {
|
|
|
|
// Otherwise, we have a pipeline stall, but no other problem,
|
|
|
|
// just advance the current cycle and try again.
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "*** Stall in cycle " << CurCycle << '\n');
|
2009-08-13 05:47:46 +08:00
|
|
|
HazardRec->AdvanceCycle();
|
2009-11-21 03:32:48 +08:00
|
|
|
++NumStalls;
|
2009-08-13 05:47:46 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise, we have no instructions to issue and we have instructions
|
|
|
|
// that will fault if we don't do this right. This is the case for
|
|
|
|
// processors without pipeline interlocks and other cases.
|
2010-01-05 09:26:01 +08:00
|
|
|
DEBUG(dbgs() << "*** Emitting noop in cycle " << CurCycle << '\n');
|
2009-08-13 05:47:46 +08:00
|
|
|
HazardRec->EmitNoop();
|
|
|
|
Sequence.push_back(0); // NULL here means noop
|
2009-11-21 03:32:48 +08:00
|
|
|
++NumNoops;
|
2009-08-13 05:47:46 +08:00
|
|
|
}
|
|
|
|
|
2009-01-16 09:33:36 +08:00
|
|
|
++CurCycle;
|
2009-09-06 20:10:17 +08:00
|
|
|
CycleHasInsts = false;
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2012-03-07 13:21:36 +08:00
|
|
|
unsigned ScheduledNodes = VerifyScheduledDAG(/*isBottomUp=*/false);
|
|
|
|
unsigned Noops = 0;
|
|
|
|
for (unsigned i = 0, e = Sequence.size(); i != e; ++i)
|
|
|
|
if (!Sequence[i])
|
|
|
|
++Noops;
|
|
|
|
assert(Sequence.size() - Noops == ScheduledNodes &&
|
|
|
|
"The number of nodes scheduled doesn't match the expected number!");
|
|
|
|
#endif // NDEBUG
|
2008-11-20 07:18:57 +08:00
|
|
|
}
|
2012-03-07 13:21:44 +08:00
|
|
|
|
|
|
|
// EmitSchedule - Emit the machine code in scheduled order.
|
|
|
|
void SchedulePostRATDList::EmitSchedule() {
|
2012-03-09 12:29:02 +08:00
|
|
|
RegionBegin = RegionEnd;
|
2012-03-07 13:21:44 +08:00
|
|
|
|
|
|
|
// If first instruction was a DBG_VALUE then put it back.
|
|
|
|
if (FirstDbgValue)
|
2012-03-09 12:29:02 +08:00
|
|
|
BB->splice(RegionEnd, BB, FirstDbgValue);
|
2012-03-07 13:21:44 +08:00
|
|
|
|
|
|
|
// Then re-insert them according to the given schedule.
|
|
|
|
for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
|
|
|
|
if (SUnit *SU = Sequence[i])
|
2012-03-09 12:29:02 +08:00
|
|
|
BB->splice(RegionEnd, BB, SU->getInstr());
|
2012-03-07 13:21:44 +08:00
|
|
|
else
|
|
|
|
// Null SUnit* is a noop.
|
2012-03-09 12:29:02 +08:00
|
|
|
TII->insertNoop(*BB, RegionEnd);
|
2012-03-07 13:21:44 +08:00
|
|
|
|
|
|
|
// Update the Begin iterator, as the first instruction in the block
|
|
|
|
// may have been scheduled later.
|
|
|
|
if (i == 0)
|
2012-03-09 12:29:02 +08:00
|
|
|
RegionBegin = prior(RegionEnd);
|
2012-03-07 13:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reinsert any remaining debug_values.
|
|
|
|
for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator
|
|
|
|
DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) {
|
|
|
|
std::pair<MachineInstr *, MachineInstr *> P = *prior(DI);
|
|
|
|
MachineInstr *DbgValue = P.first;
|
|
|
|
MachineBasicBlock::iterator OrigPrivMI = P.second;
|
|
|
|
BB->splice(++OrigPrivMI, BB, DbgValue);
|
|
|
|
}
|
|
|
|
DbgValues.clear();
|
|
|
|
FirstDbgValue = NULL;
|
|
|
|
}
|