[Native] Move remaining usages for LLVMBuildLoad to LLVMBuildLoad2.
Step towards LLVM opaque pointers.
This commit is contained in:
+1
-1
@@ -128,7 +128,7 @@ private class CallsChecker(generationState: NativeGenerationState, goodFunctions
|
|||||||
calledName = null
|
calledName = null
|
||||||
val superStruct = LLVMGetArgOperand(call, 0)
|
val superStruct = LLVMGetArgOperand(call, 0)
|
||||||
val superClassPtrPtr = LLVMBuildGEP(builder, superStruct, listOf(llvm.int32(0), llvm.int32(1)).toCValues(), 2, "")
|
val superClassPtrPtr = LLVMBuildGEP(builder, superStruct, listOf(llvm.int32(0), llvm.int32(1)).toCValues(), 2, "")
|
||||||
val superClassPtr = LLVMBuildLoad(builder, superClassPtrPtr, "")!!
|
val superClassPtr = LLVMBuildLoad2(builder, llvm.int8PtrType, superClassPtrPtr, "")!!
|
||||||
val classPtr = getSuperClass.buildCall(builder, listOf(superClassPtr))
|
val classPtr = getSuperClass.buildCall(builder, listOf(superClassPtr))
|
||||||
val calledPtrLlvmFunPtr = getMethodImpl.buildCall(builder, listOf(classPtr, LLVMGetArgOperand(call, 1)!!))
|
val calledPtrLlvmFunPtr = getMethodImpl.buildCall(builder, listOf(classPtr, LLVMGetArgOperand(call, 1)!!))
|
||||||
calledPtrLlvm = LLVMBuildBitCast(builder, calledPtrLlvmFunPtr, llvm.int8PtrType, "")!!
|
calledPtrLlvm = LLVMBuildBitCast(builder, calledPtrLlvmFunPtr, llvm.int8PtrType, "")!!
|
||||||
|
|||||||
+12
-5
@@ -725,13 +725,20 @@ internal abstract class FunctionGenerationContext(
|
|||||||
return applyMemoryOrderAndAlignment(LLVMBuildLoad2(builder, type, address, name)!!, memoryOrder, alignment)
|
return applyMemoryOrderAndAlignment(LLVMBuildLoad2(builder, type, address, name)!!, memoryOrder, alignment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadSlot(address: LLVMValueRef, isVar: Boolean, resultSlot: LLVMValueRef? = null, name: String = "",
|
fun loadSlot(
|
||||||
memoryOrder: LLVMAtomicOrdering? = null, alignment: Int? = null): LLVMValueRef {
|
type: LLVMTypeRef,
|
||||||
val value = LLVMBuildLoad(builder, address, name)!!
|
address: LLVMValueRef,
|
||||||
|
isVar: Boolean,
|
||||||
|
resultSlot: LLVMValueRef? = null,
|
||||||
|
name: String = "",
|
||||||
|
memoryOrder: LLVMAtomicOrdering? = null,
|
||||||
|
alignment: Int? = null
|
||||||
|
): LLVMValueRef {
|
||||||
|
val value = LLVMBuildLoad2(builder, type, address, name)!!
|
||||||
memoryOrder?.let { LLVMSetOrdering(value, it) }
|
memoryOrder?.let { LLVMSetOrdering(value, it) }
|
||||||
alignment?.let { LLVMSetAlignment(value, it) }
|
alignment?.let { LLVMSetAlignment(value, it) }
|
||||||
if (isObjectRef(value) && isVar) {
|
if (isObjectType(type) && isVar) {
|
||||||
val slot = resultSlot ?: alloca(LLVMTypeOf(value), variableLocation = null)
|
val slot = resultSlot ?: alloca(type, variableLocation = null)
|
||||||
storeStackRef(value, slot)
|
storeStackRef(value, slot)
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
|||||||
+1
-1
@@ -419,7 +419,7 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv
|
|||||||
private fun FunctionGenerationContext.emitAtomicGetArrayElement(callSite: IrCall, args: List<LLVMValueRef>, resultSlot: LLVMValueRef?): LLVMValueRef {
|
private fun FunctionGenerationContext.emitAtomicGetArrayElement(callSite: IrCall, args: List<LLVMValueRef>, resultSlot: LLVMValueRef?): LLVMValueRef {
|
||||||
require(args.size == 2) { "The call to ${callSite.symbol.owner.name.asString()} expects 2 value arguments." }
|
require(args.size == 2) { "The call to ${callSite.symbol.owner.name.asString()} expects 2 value arguments." }
|
||||||
val address = arrayGetElementAddress(callSite, args[0], args[1])
|
val address = arrayGetElementAddress(callSite, args[0], args[1])
|
||||||
return loadSlot(address, isVar = true, resultSlot, memoryOrder = LLVMAtomicOrdering.LLVMAtomicOrderingSequentiallyConsistent)
|
return loadSlot(callSite.llvmReturnType, address, isVar = true, resultSlot, memoryOrder = LLVMAtomicOrdering.LLVMAtomicOrderingSequentiallyConsistent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FunctionGenerationContext.transformArgsForAtomicArray(callSite: IrCall, args: List<LLVMValueRef>): List<LLVMValueRef> {
|
private fun FunctionGenerationContext.transformArgsForAtomicArray(callSite: IrCall, args: List<LLVMValueRef>): List<LLVMValueRef> {
|
||||||
|
|||||||
+5
-2
@@ -1785,7 +1785,10 @@ internal class CodeGeneratorVisitor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return functionGenerationContext.loadSlot(
|
return functionGenerationContext.loadSlot(
|
||||||
fieldAddress, !value.symbol.owner.isFinal, resultSlot,
|
value.type.toLLVMType(llvm),
|
||||||
|
fieldAddress,
|
||||||
|
!value.symbol.owner.isFinal,
|
||||||
|
resultSlot,
|
||||||
memoryOrder = order,
|
memoryOrder = order,
|
||||||
alignment = alignment
|
alignment = alignment
|
||||||
)
|
)
|
||||||
@@ -2938,7 +2941,7 @@ internal class CodeGeneratorVisitor(
|
|||||||
val bbNeedInit = basicBlock("need_init", null)
|
val bbNeedInit = basicBlock("need_init", null)
|
||||||
|
|
||||||
|
|
||||||
val value = LLVMBuildLoad(builder, initGuard, "")!!
|
val value = LLVMBuildLoad2(builder, llvm.int32Type, initGuard, "")!!
|
||||||
condBr(icmpEq(value, llvm.kImmInt32Zero), bbNeedInit, bbInited)
|
condBr(icmpEq(value, llvm.kImmInt32Zero), bbNeedInit, bbInited)
|
||||||
|
|
||||||
appendingTo(bbInited) {
|
appendingTo(bbInited) {
|
||||||
|
|||||||
+9
-7
@@ -23,8 +23,9 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
|
|||||||
fun address() : LLVMValueRef
|
fun address() : LLVMValueRef
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class SlotRecord(val address: LLVMValueRef, val refSlot: Boolean, val isVar: Boolean) : Record {
|
inner class SlotRecord(val address: LLVMValueRef, val type: LLVMTypeRef, val isVar: Boolean) : Record {
|
||||||
override fun load(resultSlot: LLVMValueRef?) : LLVMValueRef = functionGenerationContext.loadSlot(address, isVar, resultSlot)
|
val refSlot = functionGenerationContext.isObjectType(type)
|
||||||
|
override fun load(resultSlot: LLVMValueRef?) : LLVMValueRef = functionGenerationContext.loadSlot(type, address, isVar, resultSlot)
|
||||||
override fun store(value: LLVMValueRef) {
|
override fun store(value: LLVMValueRef) {
|
||||||
functionGenerationContext.storeAny(value, address, true)
|
functionGenerationContext.storeAny(value, address, true)
|
||||||
}
|
}
|
||||||
@@ -32,8 +33,9 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
|
|||||||
override fun toString() = (if (refSlot) "refslot" else "slot") + " for ${address}"
|
override fun toString() = (if (refSlot) "refslot" else "slot") + " for ${address}"
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ParameterRecord(val address: LLVMValueRef, val refSlot: Boolean) : Record {
|
inner class ParameterRecord(val address: LLVMValueRef, val type: LLVMTypeRef) : Record {
|
||||||
override fun load(resultSlot: LLVMValueRef?): LLVMValueRef = functionGenerationContext.loadSlot(address, false, resultSlot)
|
val refSlot = functionGenerationContext.isObjectType(type)
|
||||||
|
override fun load(resultSlot: LLVMValueRef?): LLVMValueRef = functionGenerationContext.loadSlot(type, address, false, resultSlot)
|
||||||
override fun store(value: LLVMValueRef) = functionGenerationContext.store(value, address)
|
override fun store(value: LLVMValueRef) = functionGenerationContext.store(value, address)
|
||||||
override fun address() : LLVMValueRef = this.address
|
override fun address() : LLVMValueRef = this.address
|
||||||
override fun toString() = (if (refSlot) "refslot" else "slot") + " for ${address}"
|
override fun toString() = (if (refSlot) "refslot" else "slot") + " for ${address}"
|
||||||
@@ -79,7 +81,7 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
|
|||||||
val slot = functionGenerationContext.alloca(type, valueDeclaration.name.asString(), variableLocation)
|
val slot = functionGenerationContext.alloca(type, valueDeclaration.name.asString(), variableLocation)
|
||||||
if (value != null)
|
if (value != null)
|
||||||
functionGenerationContext.storeAny(value, slot, true)
|
functionGenerationContext.storeAny(value, slot, true)
|
||||||
variables.add(SlotRecord(slot, functionGenerationContext.isObjectType(type), isVar))
|
variables.add(SlotRecord(slot, type, isVar))
|
||||||
contextVariablesToIndex[valueDeclaration] = index
|
contextVariablesToIndex[valueDeclaration] = index
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,7 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
|
|||||||
val slot = functionGenerationContext.alloca(
|
val slot = functionGenerationContext.alloca(
|
||||||
type, "p-${valueDeclaration.name.asString()}", variableLocation)
|
type, "p-${valueDeclaration.name.asString()}", variableLocation)
|
||||||
val isObject = functionGenerationContext.isObjectType(type)
|
val isObject = functionGenerationContext.isObjectType(type)
|
||||||
variables.add(ParameterRecord(slot, isObject))
|
variables.add(ParameterRecord(slot, type))
|
||||||
contextVariablesToIndex[valueDeclaration] = index
|
contextVariablesToIndex[valueDeclaration] = index
|
||||||
if (isObject)
|
if (isObject)
|
||||||
skipSlots++
|
skipSlots++
|
||||||
@@ -114,7 +116,7 @@ internal class VariableManager(val functionGenerationContext: FunctionGeneration
|
|||||||
val slot = functionGenerationContext.alloca(type, variableLocation = null)
|
val slot = functionGenerationContext.alloca(type, variableLocation = null)
|
||||||
if (value != null)
|
if (value != null)
|
||||||
functionGenerationContext.storeAny(value, slot, true)
|
functionGenerationContext.storeAny(value, slot, true)
|
||||||
variables.add(SlotRecord(slot, functionGenerationContext.isObjectType(type), true))
|
variables.add(SlotRecord(slot, type, true))
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ internal fun ObjCExportCodeGeneratorBase.generateBlockToKotlinFunctionConverter(
|
|||||||
val thisRef = param(0)
|
val thisRef = param(0)
|
||||||
val associatedObjectHolder = if (useSeparateHolder) {
|
val associatedObjectHolder = if (useSeparateHolder) {
|
||||||
val bodyPtr = bitcast(pointerType(bodyType), thisRef)
|
val bodyPtr = bitcast(pointerType(bodyType), thisRef)
|
||||||
loadSlot(structGep(bodyPtr, 1), isVar = false)
|
loadSlot(codegen.kObjHeaderPtr, structGep(bodyPtr, 1), isVar = false)
|
||||||
} else {
|
} else {
|
||||||
thisRef
|
thisRef
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ excludedFunctions.mingw = LLVMDumpType
|
|||||||
|
|
||||||
# Functions from LLVMIntPtrType to LLVMModuleCreateWithName are excluded because they work with the GlobalContext.
|
# Functions from LLVMIntPtrType to LLVMModuleCreateWithName are excluded because they work with the GlobalContext.
|
||||||
# This might not be safe if the compiler is called from a daemon process.
|
# This might not be safe if the compiler is called from a daemon process.
|
||||||
|
#
|
||||||
|
# Also exclude the functions that rely on typed pointers as we get rid of them from the code generator.
|
||||||
excludedFunctions = LLVMInitializeAllAsmParsers LLVMInitializeAllAsmPrinters LLVMInitializeAllDisassemblers \
|
excludedFunctions = LLVMInitializeAllAsmParsers LLVMInitializeAllAsmPrinters LLVMInitializeAllDisassemblers \
|
||||||
LLVMInitializeAllTargetInfos LLVMInitializeAllTargetMCs LLVMInitializeAllTargets LLVMInitializeNativeTarget \
|
LLVMInitializeAllTargetInfos LLVMInitializeAllTargetMCs LLVMInitializeAllTargets LLVMInitializeNativeTarget \
|
||||||
LLVMInitializeNativeAsmParser LLVMInitializeNativeAsmPrinter LLVMInitializeNativeDisassembler \
|
LLVMInitializeNativeAsmParser LLVMInitializeNativeAsmPrinter LLVMInitializeNativeDisassembler \
|
||||||
@@ -83,6 +85,7 @@ excludedFunctions = LLVMInitializeAllAsmParsers LLVMInitializeAllAsmPrinters LLV
|
|||||||
LLVMInt16Type LLVMInt32Type LLVMInt64Type LLVMInt128Type LLVMIntType LLVMHalfType LLVMFloatType LLVMDoubleType \
|
LLVMInt16Type LLVMInt32Type LLVMInt64Type LLVMInt128Type LLVMIntType LLVMHalfType LLVMFloatType LLVMDoubleType \
|
||||||
LLVMX86FP80Type LLVMFP128Type LLVMPPCFP128Type LLVMX86MMXType LLVMStructType LLVMVoidType LLVMLabelType \
|
LLVMX86FP80Type LLVMFP128Type LLVMPPCFP128Type LLVMX86MMXType LLVMStructType LLVMVoidType LLVMLabelType \
|
||||||
LLVMMDString LLVMMDNode LLVMConstString LLVMConstStruct LLVMAppendBasicBlock LLVMInsertBasicBlock LLVMCreateBuilder \
|
LLVMMDString LLVMMDNode LLVMConstString LLVMConstStruct LLVMAppendBasicBlock LLVMInsertBasicBlock LLVMCreateBuilder \
|
||||||
LLVMParseBitcode LLVMParseBitcode2 LLVMGetBitcodeModule LLVMGetBitcodeModule2 LLVMGetGlobalContext LLVMModuleCreateWithName
|
LLVMParseBitcode LLVMParseBitcode2 LLVMGetBitcodeModule LLVMGetBitcodeModule2 LLVMGetGlobalContext LLVMModuleCreateWithName \
|
||||||
|
LLVMBuildLoad
|
||||||
|
|
||||||
strictEnums = LLVMIntPredicate LLVMOpcode LLVMDLLStorageClass LLVMCallConv LLVMThreadLocalMode LLVMAtomicOrdering
|
strictEnums = LLVMIntPredicate LLVMOpcode LLVMDLLStorageClass LLVMCallConv LLVMThreadLocalMode LLVMAtomicOrdering
|
||||||
|
|||||||
Reference in New Issue
Block a user