diff options
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/go/README.txt | 8 | ||||
-rw-r--r-- | bindings/go/llvm/DIBuilderBindings.cpp | 234 | ||||
-rw-r--r-- | bindings/go/llvm/DIBuilderBindings.h | 134 | ||||
-rw-r--r-- | bindings/go/llvm/IRBindings.cpp | 16 | ||||
-rw-r--r-- | bindings/go/llvm/IRBindings.h | 7 | ||||
-rw-r--r-- | bindings/go/llvm/dibuilder.go | 109 | ||||
-rw-r--r-- | bindings/go/llvm/ir.go | 72 | ||||
-rw-r--r-- | bindings/go/llvm/ir_test.go | 7 | ||||
-rw-r--r-- | bindings/go/llvm/transforms_scalar.go | 1 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm.mli | 2 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm_ocaml.c | 1 | ||||
-rw-r--r-- | bindings/ocaml/transforms/vectorize/llvm_vectorize.ml | 3 | ||||
-rw-r--r-- | bindings/ocaml/transforms/vectorize/llvm_vectorize.mli | 5 | ||||
-rw-r--r-- | bindings/ocaml/transforms/vectorize/vectorize_ocaml.c | 6 | ||||
-rw-r--r-- | bindings/python/llvm/core.py | 3 |
15 files changed, 147 insertions, 461 deletions
diff --git a/bindings/go/README.txt b/bindings/go/README.txt index 2fc4afa07715..6ed224d8280e 100644 --- a/bindings/go/README.txt +++ b/bindings/go/README.txt @@ -51,3 +51,11 @@ CGO_CPPFLAGS, CGO_CXXFLAGS and CGO_LDFLAGS environment variables: $ export CGO_CXXFLAGS=-std=c++11 $ export CGO_LDFLAGS="`/path/to/llvm-build/bin/llvm-config --ldflags --libs --system-libs all`" $ go build -tags byollvm + +If you see a compilation error while compiling your code with Go 1.9.4 or later as follows, + + go build llvm.org/llvm/bindings/go/llvm: invalid flag in #cgo LDFLAGS: -Wl,-headerpad_max_install_names + +you need to setup $CGO_LDFLAGS_ALLOW to allow a compiler to specify some linker options: + + $ export CGO_LDFLAGS_ALLOW='-Wl,(-search_paths_first|-headerpad_max_install_names)' diff --git a/bindings/go/llvm/DIBuilderBindings.cpp b/bindings/go/llvm/DIBuilderBindings.cpp deleted file mode 100644 index ea53694b9c13..000000000000 --- a/bindings/go/llvm/DIBuilderBindings.cpp +++ /dev/null @@ -1,234 +0,0 @@ -//===- DIBuilderBindings.cpp - Bindings for DIBuilder ---------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines C bindings for the DIBuilder class. -// -//===----------------------------------------------------------------------===// - -#include "DIBuilderBindings.h" -#include "IRBindings.h" -#include "llvm/IR/DIBuilder.h" -#include "llvm/IR/IRBuilder.h" -#include "llvm/IR/Module.h" - -using namespace llvm; - -LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) { - Module *m = unwrap(mref); - return wrap(new DIBuilder(*m)); -} - -void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) { - DIBuilder *d = unwrap(dref); - delete d; -} - -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Line, - unsigned Column) { - DIBuilder *D = unwrap(Dref); - auto *LB = D->createLexicalBlock(unwrap<DILocalScope>(Scope), - unwrap<DIFile>(File), Line, Column); - return wrap(LB); -} - -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Discriminator) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createLexicalBlockFile(unwrap<DILocalScope>(Scope), - unwrap<DIFile>(File), Discriminator)); -} - -LLVMMetadataRef LLVMDIBuilderCreateFunction( - LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - const char *LinkageName, LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition, - unsigned ScopeLine, unsigned Flags, int IsOptimized) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createFunction( - unwrap<DIScope>(Scope), Name, LinkageName, - File ? unwrap<DIFile>(File) : nullptr, Line, - unwrap<DISubroutineType>(CompositeType), IsLocalToUnit, IsDefinition, - ScopeLine, static_cast<DINode::DIFlags>(Flags), IsOptimized)); -} - -LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( - LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, - unsigned Flags, uint32_t AlignInBits) { - DIBuilder *D = unwrap(Dref); - return wrap( - D->createAutoVariable(unwrap<DIScope>(Scope), Name, unwrap<DIFile>(File), - Line, unwrap<DIType>(Ty), AlwaysPreserve, - static_cast<DINode::DIFlags>(Flags), AlignInBits)); -} - -LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( - LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - unsigned ArgNo, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, - int AlwaysPreserve, unsigned Flags) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createParameterVariable( - unwrap<DIScope>(Scope), Name, ArgNo, unwrap<DIFile>(File), Line, - unwrap<DIType>(Ty), AlwaysPreserve, static_cast<DINode::DIFlags>(Flags))); -} - -LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, - const char *Name, - uint64_t SizeInBits, - unsigned Encoding) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createBasicType(Name, SizeInBits, Encoding)); -} - -LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, - LLVMMetadataRef PointeeType, - uint64_t SizeInBits, - uint32_t AlignInBits, - const char *Name) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits, - AlignInBits, /* DWARFAddressSpace */ None, - Name)); -} - -LLVMMetadataRef -LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File, - LLVMMetadataRef ParameterTypes) { - DIBuilder *D = unwrap(Dref); - return wrap( - D->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); -} - -LLVMMetadataRef LLVMDIBuilderCreateStructType( - LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, - uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom, - LLVMMetadataRef ElementTypes) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createStructType( - unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line, - SizeInBits, AlignInBits, static_cast<DINode::DIFlags>(Flags), - DerivedFrom ? unwrap<DIType>(DerivedFrom) : nullptr, - ElementTypes ? DINodeArray(unwrap<MDTuple>(ElementTypes)) : nullptr)); -} - -LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType( - LLVMDIBuilderRef Dref, unsigned Tag, const char *Name, - LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, - unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, - unsigned Flags) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createReplaceableCompositeType( - Tag, Name, unwrap<DIScope>(Scope), File ? unwrap<DIFile>(File) : nullptr, - Line, RuntimeLang, SizeInBits, AlignInBits, - static_cast<DINode::DIFlags>(Flags))); -} - -LLVMMetadataRef -LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, - const char *Name, LLVMMetadataRef File, - unsigned Line, uint64_t SizeInBits, - uint32_t AlignInBits, uint64_t OffsetInBits, - unsigned Flags, LLVMMetadataRef Ty) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createMemberType( - unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line, - SizeInBits, AlignInBits, OffsetInBits, - static_cast<DINode::DIFlags>(Flags), unwrap<DIType>(Ty))); -} - -LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref, - uint64_t SizeInBits, - uint32_t AlignInBits, - LLVMMetadataRef ElementType, - LLVMMetadataRef Subscripts) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createArrayType(SizeInBits, AlignInBits, - unwrap<DIType>(ElementType), - DINodeArray(unwrap<MDTuple>(Subscripts)))); -} - -LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, - LLVMMetadataRef Ty, const char *Name, - LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef Context) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createTypedef(unwrap<DIType>(Ty), Name, - File ? unwrap<DIFile>(File) : nullptr, Line, - Context ? unwrap<DIScope>(Context) : nullptr)); -} - -LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, - int64_t Lo, int64_t Count) { - DIBuilder *D = unwrap(Dref); - return wrap(D->getOrCreateSubrange(Lo, Count)); -} - -LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref, - LLVMMetadataRef *Data, - size_t Length) { - DIBuilder *D = unwrap(Dref); - Metadata **DataValue = unwrap(Data); - ArrayRef<Metadata *> Elements(DataValue, Length); - DINodeArray A = D->getOrCreateArray(Elements); - return wrap(A.get()); -} - -LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref, - LLVMMetadataRef *Data, - size_t Length) { - DIBuilder *D = unwrap(Dref); - Metadata **DataValue = unwrap(Data); - ArrayRef<Metadata *> Elements(DataValue, Length); - DITypeRefArray A = D->getOrCreateTypeArray(Elements); - return wrap(A.get()); -} - -LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, - int64_t *Addr, size_t Length) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createExpression(ArrayRef<int64_t>(Addr, Length))); -} - -LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref, - LLVMValueRef Storage, - LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, - LLVMBasicBlockRef Block) { - // Fail immediately here until the llgo folks update their bindings. The - // called function is going to assert out anyway. - llvm_unreachable("DIBuilder API change requires a DebugLoc"); - - DIBuilder *D = unwrap(Dref); - Instruction *Instr = D->insertDeclare( - unwrap(Storage), unwrap<DILocalVariable>(VarInfo), - unwrap<DIExpression>(Expr), /* DebugLoc */ nullptr, unwrap(Block)); - return wrap(Instr); -} - -LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref, - LLVMValueRef Val, - LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, - LLVMBasicBlockRef Block) { - // Fail immediately here until the llgo folks update their bindings. The - // called function is going to assert out anyway. - llvm_unreachable("DIBuilder API change requires a DebugLoc"); - - DIBuilder *D = unwrap(Dref); - Instruction *Instr = D->insertDbgValueIntrinsic( - unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr), - /* DebugLoc */ nullptr, unwrap(Block)); - return wrap(Instr); -} diff --git a/bindings/go/llvm/DIBuilderBindings.h b/bindings/go/llvm/DIBuilderBindings.h deleted file mode 100644 index cc5d2c1177f6..000000000000 --- a/bindings/go/llvm/DIBuilderBindings.h +++ /dev/null @@ -1,134 +0,0 @@ -//===- DIBuilderBindings.h - Bindings for DIBuilder -------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines C bindings for the DIBuilder class. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H -#define LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H - -#include "IRBindings.h" -#include "llvm-c/Core.h" -#include "llvm-c/DebugInfo.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// FIXME: These bindings shouldn't be Go-specific and should eventually move to -// a (somewhat) less stable collection of C APIs for use in creating bindings of -// LLVM in other languages. - -typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef; - -LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef m); - -void LLVMDIBuilderDestroy(LLVMDIBuilderRef d); - -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef D, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Line, unsigned Column); - -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef D, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Discriminator); - -LLVMMetadataRef LLVMDIBuilderCreateFunction( - LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, - const char *LinkageName, LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition, - unsigned ScopeLine, unsigned Flags, int IsOptimized); - -LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( - LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, - unsigned Flags, uint32_t AlignInBits); - -LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( - LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, unsigned ArgNo, - LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, - unsigned Flags); - -LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef D, - const char *Name, - uint64_t SizeInBits, - unsigned Encoding); - -LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef D, - LLVMMetadataRef PointeeType, - uint64_t SizeInBits, - uint32_t AlignInBits, - const char *Name); - -LLVMMetadataRef -LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef D, LLVMMetadataRef File, - LLVMMetadataRef ParameterTypes); - -LLVMMetadataRef LLVMDIBuilderCreateStructType( - LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, - uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom, - LLVMMetadataRef ElementTypes); - -LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType( - LLVMDIBuilderRef D, unsigned Tag, const char *Name, LLVMMetadataRef Scope, - LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, - uint64_t SizeInBits, uint32_t AlignInBits, unsigned Flags); - -LLVMMetadataRef -LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef D, LLVMMetadataRef Scope, - const char *Name, LLVMMetadataRef File, - unsigned Line, uint64_t SizeInBits, - uint32_t AlignInBits, uint64_t OffsetInBits, - unsigned Flags, LLVMMetadataRef Ty); - -LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef D, - uint64_t SizeInBits, - uint32_t AlignInBits, - LLVMMetadataRef ElementType, - LLVMMetadataRef Subscripts); - -LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef D, - LLVMMetadataRef Ty, const char *Name, - LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef Context); - -LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef D, int64_t Lo, - int64_t Count); - -LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef D, - LLVMMetadataRef *Data, - size_t Length); - -LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef D, - LLVMMetadataRef *Data, - size_t Length); - -LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, - int64_t *Addr, size_t Length); - -LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef D, - LLVMValueRef Storage, - LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, - LLVMBasicBlockRef Block); - -LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef D, LLVMValueRef Val, - LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, - LLVMBasicBlockRef Block); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/bindings/go/llvm/IRBindings.cpp b/bindings/go/llvm/IRBindings.cpp index 4bfa1bbaf0cc..b8e3063eb9ac 100644 --- a/bindings/go/llvm/IRBindings.cpp +++ b/bindings/go/llvm/IRBindings.cpp @@ -36,13 +36,6 @@ LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs, MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count))); } -LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs, - unsigned Count) { - return wrap(MDTuple::getTemporary(*unwrap(C), - ArrayRef<Metadata *>(unwrap(MDs), Count)) - .release()); -} - void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name, LLVMMetadataRef Val) { NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name); @@ -58,12 +51,6 @@ void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) { unwrap<Instruction>(Inst)->setMetadata(KindID, N); } -void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) { - auto *Node = unwrap<MDNode>(MD); - Node->replaceAllUsesWith(unwrap<Metadata>(New)); - MDNode::deleteTemporary(Node); -} - void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt) { @@ -84,6 +71,3 @@ LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref) { return md; } -void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { - unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP)); -} diff --git a/bindings/go/llvm/IRBindings.h b/bindings/go/llvm/IRBindings.h index 25a00b138044..66b328c43257 100644 --- a/bindings/go/llvm/IRBindings.h +++ b/bindings/go/llvm/IRBindings.h @@ -15,6 +15,7 @@ #define LLVM_BINDINGS_GO_LLVM_IRBINDINGS_H #include "llvm-c/Core.h" +#include "llvm-c/DebugInfo.h" #ifdef __cplusplus #include "llvm/IR/Metadata.h" #include "llvm/Support/CBindingWrapping.h" @@ -38,23 +39,17 @@ LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef Val); LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen); LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs, unsigned Count); -LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs, - unsigned Count); void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name, LLVMMetadataRef Val); void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD); -void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New); - void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt); struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref); -void LLVMSetSubprogram(LLVMValueRef Fn, LLVMMetadataRef SP); - #ifdef __cplusplus } diff --git a/bindings/go/llvm/dibuilder.go b/bindings/go/llvm/dibuilder.go index 475fa685cc4b..8ec8f3cd2805 100644 --- a/bindings/go/llvm/dibuilder.go +++ b/bindings/go/llvm/dibuilder.go @@ -14,7 +14,7 @@ package llvm /* -#include "DIBuilderBindings.h" +#include "IRBindings.h" #include <stdlib.h> */ import "C" @@ -95,13 +95,13 @@ type DIBuilder struct { // NewDIBuilder creates a new DIBuilder, associated with the given module. func NewDIBuilder(m Module) *DIBuilder { - d := C.LLVMNewDIBuilder(m.C) + d := C.LLVMCreateDIBuilder(m.C) return &DIBuilder{ref: d, m: m} } // Destroy destroys the DIBuilder. func (d *DIBuilder) Destroy() { - C.LLVMDIBuilderDestroy(d.ref) + C.LLVMDisposeDIBuilder(d.ref) } // FInalize finalizes the debug information generated by the DIBuilder. @@ -147,7 +147,7 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata { return Metadata{C: result} } -// CreateCompileUnit creates file debug metadata. +// CreateFile creates file debug metadata. func (d *DIBuilder) CreateFile(filename, dir string) Metadata { cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) @@ -166,7 +166,7 @@ type DILexicalBlock struct { Column int } -// CreateCompileUnit creates lexical block debug metadata. +// CreateLexicalBlock creates lexical block debug metadata. func (d *DIBuilder) CreateLexicalBlock(diScope Metadata, b DILexicalBlock) Metadata { result := C.LLVMDIBuilderCreateLexicalBlock( d.ref, @@ -198,7 +198,7 @@ type DIFunction struct { Optimized bool } -// CreateCompileUnit creates function debug metadata. +// CreateFunction creates function debug metadata. func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata { name := C.CString(f.Name) defer C.free(unsafe.Pointer(name)) @@ -207,16 +207,16 @@ func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata { result := C.LLVMDIBuilderCreateFunction( d.ref, diScope.C, - name, - linkageName, + name, C.size_t(len(f.Name)), + linkageName, C.size_t(len(f.LinkageName)), f.File.C, C.unsigned(f.Line), f.Type.C, - boolToCInt(f.LocalToUnit), - boolToCInt(f.IsDefinition), + C.LLVMBool(boolToCInt(f.LocalToUnit)), + C.LLVMBool(boolToCInt(f.IsDefinition)), C.unsigned(f.ScopeLine), - C.unsigned(f.Flags), - boolToCInt(f.Optimized), + C.LLVMDIFlags(f.Flags), + C.LLVMBool(boolToCInt(f.Optimized)), ) return Metadata{C: result} } @@ -239,12 +239,12 @@ func (d *DIBuilder) CreateAutoVariable(scope Metadata, v DIAutoVariable) Metadat result := C.LLVMDIBuilderCreateAutoVariable( d.ref, scope.C, - name, + name, C.size_t(len(v.Name)), v.File.C, C.unsigned(v.Line), v.Type.C, - boolToCInt(v.AlwaysPreserve), - C.unsigned(v.Flags), + C.LLVMBool(boolToCInt(v.AlwaysPreserve)), + C.LLVMDIFlags(v.Flags), C.uint32_t(v.AlignInBits), ) return Metadata{C: result} @@ -271,13 +271,13 @@ func (d *DIBuilder) CreateParameterVariable(scope Metadata, v DIParameterVariabl result := C.LLVMDIBuilderCreateParameterVariable( d.ref, scope.C, - name, + name, C.size_t(len(v.Name)), C.unsigned(v.ArgNo), v.File.C, C.unsigned(v.Line), v.Type.C, - boolToCInt(v.AlwaysPreserve), - C.unsigned(v.Flags), + C.LLVMBool(boolToCInt(v.AlwaysPreserve)), + C.LLVMDIFlags(v.Flags), ) return Metadata{C: result} } @@ -296,6 +296,7 @@ func (d *DIBuilder) CreateBasicType(t DIBasicType) Metadata { result := C.LLVMDIBuilderCreateBasicType( d.ref, name, + C.size_t(len(t.Name)), C.uint64_t(t.SizeInBits), C.unsigned(t.Encoding), ) @@ -307,10 +308,11 @@ type DIPointerType struct { Pointee Metadata SizeInBits uint64 AlignInBits uint32 // optional + AddressSpace uint32 Name string // optional } -// CreateBasicType creates basic type debug metadata. +// CreatePointerType creates a type that represents a pointer to another type. func (d *DIBuilder) CreatePointerType(t DIPointerType) Metadata { name := C.CString(t.Name) defer C.free(unsafe.Pointer(name)) @@ -319,7 +321,9 @@ func (d *DIBuilder) CreatePointerType(t DIPointerType) Metadata { t.Pointee.C, C.uint64_t(t.SizeInBits), C.uint32_t(t.AlignInBits), + C.unsigned(t.AddressSpace), name, + C.size_t(len(t.Name)), ) return Metadata{C: result} } @@ -332,12 +336,20 @@ type DISubroutineType struct { // Parameters contains the subroutine parameter types, // including the return type at the 0th index. Parameters []Metadata + + Flags int } // CreateSubroutineType creates subroutine type debug metadata. func (d *DIBuilder) CreateSubroutineType(t DISubroutineType) Metadata { - params := d.getOrCreateTypeArray(t.Parameters) - result := C.LLVMDIBuilderCreateSubroutineType(d.ref, t.File.C, params.C) + params, length := llvmMetadataRefs(t.Parameters) + result := C.LLVMDIBuilderCreateSubroutineType( + d.ref, + t.File.C, + params, + length, + C.LLVMDIFlags(t.Flags), + ) return Metadata{C: result} } @@ -351,24 +363,34 @@ type DIStructType struct { Flags int DerivedFrom Metadata Elements []Metadata + VTableHolder Metadata // optional + UniqueID string } // CreateStructType creates struct type debug metadata. func (d *DIBuilder) CreateStructType(scope Metadata, t DIStructType) Metadata { - elements := d.getOrCreateArray(t.Elements) + elements, length := llvmMetadataRefs(t.Elements) name := C.CString(t.Name) + uniqueID := C.CString(t.UniqueID) defer C.free(unsafe.Pointer(name)) + defer C.free(unsafe.Pointer(uniqueID)) result := C.LLVMDIBuilderCreateStructType( d.ref, scope.C, name, + C.size_t(len(t.Name)), t.File.C, C.unsigned(t.Line), C.uint64_t(t.SizeInBits), C.uint32_t(t.AlignInBits), - C.unsigned(t.Flags), + C.LLVMDIFlags(t.Flags), t.DerivedFrom.C, - elements.C, + elements, + length, + C.unsigned(0), // Optional Objective-C runtime version. + t.VTableHolder.C, + uniqueID, + C.size_t(len(t.UniqueID)), ) return Metadata{C: result} } @@ -384,23 +406,29 @@ type DIReplaceableCompositeType struct { SizeInBits uint64 AlignInBits uint32 Flags int + UniqueID string } // CreateReplaceableCompositeType creates replaceable composite type debug metadata. func (d *DIBuilder) CreateReplaceableCompositeType(scope Metadata, t DIReplaceableCompositeType) Metadata { name := C.CString(t.Name) + uniqueID := C.CString(t.UniqueID) defer C.free(unsafe.Pointer(name)) + defer C.free(unsafe.Pointer(uniqueID)) result := C.LLVMDIBuilderCreateReplaceableCompositeType( d.ref, C.unsigned(t.Tag), name, + C.size_t(len(t.Name)), scope.C, t.File.C, C.unsigned(t.Line), C.unsigned(t.RuntimeLang), C.uint64_t(t.SizeInBits), C.uint32_t(t.AlignInBits), - C.unsigned(t.Flags), + C.LLVMDIFlags(t.Flags), + uniqueID, + C.size_t(len(t.UniqueID)), ) return Metadata{C: result} } @@ -425,12 +453,13 @@ func (d *DIBuilder) CreateMemberType(scope Metadata, t DIMemberType) Metadata { d.ref, scope.C, name, + C.size_t(len(t.Name)), t.File.C, C.unsigned(t.Line), C.uint64_t(t.SizeInBits), C.uint32_t(t.AlignInBits), C.uint64_t(t.OffsetInBits), - C.unsigned(t.Flags), + C.LLVMDIFlags(t.Flags), t.Type.C, ) return Metadata{C: result} @@ -456,13 +485,14 @@ func (d *DIBuilder) CreateArrayType(t DIArrayType) Metadata { for i, s := range t.Subscripts { subscriptsSlice[i] = d.getOrCreateSubrange(s.Lo, s.Count) } - subscripts := d.getOrCreateArray(subscriptsSlice) + subscripts, length := llvmMetadataRefs(subscriptsSlice) result := C.LLVMDIBuilderCreateArrayType( d.ref, C.uint64_t(t.SizeInBits), C.uint32_t(t.AlignInBits), t.ElementType.C, - subscripts.C, + subscripts, + length, ) return Metadata{C: result} } @@ -484,6 +514,7 @@ func (d *DIBuilder) CreateTypedef(t DITypedef) Metadata { d.ref, t.Type.C, name, + C.size_t(len(t.Name)), t.File.C, C.unsigned(t.Line), t.Context.C, @@ -534,20 +565,38 @@ func (d *DIBuilder) CreateExpression(addr []int64) Metadata { // InsertDeclareAtEnd inserts a call to llvm.dbg.declare at the end of the // specified basic block for the given value and associated debug metadata. func (d *DIBuilder) InsertDeclareAtEnd(v Value, diVarInfo, expr Metadata, bb BasicBlock) Value { - result := C.LLVMDIBuilderInsertDeclareAtEnd(d.ref, v.C, diVarInfo.C, expr.C, bb.C) + result := C.LLVMDIBuilderInsertDeclareAtEnd(d.ref, v.C, diVarInfo.C, expr.C, nil, bb.C) return Value{C: result} } // InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the // specified basic block for the given value and associated debug metadata. func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, bb BasicBlock) Value { - result := C.LLVMDIBuilderInsertValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, bb.C) + result := C.LLVMDIBuilderInsertDbgValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, nil, bb.C) return Value{C: result} } +func (v Value) SetSubprogram(sp Metadata) { + C.LLVMSetSubprogram(v.C, sp.C) +} + func boolToCInt(v bool) C.int { if v { return 1 } return 0 } + +//------------------------------------------------------------------------- +// llvm.Metadata +//------------------------------------------------------------------------- + +func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) { + ptr, nvals := llvmMetadataRefs(mds) + md.C = C.LLVMTemporaryMDNode(c.C, ptr, C.size_t(nvals)) + return +} + +func (md Metadata) ReplaceAllUsesWith(new Metadata) { + C.LLVMMetadataReplaceAllUsesWith(md.C, new.C) +} diff --git a/bindings/go/llvm/ir.go b/bindings/go/llvm/ir.go index 222097034307..a336c0ef44c7 100644 --- a/bindings/go/llvm/ir.go +++ b/bindings/go/llvm/ir.go @@ -15,6 +15,7 @@ package llvm /* #include "llvm-c/Core.h" +#include "llvm-c/Comdat.h" #include "IRBindings.h" #include <stdlib.h> */ @@ -37,6 +38,9 @@ type ( Value struct { C C.LLVMValueRef } + Comdat struct { + C C.LLVMComdatRef + } BasicBlock struct { C C.LLVMBasicBlockRef } @@ -61,14 +65,15 @@ type ( Attribute struct { C C.LLVMAttributeRef } - Opcode C.LLVMOpcode - TypeKind C.LLVMTypeKind - Linkage C.LLVMLinkage - Visibility C.LLVMVisibility - CallConv C.LLVMCallConv - IntPredicate C.LLVMIntPredicate - FloatPredicate C.LLVMRealPredicate - LandingPadClause C.LLVMLandingPadClauseTy + Opcode C.LLVMOpcode + TypeKind C.LLVMTypeKind + Linkage C.LLVMLinkage + Visibility C.LLVMVisibility + CallConv C.LLVMCallConv + ComdatSelectionKind C.LLVMComdatSelectionKind + IntPredicate C.LLVMIntPredicate + FloatPredicate C.LLVMRealPredicate + LandingPadClause C.LLVMLandingPadClauseTy ) func (c Context) IsNil() bool { return c.C == nil } @@ -249,6 +254,18 @@ const ( ) //------------------------------------------------------------------------- +// llvm.ComdatSelectionKind +//------------------------------------------------------------------------- + +const ( + AnyComdatSelectionKind ComdatSelectionKind = C.LLVMAnyComdatSelectionKind + ExactMatchComdatSelectionKind ComdatSelectionKind = C.LLVMExactMatchComdatSelectionKind + LargestComdatSelectionKind ComdatSelectionKind = C.LLVMLargestComdatSelectionKind + NoDuplicatesComdatSelectionKind ComdatSelectionKind = C.LLVMNoDuplicatesComdatSelectionKind + SameSizeComdatSelectionKind ComdatSelectionKind = C.LLVMSameSizeComdatSelectionKind +) + +//------------------------------------------------------------------------- // llvm.IntPredicate //------------------------------------------------------------------------- @@ -767,11 +784,6 @@ func (c Context) MDNode(mds []Metadata) (md Metadata) { md.C = C.LLVMMDNode2(c.C, ptr, nvals) return } -func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) { - ptr, nvals := llvmMetadataRefs(mds) - md.C = C.LLVMTemporaryMDNode(c.C, ptr, nvals) - return -} func (v Value) ConstantAsMetadata() (md Metadata) { md.C = C.LLVMConstantAsMetadata(v.C) return @@ -1020,6 +1032,8 @@ func (v Value) IsThreadLocal() bool { return C.LLVMIsThreadLocal(v.C) != 0 func (v Value) SetThreadLocal(tl bool) { C.LLVMSetThreadLocal(v.C, boolToLLVMBool(tl)) } func (v Value) IsGlobalConstant() bool { return C.LLVMIsGlobalConstant(v.C) != 0 } func (v Value) SetGlobalConstant(gc bool) { C.LLVMSetGlobalConstant(v.C, boolToLLVMBool(gc)) } +func (v Value) IsVolatile() bool { return C.LLVMGetVolatile(v.C) != 0 } +func (v Value) SetVolatile(volatile bool) { C.LLVMSetVolatile(v.C, boolToLLVMBool(volatile)) } // Operations on aliases func AddAlias(m Module, t Type, aliasee Value, name string) (v Value) { @@ -1029,6 +1043,25 @@ func AddAlias(m Module, t Type, aliasee Value, name string) (v Value) { return } +// Operations on comdat +func (m Module) Comdat(name string) (c Comdat) { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + c.C = C.LLVMGetOrInsertComdat(m.C, cname) + return +} + +func (v Value) Comdat() (c Comdat) { c.C = C.LLVMGetComdat(v.C); return } +func (v Value) SetComdat(c Comdat) { C.LLVMSetComdat(v.C, c.C) } + +func (c Comdat) SelectionKind() ComdatSelectionKind { + return ComdatSelectionKind(C.LLVMGetComdatSelectionKind(c.C)) +} + +func (c Comdat) SetSelectionKind(k ComdatSelectionKind) { + C.LLVMSetComdatSelectionKind(c.C, (C.LLVMComdatSelectionKind)(k)) +} + // Operations on functions func AddFunction(m Module, name string, ft Type) (v Value) { cname := C.CString(name) @@ -1102,9 +1135,6 @@ func (v Value) AddTargetDependentFunctionAttr(attr, value string) { func (v Value) SetPersonality(p Value) { C.LLVMSetPersonalityFn(v.C, p.C) } -func (v Value) SetSubprogram(sp Metadata) { - C.LLVMSetSubprogram(v.C, sp.C) -} // Operations on parameters func (v Value) ParamsCount() int { return int(C.LLVMCountParams(v.C)) } @@ -1872,7 +1902,7 @@ func (pm PassManager) InitializeFunc() bool { return C.LLVMInitializeFunctionPas // See llvm::FunctionPassManager::run(Function&). func (pm PassManager) RunFunc(f Value) bool { return C.LLVMRunFunctionPassManager(pm.C, f.C) != 0 } -// Finalizes all of the function passes scheduled in in the function pass +// Finalizes 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::doFinalization. func (pm PassManager) FinalizeFunc() bool { return C.LLVMFinalizeFunctionPassManager(pm.C) != 0 } @@ -1881,11 +1911,3 @@ func (pm PassManager) FinalizeFunc() bool { return C.LLVMFinalizeFunctionPassMan // the module provider. // See llvm::PassManagerBase::~PassManagerBase. func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) } - -//------------------------------------------------------------------------- -// llvm.Metadata -//------------------------------------------------------------------------- - -func (md Metadata) ReplaceAllUsesWith(new Metadata) { - C.LLVMMetadataReplaceAllUsesWith(md.C, new.C) -} diff --git a/bindings/go/llvm/ir_test.go b/bindings/go/llvm/ir_test.go index fb39955ec10f..10f4968ba89f 100644 --- a/bindings/go/llvm/ir_test.go +++ b/bindings/go/llvm/ir_test.go @@ -89,6 +89,7 @@ func TestAttributes(t *testing.T) { "uwtable", "zeroext", "cold", + "nocf_check", } for _, name := range attrTests { @@ -111,7 +112,11 @@ func TestDebugLoc(t *testing.T) { }() file := d.CreateFile("dummy_file", "dummy_dir") voidInfo := d.CreateBasicType(DIBasicType{Name: "void"}) - typeInfo := d.CreateSubroutineType(DISubroutineType{file, []Metadata{voidInfo}}) + typeInfo := d.CreateSubroutineType(DISubroutineType{ + File: file, + Parameters: []Metadata{voidInfo}, + Flags: 0, + }) scope := d.CreateFunction(file, DIFunction{ Name: "foo", LinkageName: "foo", diff --git a/bindings/go/llvm/transforms_scalar.go b/bindings/go/llvm/transforms_scalar.go index 6492a85a7fae..cb46f6881859 100644 --- a/bindings/go/llvm/transforms_scalar.go +++ b/bindings/go/llvm/transforms_scalar.go @@ -15,6 +15,7 @@ package llvm /* #include "llvm-c/Transforms/Scalar.h" +#include "llvm-c/Transforms/Utils.h" */ import "C" diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index 3387c1ec52fe..b91d059e3b18 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -2619,7 +2619,7 @@ module PassManager : sig See the [llvm::FunctionPassManager::run] method. *) val run_function : llvalue -> [ `Function ] t -> bool - (** [finalize fpm] finalizes all of the function passes scheduled in in the + (** [finalize fpm] finalizes all of the function passes scheduled in the function pass manager [fpm]. Returns [true] if any of the passes modified the module, [false] otherwise. See the [llvm::FunctionPassManager::doFinalization] method. *) diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index 137b17f26bfb..77689edcf6d1 100644 --- a/bindings/ocaml/llvm/llvm_ocaml.c +++ b/bindings/ocaml/llvm/llvm_ocaml.c @@ -20,6 +20,7 @@ #include <string.h> #include "llvm-c/Core.h" #include "llvm-c/Support.h" +#include "llvm/Config/llvm-config.h" #include "caml/alloc.h" #include "caml/custom.h" #include "caml/memory.h" diff --git a/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml b/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml index 88831daf5194..f9f6be26d7f1 100644 --- a/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml +++ b/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml @@ -7,9 +7,6 @@ * *===----------------------------------------------------------------------===*) -external add_bb_vectorize - : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_bb_vectorize" external add_loop_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit = "llvm_add_loop_vectorize" diff --git a/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli b/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli index 23a68a28dadf..f9b4ce5aae58 100644 --- a/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli +++ b/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli @@ -12,11 +12,6 @@ This interface provides an OCaml API for LLVM vectorize transforms, the classes in the [LLVMVectorize] library. *) -(** See the [llvm::createBBVectorizePass] function. *) -external add_bb_vectorize - : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_bb_vectorize" - (** See the [llvm::createLoopVectorizePass] function. *) external add_loop_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit diff --git a/bindings/ocaml/transforms/vectorize/vectorize_ocaml.c b/bindings/ocaml/transforms/vectorize/vectorize_ocaml.c index 1c8104951c4a..dcd9231b5bf2 100644 --- a/bindings/ocaml/transforms/vectorize/vectorize_ocaml.c +++ b/bindings/ocaml/transforms/vectorize/vectorize_ocaml.c @@ -20,12 +20,6 @@ #include "caml/misc.h" /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_bb_vectorize(LLVMPassManagerRef PM) { - LLVMAddBBVectorizePass(PM); - return Val_unit; -} - -/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ CAMLprim value llvm_add_loop_vectorize(LLVMPassManagerRef PM) { LLVMAddLoopVectorizePass(PM); return Val_unit; diff --git a/bindings/python/llvm/core.py b/bindings/python/llvm/core.py index 47e81dd1a4f9..6b3da6d86792 100644 --- a/bindings/python/llvm/core.py +++ b/bindings/python/llvm/core.py @@ -456,6 +456,9 @@ def register_library(library): library.LLVMInitializeInstCombine.argtypes = [PassRegistry] library.LLVMInitializeInstCombine.restype = None + library.LLVMInitializeAggressiveInstCombiner.argtypes = [PassRegistry] + library.LLVMInitializeAggressiveInstCombiner.restype = None + library.LLVMInitializeIPO.argtypes = [PassRegistry] library.LLVMInitializeIPO.restype = None |