Add an accessor to Function so that Passes can easily get access to the context.
authorOwen Anderson <resistor@mac.com>
Thu, 2 Jul 2009 18:03:58 +0000 (18:03 +0000)
committerOwen Anderson <resistor@mac.com>
Thu, 2 Jul 2009 18:03:58 +0000 (18:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74714 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Function.h
lib/VMCore/Function.cpp

index 228ef9440e09d91ad30df381f3913ce10b589b20..34ced973dd5580974ef0d1fcba09d43d8d7f83a0 100644 (file)
@@ -27,6 +27,7 @@
 namespace llvm {
 
 class FunctionType;
+class LLVMContext;
 
 // Traits for intrusive list of basic blocks...
 template<> struct ilist_traits<BasicBlock>
@@ -126,6 +127,10 @@ public:
   const Type *getReturnType() const;           // Return the type of the ret val
   const FunctionType *getFunctionType() const; // Return the FunctionType for me
 
+  /// getContext - Return a pointer to the LLVMContext associated with this 
+  /// function, or NULL if this function is not bound to a context yet.
+  LLVMContext* getContext();
+
   /// isVarArg - Return true if this function takes a variable number of
   /// arguments.
   bool isVarArg() const;
index 045056643b548cc2cdd96e4b52fc2a8fe2a203b2..eeade051ac5328b7a8acb4e295643cd1d22a9f25 100644 (file)
@@ -114,6 +114,12 @@ void Argument::removeAttr(Attributes attr) {
 // Helper Methods in Function
 //===----------------------------------------------------------------------===//
 
+LLVMContext* Function::getContext() {
+  Module* M = getParent();
+  if (M) return &M->getContext();
+  return 0;
+}
+
 const FunctionType *Function::getFunctionType() const {
   return cast<FunctionType>(getType()->getElementType());
 }