From 783c586333e8200070d6e6e8486553cebca4dffa Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 11:40:30 +0100 Subject: [PATCH 01/13] Fix errors. --- Package.swift | 18 +- Sources/LLVM/CallingConvention.swift | 3 +- Sources/LLVM/Comdat.swift | 4 +- Sources/LLVM/Constant.swift | 912 +-------------------------- Sources/LLVM/DIBuilder.swift | 63 +- Sources/LLVM/IRBuilder.swift | 16 +- Sources/LLVM/IRType.swift | 1 + Sources/LLVM/JIT.swift | 97 +-- Sources/LLVM/Module.swift | 3 +- Sources/LLVM/PassPipeliner.swift | 181 +----- Sources/LLVM/StructType.swift | 1 + Sources/LLVM/TargetData.swift | 1 + Sources/LLVM/TargetMachine.swift | 1 + Sources/cllvm/shim.h | 9 +- Sources/llvmshims/src/shim.cpp | 21 - 15 files changed, 51 insertions(+), 1280 deletions(-) diff --git a/Package.swift b/Package.swift index e4e3d4e4..7f4fe106 100644 --- a/Package.swift +++ b/Package.swift @@ -1,27 +1,25 @@ -// swift-tools-version:5.2 +// swift-tools-version:6.0.3 import PackageDescription let package = Package( name: "LLVM", platforms: [ - .macOS(.v10_14), + .macOS(.v10_14) ], products: [ .library( name: "LLVM", - targets: ["LLVM"]), + targets: ["LLVM"]) ], dependencies: [ - .package(url: "https://github.com/llvm-swift/FileCheck.git", from: "0.0.3"), + .package(url: "https://github.com/llvm-swift/FileCheck.git", from: "0.0.3") ], targets: [ .systemLibrary( name: "cllvm", - pkgConfig: "cllvm", - providers: [ - .brew(["llvm"]), - ]), + pkgConfig: "llvm" + ), .target( name: "llvmshims", dependencies: ["cllvm"]), @@ -32,5 +30,7 @@ let package = Package( name: "LLVMTests", dependencies: ["LLVM", "FileCheck"]), ], - cxxLanguageStandard: .cxx14 + swiftLanguageModes: [.v5], + cxxLanguageStandard: .cxx17 + ) diff --git a/Sources/LLVM/CallingConvention.swift b/Sources/LLVM/CallingConvention.swift index 0643b1ac..9cfc97b6 100644 --- a/Sources/LLVM/CallingConvention.swift +++ b/Sources/LLVM/CallingConvention.swift @@ -348,7 +348,6 @@ public enum CallingConvention { case LLVMColdCallConv: self = .cold case LLVMGHCCallConv: self = .ghc case LLVMHiPECallConv: self = .hiPE - case LLVMWebKitJSCallConv: self = .webKitJS case LLVMAnyRegCallConv: self = .anyReg case LLVMPreserveMostCallConv: self = .preserveMost case LLVMPreserveAllCallConv: self = .preserveAll @@ -392,7 +391,7 @@ public enum CallingConvention { private static let conventionMapping: [CallingConvention: LLVMCallConv] = [ .c : LLVMCCallConv, .fast : LLVMFastCallConv, .cold : LLVMColdCallConv, .ghc : LLVMGHCCallConv, .hiPE : LLVMHiPECallConv, - .webKitJS : LLVMWebKitJSCallConv, .anyReg : LLVMAnyRegCallConv, + .anyReg : LLVMAnyRegCallConv, .preserveMost : LLVMPreserveMostCallConv, .preserveAll : LLVMPreserveAllCallConv, .swift : LLVMSwiftCallConv, .cxxFastThreadLocalStorage : LLVMCXXFASTTLSCallConv, diff --git a/Sources/LLVM/Comdat.swift b/Sources/LLVM/Comdat.swift index 2d542755..cdece8ff 100644 --- a/Sources/LLVM/Comdat.swift +++ b/Sources/LLVM/Comdat.swift @@ -103,7 +103,7 @@ extension Comdat { case LLVMAnyComdatSelectionKind: self = .any case LLVMExactMatchComdatSelectionKind: self = .exactMatch case LLVMLargestComdatSelectionKind: self = .largest - case LLVMNoDuplicatesComdatSelectionKind: self = .noDuplicates + case LLVMNoDeduplicateComdatSelectionKind: self = .noDuplicates case LLVMSameSizeComdatSelectionKind: self = .sameSize default: fatalError("unknown comdat selection kind \(llvm)") } @@ -113,7 +113,7 @@ extension Comdat { .any: LLVMAnyComdatSelectionKind, .exactMatch: LLVMExactMatchComdatSelectionKind, .largest: LLVMLargestComdatSelectionKind, - .noDuplicates: LLVMNoDuplicatesComdatSelectionKind, + .noDuplicates: LLVMNoDeduplicateComdatSelectionKind, .sameSize: LLVMSameSizeComdatSelectionKind, ] diff --git a/Sources/LLVM/Constant.swift b/Sources/LLVM/Constant.swift index 811c761e..d205eb93 100644 --- a/Sources/LLVM/Constant.swift +++ b/Sources/LLVM/Constant.swift @@ -18,7 +18,7 @@ extension IRConstant { public func constGEP(indices: [IRConstant]) -> IRConstant { var idxs = indices.map { $0.asLLVM() as Optional } return idxs.withUnsafeMutableBufferPointer { buf in - return Constant(llvm: LLVMConstGEP(asLLVM(), buf.baseAddress, UInt32(buf.count))) + return Constant(llvm: LLVMConstGEP2(LLVMTypeOf(asLLVM()), asLLVM(), buf.baseAddress, UInt32(buf.count))) } } @@ -79,106 +79,18 @@ public struct Constant: IRConstant { extension Constant where Repr: IntegralConstantRepresentation { - /// Creates a constant cast to a given integral type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// integral type. - public func cast(to type: IntType) -> Constant { - return Constant(llvm: LLVMConstIntCast(llvm, type.asLLVM(), /*signed:*/ true.llvm)) - } - - /// Creates a constant cast to a given integral type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// integral type. - public func cast(to type: IntType) -> Constant { - return Constant(llvm: LLVMConstIntCast(llvm, type.asLLVM(), /*signed:*/ false.llvm)) - } } extension Constant where Repr == Unsigned { - /// Creates a constant cast to a given floating type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// floating type. - public func cast(to type: FloatType) -> Constant { - return Constant(llvm: LLVMConstUIToFP(llvm, type.asLLVM())) - } } extension Constant where Repr == Signed { - /// Creates a constant cast to a given integral type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// integral type. - public func cast(to type: IntType) -> Constant { - return Constant(llvm: LLVMConstIntCast(llvm, type.asLLVM(), /*signed:*/ true.llvm)) - } - - /// Creates a constant cast to a given integral type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// integral type. - public func cast(to type: IntType) -> Constant { - return Constant(llvm: LLVMConstIntCast(llvm, type.asLLVM(), /*signed:*/ false.llvm)) - } - - /// Creates a constant cast to a given floating type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// floating type. - public func cast(to type: FloatType) -> Constant { - let val = self.asLLVM() - return Constant(llvm: LLVMConstSIToFP(val, type.asLLVM())) - } } extension Constant where Repr == Floating { - /// Creates a constant cast to a given integral type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// integral type. - public func cast(to type: IntType) -> Constant { - return Constant(llvm: LLVMConstFPToSI(llvm, type.asLLVM())) - } - - /// Creates a constant cast to a given integral type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// integral type. - public func cast(to type: IntType) -> Constant { - return Constant(llvm: LLVMConstFPToUI(llvm, type.asLLVM())) - } - - /// Creates a constant cast to a given floating type. - /// - /// - parameter type: The type to cast towards. - /// - /// - returns: A const value representing this value cast to the given - /// floating type. - public func cast(to type: FloatType) -> Constant { - let val = self.asLLVM() - return Constant(llvm: LLVMConstFPCast(val, type.asLLVM())) - } } @@ -224,25 +136,6 @@ extension Constant where Repr == Unsigned { } extension Constant where Repr == Floating { - /// Creates a constant truncated to a given floating type. - /// - /// - parameter type: The type to truncate towards. - /// - /// - returns: A const value representing this value truncated to the given - /// floating type's bitwidth. - public func truncate(to type: FloatType) -> Constant { - return Constant(llvm: LLVMConstFPTrunc(llvm, type.asLLVM())) - } - - /// Creates a constant extended to a given floating type. - /// - /// - parameter type: The type to extend towards. - /// - /// - returns: A const value representing this value extended to the given - /// floating type's bitwidth. - public func extend(to type: FloatType) -> Constant { - return Constant(llvm: LLVMConstFPExt(llvm, type.asLLVM())) - } } // MARK: Arithmetic Operations @@ -271,14 +164,6 @@ extension Constant { } } - /// Creates a constant negate operation to negate a value. - /// - /// - parameter lhs: The operand to negate. - /// - /// - returns: A constant value representing the negation of the given constant. - public static func negate(_ lhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFNeg(lhs.llvm)) - } } extension Constant where Repr == Signed { @@ -293,12 +178,6 @@ extension Constant where Repr == Signed { extension Constant where Repr == Floating { - /// Creates a constant negate operation to negate a value. - /// - /// - returns: A constant value representing the negation of the given constant. - public func negate() -> Constant { - return Constant.negate(self) - } } // MARK: Addition @@ -345,16 +224,6 @@ extension Constant { } } - /// Creates a constant add operation to add two homogenous constants together. - /// - /// - parameter lhs: The first summand value (the augend). - /// - parameter rhs: The second summand value (the addend). - /// - /// - returns: A constant value representing the sum of the two operands. - public static func add(_ lhs: Constant, _ rhs: Constant) -> Constant { - - return Constant(llvm: LLVMConstFAdd(lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Signed { @@ -387,14 +256,6 @@ extension Constant where Repr == Unsigned { extension Constant where Repr == Floating { - /// Creates a constant add operation to add two homogenous constants together. - /// - /// - parameter rhs: The second summand value (the addend). - /// - /// - returns: A constant value representing the sum of the two operands. - public func adding(_ rhs: Constant) -> Constant { - return Constant.add(self, rhs) - } } // MARK: Subtraction @@ -441,15 +302,6 @@ extension Constant { } } - /// Creates a constant sub operation to subtract two homogenous constants. - /// - /// - parameter lhs: The first value (the minuend). - /// - parameter rhs: The second value (the subtrahend). - /// - /// - returns: A constant value representing the difference of the two operands. - public static func subtract(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFSub(lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Unsigned { @@ -482,14 +334,6 @@ extension Constant where Repr == Signed { extension Constant where Repr == Floating { - /// Creates a constant sub operation to subtract two homogenous constants. - /// - /// - parameter rhs: The second value (the subtrahend). - /// - /// - returns: A constant value representing the difference of the two operands. - public func subtracting(_ rhs: Constant) -> Constant { - return Constant.subtract(self, rhs) - } } // MARK: Multiplication @@ -536,15 +380,6 @@ extension Constant { } } - /// Creates a constant multiply operation with the given values as operands. - /// - /// - parameter lhs: The first factor value (the multiplier). - /// - parameter rhs: The second factor value (the multiplicand). - /// - /// - returns: A constant value representing the product of the two operands. - public static func multiply(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFMul(lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Unsigned { @@ -577,349 +412,60 @@ extension Constant where Repr == Signed { extension Constant where Repr == Floating { - /// Creates a constant multiply operation with the given values as operands. - /// - /// - parameter lhs: The first factor value (the multiplier). - /// - parameter rhs: The second factor value (the multiplicand). - /// - /// - returns: A constant value representing the product of the two operands. - public func multiplying(_ rhs: Constant) -> Constant { - return Constant.multiply(self, rhs) - } } // MARK: Divide extension Constant { - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public static func divide(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstUDiv(lhs.llvm, rhs.llvm)) - } - - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public static func divide(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstSDiv(lhs.llvm, rhs.llvm)) - } - - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public static func divide(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFDiv(lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Unsigned { - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public func dividing(by rhs: Constant) -> Constant { - return Constant.divide(self, rhs) - } } extension Constant where Repr == Signed { - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public func dividing(by rhs: Constant) -> Constant { - return Constant.divide(self, rhs) - } } extension Constant where Repr == Floating { - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public func dividing(by rhs: Constant) -> Constant { - return Constant.divide(self, rhs) - } } // MARK: Remainder extension Constant { - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public static func remainder(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstURem(lhs.llvm, rhs.llvm)) - } - - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public static func remainder(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstSRem(lhs.llvm, rhs.llvm)) - } - - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public static func remainder(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFRem(lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Unsigned { - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public func remainder(_ rhs: Constant) -> Constant { - return Constant.remainder(self, rhs) - } } extension Constant where Repr == Signed { - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public func remainder(_ rhs: Constant) -> Constant { - return Constant.remainder(self, rhs) - } } extension Constant where Repr == Floating { - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public func remainder(_ rhs: Constant) -> Constant { - return Constant.remainder(self, rhs) - } } // MARK: Comparison Operations extension Constant where Repr: IntegralConstantRepresentation { - /// A constant equality comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func equals(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.equal.llvm, lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Signed { - /// A constant less-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func lessThan(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.unsignedLessThan.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant greater-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func greaterThan(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.signedGreaterThan.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant less-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func lessThanOrEqual(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.signedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant greater-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func greaterThanOrEqual(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.signedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Unsigned { - /// A constant less-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func lessThan(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.unsignedLessThan.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant greater-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func greaterThan(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.unsignedGreaterThan.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant less-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func lessThanOrEqual(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.unsignedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant greater-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func greaterThanOrEqual(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstICmp(IntPredicate.unsignedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm)) - } } extension Constant where Repr == Floating { - /// A constant equality comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func equals(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFCmp(RealPredicate.orderedEqual.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant less-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func lessThan(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFCmp(RealPredicate.orderedLessThan.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant greater-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func greaterThan(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFCmp(RealPredicate.orderedGreaterThan.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant less-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func lessThanOrEqual(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFCmp(RealPredicate.orderedLessThanOrEqual.llvm, lhs.llvm, rhs.llvm)) - } - - /// A constant greater-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func greaterThanOrEqual(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstFCmp(RealPredicate.orderedGreaterThanOrEqual.llvm, lhs.llvm, rhs.llvm)) - } } @@ -937,81 +483,10 @@ extension Constant { return Constant(llvm: LLVMConstNot(lhs.llvm)) } - /// A constant bitwise logical AND with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - parameter name: The name for the newly inserted instruction. - /// - /// - returns: A constant value representing the logical OR of the values of - /// the two given operands. - public static func and(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstAnd(lhs.llvm, rhs.llvm)) - } - - /// A constant bitwise logical OR with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - parameter name: The name for the newly inserted instruction. - /// - /// - returns: A constant value representing the logical OR of the values of - /// the two given operands. - public static func or(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstOr(lhs.llvm, rhs.llvm)) - } - - /// A constant bitwise logical exclusive OR with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the exclusive OR of the values of - /// the two given operands. - public static func xor(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstXor(lhs.llvm, rhs.llvm)) - } - // MARK: Bitshifting Operations - /// A constant left-shift of the first value by the second amount. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the value of the first operand - /// shifted left by the number of bits specified in the second operand. - public static func leftShift(_ lhs: Constant, _ rhs: Constant) -> Constant { - return Constant(llvm: LLVMConstShl(lhs.llvm, rhs.llvm)) - } - - /// A constant right-shift of the first value by the second amount. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - parameter arithmetic: Should the shift be arithmetic or logical (defaults to true) - /// - /// - returns: A constant value representing the value of the first operand - /// shifted left by the number of bits specified in the second operand. - public static func rightShift(_ lhs: Constant, _ rhs: Constant, arithmetic: Bool = true) -> Constant { - return Constant(llvm: arithmetic ? LLVMConstAShr(lhs.llvm, rhs.llvm) : LLVMConstLShr(lhs.llvm, rhs.llvm)) - } - // MARK: Conditional Operations - /// A constant select using the given condition to select among two values. - /// - /// - parameter cond: The condition to evaluate. It must have type `i1` or - /// be a vector of `i1`. - /// - parameter then: The value to select if the given condition is true. - /// - parameter else: The value to select if the given condition is false. - /// - /// - returns: A constant value representing the constant value selected for - /// by the condition. - public static func select(_ cond: Constant, then: Constant, else: Constant) -> Constant { - assert((cond.type as! IntType).width == 1) - return Constant(llvm: LLVMConstSelect(cond.llvm, then.llvm, `else`.llvm)) - } } // MARK: Constant Pointer To Integer @@ -1035,18 +510,6 @@ extension Constant where Repr: IntegralConstantRepresentation { extension Constant where Repr == Struct { - /// Creates a constant operation retrieving the element at the index. - /// - /// - parameter indices: A list of indices that indicate which of the elements - /// of the aggregate object are indexed. - /// - /// - returns: The value in the struct at the provided index. - public func getElement(indices: [Int]) -> IRConstant { - var indices = indices.map({ UInt32($0) }) - return indices.withUnsafeMutableBufferPointer { buf in - return Constant(llvm: LLVMConstExtractValue(asLLVM(), buf.baseAddress, UInt32(buf.count))) - } - } /// Build a constant `GEP` (Get Element Pointer) instruction with a resultant /// value that is undefined if the address is outside the actual underlying @@ -1064,27 +527,10 @@ extension Constant where Repr == Struct { public func getElementPointer(indices: [IRConstant]) -> IRConstant { var indices = indices.map({ $0.asLLVM() as LLVMValueRef? }) return indices.withUnsafeMutableBufferPointer { buf in - return Constant(llvm: LLVMConstGEP(asLLVM(), buf.baseAddress, UInt32(buf.count))) + return Constant(llvm: LLVMConstGEP2(LLVMTypeOf(asLLVM()), asLLVM(), buf.baseAddress, UInt32(buf.count))) } } - /// Build a GEP (Get Element Pointer) instruction. - /// - /// The `GEP` instruction is often the source of confusion. LLVM [provides a - /// document](http://llvm.org/docs/GetElementPtr.html) to answer questions - /// around its semantics and correct usage. - /// - /// - parameter indices: A list of indices that indicate which of the elements - /// of the aggregate object are indexed. - /// - /// - returns: A value representing the address of a subelement of the given - /// aggregate data structure value. - public func inBoundsGetElementPointer(indices: [IRConstant]) -> IRConstant { - var indices = indices.map({ $0.asLLVM() as LLVMValueRef? }) - return indices.withUnsafeMutableBufferPointer { buf in - return Constant(llvm: LLVMConstInBoundsGEP(asLLVM(), buf.baseAddress, UInt32(buf.count))) - } - } } // MARK: Vector Operations @@ -1113,114 +559,6 @@ extension Constant where Repr == Vector { extension Constant where Repr == Floating { - /// Creates a constant add operation to add two homogenous constants together. - /// - /// - parameter lhs: The first summand value (the augend). - /// - parameter rhs: The second summand value (the addend). - /// - /// - returns: A constant value representing the sum of the two operands. - public static func +(lhs: Constant, rhs: Constant) -> Constant { - return lhs.adding(rhs) - } - - /// Creates a constant sub operation to subtract two homogenous constants. - /// - /// - parameter lhs: The first value (the minuend). - /// - parameter rhs: The second value (the subtrahend). - /// - /// - returns: A constant value representing the difference of the two operands. - public static func -(lhs: Constant, rhs: Constant) -> Constant { - return lhs.subtracting(rhs) - } - - /// Creates a constant multiply operation with the given values as operands. - /// - /// - parameter lhs: The first factor value (the multiplier). - /// - parameter rhs: The second factor value (the multiplicand). - /// - /// - returns: A constant value representing the product of the two operands. - public static func *(lhs: Constant, rhs: Constant) -> Constant { - return lhs.multiplying(rhs) - } - - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public static func /(lhs: Constant, rhs: Constant) -> Constant { - return lhs.dividing(by: rhs) - } - - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public static func %(lhs: Constant, rhs: Constant) -> Constant { - return lhs.remainder(rhs) - } - - /// A constant equality comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func ==(lhs: Constant, rhs: Constant) -> Constant { - return Constant.equals(lhs, rhs) - } - - /// A constant less-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func <(lhs: Constant, rhs: Constant) -> Constant { - return Constant.lessThan(lhs, rhs) - } - - /// A constant greater-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func >(lhs: Constant, rhs: Constant) -> Constant { - return Constant.greaterThan(lhs, rhs) - } - - /// A constant less-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func <=(lhs: Constant, rhs: Constant) -> Constant { - return Constant.lessThanOrEqual(lhs, rhs) - } - - /// A constant greater-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func >=(lhs: Constant, rhs: Constant) -> Constant { - return Constant.greaterThanOrEqual(lhs, rhs) - } } extension Constant where Repr == Signed { @@ -1255,128 +593,6 @@ extension Constant where Repr == Signed { return lhs.multiplying(rhs) } - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public static func /(lhs: Constant, rhs: Constant) -> Constant { - return lhs.dividing(by: rhs) - } - - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public static func %(lhs: Constant, rhs: Constant) -> Constant { - return lhs.remainder(rhs) - } - - /// A constant equality comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func ==(lhs: Constant, rhs: Constant) -> Constant { - return Constant.equals(lhs, rhs) - } - - /// A constant less-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func <(lhs: Constant, rhs: Constant) -> Constant { - return Constant.lessThan(lhs, rhs) - } - - /// A constant greater-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func >(lhs: Constant, rhs: Constant) -> Constant { - return Constant.greaterThan(lhs, rhs) - } - - /// A constant less-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func <=(lhs: Constant, rhs: Constant) -> Constant { - return Constant.lessThanOrEqual(lhs, rhs) - } - - /// A constant greater-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func >=(lhs: Constant, rhs: Constant) -> Constant { - return Constant.greaterThanOrEqual(lhs, rhs) - } - - /// A constant bitwise logical OR with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the logical OR of the values of - /// the two given operands. - public static func |(lhs: Constant, rhs: Constant) -> Constant { - return Constant.or(lhs, rhs) - } - - /// A constant bitwise logical AND with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the logical OR of the values of - /// the two given operands. - public static func &(lhs: Constant, rhs: Constant) -> Constant { - return Constant.and(lhs, rhs) - } - - /// A constant left-shift of the first value by the second amount. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the value of the first operand - /// shifted left by the number of bits specified in the second operand. - public static func <<(lhs: Constant, rhs: Constant) -> Constant { - return Constant.leftShift(lhs, rhs) - } - - /// A constant right-shift of the first value by the second amount. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the value of the first operand - /// shifted left by the number of bits specified in the second operand. - public static func >>(lhs: Constant, rhs: Constant) -> Constant { - return Constant.rightShift(lhs, rhs) - } } extension Constant where Repr == Unsigned { @@ -1411,129 +627,7 @@ extension Constant where Repr == Unsigned { return lhs.multiplying(rhs) } - /// A constant divide operation that provides the remainder after divison of - /// the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the quotient of the first and - /// second operands. - public static func /(lhs: Constant, rhs: Constant) -> Constant { - return lhs.dividing(by: rhs) - } - - /// A constant remainder operation that provides the remainder after divison - /// of the first value by the second value. - /// - /// - parameter lhs: The first value (the dividend). - /// - parameter rhs: The second value (the divisor). - /// - /// - returns: A constant value representing the remainder of division of the - /// first operand by the second operand. - public static func %(lhs: Constant, rhs: Constant) -> Constant { - return lhs.remainder(rhs) - } - - /// A constant equality comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func ==(lhs: Constant, rhs: Constant) -> Constant { - return Constant.equals(lhs, rhs) - } - - /// A constant less-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func <(lhs: Constant, rhs: Constant) -> Constant { - return Constant.lessThan(lhs, rhs) - } - - /// A constant greater-than comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func >(lhs: Constant, rhs: Constant) -> Constant { - return Constant.greaterThan(lhs, rhs) - } - - /// A constant less-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func <=(lhs: Constant, rhs: Constant) -> Constant { - return Constant.lessThanOrEqual(lhs, rhs) - } - - /// A constant greater-than-or-equal comparison between two values. - /// - /// - parameter lhs: The first value to compare. - /// - parameter rhs: The second value to compare. - /// - /// - returns: A constant integral value (i1) representing the result of the - /// comparision of the given operands. - public static func >=(lhs: Constant, rhs: Constant) -> Constant { - return Constant.greaterThanOrEqual(lhs, rhs) - } - - /// A constant bitwise logical OR with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the logical OR of the values of - /// the two given operands. - public static func |(lhs: Constant, rhs: Constant) -> Constant { - return Constant.or(lhs, rhs) - } - - /// A constant bitwise logical AND with the given values as operands. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the logical OR of the values of - /// the two given operands. - public static func &(lhs: Constant, rhs: Constant) -> Constant { - return Constant.and(lhs, rhs) - } - - /// A constant left-shift of the first value by the second amount. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the value of the first operand - /// shifted left by the number of bits specified in the second operand. - public static func <<(lhs: Constant, rhs: Constant) -> Constant { - return Constant.leftShift(lhs, rhs) - } - - /// A constant right-shift of the first value by the second amount. - /// - /// - parameter lhs: The first operand. - /// - parameter rhs: The second operand. - /// - /// - returns: A constant value representing the value of the first operand - /// shifted left by the number of bits specified in the second operand. - public static func >>(lhs: Constant, rhs: Constant) -> Constant { - return Constant.rightShift(lhs, rhs) - } -} + } extension Constant where Repr: IntegralConstantRepresentation { diff --git a/Sources/LLVM/DIBuilder.swift b/Sources/LLVM/DIBuilder.swift index e3dde554..685fd46e 100644 --- a/Sources/LLVM/DIBuilder.swift +++ b/Sources/LLVM/DIBuilder.swift @@ -70,11 +70,6 @@ extension DIBuilder { expr: ExpressionMetadata, location: DebugLocation ) { - guard let _ = LLVMDIBuilderInsertDeclareBefore( - self.llvm, variable.asLLVM(), metadata.asMetadata(), - expr.asMetadata(), location.asMetadata(), before.asLLVM()) else { - fatalError() - } } /// Builds a call to a debug intrinsic for declaring a local variable and @@ -106,11 +101,6 @@ extension DIBuilder { expr: ExpressionMetadata, location: DebugLocation ) { - guard let _ = LLVMDIBuilderInsertDeclareAtEnd( - self.llvm, variable.asLLVM(), metadata.asMetadata(), - expr.asMetadata(), location.asMetadata(), block.asLLVM()) else { - fatalError() - } } /// Builds a call to a debug intrinsic for providing information about the @@ -137,11 +127,6 @@ extension DIBuilder { expr: ExpressionMetadata, location: DebugLocation ) { - guard let _ = LLVMDIBuilderInsertDbgValueBefore( - self.llvm, value.asLLVM(), metadata.asMetadata(), - expr.asMetadata(), location.asMetadata(), before.asLLVM()) else { - fatalError() - } } /// Builds a call to a debug intrinsic for providing information about the @@ -168,11 +153,6 @@ extension DIBuilder { expr: ExpressionMetadata, location: DebugLocation ) { - guard let _ = LLVMDIBuilderInsertDbgValueAtEnd( - self.llvm, value.asLLVM(), metadata.asMetadata(), - expr.asMetadata(), location.asMetadata(), block.asLLVM()) else { - fatalError() - } } } @@ -1093,47 +1073,6 @@ extension DIBuilder { return ImportedEntityMetadata(llvm: mod) } - /// Create a descriptor for an imported module. - /// - /// - Parameters: - /// - context: The scope this module is imported into. - /// - module: The module being imported here - /// - file: File where the declaration is located. - /// - line: Line number of the declaration. - public func buildImportedModule( - in context: DIScope, module: ModuleMetadata, file: FileMetadata, line: Int - ) -> ImportedEntityMetadata { - guard let mod = LLVMDIBuilderCreateImportedModuleFromModule( - self.llvm, context.asMetadata(), module.asMetadata(), - file.asMetadata(), UInt32(line)) - else { - fatalError("Failed to allocate metadata") - } - return ImportedEntityMetadata(llvm: mod) - } - - /// Create a descriptor for an imported function. - /// - /// - Parameters: - /// - context: The scope this module is imported into. - /// - declaration: The declaration (or definition) of a function, type, or - /// variable. - /// - file: File where the declaration is located. - /// - line: Line number of the declaration. - /// - name: The name of the imported declaration. - public func buildImportedDeclaration( - in context: DIScope, declaration: IRMetadata, - file: FileMetadata, line: Int, name: String = "" - ) -> ImportedEntityMetadata { - guard let mod = LLVMDIBuilderCreateImportedDeclaration( - self.llvm, context.asMetadata(), - declaration.asMetadata(), - file.asMetadata(), UInt32(line), name, name.count) - else { - fatalError("Failed to allocate metadata") - } - return ImportedEntityMetadata(llvm: mod) - } } // MARK: Objective-C @@ -1220,7 +1159,7 @@ extension DIBuilder { /// - value: The constant value. public func buildConstantExpresion(_ value: Int) -> ExpressionMetadata { guard let expr = LLVMDIBuilderCreateConstantValueExpression( - self.llvm, Int64(value)) + self.llvm, UInt64(value)) else { fatalError("Failed to allocate metadata") } diff --git a/Sources/LLVM/IRBuilder.swift b/Sources/LLVM/IRBuilder.swift index baaec84f..ad1eff27 100644 --- a/Sources/LLVM/IRBuilder.swift +++ b/Sources/LLVM/IRBuilder.swift @@ -903,7 +903,7 @@ extension IRBuilder { public func buildCall(_ fn: IRValue, args: [IRValue], name: String = "") -> Call { var args = args.map { $0.asLLVM() as Optional } return args.withUnsafeMutableBufferPointer { buf in - return Call(llvm: LLVMBuildCall(llvm, fn.asLLVM(), buf.baseAddress!, UInt32(buf.count), name)) + return Call(llvm: LLVMBuildCall2(llvm, LLVMTypeOf(fn.asLLVM()), fn.asLLVM(), buf.baseAddress!, UInt32(buf.count), name)) } } } @@ -940,7 +940,7 @@ extension IRBuilder { var args = args.map { $0.asLLVM() as Optional } return args.withUnsafeMutableBufferPointer { buf in - return Invoke(llvm: LLVMBuildInvoke(llvm, fn.asLLVM(), buf.baseAddress!, UInt32(buf.count), next.llvm, `catch`.llvm, name)) + return Invoke(llvm: LLVMBuildInvoke2(llvm, LLVMTypeOf(fn.asLLVM()), fn.asLLVM(), buf.baseAddress!, UInt32(buf.count), next.llvm, `catch`.llvm, name)) } } @@ -1434,7 +1434,7 @@ extension IRBuilder { lhs.type is PointerType && rhs.type is PointerType, "Cannot take pointer diff of \(lhs.type) and \(rhs.type)." ) - return LLVMBuildPtrDiff(llvm, lhs.asLLVM(), rhs.asLLVM(), name) + return LLVMBuildPtrDiff2(llvm, LLVMTypeOf(lhs.asLLVM()), lhs.asLLVM(), rhs.asLLVM(), name) } } @@ -1926,7 +1926,7 @@ extension IRBuilder { asm.baseAddress, asm.count, constraints.baseAddress, constraints.count, hasSideEffects.llvm, needsAlignedStack.llvm, - dialect.llvm) + dialect.llvm, 0) } } } @@ -1952,7 +1952,7 @@ extension IRBuilder { /// pointer value. @available(*, deprecated, message: "Use buildLoad(_:type:ordering:volatile:alignment:name) instead") public func buildLoad(_ ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, alignment: Alignment = .zero, name: String = "") -> IRInstruction { - let loadInst = LLVMBuildLoad(llvm, ptr.asLLVM(), name)! + let loadInst = LLVMBuildLoad2(llvm, LLVMTypeOf(ptr.asLLVM()), ptr.asLLVM(), name)! LLVMSetOrdering(loadInst, ordering.llvm) LLVMSetVolatile(loadInst, volatile.llvm) if !alignment.isZero { @@ -1972,7 +1972,7 @@ extension IRBuilder { /// struct value. @available(*, deprecated, message: "Use buildStructGEP(_:type:index:name) instead") public func buildStructGEP(_ ptr: IRValue, index: Int, name: String = "") -> IRValue { - return LLVMBuildStructGEP(llvm, ptr.asLLVM(), UInt32(index), name) + return LLVMBuildStructGEP2(llvm, LLVMTypeOf(ptr.asLLVM()), ptr.asLLVM(), UInt32(index), name) } /// Build a GEP (Get Element Pointer) instruction. @@ -1992,7 +1992,7 @@ extension IRBuilder { public func buildGEP(_ ptr: IRValue, indices: [IRValue], name: String = "") -> IRValue { var vals = indices.map { $0.asLLVM() as Optional } return vals.withUnsafeMutableBufferPointer { buf in - return LLVMBuildGEP(llvm, ptr.asLLVM(), buf.baseAddress, UInt32(buf.count), name) + return LLVMBuildGEP2(llvm, LLVMTypeOf(ptr.asLLVM()), ptr.asLLVM(), buf.baseAddress, UInt32(buf.count), name) } } @@ -2015,7 +2015,7 @@ extension IRBuilder { public func buildInBoundsGEP(_ ptr: IRValue, indices: [IRValue], name: String = "") -> IRValue { var vals = indices.map { $0.asLLVM() as Optional } return vals.withUnsafeMutableBufferPointer { buf in - return LLVMBuildInBoundsGEP(llvm, ptr.asLLVM(), buf.baseAddress, UInt32(buf.count), name) + return LLVMBuildInBoundsGEP2(llvm, LLVMTypeOf(ptr.asLLVM()), ptr.asLLVM(), buf.baseAddress, UInt32(buf.count), name) } } } diff --git a/Sources/LLVM/IRType.swift b/Sources/LLVM/IRType.swift index a77b1982..9d24525a 100644 --- a/Sources/LLVM/IRType.swift +++ b/Sources/LLVM/IRType.swift @@ -1,4 +1,5 @@ #if SWIFT_PACKAGE +import Glibc import cllvm #endif diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index 2a89c4b0..6b5d7895 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -30,38 +30,28 @@ public final class JIT { /// A type that represents an address, either symbolically within the JIT or /// physically in the execution environment. public struct TargetAddress: Comparable { - fileprivate var llvm: LLVMOrcTargetAddress /// Creates a target address value of `0`. public init() { - self.llvm = 0 - } - - /// Creates a target address from a raw address value. - public init(raw: LLVMOrcTargetAddress) { - self.llvm = raw } public static func == (lhs: TargetAddress, rhs: TargetAddress) -> Bool { - return lhs.llvm == rhs.llvm + return true } public static func < (lhs: TargetAddress, rhs: TargetAddress) -> Bool { - return lhs.llvm < rhs.llvm + return true } } /// Represents a handle to a module owned by the JIT stack. public struct ModuleHandle { - fileprivate var llvm: LLVMOrcModuleHandle } /// The underlying LLVMExecutionEngineRef backing this JIT. - internal let llvm: LLVMOrcJITStackRef private let ownsContext: Bool - internal init(llvm: LLVMOrcJITStackRef, ownsContext: Bool) { - self.llvm = llvm + internal init(ownsContext: Bool) { self.ownsContext = ownsContext } @@ -69,7 +59,7 @@ public final class JIT { public convenience init(machine: TargetMachine) { // The JIT stack takes ownership of the target machine. machine.ownsContext = false - self.init(llvm: LLVMOrcCreateInstance(machine.llvm), ownsContext: true) + self.init(ownsContext: true) } /// Deinitialize this value and dispose of its resources. @@ -77,7 +67,6 @@ public final class JIT { guard self.ownsContext else { return } - _ = LLVMOrcDisposeInstance(self.llvm) } // MARK: Symbols @@ -88,12 +77,10 @@ public final class JIT { /// - parameter symbol: The symbol name to mangle. /// - returns: A mangled representation of the given symbol name. public func mangle(symbol: String) -> String { - var mangledResult: UnsafeMutablePointer? = nil - LLVMOrcGetMangledSymbol(self.llvm, &mangledResult, symbol) + let mangledResult: UnsafeMutablePointer? = nil guard let result = mangledResult else { fatalError("Mangled name should never be nil!") } - defer { LLVMOrcDisposeMangledSymbol(mangledResult) } return String(cString: result) } @@ -106,13 +93,7 @@ public final class JIT { /// restrict the search, if any. /// - returns: The address of the symbol, or 0 if it does not exist. public func address(of symbol: String, in module: ModuleHandle? = nil) throws -> TargetAddress { - var retAddr: LLVMOrcTargetAddress = 0 - if let targetModule = module { - try checkForJITError(LLVMOrcGetSymbolAddressIn(self.llvm, &retAddr, targetModule.llvm, symbol)) - } else { - try checkForJITError(LLVMOrcGetSymbolAddress(self.llvm, &retAddr, symbol)) - } - return TargetAddress(raw: retAddr) + return TargetAddress() } // MARK: Lazy Compilation @@ -132,11 +113,7 @@ public final class JIT { /// - returns: The target address representing a stub. Calling this stub /// forces the given compilation callback to fire. public func registerLazyCompile(_ callback: @escaping (JIT) -> TargetAddress) throws -> TargetAddress { - var addr: LLVMOrcTargetAddress = 0 - let callbackContext = ORCLazyCompileCallbackContext(callback) - let contextPtr = Unmanaged.passRetained(callbackContext).toOpaque() - try checkForJITError(LLVMOrcCreateLazyCompileCallback(self.llvm, &addr, lazyCompileBlockTrampoline, contextPtr)) - return TargetAddress(raw: addr) + return TargetAddress() } // MARK: Stubs @@ -149,7 +126,6 @@ public final class JIT { /// - parameter name: The name of the indirect stub. /// - parameter address: The address of the indirect stub. public func createIndirectStub(named name: String, address: TargetAddress) throws { - try checkForJITError(LLVMOrcCreateIndirectStub(self.llvm, name, address.llvm)) } /// Resets the address of an indirect stub. @@ -161,7 +137,6 @@ public final class JIT { /// - parameter name: The name of an indirect stub. /// - parameter address: The address to set the indirect stub to point to. public func setIndirectStubPointer(named name: String, address: TargetAddress) throws { - try checkForJITError(LLVMOrcSetIndirectStubPointer(self.llvm, name, address.llvm)) } // MARK: Adding Code to the JIT @@ -185,14 +160,14 @@ public final class JIT { /// - parameter module: The module to compile. /// - parameter callback: A function that is called by the JIT to compute the /// address of symbols. - public func addEagerlyCompiledIR(_ module: Module, _ callback: @escaping (String) -> TargetAddress) throws -> ModuleHandle { - var handle: LLVMOrcModuleHandle = 0 - let callbackContext = ORCSymbolCallbackContext(callback) - let contextPtr = Unmanaged.passRetained(callbackContext).toOpaque() + public func addEagerlyCompiledIR( + _ module: Module, + _ callback: @escaping (String) + -> TargetAddress + ) throws -> ModuleHandle { // The JIT stack takes ownership of the given module. module.ownsContext = false - try checkForJITError(LLVMOrcAddEagerlyCompiledIR(self.llvm, &handle, module.llvm, symbolBlockTrampoline, contextPtr)) - return ModuleHandle(llvm: handle) + return ModuleHandle() } /// Adds the IR from a given module to the JIT, consuming it in the process. @@ -214,13 +189,9 @@ public final class JIT { /// - parameter callback: A function that is called by the JIT to compute the /// address of symbols. public func addLazilyCompiledIR(_ module: Module, _ callback: @escaping (String) -> TargetAddress) throws -> ModuleHandle { - var handle: LLVMOrcModuleHandle = 0 - let callbackContext = ORCSymbolCallbackContext(callback) - let contextPtr = Unmanaged.passRetained(callbackContext).toOpaque() // The JIT stack takes ownership of the given module. module.ownsContext = false - try checkForJITError(LLVMOrcAddLazilyCompiledIR(self.llvm, &handle, module.llvm, symbolBlockTrampoline, contextPtr)) - return ModuleHandle(llvm: handle) + return ModuleHandle() } /// Adds the executable code from an object file to ths JIT, consuming it in @@ -239,13 +210,9 @@ public final class JIT { /// - parameter callback: A function that is called by the JIT to compute the /// address of symbols. public func addObjectFile(_ buffer: MemoryBuffer, _ callback: @escaping (String) -> TargetAddress) throws -> ModuleHandle { - var handle: LLVMOrcModuleHandle = 0 - let callbackContext = ORCSymbolCallbackContext(callback) - let contextPtr = Unmanaged.passRetained(callbackContext).toOpaque() // The JIT stack takes ownership of the given buffer. buffer.ownsContext = false - try checkForJITError(LLVMOrcAddObjectFile(self.llvm, &handle, buffer.llvm, symbolBlockTrampoline, contextPtr)) - return ModuleHandle(llvm: handle) + return ModuleHandle() } /// Remove previously-added code from the JIT. @@ -255,7 +222,6 @@ public final class JIT { /// /// - parameter handle: A handle to previously-added module. public func removeModule(_ handle: ModuleHandle) throws { - try checkForJITError(LLVMOrcRemoveModule(self.llvm, handle.llvm)) } private func checkForJITError(_ orcError: LLVMErrorRef!) throws { @@ -270,42 +236,11 @@ public final class JIT { } throw JITError.generic(String(cString: msg)) default: - guard let msg = LLVMOrcGetErrorMsg(self.llvm) else { - fatalError("Couldn't get the error message?") - } - throw JITError.generic(String(cString: msg)) + fatalError("Couldn't get the error message?") } } } -private let lazyCompileBlockTrampoline : LLVMOrcLazyCompileCallbackFn = { (callbackJIT, callbackCtx) in - guard let jit = callbackJIT, let ctx = callbackCtx else { - fatalError("Internal JIT callback and context must be non-nil") - } - - let tempJIT = JIT(llvm: jit, ownsContext: false) - let callback = Unmanaged.fromOpaque(ctx).takeUnretainedValue() - return callback.block(tempJIT).llvm -} - -private let symbolBlockTrampoline : LLVMOrcSymbolResolverFn = { (callbackName, callbackCtx) in - guard let cname = callbackName, let ctx = callbackCtx else { - fatalError("Internal JIT name and context must be non-nil") - } - - let name = String(cString: cname) - let callback = Unmanaged.fromOpaque(ctx).takeUnretainedValue() - return callback.block(name).llvm -} - -private class ORCLazyCompileCallbackContext { - fileprivate let block: (JIT) -> JIT.TargetAddress - - fileprivate init(_ block: @escaping (JIT) -> JIT.TargetAddress) { - self.block = block - } -} - private class ORCSymbolCallbackContext { fileprivate let block: (String) -> JIT.TargetAddress diff --git a/Sources/LLVM/Module.swift b/Sources/LLVM/Module.swift index 0487dd27..aaaa8270 100644 --- a/Sources/LLVM/Module.swift +++ b/Sources/LLVM/Module.swift @@ -1,4 +1,5 @@ #if SWIFT_PACKAGE +import Glibc import cllvm #endif @@ -586,7 +587,7 @@ extension Module { /// /// - returns: A value representing the newly created alias. public func addAlias(name: String, to aliasee: IRGlobal, type: IRType) -> Alias { - return Alias(llvm: LLVMAddAlias(llvm, type.asLLVM(), aliasee.asLLVM(), name)) + return Alias(llvm: LLVMAddAlias2(llvm, type.asLLVM(), 0, aliasee.asLLVM(), name)) } /// Append to the module-scope inline assembly blocks. diff --git a/Sources/LLVM/PassPipeliner.swift b/Sources/LLVM/PassPipeliner.swift index c4f6088e..5835b755 100644 --- a/Sources/LLVM/PassPipeliner.swift +++ b/Sources/LLVM/PassPipeliner.swift @@ -169,14 +169,6 @@ extension PassPipeliner { optimization: CodeGenOptLevel = .`default`, size: CodeGenOptLevel = .none ) { - let passBuilder = self.configurePassBuilder(optimization, size) - let functionPasses = - LLVMCreateFunctionPassManagerForModule(self.module.llvm)! - LLVMPassManagerBuilderPopulateFunctionPassManager(passBuilder, - functionPasses) - LLVMPassManagerBuilderDispose(passBuilder) - self.stages.append(name) - self.stageMapping[name] = .functionPassManager(functionPasses) } /// Adds a pipeline stage populated with module passes that LLVM considers @@ -193,46 +185,10 @@ extension PassPipeliner { optimization: CodeGenOptLevel = .`default`, size: CodeGenOptLevel = .none ) { - let passBuilder = self.configurePassBuilder(optimization, size) let modulePasses = LLVMCreatePassManager()! - LLVMPassManagerBuilderPopulateModulePassManager(passBuilder, modulePasses) - LLVMPassManagerBuilderDispose(passBuilder) - self.stages.append(name) - self.stageMapping[name] = .modulePassManager(modulePasses) - } - - private func configurePassBuilder( - _ opt: CodeGenOptLevel, - _ size: CodeGenOptLevel - ) -> LLVMPassManagerBuilderRef { - let passBuilder = LLVMPassManagerBuilderCreate()! - switch opt { - case .none: - LLVMPassManagerBuilderSetOptLevel(passBuilder, 0) - case .less: - LLVMPassManagerBuilderSetOptLevel(passBuilder, 1) - case .default: - LLVMPassManagerBuilderSetOptLevel(passBuilder, 2) - case .aggressive: - LLVMPassManagerBuilderSetOptLevel(passBuilder, 3) - } - - switch size { - case .none: - LLVMPassManagerBuilderSetSizeLevel(passBuilder, 0) - case .less: - LLVMPassManagerBuilderSetSizeLevel(passBuilder, 1) - case .default: - LLVMPassManagerBuilderSetSizeLevel(passBuilder, 2) - case .aggressive: - LLVMPassManagerBuilderSetSizeLevel(passBuilder, 3) - } - - return passBuilder } } - extension PassPipeliner { /// Configures and adds a pass to the given pass manager. /// @@ -246,142 +202,13 @@ extension PassPipeliner { static func configurePass( _ pass: Pass, passManager: LLVMPassManagerRef, - keepalive: inout [Any]) { + keepalive: inout [Any] + ) { switch pass { case .invalid(let reason): fatalError("Cannot configure pass: \(reason)") - case .aggressiveDCE: - LLVMAddAggressiveDCEPass(passManager) - case .bitTrackingDCE: - LLVMAddBitTrackingDCEPass(passManager) - case .alignmentFromAssumptions: - LLVMAddAlignmentFromAssumptionsPass(passManager) - case .cfgSimplification: - LLVMAddCFGSimplificationPass(passManager) - case .deadStoreElimination: - LLVMAddDeadStoreEliminationPass(passManager) - case .scalarizer: - LLVMAddScalarizerPass(passManager) - case .mergedLoadStoreMotion: - LLVMAddMergedLoadStoreMotionPass(passManager) - case .gvn: - LLVMAddGVNPass(passManager) - case .indVarSimplify: - LLVMAddIndVarSimplifyPass(passManager) - case .instructionCombining: - LLVMAddInstructionCombiningPass(passManager) - case .jumpThreading: - LLVMAddJumpThreadingPass(passManager) - case .licm: - LLVMAddLICMPass(passManager) - case .loopDeletion: - LLVMAddLoopDeletionPass(passManager) - case .loopIdiom: - LLVMAddLoopIdiomPass(passManager) - case .loopRotate: - LLVMAddLoopRotatePass(passManager) - case .loopReroll: - LLVMAddLoopRerollPass(passManager) - case .loopUnroll: - LLVMAddLoopUnrollPass(passManager) - case .loopUnrollAndJam: - LLVMAddLoopUnrollAndJamPass(passManager) - case .loopUnswitch: - LLVMAddLoopUnswitchPass(passManager) - case .lowerAtomic: - LLVMAddLowerAtomicPass(passManager) - case .memCpyOpt: - LLVMAddMemCpyOptPass(passManager) - case .partiallyInlineLibCalls: - LLVMAddPartiallyInlineLibCallsPass(passManager) - case .lowerSwitch: - LLVMAddLowerSwitchPass(passManager) - case .promoteMemoryToRegister: - LLVMAddPromoteMemoryToRegisterPass(passManager) - case .addDiscriminators: - LLVMAddAddDiscriminatorsPass(passManager) - case .reassociate: - LLVMAddReassociatePass(passManager) - case .sccp: - LLVMAddSCCPPass(passManager) - case .tailCallElimination: - LLVMAddTailCallEliminationPass(passManager) - case .constantPropagation: - LLVMAddConstantPropagationPass(passManager) - case .demoteMemoryToRegister: - LLVMAddDemoteMemoryToRegisterPass(passManager) - case .verifier: - LLVMAddVerifierPass(passManager) - case .correlatedValuePropagation: - LLVMAddCorrelatedValuePropagationPass(passManager) - case .earlyCSE: - LLVMAddEarlyCSEPass(passManager) - case .lowerExpectIntrinsic: - LLVMAddLowerExpectIntrinsicPass(passManager) - case .typeBasedAliasAnalysis: - LLVMAddTypeBasedAliasAnalysisPass(passManager) - case .scopedNoAliasAA: - LLVMAddScopedNoAliasAAPass(passManager) - case .basicAliasAnalysis: - LLVMAddBasicAliasAnalysisPass(passManager) - case .globalsAliasAnalysis: - LLVMAddGlobalsAAWrapperPass(passManager) - case .unifyFunctionExitNodes: - LLVMAddUnifyFunctionExitNodesPass(passManager) - case .alwaysInliner: - LLVMAddAlwaysInlinerPass(passManager) - case .argumentPromotion: - LLVMAddArgumentPromotionPass(passManager) - case .constantMerge: - LLVMAddConstantMergePass(passManager) - case .deadArgElimination: - LLVMAddDeadArgEliminationPass(passManager) - case .functionAttrs: - LLVMAddFunctionAttrsPass(passManager) - case .functionInlining: - LLVMAddFunctionInliningPass(passManager) - case .globalDCE: - LLVMAddGlobalDCEPass(passManager) - case .globalOptimizer: - LLVMAddGlobalOptimizerPass(passManager) - case .ipConstantPropagation: - LLVMAddIPConstantPropagationPass(passManager) - case .ipscc: - LLVMAddIPSCCPPass(passManager) - case .pruneEH: - LLVMAddPruneEHPass(passManager) - case .stripDeadPrototypes: - LLVMAddStripDeadPrototypesPass(passManager) - case .stripSymbols: - LLVMAddStripSymbolsPass(passManager) - case .loopVectorize: - LLVMAddLoopVectorizePass(passManager) - case .slpVectorize: - LLVMAddSLPVectorizePass(passManager) - case .internalizeAll(let preserveMain): - LLVMAddInternalizePass(passManager, preserveMain == false ? 0 : 1) - case .internalize(let pred): - // The lifetime of this callback is must be manually managed to ensure - // it remains alive across the execution of the given pass manager. - - // Create a callback context at +1 - let callbackContext = InternalizeCallbackContext(pred) - // Stick it in the keepalive array, now at +2 - keepalive.append(callbackContext) - // Pass it unmanaged at +2 - let contextPtr = Unmanaged.passUnretained(callbackContext).toOpaque() - LLVMAddInternalizePassWithMustPreservePredicate(passManager, contextPtr) { globalValue, callbackCtx in - guard let globalValue = globalValue, let callbackCtx = callbackCtx else { - fatalError("Global value and context must be non-nil") - } - - let callback = Unmanaged.fromOpaque(callbackCtx).takeUnretainedValue() - return callback.block(realizeGlobalValue(globalValue)).llvm - } - // Context dropped, now at +1 - // When the keepalive array is dropped by the caller, it will drop to +0. - case .scalarReplacementOfAggregates: - LLVMAddScalarReplAggregatesPassWithThreshold(passManager, /*ignored*/ 0) + default: + fatalError("Cannot configure pass)") } } } diff --git a/Sources/LLVM/StructType.swift b/Sources/LLVM/StructType.swift index c71be697..f4620879 100644 --- a/Sources/LLVM/StructType.swift +++ b/Sources/LLVM/StructType.swift @@ -1,4 +1,5 @@ #if SWIFT_PACKAGE +import Glibc import cllvm #endif diff --git a/Sources/LLVM/TargetData.swift b/Sources/LLVM/TargetData.swift index d90eb2bc..14eab8f6 100644 --- a/Sources/LLVM/TargetData.swift +++ b/Sources/LLVM/TargetData.swift @@ -1,4 +1,5 @@ #if SWIFT_PACKAGE +import Glibc import cllvm #endif diff --git a/Sources/LLVM/TargetMachine.swift b/Sources/LLVM/TargetMachine.swift index 6c6995c9..b043230f 100644 --- a/Sources/LLVM/TargetMachine.swift +++ b/Sources/LLVM/TargetMachine.swift @@ -1,4 +1,5 @@ #if SWIFT_PACKAGE +import Glibc import cllvm #endif diff --git a/Sources/cllvm/shim.h b/Sources/cllvm/shim.h index 34606ac0..bbf620c9 100644 --- a/Sources/cllvm/shim.h +++ b/Sources/cllvm/shim.h @@ -12,19 +12,12 @@ #include #include #include -#include #include #include -#include #include #include -#include +#include #include #include #include -#include -#include -#include -#include -#include #include diff --git a/Sources/llvmshims/src/shim.cpp b/Sources/llvmshims/src/shim.cpp index 766d7b7e..b5bc7583 100644 --- a/Sources/llvmshims/src/shim.cpp +++ b/Sources/llvmshims/src/shim.cpp @@ -10,7 +10,6 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/Object/MachOUniversal.h" #include "llvm/Object/ObjectFile.h" -#include "llvm/Support/ARMTargetParser.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/IPO.h" @@ -41,14 +40,6 @@ extern "C" { // https://reviews.llvm.org/D66237 void LLVMAddGlobalsAAWrapperPass(LLVMPassManagerRef PM); - // https://reviews.llvm.org/D66061 - typedef enum { - LLVMTailCallKindNone, - LLVMTailCallKindTail, - LLVMTailCallKindMustTail, - LLVMTailCallKindNoTail - } LLVMTailCallKind; - LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst); void LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind TCK); } @@ -64,18 +55,6 @@ const char *LLVMSwiftGetIntrinsicAtIndex(size_t index) { return llvm::Intrinsic::getName(static_cast(index)).data(); } -LLVMARMProfileKind LLVMARMParseArchProfile(const char *Name, size_t NameLen) { - return static_cast(llvm::ARM::parseArchProfile({Name, NameLen})); -} - -unsigned LLVMARMParseArchVersion(const char *Name, size_t NameLen) { - return llvm::ARM::parseArchVersion({Name, NameLen}); -} - -const char *LLVMGetARMCanonicalArchName(const char *Name, size_t NameLen) { - return llvm::ARM::getCanonicalArchName({Name, NameLen}).data(); -} - uint64_t LLVMGlobalGetGUID(LLVMValueRef Glob) { return unwrap(Glob)->getGUID(); } From 3b8a36b3ad76f38c0ff37137c83a92a4472a6660 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 11:50:34 +0100 Subject: [PATCH 02/13] Remove stuff. --- Sources/LLVM/Triple.swift | 109 +------------------------------------- 1 file changed, 1 insertion(+), 108 deletions(-) diff --git a/Sources/LLVM/Triple.swift b/Sources/LLVM/Triple.swift index 325671d0..f27bb239 100644 --- a/Sources/LLVM/Triple.swift +++ b/Sources/LLVM/Triple.swift @@ -530,113 +530,6 @@ extension Triple { } } - func parseARMArch(_ ArchName: Substring) -> Architecture { - enum ARMISA { - case invalid - case arm - case thumb - case aarch64 - } - func parseISA(_ Arch: Substring) -> ARMISA { - switch Arch { - case let x where x.starts(with: "aarch64"): - return .aarch64 - case let x where x.starts(with: "arm64"): - return .aarch64 - case let x where x.starts(with: "thumb"): - return .thumb - case let x where x.starts(with: "arm"): - return .arm - default: - return .invalid - } - } - - enum EndianKind { - case invalid - case little - case big - } - - func parseArchEndian(_ Arch: Substring) -> EndianKind { - if (Arch.starts(with: "armeb") || Arch.starts(with: "thumbeb") || - Arch.starts(with: "aarch64_be")) { - return .big - } - - if Arch.starts(with: "arm") || Arch.starts(with: "thumb") { - if Arch.hasSuffix("eb") { - return .big - } else { - return .little - } - } - - if Arch.starts(with: "aarch64") { - return .little - } - - return .invalid - } - - let isa = parseISA(archName) - let endian = parseArchEndian(archName) - - var arch = Architecture.unknown - switch endian { - case .little: - switch isa { - case .arm: - arch = .arm - case .thumb: - arch = .thumb - case .aarch64: - arch = .aarch64 - case .invalid: - break - } - case .big: - switch isa { - case .arm: - arch = .armeb - case .thumb: - arch = .thumbeb - case .aarch64: - arch = .aarch64_be - case .invalid: - break - } - case .invalid: - break - } - - let ownedStr = String(archName) - guard let rawArch = LLVMGetARMCanonicalArchName(ownedStr, ownedStr.count) else { - fatalError() - } - let archName = String(cString: rawArch) - guard !archName.isEmpty else { - return .unknown - } - // Thumb only exists in v4+ - if isa == .thumb && (ArchName.starts(with: "v2") || ArchName.starts(with: "v3")) { - return .unknown - } - - // Thumb only for v6m - let Profile = LLVMARMParseArchProfile(archName, archName.count) - let Version = LLVMARMParseArchVersion(archName, archName.count) - if Profile == LLVMARMProfileKindM && Version == 6 { - if endian == .big { - return .thumbeb - } else { - return .thumb - } - } - - return arch - } - switch archName { case "i386", "i486", "i586", "i686": self = .x86 @@ -743,7 +636,7 @@ extension Triple { self = .renderscript64 default: if archName.starts(with: "arm") || archName.starts(with: "thumb") || archName.starts(with: "aarch64") { - self = parseARMArch(archName) + self = .unknown } else if archName.starts(with: "bpf") { self = parseBPFArch(archName) } else { From 27787a614a8095f4d7d825a81f4ffd4593685169 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 11:59:32 +0100 Subject: [PATCH 03/13] Address. --- Sources/LLVM/JIT.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index 6b5d7895..3c1d1df5 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -29,18 +29,22 @@ public enum JITError: Error, CustomStringConvertible { public final class JIT { /// A type that represents an address, either symbolically within the JIT or /// physically in the execution environment. + public struct TargetAddress: Comparable { + fileprivate var llvm: LLVMOrcJITTargetAddress + /// Creates a target address value of `0`. public init() { + self.llvm = 0 } public static func == (lhs: TargetAddress, rhs: TargetAddress) -> Bool { - return true + return lhs.llvm == rhs.llvm } public static func < (lhs: TargetAddress, rhs: TargetAddress) -> Bool { - return true + return lhs.llvm < rhs.llvm } } From 0e163385f8432179785798868a0964bbf465c172 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:04:30 +0100 Subject: [PATCH 04/13] Try new JIT. --- Sources/LLVM/JIT.swift | 255 +++----------------------------------- Sources/LLVM/Module.swift | 2 - Sources/cllvm/shim.h | 1 + 3 files changed, 18 insertions(+), 240 deletions(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index 3c1d1df5..a7462c2d 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -1,254 +1,33 @@ #if SWIFT_PACKAGE -import cllvm + import cllvm #endif -/// JITError represents the different kinds of errors the JIT compiler can -/// throw. -public enum JITError: Error, CustomStringConvertible { - /// A generic error thrown by the JIT during exceptional circumstances. - /// - /// In general, it is not safe to catch and continue after this exception has - /// been thrown. - case generic(String) - - public var description: String { - switch self { - case let .generic(desc): - return desc - } - } -} - -/// A `JIT` is a Just-In-Time compiler that will compile and execute LLVM IR -/// that has been generated in a `Module`. It can execute arbitrary functions -/// and return the value the function generated, allowing you to write -/// interactive programs that will run as soon as they are compiled. -/// -/// The JIT is fundamentally lazy, and allows control over when and how symbols -/// are resolved. public final class JIT { - /// A type that represents an address, either symbolically within the JIT or - /// physically in the execution environment. - - public struct TargetAddress: Comparable { - fileprivate var llvm: LLVMOrcJITTargetAddress + let jit: UnsafeMutablePointer? = nil + let mainDyLib: LLVMOrcJITDylibRef - /// Creates a target address value of `0`. - public init() { - self.llvm = 0 - } + public init() { + LLVMInitializeNativeTarget() + LLVMInitializeNativeAsmPrinter() - public static func == (lhs: TargetAddress, rhs: TargetAddress) -> Bool { - return lhs.llvm == rhs.llvm - } - - public static func < (lhs: TargetAddress, rhs: TargetAddress) -> Bool { - return lhs.llvm < rhs.llvm - } + LLVMOrcCreateLLJIT(self.jit, nil) + self.mainDyLib = LLVMOrcLLJITGetMainJITDylib(jit!.pointee) } - /// Represents a handle to a module owned by the JIT stack. - public struct ModuleHandle { - } + func compile(module: Module, name: String) -> LLVMOrcExecutorAddress { + let threadContext = LLVMOrcCreateNewThreadSafeContext() + let threadModule = LLVMOrcCreateNewThreadSafeModule(module.llvm, threadContext) + LLVMOrcLLJITAddLLVMIRModule(jit!.pointee, self.mainDyLib, threadModule) - /// The underlying LLVMExecutionEngineRef backing this JIT. - private let ownsContext: Bool + let res = UnsafeMutablePointer(bitPattern: 0) + LLVMOrcLLJITLookup(jit!.pointee, res, name) - internal init(ownsContext: Bool) { - self.ownsContext = ownsContext + return res!.pointee } - /// Create and initialize a `JIT` with this target machine's representation. - public convenience init(machine: TargetMachine) { - // The JIT stack takes ownership of the target machine. - machine.ownsContext = false - self.init(ownsContext: true) - } - - /// Deinitialize this value and dispose of its resources. deinit { - guard self.ownsContext else { - return - } - } - - // MARK: Symbols - - /// Mangles the given symbol name according to the data layout of the JIT's - /// target machine. - /// - /// - parameter symbol: The symbol name to mangle. - /// - returns: A mangled representation of the given symbol name. - public func mangle(symbol: String) -> String { - let mangledResult: UnsafeMutablePointer? = nil - guard let result = mangledResult else { - fatalError("Mangled name should never be nil!") - } - return String(cString: result) - } - - /// Computes the address of the given symbol, optionally restricting the - /// search for its address to a particular module. If this symbol does not - /// exist, an address of `0` is returned. - /// - /// - parameter symbol: The symbol name to search for. - /// - parameter module: An optional value describing the module in which to - /// restrict the search, if any. - /// - returns: The address of the symbol, or 0 if it does not exist. - public func address(of symbol: String, in module: ModuleHandle? = nil) throws -> TargetAddress { - return TargetAddress() - } - - // MARK: Lazy Compilation - - /// Registers a lazy compile callback that can be used to get the target - /// address of a trampoline function. When that trampoline address is - /// called, the given compilation callback is fired. - /// - /// Normally, the trampoline function is a known stub that has been previously - /// registered with the JIT. The callback then computes the address of a - /// known entry point and sets the address of the stub to it. See - /// `JIT.createIndirectStub` to create a stub function and - /// `JIT.setIndirectStubPointer` to set the address of a stub. - /// - /// - parameter callback: A callback that returns the actual address of the - /// trampoline function. - /// - returns: The target address representing a stub. Calling this stub - /// forces the given compilation callback to fire. - public func registerLazyCompile(_ callback: @escaping (JIT) -> TargetAddress) throws -> TargetAddress { - return TargetAddress() - } - - // MARK: Stubs - - /// Creates a new named indirect stub pointing to the given target address. - /// - /// An indirect stub may be resolved to a different address at any time by - /// invoking `JIT.setIndirectStubPointer`. - /// - /// - parameter name: The name of the indirect stub. - /// - parameter address: The address of the indirect stub. - public func createIndirectStub(named name: String, address: TargetAddress) throws { - } - - /// Resets the address of an indirect stub. - /// - /// - warning: The indirect stub must be registered with a call to - /// `JIT.createIndirectStub`. Failure to do so will result in undefined - /// behavior. - /// - /// - parameter name: The name of an indirect stub. - /// - parameter address: The address to set the indirect stub to point to. - public func setIndirectStubPointer(named name: String, address: TargetAddress) throws { - } - - // MARK: Adding Code to the JIT - - /// Adds the IR from a given module to the JIT, consuming it in the process. - /// - /// Despite the name of this function, the callback to compile the symbols in - /// the module is not necessarily called immediately. It is called at least - /// when a given symbol's address is requested, either by the JIT or by - /// the user e.g. `JIT.address(of:)`. - /// - /// The callback function is required to compute the address of the given - /// symbol. The symbols are passed in mangled form. Use - /// `JIT.mangle(symbol:)` to request the mangled name of a symbol. - /// - /// - warning: The JIT invalidates the underlying reference to the provided - /// module. Further references to the module are thus dangling pointers and - /// may be a source of subtle memory bugs. This will be addressed in a - /// future revision of LLVM. - /// - /// - parameter module: The module to compile. - /// - parameter callback: A function that is called by the JIT to compute the - /// address of symbols. - public func addEagerlyCompiledIR( - _ module: Module, - _ callback: @escaping (String) - -> TargetAddress - ) throws -> ModuleHandle { - // The JIT stack takes ownership of the given module. - module.ownsContext = false - return ModuleHandle() - } - - /// Adds the IR from a given module to the JIT, consuming it in the process. - /// - /// This function differs from `JIT.addEagerlyCompiledIR` in that the callback - /// to request the address of symbols is only executed when that symbol is - /// called, either in user code or by the JIT. - /// - /// The callback function is required to compute the address of the given - /// symbol. The symbols are passed in mangled form. Use - /// `JIT.mangle(symbol:)` to request the mangled name of a symbol. - /// - /// - warning: The JIT invalidates the underlying reference to the provided - /// module. Further references to the module are thus dangling pointers and - /// may be a source of subtle memory bugs. This will be addressed in a - /// future revision of LLVM. - /// - /// - parameter module: The module to compile. - /// - parameter callback: A function that is called by the JIT to compute the - /// address of symbols. - public func addLazilyCompiledIR(_ module: Module, _ callback: @escaping (String) -> TargetAddress) throws -> ModuleHandle { - // The JIT stack takes ownership of the given module. - module.ownsContext = false - return ModuleHandle() - } - - /// Adds the executable code from an object file to ths JIT, consuming it in - /// the process. - /// - /// The callback function is required to compute the address of the given - /// symbol. The symbols are passed in mangled form. Use - /// `JIT.mangle(symbol:)` to request the mangled name of a symbol. - /// - /// - warning: The JIT invalidates the underlying reference to the provided - /// memory buffer. Further references to the buffer are thus dangling - /// pointers and may be a source of subtle memory bugs. This will be - /// addressed in a future revision of LLVM. - /// - /// - parameter buffer: A buffer containing an object file. - /// - parameter callback: A function that is called by the JIT to compute the - /// address of symbols. - public func addObjectFile(_ buffer: MemoryBuffer, _ callback: @escaping (String) -> TargetAddress) throws -> ModuleHandle { - // The JIT stack takes ownership of the given buffer. - buffer.ownsContext = false - return ModuleHandle() - } - - /// Remove previously-added code from the JIT. - /// - /// - warning: Removing a module handle consumes the handle. Further use of - /// the handle will then result in undefined behavior. - /// - /// - parameter handle: A handle to previously-added module. - public func removeModule(_ handle: ModuleHandle) throws { - } - - private func checkForJITError(_ orcError: LLVMErrorRef!) throws { - guard let err = orcError else { - return - } - - switch LLVMGetErrorTypeId(err)! { - case LLVMGetStringErrorTypeId(): - guard let msg = LLVMGetErrorMessage(err) else { - fatalError("Couldn't get the error message?") - } - throw JITError.generic(String(cString: msg)) - default: - fatalError("Couldn't get the error message?") - } - } -} - -private class ORCSymbolCallbackContext { - fileprivate let block: (String) -> JIT.TargetAddress - - fileprivate init(_ block: @escaping (String) -> JIT.TargetAddress) { - self.block = block + LLVMOrcDisposeLLJIT(jit!.pointee) + LLVMShutdown() } } diff --git a/Sources/LLVM/Module.swift b/Sources/LLVM/Module.swift index aaaa8270..8da97227 100644 --- a/Sources/LLVM/Module.swift +++ b/Sources/LLVM/Module.swift @@ -84,7 +84,6 @@ public final class Module: CustomStringConvertible { /// Returns the context associated with this module. public let context: Context - /// Creates a `Module` with the given name. /// /// - parameter name: The name of the module. @@ -99,7 +98,6 @@ public final class Module: CustomStringConvertible { self.context = context } - /// Deinitialize this value and dispose of its resources. deinit { guard self.ownsContext else { diff --git a/Sources/cllvm/shim.h b/Sources/cllvm/shim.h index bbf620c9..9b67679c 100644 --- a/Sources/cllvm/shim.h +++ b/Sources/cllvm/shim.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include From 305d778a3d517208bde0355538846e6300c8cad4 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:06:00 +0100 Subject: [PATCH 05/13] Public. --- Sources/LLVM/JIT.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index a7462c2d..6a203bfa 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -15,7 +15,7 @@ public final class JIT { self.mainDyLib = LLVMOrcLLJITGetMainJITDylib(jit!.pointee) } - func compile(module: Module, name: String) -> LLVMOrcExecutorAddress { + public func compile(module: Module, name: String) -> LLVMOrcExecutorAddress { let threadContext = LLVMOrcCreateNewThreadSafeContext() let threadModule = LLVMOrcCreateNewThreadSafeModule(module.llvm, threadContext) LLVMOrcLLJITAddLLVMIRModule(jit!.pointee, self.mainDyLib, threadModule) From e8f4b6ed9df0b607e60a22b0fa8c124cae93b6dd Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:10:11 +0100 Subject: [PATCH 06/13] Fix. --- Sources/LLVM/JIT.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index 6a203bfa..af541c2c 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -4,7 +4,7 @@ public final class JIT { - let jit: UnsafeMutablePointer? = nil + let jit = UnsafeMutablePointer(bitPattern: 0) let mainDyLib: LLVMOrcJITDylibRef public init() { From 5e543b3482dbfcd11032d3d7576ec73796525d48 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:17:15 +0100 Subject: [PATCH 07/13] Builder. --- Sources/LLVM/JIT.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index af541c2c..d1f19e30 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -11,7 +11,8 @@ public final class JIT { LLVMInitializeNativeTarget() LLVMInitializeNativeAsmPrinter() - LLVMOrcCreateLLJIT(self.jit, nil) + let jitBuilder = LLVMOrcCreateLLJITBuilder() + LLVMOrcCreateLLJIT(self.jit, jitBuilder) self.mainDyLib = LLVMOrcLLJITGetMainJITDylib(jit!.pointee) } From d5ad30a3177e59b2d6c391e02e9a965d5bc38921 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:20:48 +0100 Subject: [PATCH 08/13] bla. --- Sources/LLVM/JIT.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index d1f19e30..a02a0629 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -4,7 +4,7 @@ public final class JIT { - let jit = UnsafeMutablePointer(bitPattern: 0) + let jit: UnsafeMutablePointer? = nil let mainDyLib: LLVMOrcJITDylibRef public init() { From 7bd9067efd6d862d200a7f227ae7bfe0b3e890a1 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:31:16 +0100 Subject: [PATCH 09/13] Fix. --- Sources/LLVM/JIT.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index a02a0629..cc0a0f7a 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -4,7 +4,7 @@ public final class JIT { - let jit: UnsafeMutablePointer? = nil + var jit: LLVMOrcLLJITRef? = nil let mainDyLib: LLVMOrcJITDylibRef public init() { @@ -12,23 +12,23 @@ public final class JIT { LLVMInitializeNativeAsmPrinter() let jitBuilder = LLVMOrcCreateLLJITBuilder() - LLVMOrcCreateLLJIT(self.jit, jitBuilder) - self.mainDyLib = LLVMOrcLLJITGetMainJITDylib(jit!.pointee) + LLVMOrcCreateLLJIT(&self.jit, jitBuilder) + self.mainDyLib = LLVMOrcLLJITGetMainJITDylib(jit) } public func compile(module: Module, name: String) -> LLVMOrcExecutorAddress { let threadContext = LLVMOrcCreateNewThreadSafeContext() let threadModule = LLVMOrcCreateNewThreadSafeModule(module.llvm, threadContext) - LLVMOrcLLJITAddLLVMIRModule(jit!.pointee, self.mainDyLib, threadModule) + LLVMOrcLLJITAddLLVMIRModule(jit, self.mainDyLib, threadModule) let res = UnsafeMutablePointer(bitPattern: 0) - LLVMOrcLLJITLookup(jit!.pointee, res, name) + LLVMOrcLLJITLookup(jit, res, name) return res!.pointee } deinit { - LLVMOrcDisposeLLJIT(jit!.pointee) + LLVMOrcDisposeLLJIT(jit) LLVMShutdown() } } From bc169005aeafce997b08c23ed129423ecea7c211 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 17:33:12 +0100 Subject: [PATCH 10/13] Fix. --- Sources/LLVM/JIT.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/LLVM/JIT.swift b/Sources/LLVM/JIT.swift index cc0a0f7a..1f2d4a54 100644 --- a/Sources/LLVM/JIT.swift +++ b/Sources/LLVM/JIT.swift @@ -21,10 +21,10 @@ public final class JIT { let threadModule = LLVMOrcCreateNewThreadSafeModule(module.llvm, threadContext) LLVMOrcLLJITAddLLVMIRModule(jit, self.mainDyLib, threadModule) - let res = UnsafeMutablePointer(bitPattern: 0) - LLVMOrcLLJITLookup(jit, res, name) + var res: LLVMOrcExecutorAddress = 0 + LLVMOrcLLJITLookup(jit, &res, name) - return res!.pointee + return res } deinit { From 346014af579c3730d919d296070d7d518d7fb5ab Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 19:21:16 +0100 Subject: [PATCH 11/13] Fix build. --- Sources/cllvm/shim.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/cllvm/shim.h b/Sources/cllvm/shim.h index 9b67679c..97c66d5b 100644 --- a/Sources/cllvm/shim.h +++ b/Sources/cllvm/shim.h @@ -1,4 +1,3 @@ -#define _GNU_SOURCE #define __STDC_CONSTANT_MACROS #define __STDC_FORMAT_MACROS #define __STDC_LIMIT_MACROS From 883638b4893a596beabef0753804796162505fae Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Wed, 12 Mar 2025 19:41:03 +0100 Subject: [PATCH 12/13] Fix for CI. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 7f4fe106..01a9a90e 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:6.0.3 +// swift-tools-version:6.0.2 import PackageDescription From 9c2ef226a71ef6f2d91941599e1cab810555eb10 Mon Sep 17 00:00:00 2001 From: Gon Solo Date: Thu, 3 Apr 2025 23:11:40 +0200 Subject: [PATCH 13/13] Swift 6.1 fixes. --- Sources/LLVM/Constant.swift | 7 ++++--- Sources/LLVM/IRBuilder.swift | 12 ++++++++---- Sources/LLVM/PassPipeliner.swift | 2 +- Sources/llvmshims/include/shim.h | 11 +---------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Sources/LLVM/Constant.swift b/Sources/LLVM/Constant.swift index d205eb93..11aa34f6 100644 --- a/Sources/LLVM/Constant.swift +++ b/Sources/LLVM/Constant.swift @@ -151,14 +151,15 @@ extension Constant { /// behavior of the resulting constant value. /// /// - returns: A constant value representing the negation of the given constant. - public static func negate(_ lhs: Constant, overflowBehavior: OverflowBehavior = .default) -> Constant { - + public static func negate(_ lhs: Constant, overflowBehavior: OverflowBehavior = .default) + -> Constant + { let lhsVal = lhs.asLLVM() switch overflowBehavior { case .noSignedWrap: return Constant(llvm: LLVMConstNSWNeg(lhsVal)) case .noUnsignedWrap: - return Constant(llvm: LLVMConstNUWNeg(lhsVal)) + return Constant(llvm: LLVMConstNull(LLVMTypeOf(lhsVal))) case .default: return Constant(llvm: LLVMConstNeg(lhsVal)) } diff --git a/Sources/LLVM/IRBuilder.swift b/Sources/LLVM/IRBuilder.swift index ad1eff27..9f6d6a25 100644 --- a/Sources/LLVM/IRBuilder.swift +++ b/Sources/LLVM/IRBuilder.swift @@ -322,16 +322,20 @@ extension IRBuilder { /// - parameter name: The name for the newly inserted instruction. /// /// - returns: A value representing the negation of the given value. - public func buildNeg(_ value: IRValue, - overflowBehavior: OverflowBehavior = .default, - name: String = "") -> IRValue { + public func buildNeg( + _ value: IRValue, + overflowBehavior: OverflowBehavior = .default, + name: String = "" + ) -> IRValue { let val = value.asLLVM() if value.type is IntType { switch overflowBehavior { case .noSignedWrap: return LLVMBuildNSWNeg(llvm, val, name) case .noUnsignedWrap: - return LLVMBuildNUWNeg(llvm, val, name) + let negInst = LLVMBuildNeg(llvm, val, name) + LLVMSetNUW(negInst, 1) + return negInst! case .default: return LLVMBuildNeg(llvm, val, name) } diff --git a/Sources/LLVM/PassPipeliner.swift b/Sources/LLVM/PassPipeliner.swift index 5835b755..dff53bcc 100644 --- a/Sources/LLVM/PassPipeliner.swift +++ b/Sources/LLVM/PassPipeliner.swift @@ -185,7 +185,7 @@ extension PassPipeliner { optimization: CodeGenOptLevel = .`default`, size: CodeGenOptLevel = .none ) { - let modulePasses = LLVMCreatePassManager()! + _ = LLVMCreatePassManager()! } } diff --git a/Sources/llvmshims/include/shim.h b/Sources/llvmshims/include/shim.h index 30b5648e..672afaaa 100644 --- a/Sources/llvmshims/include/shim.h +++ b/Sources/llvmshims/include/shim.h @@ -1,4 +1,5 @@ #include +#include "llvm-c/Core.h" #include "llvm-c/Types.h" #include "llvm-c/Object.h" #include "llvm-c/DebugInfo.h" @@ -23,14 +24,4 @@ uint64_t LLVMGlobalGetGUID(LLVMValueRef Global); void LLVMAddGlobalsAAWrapperPass(LLVMPassManagerRef PM); -typedef enum { - LLVMTailCallKindNone, - LLVMTailCallKindTail, - LLVMTailCallKindMustTail, - LLVMTailCallKindNoTail -} LLVMTailCallKind; - -LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst); -void LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind TCK); - #endif /* LLVMSWIFT_LLVM_SHIM_H */