Hi Clang folks,
I'm introducing a new pragma "vectorize" to Clang to enable the loop
info metadata in IR that LLVM already understands.
The syntax is:
#pragma vectorize enable
Forces aggressive vectorization of the following loop, at any optimization level
Adds metadata to the loop {"llvm.vectorize.enable", i1 1}
#pragma vectorize disable
Disable vectorization of the following loop, at any optimization level
Adds metadata to the loop {"llvm.vectorize.enable", i1 0}
#pragma vectorize width(N)
Forces specified vector width for the following loop
Adds metadata to the loop {"llvm.vectorize.width", i32 N}
#pragma vectorize unroll(N)
Forces specified unroll factor for the following loop
Adds metadata to the loop {"llvm.vectorize.unroll", i32 N}
None of these pragmas forces vectorization if the transformation is
illegal (type/memory/instruction-wise), but "enable" will make -Oz/s
bloated, as it'll force the aggressive vectorization to run. I'll add
documentation to Clang and LLVM once this is finished.
I don't know Clang parser's code that well, but I started on the
obvious ParsePragma.cpp, and added some logic to recognise the
pragma's syntax. Now I need to attach this information to the AST, and
later on to the IR as metadata.
Attached is my naive implementation of PragmaVectorizeHandler, but
I'll need some pointers on how to convert this into AST annotation and
later into metadata.
Thanks!
--renato
pragma-clang.patch (4.82 KB)