diff options
author | Adam Nemet <anemet@apple.com> | 2016-06-14 12:04:26 +0000 |
---|---|---|
committer | Adam Nemet <anemet@apple.com> | 2016-06-14 12:04:26 +0000 |
commit | 2de463ece38ae71bd5d6487db8f84d8e17c3059b (patch) | |
tree | 93c5962300ff9b9c1523a302fc810f10356feebb /clang/lib/Sema | |
parent | 4fbf76f7c34b1c7242340d79a0c256b0e5293346 (diff) | |
download | bcm5719-llvm-2de463ece38ae71bd5d6487db8f84d8e17c3059b.tar.gz bcm5719-llvm-2de463ece38ae71bd5d6487db8f84d8e17c3059b.zip |
Add loop pragma for Loop Distribution
Summary:
This is similar to other loop pragmas like 'vectorize'. Currently it
only has state values: distribute(enable) and distribute(disable). When
one of these is specified the corresponding loop metadata is generated:
!{!"llvm.loop.distribute.enable", i1 true/false}
As a result, loop distribution will be attempted on the loop even if
Loop Distribution in not enabled globally. Analogously, with 'disable'
distribution can be turned off for an individual loop even when the pass
is otherwise enabled.
There are some slight differences compared to the existing loop pragmas.
1. There is no 'assume_safety' variant which makes its handling slightly
different from 'vectorize'/'interleave'.
2. Unlike the existing loop pragmas, it does not have a corresponding
numeric pragma like 'vectorize' -> 'vectorize_width'. So for the
consistency checks in CheckForIncompatibleAttributes we don't need to
check it against other pragmas. We just need to check for duplicates of
the same pragma.
Reviewers: rsmith, dexonsmith, aaron.ballman
Subscribers: bob.wilson, cfe-commits, hfinkel
Differential Revision: http://reviews.llvm.org/D19403
llvm-svn: 272656
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaStmtAttr.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 5120a8773c5..87fd8893957 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -107,6 +107,7 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const AttributeList &A, .Case("interleave_count", LoopHintAttr::InterleaveCount) .Case("unroll", LoopHintAttr::Unroll) .Case("unroll_count", LoopHintAttr::UnrollCount) + .Case("distribute", LoopHintAttr::Distribute) .Default(LoopHintAttr::Vectorize); if (Option == LoopHintAttr::VectorizeWidth || Option == LoopHintAttr::InterleaveCount || @@ -117,7 +118,8 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const AttributeList &A, State = LoopHintAttr::Numeric; } else if (Option == LoopHintAttr::Vectorize || Option == LoopHintAttr::Interleave || - Option == LoopHintAttr::Unroll) { + Option == LoopHintAttr::Unroll || + Option == LoopHintAttr::Distribute) { assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument"); if (StateLoc->Ident->isStr("disable")) State = LoopHintAttr::Disable; @@ -140,18 +142,21 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const AttributeList &A, static void CheckForIncompatibleAttributes(Sema &S, const SmallVectorImpl<const Attr *> &Attrs) { - // There are 3 categories of loop hints attributes: vectorize, interleave, - // and unroll. Each comes in two variants: a state form and a numeric form. - // The state form selectively defaults/enables/disables the transformation - // for the loop (for unroll, default indicates full unrolling rather than - // enabling the transformation). The numeric form form provides an integer - // hint (for example, unroll count) to the transformer. The following array - // accumulates the hints encountered while iterating through the attributes - // to check for compatibility. + // There are 4 categories of loop hints attributes: vectorize, interleave, + // unroll and distribute. Except for distribute they come in two variants: a + // state form and a numeric form. The state form selectively + // defaults/enables/disables the transformation for the loop (for unroll, + // default indicates full unrolling rather than enabling the transformation). + // The numeric form form provides an integer hint (for example, unroll count) + // to the transformer. The following array accumulates the hints encountered + // while iterating through the attributes to check for compatibility. struct { const LoopHintAttr *StateAttr; const LoopHintAttr *NumericAttr; - } HintAttrs[] = {{nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}}; + } HintAttrs[] = {{nullptr, nullptr}, + {nullptr, nullptr}, + {nullptr, nullptr}, + {nullptr, nullptr}}; for (const auto *I : Attrs) { const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(I); @@ -161,7 +166,7 @@ CheckForIncompatibleAttributes(Sema &S, continue; LoopHintAttr::OptionType Option = LH->getOption(); - enum { Vectorize, Interleave, Unroll } Category; + enum { Vectorize, Interleave, Unroll, Distribute } Category; switch (Option) { case LoopHintAttr::Vectorize: case LoopHintAttr::VectorizeWidth: @@ -175,12 +180,17 @@ CheckForIncompatibleAttributes(Sema &S, case LoopHintAttr::UnrollCount: Category = Unroll; break; + case LoopHintAttr::Distribute: + // Perform the check for duplicated 'distribute' hints. + Category = Distribute; + break; }; auto &CategoryState = HintAttrs[Category]; const LoopHintAttr *PrevAttr; if (Option == LoopHintAttr::Vectorize || - Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll) { + Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll || + Option == LoopHintAttr::Distribute) { // Enable|Disable|AssumeSafety hint. For example, vectorize(enable). PrevAttr = CategoryState.StateAttr; CategoryState.StateAttr = LH; |