2007-07-13 19:31:29 +02:00
|
|
|
//===----- SchedulePostRAList.cpp - list scheduler ------------------------===//
|
2007-07-13 19:13:54 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2007-07-13 19:13:54 +02: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2020-04-13 21:26:44 +02:00
|
|
|
#include "llvm/CodeGen/AntiDepBreaker.h"
|
2008-11-20 00:18:57 +01:00
|
|
|
#include "llvm/CodeGen/LatencyPriorityQueue.h"
|
2008-12-16 04:25:46 +01:00
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
2007-07-13 19:13:54 +02:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2008-12-16 04:25:46 +01:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2008-11-25 01:52:40 +01:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2016-04-18 11:17:29 +02:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2012-06-06 22:29:31 +02:00
|
|
|
#include "llvm/CodeGen/RegisterClassInfo.h"
|
2012-03-08 00:01:06 +01:00
|
|
|
#include "llvm/CodeGen/ScheduleDAGInstrs.h"
|
2009-01-16 02:33:36 +01:00
|
|
|
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/CodeGen/SchedulerRegistry.h"
|
2017-11-08 02:01:31 +01:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2016-05-10 05:21:59 +02:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2018-04-30 16:59:11 +02:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-13 22:15:01 +01:00
|
|
|
#include "llvm/InitializePasses.h"
|
2009-10-26 23:31:16 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2007-07-13 19:13:54 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-11 03:44:26 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-07-13 19:13:54 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 04:02:50 +02:00
|
|
|
#define DEBUG_TYPE "post-RA-sched"
|
|
|
|
|
2009-01-16 02:33:36 +01:00
|
|
|
STATISTIC(NumNoops, "Number of noops inserted");
|
2008-11-20 00:18:57 +01:00
|
|
|
STATISTIC(NumStalls, "Number of pipeline stalls");
|
2009-10-26 17:59:04 +01:00
|
|
|
STATISTIC(NumFixedAnti, "Number of fixed anti-dependencies");
|
2008-11-20 00:18:57 +01:00
|
|
|
|
2009-10-01 23:46:35 +02:00
|
|
|
// Post-RA scheduling is enabled with
|
2011-07-01 23:01:15 +02:00
|
|
|
// TargetSubtargetInfo.enablePostRAScheduler(). This flag can be used to
|
2009-10-01 23:46:35 +02:00
|
|
|
// override the target.
|
|
|
|
static cl::opt<bool>
|
|
|
|
EnablePostRAScheduler("post-RA-scheduler",
|
|
|
|
cl::desc("Enable scheduling after register allocation"),
|
2009-10-02 00:19:57 +02:00
|
|
|
cl::init(false), cl::Hidden);
|
2009-10-26 17:59:04 +01:00
|
|
|
static cl::opt<std::string>
|
2008-11-25 01:52:40 +01:00
|
|
|
EnableAntiDepBreaking("break-anti-dependencies",
|
2009-10-26 17:59:04 +01:00
|
|
|
cl::desc("Break post-RA scheduling anti-dependencies: "
|
|
|
|
"\"critical\", \"all\", or \"none\""),
|
|
|
|
cl::init("none"), cl::Hidden);
|
2009-01-16 02:33:36 +01:00
|
|
|
|
2009-09-01 20:34:03 +02: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-26 20:41:00 +01:00
|
|
|
AntiDepBreaker::~AntiDepBreaker() { }
|
|
|
|
|
2007-07-13 19:13:54 +02:00
|
|
|
namespace {
|
2009-10-25 07:33:48 +01:00
|
|
|
class PostRAScheduler : public MachineFunctionPass {
|
2019-11-07 17:45:01 +01:00
|
|
|
const TargetInstrInfo *TII = nullptr;
|
2011-06-16 23:56:21 +02:00
|
|
|
RegisterClassInfo RegClassInfo;
|
2009-10-10 01:27:56 +02:00
|
|
|
|
2007-07-13 19:13:54 +02:00
|
|
|
public:
|
|
|
|
static char ID;
|
2012-02-08 22:22:53 +01:00
|
|
|
PostRAScheduler() : MachineFunctionPass(ID) {}
|
2008-11-25 01:52:40 +01:00
|
|
|
|
2014-03-07 10:26:03 +01:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2009-08-01 01:37:33 +02:00
|
|
|
AU.setPreservesCFG();
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-09 19:55:00 +02:00
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
2012-02-08 22:22:53 +01:00
|
|
|
AU.addRequired<TargetPassConfig>();
|
2008-12-16 04:25:46 +01:00
|
|
|
AU.addRequired<MachineDominatorTree>();
|
|
|
|
AU.addPreserved<MachineDominatorTree>();
|
|
|
|
AU.addRequired<MachineLoopInfo>();
|
|
|
|
AU.addPreserved<MachineLoopInfo>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2016-03-28 19:05:30 +02:00
|
|
|
MachineFunctionProperties getRequiredProperties() const override {
|
|
|
|
return MachineFunctionProperties().set(
|
2016-08-25 03:27:13 +02:00
|
|
|
MachineFunctionProperties::Property::NoVRegs);
|
2016-03-28 19:05:30 +02:00
|
|
|
}
|
|
|
|
|
2014-03-07 10:26:03 +01:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
2014-10-29 16:23:11 +01:00
|
|
|
|
2016-05-19 18:40:49 +02:00
|
|
|
private:
|
2014-07-16 00:39:58 +02:00
|
|
|
bool enablePostRAScheduler(
|
|
|
|
const TargetSubtargetInfo &ST, CodeGenOpt::Level OptLevel,
|
|
|
|
TargetSubtargetInfo::AntiDepBreakMode &Mode,
|
|
|
|
TargetSubtargetInfo::RegClassVector &CriticalPathRCs) const;
|
2008-11-20 00:18:57 +01:00
|
|
|
};
|
|
|
|
char PostRAScheduler::ID = 0;
|
|
|
|
|
2009-10-25 07:33:48 +01:00
|
|
|
class SchedulePostRATDList : public ScheduleDAGInstrs {
|
2008-11-20 00:18:57 +01:00
|
|
|
/// AvailableQueue - The priority queue to use for the available SUnits.
|
2009-10-21 03:44:44 +02:00
|
|
|
///
|
2008-11-20 00:18:57 +01:00
|
|
|
LatencyPriorityQueue AvailableQueue;
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2008-11-20 00:18:57 +01: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 03:44:44 +02:00
|
|
|
/// HazardRec - The hazard recognizer to use.
|
|
|
|
ScheduleHazardRecognizer *HazardRec;
|
|
|
|
|
2009-10-26 17:59:04 +01:00
|
|
|
/// AntiDepBreak - Anti-dependence breaking object, or NULL if none
|
|
|
|
AntiDepBreaker *AntiDepBreak;
|
|
|
|
|
2009-10-21 03:44:44 +02:00
|
|
|
/// AA - AliasAnalysis for making memory reference queries.
|
|
|
|
AliasAnalysis *AA;
|
2009-10-20 21:54:44 +02:00
|
|
|
|
2012-03-07 06:21:52 +01:00
|
|
|
/// The schedule. Null SUnit*'s represent noop instructions.
|
|
|
|
std::vector<SUnit*> Sequence;
|
|
|
|
|
2016-03-05 16:45:23 +01:00
|
|
|
/// Ordered list of DAG postprocessing steps.
|
|
|
|
std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
|
|
|
|
|
2013-08-23 19:48:33 +02:00
|
|
|
/// The index in BB of RegionEnd.
|
|
|
|
///
|
|
|
|
/// This is the instruction number from the top of the current block, not
|
|
|
|
/// the SlotIndex. It is only used by the AntiDepBreaker.
|
|
|
|
unsigned EndIndex;
|
|
|
|
|
2008-11-25 01:52:40 +01: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 06:03:26 +01:00
|
|
|
SchedulePostRATDList(
|
2014-08-20 22:57:26 +02:00
|
|
|
MachineFunction &MF, MachineLoopInfo &MLI, AliasAnalysis *AA,
|
|
|
|
const RegisterClassInfo &,
|
|
|
|
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
|
|
|
|
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 06:03:26 +01:00
|
|
|
|
2015-04-11 04:11:45 +02:00
|
|
|
~SchedulePostRATDList() override;
|
2008-11-20 00:18:57 +01:00
|
|
|
|
2012-03-08 00:00:49 +01:00
|
|
|
/// startBlock - Initialize register live-range state for scheduling in
|
2009-02-11 00:27:53 +01:00
|
|
|
/// this block.
|
|
|
|
///
|
2014-03-07 10:26:03 +01:00
|
|
|
void startBlock(MachineBasicBlock *BB) override;
|
2009-02-11 00:27:53 +01:00
|
|
|
|
2013-08-23 19:48:33 +02:00
|
|
|
// Set the index of RegionEnd within the current BB.
|
|
|
|
void setEndIndex(unsigned EndIdx) { EndIndex = EndIdx; }
|
|
|
|
|
2012-03-07 06:21:52 +01:00
|
|
|
/// Initialize the scheduler state for the next scheduling region.
|
2014-03-07 10:26:03 +01:00
|
|
|
void enterRegion(MachineBasicBlock *bb,
|
|
|
|
MachineBasicBlock::iterator begin,
|
|
|
|
MachineBasicBlock::iterator end,
|
|
|
|
unsigned regioninstrs) override;
|
2012-03-07 06:21:52 +01:00
|
|
|
|
|
|
|
/// Notify that the scheduler has finished scheduling the current region.
|
2014-03-07 10:26:03 +01:00
|
|
|
void exitRegion() override;
|
2012-03-07 06:21:52 +01:00
|
|
|
|
2009-10-20 21:54:44 +02:00
|
|
|
/// Schedule - Schedule the instruction range using list scheduling.
|
2009-02-11 00:27:53 +01:00
|
|
|
///
|
2014-03-07 10:26:03 +01:00
|
|
|
void schedule() override;
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2012-03-07 06:21:44 +01:00
|
|
|
void EmitSchedule();
|
|
|
|
|
2009-10-21 03:44:44 +02:00
|
|
|
/// Observe - Update liveness information to account for the current
|
|
|
|
/// instruction, which will not be scheduled.
|
|
|
|
///
|
2016-02-27 20:33:37 +01:00
|
|
|
void Observe(MachineInstr &MI, unsigned Count);
|
2009-10-20 21:54:44 +02:00
|
|
|
|
2012-03-08 00:00:49 +01:00
|
|
|
/// finishBlock - Clean up register live-range state.
|
2009-10-21 03:44:44 +02:00
|
|
|
///
|
2014-03-07 10:26:03 +01:00
|
|
|
void finishBlock() override;
|
2009-10-20 21:54:44 +02:00
|
|
|
|
2009-10-21 03:44:44 +02:00
|
|
|
private:
|
2016-03-05 16:45:23 +01:00
|
|
|
/// Apply each ScheduleDAGMutation step in order.
|
|
|
|
void postprocessDAG();
|
|
|
|
|
2009-11-20 20:32:48 +01:00
|
|
|
void ReleaseSucc(SUnit *SU, SDep *SuccEdge);
|
|
|
|
void ReleaseSuccessors(SUnit *SU);
|
|
|
|
void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle);
|
|
|
|
void ListScheduleTopDown();
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2012-03-07 06:21:40 +01:00
|
|
|
void dumpSchedule() const;
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
void emitNoop(unsigned CurCycle);
|
2007-07-13 19:13:54 +02:00
|
|
|
};
|
2015-06-23 11:49:53 +02:00
|
|
|
}
|
2007-07-13 19:13:54 +02:00
|
|
|
|
2012-02-08 22:23:13 +01:00
|
|
|
char &llvm::PostRASchedulerID = PostRAScheduler::ID;
|
|
|
|
|
2017-05-25 23:26:32 +02:00
|
|
|
INITIALIZE_PASS(PostRAScheduler, DEBUG_TYPE,
|
2012-02-08 22:23:13 +01:00
|
|
|
"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 06:03:26 +01:00
|
|
|
SchedulePostRATDList::SchedulePostRATDList(
|
2014-08-20 22:57:26 +02:00
|
|
|
MachineFunction &MF, MachineLoopInfo &MLI, AliasAnalysis *AA,
|
|
|
|
const RegisterClassInfo &RCI,
|
|
|
|
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
|
|
|
|
SmallVectorImpl<const TargetRegisterClass *> &CriticalPathRCs)
|
2015-11-03 02:53:29 +01:00
|
|
|
: ScheduleDAGInstrs(MF, &MLI), AA(AA), EndIndex(0) {
|
2013-12-28 22:56:55 +01:00
|
|
|
|
2014-08-04 23:25:23 +02:00
|
|
|
const InstrItineraryData *InstrItins =
|
2014-10-14 09:17:23 +02:00
|
|
|
MF.getSubtarget().getInstrItineraryData();
|
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 06:03:26 +01:00
|
|
|
HazardRec =
|
2014-10-14 09:17:23 +02:00
|
|
|
MF.getSubtarget().getInstrInfo()->CreateTargetPostRAHazardRecognizer(
|
2014-08-04 23:25:23 +02:00
|
|
|
InstrItins, this);
|
2016-03-05 16:45:23 +01:00
|
|
|
MF.getSubtarget().getPostRAMutations(Mutations);
|
2012-04-23 23:39:35 +02:00
|
|
|
|
|
|
|
assert((AntiDepMode == TargetSubtargetInfo::ANTIDEP_NONE ||
|
|
|
|
MRI.tracksLiveness()) &&
|
|
|
|
"Live-ins must be accurate for anti-dependency breaking");
|
2020-04-13 21:26:44 +02:00
|
|
|
AntiDepBreak = ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL)
|
|
|
|
? createAggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs)
|
|
|
|
: ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_CRITICAL)
|
|
|
|
? createCriticalAntiDepBreaker(MF, RCI)
|
|
|
|
: nullptr));
|
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 06:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SchedulePostRATDList::~SchedulePostRATDList() {
|
|
|
|
delete HazardRec;
|
|
|
|
delete AntiDepBreak;
|
|
|
|
}
|
|
|
|
|
2012-03-07 06:21:52 +01:00
|
|
|
/// Initialize state associated with the next scheduling region.
|
|
|
|
void SchedulePostRATDList::enterRegion(MachineBasicBlock *bb,
|
|
|
|
MachineBasicBlock::iterator begin,
|
|
|
|
MachineBasicBlock::iterator end,
|
2013-08-23 19:48:33 +02:00
|
|
|
unsigned regioninstrs) {
|
|
|
|
ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs);
|
2012-03-07 06:21:52 +01:00
|
|
|
Sequence.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Print the schedule before exiting the region.
|
|
|
|
void SchedulePostRATDList::exitRegion() {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG({
|
|
|
|
dbgs() << "*** Final schedule ***\n";
|
|
|
|
dumpSchedule();
|
|
|
|
dbgs() << '\n';
|
|
|
|
});
|
2012-03-07 06:21:52 +01:00
|
|
|
ScheduleDAGInstrs::exitRegion();
|
|
|
|
}
|
|
|
|
|
2017-10-15 16:32:27 +02:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2012-03-07 06:21:40 +01:00
|
|
|
/// dumpSchedule - dump the scheduled Sequence.
|
2017-01-28 03:02:38 +01:00
|
|
|
LLVM_DUMP_METHOD void SchedulePostRATDList::dumpSchedule() const {
|
2012-03-07 06:21:40 +01:00
|
|
|
for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
|
|
|
|
if (SUnit *SU = Sequence[i])
|
2018-09-19 02:23:35 +02:00
|
|
|
dumpNode(*SU);
|
2012-03-07 06:21:40 +01:00
|
|
|
else
|
|
|
|
dbgs() << "**** NOOP ****\n";
|
|
|
|
}
|
|
|
|
}
|
2012-09-06 21:06:06 +02:00
|
|
|
#endif
|
2012-03-07 06:21:40 +01:00
|
|
|
|
2014-07-16 00:39:58 +02:00
|
|
|
bool PostRAScheduler::enablePostRAScheduler(
|
|
|
|
const TargetSubtargetInfo &ST,
|
|
|
|
CodeGenOpt::Level OptLevel,
|
|
|
|
TargetSubtargetInfo::AntiDepBreakMode &Mode,
|
|
|
|
TargetSubtargetInfo::RegClassVector &CriticalPathRCs) const {
|
|
|
|
Mode = ST.getAntiDepBreakMode();
|
|
|
|
ST.getCriticalPathRCs(CriticalPathRCs);
|
2016-05-19 18:40:49 +02:00
|
|
|
|
|
|
|
// Check for explicit enable/disable of post-ra scheduling.
|
|
|
|
if (EnablePostRAScheduler.getPosition() > 0)
|
|
|
|
return EnablePostRAScheduler;
|
|
|
|
|
2015-06-13 05:42:16 +02:00
|
|
|
return ST.enablePostRAScheduler() &&
|
2014-07-16 00:39:58 +02:00
|
|
|
OptLevel >= ST.getOptLevelToEnablePostRAScheduler();
|
|
|
|
}
|
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) {
|
2017-12-15 23:22:58 +01:00
|
|
|
if (skipFunction(Fn.getFunction()))
|
2014-03-31 19:43:35 +02:00
|
|
|
return false;
|
|
|
|
|
2014-08-05 04:39:49 +02:00
|
|
|
TII = Fn.getSubtarget().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 06:03:26 +01:00
|
|
|
MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
with the new pass manager, and no longer relying on analysis groups.
This builds essentially a ground-up new AA infrastructure stack for
LLVM. The core ideas are the same that are used throughout the new pass
manager: type erased polymorphism and direct composition. The design is
as follows:
- FunctionAAResults is a type-erasing alias analysis results aggregation
interface to walk a single query across a range of results from
different alias analyses. Currently this is function-specific as we
always assume that aliasing queries are *within* a function.
- AAResultBase is a CRTP utility providing stub implementations of
various parts of the alias analysis result concept, notably in several
cases in terms of other more general parts of the interface. This can
be used to implement only a narrow part of the interface rather than
the entire interface. This isn't really ideal, this logic should be
hoisted into FunctionAAResults as currently it will cause
a significant amount of redundant work, but it faithfully models the
behavior of the prior infrastructure.
- All the alias analysis passes are ported to be wrapper passes for the
legacy PM and new-style analysis passes for the new PM with a shared
result object. In some cases (most notably CFL), this is an extremely
naive approach that we should revisit when we can specialize for the
new pass manager.
- BasicAA has been restructured to reflect that it is much more
fundamentally a function analysis because it uses dominator trees and
loop info that need to be constructed for each function.
All of the references to getting alias analysis results have been
updated to use the new aggregation interface. All the preservation and
other pass management code has been updated accordingly.
The way the FunctionAAResultsWrapperPass works is to detect the
available alias analyses when run, and add them to the results object.
This means that we should be able to continue to respect when various
passes are added to the pipeline, for example adding CFL or adding TBAA
passes should just cause their results to be available and to get folded
into this. The exception to this rule is BasicAA which really needs to
be a function pass due to using dominator trees and loop info. As
a consequence, the FunctionAAResultsWrapperPass directly depends on
BasicAA and always includes it in the aggregation.
This has significant implications for preserving analyses. Generally,
most passes shouldn't bother preserving FunctionAAResultsWrapperPass
because rebuilding the results just updates the set of known AA passes.
The exception to this rule are LoopPass instances which need to preserve
all the function analyses that the loop pass manager will end up
needing. This means preserving both BasicAAWrapperPass and the
aggregating FunctionAAResultsWrapperPass.
Now, when preserving an alias analysis, you do so by directly preserving
that analysis. This is only necessary for non-immutable-pass-provided
alias analyses though, and there are only three of interest: BasicAA,
GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
preserved when needed because it (like DominatorTree and LoopInfo) is
marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
set everywhere we previously were preserving all of AliasAnalysis, and
I've added SCEVAA in the intersection of that with where we preserve
SCEV itself.
One significant challenge to all of this is that the CGSCC passes were
actually using the alias analysis implementations by taking advantage of
a pretty amazing set of loop holes in the old pass manager's analysis
management code which allowed analysis groups to slide through in many
cases. Moving away from analysis groups makes this problem much more
obvious. To fix it, I've leveraged the flexibility the design of the new
PM components provides to just directly construct the relevant alias
analyses for the relevant functions in the IPO passes that need them.
This is a bit hacky, but should go away with the new pass manager, and
is already in many ways cleaner than the prior state.
Another significant challenge is that various facilities of the old
alias analysis infrastructure just don't fit any more. The most
significant of these is the alias analysis 'counter' pass. That pass
relied on the ability to snoop on AA queries at different points in the
analysis group chain. Instead, I'm planning to build printing
functionality directly into the aggregation layer. I've not included
that in this patch merely to keep it smaller.
Note that all of this needs a nearly complete rewrite of the AA
documentation. I'm planning to do that, but I'd like to make sure the
new design settles, and to flesh out a bit more of what it looks like in
the new pass manager first.
Differential Revision: http://reviews.llvm.org/D12080
llvm-svn: 247167
2015-09-09 19:55:00 +02:00
|
|
|
AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
2012-02-08 22:22:53 +01:00
|
|
|
TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>();
|
|
|
|
|
2011-06-16 23:56:21 +02:00
|
|
|
RegClassInfo.runOnMachineFunction(Fn);
|
2009-10-10 02:15:38 +02:00
|
|
|
|
2011-12-14 03:11:42 +01:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode AntiDepMode =
|
|
|
|
TargetSubtargetInfo::ANTIDEP_NONE;
|
2012-02-22 06:59:10 +01:00
|
|
|
SmallVector<const TargetRegisterClass*, 4> CriticalPathRCs;
|
2016-05-19 18:40:49 +02:00
|
|
|
|
|
|
|
// Check that post-RA scheduling is enabled for this target.
|
|
|
|
// This may upgrade the AntiDepMode.
|
|
|
|
if (!enablePostRAScheduler(Fn.getSubtarget(), PassConfig->getOptLevel(),
|
|
|
|
AntiDepMode, CriticalPathRCs))
|
|
|
|
return false;
|
2009-09-30 02:10:16 +02:00
|
|
|
|
2009-10-23 01:19:17 +02:00
|
|
|
// Check for antidep breaking override...
|
|
|
|
if (EnableAntiDepBreaking.getPosition() > 0) {
|
2011-07-01 23:01:15 +02:00
|
|
|
AntiDepMode = (EnableAntiDepBreaking == "all")
|
|
|
|
? TargetSubtargetInfo::ANTIDEP_ALL
|
|
|
|
: ((EnableAntiDepBreaking == "critical")
|
|
|
|
? TargetSubtargetInfo::ANTIDEP_CRITICAL
|
|
|
|
: TargetSubtargetInfo::ANTIDEP_NONE);
|
2009-10-23 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "PostRAScheduler\n");
|
2007-07-13 19:13:54 +02:00
|
|
|
|
2014-08-20 22:57:26 +02:00
|
|
|
SchedulePostRATDList Scheduler(Fn, MLI, 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 06:03:26 +01:00
|
|
|
CriticalPathRCs);
|
2009-01-15 20:20:50 +01:00
|
|
|
|
2007-07-13 19:13:54 +02:00
|
|
|
// Loop over all of the basic blocks
|
2015-10-09 23:05:00 +02:00
|
|
|
for (auto &MBB : Fn) {
|
2009-09-01 20:34:03 +02: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;
|
2017-12-04 18:18:51 +01:00
|
|
|
dbgs() << "*** DEBUG scheduling " << Fn.getName() << ":"
|
|
|
|
<< printMBBReference(MBB) << " ***\n";
|
2009-09-01 20:34:03 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 00:27:53 +01:00
|
|
|
// Initialize register live-range state for scheduling in this block.
|
2015-10-09 23:05:00 +02:00
|
|
|
Scheduler.startBlock(&MBB);
|
2009-02-11 00:27:53 +01:00
|
|
|
|
2009-01-16 23:10:20 +01:00
|
|
|
// Schedule each sequence of instructions not interrupted by a label
|
|
|
|
// or anything else that effectively needs to shut down scheduling.
|
2015-10-09 23:05:00 +02:00
|
|
|
MachineBasicBlock::iterator Current = MBB.end();
|
|
|
|
unsigned Count = MBB.size(), CurrentCount = Count;
|
|
|
|
for (MachineBasicBlock::iterator I = Current; I != MBB.begin();) {
|
2016-07-01 03:18:53 +02:00
|
|
|
MachineInstr &MI = *std::prev(I);
|
2013-08-23 19:48:33 +02:00
|
|
|
--Count;
|
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-23 18:54:21 +01: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.
|
2016-07-01 03:18:53 +02:00
|
|
|
if (MI.isCall() || TII->isSchedulingBoundary(MI, &MBB, Fn)) {
|
2015-10-09 23:05:00 +02:00
|
|
|
Scheduler.enterRegion(&MBB, I, Current, CurrentCount - Count);
|
2013-08-23 19:48:33 +02:00
|
|
|
Scheduler.setEndIndex(CurrentCount);
|
2012-03-08 00:00:49 +01:00
|
|
|
Scheduler.schedule();
|
2012-03-07 06:21:52 +01:00
|
|
|
Scheduler.exitRegion();
|
2010-05-01 02:01:06 +02:00
|
|
|
Scheduler.EmitSchedule();
|
2016-07-01 03:18:53 +02:00
|
|
|
Current = &MI;
|
2013-08-23 19:48:33 +02:00
|
|
|
CurrentCount = Count;
|
2016-07-01 03:18:53 +02:00
|
|
|
Scheduler.Observe(MI, CurrentCount);
|
2009-01-16 23:10:20 +01:00
|
|
|
}
|
2009-02-11 00:27:53 +01:00
|
|
|
I = MI;
|
2016-07-01 03:18:53 +02:00
|
|
|
if (MI.isBundle())
|
|
|
|
Count -= MI.getBundleSize();
|
2009-02-11 05:27:20 +01:00
|
|
|
}
|
|
|
|
assert(Count == 0 && "Instruction count mismatch!");
|
2015-10-09 23:05:00 +02:00
|
|
|
assert((MBB.begin() == Current || CurrentCount != 0) &&
|
2009-03-10 19:10:43 +01:00
|
|
|
"Instruction count mismatch!");
|
2015-10-09 23:05:00 +02:00
|
|
|
Scheduler.enterRegion(&MBB, MBB.begin(), Current, CurrentCount);
|
2013-08-23 19:48:33 +02:00
|
|
|
Scheduler.setEndIndex(CurrentCount);
|
2012-03-08 00:00:49 +01:00
|
|
|
Scheduler.schedule();
|
2012-03-07 06:21:52 +01:00
|
|
|
Scheduler.exitRegion();
|
2010-05-01 02:01:06 +02:00
|
|
|
Scheduler.EmitSchedule();
|
2009-02-11 00:27:53 +01:00
|
|
|
|
|
|
|
// Clean up register live-range state.
|
2012-03-08 00:00:49 +01:00
|
|
|
Scheduler.finishBlock();
|
2009-08-25 19:03:05 +02:00
|
|
|
|
2009-09-04 00:15:25 +02:00
|
|
|
// Update register kills
|
2017-05-27 04:50:50 +02:00
|
|
|
Scheduler.fixupKills(MBB);
|
2008-11-20 00:18:57 +01:00
|
|
|
}
|
2007-07-13 19:13:54 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2009-02-11 00:27:53 +01:00
|
|
|
/// StartBlock - Initialize register live-range state for scheduling in
|
|
|
|
/// this block.
|
|
|
|
///
|
2012-03-08 00:00:49 +01:00
|
|
|
void SchedulePostRATDList::startBlock(MachineBasicBlock *BB) {
|
2009-02-11 00:27:53 +01:00
|
|
|
// Call the superclass.
|
2012-03-08 00:00:49 +01:00
|
|
|
ScheduleDAGInstrs::startBlock(BB);
|
2009-02-11 00:27:53 +01:00
|
|
|
|
2009-10-26 17:59:04 +01:00
|
|
|
// Reset the hazard recognizer and anti-dep breaker.
|
2009-08-10 17:55:25 +02:00
|
|
|
HazardRec->Reset();
|
2014-04-14 02:51:57 +02:00
|
|
|
if (AntiDepBreak)
|
2009-10-26 17:59:04 +01:00
|
|
|
AntiDepBreak->StartBlock(BB);
|
2009-02-11 00:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Schedule - Schedule the instruction range using list scheduling.
|
|
|
|
///
|
2012-03-08 00:00:49 +01:00
|
|
|
void SchedulePostRATDList::schedule() {
|
2008-12-23 19:36:58 +01:00
|
|
|
// Build the scheduling graph.
|
2012-03-08 00:00:49 +01:00
|
|
|
buildSchedGraph(AA);
|
2008-11-20 00:18:57 +01:00
|
|
|
|
2014-04-14 02:51:57 +02:00
|
|
|
if (AntiDepBreak) {
|
2010-05-14 23:19:48 +02:00
|
|
|
unsigned Broken =
|
2012-03-09 05:29:02 +01:00
|
|
|
AntiDepBreak->BreakAntiDependencies(SUnits, RegionBegin, RegionEnd,
|
|
|
|
EndIndex, DbgValues);
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2009-11-20 20:32:48 +01:00
|
|
|
if (Broken != 0) {
|
2008-11-25 01:52:40 +01: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 06:21:52 +01:00
|
|
|
ScheduleDAG::clearDAG();
|
2012-03-08 00:00:49 +01:00
|
|
|
buildSchedGraph(AA);
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2009-10-26 17:59:04 +01:00
|
|
|
NumFixedAnti += Broken;
|
2008-11-25 01:52:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 17:54:20 +01:00
|
|
|
postprocessDAG();
|
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "********** List Scheduling **********\n");
|
2018-09-19 02:23:35 +02:00
|
|
|
LLVM_DEBUG(dump());
|
2009-08-10 17:55:25 +02:00
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
AvailableQueue.initNodes(SUnits);
|
2009-11-20 20:32:48 +01:00
|
|
|
ListScheduleTopDown();
|
2008-11-20 00:18:57 +01:00
|
|
|
AvailableQueue.releaseState();
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:27:53 +01:00
|
|
|
/// Observe - Update liveness information to account for the current
|
|
|
|
/// instruction, which will not be scheduled.
|
|
|
|
///
|
2016-02-27 20:33:37 +01:00
|
|
|
void SchedulePostRATDList::Observe(MachineInstr &MI, unsigned Count) {
|
2014-04-14 02:51:57 +02:00
|
|
|
if (AntiDepBreak)
|
2012-03-08 00:00:52 +01:00
|
|
|
AntiDepBreak->Observe(MI, Count, EndIndex);
|
2009-02-11 00:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// FinishBlock - Clean up register live-range state.
|
|
|
|
///
|
2012-03-08 00:00:49 +01:00
|
|
|
void SchedulePostRATDList::finishBlock() {
|
2014-04-14 02:51:57 +02:00
|
|
|
if (AntiDepBreak)
|
2009-10-26 17:59:04 +01:00
|
|
|
AntiDepBreak->FinishBlock();
|
2009-02-11 00:27:53 +01:00
|
|
|
|
|
|
|
// Call the superclass.
|
2012-03-08 00:00:49 +01:00
|
|
|
ScheduleDAGInstrs::finishBlock();
|
2009-02-11 00:27:53 +01:00
|
|
|
}
|
|
|
|
|
2016-03-05 16:45:23 +01:00
|
|
|
/// Apply each ScheduleDAGMutation step in order.
|
|
|
|
void SchedulePostRATDList::postprocessDAG() {
|
|
|
|
for (auto &M : Mutations)
|
|
|
|
M->apply(this);
|
|
|
|
}
|
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-Down Scheduling
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
|
2012-11-12 20:28:57 +01:00
|
|
|
/// the PendingQueue if the count reaches zero.
|
2009-11-20 20:32:48 +01:00
|
|
|
void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
|
2008-12-09 23:54:47 +01:00
|
|
|
SUnit *SuccSU = SuccEdge->getSUnit();
|
2009-09-30 22:15:38 +02:00
|
|
|
|
2012-11-13 03:35:06 +01:00
|
|
|
if (SuccEdge->isWeak()) {
|
2012-11-12 20:28:57 +01:00
|
|
|
--SuccSU->WeakPredsLeft;
|
|
|
|
return;
|
|
|
|
}
|
2008-11-20 00:18:57 +01:00
|
|
|
#ifndef NDEBUG
|
2009-09-30 22:15:38 +02:00
|
|
|
if (SuccSU->NumPredsLeft == 0) {
|
2010-01-05 02:26:01 +01:00
|
|
|
dbgs() << "*** Scheduling failed! ***\n";
|
2018-09-19 02:23:35 +02:00
|
|
|
dumpNode(*SuccSU);
|
2010-01-05 02:26:01 +01:00
|
|
|
dbgs() << " has been released too many times!\n";
|
2014-04-14 02:51:57 +02:00
|
|
|
llvm_unreachable(nullptr);
|
2008-11-20 00:18:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
2009-09-30 22:15:38 +02:00
|
|
|
--SuccSU->NumPredsLeft;
|
|
|
|
|
2011-05-06 20:14:32 +02:00
|
|
|
// Standard scheduler algorithms will recompute the depth of the successor
|
2011-05-06 19:09:08 +02: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-14 23:19:48 +02:00
|
|
|
|
2009-02-11 00:27:53 +01: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 00:18:57 +01:00
|
|
|
PendingQueue.push_back(SuccSU);
|
2009-02-11 00:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ReleaseSuccessors - Call ReleaseSucc on each of SU's successors.
|
2009-11-20 20:32:48 +01:00
|
|
|
void SchedulePostRATDList::ReleaseSuccessors(SUnit *SU) {
|
2009-02-11 00:27:53 +01:00
|
|
|
for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
|
2009-11-03 21:57:50 +01:00
|
|
|
I != E; ++I) {
|
2009-11-20 20:32:48 +01:00
|
|
|
ReleaseSucc(SU, &*I);
|
2009-11-03 21:57:50 +01:00
|
|
|
}
|
2008-11-20 00:18:57 +01: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-20 20:32:48 +01:00
|
|
|
void SchedulePostRATDList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: ");
|
2018-09-19 02:23:35 +02:00
|
|
|
LLVM_DEBUG(dumpNode(*SU));
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
Sequence.push_back(SU);
|
2010-05-14 23:19:48 +02:00
|
|
|
assert(CurCycle >= SU->getDepth() &&
|
2009-11-03 21:57:50 +01:00
|
|
|
"Node scheduled above its depth!");
|
2009-11-20 20:32:48 +01:00
|
|
|
SU->setDepthToAtLeast(CurCycle);
|
2008-11-20 00:18:57 +01:00
|
|
|
|
2009-11-20 20:32:48 +01:00
|
|
|
ReleaseSuccessors(SU);
|
2008-11-20 00:18:57 +01:00
|
|
|
SU->isScheduled = true;
|
2012-03-08 00:00:49 +01:00
|
|
|
AvailableQueue.scheduledNode(SU);
|
2008-11-20 00:18:57 +01:00
|
|
|
}
|
|
|
|
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
/// emitNoop - Add a noop to the current instruction sequence.
|
|
|
|
void SchedulePostRATDList::emitNoop(unsigned CurCycle) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "*** Emitting noop in cycle " << CurCycle << '\n');
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
HazardRec->EmitNoop();
|
2014-04-14 02:51:57 +02:00
|
|
|
Sequence.push_back(nullptr); // NULL here means noop
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
++NumNoops;
|
|
|
|
}
|
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
/// ListScheduleTopDown - The main loop of list scheduling for top-down
|
|
|
|
/// schedulers.
|
2009-11-20 20:32:48 +01:00
|
|
|
void SchedulePostRATDList::ListScheduleTopDown() {
|
2008-11-20 00:18:57 +01:00
|
|
|
unsigned CurCycle = 0;
|
2010-05-14 23:19:48 +02:00
|
|
|
|
2009-11-03 21:57:50 +01: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();
|
|
|
|
|
2020-09-21 13:18:39 +02:00
|
|
|
// Release any successors of the special Entry node.
|
|
|
|
ReleaseSuccessors(&EntrySU);
|
|
|
|
|
2009-11-20 20:32:48 +01:00
|
|
|
// Add all leaves to Available queue.
|
2008-11-20 00:18:57 +01:00
|
|
|
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
|
|
|
|
// It is available if it has no predecessors.
|
2012-11-12 20:28:57 +01:00
|
|
|
if (!SUnits[i].NumPredsLeft && !SUnits[i].isAvailable) {
|
2008-11-20 00:18:57 +01:00
|
|
|
AvailableQueue.push(&SUnits[i]);
|
|
|
|
SUnits[i].isAvailable = true;
|
|
|
|
}
|
|
|
|
}
|
2009-02-11 00:27:53 +01:00
|
|
|
|
2009-08-12 23:47:46 +02: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 14:10:17 +02:00
|
|
|
bool CycleHasInsts = false;
|
2009-08-12 23:47:46 +02:00
|
|
|
|
2008-11-20 00:18:57 +01: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 02:33:36 +01:00
|
|
|
std::vector<SUnit*> NotReady;
|
2008-11-20 00:18:57 +01: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 04:25:46 +01:00
|
|
|
unsigned MinDepth = ~0u;
|
2008-11-20 00:18:57 +01:00
|
|
|
for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
|
2009-11-20 20:32:48 +01:00
|
|
|
if (PendingQueue[i]->getDepth() <= CurCycle) {
|
2008-11-20 00:18:57 +01:00
|
|
|
AvailableQueue.push(PendingQueue[i]);
|
|
|
|
PendingQueue[i]->isAvailable = true;
|
|
|
|
PendingQueue[i] = PendingQueue.back();
|
|
|
|
PendingQueue.pop_back();
|
|
|
|
--i; --e;
|
2009-11-20 20:32:48 +01:00
|
|
|
} else if (PendingQueue[i]->getDepth() < MinDepth)
|
|
|
|
MinDepth = PendingQueue[i]->getDepth();
|
2008-11-20 00:18:57 +01:00
|
|
|
}
|
2009-08-11 19:35:23 +02:00
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "\n*** Examining Available\n";
|
|
|
|
AvailableQueue.dump(this));
|
2009-08-11 19:35:23 +02:00
|
|
|
|
2014-04-14 02:51:57 +02:00
|
|
|
SUnit *FoundSUnit = nullptr, *NotPreferredSUnit = nullptr;
|
2009-01-16 02:33:36 +01:00
|
|
|
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 06:03:26 +01:00
|
|
|
HazardRec->getHazardType(CurSUnit, 0/*no stalls*/);
|
2009-01-16 02:33:36 +01:00
|
|
|
if (HT == ScheduleHazardRecognizer::NoHazard) {
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
if (HazardRec->ShouldPreferAnother(CurSUnit)) {
|
|
|
|
if (!NotPreferredSUnit) {
|
2014-10-29 16:23:11 +01:00
|
|
|
// If this is the first non-preferred node for this cycle, then
|
|
|
|
// record it and continue searching for a preferred node. If this
|
|
|
|
// is not the first non-preferred node, then treat it as though
|
|
|
|
// there had been a hazard.
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
NotPreferredSUnit = CurSUnit;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FoundSUnit = CurSUnit;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-16 02:33:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember if this is a noop hazard.
|
|
|
|
HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard;
|
|
|
|
|
|
|
|
NotReady.push_back(CurSUnit);
|
|
|
|
}
|
|
|
|
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
// If we have a non-preferred node, push it back onto the available list.
|
|
|
|
// If we did not find a preferred node, then schedule this first
|
|
|
|
// non-preferred node.
|
|
|
|
if (NotPreferredSUnit) {
|
|
|
|
if (!FoundSUnit) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs() << "*** Will schedule a non-preferred instruction...\n");
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
FoundSUnit = NotPreferredSUnit;
|
|
|
|
} else {
|
|
|
|
AvailableQueue.push(NotPreferredSUnit);
|
|
|
|
}
|
|
|
|
|
2014-04-14 02:51:57 +02:00
|
|
|
NotPreferredSUnit = nullptr;
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
}
|
|
|
|
|
2009-01-16 02:33:36 +01:00
|
|
|
// Add the nodes that aren't ready back onto the available list.
|
|
|
|
if (!NotReady.empty()) {
|
|
|
|
AvailableQueue.push_all(NotReady);
|
|
|
|
NotReady.clear();
|
|
|
|
}
|
|
|
|
|
2009-11-03 21:57:50 +01:00
|
|
|
// If we found a node to schedule...
|
2008-11-20 00:18:57 +01:00
|
|
|
if (FoundSUnit) {
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
// If we need to emit noops prior to this instruction, then do so.
|
|
|
|
unsigned NumPreNoops = HazardRec->PreEmitNoops(FoundSUnit);
|
|
|
|
for (unsigned i = 0; i != NumPreNoops; ++i)
|
|
|
|
emitNoop(CurCycle);
|
|
|
|
|
2009-11-03 21:57:50 +01:00
|
|
|
// ... schedule the node...
|
2009-11-20 20:32:48 +01:00
|
|
|
ScheduleNodeTopDown(FoundSUnit, CurCycle);
|
2009-01-16 02:33:36 +01:00
|
|
|
HazardRec->EmitInstruction(FoundSUnit);
|
2009-09-06 14:10:17 +02:00
|
|
|
CycleHasInsts = true;
|
2011-06-01 05:27:56 +02:00
|
|
|
if (HazardRec->atIssueLimit()) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "*** Max instructions per cycle " << CurCycle
|
|
|
|
<< '\n');
|
2011-06-01 05:27:56 +02:00
|
|
|
HazardRec->AdvanceCycle();
|
|
|
|
++CurCycle;
|
|
|
|
CycleHasInsts = false;
|
|
|
|
}
|
2009-01-16 02:33:36 +01:00
|
|
|
} else {
|
2009-09-06 14:10:17 +02:00
|
|
|
if (CycleHasInsts) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "*** Finished cycle " << CurCycle << '\n');
|
2009-08-12 23:47:46 +02:00
|
|
|
HazardRec->AdvanceCycle();
|
|
|
|
} else if (!HasNoopHazards) {
|
|
|
|
// Otherwise, we have a pipeline stall, but no other problem,
|
|
|
|
// just advance the current cycle and try again.
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "*** Stall in cycle " << CurCycle << '\n');
|
2009-08-12 23:47:46 +02:00
|
|
|
HazardRec->AdvanceCycle();
|
2009-11-20 20:32:48 +01:00
|
|
|
++NumStalls;
|
2009-08-12 23:47:46 +02: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.
|
Add two additional hazard recognizer functions
This adds two additional functions to the hazard recognizer interface. These
are optional (in the sense that the default implementations preserve the
current behavior), and used by the post-RA scheduler. Upcoming commits will use
this functionality in order to improve dispatch-group formation on the POWER7
and related cores. Dispatch groups are an odd construct: sometimes we need to
insert nops to force a new one to start (for performance reasons), and some
instructions need to appear in certain positions within a group, but the groups
are not fundamentally cycle based (they can contain instructions with data
dependencies with non-trivial latencies).
Motivation:
unsigned PreEmitNoops(SUnit *) - Used to force the post-RA scheduler to insert
nops to force a new dispatch group to begin. We already have a NoopHazard, and
this is also still needed. However, NoopHazard only causes a nop to be inserted
if there are no other available instructions, and so is not always sufficient.
The number of nops to insert depends on state that only the hazard recognizer
has, so a general callback is necessary.
bool ShouldPreferAnother(SUnit *) - Used to avoid scheduling instructions that
would start a new dispatch group when others are available that could be part
of the current dispatch group. In this case, we don't want to issue nops,
because the non-preferred instruction will implicitly start a new dispatch
group regardless.
Although the motivation for these functions is driven by the PowerPC backend,
they are completely general.
llvm-svn: 197084
2013-12-11 23:33:43 +01:00
|
|
|
emitNoop(CurCycle);
|
2009-08-12 23:47:46 +02:00
|
|
|
}
|
|
|
|
|
2009-01-16 02:33:36 +01:00
|
|
|
++CurCycle;
|
2009-09-06 14:10:17 +02:00
|
|
|
CycleHasInsts = false;
|
2008-11-20 00:18:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2012-03-07 06:21:36 +01: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 00:18:57 +01:00
|
|
|
}
|
2012-03-07 06:21:44 +01:00
|
|
|
|
|
|
|
// EmitSchedule - Emit the machine code in scheduled order.
|
|
|
|
void SchedulePostRATDList::EmitSchedule() {
|
2012-03-09 05:29:02 +01:00
|
|
|
RegionBegin = RegionEnd;
|
2012-03-07 06:21:44 +01:00
|
|
|
|
|
|
|
// If first instruction was a DBG_VALUE then put it back.
|
|
|
|
if (FirstDbgValue)
|
2012-03-09 05:29:02 +01:00
|
|
|
BB->splice(RegionEnd, BB, FirstDbgValue);
|
2012-03-07 06:21:44 +01: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 05:29:02 +01:00
|
|
|
BB->splice(RegionEnd, BB, SU->getInstr());
|
2012-03-07 06:21:44 +01:00
|
|
|
else
|
|
|
|
// Null SUnit* is a noop.
|
2012-03-09 05:29:02 +01:00
|
|
|
TII->insertNoop(*BB, RegionEnd);
|
2012-03-07 06:21:44 +01:00
|
|
|
|
|
|
|
// Update the Begin iterator, as the first instruction in the block
|
|
|
|
// may have been scheduled later.
|
|
|
|
if (i == 0)
|
2014-03-02 13:27:27 +01:00
|
|
|
RegionBegin = std::prev(RegionEnd);
|
2012-03-07 06:21:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reinsert any remaining debug_values.
|
|
|
|
for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator
|
|
|
|
DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) {
|
2014-03-02 13:27:27 +01:00
|
|
|
std::pair<MachineInstr *, MachineInstr *> P = *std::prev(DI);
|
2012-03-07 06:21:44 +01:00
|
|
|
MachineInstr *DbgValue = P.first;
|
|
|
|
MachineBasicBlock::iterator OrigPrivMI = P.second;
|
|
|
|
BB->splice(++OrigPrivMI, BB, DbgValue);
|
|
|
|
}
|
|
|
|
DbgValues.clear();
|
2014-04-14 02:51:57 +02:00
|
|
|
FirstDbgValue = nullptr;
|
2012-03-07 06:21:44 +01:00
|
|
|
}
|