C and Objective Caml bindings for PassManagers.
[oota-llvm.git] / include / llvm-c / Core.h
index 0d446d6640c3e82bb82b2b3384eaf21c4a3abf02..6c4b5de2b6ab9f9ca821a27c9e412fe45bbe738b 100644 (file)
@@ -39,6 +39,8 @@
    and 'unwrap' conversion functions. */
 #include "llvm/Module.h"
 #include "llvm/Support/LLVMBuilder.h"
    and 'unwrap' conversion functions. */
 #include "llvm/Module.h"
 #include "llvm/Support/LLVMBuilder.h"
+#include "llvm/Pass.h"
+#include "llvm/PassManager.h"
 
 extern "C" {
 #endif
 
 extern "C" {
 #endif
@@ -53,15 +55,15 @@ extern "C" {
 typedef struct LLVMOpaqueModule *LLVMModuleRef;
 
 /**
 typedef struct LLVMOpaqueModule *LLVMModuleRef;
 
 /**
- * Each value in the LLVM IR has a type, an instance of [lltype]. See the
- * llvm::Type class.
+ * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
+ * class.
  */
 typedef struct LLVMOpaqueType *LLVMTypeRef;
 
 /**
  */
 typedef struct LLVMOpaqueType *LLVMTypeRef;
 
 /**
- * When building recursive types using [refine_type], [lltype] values may become
- * invalid; use [lltypehandle] to resolve this problem. See the
- * llvm::AbstractTypeHolder] class. 
+ * When building recursive types using LLVMRefineType, LLVMTypeRef values may
+ * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
+ * llvm::AbstractTypeHolder class.
  */
 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
 
  */
 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
 
@@ -79,6 +81,9 @@ typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
  */
 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
 
  */
 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
 
+/** See the llvm::PassManagerBase class. */
+typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
+
 typedef enum {
   LLVMVoidTypeKind,        /**< type with no size */
   LLVMFloatTypeKind,       /**< 32 bit floating point type */
 typedef enum {
   LLVMVoidTypeKind,        /**< type with no size */
   LLVMFloatTypeKind,       /**< 32 bit floating point type */
@@ -165,21 +170,27 @@ void LLVMDisposeMessage(char *Message);
 /*===-- Modules -----------------------------------------------------------===*/
 
 /* Create and destroy modules. */ 
 /*===-- Modules -----------------------------------------------------------===*/
 
 /* Create and destroy modules. */ 
+/** See llvm::Module::Module. */
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
+
+/** See llvm::Module::~Module. */
 void LLVMDisposeModule(LLVMModuleRef M);
 
 void LLVMDisposeModule(LLVMModuleRef M);
 
-/* Data layout */
+/** Data layout. See Module::getDataLayout. */
 const char *LLVMGetDataLayout(LLVMModuleRef M);
 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
 
 const char *LLVMGetDataLayout(LLVMModuleRef M);
 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
 
-/* Target triple */
+/** Target triple. See Module::getTargetTriple. */
 const char *LLVMGetTarget(LLVMModuleRef M);
 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
 
 const char *LLVMGetTarget(LLVMModuleRef M);
 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
 
-/* Same as Module::addTypeName. */
+/** See Module::addTypeName. */
 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
 
 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
 
+/** See Module::dump. */
+void LLVMDumpModule(LLVMModuleRef M);
+
 
 /*===-- Types -------------------------------------------------------------===*/
 
 
 /*===-- Types -------------------------------------------------------------===*/
 
@@ -198,7 +209,10 @@ void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
  *     opaque type
  */
 
  *     opaque type
  */
 
+/** See llvm::LLVMTypeKind::getTypeID. */
 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
+
+/** See llvm::DerivedType::refineAbstractTypeTo. */
 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
 
 /* Operations on integer types */
 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
 
 /* Operations on integer types */
@@ -289,6 +303,7 @@ int LLVMIsUndef(LLVMValueRef Val);
 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
                           int SignExtend);
 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
                           int SignExtend);
 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
+LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
 
 /* Operations on composite constants */
 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
 
 /* Operations on composite constants */
 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
@@ -434,6 +449,10 @@ LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
 
 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
 
+/* Add a case to the switch instruction */
+void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
+                 LLVMBasicBlockRef Dest);
+
 /* Arithmetic */
 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
                           const char *Name);
 /* Arithmetic */
 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
                           const char *Name);
@@ -561,6 +580,47 @@ int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
                                     char **OutMessage);
 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
 
                                     char **OutMessage);
 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
 
+
+/*===-- Pass Managers -----------------------------------------------------===*/
+
+/** Constructs a new whole-module pass pipeline. This type of pipeline is
+    suitable for link-time optimization and whole-module transformations.
+    See llvm::PassManager::PassManager. */
+LLVMPassManagerRef LLVMCreatePassManager();
+
+/** Constructs a new function-by-function pass pipeline over the module
+    provider. It does not take ownership of the module provider. This type of
+    pipeline is suitable for code generation and JIT compilation tasks.
+    See llvm::FunctionPassManager::FunctionPassManager. */
+LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
+
+/** Initializes, executes on the provided module, and finalizes all of the
+    passes scheduled in the pass manager. Returns 1 if any of the passes
+    modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
+int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
+
+/** Initializes all of the function passes scheduled in the function pass
+    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
+    See llvm::FunctionPassManager::doInitialization. */
+int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
+
+/** Executes all of the function passes scheduled in the function pass manager
+    on the provided function. Returns 1 if any of the passes modified the
+    function, false otherwise.
+    See llvm::FunctionPassManager::run(Function&). */
+int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
+
+/** Finalizes all of the function passes scheduled in in the function pass
+    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
+    See llvm::FunctionPassManager::doFinalization. */
+int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
+
+/** Frees the memory of a pass pipeline. For function pipelines, does not free
+    the module provider.
+    See llvm::PassManagerBase::~PassManagerBase. */
+void LLVMDisposePassManager(LLVMPassManagerRef PM);
+
+
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
 
@@ -577,24 +637,40 @@ namespace llvm {
       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
     }
   
       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
     }
   
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Type,               LLVMTypeRef          )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Value,              LLVMValueRef         )
+  #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
+    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
+                                                        \
+    template<typename T>                                \
+    inline T *unwrap(ref P) {                           \
+      return cast<T>(unwrap(P));                        \
+    }
+  
+  #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
+    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
+                                                        \
+    template<typename T>                                \
+    inline T *unwrap(ref P) {                           \
+      T *Q = dynamic_cast<T*>(unwrap(P));               \
+      assert(Q && "Invalid cast!");                     \
+      return Q;                                         \
+    }
+  
+  DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
+  DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef       )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef       )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
+  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
   
   
+  #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
+  #undef DEFINE_ISA_CONVERSION_FUNCTIONS
   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
   
   /* Specialized opaque type conversions.
    */
   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
   
   /* Specialized opaque type conversions.
    */
-  template<typename T>
-  inline T *unwrap(LLVMTypeRef Ty) {
-    return cast<T>(unwrap(Ty));
-  }
-  
   inline Type **unwrap(LLVMTypeRef* Tys) {
     return reinterpret_cast<Type**>(Tys);
   }
   inline Type **unwrap(LLVMTypeRef* Tys) {
     return reinterpret_cast<Type**>(Tys);
   }
@@ -605,11 +681,6 @@ namespace llvm {
   
   /* Specialized opaque value conversions.
    */ 
   
   /* Specialized opaque value conversions.
    */ 
-  template<typename T>
-  inline T *unwrap(LLVMValueRef Val) {
-    return cast<T>(unwrap(Val));
-  }
-
   inline Value **unwrap(LLVMValueRef *Vals) {
     return reinterpret_cast<Value**>(Vals);
   }
   inline Value **unwrap(LLVMValueRef *Vals) {
     return reinterpret_cast<Value**>(Vals);
   }