diff --git a/Makefile b/Makefile index a8c4c0a..7764369 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ NIMFLAGS=--debuginfo --linedir:on NLVMFLAGS= --debuginfo --linedir:on -LLVM_MAJ=16 +LLVM_MAJ=17 LLVM_MIN=0 LLVM_PAT=2 diff --git a/llvm/llvm.nim b/llvm/llvm.nim index a62a0fc..c43bfa5 100644 --- a/llvm/llvm.nim +++ b/llvm/llvm.nim @@ -5,7 +5,7 @@ import strformat const - LLVMMaj = 16 + LLVMMaj = 17 LLVMMin = 0 LLVMPat = 2 LLVMVersion* = fmt"{LLVMMaj}.{LLVMMin}.{LLVMPat}" @@ -59,11 +59,9 @@ type OpaqueBuilder{.pure, final.} = object OpaqueModuleProvider{.pure, final.} = object OpaquePassManager{.pure, final.} = object - OpaquePassRegistry{.pure, final.} = object OpaqueUse{.pure, final.} = object OpaqueDiagnosticInfo{.pure, final.} = object OpaqueTargetMachine{.pure, final.} = object - OpaquePassManagerBuilder{.pure, final.} = object OpaqueMetaData{.pure, final.} = object OpaqueDIBuilder{.pure, final.} = object target{.pure, final.} = object @@ -143,7 +141,6 @@ include llvm/Linker include llvm/Target include llvm/TargetMachine include llvm/Transforms/PassBuilder -include llvm/Transforms/PassManagerBuilder include llvm/ExecutionEngine include llvm/Orc diff --git a/llvm/llvm/Core.nim b/llvm/llvm/Core.nim index a0cbd6e..a3cf097 100644 --- a/llvm/llvm/Core.nim +++ b/llvm/llvm/Core.nim @@ -290,9 +290,6 @@ type ## ## @} ## - -proc initializeCore*(r: PassRegistryRef) {.importc: "LLVMInitializeCore", - dynlib: LLVMLib.} ## Deallocate and destroy all ManagedStatic variables. ## @see llvm::llvm_shutdown ## @see ManagedStatic @@ -393,14 +390,6 @@ proc contextShouldDiscardValueNames*(c: ContextRef): Bool {. proc contextSetDiscardValueNames*(c: ContextRef; `discard`: Bool) {. importc: "LLVMContextSetDiscardValueNames", dynlib: LLVMLib.} ## -## Set whether the given context is in opaque pointer mode. -## -## @see LLVMContext::setOpaquePointers() -## - -proc contextSetOpaquePointers*(c: ContextRef; opaquePointers: Bool) {. - importc: "LLVMContextSetOpaquePointers", dynlib: LLVMLib.} -## ## Destroy a context instance. ## ## This should be called for every call to LLVMContextCreate() or memory @@ -1316,8 +1305,6 @@ proc isLiteralStruct*(structTy: TypeRef): Bool {.importc: "LLVMIsLiteralStruct", ## ## Obtain the element type of an array or vector type. ## -## This currently also works for pointer types, but this usage is deprecated. -## ## @see llvm::SequentialType::getElementType() ## @@ -1345,22 +1332,47 @@ proc getNumContainedTypes*(tp: TypeRef): cuint {. ## The created type will exist in the context that its element type ## exists in. ## +## @deprecated LLVMArrayType is deprecated in favor of the API accurate +## LLVMArrayType2 ## @see llvm::ArrayType::get() ## proc arrayType*(elementType: TypeRef; elementCount: cuint): TypeRef {. importc: "LLVMArrayType", dynlib: LLVMLib.} ## +## Create a fixed size array type that refers to a specific type. +## +## The created type will exist in the context that its element type +## exists in. +## +## @see llvm::ArrayType::get() +## + +proc arrayType2*(elementType: TypeRef; elementCount: uint64): TypeRef {. + importc: "LLVMArrayType2", dynlib: LLVMLib.} +## ## Obtain the length of an array type. ## ## This only works on types that represent arrays. ## +## @deprecated LLVMGetArrayLength is deprecated in favor of the API accurate +## LLVMGetArrayLength2 ## @see llvm::ArrayType::getNumElements() ## proc getArrayLength*(arrayTy: TypeRef): cuint {.importc: "LLVMGetArrayLength", dynlib: LLVMLib.} ## +## Obtain the length of an array type. +## +## This only works on types that represent arrays. +## +## @see llvm::ArrayType::getNumElements() +## + +proc getArrayLength2*(arrayTy: TypeRef): uint64 {. + importc: "LLVMGetArrayLength2", dynlib: LLVMLib.} +## ## Create a pointer type that points to a defined type. ## ## The created type will exist in the context that its pointee type @@ -1624,6 +1636,8 @@ template declare_Value_Cast*(name: untyped): untyped = ## !!!Ignored construct: [NewLine] LLVM_FOR_EACH_VALUE_SUBCLASS ( LLVM_DECLARE_VALUE_CAST ) LLVMValueRef LLVMIsAMDNode ( LLVMValueRef Val ) ; ## Error: did not expect [NewLine]!!! +proc isAValueAsMetadata*(val: ValueRef): ValueRef {. + importc: "LLVMIsAValueAsMetadata", dynlib: LLVMLib.} proc isAMDString*(val: ValueRef): ValueRef {.importc: "LLVMIsAMDString", dynlib: LLVMLib.} ## Deprecated: Use LLVMGetValueName2 instead. @@ -1970,12 +1984,22 @@ proc constStruct*(constantVals: ptr ValueRef; count: cuint; packed: Bool): Value ## ## Create a ConstantArray from values. ## +## @deprecated LLVMConstArray is deprecated in favor of the API accurate +## LLVMConstArray2 ## @see llvm::ConstantArray::get() ## proc constArray*(elementTy: TypeRef; constantVals: ptr ValueRef; length: cuint): ValueRef {. importc: "LLVMConstArray", dynlib: LLVMLib.} ## +## Create a ConstantArray from values. +## +## @see llvm::ConstantArray::get() +## + +proc constArray2*(elementTy: TypeRef; constantVals: ptr ValueRef; length: uint64): ValueRef {. + importc: "LLVMConstArray2", dynlib: LLVMLib.} +## ## Create a non-anonymous ConstantStruct from values. ## ## @see llvm::ConstantStruct::get() @@ -2117,9 +2141,6 @@ proc constIntCast*(constantVal: ValueRef; toType: TypeRef; isSigned: Bool): Valu importc: "LLVMConstIntCast", dynlib: LLVMLib.} proc constFPCast*(constantVal: ValueRef; toType: TypeRef): ValueRef {. importc: "LLVMConstFPCast", dynlib: LLVMLib.} -proc constSelect*(constantCondition: ValueRef; constantIfTrue: ValueRef; - constantIfFalse: ValueRef): ValueRef {. - importc: "LLVMConstSelect", dynlib: LLVMLib.} proc constExtractElement*(vectorConstant: ValueRef; indexConstant: ValueRef): ValueRef {. importc: "LLVMConstExtractElement", dynlib: LLVMLib.} proc constInsertElement*(vectorConstant: ValueRef; @@ -2866,6 +2887,15 @@ proc getMDNodeNumOperands*(v: ValueRef): cuint {. proc getMDNodeOperands*(v: ValueRef; dest: ptr ValueRef) {. importc: "LLVMGetMDNodeOperands", dynlib: LLVMLib.} +## +## Replace an operand at a specific index in a llvm::MDNode value. +## +## @see llvm::MDNode::replaceOperandWith() +## + +proc replaceMDNodeOperandWith*(v: ValueRef; index: cuint; + replacement: MetadataRef) {. + importc: "LLVMReplaceMDNodeOperandWith", dynlib: LLVMLib.} ## Deprecated: Use LLVMMDStringInContext2 instead. proc mDStringInContext*(c: ContextRef; str: cstring; sLen: cuint): ValueRef {. @@ -3918,6 +3948,16 @@ proc buildFNeg*(a1: BuilderRef; v: ValueRef; name: cstring): ValueRef {. importc: "LLVMBuildFNeg", dynlib: LLVMLib.} proc buildNot*(a1: BuilderRef; v: ValueRef; name: cstring): ValueRef {. importc: "LLVMBuildNot", dynlib: LLVMLib.} +proc getNUW*(arithInst: ValueRef): Bool {.importc: "LLVMGetNUW", dynlib: LLVMLib.} +proc setNUW*(arithInst: ValueRef; hasNUW: Bool) {.importc: "LLVMSetNUW", + dynlib: LLVMLib.} +proc getNSW*(arithInst: ValueRef): Bool {.importc: "LLVMGetNSW", dynlib: LLVMLib.} +proc setNSW*(arithInst: ValueRef; hasNSW: Bool) {.importc: "LLVMSetNSW", + dynlib: LLVMLib.} +proc getExact*(divOrShrInst: ValueRef): Bool {.importc: "LLVMGetExact", + dynlib: LLVMLib.} +proc setExact*(divOrShrInst: ValueRef; isExact: Bool) {.importc: "LLVMSetExact", + dynlib: LLVMLib.} ## Memory proc buildMalloc*(a1: BuilderRef; ty: TypeRef; name: cstring): ValueRef {. @@ -4122,8 +4162,8 @@ proc getUndefMaskElem*(): cint {.importc: "LLVMGetUndefMaskElem", ## Get the mask value at position Elt in the mask of a ShuffleVector ## instruction. ## -## \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is undef -## at that position. +## \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is +## poison at that position. ## proc getMaskValue*(shuffleVectorInst: ValueRef; elt: cuint): cint {. @@ -4194,20 +4234,6 @@ proc disposeMemoryBuffer*(memBuf: MemoryBufferRef) {. ## @} ## ## -## @defgroup LLVMCCorePassRegistry Pass Registry -## @ingroup LLVMCCore -## -## @{ -## -## Return the global pass registry, for use with initialization functions. -## @see llvm::PassRegistry::getPassRegistry - -proc getGlobalPassRegistry*(): PassRegistryRef {. - importc: "LLVMGetGlobalPassRegistry", dynlib: LLVMLib.} -## -## @} -## -## ## @defgroup LLVMCCorePassManagers Pass Managers ## @ingroup LLVMCCore ## diff --git a/llvm/llvm/DebugInfo.nim b/llvm/llvm/DebugInfo.nim index 28a4d27..ecb5663 100644 --- a/llvm/llvm/DebugInfo.nim +++ b/llvm/llvm/DebugInfo.nim @@ -72,7 +72,8 @@ type DWARFSourceLanguageKotlin, DWARFSourceLanguageZig, DWARFSourceLanguageCrystal, DWARFSourceLanguageC_plusPlus17, DWARFSourceLanguageC_plusPlus20, DWARFSourceLanguageC17, - DWARFSourceLanguageFortran18, DWARFSourceLanguageAda2005, DWARFSourceLanguageAda2012, ## Vendor extensions: + DWARFSourceLanguageFortran18, DWARFSourceLanguageAda2005, + DWARFSourceLanguageAda2012, DWARFSourceLanguageMojo, ## Vendor extensions: DWARFSourceLanguageMipsAssembler, DWARFSourceLanguageGOOGLE_RenderScript, DWARFSourceLanguageBORLAND_Delphi @@ -1125,6 +1126,12 @@ proc dIBuilderCreateGlobalVariableExpression*(builder: DIBuilderRef; localToUnit: Bool; expr: MetadataRef; decl: MetadataRef; alignInBits: uint32): MetadataRef {. importc: "LLVMDIBuilderCreateGlobalVariableExpression", dynlib: LLVMLib.} ## +## Get the dwarf::Tag of a DINode +## + +proc getDINodeTag*(md: MetadataRef): uint16 {.importc: "LLVMGetDINodeTag", + dynlib: LLVMLib.} +## ## Retrieves the \c DIVariable associated with this global variable expression. ## \param GVE The global variable expression. ## diff --git a/llvm/llvm/Transforms/PassBuilder.nim b/llvm/llvm/Transforms/PassBuilder.nim index 35db638..1b6b9ff 100644 --- a/llvm/llvm/Transforms/PassBuilder.nim +++ b/llvm/llvm/Transforms/PassBuilder.nim @@ -96,6 +96,9 @@ proc passBuilderOptionsSetCallGraphProfile*(options: PassBuilderOptionsRef; proc passBuilderOptionsSetMergeFunctions*(options: PassBuilderOptionsRef; mergeFunctions: Bool) {.importc: "LLVMPassBuilderOptionsSetMergeFunctions", dynlib: LLVMLib.} +proc passBuilderOptionsSetInlinerThreshold*(options: PassBuilderOptionsRef; + threshold: cint) {.importc: "LLVMPassBuilderOptionsSetInlinerThreshold", + dynlib: LLVMLib.} ## ## Dispose of a heap-allocated PassBuilderOptions instance ## diff --git a/llvm/llvm/Transforms/PassManagerBuilder.nim b/llvm/llvm/Transforms/PassManagerBuilder.nim deleted file mode 100644 index 0e8bc61..0000000 --- a/llvm/llvm/Transforms/PassManagerBuilder.nim +++ /dev/null @@ -1,70 +0,0 @@ -## ===-- llvm-c/Transform/PassManagerBuilder.h - PMB C Interface ---*- C -*-===*\ -## |* *| -## |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| -## |* Exceptions. *| -## |* See https://llvm.org/LICENSE.txt for license information. *| -## |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| -## |* *| -## |*===----------------------------------------------------------------------===*| -## |* *| -## |* This header declares the C interface to the PassManagerBuilder class. *| -## |* *| -## \*===----------------------------------------------------------------------=== - -type - PassManagerBuilderRef* = ptr OpaquePassManagerBuilder - -## -## @defgroup LLVMCTransformsPassManagerBuilder Pass manager builder -## @ingroup LLVMCTransforms -## -## @{ -## -## See llvm::PassManagerBuilder. - -proc passManagerBuilderCreate*(): PassManagerBuilderRef {. - importc: "LLVMPassManagerBuilderCreate", dynlib: LLVMLib.} -proc passManagerBuilderDispose*(pmb: PassManagerBuilderRef) {. - importc: "LLVMPassManagerBuilderDispose", dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::OptLevel. - -proc passManagerBuilderSetOptLevel*(pmb: PassManagerBuilderRef; optLevel: cuint) {. - importc: "LLVMPassManagerBuilderSetOptLevel", dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::SizeLevel. - -proc passManagerBuilderSetSizeLevel*(pmb: PassManagerBuilderRef; - sizeLevel: cuint) {. - importc: "LLVMPassManagerBuilderSetSizeLevel", dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::DisableUnitAtATime. - -proc passManagerBuilderSetDisableUnitAtATime*(pmb: PassManagerBuilderRef; - value: Bool) {.importc: "LLVMPassManagerBuilderSetDisableUnitAtATime", - dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::DisableUnrollLoops. - -proc passManagerBuilderSetDisableUnrollLoops*(pmb: PassManagerBuilderRef; - value: Bool) {.importc: "LLVMPassManagerBuilderSetDisableUnrollLoops", - dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::DisableSimplifyLibCalls - -proc passManagerBuilderSetDisableSimplifyLibCalls*(pmb: PassManagerBuilderRef; - value: Bool) {.importc: "LLVMPassManagerBuilderSetDisableSimplifyLibCalls", - dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::Inliner. - -proc passManagerBuilderUseInlinerWithThreshold*(pmb: PassManagerBuilderRef; - threshold: cuint) {.importc: "LLVMPassManagerBuilderUseInlinerWithThreshold", - dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::populateFunctionPassManager. - -proc passManagerBuilderPopulateFunctionPassManager*(pmb: PassManagerBuilderRef; - pm: PassManagerRef) {.importc: "LLVMPassManagerBuilderPopulateFunctionPassManager", - dynlib: LLVMLib.} -## See llvm::PassManagerBuilder::populateModulePassManager. - -proc passManagerBuilderPopulateModulePassManager*(pmb: PassManagerBuilderRef; - pm: PassManagerRef) {.importc: "LLVMPassManagerBuilderPopulateModulePassManager", - dynlib: LLVMLib.} -## -## @} -## diff --git a/llvm/llvm/Types.nim b/llvm/llvm/Types.nim index c3516c6..07e5b21 100644 --- a/llvm/llvm/Types.nim +++ b/llvm/llvm/Types.nim @@ -143,11 +143,6 @@ type type PassManagerRef* = ptr OpaquePassManager -## @see llvm::PassRegistry - -type - PassRegistryRef* = ptr OpaquePassRegistry - ## ## Used to get the users and usees of a Value. ## diff --git a/llvm/rebuild.sh b/llvm/rebuild.sh index e39d704..0e1d0e3 100755 --- a/llvm/rebuild.sh +++ b/llvm/rebuild.sh @@ -1,9 +1,9 @@ -LLVM_INC=../ext/llvm-16.0.2.src/include +LLVM_INC=../ext/llvm-17.0.2.src/include C2NIM="../../c2nim/c2nim" C2NIMFLAGS="--nep1 --skipinclude --prefix:LLVM --dynlib:LLVMLib --def:LLVM_C_EXTERN_C_BEGIN= --def:LLVM_C_EXTERN_C_END= --stdints" -HEADERS="BitReader.h BitWriter.h Comdat.h Core.h Error.h ExecutionEngine.h DebugInfo.h IRReader.h Linker.h LLJIT.h OrcEE.h Orc.h Target.h TargetMachine.h Support.h Types.h Transforms/PassBuilder.h Transforms/PassManagerBuilder.h" +HEADERS="BitReader.h BitWriter.h Comdat.h Core.h Error.h ExecutionEngine.h DebugInfo.h IRReader.h Linker.h LLJIT.h OrcEE.h Orc.h Target.h TargetMachine.h Support.h Types.h Transforms/PassBuilder.h" for a in $HEADERS; do OUT="llvm/${a%.h}.nim" diff --git a/llvm/wrapper.cc b/llvm/wrapper.cc index f358b86..fea0382 100644 --- a/llvm/wrapper.cc +++ b/llvm/wrapper.cc @@ -52,11 +52,13 @@ extern "C" void LLVMNimSetMetadataGlobal(LLVMValueRef Global, unwrap(Global)->setMetadata(KindID, N); } +LLD_HAS_DRIVER(elf) extern "C" bool LLVMNimLLDLinkElf(const char **args, size_t arg_count) { ArrayRef array_ref_args(args, arg_count); return lld::elf::link(array_ref_args, llvm::outs(), llvm::errs(), false, false); } +LLD_HAS_DRIVER(wasm) extern "C" bool LLVMNimLLDLinkWasm(const char **args, size_t arg_count) { ArrayRef array_ref_args(args, arg_count); return lld::wasm::link(array_ref_args, llvm::outs(), llvm::errs(), false, false);