[llvm] r315388 - CodeGen: Add MachineInstr::getMF(). NFC
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 16:34:01 PDT 2017
Author: bogner
Date: Tue Oct 10 16:34:01 2017
New Revision: 315388
URL: http://llvm.org/viewvc/llvm-project?rev=315388&view=rev
Log:
CodeGen: Add MachineInstr::getMF(). NFC
Similarly to how Instruction has getFunction, this adds a less verbose
way to write MI->getParent()->getParent(). I'll follow up shortly with
a change that changes a bunch of the uses.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineInstr.h
llvm/trunk/lib/CodeGen/MachineInstr.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=315388&r1=315387&r2=315388&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Tue Oct 10 16:34:01 2017
@@ -139,6 +139,17 @@ public:
const MachineBasicBlock* getParent() const { return Parent; }
MachineBasicBlock* getParent() { return Parent; }
+ /// Return the function that contains the basic block that this instruction
+ /// belongs to.
+ ///
+ /// Note: this is undefined behaviour if the instruction does not have a
+ /// parent.
+ const MachineFunction *getMF() const;
+ MachineFunction *getMF() {
+ return const_cast<MachineFunction *>(
+ static_cast<const MachineInstr *>(this)->getMF());
+ }
+
/// Return the asm printer flags bitvector.
uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; }
Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=315388&r1=315387&r2=315388&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Tue Oct 10 16:34:01 2017
@@ -1154,6 +1154,10 @@ bool MachineInstr::isIdenticalTo(const M
return true;
}
+const MachineFunction *MachineInstr::getMF() const {
+ return getParent()->getParent();
+}
+
MachineInstr *MachineInstr::removeFromParent() {
assert(getParent() && "Not embedded in a basic block!");
return getParent()->remove(this);
More information about the llvm-commits
mailing list