[cfe-dev] Adding Pragma Vectorize

Renato Golin renato.golin at linaro.org
Fri Dec 6 05:35:36 PST 2013


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pragma-clang.patch
Type: text/x-patch
Size: 4933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131206/64314ec6/attachment.bin>


More information about the cfe-dev mailing list