[K/N] Move basic blocks with lazy init to middle of function

CoreSymbolication heuristics assume that last instruction in function
corresponds to last function line. This is not always true anyway,
but with this hack this will happen more often.
This commit is contained in:
Pavel Kunyavskiy
2021-10-20 18:09:02 +03:00
committed by Space
parent 6d3158b275
commit 653fc85461
2 changed files with 16 additions and 0 deletions
@@ -520,6 +520,15 @@ internal abstract class FunctionGenerationContext(
return result
}
/**
* This function shouldn't be used normally.
* It is used to move block with strange debug info in the middle of function, to avoid last debug info being too strange,
* because it will break heuristics in CoreSymbolication
*/
fun moveBlockAfterEntry(block: LLVMBasicBlockRef) {
LLVMMoveBasicBlockAfter(block, this.entryBb)
}
fun alloca(type: LLVMTypeRef?, name: String = "", variableLocation: VariableDebugLocation? = null): LLVMValueRef {
if (isObjectType(type!!)) {
appendingTo(localsInitBb) {
@@ -2378,6 +2378,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
val bbInit = basicBlock("label_init", null)
val bbExit = basicBlock("label_continue", null)
moveBlockAfterEntry(bbExit)
moveBlockAfterEntry(bbInit)
// TODO: Is it ok to use non-volatile read here since once value is FILE_INITIALIZED, it is no longer change?
val state = load(statePtr)
LLVMSetVolatile(state, 1)
@@ -2399,6 +2401,9 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
val bbInit = basicBlock("label_init", null)
val bbCheckLocalState = basicBlock("label_check_local", null)
val bbExit = basicBlock("label_continue", null)
moveBlockAfterEntry(bbExit)
moveBlockAfterEntry(bbCheckLocalState)
moveBlockAfterEntry(bbInit)
val globalState = load(globalStatePtr)
LLVMSetVolatile(globalState, 1)
// Make sure we're not in the middle of global initializer invocation -
@@ -2421,6 +2426,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
val bbInit = basicBlock("label_init", null)
val bbExit = basicBlock("label_continue", null)
moveBlockAfterEntry(bbExit)
moveBlockAfterEntry(bbInit)
condBr(icmpEq(load(statePtr), Int32(FILE_INITIALIZED).llvm), bbExit, bbInit)
positionAtEnd(bbInit)
call(context.llvm.callInitThreadLocal, listOf(kNullInt32Ptr, statePtr, initializerPtr),