[K/N] Improve consistency of using setConst vs override RuntimeGlobals
This commit is contained in:
+13
-5
@@ -138,11 +138,13 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
?: SourceInfoType.CORESYMBOLICATION.takeIf { debug && target.supportsCoreSymbolication() }
|
?: SourceInfoType.CORESYMBOLICATION.takeIf { debug && target.supportsCoreSymbolication() }
|
||||||
?: SourceInfoType.NOOP
|
?: SourceInfoType.NOOP
|
||||||
|
|
||||||
|
val defaultGCSchedulerType get() = when {
|
||||||
|
!target.supportsThreads() -> GCSchedulerType.ON_SAFE_POINTS
|
||||||
|
else -> GCSchedulerType.WITH_TIMER
|
||||||
|
}
|
||||||
|
|
||||||
val gcSchedulerType: GCSchedulerType by lazy {
|
val gcSchedulerType: GCSchedulerType by lazy {
|
||||||
configuration.get(BinaryOptions.gcSchedulerType) ?: when {
|
configuration.get(BinaryOptions.gcSchedulerType) ?: defaultGCSchedulerType
|
||||||
!target.supportsThreads() -> GCSchedulerType.ON_SAFE_POINTS
|
|
||||||
else -> GCSchedulerType.WITH_TIMER
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val needVerifyIr: Boolean
|
val needVerifyIr: Boolean
|
||||||
@@ -338,11 +340,17 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
val ignoreCacheReason = when {
|
val ignoreCacheReason = when {
|
||||||
optimizationsEnabled -> "for optimized compilation"
|
optimizationsEnabled -> "for optimized compilation"
|
||||||
memoryModel != defaultMemoryModel -> "with ${memoryModel.name.lowercase()} memory model"
|
memoryModel != defaultMemoryModel -> "with ${memoryModel.name.lowercase()} memory model"
|
||||||
propertyLazyInitialization != defaultPropertyLazyInitialization -> "with${if (propertyLazyInitialization) "" else "out"} lazy top levels initialization"
|
propertyLazyInitialization != defaultPropertyLazyInitialization -> {
|
||||||
|
"with${if (propertyLazyInitialization) "" else "out"} lazy top levels initialization"
|
||||||
|
}
|
||||||
useDebugInfoInNativeLibs -> "with native libs debug info"
|
useDebugInfoInNativeLibs -> "with native libs debug info"
|
||||||
allocationMode != defaultAllocationMode -> "with ${allocationMode.name.lowercase()} allocator"
|
allocationMode != defaultAllocationMode -> "with ${allocationMode.name.lowercase()} allocator"
|
||||||
memoryModel == MemoryModel.EXPERIMENTAL && gc != defaultGC -> "with ${gc.name.lowercase()} garbage collector"
|
memoryModel == MemoryModel.EXPERIMENTAL && gc != defaultGC -> "with ${gc.name.lowercase()} garbage collector"
|
||||||
|
memoryModel == MemoryModel.EXPERIMENTAL && gcSchedulerType != defaultGCSchedulerType -> {
|
||||||
|
"with ${gcSchedulerType.name.lowercase()} garbage collector scheduler"
|
||||||
|
}
|
||||||
freezing != defaultFreezing -> "with ${freezing.name.replaceFirstChar { it.lowercase() }} freezing mode"
|
freezing != defaultFreezing -> "with ${freezing.name.replaceFirstChar { it.lowercase() }} freezing mode"
|
||||||
|
runtimeAssertsMode != RuntimeAssertsMode.IGNORE -> "with runtime assertions"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
CacheSupport(
|
CacheSupport(
|
||||||
|
|||||||
+4
-4
@@ -2733,12 +2733,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
if (!context.producedLlvmModuleContainsStdlib)
|
if (!context.producedLlvmModuleContainsStdlib)
|
||||||
return
|
return
|
||||||
|
|
||||||
setRuntimeConstGlobal("KonanNeedDebugInfo", Int32(if (context.shouldContainDebugInfo()) 1 else 0))
|
setRuntimeConstGlobal("Kotlin_needDebugInfo", Int32(if (context.shouldContainDebugInfo()) 1 else 0))
|
||||||
setRuntimeConstGlobal("Kotlin_runtimeAssertsMode", Int32(context.config.runtimeAssertsMode.value))
|
setRuntimeConstGlobal("Kotlin_runtimeAssertsMode", Int32(context.config.runtimeAssertsMode.value))
|
||||||
val runtimeLogs = context.config.runtimeLogs?.let {
|
val runtimeLogs = context.config.runtimeLogs?.let {
|
||||||
context.llvm.staticData.cStringLiteral(it)
|
context.llvm.staticData.cStringLiteral(it)
|
||||||
} ?: NullPointer(int8Type)
|
} ?: NullPointer(int8Type)
|
||||||
setRuntimeConstGlobal("Kotlin_runtimeLogs", runtimeLogs)
|
setRuntimeConstGlobal("Kotlin_runtimeLogs", runtimeLogs)
|
||||||
|
setRuntimeConstGlobal("Kotlin_freezingEnabled", Int32(if (context.config.freezing.enableFreezeAtRuntime) 1 else 0))
|
||||||
|
setRuntimeConstGlobal("Kotlin_freezingChecksEnabled", Int32(if (context.config.freezing.enableFreezeChecks) 1 else 0))
|
||||||
|
setRuntimeConstGlobal("Kotlin_gcSchedulerType", Int32(context.config.gcSchedulerType.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Globals set this way cannot be const, but are overridable when producing final executable.
|
// Globals set this way cannot be const, but are overridable when producing final executable.
|
||||||
@@ -2774,10 +2777,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
|
|
||||||
overrideRuntimeGlobal("Kotlin_destroyRuntimeMode", Int32(context.config.destroyRuntimeMode.value))
|
overrideRuntimeGlobal("Kotlin_destroyRuntimeMode", Int32(context.config.destroyRuntimeMode.value))
|
||||||
overrideRuntimeGlobal("Kotlin_workerExceptionHandling", Int32(context.config.workerExceptionHandling.value))
|
overrideRuntimeGlobal("Kotlin_workerExceptionHandling", Int32(context.config.workerExceptionHandling.value))
|
||||||
overrideRuntimeGlobal("Kotlin_freezingEnabled", Int32(if (context.config.freezing.enableFreezeAtRuntime) 1 else 0))
|
|
||||||
overrideRuntimeGlobal("Kotlin_freezingChecksEnabled", Int32(if (context.config.freezing.enableFreezeChecks) 1 else 0))
|
|
||||||
overrideRuntimeGlobal("Kotlin_suspendFunctionsFromAnyThreadFromObjC", Int32(if (context.config.suspendFunctionsFromAnyThreadFromObjC) 1 else 0))
|
overrideRuntimeGlobal("Kotlin_suspendFunctionsFromAnyThreadFromObjC", Int32(if (context.config.suspendFunctionsFromAnyThreadFromObjC) 1 else 0))
|
||||||
overrideRuntimeGlobal("Kotlin_gcSchedulerType", Int32(context.config.gcSchedulerType.value))
|
|
||||||
val getSourceInfoFunctionName = when (context.config.sourceInfoType) {
|
val getSourceInfoFunctionName = when (context.config.sourceInfoType) {
|
||||||
SourceInfoType.NOOP -> null
|
SourceInfoType.NOOP -> null
|
||||||
SourceInfoType.LIBBACKTRACE -> "Kotlin_getSourceInfo_libbacktrace"
|
SourceInfoType.LIBBACKTRACE -> "Kotlin_getSourceInfo_libbacktrace"
|
||||||
|
|||||||
@@ -10,14 +10,18 @@
|
|||||||
|
|
||||||
using namespace kotlin;
|
using namespace kotlin;
|
||||||
|
|
||||||
// These are defined by overrideRuntimeGlobals in IrToBitcode.kt
|
using Kotlin_getSourceInfo_FunctionType = int(*)(void * /*addr*/, SourceInfo* /*result*/, int /*result_size*/);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There are two ways, how compiler can define variables for runtime usage. This one, and the other one with details in header file.
|
||||||
|
*
|
||||||
|
* This is one is variables defined by overrideRuntimeGlobals in IrToBitcode.kt. They are *not* eligible for runtime optimizations,
|
||||||
|
* but can be changed after compiling caches. So use this way for variables, which will be rarely accessed.
|
||||||
|
*/
|
||||||
RUNTIME_WEAK int32_t Kotlin_destroyRuntimeMode = 1;
|
RUNTIME_WEAK int32_t Kotlin_destroyRuntimeMode = 1;
|
||||||
RUNTIME_WEAK int32_t Kotlin_gcSchedulerType = 2;
|
|
||||||
RUNTIME_WEAK int32_t Kotlin_workerExceptionHandling = 0;
|
RUNTIME_WEAK int32_t Kotlin_workerExceptionHandling = 0;
|
||||||
RUNTIME_WEAK int32_t Kotlin_freezingEnabled = 1;
|
|
||||||
RUNTIME_WEAK int32_t Kotlin_freezingChecksEnabled = 1;
|
|
||||||
RUNTIME_WEAK int32_t Kotlin_suspendFunctionsFromAnyThreadFromObjC = 0;
|
RUNTIME_WEAK int32_t Kotlin_suspendFunctionsFromAnyThreadFromObjC = 0;
|
||||||
RUNTIME_WEAK const Kotlin_getSourceInfo_FunctionType Kotlin_getSourceInfo_Function = nullptr;
|
RUNTIME_WEAK Kotlin_getSourceInfo_FunctionType Kotlin_getSourceInfo_Function = nullptr;
|
||||||
#ifdef KONAN_ANDROID
|
#ifdef KONAN_ANDROID
|
||||||
RUNTIME_WEAK int32_t Kotlin_printToAndroidLogcat = 1;
|
RUNTIME_WEAK int32_t Kotlin_printToAndroidLogcat = 1;
|
||||||
#endif
|
#endif
|
||||||
@@ -30,24 +34,22 @@ ALWAYS_INLINE compiler::WorkerExceptionHandling compiler::workerExceptionHandlin
|
|||||||
return static_cast<compiler::WorkerExceptionHandling>(Kotlin_workerExceptionHandling);
|
return static_cast<compiler::WorkerExceptionHandling>(Kotlin_workerExceptionHandling);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE bool compiler::freezingEnabled() noexcept {
|
|
||||||
return Kotlin_freezingEnabled != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALWAYS_INLINE bool compiler::freezingChecksEnabled() noexcept {
|
|
||||||
return Kotlin_freezingChecksEnabled != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALWAYS_INLINE bool compiler::suspendFunctionsFromAnyThreadFromObjCEnabled() noexcept {
|
ALWAYS_INLINE bool compiler::suspendFunctionsFromAnyThreadFromObjCEnabled() noexcept {
|
||||||
return Kotlin_suspendFunctionsFromAnyThreadFromObjC != 0;
|
return Kotlin_suspendFunctionsFromAnyThreadFromObjC != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE compiler::GCSchedulerType compiler::getGCSchedulerType() noexcept {
|
|
||||||
return static_cast<compiler::GCSchedulerType>(Kotlin_gcSchedulerType);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef KONAN_ANDROID
|
#ifdef KONAN_ANDROID
|
||||||
ALWAYS_INLINE bool compiler::printToAndroidLogcat() noexcept {
|
ALWAYS_INLINE bool compiler::printToAndroidLogcat() noexcept {
|
||||||
return Kotlin_printToAndroidLogcat != 0;
|
return Kotlin_printToAndroidLogcat != 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ALWAYS_INLINE int compiler::getSourceInfo(void* addr, SourceInfo *result, int result_size) noexcept {
|
||||||
|
if (Kotlin_getSourceInfo_Function == nullptr) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return Kotlin_getSourceInfo_Function(addr, result, result_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,13 +24,23 @@ using string_view = std::experimental::string_view;
|
|||||||
|
|
||||||
// Prefer to use getter functions below. These constants are exposed to simplify the job of the inliner.
|
// Prefer to use getter functions below. These constants are exposed to simplify the job of the inliner.
|
||||||
|
|
||||||
// These are defined by setRuntimeConstGlobals in IrToBitcode.kt
|
/**
|
||||||
extern "C" const int32_t KonanNeedDebugInfo;
|
* There are two ways, how compiler can define variables for runtime usage. This one, and the other one with details in source file.
|
||||||
|
*
|
||||||
|
* This is one is variables defined by setRuntimeConstGlobals in IrToBitcode.kt. They are eligible for runtime optimizations,
|
||||||
|
* and fixed at the point of compiling caches. So use this way for variables, which are heavily used on performance-critical passes or
|
||||||
|
* will significantly increase code size, if not eliminated.
|
||||||
|
*
|
||||||
|
* Don't forget to adjust cache disabling rules and add value to CompilerGenerated.cpp for tests, when adding a new variable.
|
||||||
|
*/
|
||||||
|
extern "C" const int32_t Kotlin_needDebugInfo;
|
||||||
extern "C" const int32_t Kotlin_runtimeAssertsMode;
|
extern "C" const int32_t Kotlin_runtimeAssertsMode;
|
||||||
extern "C" const char* const Kotlin_runtimeLogs;
|
extern "C" const char* const Kotlin_runtimeLogs;
|
||||||
|
extern "C" const int32_t Kotlin_gcSchedulerType;
|
||||||
|
extern "C" const int32_t Kotlin_freezingEnabled;
|
||||||
|
extern "C" const int32_t Kotlin_freezingChecksEnabled;
|
||||||
|
|
||||||
class SourceInfo;
|
class SourceInfo;
|
||||||
using Kotlin_getSourceInfo_FunctionType = int(*)(void * /*addr*/, SourceInfo* /*result*/, int /*result_size*/);
|
|
||||||
extern "C" const Kotlin_getSourceInfo_FunctionType Kotlin_getSourceInfo_Function;
|
|
||||||
|
|
||||||
namespace kotlin {
|
namespace kotlin {
|
||||||
namespace compiler {
|
namespace compiler {
|
||||||
@@ -62,36 +72,36 @@ enum class GCSchedulerType {
|
|||||||
kAggressive = 3,
|
kAggressive = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
DestroyRuntimeMode destroyRuntimeMode() noexcept;
|
|
||||||
|
|
||||||
ALWAYS_INLINE inline bool shouldContainDebugInfo() noexcept {
|
ALWAYS_INLINE inline bool shouldContainDebugInfo() noexcept {
|
||||||
return KonanNeedDebugInfo != 0;
|
return Kotlin_needDebugInfo != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE inline RuntimeAssertsMode runtimeAssertsMode() noexcept {
|
ALWAYS_INLINE inline RuntimeAssertsMode runtimeAssertsMode() noexcept {
|
||||||
return static_cast<RuntimeAssertsMode>(Kotlin_runtimeAssertsMode);
|
return static_cast<RuntimeAssertsMode>(Kotlin_runtimeAssertsMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkerExceptionHandling workerExceptionHandling() noexcept;
|
|
||||||
|
|
||||||
ALWAYS_INLINE inline std::string_view runtimeLogs() noexcept {
|
ALWAYS_INLINE inline std::string_view runtimeLogs() noexcept {
|
||||||
return Kotlin_runtimeLogs == nullptr ? std::string_view() : std::string_view(Kotlin_runtimeLogs);
|
return Kotlin_runtimeLogs == nullptr ? std::string_view() : std::string_view(Kotlin_runtimeLogs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool freezingEnabled() noexcept;
|
ALWAYS_INLINE inline bool freezingEnabled() noexcept {
|
||||||
bool freezingChecksEnabled() noexcept;
|
return Kotlin_freezingEnabled != 0;
|
||||||
bool suspendFunctionsFromAnyThreadFromObjCEnabled() noexcept;
|
|
||||||
|
|
||||||
|
|
||||||
ALWAYS_INLINE inline int getSourceInfo(void* addr, SourceInfo *result, int result_size) {
|
|
||||||
if (Kotlin_getSourceInfo_Function == nullptr) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return Kotlin_getSourceInfo_Function(addr, result, result_size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compiler::GCSchedulerType getGCSchedulerType() noexcept;
|
ALWAYS_INLINE inline bool freezingChecksEnabled() noexcept {
|
||||||
|
return Kotlin_freezingChecksEnabled != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE inline GCSchedulerType getGCSchedulerType() noexcept {
|
||||||
|
return static_cast<compiler::GCSchedulerType>(Kotlin_gcSchedulerType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WorkerExceptionHandling workerExceptionHandling() noexcept;
|
||||||
|
DestroyRuntimeMode destroyRuntimeMode() noexcept;
|
||||||
|
bool suspendFunctionsFromAnyThreadFromObjCEnabled() noexcept;
|
||||||
|
int getSourceInfo(void* addr, SourceInfo *result, int result_size) noexcept;
|
||||||
|
|
||||||
#ifdef KONAN_ANDROID
|
#ifdef KONAN_ANDROID
|
||||||
bool printToAndroidLogcat() noexcept;
|
bool printToAndroidLogcat() noexcept;
|
||||||
|
|||||||
@@ -63,10 +63,12 @@ struct KBox {
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
extern const int32_t KonanNeedDebugInfo = 1;
|
extern const int32_t Kotlin_needDebugInfo = 1;
|
||||||
extern const int32_t Kotlin_runtimeAssertsMode = static_cast<int32_t>(kotlin::compiler::RuntimeAssertsMode::kPanic);
|
extern const int32_t Kotlin_runtimeAssertsMode = static_cast<int32_t>(kotlin::compiler::RuntimeAssertsMode::kPanic);
|
||||||
extern const char* const Kotlin_runtimeLogs = nullptr;
|
extern const char* const Kotlin_runtimeLogs = nullptr;
|
||||||
int32_t Kotlin_gcSchedulerType = 0; // kDisabled
|
extern const int32_t Kotlin_gcSchedulerType = static_cast<int32_t>(kotlin::compiler::GCSchedulerType::kDisabled);
|
||||||
|
extern const int32_t Kotlin_freezingChecksEnabled = 1;
|
||||||
|
extern const int32_t Kotlin_freezingEnabled = 1;
|
||||||
|
|
||||||
extern const TypeInfo* theAnyTypeInfo = theAnyTypeInfoHolder.typeInfo();
|
extern const TypeInfo* theAnyTypeInfo = theAnyTypeInfoHolder.typeInfo();
|
||||||
extern const TypeInfo* theArrayTypeInfo = theArrayTypeInfoHolder.typeInfo();
|
extern const TypeInfo* theArrayTypeInfo = theArrayTypeInfoHolder.typeInfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user