[K/N] Avoid string copying when setting up bridge debug info.

The name of the function was copied at least 4 times. This reduces
a 56 seconds codegen phase in a non-optimized build by 2 seconds.
This commit is contained in:
Mads Ager
2022-12-20 16:16:40 +01:00
committed by Space
parent ef1e4662f1
commit 6b01886334
3 changed files with 34 additions and 11 deletions
@@ -275,20 +275,17 @@ internal fun setupBridgeDebugInfo(generationState: NativeGenerationState, functi
val file = debugInfo.compilerGeneratedFile
// TODO: can we share the scope among all bridges?
val scope: DIScopeOpaqueRef = DICreateFunction(
val scope: DIScopeOpaqueRef = DICreateBridgeFunction(
builder = debugInfo.builder,
scope = file.reinterpret(),
name = function.name,
linkageName = function.name,
function = function,
file = file,
lineNo = 0,
type = debugInfo.subroutineType(generationState.runtime.targetData, emptyList()), // TODO: use proper type.
isLocal = 0,
isDefinition = 1,
scopeLine = 0
)!!.also {
DIFunctionAddSubprogram(function, it)
}.reinterpret()
)!!.reinterpret()
return LocationInfo(scope, 1, 0)
}
@@ -81,11 +81,11 @@ DIModuleRef DICreateModule(DIBuilderRef builder, DIScopeOpaqueRef scope,
return llvm::wrap(llvm::unwrap(builder)->createModule(llvm::unwrap(scope), name, configurationMacro, includePath, iSysRoot));
}
DISubprogramRef DICreateFunction(DIBuilderRef builderRef, DIScopeOpaqueRef scope,
const char* name, const char *linkageName,
DIFileRef file, unsigned lineNo,
DISubroutineTypeRef type, int isLocal,
int isDefinition, unsigned scopeLine) {
static DISubprogramRef DICreateFunctionShared(DIBuilderRef builderRef, DIScopeOpaqueRef scope,
llvm::StringRef name, llvm::StringRef linkageName,
DIFileRef file, unsigned lineNo,
DISubroutineTypeRef type, int isLocal,
int isDefinition, unsigned scopeLine) {
auto builder = llvm::unwrap(builderRef);
auto subprogram = builder->createFunction(llvm::unwrap(scope),
name,
@@ -102,6 +102,26 @@ DISubprogramRef DICreateFunction(DIBuilderRef builderRef, DIScopeOpaqueRef scope
return llvm::wrap(subprogram);
}
DISubprogramRef DICreateFunction(DIBuilderRef builderRef, DIScopeOpaqueRef scope,
const char* name, const char *linkageName,
DIFileRef file, unsigned lineNo,
DISubroutineTypeRef type, int isLocal,
int isDefinition, unsigned scopeLine) {
return DICreateFunctionShared(builderRef, scope, name, linkageName, file, lineNo, type, isLocal, isDefinition, scopeLine);
}
DISubprogramRef DICreateBridgeFunction(DIBuilderRef builderRef, DIScopeOpaqueRef scope,
LLVMValueRef function,
DIFileRef file, unsigned lineNo,
DISubroutineTypeRef type, int isLocal,
int isDefinition, unsigned scopeLine) {
auto fn = llvm::cast<llvm::Function>(llvm::unwrap(function));
auto name = fn->getName();
auto subprogram = DICreateFunctionShared(builderRef, scope, name, name, file, lineNo, type, isLocal, isDefinition, scopeLine);
fn->setSubprogram(llvm::unwrap(subprogram));
return subprogram;
}
DIScopeOpaqueRef DICreateLexicalBlockFile(DIBuilderRef builderRef, DIScopeOpaqueRef scopeRef, DIFileRef fileRef) {
return llvm::wrap(llvm::unwrap(builderRef)->createLexicalBlockFile(llvm::unwrap(scopeRef), llvm::unwrap(fileRef)));
}
@@ -93,6 +93,12 @@ DISubprogramRef DICreateFunction(DIBuilderRef builder, DIScopeOpaqueRef scope,
DISubroutineTypeRef type, int isLocal,
int isDefinition, unsigned scopeLine);
DISubprogramRef DICreateBridgeFunction(DIBuilderRef builder, DIScopeOpaqueRef scope,
LLVMValueRef function,
DIFileRef file, unsigned lineNo,
DISubroutineTypeRef type, int isLocal,
int isDefinition, unsigned scopeLine);
DISubroutineTypeRef DICreateSubroutineType(DIBuilderRef builder,
DITypeOpaqueRef* types,
unsigned typesCount);