Add new llvm.loop.unroll.enable metadata for use with "#pragma unroll".
authorMark Heffernan <meheff@google.com>
Mon, 10 Aug 2015 17:29:39 +0000 (17:29 +0000)
committerMark Heffernan <meheff@google.com>
Mon, 10 Aug 2015 17:29:39 +0000 (17:29 +0000)
commit397a98d86df781aaddf64280773657c73ee29435
tree98933ea4a0697fbb692f4a36a0e9f6600108e212
parent8939154a228b808823daa4b1ab4b38c10230b585
Add new llvm.loop.unroll.enable metadata for use with "#pragma unroll".

This change adds the new unroll metadata "llvm.loop.unroll.enable" which directs
the optimizer to unroll a loop fully if the trip count is known at compile time, and
unroll partially if the trip count is not known at compile time. This differs from
"llvm.loop.unroll.full" which explicitly does not unroll a loop if the trip count is not
known at compile time

With this change "#pragma unroll" generates "llvm.loop.unroll.enable" rather than
"llvm.loop.unroll.full" metadata. This changes the semantics of "#pragma unroll" slightly
to mean "unroll aggressively (fully or partially)" rather than "unroll fully or not at all".

The motivating example for this change was some internal code with a loop marked
with "#pragma unroll" which only sometimes had a compile-time trip count depending
on template magic. When the trip count was a compile-time constant, everything works
as expected and the loop is fully unrolled. However, when the trip count was not a
compile-time constant the "#pragma unroll" explicitly disabled unrolling of the loop(!).
Removing "#pragma unroll" caused the loop to be unrolled partially which was desirable
from a performance perspective.

llvm-svn: 244467
12 files changed:
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/CodeGen/CGLoopInfo.cpp
clang/lib/CodeGen/CGLoopInfo.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/CodeGenCXX/pragma-unroll.cpp
clang/test/Parser/pragma-loop-safety.cpp
clang/test/Parser/pragma-loop.cpp
clang/test/Parser/pragma-unroll.cpp