C/C++ and Fortran

 View Only

Use opt-viewer along with new Open XL compilers on AIX

By Zheng Chen posted Mon November 01, 2021 10:10 PM

  

With IBM Power10 GAed in September of 2021, IBM XL C/C++ and Fortran compiler completed the adoption of LLVM infrastructure and now are rebranded to IBM Open XL C/C++ and Fortran.

There are many benefits of adopting LLVM. One of them is with those LLVM-based utilities. Although not all of them are available now on AIX, some of them are already enabled/ported, such as opt-viewer, bugpoint, llvm-dwarfdump, etc. We believe more will be made available on Power platforms in the future. The functionalities that were not provided by AIX and XL compilers previously, can now be enjoyed by our enterprise clients.

In this blog, we will introduce how to use opt-viewer along with new Open XL compilers.

Compiler optimizations are key to the performance of programs. Visual feedback on compiler interactions with the program can facilitate performance analysis and tuning. It can have a huge impact on the program's performance.

Open XL compilers can emit LLVM remark diagnostics from optimization passes in the YAML format, to describe whether an optimization has been performed or missed for a particular reason, which can give more insight to users about what optimizations the compiler did during the compilation.

opt-viewer is a tool to transform the serialized remarks in YAML format to visual HTML format. Users will then be able to easily read and analyze these results of compiler optimizations and know more about how their programs were processed by the compiler.

There are two steps to use opt-viewer:

Step 1: generate serialized remarks when compiling the programs:

IBM Open XL C/C++:

ibm-clang test.c -O2 -c -foptimization-record-file=test.opt.yaml

 

Notes:

1: -foptimization-record-file is used to tell the compiler to generate YAML format serialized remarks named by test.opt.yaml. This option implies -fsave-optimization-record=yaml. More information can be found here: https://clang.llvm.org/docs/UsersManual.html#cmdoption-f-no-save-optimization-record

 

IBM Open XL Fortran:

xlf test.f -O2 -c -g1 -Xopt --pass-remarks-output=test.opt.yaml -Xllc --pass-remarks-output=test.llc.yaml

 

Notes:

1: Open XL Fortran supports passing --pass-remarks-output to ibm-opt(-Xopt), ibm-llc(-Xllc), or LTO(-Xlto) to tell these components generate serialized remarks.

2: -g1 must be used to generate debug line number to use opt-viewer tool.
More information can be found here: https://www.ibm.com/docs/en/openxl-fortran-aix/17.1.0?topic=fortran-optimization-reports

 

After this step, the serialized remarks emitted by the compiler are stored to the file test.opt.yaml. (And test.llc.yaml for IBM Open XL Fortran)

Step 2: transform the YAML format serialized remarks to visual HTML format:

IBM Open XL C/C++:

opt-viewer.py --demangler llvm-cxxfilt test.opt.yaml

 

llvm-cxxfilt is a demangler utility provided by LLVM.

 

IBM Open XL Fortran:

opt-viewer.py --demangler cat test.opt.yaml

 

Please note Fortran does not need the demangler, but the default demangler c++filt is not provided by AIX, so use cat to make sure the same string is emitted.

 

After this step, a directory html will be created. In the directory, there is a file index.html that contains visual information.


This visual HTML can clearly indicate:

1: Why some optimizations are not performed. In the above example, the function noinline is not inlined because it should never be inlined because of noinline attribute, the loop is not vectorized because of the call inside the loop.

2: Some analysis information about the program. For example, instruction number and stack size for each function.

 

Users can get opt-viewer from the LLVM repository: https://github.com/llvm/llvm-project/tree/main/llvm/tools/opt-viewer. More usage of opt-viewer can be found here: https://llvm.org/docs/Remarks.html#opt-viewer-py.

 

BTW: Open XL Fortran supports -qreport which also leverages LLVM remark diagnostics. This option can produce listing files that show how sections of code have been optimized. You can learn more here: https://www.ibm.com/docs/en/openxl-fortran-aix/17.1.0?topic=options-qreport

 

0 comments
50 views

Permalink