diff --git a/.gitignore b/.gitignore index 23f2926b..9b8dcfda 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Package.resolved Package.pins /*.xcodeproj /build +/.swiftpm diff --git a/README.md b/README.md index 33bfbe54..c29433a6 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ phi.addIncoming([ (elseVal, elseBB), ]) builder.buildStore(phi, to: local) -let ret = builder.buildLoad(local, name: "ret") +let ret = builder.buildLoad(local, type: FloatType.double, name: "ret") builder.buildRet(ret) ``` diff --git a/Sources/LLVM/IRBuilder.swift b/Sources/LLVM/IRBuilder.swift index d25e1a5e..eae8b515 100644 --- a/Sources/LLVM/IRBuilder.swift +++ b/Sources/LLVM/IRBuilder.swift @@ -1078,27 +1078,6 @@ extension IRBuilder { return storeInst } - /// Build a load instruction that loads a value from the location in the - /// given value. - /// - /// - parameter ptr: The pointer value to load from. - /// - parameter ordering: The ordering effect of the fence for this load, - /// if any. Defaults to a nonatomic load. - /// - parameter volatile: Whether this is a load from a volatile memory location. - /// - parameter alignment: The alignment of the access. - /// - parameter name: The name for the newly inserted instruction. - /// - /// - returns: A value representing the result of a load from the given - /// pointer value. - @available(*, deprecated, message: "Use buildLoad(type:ptr: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)! - LLVMSetOrdering(loadInst, ordering.llvm) - LLVMSetVolatile(loadInst, volatile.llvm) - LLVMSetAlignment(loadInst, alignment.rawValue) - return loadInst - } - /// Build a load instruction that loads a value from the location in the /// given value. /// @@ -1119,29 +1098,7 @@ extension IRBuilder { LLVMSetAlignment(loadInst, alignment.rawValue) return loadInst } - - /// Build a `GEP` (Get Element Pointer) instruction with a resultant value - /// that is undefined if the address is outside the actual underlying - /// allocated object and not the address one-past-the-end. - /// - /// 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 ptr: The base address for the index calculation. - /// - parameter indices: A list of indices that indicate which of the elements - /// of the aggregate object are indexed. - /// - parameter name: The name for the newly inserted instruction. - /// - /// - returns: A value representing the address of a subelement of the given - /// aggregate data structure value. - @available(*, deprecated, message: "Use buildInBoundsGEP(type:ptr:indices:name) instead") - 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) - } - } + /// Build a `GEP` (Get Element Pointer) instruction with a resultant value /// that is undefined if the address is outside the actual underlying @@ -1166,27 +1123,6 @@ extension IRBuilder { } } - /// 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 ptr: The base address for the index calculation. - /// - parameter indices: A list of indices that indicate which of the elements - /// of the aggregate object are indexed. - /// - parameter name: The name for the newly inserted instruction. - /// - /// - returns: A value representing the address of a subelement of the given - /// aggregate data structure value. - @available(*, deprecated, message: "Use buildGEP(type:ptr:indices:name) instead") - 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) - } - } - /// Build a GEP (Get Element Pointer) instruction. /// /// The `GEP` instruction is often the source of confusion. LLVM [provides a @@ -1207,20 +1143,6 @@ extension IRBuilder { return LLVMBuildGEP2(llvm, type.asLLVM(), ptr.asLLVM(), buf.baseAddress, UInt32(buf.count), name) } } - - /// Build a GEP (Get Element Pointer) instruction suitable for indexing into - /// a struct. - /// - /// - parameter ptr: The base address for the index calculation. - /// - parameter index: The offset from the base for the index calculation. - /// - parameter name: The name for the newly inserted instruction. - /// - /// - returns: A value representing the address of a subelement of the given - /// struct value. - @available(*, deprecated, message: "Use buildStructGEP(type:ptr:index:name) instead") - public func buildStructGEP(_ ptr: IRValue, index: Int, name: String = "") -> IRValue { - return LLVMBuildStructGEP(llvm, ptr.asLLVM(), UInt32(index), name) - } /// Build a GEP (Get Element Pointer) instruction suitable for indexing into /// a struct of a given type. @@ -1993,6 +1915,89 @@ extension IRBuilder { } } +// MARK: Deprecated APIs + +extension IRBuilder { + /// Build a load instruction that loads a value from the location in the + /// given value. + /// + /// - parameter ptr: The pointer value to load from. + /// - parameter ordering: The ordering effect of the fence for this load, + /// if any. Defaults to a nonatomic load. + /// - parameter volatile: Whether this is a load from a volatile memory location. + /// - parameter alignment: The alignment of the access. + /// - parameter name: The name for the newly inserted instruction. + /// + /// - returns: A value representing the result of a load from the given + /// 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)! + LLVMSetOrdering(loadInst, ordering.llvm) + LLVMSetVolatile(loadInst, volatile.llvm) + LLVMSetAlignment(loadInst, alignment.rawValue) + return loadInst + } + + /// Build a GEP (Get Element Pointer) instruction suitable for indexing into + /// a struct. + /// + /// - parameter ptr: The base address for the index calculation. + /// - parameter index: The offset from the base for the index calculation. + /// - parameter name: The name for the newly inserted instruction. + /// + /// - returns: A value representing the address of a subelement of the given + /// 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) + } + + /// 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 ptr: The base address for the index calculation. + /// - parameter indices: A list of indices that indicate which of the elements + /// of the aggregate object are indexed. + /// - parameter name: The name for the newly inserted instruction. + /// + /// - returns: A value representing the address of a subelement of the given + /// aggregate data structure value. + @available(*, deprecated, message: "Use buildGEP(_:type:indices:name) instead") + 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) + } + } + + /// Build a `GEP` (Get Element Pointer) instruction with a resultant value + /// that is undefined if the address is outside the actual underlying + /// allocated object and not the address one-past-the-end. + /// + /// 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 ptr: The base address for the index calculation. + /// - parameter indices: A list of indices that indicate which of the elements + /// of the aggregate object are indexed. + /// - parameter name: The name for the newly inserted instruction. + /// + /// - returns: A value representing the address of a subelement of the given + /// aggregate data structure value. + @available(*, deprecated, message: "Use buildInBoundsGEP(_:type:indices:name) instead") + 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) + } + } +} + private func lowerVector(_ type: IRType) -> IRType { guard let vectorType = type as? VectorType else { diff --git a/Tests/LLVMTests/BFC.swift b/Tests/LLVMTests/BFC.swift index b9f747a7..10e80c25 100644 --- a/Tests/LLVMTests/BFC.swift +++ b/Tests/LLVMTests/BFC.swift @@ -247,8 +247,8 @@ private func compileProgramBody( let flushExtern = Externs.flush.resolve(builder) var addressPointer: IRValue = cellTape.constGEP(indices: [ - IntType.int32.zero(), - IntType.int32.zero() + IntType.int32.zero(), // (*self) + IntType.int32.zero() // [0] ]) /// Create an artificial typedef and variable for the current @@ -291,7 +291,7 @@ private func compileProgramBody( switch c { case ">": // Move right - addressPointer = builder.buildGEP(addressPointer, indices: [ IntType.int32.constant(1) ]) + addressPointer = builder.buildGEP(addressPointer, type: cellTapeType, indices: [ IntType.int32.constant(1) ]) builder.currentDebugLocation = dibuilder.buildDebugLocation(at: (sourceLine, sourceColumn), in: scope) dibuilder.buildDbgValue(of: addressPointer, to: diVariable, atEndOf: builder.insertBlock!, @@ -299,7 +299,7 @@ private func compileProgramBody( location: builder.currentDebugLocation!) case "<": // Move left - addressPointer = builder.buildGEP(addressPointer, indices: [ IntType.int32.constant(-1) ]) + addressPointer = builder.buildGEP(addressPointer, type: cellTapeType, indices: [ IntType.int32.constant(-1) ]) builder.currentDebugLocation = dibuilder.buildDebugLocation(at: (sourceLine, sourceColumn), in: scope) dibuilder.buildDbgValue(of: addressPointer, to: diVariable, atEndOf: builder.insertBlock!, @@ -307,7 +307,7 @@ private func compileProgramBody( location: builder.currentDebugLocation!) case "+": // Increment - let value = builder.buildLoad(addressPointer) + let value = builder.buildLoad(addressPointer, type: cellType) let ptrUp = builder.buildAdd(value, cellType.constant(1)) builder.buildStore(ptrUp, to: addressPointer) builder.currentDebugLocation = dibuilder.buildDebugLocation(at: (sourceLine, sourceColumn), in: scope) @@ -317,7 +317,7 @@ private func compileProgramBody( location: builder.currentDebugLocation!) case "-": // Decrement - let value = builder.buildLoad(addressPointer) + let value = builder.buildLoad(addressPointer, type: cellType) let ptrDown = builder.buildSub(value, cellType.constant(1)) builder.buildStore(ptrDown, to: addressPointer) builder.currentDebugLocation = dibuilder.buildDebugLocation(at: (sourceLine, sourceColumn), in: scope) @@ -327,7 +327,7 @@ private func compileProgramBody( location: builder.currentDebugLocation!) case ".": // Write - let dataValue = builder.buildLoad(addressPointer) + let dataValue = builder.buildLoad(addressPointer, type: cellType) _ = builder.buildCall(putCharExtern, args: [dataValue]) builder.currentDebugLocation = dibuilder.buildDebugLocation(at: (sourceLine, sourceColumn), in: scope) case ",": @@ -343,7 +343,7 @@ private func compileProgramBody( let loopExit = function.appendBasicBlock(named: "exit") // If zero - let cond = builder.buildIsNotNull(builder.buildLoad(addressPointer)) + let cond = builder.buildIsNotNull(builder.buildLoad(addressPointer, type: cellType)) builder.buildCondBr(condition: cond, then: loopBody, else: loopExit) // Build a PHI for any address pointer changes in the exit block. @@ -387,7 +387,7 @@ private func compileProgramBody( loop.exitDestination.addIncoming([ (addressPointer, builder.insertBlock!) ]) // If not zero. - let cond = builder.buildIsNotNull(builder.buildLoad(addressPointer)) + let cond = builder.buildIsNotNull(builder.buildLoad(addressPointer, type: cellType)) builder.buildCondBr(condition: cond, then: loop.body, else: loop.exit) // Move the exit block after the loop body. diff --git a/Tests/LLVMTests/IRBuilderSpec.swift b/Tests/LLVMTests/IRBuilderSpec.swift index 772e47eb..b134023f 100644 --- a/Tests/LLVMTests/IRBuilderSpec.swift +++ b/Tests/LLVMTests/IRBuilderSpec.swift @@ -73,11 +73,11 @@ class IRBuilderSpec : XCTestCase { let g2 = builder.addGlobal("b", type: IntType.int32) g2.initializer = Int32(1) - // IRBUILDERARITH-NEXT: @vec1 = global <8 x i64> - // IRBUILDERARITH-NEXT: @vec2 = global <8 x i64> + // IRBUILDERARITH-NEXT: @vec1 = global <8 x i32> + // IRBUILDERARITH-NEXT: @vec2 = global <8 x i32> let vecTy = VectorType(elementType: IntType.int32, count: 8) - let gVec1 = builder.addGlobal("vec1", initializer: vecTy.constant([ 1, 1, 1, 1, 1, 1, 1, 1 ])) - let gVec2 = builder.addGlobal("vec2", initializer: vecTy.constant([ 2, 2, 2, 2, 2, 2, 2, 2 ])) + let gVec1 = builder.addGlobal("vec1", initializer: vecTy.constant([ 1, 1, 1, 1, 1, 1, 1, 1 ] as [Int32])) + let gVec2 = builder.addGlobal("vec2", initializer: vecTy.constant([ 2, 2, 2, 2, 2, 2, 2, 2 ] as [Int32])) // IRBUILDERARITH: define void @main() { let main = builder.addFunction("main", @@ -87,15 +87,15 @@ class IRBuilderSpec : XCTestCase { builder.positionAtEnd(of: entry) // IRBUILDERARITH-NEXT: [[A_LOAD:%[0-9]+]] = load i32, i32* @a - let vg1 = builder.buildLoad(g1) + let vg1 = builder.buildLoad(g1, type: IntType.int32) // IRBUILDERARITH-NEXT: [[B_LOAD:%[0-9]+]] = load i32, i32* @b - let vg2 = builder.buildLoad(g2) + let vg2 = builder.buildLoad(g2, type: IntType.int32) - // IRBUILDERARITH-NEXT: [[VEC1_LOAD:%[0-9]+]] = load <8 x i64>, <8 x i64>* @vec1 - let vgVec1 = builder.buildLoad(gVec1) + // IRBUILDERARITH-NEXT: [[VEC1_LOAD:%[0-9]+]] = load <8 x i32>, <8 x i32>* @vec1 + let vgVec1 = builder.buildLoad(gVec1, type: vecTy) - // IRBUILDERARITH-NEXT: [[VEC2_LOAD:%[0-9]+]] = load <8 x i64>, <8 x i64>* @vec2 - let vgVec2 = builder.buildLoad(gVec2) + // IRBUILDERARITH-NEXT: [[VEC2_LOAD:%[0-9]+]] = load <8 x i32>, <8 x i32>* @vec2 + let vgVec2 = builder.buildLoad(gVec2, type: vecTy) // IRBUILDERARITH-NEXT: {{%[0-9]+}} = add i32 [[A_LOAD]], [[B_LOAD]] _ = builder.buildAdd(vg1, vg2) @@ -122,15 +122,15 @@ class IRBuilderSpec : XCTestCase { // IRBUILDERARITH-NEXT: {{%[0-9]+}} = mul nuw i32 [[A_LOAD]], [[B_LOAD]] _ = builder.buildMul(vg1, vg2, overflowBehavior: .noUnsignedWrap) - // IRBUILDERARITH-NEXT: {{%[0-9]+}} = add <8 x i64> [[VEC1_LOAD]], [[VEC2_LOAD]] + // IRBUILDERARITH-NEXT: {{%[0-9]+}} = add <8 x i32> [[VEC1_LOAD]], [[VEC2_LOAD]] _ = builder.buildAdd(vgVec1, vgVec2) - // IRBUILDERARITH-NEXT: {{%[0-9]+}} = sub <8 x i64> [[VEC1_LOAD]], [[VEC2_LOAD]] + // IRBUILDERARITH-NEXT: {{%[0-9]+}} = sub <8 x i32> [[VEC1_LOAD]], [[VEC2_LOAD]] _ = builder.buildSub(vgVec1, vgVec2) - // IRBUILDERARITH-NEXT: {{%[0-9]+}} = mul <8 x i64> [[VEC1_LOAD]], [[VEC2_LOAD]] + // IRBUILDERARITH-NEXT: {{%[0-9]+}} = mul <8 x i32> [[VEC1_LOAD]], [[VEC2_LOAD]] _ = builder.buildMul(vgVec1, vgVec2) - // IRBUILDERARITH-NEXT: {{%[0-9]+}} = sdiv <8 x i64> [[VEC1_LOAD]], [[VEC2_LOAD]] + // IRBUILDERARITH-NEXT: {{%[0-9]+}} = sdiv <8 x i32> [[VEC1_LOAD]], [[VEC2_LOAD]] _ = builder.buildDiv(vgVec1, vgVec2, signed: true) - // IRBUILDERARITH-NEXT: {{%[0-9]+}} = udiv <8 x i64> [[VEC1_LOAD]], [[VEC2_LOAD]] + // IRBUILDERARITH-NEXT: {{%[0-9]+}} = udiv <8 x i32> [[VEC1_LOAD]], [[VEC2_LOAD]] _ = builder.buildDiv(vgVec1, vgVec2, signed: false) // IRBUILDERARITH-NEXT: {{%[0-9]+}} = sub i32 0, [[A_LOAD]] @@ -168,9 +168,9 @@ class IRBuilderSpec : XCTestCase { builder.positionAtEnd(of: entry) // IRBUILDERCMP-NEXT: %0 = load i32, i32* @a - let vg1 = builder.buildLoad(g1) + let vg1 = builder.buildLoad(g1, type: IntType.int32) // IRBUILDERCMP-NEXT: %1 = load i32, i32* @b - let vg2 = builder.buildLoad(g2) + let vg2 = builder.buildLoad(g2, type: IntType.int32) // IRBUILDERCMP-NEXT: %2 = icmp eq i32 %0, %1 _ = builder.buildICmp(vg1, vg2, .equal) @@ -221,9 +221,9 @@ class IRBuilderSpec : XCTestCase { builder.positionAtEnd(of: entry) // IRBUILDERFCMP-NEXT: %0 = load double, double* @a - let vg1 = builder.buildLoad(g1) + let vg1 = builder.buildLoad(g1, type: FloatType.double) // IRBUILDERFCMP-NEXT: %1 = load double, double* @b - let vg2 = builder.buildLoad(g2) + let vg2 = builder.buildLoad(g2, type: FloatType.double) // IRBUILDERFCMP-NEXT: %2 = fcmp oeq double %0, %1 _ = builder.buildFCmp(vg1, vg2, .orderedEqual) @@ -284,7 +284,7 @@ class IRBuilderSpec : XCTestCase { builder.buildStore(IntType.int64.constant(1), to: variable, ordering: .sequentiallyConsistent) // CONTROLFLOW-NEXT: %0 = load i64, i64* %var - let load = builder.buildLoad(variable) + let load = builder.buildLoad(variable, type: IntType.int64) // CONTROLFLOW-NEXT: %1 = icmp eq i64 %0, 0 let res = builder.buildICmp(load, IntType.int64.zero(), .equal) @@ -314,54 +314,54 @@ class IRBuilderSpec : XCTestCase { // MARK: Cast Instructions XCTAssert(fileCheckOutput(of: .stderr, withPrefixes: ["CAST"]) { - // CAST: ; ModuleID = '[[ModuleName:IRBuilderTest]]' - // CAST-NEXT: source_filename = "[[ModuleName]]" - let module = Module(name: "IRBuilderTest") - let builder = IRBuilder(module: module) + // CAST: ; ModuleID = '[[ModuleName:IRBuilderTest]]' + // CAST-NEXT: source_filename = "[[ModuleName]]" + let module = Module(name: "IRBuilderTest") + let builder = IRBuilder(module: module) - // CAST: define i32 @main() { - let main = builder.addFunction("main", - type: FunctionType([], - IntType.int32)) + // CAST: define i32 @main() { + let main = builder.addFunction("main", + type: FunctionType([], + IntType.int32)) - // CAST-NEXT: entry: - let entry = main.appendBasicBlock(named: "entry") - builder.positionAtEnd(of: entry) + // CAST-NEXT: entry: + let entry = main.appendBasicBlock(named: "entry") + builder.positionAtEnd(of: entry) - // CAST-NEXT: %0 = alloca i64 - let alloca = builder.buildAlloca(type: IntType.int64) + // CAST-NEXT: %0 = alloca i64 + let alloca = builder.buildAlloca(type: IntType.int64) - // CAST-NEXT: %1 = ptrtoint i64* %0 to i64 - _ = builder.buildPtrToInt(alloca, type: IntType.int64) + // CAST-NEXT: %1 = ptrtoint i64* %0 to i64 + _ = builder.buildPtrToInt(alloca, type: IntType.int64) - // CAST-NEXT: %2 = load i64, i64* %0 - let val = builder.buildLoad(alloca) + // CAST-NEXT: %2 = load i64, i64* %0 + let val = builder.buildLoad(alloca, type: IntType.int64) - // CAST-NEXT: %3 = inttoptr i64 %2 to i64* - _ = builder.buildIntToPtr(val, - type: PointerType(pointee: IntType.int64)) + // CAST-NEXT: %3 = inttoptr i64 %2 to i64* + _ = builder.buildIntToPtr(val, + type: PointerType(pointee: IntType.int64)) - // CAST-NEXT: %4 = bitcast i64* %0 to i8* - _ = builder.buildBitCast(alloca, type: PointerType.toVoid) + // CAST-NEXT: %4 = bitcast i64* %0 to i8* + _ = builder.buildBitCast(alloca, type: PointerType.toVoid) - // CAST-NEXT: %5 = alloca double - let dblAlloca = builder.buildAlloca(type: FloatType.double) + // CAST-NEXT: %5 = alloca double + let dblAlloca = builder.buildAlloca(type: FloatType.double) - // CAST-NEXT: %6 = load double, double* %5 - let dblVal = builder.buildLoad(dblAlloca) + // CAST-NEXT: %6 = load double, double* %5 + let dblVal = builder.buildLoad(dblAlloca, type: FloatType.double) - // CAST-NEXT: %7 = fptrunc double %6 to float - let fltVal = builder.buildFPCast(dblVal, type: FloatType.float) + // CAST-NEXT: %7 = fptrunc double %6 to float + let fltVal = builder.buildFPCast(dblVal, type: FloatType.float) - // CAST-NEXT: %8 = fpext float %7 to double - _ = builder.buildFPCast(fltVal, type: FloatType.double) + // CAST-NEXT: %8 = fpext float %7 to double + _ = builder.buildFPCast(fltVal, type: FloatType.double) - // CAST-NEXT: ret i32 0 - builder.buildRet(IntType.int32.constant(0)) + // CAST-NEXT: ret i32 0 + builder.buildRet(IntType.int32.constant(0)) - // CAST-NEXT: } - module.dump() + // CAST-NEXT: } + module.dump() }) // MARK: C Standard Library Instructions diff --git a/Tests/LLVMTests/IRInstructionSpec.swift b/Tests/LLVMTests/IRInstructionSpec.swift index c88ce280..5dd3448f 100644 --- a/Tests/LLVMTests/IRInstructionSpec.swift +++ b/Tests/LLVMTests/IRInstructionSpec.swift @@ -89,9 +89,9 @@ class IRInstructionSpec : XCTestCase { XCTAssertEqual((builder.buildVAArg(pval, type: PointerType.toVoid) as! IRInstruction).opCode, OpCode.vaArg) XCTAssertEqual(builder.buildAlloca(type: IntType.int1).opCode, OpCode.alloca) XCTAssertEqual(builder.buildStore(ival, to: pval).opCode, OpCode.store) - XCTAssertEqual(builder.buildLoad(pval).opCode, OpCode.load) - XCTAssertEqual((builder.buildInBoundsGEP(pval, indices: []) as! IRInstruction).opCode, OpCode.getElementPtr) - XCTAssertEqual((builder.buildGEP(pval, indices: []) as! IRInstruction).opCode, OpCode.getElementPtr) + XCTAssertEqual(builder.buildLoad(pval, type: IntType.int8).opCode, OpCode.load) + XCTAssertEqual((builder.buildInBoundsGEP(pval, type: IntType.int8, indices: []) as! IRInstruction).opCode, OpCode.getElementPtr) + XCTAssertEqual((builder.buildGEP(pval, type: IntType.int8, indices: []) as! IRInstruction).opCode, OpCode.getElementPtr) XCTAssertEqual((builder.buildExtractValue(sval, index: 0) as! IRInstruction).opCode, OpCode.extractValue) XCTAssertEqual((builder.buildTrunc(ival, type: IntType.int32) as! IRInstruction).opCode, OpCode.trunc) XCTAssertEqual((builder.buildSExt(ival, type: IntType.int32) as! IRInstruction).opCode, OpCode.sext) diff --git a/Tests/LLVMTests/IRIntrinsicSpec.swift b/Tests/LLVMTests/IRIntrinsicSpec.swift index 96b6a264..93df2f3b 100644 --- a/Tests/LLVMTests/IRIntrinsicSpec.swift +++ b/Tests/LLVMTests/IRIntrinsicSpec.swift @@ -85,7 +85,7 @@ class IRIntrinsicSpec : XCTestCase { let cpyVar = builder.buildCall(intrinsic, args: [variable]) // VIRTUALOVERLOAD-IRINTRINSIC-NEXT: [[LOAD_VAR:%[0-9]+]] = load i32, i32* [[COPY_PTR]] - let loadVar = builder.buildLoad(cpyVar) + let loadVar = builder.buildLoad(cpyVar, type: IntType.int32) // VIRTUALOVERLOAD-IRINTRINSIC-NEXT: ret i32 [[LOAD_VAR]] builder.buildRet(loadVar) @@ -110,15 +110,15 @@ class IRIntrinsicSpec : XCTestCase { let doubleAlloca = builder.buildAlloca(type: FloatType.double) builder.buildStore(FloatType.double.constant(1.0), to: doubleAlloca) - let double = builder.buildLoad(doubleAlloca) + let double = builder.buildLoad(doubleAlloca, type: FloatType.double) let floatAlloca = builder.buildAlloca(type: FloatType.float) builder.buildStore(FloatType.float.constant(1.0), to: floatAlloca) - let float = builder.buildLoad(floatAlloca) + let float = builder.buildLoad(floatAlloca, type: FloatType.float) let halfAlloca = builder.buildAlloca(type: FloatType.half) builder.buildStore(FloatType.half.constant(1.0), to: halfAlloca) - let half = builder.buildLoad(halfAlloca) + let half = builder.buildLoad(halfAlloca, type: FloatType.half) // INTRINSIC-FAMILY-RESOLVE: call double @llvm.sin.f64(double let sinf64 = module.intrinsic(Intrinsic.ID.llvm_sin, parameters: [ FloatType.double ])! diff --git a/Tests/LLVMTests/IRMetadataSpec.swift b/Tests/LLVMTests/IRMetadataSpec.swift index c626dcd9..7252a726 100644 --- a/Tests/LLVMTests/IRMetadataSpec.swift +++ b/Tests/LLVMTests/IRMetadataSpec.swift @@ -174,7 +174,7 @@ class IRMetadataSpec : XCTestCase { // IRSIMPLETBAA-NEXT: %0 = alloca { i32, { i16 } } let alloca = builder.buildAlloca(type: structTyB) // IRSIMPLETBAA-NEXT: %1 = getelementptr inbounds { i32, { i16 } }, { i32, { i16 } }* %0, i64 0, i32 1, i32 0 - let field = builder.buildInBoundsGEP(alloca, indices: [ + let field = builder.buildInBoundsGEP(alloca, type: structTyB, indices: [ IntType.int64.constant(0), // (*this) IntType.int32.constant(1), // .a IntType.int32.constant(0), // .s diff --git a/Tests/LLVMTests/IROperationSpec.swift b/Tests/LLVMTests/IROperationSpec.swift index 02f41847..a3c9505c 100644 --- a/Tests/LLVMTests/IROperationSpec.swift +++ b/Tests/LLVMTests/IROperationSpec.swift @@ -33,14 +33,14 @@ class IROperationSpec : XCTestCase { builder.positionAtEnd(of: entry) // BINARYOP-NEXT: %0 = load i32, i32* @a - let vgi1 = builder.buildLoad(gi1) + let vgi1 = builder.buildLoad(gi1, type: IntType.int32) // BINARYOP-NEXT: %1 = load i32, i32* @b - let vgi2 = builder.buildLoad(gi2) + let vgi2 = builder.buildLoad(gi2, type: IntType.int32) // BINARYOP-NEXT: %2 = load float, float* @c - let vgf1 = builder.buildLoad(gf1) + let vgf1 = builder.buildLoad(gf1, type: FloatType.float) // BINARYOP-NEXT: %3 = load float, float* @d - let vgf2 = builder.buildLoad(gf2) + let vgf2 = builder.buildLoad(gf2, type: FloatType.float) // BINARYOP-NEXT: %4 = add i32 %0, %1 _ = builder.buildBinaryOperation(.add, vgi1, vgi2) @@ -110,9 +110,9 @@ class IROperationSpec : XCTestCase { builder.positionAtEnd(of: entry) // CASTOP-NEXT: %0 = load i32, i32* @a - let vgi = builder.buildLoad(gi) + let vgi = builder.buildLoad(gi, type: IntType.int32) // CASTOP-NEXT: %1 = load float, float* @f - let vgf = builder.buildLoad(gf) + let vgf = builder.buildLoad(gf, type: FloatType.float) // CASTOP-NEXT: %2 = trunc i32 %0 to i16 _ = builder.buildCast(.trunc, value: vgi, type: IntType.int16) diff --git a/Tests/LLVMTests/IRPassManagerSpec.swift b/Tests/LLVMTests/IRPassManagerSpec.swift index 71984402..b01478d1 100644 --- a/Tests/LLVMTests/IRPassManagerSpec.swift +++ b/Tests/LLVMTests/IRPassManagerSpec.swift @@ -344,26 +344,26 @@ class IRPassManagerSpec : XCTestCase { builder.buildStore(fun.parameters[0], to: val1) builder.buildStore(fun.parameters[1], to: val2) builder.buildStore(IntType.int32.constant(4), to: val3) - let reloadVal1 = builder.buildLoad(val1, alignment: Alignment(4)) + let reloadVal1 = builder.buildLoad(val1, type: IntType.int32, alignment: Alignment(4)) let cmpVal = builder.buildICmp(reloadVal1, IntType.int32.constant(1), .equal) builder.buildCondBr(condition: cmpVal, then: block1, else: block2) builder.positionAtEnd(of: block1) - let reloadVal2 = builder.buildLoad(val1, alignment: Alignment(4)) - let reloadVal3 = builder.buildLoad(val3, alignment: Alignment(4)) + let reloadVal2 = builder.buildLoad(val1, type: IntType.int32, alignment: Alignment(4)) + let reloadVal3 = builder.buildLoad(val3, type: IntType.int32, alignment: Alignment(4)) let sum1 = builder.buildAdd(reloadVal2, reloadVal3, overflowBehavior: .noSignedWrap) builder.buildStore(sum1, to: val3) builder.buildBr(merge) builder.positionAtEnd(of: block2) - let reloadVal4 = builder.buildLoad(val2, alignment: Alignment(4)) - let reloadVal5 = builder.buildLoad(val3, alignment: Alignment(4)) + let reloadVal4 = builder.buildLoad(val2, type: IntType.int32, alignment: Alignment(4)) + let reloadVal5 = builder.buildLoad(val3, type: IntType.int32, alignment: Alignment(4)) let sum2 = builder.buildAdd(reloadVal4, reloadVal5, overflowBehavior: .noSignedWrap) builder.buildStore(sum2, to: val3) builder.buildBr(merge) builder.positionAtEnd(of: merge) - let reloadVal6 = builder.buildLoad(val3, alignment: Alignment(4)) + let reloadVal6 = builder.buildLoad(val3, type: IntType.int32, alignment: Alignment(4)) builder.buildRet(reloadVal6) return module diff --git a/Tests/LLVMTests/JITSpec.swift b/Tests/LLVMTests/JITSpec.swift index 5a620c04..372faf53 100644 --- a/Tests/LLVMTests/JITSpec.swift +++ b/Tests/LLVMTests/JITSpec.swift @@ -77,7 +77,7 @@ class JITSpec : XCTestCase { (elseVal, elseBB), ]) builder.buildStore(phi, to: local) - let ret = builder.buildLoad(local, name: "ret") + let ret = builder.buildLoad(local, type: FloatType.double, name: "ret") builder.buildRet(ret) let main = builder.addFunction("main", type: FunctionType([], VoidType()))