+1
-1
@@ -119,7 +119,7 @@ internal interface ContextUtils : RuntimeAware {
|
||||
val ClassDescriptor.typeInfoPtr: ConstPointer
|
||||
get() {
|
||||
return if (isExternal(this)) {
|
||||
constPointer(externalGlobal(this.typeInfoSymbolName, runtime.typeInfoType))
|
||||
constPointer(importGlobal(this.typeInfoSymbolName, runtime.typeInfoType))
|
||||
} else {
|
||||
context.llvmDeclarations.forClass(this).typeInfo
|
||||
}
|
||||
|
||||
+2
-1
@@ -1287,7 +1287,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
assert (!descriptor.isUnit())
|
||||
return if (codegen.isExternal(descriptor)) {
|
||||
val llvmType = codegen.getLLVMType(descriptor.defaultType)
|
||||
codegen.externalGlobal(descriptor.objectInstanceFieldSymbolName, llvmType)
|
||||
codegen.importGlobal(descriptor.objectInstanceFieldSymbolName, llvmType,
|
||||
threadLocal = true)
|
||||
} else {
|
||||
context.llvmDeclarations.forSingleton(descriptor).instanceFieldRef
|
||||
}
|
||||
|
||||
+4
-6
@@ -296,11 +296,8 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
|
||||
} else {
|
||||
"kobjref:" + qualifyInternalName(descriptor)
|
||||
}
|
||||
val instanceFieldRef = LLVMAddGlobal(
|
||||
context.llvmModule,
|
||||
getLLVMType(descriptor.defaultType),
|
||||
symbolName
|
||||
)!!
|
||||
val instanceFieldRef = addGlobal(
|
||||
symbolName, getLLVMType(descriptor.defaultType), threadLocal = true)
|
||||
|
||||
return SingletonLlvmDeclarations(instanceFieldRef)
|
||||
}
|
||||
@@ -326,7 +323,8 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
|
||||
// Fields are module-private, so we use internal name:
|
||||
val name = "kvar:" + qualifyInternalName(descriptor)
|
||||
|
||||
val storage = LLVMAddGlobal(context.llvmModule, getLLVMType(descriptor.type), name)!!
|
||||
val storage = addGlobal(
|
||||
name, getLLVMType(descriptor.type), threadLocal = true)
|
||||
|
||||
this.staticFields[descriptor] = StaticFieldLlvmDeclarations(storage)
|
||||
}
|
||||
|
||||
+17
-2
@@ -182,14 +182,29 @@ internal fun getGlobalType(ptrToGlobal: LLVMValueRef): LLVMTypeRef {
|
||||
return LLVMGetElementType(ptrToGlobal.type)!!
|
||||
}
|
||||
|
||||
internal fun ContextUtils.externalGlobal(name: String, type: LLVMTypeRef): LLVMValueRef {
|
||||
internal fun ContextUtils.addGlobal(name: String, type: LLVMTypeRef,
|
||||
threadLocal: Boolean = false): LLVMValueRef {
|
||||
assert(LLVMGetNamedGlobal(context.llvmModule, name) == null)
|
||||
val result = LLVMAddGlobal(context.llvmModule, type, name)!!
|
||||
if (threadLocal)
|
||||
LLVMSetThreadLocalMode(result, LLVMThreadLocalMode.LLVMLocalExecTLSModel)
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun ContextUtils.importGlobal(name: String, type: LLVMTypeRef,
|
||||
threadLocal: Boolean = false): LLVMValueRef {
|
||||
val found = LLVMGetNamedGlobal(context.llvmModule, name)
|
||||
if (found != null) {
|
||||
assert (getGlobalType(found) == type)
|
||||
assert (LLVMGetInitializer(found) == null)
|
||||
if (threadLocal)
|
||||
assert(LLVMGetThreadLocalMode(found) == LLVMThreadLocalMode.LLVMLocalExecTLSModel)
|
||||
return found
|
||||
} else {
|
||||
return LLVMAddGlobal(context.llvmModule, type, name)!!
|
||||
val result = LLVMAddGlobal(context.llvmModule, type, name)!!
|
||||
if (threadLocal)
|
||||
LLVMSetThreadLocalMode(result, LLVMThreadLocalMode.LLVMLocalExecTLSModel)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
if (annot != null) {
|
||||
val nameValue = annot.allValueArguments.values.single() as StringValue
|
||||
// TODO: use LLVMAddAlias?
|
||||
val global = LLVMAddGlobal(context.llvmModule, pointerType(runtime.typeInfoType), nameValue.value)
|
||||
val global = addGlobal(nameValue.value, pointerType(runtime.typeInfoType))
|
||||
LLVMSetInitializer(global, typeInfoGlobal)
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ internal class StaticData(override val context: Context): ContextUtils {
|
||||
throw IllegalArgumentException("Global '$name' already exists")
|
||||
}
|
||||
|
||||
// Globals created with this API are *not* thread local.
|
||||
val llvmGlobal = LLVMAddGlobal(module, type, name)!!
|
||||
|
||||
if (!isExported) {
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ internal val ContextUtils.theUnitInstanceRef: ConstPointer
|
||||
get() {
|
||||
val unitDescriptor = context.builtIns.unit
|
||||
return if (isExternal(unitDescriptor)) {
|
||||
constPointer(externalGlobal(theUnitInstanceName, context.llvm.runtime.objHeaderType))
|
||||
constPointer(importGlobal(theUnitInstanceName, context.llvm.runtime.objHeaderType))
|
||||
} else {
|
||||
context.llvmDeclarations.getUnitInstanceRef()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user