2006-03-07 06:32:48 +00:00
|
|
|
//===-- PPCHazardRecognizers.cpp - PowerPC Hazard Recognizer Impls --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-03-07 06:32:48 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements hazard recognizers for scheduling on PowerPC processors.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-07-13 17:13:54 +00:00
|
|
|
#define DEBUG_TYPE "pre-RA-sched"
|
2006-03-07 06:32:48 +00:00
|
|
|
#include "PPCHazardRecognizers.h"
|
|
|
|
#include "PPC.h"
|
2006-03-12 09:13:49 +00:00
|
|
|
#include "PPCInstrInfo.h"
|
2009-01-15 22:18:12 +00:00
|
|
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
2006-03-07 06:32:48 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 06:49:22 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-03-07 06:32:48 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-03-31 14:45:15 +00:00
|
|
|
// PowerPC Scoreboard Hazard Recognizer
|
|
|
|
void PPCScoreboardHazardRecognizer::EmitInstruction(SUnit *SU) {
|
2011-10-17 04:03:49 +00:00
|
|
|
const MCInstrDesc *MCID = DAG->getInstrDesc(SU);
|
2012-03-31 14:45:15 +00:00
|
|
|
if (!MCID)
|
2011-10-17 04:03:49 +00:00
|
|
|
// This is a PPC pseudo-instruction.
|
|
|
|
return;
|
|
|
|
|
|
|
|
ScoreboardHazardRecognizer::EmitInstruction(SU);
|
|
|
|
}
|
|
|
|
|
2012-03-31 14:45:15 +00:00
|
|
|
ScheduleHazardRecognizer::HazardType
|
|
|
|
PPCScoreboardHazardRecognizer::getHazardType(SUnit *SU, int Stalls) {
|
|
|
|
return ScoreboardHazardRecognizer::getHazardType(SU, Stalls);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PPCScoreboardHazardRecognizer::AdvanceCycle() {
|
|
|
|
ScoreboardHazardRecognizer::AdvanceCycle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PPCScoreboardHazardRecognizer::Reset() {
|
|
|
|
ScoreboardHazardRecognizer::Reset();
|
|
|
|
}
|
|
|
|
|
2011-10-17 04:03:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-03-07 06:32:48 +00:00
|
|
|
// PowerPC 970 Hazard Recognizer
|
|
|
|
//
|
2006-03-07 06:44:19 +00:00
|
|
|
// This models the dispatch group formation of the PPC970 processor. Dispatch
|
2006-03-12 09:13:49 +00:00
|
|
|
// groups are bundles of up to five instructions that can contain various mixes
|
2010-12-24 04:28:06 +00:00
|
|
|
// of instructions. The PPC970 can dispatch a peak of 4 non-branch and one
|
2006-03-12 09:13:49 +00:00
|
|
|
// branch instruction per-cycle.
|
2006-03-07 06:44:19 +00:00
|
|
|
//
|
2006-03-12 09:13:49 +00:00
|
|
|
// There are a number of restrictions to dispatch group formation: some
|
|
|
|
// instructions can only be issued in the first slot of a dispatch group, & some
|
|
|
|
// instructions fill an entire dispatch group. Additionally, only branches can
|
|
|
|
// issue in the 5th (last) slot.
|
2006-03-07 06:44:19 +00:00
|
|
|
//
|
|
|
|
// Finally, there are a number of "structural" hazards on the PPC970. These
|
|
|
|
// conditions cause large performance penalties due to misprediction, recovery,
|
|
|
|
// and replay logic that has to happen. These cases include setting a CTR and
|
|
|
|
// branching through it in the same dispatch group, and storing to an address,
|
|
|
|
// then loading from the same address within a dispatch group. To avoid these
|
|
|
|
// conditions, we insert no-op instructions when appropriate.
|
|
|
|
//
|
2006-03-07 06:32:48 +00:00
|
|
|
// FIXME: This is missing some significant cases:
|
|
|
|
// 1. Modeling of microcoded instructions.
|
2006-03-13 05:20:04 +00:00
|
|
|
// 2. Handling of serialized operations.
|
|
|
|
// 3. Handling of the esoteric cases in "Resource-based Instruction Grouping".
|
2006-03-07 06:32:48 +00:00
|
|
|
//
|
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
PPCHazardRecognizer970::PPCHazardRecognizer970(const TargetInstrInfo &tii)
|
|
|
|
: TII(tii) {
|
2006-03-08 04:25:59 +00:00
|
|
|
EndDispatchGroup();
|
|
|
|
}
|
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
void PPCHazardRecognizer970::EndDispatchGroup() {
|
2009-08-23 06:49:22 +00:00
|
|
|
DEBUG(errs() << "=== Start of dispatch group\n");
|
2006-03-07 06:32:48 +00:00
|
|
|
NumIssued = 0;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
// Structural hazard info.
|
|
|
|
HasCTRSet = false;
|
2006-03-12 09:13:49 +00:00
|
|
|
NumStores = 0;
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-24 04:28:06 +00:00
|
|
|
PPCII::PPC970_Unit
|
2006-03-12 09:13:49 +00:00
|
|
|
PPCHazardRecognizer970::GetInstrType(unsigned Opcode,
|
|
|
|
bool &isFirst, bool &isSingle,
|
2006-03-13 05:20:04 +00:00
|
|
|
bool &isCracked,
|
|
|
|
bool &isLoad, bool &isStore) {
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID = TII.get(Opcode);
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
isLoad = MCID.mayLoad();
|
|
|
|
isStore = MCID.mayStore();
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
uint64_t TSFlags = MCID.TSFlags;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-13 05:20:04 +00:00
|
|
|
isFirst = TSFlags & PPCII::PPC970_First;
|
|
|
|
isSingle = TSFlags & PPCII::PPC970_Single;
|
|
|
|
isCracked = TSFlags & PPCII::PPC970_Cracked;
|
2006-03-12 09:13:49 +00:00
|
|
|
return (PPCII::PPC970_Unit)(TSFlags & PPCII::PPC970_Mask);
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isLoadOfStoredAddress - If we have a load from the previously stored pointer
|
|
|
|
/// as indicated by StorePtr1/StorePtr2/StoreSize, return true.
|
|
|
|
bool PPCHazardRecognizer970::
|
2011-12-02 04:58:02 +00:00
|
|
|
isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset,
|
|
|
|
const Value *LoadValue) const {
|
2006-03-12 09:13:49 +00:00
|
|
|
for (unsigned i = 0, e = NumStores; i != e; ++i) {
|
|
|
|
// Handle exact and commuted addresses.
|
2011-12-02 04:58:02 +00:00
|
|
|
if (LoadValue == StoreValue[i] && LoadOffset == StoreOffset[i])
|
2006-03-12 09:13:49 +00:00
|
|
|
return true;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
// Okay, we don't have an exact match, if this is an indexed offset, see if
|
|
|
|
// we have overlap (which happens during fp->int conversion for example).
|
2011-12-02 04:58:02 +00:00
|
|
|
if (StoreValue[i] == LoadValue) {
|
|
|
|
// Okay the base pointers match, so we have [c1+r] vs [c2+r]. Check
|
|
|
|
// to see if the load and store actually overlap.
|
|
|
|
if (StoreOffset[i] < LoadOffset) {
|
|
|
|
if (int64_t(StoreOffset[i]+StoreSize[i]) > LoadOffset) return true;
|
|
|
|
} else {
|
|
|
|
if (int64_t(LoadOffset+LoadSize) > StoreOffset[i]) return true;
|
|
|
|
}
|
2006-03-12 09:13:49 +00:00
|
|
|
}
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getHazardType - We return hazard for any non-branch instruction that would
|
2010-02-10 16:03:48 +00:00
|
|
|
/// terminate the dispatch group. We turn NoopHazard for any
|
2006-03-07 06:32:48 +00:00
|
|
|
/// instructions that wouldn't terminate the dispatch group that would cause a
|
|
|
|
/// pipeline flush.
|
2009-01-15 22:18:12 +00:00
|
|
|
ScheduleHazardRecognizer::HazardType PPCHazardRecognizer970::
|
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122541 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-24 05:03:26 +00:00
|
|
|
getHazardType(SUnit *SU, int Stalls) {
|
|
|
|
assert(Stalls == 0 && "PPC hazards don't support scoreboard lookahead");
|
|
|
|
|
2011-12-02 04:58:02 +00:00
|
|
|
MachineInstr *MI = SU->getInstr();
|
|
|
|
|
|
|
|
if (MI->isDebugValue())
|
|
|
|
return NoHazard;
|
|
|
|
|
|
|
|
unsigned Opcode = MI->getOpcode();
|
2006-03-13 05:20:04 +00:00
|
|
|
bool isFirst, isSingle, isCracked, isLoad, isStore;
|
2010-12-24 04:28:06 +00:00
|
|
|
PPCII::PPC970_Unit InstrType =
|
2011-12-02 04:58:02 +00:00
|
|
|
GetInstrType(Opcode, isFirst, isSingle, isCracked,
|
2006-03-13 05:20:04 +00:00
|
|
|
isLoad, isStore);
|
2010-12-24 04:28:06 +00:00
|
|
|
if (InstrType == PPCII::PPC970_Pseudo) return NoHazard;
|
2006-03-07 06:32:48 +00:00
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
// We can only issue a PPC970_First/PPC970_Single instruction (such as
|
|
|
|
// crand/mtspr/etc) if this is the first cycle of the dispatch group.
|
2006-03-13 05:20:04 +00:00
|
|
|
if (NumIssued != 0 && (isFirst || isSingle))
|
2006-03-12 09:13:49 +00:00
|
|
|
return Hazard;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-13 05:20:04 +00:00
|
|
|
// If this instruction is cracked into two ops by the decoder, we know that
|
|
|
|
// it is not a branch and that it cannot issue if 3 other instructions are
|
|
|
|
// already in the dispatch group.
|
|
|
|
if (isCracked && NumIssued > 2)
|
|
|
|
return Hazard;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
switch (InstrType) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Unknown instruction type!");
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPCII::PPC970_FXU:
|
|
|
|
case PPCII::PPC970_LSU:
|
|
|
|
case PPCII::PPC970_FPU:
|
|
|
|
case PPCII::PPC970_VALU:
|
|
|
|
case PPCII::PPC970_VPERM:
|
|
|
|
// We can only issue a branch as the last instruction in a group.
|
|
|
|
if (NumIssued == 4) return Hazard;
|
|
|
|
break;
|
|
|
|
case PPCII::PPC970_CRU:
|
|
|
|
// We can only issue a CR instruction in the first two slots.
|
|
|
|
if (NumIssued >= 2) return Hazard;
|
|
|
|
break;
|
|
|
|
case PPCII::PPC970_BRU:
|
|
|
|
break;
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
// Do not allow MTCTR and BCTRL to be in the same dispatch group.
|
2009-07-03 06:47:08 +00:00
|
|
|
if (HasCTRSet && (Opcode == PPC::BCTRL_Darwin || Opcode == PPC::BCTRL_SVR4))
|
2006-03-07 06:32:48 +00:00
|
|
|
return NoopHazard;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
// If this is a load following a store, make sure it's not to the same or
|
|
|
|
// overlapping address.
|
2011-12-02 04:58:02 +00:00
|
|
|
if (isLoad && NumStores && !MI->memoperands_empty()) {
|
|
|
|
MachineMemOperand *MO = *MI->memoperands_begin();
|
|
|
|
if (isLoadOfStoredAddress(MO->getSize(),
|
|
|
|
MO->getOffset(), MO->getValue()))
|
2006-03-07 06:32:48 +00:00
|
|
|
return NoopHazard;
|
|
|
|
}
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
return NoHazard;
|
|
|
|
}
|
|
|
|
|
2009-01-15 22:18:12 +00:00
|
|
|
void PPCHazardRecognizer970::EmitInstruction(SUnit *SU) {
|
2011-12-02 04:58:02 +00:00
|
|
|
MachineInstr *MI = SU->getInstr();
|
|
|
|
|
|
|
|
if (MI->isDebugValue())
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned Opcode = MI->getOpcode();
|
2006-03-13 05:20:04 +00:00
|
|
|
bool isFirst, isSingle, isCracked, isLoad, isStore;
|
2010-12-24 04:28:06 +00:00
|
|
|
PPCII::PPC970_Unit InstrType =
|
2011-12-02 04:58:02 +00:00
|
|
|
GetInstrType(Opcode, isFirst, isSingle, isCracked,
|
2006-03-13 05:20:04 +00:00
|
|
|
isLoad, isStore);
|
2010-12-24 04:28:06 +00:00
|
|
|
if (InstrType == PPCII::PPC970_Pseudo) return;
|
2006-03-07 06:32:48 +00:00
|
|
|
|
|
|
|
// Update structural hazard information.
|
2011-06-03 15:47:49 +00:00
|
|
|
if (Opcode == PPC::MTCTR || Opcode == PPC::MTCTR8) HasCTRSet = true;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
// Track the address stored to.
|
2011-12-02 04:58:02 +00:00
|
|
|
if (isStore && NumStores < 4 && !MI->memoperands_empty()) {
|
|
|
|
MachineMemOperand *MO = *MI->memoperands_begin();
|
|
|
|
StoreSize[NumStores] = MO->getSize();
|
|
|
|
StoreOffset[NumStores] = MO->getOffset();
|
|
|
|
StoreValue[NumStores] = MO->getValue();
|
2006-03-12 09:13:49 +00:00
|
|
|
++NumStores;
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
if (InstrType == PPCII::PPC970_BRU || isSingle)
|
|
|
|
NumIssued = 4; // Terminate a d-group.
|
2006-03-07 06:32:48 +00:00
|
|
|
++NumIssued;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-13 05:20:04 +00:00
|
|
|
// If this instruction is cracked into two ops by the decoder, remember that
|
|
|
|
// we issued two pieces.
|
|
|
|
if (isCracked)
|
|
|
|
++NumIssued;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
if (NumIssued == 5)
|
|
|
|
EndDispatchGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PPCHazardRecognizer970::AdvanceCycle() {
|
|
|
|
assert(NumIssued < 5 && "Illegal dispatch group!");
|
|
|
|
++NumIssued;
|
|
|
|
if (NumIssued == 5)
|
|
|
|
EndDispatchGroup();
|
|
|
|
}
|
2011-12-02 04:58:02 +00:00
|
|
|
|
|
|
|
void PPCHazardRecognizer970::Reset() {
|
|
|
|
EndDispatchGroup();
|
|
|
|
}
|
|
|
|
|