From 62fabf5faba70c507c8fbe298260e9b3749fdd79 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 2 Jul 2009 18:03:58 +0000 Subject: [PATCH] Add an accessor to Function so that Passes can easily get access to the context. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74714 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Function.h | 5 +++++ lib/VMCore/Function.cpp | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 228ef9440e0..34ced973dd5 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -27,6 +27,7 @@ namespace llvm { class FunctionType; +class LLVMContext; // Traits for intrusive list of basic blocks... template<> struct ilist_traits @@ -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; diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 045056643b5..eeade051ac5 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -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(getType()->getElementType()); }