From ebe69fe11e48d322045d5949c83283927a0d790b Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Mon, 23 Mar 2015 12:10:34 -0700 Subject: Update aosp/master LLVM for rebase to r230699. Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9 --- bindings/go/llvm/DIBuilderBindings.cpp | 165 +++++++++++++----------- bindings/go/llvm/DIBuilderBindings.h | 166 +++++++++++++------------ bindings/go/llvm/IRBindings.cpp | 56 ++++++++- bindings/go/llvm/IRBindings.h | 36 ++++++ bindings/go/llvm/InstrumentationBindings.cpp | 12 +- bindings/go/llvm/InstrumentationBindings.h | 4 +- bindings/go/llvm/SupportBindings.cpp | 1 - bindings/go/llvm/dibuilder.go | 129 ++++++++++--------- bindings/go/llvm/executionengine.go | 36 ++++-- bindings/go/llvm/executionengine_test.go | 7 +- bindings/go/llvm/ir.go | 58 ++++++--- bindings/go/llvm/linker.go | 11 +- bindings/go/llvm/transforms_instrumentation.go | 11 +- 13 files changed, 426 insertions(+), 266 deletions(-) (limited to 'bindings/go') diff --git a/bindings/go/llvm/DIBuilderBindings.cpp b/bindings/go/llvm/DIBuilderBindings.cpp index 94fa96f..a7d75a3 100644 --- a/bindings/go/llvm/DIBuilderBindings.cpp +++ b/bindings/go/llvm/DIBuilderBindings.cpp @@ -12,21 +12,21 @@ //===----------------------------------------------------------------------===// #include "DIBuilderBindings.h" - -#include "llvm/IR/Module.h" +#include "IRBindings.h" #include "llvm/IR/DIBuilder.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Module.h" using namespace llvm; +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef) + namespace { -template -T unwrapDI(LLVMValueRef v) { +template T unwrapDI(LLVMMetadataRef v) { return v ? T(unwrap(v)) : T(); } } -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef) - LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) { Module *m = unwrap(mref); return wrap(new DIBuilder(*m)); @@ -39,49 +39,50 @@ void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) { void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); } -LLVMValueRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref, - unsigned Lang, const char *File, - const char *Dir, - const char *Producer, int Optimized, - const char *Flags, - unsigned RuntimeVersion) { +LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Dref, + unsigned Lang, const char *File, + const char *Dir, + const char *Producer, + int Optimized, const char *Flags, + unsigned RuntimeVersion) { DIBuilder *D = unwrap(Dref); DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized, Flags, RuntimeVersion); return wrap(CU); } -LLVMValueRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File, - const char *Dir) { +LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Dref, const char *File, + const char *Dir) { DIBuilder *D = unwrap(Dref); DIFile F = D->createFile(File, Dir); return wrap(F); } -LLVMValueRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref, - LLVMValueRef Scope, - LLVMValueRef File, unsigned Line, - unsigned Column) { +LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref, + LLVMMetadataRef Scope, + LLVMMetadataRef File, + unsigned Line, + unsigned Column) { DIBuilder *D = unwrap(Dref); DILexicalBlock LB = D->createLexicalBlock( unwrapDI(Scope), unwrapDI(File), Line, Column); return wrap(LB); } -LLVMValueRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, - LLVMValueRef Scope, - LLVMValueRef File, - unsigned Discriminator) { +LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, + LLVMMetadataRef Scope, + LLVMMetadataRef File, + unsigned Discriminator) { DIBuilder *D = unwrap(Dref); DILexicalBlockFile LBF = D->createLexicalBlockFile( unwrapDI(Scope), unwrapDI(File), Discriminator); return wrap(LBF); } -LLVMValueRef LLVMDIBuilderCreateFunction( - LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name, - const char *LinkageName, LLVMValueRef File, unsigned Line, - LLVMValueRef CompositeType, int IsLocalToUnit, int IsDefinition, +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, LLVMValueRef Func) { DIBuilder *D = unwrap(Dref); DISubprogram SP = D->createFunction( @@ -91,10 +92,10 @@ LLVMValueRef LLVMDIBuilderCreateFunction( return wrap(SP); } -LLVMValueRef LLVMDIBuilderCreateLocalVariable( - LLVMDIBuilderRef Dref, unsigned Tag, LLVMValueRef Scope, const char *Name, - LLVMValueRef File, unsigned Line, LLVMValueRef Ty, int AlwaysPreserve, - unsigned Flags, unsigned ArgNo) { +LLVMMetadataRef LLVMDIBuilderCreateLocalVariable( + LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope, + const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, + int AlwaysPreserve, unsigned Flags, unsigned ArgNo) { DIBuilder *D = unwrap(Dref); DIVariable V = D->createLocalVariable( Tag, unwrapDI(Scope), Name, unwrapDI(File), Line, @@ -102,39 +103,41 @@ LLVMValueRef LLVMDIBuilderCreateLocalVariable( return wrap(V); } -LLVMValueRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, - const char *Name, uint64_t SizeInBits, - uint64_t AlignInBits, - unsigned Encoding) { +LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, + const char *Name, + uint64_t SizeInBits, + uint64_t AlignInBits, + unsigned Encoding) { DIBuilder *D = unwrap(Dref); DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding); return wrap(T); } -LLVMValueRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, - LLVMValueRef PointeeType, - uint64_t SizeInBits, - uint64_t AlignInBits, - const char *Name) { +LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, + LLVMMetadataRef PointeeType, + uint64_t SizeInBits, + uint64_t AlignInBits, + const char *Name) { DIBuilder *D = unwrap(Dref); DIDerivedType T = D->createPointerType(unwrapDI(PointeeType), SizeInBits, AlignInBits, Name); return wrap(T); } -LLVMValueRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, - LLVMValueRef File, - LLVMValueRef ParameterTypes) { +LLVMMetadataRef +LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File, + LLVMMetadataRef ParameterTypes) { DIBuilder *D = unwrap(Dref); DICompositeType CT = D->createSubroutineType( unwrapDI(File), unwrapDI(ParameterTypes)); return wrap(CT); } -LLVMValueRef LLVMDIBuilderCreateStructType( - LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name, - LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits, - unsigned Flags, LLVMValueRef DerivedFrom, LLVMValueRef ElementTypes) { +LLVMMetadataRef LLVMDIBuilderCreateStructType( + LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, + uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom, + LLVMMetadataRef ElementTypes) { DIBuilder *D = unwrap(Dref); DICompositeType CT = D->createStructType( unwrapDI(Scope), Name, unwrapDI(File), Line, @@ -143,10 +146,12 @@ LLVMValueRef LLVMDIBuilderCreateStructType( return wrap(CT); } -LLVMValueRef LLVMDIBuilderCreateMemberType( - LLVMDIBuilderRef Dref, LLVMValueRef Scope, const char *Name, - LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits, - uint64_t OffsetInBits, unsigned Flags, LLVMValueRef Ty) { +LLVMMetadataRef +LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, + const char *Name, LLVMMetadataRef File, + unsigned Line, uint64_t SizeInBits, + uint64_t AlignInBits, uint64_t OffsetInBits, + unsigned Flags, LLVMMetadataRef Ty) { DIBuilder *D = unwrap(Dref); DIDerivedType DT = D->createMemberType( unwrapDI(Scope), Name, unwrapDI(File), Line, @@ -154,11 +159,11 @@ LLVMValueRef LLVMDIBuilderCreateMemberType( return wrap(DT); } -LLVMValueRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref, - uint64_t SizeInBits, - uint64_t AlignInBits, - LLVMValueRef ElementType, - LLVMValueRef Subscripts) { +LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref, + uint64_t SizeInBits, + uint64_t AlignInBits, + LLVMMetadataRef ElementType, + LLVMMetadataRef Subscripts) { DIBuilder *D = unwrap(Dref); DICompositeType CT = D->createArrayType(SizeInBits, AlignInBits, unwrapDI(ElementType), @@ -166,9 +171,10 @@ LLVMValueRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref, return wrap(CT); } -LLVMValueRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, LLVMValueRef Ty, - const char *Name, LLVMValueRef File, - unsigned Line, LLVMValueRef Context) { +LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, + LLVMMetadataRef Ty, const char *Name, + LLVMMetadataRef File, unsigned Line, + LLVMMetadataRef Context) { DIBuilder *D = unwrap(Dref); DIDerivedType DT = D->createTypedef(unwrapDI(Ty), Name, unwrapDI(File), Line, @@ -176,34 +182,35 @@ LLVMValueRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, LLVMValueRef Ty, return wrap(DT); } -LLVMValueRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, int64_t Lo, - int64_t Count) { +LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref, + int64_t Lo, int64_t Count) { DIBuilder *D = unwrap(Dref); DISubrange S = D->getOrCreateSubrange(Lo, Count); return wrap(S); } -LLVMValueRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref, - LLVMValueRef *Data, size_t Length) { +LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref, + LLVMMetadataRef *Data, + size_t Length) { DIBuilder *D = unwrap(Dref); - Value **DataValue = unwrap(Data); - ArrayRef Elements(DataValue, Length); + Metadata **DataValue = unwrap(Data); + ArrayRef Elements(DataValue, Length); DIArray A = D->getOrCreateArray(Elements); return wrap(A); } -LLVMValueRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref, - LLVMValueRef *Data, - size_t Length) { +LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref, + LLVMMetadataRef *Data, + size_t Length) { DIBuilder *D = unwrap(Dref); - Value **DataValue = unwrap(Data); - ArrayRef Elements(DataValue, Length); + Metadata **DataValue = unwrap(Data); + ArrayRef Elements(DataValue, Length); DITypeArray A = D->getOrCreateTypeArray(Elements); return wrap(A); } -LLVMValueRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, int64_t *Addr, - size_t Length) { +LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, + int64_t *Addr, size_t Length) { DIBuilder *D = unwrap(Dref); DIExpression Expr = D->createExpression(ArrayRef(Addr, Length)); return wrap(Expr); @@ -211,8 +218,8 @@ LLVMValueRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, int64_t *Addr, LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref, LLVMValueRef Storage, - LLVMValueRef VarInfo, - LLVMValueRef Expr, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, LLVMBasicBlockRef Block) { DIBuilder *D = unwrap(Dref); Instruction *Instr = @@ -220,3 +227,15 @@ LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref, unwrapDI(Expr), unwrap(Block)); return wrap(Instr); } + +LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref, + LLVMValueRef Val, uint64_t Offset, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, + LLVMBasicBlockRef Block) { + DIBuilder *D = unwrap(Dref); + Instruction *Instr = D->insertDbgValueIntrinsic( + unwrap(Val), Offset, unwrapDI(VarInfo), + unwrapDI(Expr), unwrap(Block)); + return wrap(Instr); +} diff --git a/bindings/go/llvm/DIBuilderBindings.h b/bindings/go/llvm/DIBuilderBindings.h index e6fe02a..e268b3c 100644 --- a/bindings/go/llvm/DIBuilderBindings.h +++ b/bindings/go/llvm/DIBuilderBindings.h @@ -14,6 +14,7 @@ #ifndef LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H #define LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H +#include "IRBindings.h" #include "llvm-c/Core.h" #ifdef __cplusplus @@ -31,93 +32,104 @@ LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef m); void LLVMDIBuilderDestroy(LLVMDIBuilderRef d); void LLVMDIBuilderFinalize(LLVMDIBuilderRef d); -LLVMValueRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef D, - unsigned Language, const char *File, - const char *Dir, - const char *Producer, int Optimized, - const char *Flags, - unsigned RuntimeVersion); - -LLVMValueRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef D, const char *File, - const char *Dir); - -LLVMValueRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef D, - LLVMValueRef Scope, - LLVMValueRef File, unsigned Line, - unsigned Column); - -LLVMValueRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef D, - LLVMValueRef Scope, - LLVMValueRef File, - unsigned Discriminator); - -LLVMValueRef LLVMDIBuilderCreateFunction( - LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, - const char *LinkageName, LLVMValueRef File, unsigned Line, - LLVMValueRef CompositeType, int IsLocalToUnit, int IsDefinition, +LLVMMetadataRef +LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef D, unsigned Language, + const char *File, const char *Dir, + const char *Producer, int Optimized, + const char *Flags, unsigned RuntimeVersion); + +LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef D, const char *File, + const char *Dir); + +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, LLVMValueRef Function); -LLVMValueRef LLVMDIBuilderCreateLocalVariable( - LLVMDIBuilderRef D, unsigned Tag, LLVMValueRef Scope, const char *Name, - LLVMValueRef File, unsigned Line, LLVMValueRef Ty, int AlwaysPreserve, +LLVMMetadataRef LLVMDIBuilderCreateLocalVariable( + LLVMDIBuilderRef D, unsigned Tag, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, unsigned Flags, unsigned ArgNo); -LLVMValueRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef D, const char *Name, - uint64_t SizeInBits, - uint64_t AlignInBits, - unsigned Encoding); - -LLVMValueRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef D, - LLVMValueRef PointeeType, - uint64_t SizeInBits, - uint64_t AlignInBits, - const char *Name); - -LLVMValueRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef D, - LLVMValueRef File, - LLVMValueRef ParameterTypes); - -LLVMValueRef LLVMDIBuilderCreateStructType( - LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, LLVMValueRef File, - unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, - LLVMValueRef DerivedFrom, LLVMValueRef ElementTypes); - -LLVMValueRef LLVMDIBuilderCreateMemberType( - LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, LLVMValueRef File, - unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits, - uint64_t OffsetInBits, unsigned Flags, LLVMValueRef Ty); - -LLVMValueRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef D, - uint64_t SizeInBits, - uint64_t AlignInBits, - LLVMValueRef ElementType, - LLVMValueRef Subscripts); - -LLVMValueRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef D, LLVMValueRef Ty, - const char *Name, LLVMValueRef File, - unsigned Line, LLVMValueRef Context); - -LLVMValueRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef D, int64_t Lo, - int64_t Count); - -LLVMValueRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef D, - LLVMValueRef *Data, size_t Length); - -LLVMValueRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef D, - LLVMValueRef *Data, - size_t Length); - -LLVMValueRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref, int64_t *Addr, - size_t Length); +LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef D, + const char *Name, + uint64_t SizeInBits, + uint64_t AlignInBits, + unsigned Encoding); + +LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef D, + LLVMMetadataRef PointeeType, + uint64_t SizeInBits, + uint64_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, + uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom, + LLVMMetadataRef ElementTypes); + +LLVMMetadataRef +LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef D, LLVMMetadataRef Scope, + const char *Name, LLVMMetadataRef File, + unsigned Line, uint64_t SizeInBits, + uint64_t AlignInBits, uint64_t OffsetInBits, + unsigned Flags, LLVMMetadataRef Ty); + +LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef D, + uint64_t SizeInBits, + uint64_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, - LLVMValueRef VarInfo, - LLVMValueRef Expr, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, LLVMBasicBlockRef Block); +LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef D, LLVMValueRef Val, + uint64_t Offset, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, + LLVMBasicBlockRef Block); + #ifdef __cplusplus -} // extern "C" +} // extern "C" #endif #endif diff --git a/bindings/go/llvm/IRBindings.cpp b/bindings/go/llvm/IRBindings.cpp index 67a54a2..fb451ef 100644 --- a/bindings/go/llvm/IRBindings.cpp +++ b/bindings/go/llvm/IRBindings.cpp @@ -12,9 +12,12 @@ //===----------------------------------------------------------------------===// #include "IRBindings.h" - #include "llvm/IR/Attributes.h" +#include "llvm/IR/DebugLoc.h" #include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" using namespace llvm; @@ -45,3 +48,54 @@ void LLVMRemoveFunctionAttr2(LLVMValueRef Fn, uint64_t PA) { AttributeSet::FunctionIndex, B)); Func->setAttributes(PALnew); } + +LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef C) { + return wrap(ConstantAsMetadata::get(unwrap(C))); +} + +LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen) { + return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen))); +} + +LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs, + unsigned Count) { + return wrap( + MDNode::get(*unwrap(C), ArrayRef(unwrap(MDs), Count))); +} + +LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs, + unsigned Count) { + return wrap(MDTuple::getTemporary(*unwrap(C), + ArrayRef(unwrap(MDs), Count)) + .release()); +} + +void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name, + LLVMMetadataRef Val) { + NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name); + if (!N) + return; + if (!Val) + return; + N->addOperand(unwrap(Val)); +} + +void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) { + MDNode *N = MD ? unwrap(MD) : nullptr; + unwrap(Inst)->setMetadata(KindID, N); +} + +void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) { + auto *Node = unwrap(MD); + assert(Node->isTemporary() && "Expected temporary node"); + Node->replaceAllUsesWith(unwrap(New)); + MDNode::deleteTemporary(Node); +} + +void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, + unsigned Col, LLVMMetadataRef Scope, + LLVMMetadataRef InlinedAt) { + unwrap(Bref)->SetCurrentDebugLocation( + DebugLoc::get(Line, Col, Scope ? unwrap(Scope) : nullptr, + InlinedAt ? unwrap(InlinedAt) : nullptr)); +} diff --git a/bindings/go/llvm/IRBindings.h b/bindings/go/llvm/IRBindings.h index cc63e4e..a53e178 100644 --- a/bindings/go/llvm/IRBindings.h +++ b/bindings/go/llvm/IRBindings.h @@ -15,12 +15,19 @@ #define LLVM_BINDINGS_GO_LLVM_IRBINDINGS_H #include "llvm-c/Core.h" +#ifdef __cplusplus +#include "llvm/IR/Metadata.h" +#include "llvm/Support/CBindingWrapping.h" +#endif + #include #ifdef __cplusplus extern "C" { #endif +typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; + // These functions duplicate the LLVM*FunctionAttr functions in the stable C // API. We cannot use the existing functions because they take 32-bit attribute // values, and the Go bindings expose all of the LLVM attributes, some of which @@ -30,8 +37,37 @@ void LLVMAddFunctionAttr2(LLVMValueRef Fn, uint64_t PA); uint64_t LLVMGetFunctionAttr2(LLVMValueRef Fn); void LLVMRemoveFunctionAttr2(LLVMValueRef Fn, uint64_t PA); +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); + #ifdef __cplusplus } + +namespace llvm { + +DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef) + +inline Metadata **unwrap(LLVMMetadataRef *Vals) { + return reinterpret_cast(Vals); +} + +} + #endif #endif diff --git a/bindings/go/llvm/InstrumentationBindings.cpp b/bindings/go/llvm/InstrumentationBindings.cpp index b604abb..8b7bafa 100644 --- a/bindings/go/llvm/InstrumentationBindings.cpp +++ b/bindings/go/llvm/InstrumentationBindings.cpp @@ -12,10 +12,9 @@ //===----------------------------------------------------------------------===// #include "InstrumentationBindings.h" - #include "llvm-c/Core.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" -#include "llvm/PassManager.h" #include "llvm/Transforms/Instrumentation.h" using namespace llvm; @@ -37,6 +36,11 @@ void LLVMAddMemorySanitizerPass(LLVMPassManagerRef PM) { } void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM, - const char *ABIListFile) { - unwrap(PM)->add(createDataFlowSanitizerPass(ABIListFile)); + int ABIListFilesNum, + const char **ABIListFiles) { + std::vector ABIListFilesVec; + for (int i = 0; i != ABIListFilesNum; ++i) { + ABIListFilesVec.push_back(ABIListFiles[i]); + } + unwrap(PM)->add(createDataFlowSanitizerPass(ABIListFilesVec)); } diff --git a/bindings/go/llvm/InstrumentationBindings.h b/bindings/go/llvm/InstrumentationBindings.h index e8dbd59..97af2d5 100644 --- a/bindings/go/llvm/InstrumentationBindings.h +++ b/bindings/go/llvm/InstrumentationBindings.h @@ -28,8 +28,8 @@ void LLVMAddAddressSanitizerFunctionPass(LLVMPassManagerRef PM); void LLVMAddAddressSanitizerModulePass(LLVMPassManagerRef PM); void LLVMAddThreadSanitizerPass(LLVMPassManagerRef PM); void LLVMAddMemorySanitizerPass(LLVMPassManagerRef PM); -void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM, - const char *ABIListFile); +void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM, int ABIListFilesNum, + const char **ABIListFiles); #ifdef __cplusplus } diff --git a/bindings/go/llvm/SupportBindings.cpp b/bindings/go/llvm/SupportBindings.cpp index df5f865..5e251b7 100644 --- a/bindings/go/llvm/SupportBindings.cpp +++ b/bindings/go/llvm/SupportBindings.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "SupportBindings.h" - #include "llvm/Support/DynamicLibrary.h" #include #include diff --git a/bindings/go/llvm/dibuilder.go b/bindings/go/llvm/dibuilder.go index 1d07e98..3b1a1a6 100644 --- a/bindings/go/llvm/dibuilder.go +++ b/bindings/go/llvm/dibuilder.go @@ -121,7 +121,7 @@ type DICompileUnit struct { } // CreateCompileUnit creates compile unit debug metadata. -func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Value { +func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata { file := C.CString(cu.File) defer C.free(unsafe.Pointer(file)) dir := C.CString(cu.Dir) @@ -139,28 +139,28 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Value { flags, C.unsigned(cu.RuntimeVersion), ) - return Value{C: result} + return Metadata{C: result} } // CreateCompileUnit creates file debug metadata. -func (d *DIBuilder) CreateFile(filename, dir string) Value { +func (d *DIBuilder) CreateFile(filename, dir string) Metadata { cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) cdir := C.CString(dir) defer C.free(unsafe.Pointer(cdir)) result := C.LLVMDIBuilderCreateFile(d.ref, cfilename, cdir) - return Value{C: result} + return Metadata{C: result} } // DILexicalBlock holds the values for creating lexical block debug metadata. type DILexicalBlock struct { - File Value + File Metadata Line int Column int } // CreateCompileUnit creates lexical block debug metadata. -func (d *DIBuilder) CreateLexicalBlock(diScope Value, b DILexicalBlock) Value { +func (d *DIBuilder) CreateLexicalBlock(diScope Metadata, b DILexicalBlock) Metadata { result := C.LLVMDIBuilderCreateLexicalBlock( d.ref, diScope.C, @@ -168,22 +168,22 @@ func (d *DIBuilder) CreateLexicalBlock(diScope Value, b DILexicalBlock) Value { C.unsigned(b.Line), C.unsigned(b.Column), ) - return Value{C: result} + return Metadata{C: result} } -func (d *DIBuilder) CreateLexicalBlockFile(diScope Value, diFile Value, discriminator int) Value { +func (d *DIBuilder) CreateLexicalBlockFile(diScope Metadata, diFile Metadata, discriminator int) Metadata { result := C.LLVMDIBuilderCreateLexicalBlockFile(d.ref, diScope.C, diFile.C, C.unsigned(discriminator)) - return Value{C: result} + return Metadata{C: result} } // DIFunction holds the values for creating function debug metadata. type DIFunction struct { Name string LinkageName string - File Value + File Metadata Line int - Type Value + Type Metadata LocalToUnit bool IsDefinition bool ScopeLine int @@ -193,7 +193,7 @@ type DIFunction struct { } // CreateCompileUnit creates function debug metadata. -func (d *DIBuilder) CreateFunction(diScope Value, f DIFunction) Value { +func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata { name := C.CString(f.Name) defer C.free(unsafe.Pointer(name)) linkageName := C.CString(f.LinkageName) @@ -213,16 +213,16 @@ func (d *DIBuilder) CreateFunction(diScope Value, f DIFunction) Value { boolToCInt(f.Optimized), f.Function.C, ) - return Value{C: result} + return Metadata{C: result} } // DILocalVariable holds the values for creating local variable debug metadata. type DILocalVariable struct { Tag dwarf.Tag Name string - File Value + File Metadata Line int - Type Value + Type Metadata AlwaysPreserve bool Flags int @@ -232,7 +232,7 @@ type DILocalVariable struct { } // CreateLocalVariable creates local variable debug metadata. -func (d *DIBuilder) CreateLocalVariable(scope Value, v DILocalVariable) Value { +func (d *DIBuilder) CreateLocalVariable(scope Metadata, v DILocalVariable) Metadata { name := C.CString(v.Name) defer C.free(unsafe.Pointer(name)) result := C.LLVMDIBuilderCreateLocalVariable( @@ -247,7 +247,7 @@ func (d *DIBuilder) CreateLocalVariable(scope Value, v DILocalVariable) Value { C.unsigned(v.Flags), C.unsigned(v.ArgNo), ) - return Value{C: result} + return Metadata{C: result} } // DIBasicType holds the values for creating basic type debug metadata. @@ -259,7 +259,7 @@ type DIBasicType struct { } // CreateBasicType creates basic type debug metadata. -func (d *DIBuilder) CreateBasicType(t DIBasicType) Value { +func (d *DIBuilder) CreateBasicType(t DIBasicType) Metadata { name := C.CString(t.Name) defer C.free(unsafe.Pointer(name)) result := C.LLVMDIBuilderCreateBasicType( @@ -269,19 +269,19 @@ func (d *DIBuilder) CreateBasicType(t DIBasicType) Value { C.uint64_t(t.AlignInBits), C.unsigned(t.Encoding), ) - return Value{C: result} + return Metadata{C: result} } // DIPointerType holds the values for creating pointer type debug metadata. type DIPointerType struct { - Pointee Value + Pointee Metadata SizeInBits uint64 AlignInBits uint64 // optional Name string // optional } // CreateBasicType creates basic type debug metadata. -func (d *DIBuilder) CreatePointerType(t DIPointerType) Value { +func (d *DIBuilder) CreatePointerType(t DIPointerType) Metadata { name := C.CString(t.Name) defer C.free(unsafe.Pointer(name)) result := C.LLVMDIBuilderCreatePointerType( @@ -291,40 +291,40 @@ func (d *DIBuilder) CreatePointerType(t DIPointerType) Value { C.uint64_t(t.AlignInBits), name, ) - return Value{C: result} + return Metadata{C: result} } // DISubroutineType holds the values for creating subroutine type debug metadata. type DISubroutineType struct { // File is the file in which the subroutine type is defined. - File Value + File Metadata // Parameters contains the subroutine parameter types, // including the return type at the 0th index. - Parameters []Value + Parameters []Metadata } // CreateSubroutineType creates subroutine type debug metadata. -func (d *DIBuilder) CreateSubroutineType(t DISubroutineType) Value { +func (d *DIBuilder) CreateSubroutineType(t DISubroutineType) Metadata { params := d.getOrCreateTypeArray(t.Parameters) result := C.LLVMDIBuilderCreateSubroutineType(d.ref, t.File.C, params.C) - return Value{C: result} + return Metadata{C: result} } // DIStructType holds the values for creating struct type debug metadata. type DIStructType struct { Name string - File Value + File Metadata Line int SizeInBits uint64 AlignInBits uint64 Flags int - DerivedFrom Value - Elements []Value + DerivedFrom Metadata + Elements []Metadata } // CreateStructType creates struct type debug metadata. -func (d *DIBuilder) CreateStructType(scope Value, t DIStructType) Value { +func (d *DIBuilder) CreateStructType(scope Metadata, t DIStructType) Metadata { elements := d.getOrCreateArray(t.Elements) name := C.CString(t.Name) defer C.free(unsafe.Pointer(name)) @@ -340,23 +340,23 @@ func (d *DIBuilder) CreateStructType(scope Value, t DIStructType) Value { t.DerivedFrom.C, elements.C, ) - return Value{C: result} + return Metadata{C: result} } // DIMemberType holds the values for creating member type debug metadata. type DIMemberType struct { Name string - File Value + File Metadata Line int SizeInBits uint64 AlignInBits uint64 OffsetInBits uint64 Flags int - Type Value + Type Metadata } // CreateMemberType creates struct type debug metadata. -func (d *DIBuilder) CreateMemberType(scope Value, t DIMemberType) Value { +func (d *DIBuilder) CreateMemberType(scope Metadata, t DIMemberType) Metadata { name := C.CString(t.Name) defer C.free(unsafe.Pointer(name)) result := C.LLVMDIBuilderCreateMemberType( @@ -371,7 +371,7 @@ func (d *DIBuilder) CreateMemberType(scope Value, t DIMemberType) Value { C.unsigned(t.Flags), t.Type.C, ) - return Value{C: result} + return Metadata{C: result} } // DISubrange describes an integer value range. @@ -384,13 +384,13 @@ type DISubrange struct { type DIArrayType struct { SizeInBits uint64 AlignInBits uint64 - ElementType Value + ElementType Metadata Subscripts []DISubrange } // CreateArrayType creates struct type debug metadata. -func (d *DIBuilder) CreateArrayType(t DIArrayType) Value { - subscriptsSlice := make([]Value, len(t.Subscripts)) +func (d *DIBuilder) CreateArrayType(t DIArrayType) Metadata { + subscriptsSlice := make([]Metadata, len(t.Subscripts)) for i, s := range t.Subscripts { subscriptsSlice[i] = d.getOrCreateSubrange(s.Lo, s.Count) } @@ -402,20 +402,20 @@ func (d *DIBuilder) CreateArrayType(t DIArrayType) Value { t.ElementType.C, subscripts.C, ) - return Value{C: result} + return Metadata{C: result} } // DITypedef holds the values for creating typedef type debug metadata. type DITypedef struct { - Type Value + Type Metadata Name string - File Value + File Metadata Line int - Context Value + Context Metadata } // CreateTypedef creates typedef type debug metadata. -func (d *DIBuilder) CreateTypedef(t DITypedef) Value { +func (d *DIBuilder) CreateTypedef(t DITypedef) Metadata { name := C.CString(t.Name) defer C.free(unsafe.Pointer(name)) result := C.LLVMDIBuilderCreateTypedef( @@ -426,64 +426,63 @@ func (d *DIBuilder) CreateTypedef(t DITypedef) Value { C.unsigned(t.Line), t.Context.C, ) - return Value{C: result} + return Metadata{C: result} } // getOrCreateSubrange gets a metadata node for the specified subrange, // creating if required. -func (d *DIBuilder) getOrCreateSubrange(lo, count int64) Value { +func (d *DIBuilder) getOrCreateSubrange(lo, count int64) Metadata { result := C.LLVMDIBuilderGetOrCreateSubrange(d.ref, C.int64_t(lo), C.int64_t(count)) - return Value{C: result} + return Metadata{C: result} } // getOrCreateArray gets a metadata node containing the specified values, // creating if required. -func (d *DIBuilder) getOrCreateArray(values []Value) Value { +func (d *DIBuilder) getOrCreateArray(values []Metadata) Metadata { if len(values) == 0 { - return Value{} - } - var data *C.LLVMValueRef - length := len(values) - if length > 0 { - data = &values[0].C + return Metadata{} } + data, length := llvmMetadataRefs(values) result := C.LLVMDIBuilderGetOrCreateArray(d.ref, data, C.size_t(length)) - return Value{C: result} + return Metadata{C: result} } // getOrCreateTypeArray gets a metadata node for a type array containing the // specified values, creating if required. -func (d *DIBuilder) getOrCreateTypeArray(values []Value) Value { +func (d *DIBuilder) getOrCreateTypeArray(values []Metadata) Metadata { if len(values) == 0 { - return Value{} - } - var data *C.LLVMValueRef - length := len(values) - if length > 0 { - data = &values[0].C + return Metadata{} } + data, length := llvmMetadataRefs(values) result := C.LLVMDIBuilderGetOrCreateTypeArray(d.ref, data, C.size_t(length)) - return Value{C: result} + return Metadata{C: result} } // CreateExpression creates a new descriptor for the specified // variable which has a complex address expression for its address. -func (d *DIBuilder) CreateExpression(addr []int64) Value { +func (d *DIBuilder) CreateExpression(addr []int64) Metadata { var data *C.int64_t if len(addr) > 0 { data = (*C.int64_t)(unsafe.Pointer(&addr[0])) } result := C.LLVMDIBuilderCreateExpression(d.ref, data, C.size_t(len(addr))) - return Value{C: result} + return Metadata{C: result} } // 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, diVarInfo, expr Value, bb BasicBlock) Value { +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) 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, offset uint64, bb BasicBlock) Value { + result := C.LLVMDIBuilderInsertValueAtEnd(d.ref, v.C, C.uint64_t(offset), diVarInfo.C, expr.C, bb.C) + return Value{C: result} +} + func boolToCInt(v bool) C.int { if v { return 1 diff --git a/bindings/go/llvm/executionengine.go b/bindings/go/llvm/executionengine.go index 26b7524..94d4e83 100644 --- a/bindings/go/llvm/executionengine.go +++ b/bindings/go/llvm/executionengine.go @@ -30,11 +30,25 @@ type GenericValue struct { type ExecutionEngine struct { C C.LLVMExecutionEngineRef } + type MCJITCompilerOptions struct { - OptLevel uint - CodeModel CodeModel - NoFramePointerElim bool - EnableFastISel bool + C C.struct_LLVMMCJITCompilerOptions +} + +func (options *MCJITCompilerOptions) SetMCJITOptimizationLevel(level uint) { + options.C.OptLevel = C.uint(level) +} + +func (options *MCJITCompilerOptions) SetMCJITNoFramePointerElim(nfp bool) { + options.C.NoFramePointerElim = boolToLLVMBool(nfp) +} + +func (options *MCJITCompilerOptions) SetMCJITEnableFastISel(fastisel bool) { + options.C.EnableFastISel = boolToLLVMBool(fastisel) +} + +func (options *MCJITCompilerOptions) SetMCJITCodeModel(CodeModel CodeModel) { + options.C.CodeModel = C.LLVMCodeModel(CodeModel) } // helpers @@ -96,15 +110,15 @@ func NewInterpreter(m Module) (ee ExecutionEngine, err error) { return } +func NewMCJITCompilerOptions() MCJITCompilerOptions { + var options C.struct_LLVMMCJITCompilerOptions + C.LLVMInitializeMCJITCompilerOptions(&options, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{}))) + return MCJITCompilerOptions{options} +} + func NewMCJITCompiler(m Module, options MCJITCompilerOptions) (ee ExecutionEngine, err error) { var cmsg *C.char - copts := C.struct_LLVMMCJITCompilerOptions{ - OptLevel: C.unsigned(options.OptLevel), - CodeModel: C.LLVMCodeModel(options.CodeModel), - NoFramePointerElim: boolToLLVMBool(options.NoFramePointerElim), - EnableFastISel: boolToLLVMBool(options.EnableFastISel), - } - fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &copts, C.size_t(unsafe.Sizeof(copts)), &cmsg) + fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &options.C, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})), &cmsg) if fail != 0 { ee.C = nil err = errors.New(C.GoString(cmsg)) diff --git a/bindings/go/llvm/executionengine_test.go b/bindings/go/llvm/executionengine_test.go index 1a3fd45..2b6a3ca 100644 --- a/bindings/go/llvm/executionengine_test.go +++ b/bindings/go/llvm/executionengine_test.go @@ -66,7 +66,12 @@ func TestFactorial(t *testing.T) { return } - engine, err := NewMCJITCompiler(mod, MCJITCompilerOptions{OptLevel: 2}) + options := NewMCJITCompilerOptions() + options.SetMCJITOptimizationLevel(2) + options.SetMCJITEnableFastISel(true) + options.SetMCJITNoFramePointerElim(true) + options.SetMCJITCodeModel(CodeModelJITDefault) + engine, err := NewMCJITCompiler(mod, options) if err != nil { t.Errorf("Error creating JIT: %s", err) return diff --git a/bindings/go/llvm/ir.go b/bindings/go/llvm/ir.go index 7834f5c..e5916a1 100644 --- a/bindings/go/llvm/ir.go +++ b/bindings/go/llvm/ir.go @@ -55,6 +55,9 @@ type ( Use struct { C C.LLVMUseRef } + Metadata struct { + C C.LLVMMetadataRef + } Attribute uint64 Opcode C.LLVMOpcode TypeKind C.LLVMTypeKind @@ -80,6 +83,9 @@ func (c Use) IsNil() bool { return c.C == nil } // helpers func llvmTypeRefPtr(t *Type) *C.LLVMTypeRef { return (*C.LLVMTypeRef)(unsafe.Pointer(t)) } func llvmValueRefPtr(t *Value) *C.LLVMValueRef { return (*C.LLVMValueRef)(unsafe.Pointer(t)) } +func llvmMetadataRefPtr(t *Metadata) *C.LLVMMetadataRef { + return (*C.LLVMMetadataRef)(unsafe.Pointer(t)) +} func llvmBasicBlockRefPtr(t *BasicBlock) *C.LLVMBasicBlockRef { return (*C.LLVMBasicBlockRef)(unsafe.Pointer(t)) } @@ -99,6 +105,15 @@ func llvmValueRefs(values []Value) (*C.LLVMValueRef, C.unsigned) { return pt, ptlen } +func llvmMetadataRefs(mds []Metadata) (*C.LLVMMetadataRef, C.unsigned) { + var pt *C.LLVMMetadataRef + ptlen := C.unsigned(len(mds)) + if ptlen > 0 { + pt = llvmMetadataRefPtr(&mds[0]) + } + return pt, ptlen +} + //------------------------------------------------------------------------- // llvm.Attribute //------------------------------------------------------------------------- @@ -421,10 +436,10 @@ func (m Module) SetInlineAsm(asm string) { C.LLVMSetModuleInlineAsm(m.C, casm) } -func (m Module) AddNamedMetadataOperand(name string, operand Value) { +func (m Module) AddNamedMetadataOperand(name string, operand Metadata) { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) - C.LLVMAddNamedMetadataOperand(m.C, cname, operand.C) + C.LLVMAddNamedMetadataOperand2(m.C, cname, operand.C) } func (m Module) Context() (c Context) { @@ -628,8 +643,8 @@ func (v Value) Metadata(kind int) (rv Value) { rv.C = C.LLVMGetMetadata(v.C, C.unsigned(kind)) return } -func (v Value) SetMetadata(kind int, node Value) { - C.LLVMSetMetadata(v.C, C.unsigned(kind), node.C) +func (v Value) SetMetadata(kind int, node Metadata) { + C.LLVMSetMetadata2(v.C, C.unsigned(kind), node.C) } // Conversion functions. @@ -723,26 +738,24 @@ func (v Value) IsUndef() bool { return C.LLVMIsUndef(v.C) != 0 } func ConstPointerNull(t Type) (v Value) { v.C = C.LLVMConstPointerNull(t.C); return } // Operations on metadata -func (c Context) MDString(str string) (v Value) { +func (c Context) MDString(str string) (md Metadata) { cstr := C.CString(str) defer C.free(unsafe.Pointer(cstr)) - v.C = C.LLVMMDStringInContext(c.C, cstr, C.unsigned(len(str))) + md.C = C.LLVMMDString2(c.C, cstr, C.unsigned(len(str))) return } -func MDString(str string) (v Value) { - cstr := C.CString(str) - defer C.free(unsafe.Pointer(cstr)) - v.C = C.LLVMMDString(cstr, C.unsigned(len(str))) +func (c Context) MDNode(mds []Metadata) (md Metadata) { + ptr, nvals := llvmMetadataRefs(mds) + md.C = C.LLVMMDNode2(c.C, ptr, nvals) return } -func (c Context) MDNode(vals []Value) (v Value) { - ptr, nvals := llvmValueRefs(vals) - v.C = C.LLVMMDNodeInContext(c.C, ptr, nvals) +func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) { + ptr, nvals := llvmMetadataRefs(mds) + md.C = C.LLVMTemporaryMDNode(c.C, ptr, nvals) return } -func MDNode(vals []Value) (v Value) { - ptr, nvals := llvmValueRefs(vals) - v.C = C.LLVMMDNode(ptr, nvals) +func (v Value) ConstantAsMetadata() (md Metadata) { + md.C = C.LLVMConstantAsMetadata(v.C) return } @@ -1188,8 +1201,9 @@ func (b Builder) InsertWithName(instr Value, name string) { func (b Builder) Dispose() { C.LLVMDisposeBuilder(b.C) } // Metadata -func (b Builder) SetCurrentDebugLocation(v Value) { C.LLVMSetCurrentDebugLocation(b.C, v.C) } -func (b Builder) CurrentDebugLocation() (v Value) { v.C = C.LLVMGetCurrentDebugLocation(b.C); return } +func (b Builder) SetCurrentDebugLocation(line, col uint, scope, inlinedAt Metadata) { + C.LLVMSetCurrentDebugLocation2(b.C, C.unsigned(line), C.unsigned(col), scope.C, inlinedAt.C) +} func (b Builder) SetInstDebugLocation(v Value) { C.LLVMSetInstDebugLocation(b.C, v.C) } func (b Builder) InsertDeclare(module Module, storage Value, md Value) Value { f := module.NamedFunction("llvm.dbg.declare") @@ -1822,3 +1836,11 @@ 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/linker.go b/bindings/go/llvm/linker.go index 31e9ad2..64d794e 100644 --- a/bindings/go/llvm/linker.go +++ b/bindings/go/llvm/linker.go @@ -20,16 +20,9 @@ package llvm import "C" import "errors" -type LinkerMode C.LLVMLinkerMode - -const ( - LinkerDestroySource = C.LLVMLinkerDestroySource - LinkerPreserveSource = C.LLVMLinkerPreserveSource -) - -func LinkModules(Dest, Src Module, Mode LinkerMode) error { +func LinkModules(Dest, Src Module) error { var cmsg *C.char - failed := C.LLVMLinkModules(Dest.C, Src.C, C.LLVMLinkerMode(Mode), &cmsg) + failed := C.LLVMLinkModules(Dest.C, Src.C, 0, &cmsg) if failed != 0 { err := errors.New(C.GoString(cmsg)) C.LLVMDisposeMessage(cmsg) diff --git a/bindings/go/llvm/transforms_instrumentation.go b/bindings/go/llvm/transforms_instrumentation.go index 9b191b2..73e2732 100644 --- a/bindings/go/llvm/transforms_instrumentation.go +++ b/bindings/go/llvm/transforms_instrumentation.go @@ -36,8 +36,11 @@ func (pm PassManager) AddMemorySanitizerPass() { C.LLVMAddMemorySanitizerPass(pm.C) } -func (pm PassManager) AddDataFlowSanitizerPass(abilist string) { - cabilist := C.CString(abilist) - defer C.free(unsafe.Pointer(cabilist)) - C.LLVMAddDataFlowSanitizerPass(pm.C, cabilist) +func (pm PassManager) AddDataFlowSanitizerPass(abilist []string) { + abiliststrs := make([]*C.char, len(abilist)) + for i, arg := range abilist { + abiliststrs[i] = C.CString(arg) + defer C.free(unsafe.Pointer(abiliststrs[i])) + } + C.LLVMAddDataFlowSanitizerPass(pm.C, C.int(len(abilist)), &abiliststrs[0]) } -- cgit v1.1