Is there a way to show where LLVM is auto vectorising?

為{幸葍}努か 提交于 2019-12-03 13:58:18

The standard llvm toolchain provided by Xcode doesn't seem to support getting debug info from the optimizer. However, if you roll your own llvm and use that, you should be able to pass flags as mishr suggested above. Here's the workflow I used:

1. Using homebrew, install llvm

brew tap homebrew/versions
brew install llvm33 --with-clang --with-asan

This should install the full and relatively current llvm toolchain. It's linked into /usr/local/bin/*-3.3 (i.e. clang++-3.3). The actual on-disk location is available via brew info llvm33 - probably /usr/local/Cellar/llvm33/3.3/bin.

2. Build the single file you're optimizing, with homebrew llvm and flags

If you've built in Xcode, you can easily copy-paste the build parameters, and use your clang++-3.3 instead of Xcode’s own clang.

Appending -mllvm -debug-only=loop-vectorize will get you the auto-vectorization report. Note: this will likely NOT work with any remotely complex build, e.g. if you've got PCH's, but is a simple way to tweak a single cpp file to make sure it's vectorizing correctly.

3. Create a compiler plugin from the new llvm

I was able to build my entire project with homebrew llvm by:

  1. Grabbing this Xcode compiler plugin: http://trac.seqan.de/browser/trunk/util/xcode/Clang%20LLVM%20MacPorts.xcplugin.zip?order=name
  2. Modifying the clang-related paths to point to my homebrew llvm and clang bin names (by appending '-3.3')
  3. Placing it in /Library/Application Support/Developer/5.0/Xcode/Plug-ins/

Relaunching Xcode should show this plugin in the list of available compilers. At this point, the -mllvm -debug-only=loop-vectorize flag will show the auto-vectorization report.

I have no idea why this isn't exposed in the Apple builds.

UPDATE: This is exposed in current (8.x) versions of Xcode. The only thing required is to enable one or more of the loop-vectorize flags.

DTharun
  • Identifies loops that were successfully vectorized:

    clang -Rpass=loop-vectorize
    
  • Identifies loops that failed vectorization and indicates if vectorization was specified:

    clang -Rpass-missed=loop-vectorize 
    
  • Identifies the statements that caused vectorization to fail:

    clang -Rpass-analysis=loop-vectorize
    

Source: http://llvm.org/docs/Vectorizers.html#diagnostics

Assuming you are using opt and you have a debug build of llvm, you can do it as follows:

opt -O1 -loop-vectorize -debug-only=loop-vectorize code.ll

where code.ll is the IR you want to vectorize.

If you are using clang, you will need to pass the -debug-only=loop-vectorize flag using -mllvm option.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!