1
votes

Hot cold splitting is an effective way for code optimization in LLVM. This built-in LLVM pass is located at :

/llvm/lib/Transforms/IPO/HotColdSplitting.cpp

Actually, I want to use this pass to optimize my code but I didn't find any documentation on how to use this built-in pass to optimize my code .

I already know that I should use LLVM opt command to load the pass but I didn't find the proper way to apply this optimization pass on my program .

I have two questions so far :

1) How to use opt properly to load this pass to optimize my code 2) Can I use this pass directly on clang to optimize C/C++ code as switches like -fsanitize=address which applies to the underlying compiling program ?

Thanks.

2

2 Answers

2
votes

You can pass the -mllvm -hot-cold-split=true flag to clang, which will enable hot/cold splitting pass in the optimizer when compiling your file.

Yes, in principle you can directly use this pass (as of the time of answering the question); hot/cold splitting in LLVM, in its current form, only optimizes for code size. Alternatively you might want to try first collecting profiling data via PGO, and then feeding the profiling data into clang for it to take advantage of profile information during the build (which might help hot/cold splitting in terms of performance).

0
votes

Hot cold splitting can be used to optimize an app for startup performance, as well as for runtime performance in some cases. To enable hot cold splitting optimization you can pass the flag to llvm using -mllvm -hot-cold-split.

Hot cold splitting gives best performance improvement in the presence of profile data. Although it does optimize applications without profile data using inbuilt static analysis. For example: catch block, non returning functions are already known to be cold. Hot cold splitting uses these information.

Currently there is no direct flag from the clang frontend to enable this so you'll have to use -mllvm -hot-cold-split. For more details on hot cold splitting the youtube video at the llvm-dev is quite informative: https://www.youtube.com/watch?v=Q8rqGg6vHAE