[llvm] r342696 - Add the ability to register callbacks for removal and insertion of MachineInstrs
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 20 16:01:57 PDT 2018
Author: aditya_nandakumar
Date: Thu Sep 20 16:01:56 2018
New Revision: 342696
URL: http://llvm.org/viewvc/llvm-project?rev=342696&view=rev
Log:
Add the ability to register callbacks for removal and insertion of MachineInstrs
https://reviews.llvm.org/D52127
This patch adds the ability to watch for insertions/deletions of
MachineInstructions similar to MachineRegisterInfo.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
llvm/trunk/lib/CodeGen/MachineFunction.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=342696&r1=342695&r2=342696&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Thu Sep 20 16:01:56 2018
@@ -363,6 +363,25 @@ public:
int Slot, const DILocation *Loc)
: Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {}
};
+
+ class Delegate {
+ virtual void anchor();
+
+ public:
+ virtual ~Delegate() = default;
+ virtual void MF_HandleInsertion(const MachineInstr &MI) = 0;
+ virtual void MF_HandleRemoval(const MachineInstr &MI) = 0;
+ };
+
+private:
+ Delegate *TheDelegate = nullptr;
+
+ // Callbacks for insertion and removal.
+ void handleInsertion(const MachineInstr &MI);
+ void handleRemoval(const MachineInstr &MI);
+ friend struct ilist_traits<MachineInstr>;
+
+public:
using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
VariableDbgInfoMapTy VariableDbgInfos;
@@ -379,6 +398,23 @@ public:
init();
}
+ /// Reset the currently registered delegate - otherwise assert.
+ void resetDelegate(Delegate *delegate) {
+ assert(TheDelegate == delegate &&
+ "Only the current delegate can perform reset!");
+ TheDelegate = nullptr;
+ }
+
+ /// Set the delegate. resetDelegate must be called before attempting
+ /// to set.
+ void setDelegate(Delegate *delegate) {
+ assert(delegate && !TheDelegate &&
+ "Attempted to set delegate to null, or to change it without "
+ "first resetting it!");
+
+ TheDelegate = delegate;
+ }
+
MachineModuleInfo &getMMI() const { return MMI; }
MCContext &getContext() const { return Ctx; }
Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=342696&r1=342695&r2=342696&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Thu Sep 20 16:01:56 2018
@@ -110,6 +110,7 @@ void ilist_traits<MachineInstr>::addNode
// use/def lists.
MachineFunction *MF = Parent->getParent();
N->AddRegOperandsToUseLists(MF->getRegInfo());
+ MF->handleInsertion(*N);
}
/// When we remove an instruction from a basic block list, we update its parent
@@ -118,8 +119,10 @@ void ilist_traits<MachineInstr>::removeN
assert(N->getParent() && "machine instruction not in a basic block");
// Remove from the use/def lists.
- if (MachineFunction *MF = N->getMF())
+ if (MachineFunction *MF = N->getMF()) {
+ MF->handleRemoval(*N);
N->RemoveRegOperandsFromUseLists(MF->getRegInfo());
+ }
N->setParent(nullptr);
}
Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=342696&r1=342695&r2=342696&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Thu Sep 20 16:01:56 2018
@@ -99,6 +99,9 @@ static const char *getPropertyName(Machi
llvm_unreachable("Invalid machine function property");
}
+// Pin the vtable to this file.
+void MachineFunction::Delegate::anchor() {}
+
void MachineFunctionProperties::print(raw_ostream &OS) const {
const char *Separator = "";
for (BitVector::size_type I = 0; I < Properties.size(); ++I) {
@@ -135,6 +138,16 @@ MachineFunction::MachineFunction(const F
init();
}
+void MachineFunction::handleInsertion(const MachineInstr &MI) {
+ if (TheDelegate)
+ TheDelegate->MF_HandleInsertion(MI);
+}
+
+void MachineFunction::handleRemoval(const MachineInstr &MI) {
+ if (TheDelegate)
+ TheDelegate->MF_HandleRemoval(MI);
+}
+
void MachineFunction::init() {
// Assume the function starts in SSA form with correct liveness.
Properties.set(MachineFunctionProperties::Property::IsSSA);
More information about the llvm-commits
mailing list