Add LLVM profiling reports to --time and --verbose object_files flags (#1566)

Added llvm reports to `--time` and `--verbose object_files`.
This commit is contained in:
Sergey Bogolepov
2018-05-08 17:53:05 +07:00
committed by GitHub
parent d525fea65c
commit fff09927fd
@@ -60,6 +60,7 @@ internal class LinkStage(val context: Context) {
val tool = "${platform.absoluteLlvmHome}/bin/llvm-lto" val tool = "${platform.absoluteLlvmHome}/bin/llvm-lto"
val command = mutableListOf(tool, "-o", combined) val command = mutableListOf(tool, "-o", combined)
command.addNonEmpty(platform.llvmLtoFlags) command.addNonEmpty(platform.llvmLtoFlags)
command.addNonEmpty(llvmProfilingFlags())
when { when {
optimize -> command.addNonEmpty(platform.llvmLtoOptFlags) optimize -> command.addNonEmpty(platform.llvmLtoOptFlags)
debug -> command.addNonEmpty(platform.llvmDebugOptFlags) debug -> command.addNonEmpty(platform.llvmDebugOptFlags)
@@ -85,7 +86,6 @@ internal class LinkStage(val context: Context) {
runTool(absoluteToolName, *arg) runTool(absoluteToolName, *arg)
} }
// TODO: pass different options llvm toolchain
private fun bitcodeToWasm(bitcodeFiles: List<BitcodeFile>): String { private fun bitcodeToWasm(bitcodeFiles: List<BitcodeFile>): String {
val configurables = platform.configurables as WasmConfigurables val configurables = platform.configurables as WasmConfigurables
@@ -96,7 +96,7 @@ internal class LinkStage(val context: Context) {
optimize -> configurables.optOptFlags optimize -> configurables.optOptFlags
debug -> configurables.optDebugFlags debug -> configurables.optDebugFlags
else -> configurables.optNooptFlags else -> configurables.optNooptFlags
}).toTypedArray() } + llvmProfilingFlags()).toTypedArray()
val optimizedBc = temporary("optimized", ".bc") val optimizedBc = temporary("optimized", ".bc")
hostLlvmTool("opt", combinedBc, "-o", optimizedBc, *optFlags) hostLlvmTool("opt", combinedBc, "-o", optimizedBc, *optFlags)
@@ -104,7 +104,7 @@ internal class LinkStage(val context: Context) {
optimize -> configurables.llcOptFlags optimize -> configurables.llcOptFlags
debug -> configurables.llcDebugFlags debug -> configurables.llcDebugFlags
else -> configurables.llcNooptFlags else -> configurables.llcNooptFlags
}).toTypedArray() } + llvmProfilingFlags()).toTypedArray()
val combinedS = temporary("combined", ".s") val combinedS = temporary("combined", ".s")
targetTool("llc", optimizedBc, "-o", combinedS, *llcFlags) targetTool("llc", optimizedBc, "-o", combinedS, *llcFlags)
@@ -124,14 +124,29 @@ internal class LinkStage(val context: Context) {
hostLlvmTool("llvm-link", "-o", combinedBc, *bitcodeFiles.toTypedArray()) hostLlvmTool("llvm-link", "-o", combinedBc, *bitcodeFiles.toTypedArray())
val optimizedBc = temporary("optimized", ".bc") val optimizedBc = temporary("optimized", ".bc")
hostLlvmTool("opt", combinedBc, "-o=$optimizedBc", "-O3", "-internalize", "-globaldce") val optFlags = llvmProfilingFlags() + listOf("-O3", "-internalize", "-globaldce")
hostLlvmTool("opt", combinedBc, "-o=$optimizedBc", *optFlags.toTypedArray())
val combinedO = temporary("combined", ".o") val combinedO = temporary("combined", ".o")
hostLlvmTool("llc", optimizedBc, "-filetype=obj", "-o", combinedO, "-function-sections", "-data-sections") val llcFlags = llvmProfilingFlags() + listOf("-function-sections", "-data-sections")
hostLlvmTool("llc", optimizedBc, "-filetype=obj", "-o", combinedO, *llcFlags.toTypedArray())
return combinedO return combinedO
} }
// llvm-lto, opt and llc share same profiling flags, so we can
// reuse this function.
private fun llvmProfilingFlags(): List<String> {
val flags = mutableListOf<String>()
if (context.shouldProfilePhases()) {
flags += "-time-passes"
}
if (context.phase?.verbose == true) {
flags += "-debug-pass=Structure"
}
return flags
}
private fun asLinkerArgs(args: List<String>): List<String> { private fun asLinkerArgs(args: List<String>): List<String> {
if (linker.useCompilerDriverAsLinker) { if (linker.useCompilerDriverAsLinker) {
return args return args
@@ -203,13 +218,13 @@ internal class LinkStage(val context: Context) {
fun linkStage() { fun linkStage() {
val bitcodeFiles = listOf(emitted) + val bitcodeFiles = listOf(emitted) +
libraries.map { it -> it.bitcodePaths }.flatten() libraries.map { it.bitcodePaths }.flatten()
val includedBinaries = val includedBinaries =
libraries.map { it -> it.includedPaths }.flatten() libraries.map { it.includedPaths }.flatten()
val libraryProvidedLinkerFlags = val libraryProvidedLinkerFlags =
libraries.map { it -> it.linkerOpts }.flatten() libraries.map { it.linkerOpts }.flatten()
val objectFiles: MutableList<String> = mutableListOf() val objectFiles: MutableList<String> = mutableListOf()