From ec7cba53e616b63981e437d88dbf572510f45970 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Tue, 10 Oct 2017 23:34:01 +0000 Subject: [PATCH] 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. llvm-svn: 315388 --- llvm/include/llvm/CodeGen/MachineInstr.h | 11 +++++++++++ llvm/lib/CodeGen/MachineInstr.cpp | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index f4aa893c45dc..7523825285a6 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -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( + static_cast(this)->getMF()); + } + /// Return the asm printer flags bitvector. uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; } diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 66de99156b4e..fadade26a89a 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -1154,6 +1154,10 @@ bool MachineInstr::isIdenticalTo(const MachineInstr &Other, 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);