2017-02-22 23:32:51 +01:00
|
|
|
//===- llvm/CodeGen/ScheduleDAG.h - Common Base Class -----------*- C++ -*-===//
|
2006-01-21 03:32:06 +01: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
|
2006-01-21 03:32:06 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2017-02-21 02:27:33 +01:00
|
|
|
/// \file Implements the ScheduleDAG class, which is used as the common base
|
|
|
|
/// class for instruction schedulers. This encapsulates the scheduling DAG,
|
|
|
|
/// which is shared between SelectionDAG and MachineInstr scheduling.
|
2006-01-21 03:32:06 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_SCHEDULEDAG_H
|
|
|
|
#define LLVM_CODEGEN_SCHEDULEDAG_H
|
|
|
|
|
2008-11-25 01:52:40 +01:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2007-08-28 22:32:58 +02:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2008-12-09 23:54:47 +01:00
|
|
|
#include "llvm/ADT/PointerIntPair.h"
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/ADT/iterator.h"
|
2013-02-20 01:26:25 +01:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2017-02-22 23:32:51 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <iterator>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2006-05-12 01:55:42 +02:00
|
|
|
|
2006-01-21 03:32:06 +01:00
|
|
|
namespace llvm {
|
2017-02-22 23:32:51 +01:00
|
|
|
|
|
|
|
template<class Graph> class GraphWriter;
|
2018-11-06 00:49:14 +01:00
|
|
|
class LLVMTargetMachine;
|
2017-02-22 23:32:51 +01:00
|
|
|
class MachineFunction;
|
|
|
|
class MachineRegisterInfo;
|
|
|
|
class MCInstrDesc;
|
|
|
|
struct MCSchedClassDesc;
|
|
|
|
class SDNode;
|
|
|
|
class SUnit;
|
2018-11-06 00:49:14 +01:00
|
|
|
class ScheduleDAG;
|
2017-02-22 23:32:51 +01:00
|
|
|
class TargetInstrInfo;
|
|
|
|
class TargetRegisterClass;
|
|
|
|
class TargetRegisterInfo;
|
2007-09-19 03:38:40 +02:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Scheduling dependency. This represents one direction of an edge in the
|
|
|
|
/// scheduling DAG.
|
2008-12-09 23:54:47 +01:00
|
|
|
class SDep {
|
|
|
|
public:
|
2017-02-21 02:27:33 +01:00
|
|
|
/// These are the different kinds of scheduling dependencies.
|
2008-12-09 23:54:47 +01:00
|
|
|
enum Kind {
|
|
|
|
Data, ///< Regular data dependence (aka true-dependence).
|
2017-05-29 13:46:44 +02:00
|
|
|
Anti, ///< A register anti-dependence (aka WAR).
|
2008-12-09 23:54:47 +01:00
|
|
|
Output, ///< A register output-dependence (aka WAW).
|
|
|
|
Order ///< Any other ordering dependency.
|
|
|
|
};
|
|
|
|
|
2013-03-01 01:19:12 +01:00
|
|
|
// Strong dependencies must be respected by the scheduler. Artificial
|
|
|
|
// dependencies may be removed only if they are redundant with another
|
2017-05-29 13:46:44 +02:00
|
|
|
// strong dependence.
|
2013-03-01 01:19:12 +01:00
|
|
|
//
|
|
|
|
// Weak dependencies may be violated by the scheduling strategy, but only if
|
|
|
|
// the strategy can prove it is correct to do so.
|
|
|
|
//
|
|
|
|
// Strong OrderKinds must occur before "Weak".
|
|
|
|
// Weak OrderKinds must occur after "Weak".
|
2012-11-06 04:13:46 +01:00
|
|
|
enum OrderKind {
|
|
|
|
Barrier, ///< An unknown scheduling barrier.
|
|
|
|
MayAliasMem, ///< Nonvolatile load/Store instructions that may alias.
|
|
|
|
MustAliasMem, ///< Nonvolatile load/Store instructions that must alias.
|
2013-03-01 01:19:12 +01:00
|
|
|
Artificial, ///< Arbitrary strong DAG edge (no real dependence).
|
|
|
|
Weak, ///< Arbitrary weak DAG edge.
|
2012-11-12 20:28:57 +01:00
|
|
|
Cluster ///< Weak DAG edge linking a chain of clustered instrs.
|
2012-11-06 04:13:46 +01:00
|
|
|
};
|
|
|
|
|
2008-12-09 23:54:47 +01:00
|
|
|
private:
|
2018-05-01 17:54:18 +02:00
|
|
|
/// A pointer to the depending/depended-on SUnit, and an enum
|
2008-12-09 23:54:47 +01:00
|
|
|
/// indicating the kind of the dependency.
|
|
|
|
PointerIntPair<SUnit *, 2, Kind> Dep;
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// A union discriminated by the dependence kind.
|
2008-12-09 23:54:47 +01:00
|
|
|
union {
|
2017-02-21 02:27:33 +01:00
|
|
|
/// For Data, Anti, and Output dependencies, the associated register. For
|
|
|
|
/// Data dependencies that don't currently have a register/ assigned, this
|
|
|
|
/// is set to zero.
|
2008-12-09 23:54:47 +01:00
|
|
|
unsigned Reg;
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Additional information about Order dependencies.
|
2012-11-06 04:13:46 +01:00
|
|
|
unsigned OrdKind; // enum OrderKind
|
2008-12-09 23:54:47 +01:00
|
|
|
} Contents;
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// The time associated with this edge. Often this is just the value of the
|
|
|
|
/// Latency field of the predecessor, however advanced models may provide
|
|
|
|
/// additional information about specific edges.
|
2008-12-09 23:54:47 +01:00
|
|
|
unsigned Latency;
|
|
|
|
|
|
|
|
public:
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Constructs a null SDep. This is only for use by container classes which
|
|
|
|
/// require default constructors. SUnits may not/ have null SDep edges.
|
2014-04-14 02:51:57 +02:00
|
|
|
SDep() : Dep(nullptr, Data) {}
|
2008-12-09 23:54:47 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Constructs an SDep with the specified values.
|
2012-11-06 04:13:46 +01:00
|
|
|
SDep(SUnit *S, Kind kind, unsigned Reg)
|
|
|
|
: Dep(S, kind), Contents() {
|
2008-12-09 23:54:47 +01:00
|
|
|
switch (kind) {
|
2012-11-06 04:13:46 +01:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Reg given for non-register dependence!");
|
2008-12-09 23:54:47 +01:00
|
|
|
case Anti:
|
|
|
|
case Output:
|
|
|
|
assert(Reg != 0 &&
|
|
|
|
"SDep::Anti and SDep::Output must use a non-zero Reg!");
|
|
|
|
Contents.Reg = Reg;
|
2012-11-06 04:13:46 +01:00
|
|
|
Latency = 0;
|
2008-12-09 23:54:47 +01:00
|
|
|
break;
|
2012-11-06 04:13:46 +01:00
|
|
|
case Data:
|
|
|
|
Contents.Reg = Reg;
|
|
|
|
Latency = 1;
|
2008-12-09 23:54:47 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-11-06 04:13:46 +01:00
|
|
|
}
|
2017-02-22 23:32:51 +01:00
|
|
|
|
2012-11-06 04:13:46 +01:00
|
|
|
SDep(SUnit *S, OrderKind kind)
|
2013-06-15 06:49:57 +02:00
|
|
|
: Dep(S, Order), Contents(), Latency(0) {
|
2012-11-06 04:13:46 +01:00
|
|
|
Contents.OrdKind = kind;
|
2008-12-09 23:54:47 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns true if the specified SDep is equivalent except for latency.
|
2015-12-29 10:24:42 +01:00
|
|
|
bool overlaps(const SDep &Other) const;
|
2008-12-09 23:54:47 +01:00
|
|
|
|
2012-06-13 04:39:00 +02:00
|
|
|
bool operator==(const SDep &Other) const {
|
2013-06-15 06:49:57 +02:00
|
|
|
return overlaps(Other) && Latency == Other.Latency;
|
2012-06-13 04:39:00 +02:00
|
|
|
}
|
|
|
|
|
2008-12-09 23:54:47 +01:00
|
|
|
bool operator!=(const SDep &Other) const {
|
|
|
|
return !operator==(Other);
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Returns the latency value for this edge, which roughly means the
|
2017-02-21 02:27:33 +01:00
|
|
|
/// minimum number of cycles that must elapse between the predecessor and
|
|
|
|
/// the successor, given that they have this edge between them.
|
2008-12-09 23:54:47 +01:00
|
|
|
unsigned getLatency() const {
|
|
|
|
return Latency;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Sets the latency for this edge.
|
2009-08-13 18:05:04 +02:00
|
|
|
void setLatency(unsigned Lat) {
|
|
|
|
Latency = Lat;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
//// Returns the SUnit to which this edge points.
|
2015-12-29 10:24:42 +01:00
|
|
|
SUnit *getSUnit() const;
|
2008-12-09 23:54:47 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
//// Assigns the SUnit to which this edge points.
|
2015-12-29 10:24:42 +01:00
|
|
|
void setSUnit(SUnit *SU);
|
2008-12-09 23:54:47 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns an enum value representing the kind of the dependence.
|
2015-12-29 10:24:42 +01:00
|
|
|
Kind getKind() const;
|
2008-12-09 23:54:47 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Shorthand for getKind() != SDep::Data.
|
2008-12-09 23:54:47 +01:00
|
|
|
bool isCtrl() const {
|
|
|
|
return getKind() != Data;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Tests if this is an Order dependence between two memory accesses
|
2017-02-21 02:27:33 +01:00
|
|
|
/// where both sides of the dependence access memory in non-volatile and
|
|
|
|
/// fully modeled ways.
|
2008-12-22 22:06:56 +01:00
|
|
|
bool isNormalMemory() const {
|
2012-11-06 04:13:46 +01:00
|
|
|
return getKind() == Order && (Contents.OrdKind == MayAliasMem
|
|
|
|
|| Contents.OrdKind == MustAliasMem);
|
2008-12-22 22:06:56 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if this is an Order dependence that is marked as a barrier.
|
2013-12-12 01:19:07 +01:00
|
|
|
bool isBarrier() const {
|
|
|
|
return getKind() == Order && Contents.OrdKind == Barrier;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if this is could be any kind of memory dependence.
|
2015-01-07 14:38:29 +01:00
|
|
|
bool isNormalMemoryOrBarrier() const {
|
|
|
|
return (isNormalMemory() || isBarrier());
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Tests if this is an Order dependence that is marked as
|
2017-02-21 02:27:33 +01:00
|
|
|
/// "must alias", meaning that the SUnits at either end of the edge have a
|
|
|
|
/// memory dependence on a known memory location.
|
2008-12-09 23:54:47 +01:00
|
|
|
bool isMustAlias() const {
|
2012-11-06 04:13:46 +01:00
|
|
|
return getKind() == Order && Contents.OrdKind == MustAliasMem;
|
2008-12-09 23:54:47 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if this a weak dependence. Weak dependencies are considered DAG
|
|
|
|
/// edges for height computation and other heuristics, but do not force
|
|
|
|
/// ordering. Breaking a weak edge may require the scheduler to compensate,
|
|
|
|
/// for example by inserting a copy.
|
2012-11-12 20:28:57 +01:00
|
|
|
bool isWeak() const {
|
2013-03-01 01:19:12 +01:00
|
|
|
return getKind() == Order && Contents.OrdKind >= Weak;
|
2012-11-12 20:28:57 +01:00
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Tests if this is an Order dependence that is marked as
|
2017-02-21 02:27:33 +01:00
|
|
|
/// "artificial", meaning it isn't necessary for correctness.
|
2008-12-16 01:48:53 +01:00
|
|
|
bool isArtificial() const {
|
2012-11-06 04:13:46 +01:00
|
|
|
return getKind() == Order && Contents.OrdKind == Artificial;
|
2008-12-16 01:48:53 +01:00
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Tests if this is an Order dependence that is marked as "cluster",
|
2017-02-21 02:27:33 +01:00
|
|
|
/// meaning it is artificial and wants to be adjacent.
|
2012-11-12 20:28:57 +01:00
|
|
|
bool isCluster() const {
|
|
|
|
return getKind() == Order && Contents.OrdKind == Cluster;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if this is a Data dependence that is associated with a register.
|
2008-12-09 23:54:47 +01:00
|
|
|
bool isAssignedRegDep() const {
|
|
|
|
return getKind() == Data && Contents.Reg != 0;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns the register associated with this edge. This is only valid on
|
|
|
|
/// Data, Anti, and Output edges. On Data edges, this value may be zero,
|
|
|
|
/// meaning there is no associated register.
|
2008-12-09 23:54:47 +01:00
|
|
|
unsigned getReg() const {
|
|
|
|
assert((getKind() == Data || getKind() == Anti || getKind() == Output) &&
|
|
|
|
"getReg called on non-register dependence edge!");
|
|
|
|
return Contents.Reg;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Assigns the associated register for this edge. This is only valid on
|
|
|
|
/// Data, Anti, and Output edges. On Anti and Output edges, this value must
|
|
|
|
/// not be zero. On Data edges, the value may be zero, which would mean that
|
|
|
|
/// no specific register is associated with this edge.
|
2008-12-09 23:54:47 +01:00
|
|
|
void setReg(unsigned Reg) {
|
|
|
|
assert((getKind() == Data || getKind() == Anti || getKind() == Output) &&
|
|
|
|
"setReg called on non-register dependence edge!");
|
|
|
|
assert((getKind() != Anti || Reg != 0) &&
|
|
|
|
"SDep::Anti edge cannot use the zero register!");
|
|
|
|
assert((getKind() != Output || Reg != 0) &&
|
|
|
|
"SDep::Output edge cannot use the zero register!");
|
|
|
|
Contents.Reg = Reg;
|
|
|
|
}
|
2017-07-12 17:30:59 +02:00
|
|
|
|
2018-09-19 02:23:35 +02:00
|
|
|
void dump(const TargetRegisterInfo *TRI = nullptr) const;
|
2007-09-19 03:38:40 +02:00
|
|
|
};
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Scheduling unit. This is a node in the scheduling DAG.
|
2009-02-14 17:06:42 +01:00
|
|
|
class SUnit {
|
2008-11-13 22:36:12 +01:00
|
|
|
private:
|
2014-03-02 04:20:38 +01:00
|
|
|
enum : unsigned { BoundaryID = ~0u };
|
2013-01-25 07:52:30 +01:00
|
|
|
|
2017-02-22 23:32:51 +01:00
|
|
|
SDNode *Node = nullptr; ///< Representative node.
|
|
|
|
MachineInstr *Instr = nullptr; ///< Alternatively, a MachineInstr.
|
|
|
|
|
2008-11-13 22:36:12 +01:00
|
|
|
public:
|
2018-07-30 21:41:25 +02:00
|
|
|
SUnit *OrigNode = nullptr; ///< If not this, the node from which this node
|
2017-02-22 23:32:51 +01:00
|
|
|
/// was cloned. (SD scheduling only)
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2017-02-22 23:32:51 +01:00
|
|
|
const MCSchedClassDesc *SchedClass =
|
|
|
|
nullptr; ///< nullptr or resolved SchedClass.
|
2012-11-06 08:10:38 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
SmallVector<SDep, 4> Preds; ///< All sunit predecessors.
|
|
|
|
SmallVector<SDep, 4> Succs; ///< All sunit successors.
|
2007-09-19 03:38:40 +02:00
|
|
|
|
2013-07-03 07:01:24 +02:00
|
|
|
typedef SmallVectorImpl<SDep>::iterator pred_iterator;
|
|
|
|
typedef SmallVectorImpl<SDep>::iterator succ_iterator;
|
|
|
|
typedef SmallVectorImpl<SDep>::const_iterator const_pred_iterator;
|
|
|
|
typedef SmallVectorImpl<SDep>::const_iterator const_succ_iterator;
|
2010-05-21 01:26:43 +02:00
|
|
|
|
2017-02-22 23:32:51 +01:00
|
|
|
unsigned NodeNum = BoundaryID; ///< Entry # of node in the node vector.
|
|
|
|
unsigned NodeQueueId = 0; ///< Queue id of node.
|
|
|
|
unsigned NumPreds = 0; ///< # of SDep::Data preds.
|
|
|
|
unsigned NumSuccs = 0; ///< # of SDep::Data sucss.
|
|
|
|
unsigned NumPredsLeft = 0; ///< # of preds not scheduled.
|
|
|
|
unsigned NumSuccsLeft = 0; ///< # of succs not scheduled.
|
|
|
|
unsigned WeakPredsLeft = 0; ///< # of weak preds not scheduled.
|
|
|
|
unsigned WeakSuccsLeft = 0; ///< # of weak succs not scheduled.
|
|
|
|
unsigned short NumRegDefsLeft = 0; ///< # of reg defs with no scheduled use.
|
|
|
|
unsigned short Latency = 0; ///< Node latency.
|
|
|
|
bool isVRegCycle : 1; ///< May use and def the same vreg.
|
|
|
|
bool isCall : 1; ///< Is a function call.
|
|
|
|
bool isCallOp : 1; ///< Is a function call operand.
|
|
|
|
bool isTwoAddress : 1; ///< Is a two-address instruction.
|
|
|
|
bool isCommutable : 1; ///< Is a commutable instruction.
|
|
|
|
bool hasPhysRegUses : 1; ///< Has physreg uses.
|
|
|
|
bool hasPhysRegDefs : 1; ///< Has physreg defs that are being used.
|
|
|
|
bool hasPhysRegClobbers : 1; ///< Has any physreg defs, used or not.
|
|
|
|
bool isPending : 1; ///< True once pending.
|
|
|
|
bool isAvailable : 1; ///< True once available.
|
|
|
|
bool isScheduled : 1; ///< True once scheduled.
|
|
|
|
bool isScheduleHigh : 1; ///< True if preferable to schedule high.
|
|
|
|
bool isScheduleLow : 1; ///< True if preferable to schedule low.
|
|
|
|
bool isCloned : 1; ///< True if this node has been cloned.
|
|
|
|
bool isUnbuffered : 1; ///< Uses an unbuffered resource.
|
|
|
|
bool hasReservedResource : 1; ///< Uses a reserved resource.
|
|
|
|
Sched::Preference SchedulingPref = Sched::None; ///< Scheduling preference.
|
2010-05-20 00:57:06 +02:00
|
|
|
|
2008-12-16 04:25:46 +01:00
|
|
|
private:
|
2017-02-22 23:32:51 +01:00
|
|
|
bool isDepthCurrent : 1; ///< True if Depth is current.
|
|
|
|
bool isHeightCurrent : 1; ///< True if Height is current.
|
|
|
|
unsigned Depth = 0; ///< Node depth.
|
|
|
|
unsigned Height = 0; ///< Node height.
|
|
|
|
|
2008-12-16 04:25:46 +01:00
|
|
|
public:
|
2017-02-22 23:32:51 +01:00
|
|
|
unsigned TopReadyCycle = 0; ///< Cycle relative to start when node is ready.
|
|
|
|
unsigned BotReadyCycle = 0; ///< Cycle relative to end when node is ready.
|
2012-06-05 23:11:27 +02:00
|
|
|
|
2017-02-22 23:32:51 +01:00
|
|
|
const TargetRegisterClass *CopyDstRC =
|
|
|
|
nullptr; ///< Is a special copy node if != nullptr.
|
|
|
|
const TargetRegisterClass *CopySrcRC = nullptr;
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Constructs an SUnit for pre-regalloc scheduling to represent an
|
2017-02-21 02:27:33 +01:00
|
|
|
/// SDNode and any nodes flagged to it.
|
2006-05-12 01:55:42 +02:00
|
|
|
SUnit(SDNode *node, unsigned nodenum)
|
2017-02-22 23:32:51 +01:00
|
|
|
: Node(node), NodeNum(nodenum), isVRegCycle(false), isCall(false),
|
2014-04-14 02:51:57 +02:00
|
|
|
isCallOp(false), isTwoAddress(false), isCommutable(false),
|
|
|
|
hasPhysRegUses(false), hasPhysRegDefs(false), hasPhysRegClobbers(false),
|
|
|
|
isPending(false), isAvailable(false), isScheduled(false),
|
|
|
|
isScheduleHigh(false), isScheduleLow(false), isCloned(false),
|
2017-02-22 23:32:51 +01:00
|
|
|
isUnbuffered(false), hasReservedResource(false), isDepthCurrent(false),
|
|
|
|
isHeightCurrent(false) {}
|
2008-11-14 01:06:09 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Constructs an SUnit for post-regalloc scheduling to represent a
|
2017-02-21 02:27:33 +01:00
|
|
|
/// MachineInstr.
|
2008-11-14 01:06:09 +01:00
|
|
|
SUnit(MachineInstr *instr, unsigned nodenum)
|
2017-02-22 23:32:51 +01:00
|
|
|
: Instr(instr), NodeNum(nodenum), isVRegCycle(false), isCall(false),
|
2014-04-14 02:51:57 +02:00
|
|
|
isCallOp(false), isTwoAddress(false), isCommutable(false),
|
|
|
|
hasPhysRegUses(false), hasPhysRegDefs(false), hasPhysRegClobbers(false),
|
|
|
|
isPending(false), isAvailable(false), isScheduled(false),
|
|
|
|
isScheduleHigh(false), isScheduleLow(false), isCloned(false),
|
2017-02-22 23:32:51 +01:00
|
|
|
isUnbuffered(false), hasReservedResource(false), isDepthCurrent(false),
|
|
|
|
isHeightCurrent(false) {}
|
2007-09-25 03:54:36 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Constructs a placeholder SUnit.
|
2009-02-11 00:27:53 +01:00
|
|
|
SUnit()
|
2017-02-22 23:32:51 +01:00
|
|
|
: isVRegCycle(false), isCall(false), isCallOp(false), isTwoAddress(false),
|
|
|
|
isCommutable(false), hasPhysRegUses(false), hasPhysRegDefs(false),
|
|
|
|
hasPhysRegClobbers(false), isPending(false), isAvailable(false),
|
|
|
|
isScheduled(false), isScheduleHigh(false), isScheduleLow(false),
|
|
|
|
isCloned(false), isUnbuffered(false), hasReservedResource(false),
|
|
|
|
isDepthCurrent(false), isHeightCurrent(false) {}
|
2009-02-11 00:27:53 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Boundary nodes are placeholders for the boundary of the
|
2013-01-25 07:52:30 +01:00
|
|
|
/// scheduling region.
|
|
|
|
///
|
|
|
|
/// BoundaryNodes can have DAG edges, including Data edges, but they do not
|
|
|
|
/// correspond to schedulable entities (e.g. instructions) and do not have a
|
|
|
|
/// valid ID. Consequently, always check for boundary nodes before accessing
|
2017-05-29 13:46:44 +02:00
|
|
|
/// an associative data structure keyed on node ID.
|
2015-07-22 22:46:11 +02:00
|
|
|
bool isBoundaryNode() const { return NodeNum == BoundaryID; }
|
2013-01-25 07:52:30 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Assigns the representative SDNode for this SUnit. This may be used
|
|
|
|
/// during pre-regalloc scheduling.
|
2008-11-14 01:06:09 +01:00
|
|
|
void setNode(SDNode *N) {
|
|
|
|
assert(!Instr && "Setting SDNode of SUnit with MachineInstr!");
|
|
|
|
Node = N;
|
|
|
|
}
|
2008-11-13 22:36:12 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns the representative SDNode for this SUnit. This may be used
|
|
|
|
/// during pre-regalloc scheduling.
|
2008-11-14 01:06:09 +01:00
|
|
|
SDNode *getNode() const {
|
|
|
|
assert(!Instr && "Reading SDNode of SUnit with MachineInstr!");
|
|
|
|
return Node;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Returns true if this SUnit refers to a machine instruction as
|
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
|
|
|
/// opposed to an SDNode.
|
2010-12-24 08:10:19 +01:00
|
|
|
bool isInstr() const { return Instr; }
|
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
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Assigns the instruction for the SUnit. This may be used during
|
|
|
|
/// post-regalloc scheduling.
|
2008-11-14 01:06:09 +01:00
|
|
|
void setInstr(MachineInstr *MI) {
|
|
|
|
assert(!Node && "Setting MachineInstr of SUnit with SDNode!");
|
|
|
|
Instr = MI;
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns the representative MachineInstr for this SUnit. This may be used
|
|
|
|
/// during post-regalloc scheduling.
|
2008-11-14 01:06:09 +01:00
|
|
|
MachineInstr *getInstr() const {
|
|
|
|
assert(!Node && "Reading MachineInstr of SUnit with SDNode!");
|
|
|
|
return Instr;
|
|
|
|
}
|
2008-11-13 22:36:12 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Adds the specified edge as a pred of the current node if not already.
|
|
|
|
/// It also adds the current node as a successor of the specified node.
|
2012-11-12 20:28:57 +01:00
|
|
|
bool addPred(const SDep &D, bool Required = true);
|
2006-08-17 02:09:56 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Adds a barrier edge to SU by calling addPred(), with latency 0
|
2017-02-21 02:27:33 +01:00
|
|
|
/// generally or latency 1 for a store followed by a load.
|
2016-02-03 18:52:29 +01:00
|
|
|
bool addPredBarrier(SUnit *SU) {
|
|
|
|
SDep Dep(SU, SDep::Barrier);
|
|
|
|
unsigned TrueMemOrderLatency =
|
|
|
|
((SU->getInstr()->mayStore() && this->getInstr()->mayLoad()) ? 1 : 0);
|
|
|
|
Dep.setLatency(TrueMemOrderLatency);
|
|
|
|
return addPred(Dep);
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Removes the specified edge as a pred of the current node if it exists.
|
|
|
|
/// It also removes the current node as a successor of the specified node.
|
2008-12-16 02:05:52 +01:00
|
|
|
void removePred(const SDep &D);
|
2007-09-25 03:54:36 +02:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns the depth of this node, which is the length of the maximum path
|
|
|
|
/// up to any node which has no predecessors.
|
2009-11-20 20:32:48 +01:00
|
|
|
unsigned getDepth() const {
|
2010-12-24 05:28:06 +01:00
|
|
|
if (!isDepthCurrent)
|
2009-11-20 20:32:48 +01:00
|
|
|
const_cast<SUnit *>(this)->ComputeDepth();
|
2008-12-16 04:25:46 +01:00
|
|
|
return Depth;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Returns the height of this node, which is the length of the
|
2011-03-07 23:48:16 +01:00
|
|
|
/// maximum path down to any node which has no successors.
|
2009-11-20 20:32:48 +01:00
|
|
|
unsigned getHeight() const {
|
2010-12-24 05:28:06 +01:00
|
|
|
if (!isHeightCurrent)
|
2009-11-20 20:32:48 +01:00
|
|
|
const_cast<SUnit *>(this)->ComputeHeight();
|
2008-12-16 04:25:46 +01:00
|
|
|
return Height;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// If NewDepth is greater than this node's depth value, sets it to
|
2017-02-21 02:27:33 +01:00
|
|
|
/// be the new depth value. This also recursively marks successor nodes
|
|
|
|
/// dirty.
|
2009-11-20 20:32:48 +01:00
|
|
|
void setDepthToAtLeast(unsigned NewDepth);
|
2008-12-16 04:25:46 +01:00
|
|
|
|
2019-03-29 06:05:21 +01:00
|
|
|
/// If NewHeight is greater than this node's height value, set it to be
|
2017-02-21 02:27:33 +01:00
|
|
|
/// the new height value. This also recursively marks predecessor nodes
|
|
|
|
/// dirty.
|
2009-11-20 20:32:48 +01:00
|
|
|
void setHeightToAtLeast(unsigned NewHeight);
|
2008-12-16 04:25:46 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Sets a flag in this node to indicate that its stored Depth value
|
2017-02-21 02:27:33 +01:00
|
|
|
/// will require recomputation the next time getDepth() is called.
|
2008-12-16 04:25:46 +01:00
|
|
|
void setDepthDirty();
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Sets a flag in this node to indicate that its stored Height value
|
2017-02-21 02:27:33 +01:00
|
|
|
/// will require recomputation the next time getHeight() is called.
|
2008-12-16 04:25:46 +01:00
|
|
|
void setHeightDirty();
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if node N is a predecessor of this node.
|
|
|
|
bool isPred(const SUnit *N) const {
|
|
|
|
for (const SDep &Pred : Preds)
|
|
|
|
if (Pred.getSUnit() == N)
|
2007-09-25 03:54:36 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if node N is a successor of this node.
|
|
|
|
bool isSucc(const SUnit *N) const {
|
|
|
|
for (const SDep &Succ : Succs)
|
|
|
|
if (Succ.getSUnit() == N)
|
2007-09-25 03:54:36 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
2006-08-17 02:09:56 +02:00
|
|
|
}
|
2010-05-21 01:26:43 +02:00
|
|
|
|
2012-03-14 05:00:41 +01:00
|
|
|
bool isTopReady() const {
|
|
|
|
return NumPredsLeft == 0;
|
|
|
|
}
|
|
|
|
bool isBottomReady() const {
|
|
|
|
return NumSuccsLeft == 0;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Orders this node's predecessor edges such that the critical path
|
2013-01-24 03:09:55 +01:00
|
|
|
/// edge occurs first.
|
|
|
|
void biasCriticalPath();
|
|
|
|
|
2018-09-19 02:23:35 +02:00
|
|
|
void dumpAttributes() const;
|
2008-12-16 04:25:46 +01:00
|
|
|
|
|
|
|
private:
|
2009-11-20 20:32:48 +01:00
|
|
|
void ComputeDepth();
|
|
|
|
void ComputeHeight();
|
2006-05-12 01:55:42 +02:00
|
|
|
};
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns true if the specified SDep is equivalent except for latency.
|
2015-12-29 10:24:42 +01:00
|
|
|
inline bool SDep::overlaps(const SDep &Other) const {
|
|
|
|
if (Dep != Other.Dep)
|
|
|
|
return false;
|
|
|
|
switch (Dep.getInt()) {
|
|
|
|
case Data:
|
|
|
|
case Anti:
|
|
|
|
case Output:
|
|
|
|
return Contents.Reg == Other.Contents.Reg;
|
|
|
|
case Order:
|
|
|
|
return Contents.OrdKind == Other.Contents.OrdKind;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid dependency kind!");
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
//// Returns the SUnit to which this edge points.
|
2015-12-29 10:24:42 +01:00
|
|
|
inline SUnit *SDep::getSUnit() const { return Dep.getPointer(); }
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
//// Assigns the SUnit to which this edge points.
|
2015-12-29 10:24:42 +01:00
|
|
|
inline void SDep::setSUnit(SUnit *SU) { Dep.setPointer(SU); }
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns an enum value representing the kind of the dependence.
|
2015-12-29 10:24:42 +01:00
|
|
|
inline SDep::Kind SDep::getKind() const { return Dep.getInt(); }
|
|
|
|
|
2006-05-12 01:55:42 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
2017-02-21 02:27:33 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// This interface is used to plug different priorities computation
|
2017-02-21 02:27:33 +01:00
|
|
|
/// algorithms into the list scheduler. It implements the interface of a
|
|
|
|
/// standard priority queue, where nodes are inserted in arbitrary order and
|
|
|
|
/// returned in priority order. The computation of the priority and the
|
|
|
|
/// representation of the queue are totally up to the implementation to
|
|
|
|
/// decide.
|
2006-05-12 01:55:42 +02:00
|
|
|
class SchedulingPriorityQueue {
|
2011-12-20 03:50:00 +01:00
|
|
|
virtual void anchor();
|
2017-02-22 23:32:51 +01:00
|
|
|
|
|
|
|
unsigned CurCycle = 0;
|
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
|
|
|
bool HasReadyFilter;
|
2017-02-22 23:32:51 +01:00
|
|
|
|
2006-05-12 01:55:42 +02:00
|
|
|
public:
|
2017-02-22 23:32:51 +01:00
|
|
|
SchedulingPriorityQueue(bool rf = false) : HasReadyFilter(rf) {}
|
|
|
|
|
|
|
|
virtual ~SchedulingPriorityQueue() = default;
|
2010-12-24 05:28:06 +01: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 06:03:26 +01:00
|
|
|
virtual bool isBottomUp() const = 0;
|
|
|
|
|
2008-06-21 21:18:17 +02:00
|
|
|
virtual void initNodes(std::vector<SUnit> &SUnits) = 0;
|
2007-09-25 03:54:36 +02:00
|
|
|
virtual void addNode(const SUnit *SU) = 0;
|
|
|
|
virtual void updateNode(const SUnit *SU) = 0;
|
2006-05-12 01:55:42 +02:00
|
|
|
virtual void releaseState() = 0;
|
2007-09-25 03:54:36 +02:00
|
|
|
|
2006-05-12 01:55:42 +02:00
|
|
|
virtual bool empty() const = 0;
|
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
|
|
|
|
|
|
|
bool hasReadyFilter() const { return HasReadyFilter; }
|
|
|
|
|
2011-02-04 04:18:17 +01:00
|
|
|
virtual bool tracksRegPressure() const { return false; }
|
|
|
|
|
2010-12-25 03:38:01 +01:00
|
|
|
virtual bool isReady(SUnit *) const {
|
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
|
|
|
assert(!HasReadyFilter && "The ready filter must override isReady()");
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-22 23:32:51 +01:00
|
|
|
|
2006-05-12 01:55:42 +02:00
|
|
|
virtual void push(SUnit *U) = 0;
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2010-05-26 03:10:55 +02:00
|
|
|
void push_all(const std::vector<SUnit *> &Nodes) {
|
|
|
|
for (std::vector<SUnit *>::const_iterator I = Nodes.begin(),
|
|
|
|
E = Nodes.end(); I != E; ++I)
|
|
|
|
push(*I);
|
|
|
|
}
|
|
|
|
|
2006-05-12 01:55:42 +02:00
|
|
|
virtual SUnit *pop() = 0;
|
|
|
|
|
2007-09-25 03:54:36 +02:00
|
|
|
virtual void remove(SUnit *SU) = 0;
|
|
|
|
|
2010-12-25 03:38:01 +01:00
|
|
|
virtual void dump(ScheduleDAG *) const {}
|
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
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// As each node is scheduled, this method is invoked. This allows the
|
|
|
|
/// priority function to adjust the priority of related unscheduled nodes,
|
|
|
|
/// for example.
|
2012-03-08 00:00:49 +01:00
|
|
|
virtual void scheduledNode(SUnit *) {}
|
2007-09-25 03:54:36 +02:00
|
|
|
|
2012-03-08 00:00:49 +01:00
|
|
|
virtual void unscheduledNode(SUnit *) {}
|
2010-05-20 08:13:19 +02:00
|
|
|
|
|
|
|
void setCurCycle(unsigned Cycle) {
|
|
|
|
CurCycle = Cycle;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getCurCycle() const {
|
|
|
|
return CurCycle;
|
2010-12-24 05:28:06 +01:00
|
|
|
}
|
2006-05-12 01:55:42 +02:00
|
|
|
};
|
|
|
|
|
2006-01-21 03:32:06 +01:00
|
|
|
class ScheduleDAG {
|
|
|
|
public:
|
2018-11-06 00:49:14 +01:00
|
|
|
const LLVMTargetMachine &TM; ///< Target processor
|
2017-02-21 02:27:33 +01:00
|
|
|
const TargetInstrInfo *TII; ///< Target instruction information
|
|
|
|
const TargetRegisterInfo *TRI; ///< Target processor register info
|
|
|
|
MachineFunction &MF; ///< Machine function
|
|
|
|
MachineRegisterInfo &MRI; ///< Virtual/real register map
|
|
|
|
std::vector<SUnit> SUnits; ///< The scheduling units.
|
2020-09-21 13:18:39 +02:00
|
|
|
SUnit EntrySU; ///< Special node for the region entry.
|
2017-02-21 02:27:33 +01:00
|
|
|
SUnit ExitSU; ///< Special node for the region exit.
|
2006-01-21 03:32:06 +01:00
|
|
|
|
2011-06-15 19:16:12 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
static const bool StressSched = false;
|
|
|
|
#else
|
|
|
|
bool StressSched;
|
|
|
|
#endif
|
|
|
|
|
2009-01-15 20:20:50 +01:00
|
|
|
explicit ScheduleDAG(MachineFunction &mf);
|
2006-02-04 07:49:00 +01:00
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
virtual ~ScheduleDAG();
|
2006-01-21 03:32:06 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Clears the DAG state (between regions).
|
2012-03-07 06:21:52 +01:00
|
|
|
void clearDAG();
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns the MCInstrDesc of this SUnit.
|
|
|
|
/// Returns NULL for SDNodes without a machine opcode.
|
2011-06-28 21:10:37 +02:00
|
|
|
const MCInstrDesc *getInstrDesc(const SUnit *SU) const {
|
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
|
|
|
if (SU->isInstr()) return &SU->getInstr()->getDesc();
|
|
|
|
return getNodeDesc(SU->getNode());
|
|
|
|
}
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Pops up a GraphViz/gv window with the ScheduleDAG rendered using 'dot'.
|
2013-01-25 08:45:29 +01:00
|
|
|
virtual void viewGraph(const Twine &Name, const Twine &Title);
|
|
|
|
virtual void viewGraph();
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2018-09-19 02:23:35 +02:00
|
|
|
virtual void dumpNode(const SUnit &SU) const = 0;
|
|
|
|
virtual void dump() const = 0;
|
|
|
|
void dumpNodeName(const SUnit &SU) const;
|
2008-11-19 23:09:45 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns a label for an SUnit node in a visualization of the ScheduleDAG.
|
2008-11-20 00:18:57 +01:00
|
|
|
virtual std::string getGraphNodeLabel(const SUnit *SU) const = 0;
|
2008-04-03 18:36:07 +02:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns a label for the region of code covered by the DAG.
|
2012-03-07 01:18:22 +01:00
|
|
|
virtual std::string getDAGName() const = 0;
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Adds custom features for a visualization of the ScheduleDAG.
|
2008-11-24 20:51:59 +01:00
|
|
|
virtual void addCustomGraphFeatures(GraphWriter<ScheduleDAG*> &) const {}
|
2008-04-03 18:36:07 +02:00
|
|
|
|
2008-11-20 02:26:25 +01:00
|
|
|
#ifndef NDEBUG
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Verifies that all SUnits were scheduled and that their state is
|
2017-02-21 02:27:33 +01:00
|
|
|
/// consistent. Returns the number of scheduled SUnits.
|
2012-03-07 06:21:36 +01:00
|
|
|
unsigned VerifyScheduledDAG(bool isBottomUp);
|
2008-11-20 02:26:25 +01:00
|
|
|
#endif
|
|
|
|
|
2018-09-19 02:23:35 +02:00
|
|
|
protected:
|
|
|
|
void dumpNodeAll(const SUnit &SU) const;
|
|
|
|
|
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
|
|
|
private:
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns the MCInstrDesc of this SDNode or NULL.
|
2011-06-28 21:10:37 +02:00
|
|
|
const MCInstrDesc *getNodeDesc(const SDNode *Node) const;
|
2006-01-21 03:32:06 +01:00
|
|
|
};
|
|
|
|
|
2021-04-12 19:47:14 +02:00
|
|
|
class SUnitIterator {
|
2007-08-28 22:32:58 +02:00
|
|
|
SUnit *Node;
|
|
|
|
unsigned Operand;
|
|
|
|
|
|
|
|
SUnitIterator(SUnit *N, unsigned Op) : Node(N), Operand(Op) {}
|
2017-02-22 23:32:51 +01:00
|
|
|
|
2007-08-28 22:32:58 +02:00
|
|
|
public:
|
2021-04-12 19:47:14 +02:00
|
|
|
using iterator_category = std::forward_iterator_tag;
|
|
|
|
using value_type = SUnit;
|
|
|
|
using difference_type = std::ptrdiff_t;
|
|
|
|
using pointer = value_type *;
|
|
|
|
using reference = value_type &;
|
|
|
|
|
2007-08-28 22:32:58 +02:00
|
|
|
bool operator==(const SUnitIterator& x) const {
|
|
|
|
return Operand == x.Operand;
|
|
|
|
}
|
|
|
|
bool operator!=(const SUnitIterator& x) const { return !operator==(x); }
|
|
|
|
|
|
|
|
pointer operator*() const {
|
2008-12-09 23:54:47 +01:00
|
|
|
return Node->Preds[Operand].getSUnit();
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|
|
|
|
pointer operator->() const { return operator*(); }
|
|
|
|
|
|
|
|
SUnitIterator& operator++() { // Preincrement
|
|
|
|
++Operand;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SUnitIterator operator++(int) { // Postincrement
|
|
|
|
SUnitIterator tmp = *this; ++*this; return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SUnitIterator begin(SUnit *N) { return SUnitIterator(N, 0); }
|
|
|
|
static SUnitIterator end (SUnit *N) {
|
2008-05-05 20:30:58 +02:00
|
|
|
return SUnitIterator(N, (unsigned)N->Preds.size());
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getOperand() const { return Operand; }
|
|
|
|
const SUnit *getNode() const { return Node; }
|
2017-02-22 23:32:51 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Tests if this is not an SDep::Data dependence.
|
2008-12-09 23:54:47 +01:00
|
|
|
bool isCtrlDep() const {
|
2008-12-16 01:51:33 +01:00
|
|
|
return getSDep().isCtrl();
|
2008-12-09 23:54:47 +01:00
|
|
|
}
|
|
|
|
bool isArtificialDep() const {
|
2008-12-16 01:51:33 +01:00
|
|
|
return getSDep().isArtificial();
|
|
|
|
}
|
|
|
|
const SDep &getSDep() const {
|
|
|
|
return Node->Preds[Operand];
|
2008-12-09 23:54:47 +01:00
|
|
|
}
|
2007-08-28 22:32:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<SUnit*> {
|
2016-08-17 22:07:29 +02:00
|
|
|
typedef SUnit *NodeRef;
|
2007-08-28 22:32:58 +02:00
|
|
|
typedef SUnitIterator ChildIteratorType;
|
2016-08-31 18:48:13 +02:00
|
|
|
static NodeRef getEntryNode(SUnit *N) { return N; }
|
|
|
|
static ChildIteratorType child_begin(NodeRef N) {
|
2007-08-28 22:32:58 +02:00
|
|
|
return SUnitIterator::begin(N);
|
|
|
|
}
|
2016-08-31 18:48:13 +02:00
|
|
|
static ChildIteratorType child_end(NodeRef N) {
|
2007-08-28 22:32:58 +02:00
|
|
|
return SUnitIterator::end(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<ScheduleDAG*> : public GraphTraits<SUnit*> {
|
2016-08-19 23:20:13 +02:00
|
|
|
typedef pointer_iterator<std::vector<SUnit>::iterator> nodes_iterator;
|
2007-08-28 22:32:58 +02:00
|
|
|
static nodes_iterator nodes_begin(ScheduleDAG *G) {
|
2016-08-19 23:20:13 +02:00
|
|
|
return nodes_iterator(G->SUnits.begin());
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|
|
|
|
static nodes_iterator nodes_end(ScheduleDAG *G) {
|
2016-08-19 23:20:13 +02:00
|
|
|
return nodes_iterator(G->SUnits.end());
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|
|
|
|
};
|
2008-11-25 01:52:40 +01:00
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// This class can compute a topological ordering for SUnits and provides
|
|
|
|
/// methods for dynamically updating the ordering as new edges are added.
|
2008-11-25 01:52:40 +01:00
|
|
|
///
|
|
|
|
/// This allows a very fast implementation of IsReachable, for example.
|
|
|
|
class ScheduleDAGTopologicalSort {
|
2017-02-21 02:27:33 +01:00
|
|
|
/// A reference to the ScheduleDAG's SUnits.
|
2008-11-25 01:52:40 +01:00
|
|
|
std::vector<SUnit> &SUnits;
|
2012-11-12 20:28:57 +01:00
|
|
|
SUnit *ExitSU;
|
2008-11-25 01:52:40 +01:00
|
|
|
|
[ScheduleDAGRRList] Recompute topological ordering on demand.
Currently there is a single point in ScheduleDAGRRList, where we
actually query the topological order (besides init code). Currently we
are recomputing the order after adding a node (which does not have
predecessors) and then we add predecessors edge-by-edge.
We can avoid adding edges one-by-one after we added a new node. In that case, we can
just rebuild the order from scratch after adding the edges to the DAG
and avoid all the updates to the ordering.
Also, we can delay updating the DAG until we query the DAG, if we keep a
list of added edges. Depending on the number of updates, we can either
apply them when needed or recompute the order from scratch.
This brings down the geomean compile time for of CTMark with -O1 down 0.3% on X86,
with no regressions.
Reviewers: MatzeB, atrick, efriedma, niravd, paquette
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D60125
llvm-svn: 358583
2019-04-17 17:05:29 +02:00
|
|
|
// Have any new nodes been added?
|
|
|
|
bool Dirty = false;
|
|
|
|
|
|
|
|
// Outstanding added edges, that have not been applied to the ordering.
|
|
|
|
SmallVector<std::pair<SUnit *, SUnit *>, 16> Updates;
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Maps topological index to the node number.
|
2008-11-25 01:52:40 +01:00
|
|
|
std::vector<int> Index2Node;
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Maps the node number to its topological index.
|
2008-11-25 01:52:40 +01:00
|
|
|
std::vector<int> Node2Index;
|
2017-02-21 02:27:33 +01:00
|
|
|
/// a set of nodes visited during a DFS traversal.
|
2008-11-25 01:52:40 +01:00
|
|
|
BitVector Visited;
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Makes a DFS traversal and mark all nodes affected by the edge insertion.
|
|
|
|
/// These nodes will later get new topological indexes by means of the Shift
|
|
|
|
/// method.
|
2008-11-25 01:52:40 +01:00
|
|
|
void DFS(const SUnit *SU, int UpperBound, bool& HasLoop);
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Reassigns topological indexes for the nodes in the DAG to
|
2017-02-21 02:27:33 +01:00
|
|
|
/// preserve the topological ordering.
|
2008-11-25 01:52:40 +01:00
|
|
|
void Shift(BitVector& Visited, int LowerBound, int UpperBound);
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Assigns the topological index to the node n.
|
2008-11-25 01:52:40 +01:00
|
|
|
void Allocate(int n, int index);
|
|
|
|
|
[ScheduleDAGRRList] Recompute topological ordering on demand.
Currently there is a single point in ScheduleDAGRRList, where we
actually query the topological order (besides init code). Currently we
are recomputing the order after adding a node (which does not have
predecessors) and then we add predecessors edge-by-edge.
We can avoid adding edges one-by-one after we added a new node. In that case, we can
just rebuild the order from scratch after adding the edges to the DAG
and avoid all the updates to the ordering.
Also, we can delay updating the DAG until we query the DAG, if we keep a
list of added edges. Depending on the number of updates, we can either
apply them when needed or recompute the order from scratch.
This brings down the geomean compile time for of CTMark with -O1 down 0.3% on X86,
with no regressions.
Reviewers: MatzeB, atrick, efriedma, niravd, paquette
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D60125
llvm-svn: 358583
2019-04-17 17:05:29 +02:00
|
|
|
/// Fix the ordering, by either recomputing from scratch or by applying
|
|
|
|
/// any outstanding updates. Uses a heuristic to estimate what will be
|
|
|
|
/// cheaper.
|
|
|
|
void FixOrder();
|
|
|
|
|
2008-11-25 01:52:40 +01:00
|
|
|
public:
|
2012-11-12 20:28:57 +01:00
|
|
|
ScheduleDAGTopologicalSort(std::vector<SUnit> &SUnits, SUnit *ExitSU);
|
2008-11-25 01:52:40 +01:00
|
|
|
|
[ScheduleDAG] Avoid unnecessary recomputation of topological order.
In some cases ScheduleDAGRRList has to add new nodes to resolve problems
with interfering physical registers. When new nodes are added, it
completely re-computes the topological order, which can take a long
time, but is unnecessary. We only add nodes one by one, and initially
they do not have any predecessors. So we can just insert them at the end
of the vector. Later we add predecessors, but the helper function
properly updates the topological order much more efficiently. With this
change, the compile time for the program below drops from 300s to 30s on
my machine.
define i11129 @test1() {
%L1 = load i11129, i11129* undef
%B30 = ashr i11129 %L1, %L1
store i11129 %B30, i11129* undef
ret i11129 %L1
}
This should be generally beneficial, as we can skip a large amount of
work. Theoretically there are some scenarios where we might not safe
much, e.g. when we add a dependency between the first and last node.
Then we would have to shift all nodes. But we still do not have to spend
the time re-computing the initial order.
Reviewers: MatzeB, atrick, efriedma, niravd, paquette
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D59722
2020-05-31 12:04:35 +02:00
|
|
|
/// Add a SUnit without predecessors to the end of the topological order. It
|
|
|
|
/// also must be the first new node added to the DAG.
|
|
|
|
void AddSUnitWithoutPredecessors(const SUnit *SU);
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Creates the initial topological ordering from the DAG to be scheduled.
|
2008-11-25 01:52:40 +01:00
|
|
|
void InitDAGTopologicalSorting();
|
|
|
|
|
2017-03-28 07:12:31 +02:00
|
|
|
/// Returns an array of SUs that are both in the successor
|
|
|
|
/// subtree of StartSU and in the predecessor subtree of TargetSU.
|
|
|
|
/// StartSU and TargetSU are not in the array.
|
|
|
|
/// Success is false if TargetSU is not in the successor subtree of
|
|
|
|
/// StartSU, else it is true.
|
|
|
|
std::vector<int> GetSubGraph(const SUnit &StartSU, const SUnit &TargetSU,
|
|
|
|
bool &Success);
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Checks if \p SU is reachable from \p TargetSU.
|
2008-11-25 01:52:40 +01:00
|
|
|
bool IsReachable(const SUnit *SU, const SUnit *TargetSU);
|
|
|
|
|
2017-02-21 02:27:33 +01:00
|
|
|
/// Returns true if addPred(TargetSU, SU) creates a cycle.
|
2013-04-24 17:54:43 +02:00
|
|
|
bool WillCreateCycle(SUnit *TargetSU, SUnit *SU);
|
2008-11-25 01:52:40 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Updates the topological ordering to accommodate an edge to be
|
2017-02-21 02:27:33 +01:00
|
|
|
/// added from SUnit \p X to SUnit \p Y.
|
2008-11-25 01:52:40 +01:00
|
|
|
void AddPred(SUnit *Y, SUnit *X);
|
|
|
|
|
[ScheduleDAGRRList] Recompute topological ordering on demand.
Currently there is a single point in ScheduleDAGRRList, where we
actually query the topological order (besides init code). Currently we
are recomputing the order after adding a node (which does not have
predecessors) and then we add predecessors edge-by-edge.
We can avoid adding edges one-by-one after we added a new node. In that case, we can
just rebuild the order from scratch after adding the edges to the DAG
and avoid all the updates to the ordering.
Also, we can delay updating the DAG until we query the DAG, if we keep a
list of added edges. Depending on the number of updates, we can either
apply them when needed or recompute the order from scratch.
This brings down the geomean compile time for of CTMark with -O1 down 0.3% on X86,
with no regressions.
Reviewers: MatzeB, atrick, efriedma, niravd, paquette
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D60125
llvm-svn: 358583
2019-04-17 17:05:29 +02:00
|
|
|
/// Queues an update to the topological ordering to accommodate an edge to
|
|
|
|
/// be added from SUnit \p X to SUnit \p Y.
|
|
|
|
void AddPredQueued(SUnit *Y, SUnit *X);
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Updates the topological ordering to accommodate an an edge to be
|
2017-02-21 02:27:33 +01:00
|
|
|
/// removed from the specified node \p N from the predecessors of the
|
|
|
|
/// current node \p M.
|
2008-11-25 01:52:40 +01:00
|
|
|
void RemovePred(SUnit *M, SUnit *N);
|
|
|
|
|
[ScheduleDAGRRList] Recompute topological ordering on demand.
Currently there is a single point in ScheduleDAGRRList, where we
actually query the topological order (besides init code). Currently we
are recomputing the order after adding a node (which does not have
predecessors) and then we add predecessors edge-by-edge.
We can avoid adding edges one-by-one after we added a new node. In that case, we can
just rebuild the order from scratch after adding the edges to the DAG
and avoid all the updates to the ordering.
Also, we can delay updating the DAG until we query the DAG, if we keep a
list of added edges. Depending on the number of updates, we can either
apply them when needed or recompute the order from scratch.
This brings down the geomean compile time for of CTMark with -O1 down 0.3% on X86,
with no regressions.
Reviewers: MatzeB, atrick, efriedma, niravd, paquette
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D60125
llvm-svn: 358583
2019-04-17 17:05:29 +02:00
|
|
|
/// Mark the ordering as temporarily broken, after a new node has been
|
|
|
|
/// added.
|
|
|
|
void MarkDirty() { Dirty = true; }
|
|
|
|
|
2008-11-25 01:52:40 +01:00
|
|
|
typedef std::vector<int>::iterator iterator;
|
|
|
|
typedef std::vector<int>::const_iterator const_iterator;
|
|
|
|
iterator begin() { return Index2Node.begin(); }
|
|
|
|
const_iterator begin() const { return Index2Node.begin(); }
|
|
|
|
iterator end() { return Index2Node.end(); }
|
|
|
|
const_iterator end() const { return Index2Node.end(); }
|
|
|
|
|
|
|
|
typedef std::vector<int>::reverse_iterator reverse_iterator;
|
|
|
|
typedef std::vector<int>::const_reverse_iterator const_reverse_iterator;
|
|
|
|
reverse_iterator rbegin() { return Index2Node.rbegin(); }
|
|
|
|
const_reverse_iterator rbegin() const { return Index2Node.rbegin(); }
|
|
|
|
reverse_iterator rend() { return Index2Node.rend(); }
|
|
|
|
const_reverse_iterator rend() const { return Index2Node.rend(); }
|
|
|
|
};
|
2006-01-21 03:32:06 +01:00
|
|
|
|
2017-02-22 23:32:51 +01:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_CODEGEN_SCHEDULEDAG_H
|