mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-05 14:34:55 +00:00
Generalize PostRAHazardRecognizer so it can be used in any pass for
both forward and backward scheduling. Rename it to ScoreboardHazardRecognizer (Scoreboard is one word). Remove integer division from the scoreboard's critical path. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121274 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cd466f582a
commit
6b1207267f
@ -1,4 +1,4 @@
|
||||
//=- llvm/CodeGen/PostRAHazardRecognizer.h - Scheduling Support -*- C++ -*-=//
|
||||
//=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule Support -*- C++ -*-=//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
@ -7,14 +7,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the PostRAHazardRecognizer class, which
|
||||
// implements hazard-avoidance heuristics for scheduling, based on the
|
||||
// This file defines the ScoreboardHazardRecognizer class, which
|
||||
// encapsulates hazard-avoidance heuristics for scheduling, based on the
|
||||
// scheduling itineraries specified for the target.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
|
||||
#define LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
|
||||
#ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
|
||||
#define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
|
||||
|
||||
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
@ -28,13 +28,17 @@ namespace llvm {
|
||||
class InstrItineraryData;
|
||||
class SUnit;
|
||||
|
||||
class PostRAHazardRecognizer : public ScheduleHazardRecognizer {
|
||||
// ScoreBoard to track function unit usage. ScoreBoard[0] is a
|
||||
class ScoreboardHazardRecognizer : public ScheduleHazardRecognizer {
|
||||
// Scoreboard to track function unit usage. Scoreboard[0] is a
|
||||
// mask of the FUs in use in the cycle currently being
|
||||
// schedule. ScoreBoard[1] is a mask for the next cycle. The
|
||||
// ScoreBoard is used as a circular buffer with the current cycle
|
||||
// schedule. Scoreboard[1] is a mask for the next cycle. The
|
||||
// Scoreboard is used as a circular buffer with the current cycle
|
||||
// indicated by Head.
|
||||
class ScoreBoard {
|
||||
//
|
||||
// Scoreboard always counts cycles in forward execution order. If used by a
|
||||
// bottom-up scheduler, then the scoreboard cycles are the inverse of the
|
||||
// scheduler's cycles.
|
||||
class Scoreboard {
|
||||
unsigned *Data;
|
||||
|
||||
// The maximum number of cycles monitored by the Scoreboard. This
|
||||
@ -44,16 +48,18 @@ class PostRAHazardRecognizer : public ScheduleHazardRecognizer {
|
||||
// Indices into the Scoreboard that represent the current cycle.
|
||||
size_t Head;
|
||||
public:
|
||||
ScoreBoard():Data(NULL), Depth(0), Head(0) { }
|
||||
~ScoreBoard() {
|
||||
Scoreboard():Data(NULL), Depth(0), Head(0) { }
|
||||
~Scoreboard() {
|
||||
delete[] Data;
|
||||
}
|
||||
|
||||
size_t getDepth() const { return Depth; }
|
||||
unsigned& operator[](size_t idx) const {
|
||||
assert(Depth && "ScoreBoard was not initialized properly!");
|
||||
// Depth is expected to be a power-of-2.
|
||||
assert(Depth && !(Depth & (Depth - 1)) &&
|
||||
"Scoreboard was not initialized properly!");
|
||||
|
||||
return Data[(Head + idx) % Depth];
|
||||
return Data[(Head + idx) & (Depth-1)];
|
||||
}
|
||||
|
||||
void reset(size_t d = 1) {
|
||||
@ -67,7 +73,11 @@ class PostRAHazardRecognizer : public ScheduleHazardRecognizer {
|
||||
}
|
||||
|
||||
void advance() {
|
||||
Head = (Head + 1) % Depth;
|
||||
Head = (Head + 1) & (Depth-1);
|
||||
}
|
||||
|
||||
void recede() {
|
||||
Head = (Head - 1) & (Depth-1);
|
||||
}
|
||||
|
||||
// Print the scoreboard.
|
||||
@ -77,18 +87,19 @@ class PostRAHazardRecognizer : public ScheduleHazardRecognizer {
|
||||
// Itinerary data for the target.
|
||||
const InstrItineraryData *ItinData;
|
||||
|
||||
ScoreBoard ReservedScoreboard;
|
||||
ScoreBoard RequiredScoreboard;
|
||||
Scoreboard ReservedScoreboard;
|
||||
Scoreboard RequiredScoreboard;
|
||||
|
||||
public:
|
||||
PostRAHazardRecognizer(const InstrItineraryData *ItinData);
|
||||
ScoreboardHazardRecognizer(const InstrItineraryData *ItinData);
|
||||
|
||||
virtual HazardType getHazardType(SUnit *SU);
|
||||
virtual void Reset();
|
||||
virtual void EmitInstruction(SUnit *SU);
|
||||
virtual void AdvanceCycle();
|
||||
virtual void RecedeCycle();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif //!LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
|
@ -53,7 +53,7 @@ add_llvm_library(LLVMCodeGen
|
||||
PHIEliminationUtils.cpp
|
||||
Passes.cpp
|
||||
PeepholeOptimizer.cpp
|
||||
PostRAHazardRecognizer.cpp
|
||||
ScoreboardHazardRecognizer.cpp
|
||||
PostRASchedulerList.cpp
|
||||
PreAllocSplitting.cpp
|
||||
ProcessImplicitDefs.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
//===----- PostRAHazardRecognizer.cpp - hazard recognizer -------- ---------===//
|
||||
//===----- ScoreboardHazardRecognizer.cpp - Scheduler Support -------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
@ -7,13 +7,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This implements a hazard recognizer using the instructions itineraries
|
||||
// defined for the current target.
|
||||
// This file implements the ScoreboardHazardRecognizer class, which
|
||||
// encapsultes hazard-avoidance heuristics for scheduling, based on the
|
||||
// scheduling itineraries specified for the target.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DEBUG_TYPE "post-RA-sched"
|
||||
#include "llvm/CodeGen/PostRAHazardRecognizer.h"
|
||||
#define DEBUG_TYPE "sched-hazard"
|
||||
#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
|
||||
#include "llvm/CodeGen/ScheduleDAG.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
@ -22,8 +23,8 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
PostRAHazardRecognizer::
|
||||
PostRAHazardRecognizer(const InstrItineraryData *LItinData) :
|
||||
ScoreboardHazardRecognizer::
|
||||
ScoreboardHazardRecognizer(const InstrItineraryData *LItinData) :
|
||||
ScheduleHazardRecognizer(), ItinData(LItinData) {
|
||||
// Determine the maximum depth of any itinerary. This determines the
|
||||
// depth of the scoreboard. We always make the scoreboard at least 1
|
||||
@ -40,23 +41,26 @@ PostRAHazardRecognizer(const InstrItineraryData *LItinData) :
|
||||
for (; IS != E; ++IS)
|
||||
ItinDepth += IS->getCycles();
|
||||
|
||||
ScoreboardDepth = std::max(ScoreboardDepth, ItinDepth);
|
||||
// Find the next power-of-2 >= ItinDepth
|
||||
while (ItinDepth > ScoreboardDepth) {
|
||||
ScoreboardDepth *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReservedScoreboard.reset(ScoreboardDepth);
|
||||
RequiredScoreboard.reset(ScoreboardDepth);
|
||||
|
||||
DEBUG(dbgs() << "Using post-ra hazard recognizer: ScoreboardDepth = "
|
||||
DEBUG(dbgs() << "Using scoreboard hazard recognizer: Depth = "
|
||||
<< ScoreboardDepth << '\n');
|
||||
}
|
||||
|
||||
void PostRAHazardRecognizer::Reset() {
|
||||
void ScoreboardHazardRecognizer::Reset() {
|
||||
RequiredScoreboard.reset();
|
||||
ReservedScoreboard.reset();
|
||||
}
|
||||
|
||||
void PostRAHazardRecognizer::ScoreBoard::dump() const {
|
||||
void ScoreboardHazardRecognizer::Scoreboard::dump() const {
|
||||
dbgs() << "Scoreboard:\n";
|
||||
|
||||
unsigned last = Depth - 1;
|
||||
@ -73,7 +77,7 @@ void PostRAHazardRecognizer::ScoreBoard::dump() const {
|
||||
}
|
||||
|
||||
ScheduleHazardRecognizer::HazardType
|
||||
PostRAHazardRecognizer::getHazardType(SUnit *SU) {
|
||||
ScoreboardHazardRecognizer::getHazardType(SUnit *SU) {
|
||||
if (!ItinData || ItinData->isEmpty())
|
||||
return NoHazard;
|
||||
|
||||
@ -120,7 +124,7 @@ PostRAHazardRecognizer::getHazardType(SUnit *SU) {
|
||||
return NoHazard;
|
||||
}
|
||||
|
||||
void PostRAHazardRecognizer::EmitInstruction(SUnit *SU) {
|
||||
void ScoreboardHazardRecognizer::EmitInstruction(SUnit *SU) {
|
||||
if (!ItinData || ItinData->isEmpty())
|
||||
return;
|
||||
|
||||
@ -174,7 +178,14 @@ void PostRAHazardRecognizer::EmitInstruction(SUnit *SU) {
|
||||
DEBUG(RequiredScoreboard.dump());
|
||||
}
|
||||
|
||||
void PostRAHazardRecognizer::AdvanceCycle() {
|
||||
void ScoreboardHazardRecognizer::AdvanceCycle() {
|
||||
ReservedScoreboard[0] = 0; ReservedScoreboard.advance();
|
||||
RequiredScoreboard[0] = 0; RequiredScoreboard.advance();
|
||||
}
|
||||
|
||||
void ScoreboardHazardRecognizer::RecedeCycle() {
|
||||
ReservedScoreboard[ReservedScoreboard.getDepth()-1] = 0;
|
||||
ReservedScoreboard.recede();
|
||||
RequiredScoreboard[RequiredScoreboard.getDepth()-1] = 0;
|
||||
RequiredScoreboard.recede();
|
||||
}
|
@ -22,7 +22,7 @@
|
||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||
#include "llvm/CodeGen/MachineMemOperand.h"
|
||||
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
||||
#include "llvm/CodeGen/PostRAHazardRecognizer.h"
|
||||
#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
|
||||
#include "llvm/CodeGen/PseudoSourceValue.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
@ -135,7 +135,7 @@ bool TargetInstrInfoImpl::PredicateInstruction(MachineInstr *MI,
|
||||
const TargetInstrDesc &TID = MI->getDesc();
|
||||
if (!TID.isPredicable())
|
||||
return false;
|
||||
|
||||
|
||||
for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
||||
if (TID.OpInfo[i].isPredicate()) {
|
||||
MachineOperand &MO = MI->getOperand(i);
|
||||
@ -417,5 +417,5 @@ bool TargetInstrInfoImpl::isSchedulingBoundary(const MachineInstr *MI,
|
||||
// Default implementation of CreateTargetPostRAHazardRecognizer.
|
||||
ScheduleHazardRecognizer *TargetInstrInfoImpl::
|
||||
CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II) const {
|
||||
return (ScheduleHazardRecognizer *)new PostRAHazardRecognizer(II);
|
||||
return (ScheduleHazardRecognizer *)new ScoreboardHazardRecognizer(II);
|
||||
}
|
||||
|
@ -68,14 +68,14 @@ ARMHazardRecognizer::getHazardType(SUnit *SU) {
|
||||
}
|
||||
}
|
||||
|
||||
return PostRAHazardRecognizer::getHazardType(SU);
|
||||
return ScoreboardHazardRecognizer::getHazardType(SU);
|
||||
}
|
||||
|
||||
void ARMHazardRecognizer::Reset() {
|
||||
LastMI = 0;
|
||||
Stalls = 0;
|
||||
ITBlockSize = 0;
|
||||
PostRAHazardRecognizer::Reset();
|
||||
ScoreboardHazardRecognizer::Reset();
|
||||
}
|
||||
|
||||
void ARMHazardRecognizer::EmitInstruction(SUnit *SU) {
|
||||
@ -103,12 +103,16 @@ void ARMHazardRecognizer::EmitInstruction(SUnit *SU) {
|
||||
Stalls = 0;
|
||||
}
|
||||
|
||||
PostRAHazardRecognizer::EmitInstruction(SU);
|
||||
ScoreboardHazardRecognizer::EmitInstruction(SU);
|
||||
}
|
||||
|
||||
void ARMHazardRecognizer::AdvanceCycle() {
|
||||
if (Stalls && --Stalls == 0)
|
||||
// Stalled for 4 cycles but still can't schedule any other instructions.
|
||||
LastMI = 0;
|
||||
PostRAHazardRecognizer::AdvanceCycle();
|
||||
ScoreboardHazardRecognizer::AdvanceCycle();
|
||||
}
|
||||
|
||||
void ARMHazardRecognizer::RecedeCycle() {
|
||||
llvm_unreachable("reverse ARM hazard checking unsupported");
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
#ifndef ARMHAZARDRECOGNIZER_H
|
||||
#define ARMHAZARDRECOGNIZER_H
|
||||
|
||||
#include "llvm/CodeGen/PostRAHazardRecognizer.h"
|
||||
#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -23,7 +23,7 @@ class ARMBaseRegisterInfo;
|
||||
class ARMSubtarget;
|
||||
class MachineInstr;
|
||||
|
||||
class ARMHazardRecognizer : public PostRAHazardRecognizer {
|
||||
class ARMHazardRecognizer : public ScoreboardHazardRecognizer {
|
||||
const ARMBaseInstrInfo &TII;
|
||||
const ARMBaseRegisterInfo &TRI;
|
||||
const ARMSubtarget &STI;
|
||||
@ -38,16 +38,16 @@ public:
|
||||
const ARMBaseInstrInfo &tii,
|
||||
const ARMBaseRegisterInfo &tri,
|
||||
const ARMSubtarget &sti) :
|
||||
PostRAHazardRecognizer(ItinData), TII(tii), TRI(tri), STI(sti),
|
||||
ScoreboardHazardRecognizer(ItinData), TII(tii), TRI(tri), STI(sti),
|
||||
LastMI(0), ITBlockSize(0) {}
|
||||
|
||||
virtual HazardType getHazardType(SUnit *SU);
|
||||
virtual void Reset();
|
||||
virtual void EmitInstruction(SUnit *SU);
|
||||
virtual void AdvanceCycle();
|
||||
virtual void RecedeCycle();
|
||||
};
|
||||
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // ARMHAZARDRECOGNIZER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user