I want to compile a module, using WMO but output each swift file as LLVM IR in a separate file. I will then compile each of these to binary using a separate process.
I can't figure out what flags to use to do this.
I'm attempting to do it like this...
swiftc -emit-ir -O -parse-as-library ... -whole-module-optimization -num-threads 4 -output-file-map outputMap.json -module-name XXX A.swift B.swift C.swift...
And my output file map looks like this...
{
"A.swift":{ "object":"A.ll" },
"B.swift":{ "object":"B.ll" },
"C.swift":{ "object":"C.ll" },
...
}
I was expecting the optimisation to be done together, then each file lowered to IR and emitted producing A.ll
, B.ll
, C.ll
in the directory.
This is not what is happening. Instead the whole LLVM IR is being dumped to stdout. I can't use a -o
flag or it will just dump the whole LLVM IR to that file.
My understanding of WMO is it optimises the whole module using SIL transforms, but then lowers to separate LLVM IR for each compilation unit separately, so they can undergo target lowering in LLVM separately (usually multi threaded). So I don't understand why this isn't working.
Is there some magic flag I can pass to get the result I want? I need WMO and also separate LLVM IR text files for the final phase of compilation.
Thanks for any help or advice you can give.
Carl