2006-03-07 06:32:48 +00:00
|
|
|
//===-- PPCHazardRecognizers.cpp - PowerPC Hazard Recognizer Impls --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements hazard recognizers for scheduling on PowerPC processors.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "sched"
|
|
|
|
#include "PPCHazardRecognizers.h"
|
|
|
|
#include "PPC.h"
|
2006-03-12 09:13:49 +00:00
|
|
|
#include "PPCInstrInfo.h"
|
2006-03-07 06:32:48 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include <iostream>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// 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
|
|
|
|
// of instructions. The PPC970 can dispatch a peak of 4 non-branch and one
|
|
|
|
// 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() {
|
|
|
|
DEBUG(std::cerr << "=== Start of dispatch group\n");
|
|
|
|
NumIssued = 0;
|
|
|
|
|
|
|
|
// Structural hazard info.
|
|
|
|
HasCTRSet = false;
|
2006-03-12 09:13:49 +00:00
|
|
|
NumStores = 0;
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
PPCII::PPC970_Unit
|
|
|
|
PPCHazardRecognizer970::GetInstrType(unsigned Opcode,
|
|
|
|
bool &isFirst, bool &isSingle,
|
2006-03-13 05:20:04 +00:00
|
|
|
bool &isCracked,
|
|
|
|
bool &isLoad, bool &isStore) {
|
2006-03-12 09:13:49 +00:00
|
|
|
if (Opcode < ISD::BUILTIN_OP_END) {
|
2006-03-13 05:20:04 +00:00
|
|
|
isFirst = isSingle = isCracked = isLoad = isStore = false;
|
2006-03-12 09:13:49 +00:00
|
|
|
return PPCII::PPC970_Pseudo;
|
|
|
|
}
|
2006-03-07 06:32:48 +00:00
|
|
|
Opcode -= ISD::BUILTIN_OP_END;
|
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
const TargetInstrDescriptor &TID = TII.get(Opcode);
|
|
|
|
|
|
|
|
isLoad = TID.Flags & M_LOAD_FLAG;
|
|
|
|
isStore = TID.Flags & M_STORE_FLAG;
|
2006-03-07 06:32:48 +00:00
|
|
|
|
2006-03-12 09:13:49 +00:00
|
|
|
unsigned TSFlags = TID.TSFlags;
|
|
|
|
|
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::
|
|
|
|
isLoadOfStoredAddress(unsigned LoadSize, SDOperand Ptr1, SDOperand Ptr2) const {
|
2006-03-12 09:13:49 +00:00
|
|
|
for (unsigned i = 0, e = NumStores; i != e; ++i) {
|
|
|
|
// Handle exact and commuted addresses.
|
|
|
|
if (Ptr1 == StorePtr1[i] && Ptr2 == StorePtr2[i])
|
|
|
|
return true;
|
|
|
|
if (Ptr2 == StorePtr1[i] && Ptr1 == StorePtr2[i])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
if (StorePtr2[i] == Ptr2) {
|
|
|
|
if (ConstantSDNode *StoreOffset = dyn_cast<ConstantSDNode>(StorePtr1[i]))
|
|
|
|
if (ConstantSDNode *LoadOffset = dyn_cast<ConstantSDNode>(Ptr1)) {
|
|
|
|
// Okay the base pointers match, so we have [c1+r] vs [c2+r]. Check
|
|
|
|
// to see if the load and store actually overlap.
|
|
|
|
int StoreOffs = StoreOffset->getValue();
|
|
|
|
int LoadOffs = LoadOffset->getValue();
|
|
|
|
if (StoreOffs < LoadOffs) {
|
2006-03-13 05:23:59 +00:00
|
|
|
if (int(StoreOffs+StoreSize[i]) > LoadOffs) return true;
|
2006-03-12 09:13:49 +00:00
|
|
|
} else {
|
|
|
|
if (int(LoadOffs+LoadSize) > StoreOffs) return true;
|
|
|
|
}
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
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
|
|
|
|
/// terminate terminate the dispatch group. We turn NoopHazard for any
|
|
|
|
/// instructions that wouldn't terminate the dispatch group that would cause a
|
|
|
|
/// pipeline flush.
|
|
|
|
HazardRecognizer::HazardType PPCHazardRecognizer970::
|
|
|
|
getHazardType(SDNode *Node) {
|
2006-03-13 05:20:04 +00:00
|
|
|
bool isFirst, isSingle, isCracked, isLoad, isStore;
|
2006-03-12 09:13:49 +00:00
|
|
|
PPCII::PPC970_Unit InstrType =
|
2006-03-13 05:20:04 +00:00
|
|
|
GetInstrType(Node->getOpcode(), isFirst, isSingle, isCracked,
|
|
|
|
isLoad, isStore);
|
2006-03-12 09:13:49 +00:00
|
|
|
if (InstrType == PPCII::PPC970_Pseudo) return NoHazard;
|
2006-03-07 06:32:48 +00:00
|
|
|
unsigned Opcode = Node->getOpcode()-ISD::BUILTIN_OP_END;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
switch (InstrType) {
|
|
|
|
default: assert(0 && "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
|
|
|
}
|
2006-03-13 05:20:04 +00:00
|
|
|
|
2006-03-07 06:32:48 +00:00
|
|
|
// Do not allow MTCTR and BCTRL to be in the same dispatch group.
|
|
|
|
if (HasCTRSet && Opcode == PPC::BCTRL)
|
|
|
|
return NoopHazard;
|
|
|
|
|
|
|
|
// If this is a load following a store, make sure it's not to the same or
|
|
|
|
// overlapping address.
|
2006-03-13 05:23:59 +00:00
|
|
|
if (isLoad && NumStores) {
|
2006-03-07 06:32:48 +00:00
|
|
|
unsigned LoadSize;
|
|
|
|
switch (Opcode) {
|
|
|
|
default: assert(0 && "Unknown load!");
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LBZ: case PPC::LBZU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LBZX:
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LBZ8: case PPC::LBZU8:
|
2006-07-14 04:42:02 +00:00
|
|
|
case PPC::LBZX8:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LVEBX:
|
|
|
|
LoadSize = 1;
|
|
|
|
break;
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LHA: case PPC::LHAU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LHAX:
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LHZ: case PPC::LHZU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LHZX:
|
|
|
|
case PPC::LVEHX:
|
2006-07-10 20:56:58 +00:00
|
|
|
case PPC::LHBRX:
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LHA8: case PPC::LHAU8:
|
2006-07-14 04:42:02 +00:00
|
|
|
case PPC::LHAX8:
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LHZ8: case PPC::LHZU8:
|
2006-07-14 04:42:02 +00:00
|
|
|
case PPC::LHZX8:
|
2006-03-12 09:13:49 +00:00
|
|
|
LoadSize = 2;
|
|
|
|
break;
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LFS: case PPC::LFSU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LFSX:
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LWZ: case PPC::LWZU:
|
2006-03-07 07:14:55 +00:00
|
|
|
case PPC::LWZX:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LWA:
|
|
|
|
case PPC::LWAX:
|
|
|
|
case PPC::LVEWX:
|
2006-07-10 20:56:58 +00:00
|
|
|
case PPC::LWBRX:
|
2006-07-14 04:42:02 +00:00
|
|
|
case PPC::LWZ8:
|
|
|
|
case PPC::LWZX8:
|
2006-03-12 09:13:49 +00:00
|
|
|
LoadSize = 4;
|
|
|
|
break;
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LFD: case PPC::LFDU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LFDX:
|
2006-11-13 20:11:06 +00:00
|
|
|
case PPC::LD: case PPC::LDU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::LDX:
|
|
|
|
LoadSize = 8;
|
|
|
|
break;
|
|
|
|
case PPC::LVX:
|
|
|
|
LoadSize = 16;
|
|
|
|
break;
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isLoadOfStoredAddress(LoadSize,
|
|
|
|
Node->getOperand(0), Node->getOperand(1)))
|
|
|
|
return NoopHazard;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NoHazard;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PPCHazardRecognizer970::EmitInstruction(SDNode *Node) {
|
2006-03-13 05:20:04 +00:00
|
|
|
bool isFirst, isSingle, isCracked, isLoad, isStore;
|
2006-03-12 09:13:49 +00:00
|
|
|
PPCII::PPC970_Unit InstrType =
|
2006-03-13 05:20:04 +00:00
|
|
|
GetInstrType(Node->getOpcode(), isFirst, isSingle, isCracked,
|
|
|
|
isLoad, isStore);
|
2006-03-12 09:13:49 +00:00
|
|
|
if (InstrType == PPCII::PPC970_Pseudo) return;
|
2006-03-07 06:32:48 +00:00
|
|
|
unsigned Opcode = Node->getOpcode()-ISD::BUILTIN_OP_END;
|
|
|
|
|
|
|
|
// Update structural hazard information.
|
|
|
|
if (Opcode == PPC::MTCTR) HasCTRSet = true;
|
|
|
|
|
|
|
|
// Track the address stored to.
|
2006-03-12 09:13:49 +00:00
|
|
|
if (isStore) {
|
|
|
|
unsigned ThisStoreSize;
|
2006-03-07 06:32:48 +00:00
|
|
|
switch (Opcode) {
|
|
|
|
default: assert(0 && "Unknown store instruction!");
|
2006-11-16 00:57:19 +00:00
|
|
|
case PPC::STB: case PPC::STB8:
|
|
|
|
case PPC::STBU: case PPC::STBU8:
|
|
|
|
case PPC::STBX: case PPC::STBX8:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::STVEBX:
|
|
|
|
ThisStoreSize = 1;
|
|
|
|
break;
|
2006-11-16 00:57:19 +00:00
|
|
|
case PPC::STH: case PPC::STH8:
|
|
|
|
case PPC::STHU: case PPC::STHU8:
|
|
|
|
case PPC::STHX: case PPC::STHX8:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::STVEHX:
|
2006-07-10 20:56:58 +00:00
|
|
|
case PPC::STHBRX:
|
2006-03-12 09:13:49 +00:00
|
|
|
ThisStoreSize = 2;
|
|
|
|
break;
|
2006-11-16 00:57:19 +00:00
|
|
|
case PPC::STFS:
|
|
|
|
case PPC::STFSU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::STFSX:
|
2006-11-16 00:57:19 +00:00
|
|
|
case PPC::STWX: case PPC::STWX8:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::STWUX:
|
2006-11-16 00:57:19 +00:00
|
|
|
case PPC::STW: case PPC::STW8:
|
|
|
|
case PPC::STWU: case PPC::STWU8:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::STVEWX:
|
|
|
|
case PPC::STFIWX:
|
2006-07-10 20:56:58 +00:00
|
|
|
case PPC::STWBRX:
|
2006-03-12 09:13:49 +00:00
|
|
|
ThisStoreSize = 4;
|
|
|
|
break;
|
When possible, custom lower 32-bit SINT_TO_FP to this:
_foo2:
extsw r2, r3
std r2, -8(r1)
lfd f0, -8(r1)
fcfid f0, f0
frsp f1, f0
blr
instead of this:
_foo2:
lis r2, ha16(LCPI2_0)
lis r4, 17200
xoris r3, r3, 32768
stw r3, -4(r1)
stw r4, -8(r1)
lfs f0, lo16(LCPI2_0)(r2)
lfd f1, -8(r1)
fsub f0, f1, f0
frsp f1, f0
blr
This speeds up Misc/pi from 2.44s->2.09s with LLC and from 3.01->2.18s
with llcbeta (16.7% and 38.1% respectively).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26943 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-22 05:30:33 +00:00
|
|
|
case PPC::STD_32:
|
|
|
|
case PPC::STDX_32:
|
2006-11-16 00:57:19 +00:00
|
|
|
case PPC::STD:
|
|
|
|
case PPC::STDU:
|
2006-03-12 09:13:49 +00:00
|
|
|
case PPC::STFD:
|
|
|
|
case PPC::STFDX:
|
|
|
|
case PPC::STDX:
|
|
|
|
case PPC::STDUX:
|
|
|
|
ThisStoreSize = 8;
|
|
|
|
break;
|
|
|
|
case PPC::STVX:
|
|
|
|
ThisStoreSize = 16;
|
|
|
|
break;
|
2006-03-07 06:32:48 +00:00
|
|
|
}
|
2006-03-12 09:13:49 +00:00
|
|
|
|
|
|
|
StoreSize[NumStores] = ThisStoreSize;
|
|
|
|
StorePtr1[NumStores] = Node->getOperand(1);
|
|
|
|
StorePtr2[NumStores] = Node->getOperand(2);
|
|
|
|
++NumStores;
|
2006-03-07 06:32:48 +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;
|
|
|
|
|
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;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PPCHazardRecognizer970::EmitNoop() {
|
|
|
|
AdvanceCycle();
|
|
|
|
}
|