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