[PATCH] D11738: Add new llvm.loop.unroll.enable metadata which is now generated by "#pragma unroll" directive

Mark Heffernan meheff at google.com
Mon Aug 3 15:38:02 PDT 2015


meheff created this revision.
meheff added reviewers: tyler.nowicki, hfinkel.
meheff added subscribers: cfe-commits, llvm-commits.

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.

Optimizer patch will follow shortly.

http://reviews.llvm.org/D11738

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11738.31277.patch
Type: text/x-patch
Size: 20372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150803/51001d6d/attachment.bin>


More information about the cfe-commits mailing list