summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse
diff options
context:
space:
mode:
authorMark Heffernan <meheff@google.com>2015-08-10 17:29:39 +0000
committerMark Heffernan <meheff@google.com>2015-08-10 17:29:39 +0000
commit397a98d86df781aaddf64280773657c73ee29435 (patch)
tree98933ea4a0697fbb692f4a36a0e9f6600108e212 /clang/lib/Parse
parent8939154a228b808823daa4b1ab4b38c10230b585 (diff)
downloadbcm5719-llvm-397a98d86df781aaddf64280773657c73ee29435.tar.gz
bcm5719-llvm-397a98d86df781aaddf64280773657c73ee29435.zip
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
Diffstat (limited to 'clang/lib/Parse')
-rw-r--r--clang/lib/Parse/ParsePragma.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index aa7b843837d..5ffce000364 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -822,10 +822,9 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
SourceLocation StateLoc = Toks[0].getLocation();
IdentifierInfo *StateInfo = Toks[0].getIdentifierInfo();
if (!StateInfo ||
- ((OptionUnroll ? !StateInfo->isStr("full")
- : !StateInfo->isStr("enable") &&
- !StateInfo->isStr("assume_safety")) &&
- !StateInfo->isStr("disable"))) {
+ (!StateInfo->isStr("enable") && !StateInfo->isStr("disable") &&
+ ((OptionUnroll && !StateInfo->isStr("full")) ||
+ (!OptionUnroll && !StateInfo->isStr("assume_safety"))))) {
Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
<< /*FullKeyword=*/OptionUnroll;
return false;
@@ -1953,8 +1952,9 @@ static bool ParseLoopHintValue(Preprocessor &PP, Token &Tok, Token PragmaName,
/// 'assume_safety'
///
/// unroll-hint-keyword:
-/// 'full'
+/// 'enable'
/// 'disable'
+/// 'full'
///
/// loop-hint-value:
/// constant-expression
@@ -1970,10 +1970,13 @@ static bool ParseLoopHintValue(Preprocessor &PP, Token &Tok, Token PragmaName,
/// only works on inner loops.
///
/// The unroll and unroll_count directives control the concatenation
-/// unroller. Specifying unroll(full) instructs llvm to try to
-/// unroll the loop completely, and unroll(disable) disables unrolling
-/// for the loop. Specifying unroll_count(_value_) instructs llvm to
-/// try to unroll the loop the number of times indicated by the value.
+/// unroller. Specifying unroll(enable) instructs llvm to unroll the loop
+/// completely if the trip count is known at compile time and unroll partially
+/// if the trip count is not known. Specifying unroll(full) is similar to
+/// unroll(enable) but will unroll the loop only if the trip count is known at
+/// compile time. Specifying unroll(disable) disables unrolling for the
+/// loop. Specifying unroll_count(_value_) instructs llvm to try to unroll the
+/// loop the number of times indicated by the value.
void PragmaLoopHintHandler::HandlePragma(Preprocessor &PP,
PragmaIntroducerKind Introducer,
Token &Tok) {
OpenPOWER on IntegriCloud