From c074cf66352fc77e93881f3ace6c84bfc2586278 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Thu, 26 Jan 2023 14:30:44 +0200 Subject: [PATCH] [K/N] Update HACKING.md to reflect -Xsave-llvm-ir-directory --- kotlin-native/HACKING.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/kotlin-native/HACKING.md b/kotlin-native/HACKING.md index b99a9528920..029dc5c724b 100644 --- a/kotlin-native/HACKING.md +++ b/kotlin-native/HACKING.md @@ -371,23 +371,27 @@ Please note: 1. Kotlin Native passes bitcode files to Clang instead of C or C++, so many flags won't work. 2. `-cc1 -emit-obj` should be passed because Kotlin/Native calls linker by itself. 3. Use `clang -cc1 -help` to see a list of available options. - -Another useful compiler option is `-Xtemporary-files-dir=` which allows - specifying a directory for intermediate compiler artifacts like bitcode and object files. -For example, it allows to store LLVM IR after a particular compiler phase. - -```shell script -konanc main.kt -Xsave-llvm-ir-after=BitcodeOptimization -Xtemporary-files-dir= -``` - -`/out.BitcodeOptimization.ll` will contain LLVM IR after LLVM optimization pipeline. #### Example: replace predefined LLVM pipeline with Clang options. ```shell script CLANG_FLAGS="clangFlags.macos_x64=-cc1 -emit-obj;clangNooptFlags.macos_x64=-O2" -konanc main.kt -Xdisable-phases=BitcodeOptimization -Xoverride-konan-properties="$CLANG_FLAGS" +kotlinc-native main.kt -Xdisable-phases=BitcodeOptimization -Xoverride-konan-properties="$CLANG_FLAGS" ``` +### Dumping LLVM IR + +It is possible to dump LLVM IR after a particular compiler phase. + +```shell script +kotlinc-native main.kt -Xsave-llvm-ir-after= -Xsave-llvm-ir-directory= +``` + +`/out..ll` will contain LLVM IR after LLVM optimization pipeline. + +Passing `Codegen` phase allows to get LLVM IR right after translation from Kotlin Backend IR, and +`BitcodeOptimization` phase allows to see the result of LLVM optimization pipeline. The list of phases that support LLVM IR dumping is constantly changing, so check out compiler sources +if you want to get the full list of such phases. + ## Running Clang the same way Kotlin/Native compiler does Kotlin/Native compiler (including `cinterop` tool) has machinery that manages LLVM, Clang and native SDKs for supported targets