summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/GlobalISel/Combiner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/Combiner.cpp')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/Combiner.cpp61
1 files changed, 44 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/Combiner.cpp b/llvm/lib/CodeGen/GlobalISel/Combiner.cpp
index a2f220aa3d4..90fd54ec244 100644
--- a/llvm/lib/CodeGen/GlobalISel/Combiner.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Combiner.cpp
@@ -1,4 +1,4 @@
-//===-- lib/CodeGen/GlobalISel/GICombiner.cpp -----------------------===//
+//===-- lib/CodeGen/GlobalISel/Combiner.cpp -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -29,36 +29,62 @@ using namespace llvm;
namespace {
/// This class acts as the glue the joins the CombinerHelper to the overall
/// Combine algorithm. The CombinerHelper is intended to report the
-/// modifications it makes to the MIR to the CombinerChangeObserver and the
+/// modifications it makes to the MIR to the GISelChangeObserver and the
/// observer subclass will act on these events. In this case, instruction
/// erasure will cancel any future visits to the erased instruction and
/// instruction creation will schedule that instruction for a future visit.
/// Other Combiner implementations may require more complex behaviour from
-/// their CombinerChangeObserver subclass.
-class WorkListMaintainer : public GISelChangeObserver {
+/// their GISelChangeObserver subclass.
+class WorkListMaintainer : public GISelChangeObserver,
+ public MachineFunction::Delegate {
using WorkListTy = GISelWorkList<512>;
+ MachineFunction &MF;
WorkListTy &WorkList;
+ /// The instructions that have been created but we want to report once they
+ /// have their operands. This is only maintained if debug output is requested.
+ SmallPtrSet<const MachineInstr *, 4> CreatedInstrs;
public:
- WorkListMaintainer(WorkListTy &WorkList) : WorkList(WorkList) {}
- virtual ~WorkListMaintainer() {}
+ WorkListMaintainer(MachineFunction &MF, WorkListTy &WorkList)
+ : GISelChangeObserver(), MF(MF), WorkList(WorkList) {
+ MF.setDelegate(this);
+ }
+ virtual ~WorkListMaintainer() {
+ MF.resetDelegate(this);
+ }
- void erasingInstr(MachineInstr &MI) override {
+ void erasingInstr(const MachineInstr &MI) override {
LLVM_DEBUG(dbgs() << "Erased: " << MI << "\n");
WorkList.remove(&MI);
}
- void createdInstr(MachineInstr &MI) override {
- LLVM_DEBUG(dbgs() << "Created: " << MI << "\n");
+ void createdInstr(const MachineInstr &MI) override {
+ LLVM_DEBUG(dbgs() << "Creating: " << MI << "\n");
WorkList.insert(&MI);
+ LLVM_DEBUG(CreatedInstrs.insert(&MI));
}
- void changingInstr(MachineInstr &MI) override {
+ void changingInstr(const MachineInstr &MI) override {
LLVM_DEBUG(dbgs() << "Changing: " << MI << "\n");
- WorkList.remove(&MI);
+ WorkList.insert(&MI);
}
- // Currently changed conservatively assumes erased.
- void changedInstr(MachineInstr &MI) override {
+ void changedInstr(const MachineInstr &MI) override {
LLVM_DEBUG(dbgs() << "Changed: " << MI << "\n");
- WorkList.remove(&MI);
+ WorkList.insert(&MI);
+ }
+
+ void reportFullyCreatedInstrs() {
+ LLVM_DEBUG(for (const auto *MI
+ : CreatedInstrs) {
+ dbgs() << "Created: ";
+ MI->print(dbgs());
+ });
+ LLVM_DEBUG(CreatedInstrs.clear());
+ }
+
+ void MF_HandleInsertion(const MachineInstr &MI) override {
+ createdInstr(MI);
+ }
+ void MF_HandleRemoval(const MachineInstr &MI) override {
+ erasingInstr(MI);
}
};
}
@@ -90,8 +116,8 @@ bool Combiner::combineMachineInstrs(MachineFunction &MF) {
// insert with list bottom up, so while we pop_back_val, we'll traverse top
// down RPOT.
Changed = false;
- GISelWorkList<512> WorkList;
- WorkListMaintainer Observer(WorkList);
+ GISelWorkList<512> WorkList(&MF);
+ WorkListMaintainer Observer(MF, WorkList);
for (MachineBasicBlock *MBB : post_order(&MF)) {
if (MBB->empty())
continue;
@@ -110,8 +136,9 @@ bool Combiner::combineMachineInstrs(MachineFunction &MF) {
// Main Loop. Process the instructions here.
while (!WorkList.empty()) {
MachineInstr *CurrInst = WorkList.pop_back_val();
- LLVM_DEBUG(dbgs() << "Try combining " << *CurrInst << "\n";);
+ LLVM_DEBUG(dbgs() << "\nTry combining " << *CurrInst;);
Changed |= CInfo.combine(Observer, *CurrInst, Builder);
+ Observer.reportFullyCreatedInstrs();
}
MFChanged |= Changed;
} while (Changed);
OpenPOWER on IntegriCloud