Skip to content

Commit 208e4fe

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd24aabc1b5cf' from apple/main into swift/next
2 parents 6f22687 + d24aabc commit 208e4fe

15 files changed

+146
-356
lines changed

llvm/include/llvm/CodeGen/ScheduleHazardRecognizer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ class ScheduleHazardRecognizer {
114114
// Default implementation: count it as a cycle.
115115
AdvanceCycle();
116116
}
117+
118+
/// EmitNoops - This callback is invoked when noops were added to the
119+
/// instruction stream.
120+
virtual void EmitNoops(unsigned Quantity) {
121+
// Default implementation: count it as a cycle.
122+
for (unsigned i = 0; i < Quantity; ++i)
123+
EmitNoop();
124+
}
117125
};
118126

119127
} // end namespace llvm

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,11 @@ class TargetInstrInfo : public MCInstrInfo {
13431343
virtual void insertNoop(MachineBasicBlock &MBB,
13441344
MachineBasicBlock::iterator MI) const;
13451345

1346+
/// Insert noops into the instruction stream at the specified point.
1347+
virtual void insertNoops(MachineBasicBlock &MBB,
1348+
MachineBasicBlock::iterator MI,
1349+
unsigned Quantity) const;
1350+
13461351
/// Return the noop instruction to use for a noop.
13471352
virtual void getNoop(MCInst &NopInst) const;
13481353

llvm/lib/CodeGen/PostRAHazardRecognizer.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ bool PostRAHazardRecognizer::runOnMachineFunction(MachineFunction &Fn) {
8282
for (MachineInstr &MI : MBB) {
8383
// If we need to emit noops prior to this instruction, then do so.
8484
unsigned NumPreNoops = HazardRec->PreEmitNoops(&MI);
85-
for (unsigned i = 0; i != NumPreNoops; ++i) {
86-
HazardRec->EmitNoop();
87-
TII->insertNoop(MBB, MachineBasicBlock::iterator(MI));
88-
++NumNoops;
89-
}
85+
HazardRec->EmitNoops(NumPreNoops);
86+
TII->insertNoops(MBB, MachineBasicBlock::iterator(MI), NumPreNoops);
87+
NumNoops += NumPreNoops;
9088

9189
HazardRec->EmitInstruction(&MI);
9290
if (HazardRec->atIssueLimit()) {

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
6969
llvm_unreachable("Target didn't implement insertNoop!");
7070
}
7171

72+
/// insertNoops - Insert noops into the instruction stream at the specified
73+
/// point.
74+
void TargetInstrInfo::insertNoops(MachineBasicBlock &MBB,
75+
MachineBasicBlock::iterator MI,
76+
unsigned Quantity) const {
77+
for (unsigned i = 0; i < Quantity; ++i)
78+
insertNoop(MBB, MI);
79+
}
80+
7281
static bool isAsmComment(const char *Str, const MCAsmInfo &MAI) {
7382
return strncmp(Str, MAI.getCommentString().data(),
7483
MAI.getCommentString().size()) == 0;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,6 @@ void GCNPassConfig::addPreEmitPass() {
10471047
//
10481048
// Here we add a stand-alone hazard recognizer pass which can handle all
10491049
// cases.
1050-
//
1051-
// FIXME: This stand-alone pass will emit indiv. S_NOP 0, as needed. It would
1052-
// be better for it to emit S_NOP <N> when possible.
10531050
addPass(&PostRAHazardRecognizerID);
10541051
addPass(&BranchRelaxationPassID);
10551052
}

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,27 +1533,26 @@ void SIInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
15331533
.addMemOperand(MMO);
15341534
}
15351535

1536-
void SIInstrInfo::insertWaitStates(MachineBasicBlock &MBB,
1537-
MachineBasicBlock::iterator MI,
1538-
int Count) const {
1536+
void SIInstrInfo::insertNoop(MachineBasicBlock &MBB,
1537+
MachineBasicBlock::iterator MI) const {
1538+
insertNoops(MBB, MI, 1);
1539+
}
1540+
1541+
void SIInstrInfo::insertNoops(MachineBasicBlock &MBB,
1542+
MachineBasicBlock::iterator MI,
1543+
unsigned Quantity) const {
15391544
DebugLoc DL = MBB.findDebugLoc(MI);
1540-
while (Count > 0) {
1541-
int Arg;
1542-
if (Count >= 8)
1545+
while (Quantity > 0) {
1546+
unsigned Arg;
1547+
if (Quantity >= 8)
15431548
Arg = 7;
15441549
else
1545-
Arg = Count - 1;
1546-
Count -= 8;
1547-
BuildMI(MBB, MI, DL, get(AMDGPU::S_NOP))
1548-
.addImm(Arg);
1550+
Arg = Quantity - 1;
1551+
Quantity -= Arg + 1;
1552+
BuildMI(MBB, MI, DL, get(AMDGPU::S_NOP)).addImm(Arg);
15491553
}
15501554
}
15511555

1552-
void SIInstrInfo::insertNoop(MachineBasicBlock &MBB,
1553-
MachineBasicBlock::iterator MI) const {
1554-
insertWaitStates(MBB, MI, 1);
1555-
}
1556-
15571556
void SIInstrInfo::insertReturn(MachineBasicBlock &MBB) const {
15581557
auto MF = MBB.getParent();
15591558
SIMachineFunctionInfo *Info = MF->getInfo<SIMachineFunctionInfo>();

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,12 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
898898
/// VALU if necessary. If present, \p MDT is updated.
899899
void moveToVALU(MachineInstr &MI, MachineDominatorTree *MDT = nullptr) const;
900900

901-
void insertWaitStates(MachineBasicBlock &MBB,MachineBasicBlock::iterator MI,
902-
int Count) const;
903-
904901
void insertNoop(MachineBasicBlock &MBB,
905902
MachineBasicBlock::iterator MI) const override;
906903

904+
void insertNoops(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
905+
unsigned Quantity) const override;
906+
907907
void insertReturn(MachineBasicBlock &MBB) const;
908908
/// Return the number of wait states that result from executing this
909909
/// instruction.

0 commit comments

Comments
 (0)