Add a MachineBasicBlock::getParent() method
authorChris Lattner <sabre@nondot.org>
Thu, 19 Feb 2004 16:13:54 +0000 (16:13 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Feb 2004 16:13:54 +0000 (16:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11622 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineBasicBlock.h
lib/CodeGen/MachineBasicBlock.cpp

index 9399d56b76fff2b4cdbab09d5542b8345b1bac42..44cab9e9e3fc552480c69890ca61bb09feee640f 100644 (file)
 #include <iosfwd>
 
 namespace llvm {
+  class MachineFunction;
 
 // ilist_traits
 template <>
-class ilist_traits<MachineInstr>
-{
+class ilist_traits<MachineInstr> {
   // this is only set by the MachineBasicBlock owning the ilist
   friend class MachineBasicBlock;
   MachineBasicBlock* parent;
@@ -70,7 +70,11 @@ public:
   /// corresponded to originally.
   ///
   const BasicBlock *getBasicBlock() const { return BB; }
-  
+
+  /// getParent - Return the MachineFunction containing this basic block.
+  ///
+  const MachineFunction *getParent() const;
+
   typedef ilist<MachineInstr>::iterator                       iterator;
   typedef ilist<MachineInstr>::const_iterator           const_iterator;
   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
index 93606931868814019299e2c888d1115480d85afa..9d65453edff2ef877d83aacfca51c4b8eeb83e84 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/MachineBasicBlock.h"
-
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "Support/LeakDetector.h"
-#include <iostream>
-
 using namespace llvm;
 
+const MachineFunction *MachineBasicBlock::getParent() const {
+  // Get the parent by getting the Function parent of the basic block, and
+  // getting the MachineFunction from it.
+  return &MachineFunction::get(getBasicBlock()->getParent());
+}
+
+
 MachineInstr* ilist_traits<MachineInstr>::createNode()
 {
     MachineInstr* dummy = new MachineInstr(0, 0);