Skip to content

Commit d041e80

Browse files
author
Tony Linthicum
committed
Review comments
1 parent f5c3045 commit d041e80

File tree

4 files changed

+455
-829
lines changed

4 files changed

+455
-829
lines changed

llvm/include/llvm/CodeGen/MachineInstrBuilder.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,6 @@ class MachineInstrBuilder {
380380
return *this;
381381
}
382382

383-
/// Inserts the newly-built instruction after the given position in the
384-
/// given MachineBasicBlock.
385-
const MachineInstrBuilder &insertAfter(MachineInstr *MInstr) const {
386-
MachineBasicBlock *MBB = MInstr->getParent();
387-
MachineBasicBlock::iterator I = MInstr->getIterator();
388-
MBB->insertAfter(I, MI);
389-
return *this;
390-
}
391-
392383
bool constrainAllUses(const TargetInstrInfo &TII,
393384
const TargetRegisterInfo &TRI,
394385
const RegisterBankInfo &RBI) const {

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,9 +2096,8 @@ int64_t RewriteScheduleStage::getRewriteCost(
20962096
? MBFI.getBlockFreq(DefMI->getParent()).getFrequency() / EntryFreq
20972097
: 1;
20982098

2099-
unsigned RegSize = DAG.TRI->getRegSizeInBits(*DAG.MRI.getRegClass(DefReg));
2100-
unsigned NumRegs = std::max(RegSize / 32, (unsigned)1);
2101-
CopyCost += NumRegs * DefFreq;
2099+
const TargetRegisterClass *RC = DAG.MRI.getRegClass(DefReg);
2100+
CopyCost += RC->getCopyCost() * DefFreq;
21022101
}
21032102

21042103
// Account for CopyForUse copies in each block that the register is used.
@@ -2107,18 +2106,16 @@ int64_t RewriteScheduleStage::getRewriteCost(
21072106
EntryFreq ? MBFI.getBlockFreq(UseBlock).getFrequency() / EntryFreq : 1;
21082107

21092108
for (Register UseReg : UseRegs) {
2110-
unsigned RegSize =
2111-
DAG.TRI->getRegSizeInBits(*DAG.MRI.getRegClass(UseReg));
2112-
unsigned NumRegs = std::max(RegSize / 32, (unsigned)1);
2113-
CopyCost += NumRegs * UseFreq;
2109+
const TargetRegisterClass *RC = DAG.MRI.getRegClass(UseReg);
2110+
CopyCost += RC->getCopyCost() * UseFreq;
21142111
}
21152112
}
21162113

21172114
Cost += CopyCost;
21182115

21192116
// Reset to the vgpr form. We must do rewriting after copy-insertion, as some
21202117
// defs of the register may require VGPR.
2121-
for (auto &[MI, OriginalOpcode] : RewriteCands) {
2118+
for (auto [MI, OriginalOpcode] : RewriteCands) {
21222119
assert(TII->isMAI(*MI));
21232120
const TargetRegisterClass *AGPRRC =
21242121
DAG.MRI.getRegClass(MI->getOperand(0).getReg());
@@ -2252,10 +2249,10 @@ bool RewriteScheduleStage::rewrite(
22522249
// Do not create redundant copies.
22532250
if (ReachingDefCopyMap[Src2Reg].insert(RD).second) {
22542251
MachineInstrBuilder VGPRCopy =
2255-
BuildMI(DAG.MF, RD->getDebugLoc(), TII->get(TargetOpcode::COPY))
2252+
BuildMI(*RD->getParent(), std::next(RD->getIterator()),
2253+
RD->getDebugLoc(), TII->get(TargetOpcode::COPY))
22562254
.addDef(MappedReg, 0, 0)
2257-
.addUse(Src2Reg, 0, 0)
2258-
.insertAfter(RD);
2255+
.addUse(Src2Reg, 0, 0);
22592256
DAG.LIS->InsertMachineInstrInMaps(*VGPRCopy);
22602257

22612258
// If this reaching def was the last MI in the region, update the
@@ -2335,10 +2332,10 @@ bool RewriteScheduleStage::rewrite(
23352332
// Do not create reundant copies.
23362333
if (ReachingDefCopyMap[DstReg].insert(RD).second) {
23372334
MachineInstrBuilder VGPRCopy =
2338-
BuildMI(DAG.MF, RD->getDebugLoc(), TII->get(TargetOpcode::COPY))
2335+
BuildMI(*RD->getParent(), std::next(RD->getIterator()),
2336+
RD->getDebugLoc(), TII->get(TargetOpcode::COPY))
23392337
.addDef(MappedReg, 0, 0)
2340-
.addUse(DstReg, 0, 0)
2341-
.insertAfter(RD);
2338+
.addUse(DstReg, 0, 0);
23422339
DAG.LIS->InsertMachineInstrInMaps(*VGPRCopy);
23432340

23442341
// If this reaching def was the last MI in the region, update the

0 commit comments

Comments
 (0)