[PATCH] D115129: [GlobalISel] Add hasPostISelHook handling.
Abinav Puthan Purayil via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 5 20:10:53 PST 2021
abinavpp created this revision.
abinavpp added reviewers: ab, aemerson, arsenm, foad, paquette, qcolombet, rampitec.
Herald added subscribers: hiraditya, rovka.
abinavpp requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
SelectionDAG handles MachineInstr's MCID::hasPostISelHook using
TargetLowering::AdjustInstrPostInstrSelection() which depends on SDNode.
This change adds the global-isel version in TargetLoweringBase.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115129
Files:
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
Index: llvm/lib/CodeGen/TargetLoweringBase.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2361,3 +2361,9 @@
}
}
}
+
+bool TargetLoweringBase::adjustInstrPostGISel(MachineInstr &MI) const {
+ // TODO: Add assertion for MI.hasPostISelHook() once every global-isel target
+ // overrides this function.
+ return false;
+}
Index: llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
+++ llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
@@ -133,6 +133,9 @@
// Keep track of selected blocks, so we can delete unreachable ones later.
DenseSet<MachineBasicBlock *> SelectedBlocks;
+ // List of newly added MachineInstrs during selection.
+ SmallVector<MachineInstr *, 8> InsertedMIs;
+
for (MachineBasicBlock *MBB : post_order(&MF)) {
ISel->CurMBB = MBB;
SelectedBlocks.insert(MBB);
@@ -144,10 +147,8 @@
bool ReachedBegin = false;
for (auto MII = std::prev(MBB->end()), Begin = MBB->begin();
!ReachedBegin;) {
-#ifndef NDEBUG
- // Keep track of the insertion range for debug printing.
+
const auto AfterIt = std::next(MII);
-#endif
// Select this instruction.
MachineInstr &MI = *MII;
@@ -193,14 +194,13 @@
return false;
}
- // Dump the range of instructions that MI expanded into.
- LLVM_DEBUG({
- auto InsertedBegin = ReachedBegin ? MBB->begin() : std::next(MII);
- dbgs() << "Into:\n";
- for (auto &InsertedMI : make_range(InsertedBegin, AfterIt))
- dbgs() << " " << InsertedMI;
- dbgs() << '\n';
- });
+ auto InsertedBegin = ReachedBegin ? MBB->begin() : std::next(MII);
+ LLVM_DEBUG(dbgs() << "Into:\n");
+ for (auto &InsertedMI : make_range(InsertedBegin, AfterIt)) {
+ InsertedMIs.push_back(&InsertedMI);
+ LLVM_DEBUG(dbgs() << " " << InsertedMI);
+ }
+ LLVM_DEBUG(dbgs() << '\n');
}
}
@@ -304,6 +304,16 @@
auto &TLI = *MF.getSubtarget().getTargetLowering();
TLI.finalizeLowering(MF);
+ for (MachineInstr *MI : InsertedMIs) {
+ if (MI->hasPostISelHook()) {
+ LLVM_DEBUG(dbgs() << "hasPostISelHook handling of:\n " << *MI);
+ bool Modified = TLI.adjustInstrPostGISel(*MI);
+ (void)Modified;
+ LLVM_DEBUG(if (Modified) dbgs() << "Modified To:\n " << *MI;
+ else dbgs() << "Didn't modify\n";);
+ }
+ }
+
LLVM_DEBUG({
dbgs() << "Rules covered by selecting function: " << MF.getName() << ":";
for (auto RuleID : CoverageInfo.covered())
Index: llvm/include/llvm/CodeGen/TargetLowering.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLowering.h
+++ llvm/include/llvm/CodeGen/TargetLowering.h
@@ -2959,6 +2959,9 @@
/// Check whether or not \p MI needs to be moved close to its uses.
virtual bool shouldLocalize(const MachineInstr &MI, const TargetTransformInfo *TTI) const;
+ /// GlobalISel version of TargetLowering::AdjustInstrPostInstrSelection.
+ /// Returns true if the MIR was modified.
+ virtual bool adjustInstrPostGISel(MachineInstr &MI) const;
private:
const TargetMachine &TM;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115129.391956.patch
Type: text/x-patch
Size: 3359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211206/3bcaefd8/attachment.bin>
More information about the llvm-commits
mailing list