[PATCH] D64471: Loop pragma parsing. NFC.
Sjoerd Meijer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 10 01:16:45 PDT 2019
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: Meinersbur, dmgreen, samparker.
I would like to add some pragma handling here, but couldn't resist a little NFC and tidy up first.
https://reviews.llvm.org/D64471
Files:
clang/lib/Sema/SemaStmtAttr.cpp
Index: clang/lib/Sema/SemaStmtAttr.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -82,22 +82,17 @@
IdentifierLoc *StateLoc = A.getArgAsIdent(2);
Expr *ValueExpr = A.getArgAsExpr(3);
- bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
- bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
- bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == "unroll_and_jam";
- bool PragmaNoUnrollAndJam =
- PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
+ StringRef PragmaName =
+ llvm::StringSwitch<StringRef>(PragmaNameLoc->Ident->getName())
+ .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ PragmaNameLoc->Ident->getName())
+ .Default("clang loop");
+
if (St->getStmtClass() != Stmt::DoStmtClass &&
St->getStmtClass() != Stmt::ForStmtClass &&
St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
St->getStmtClass() != Stmt::WhileStmtClass) {
- const char *Pragma =
- llvm::StringSwitch<const char *>(PragmaNameLoc->Ident->getName())
- .Case("unroll", "#pragma unroll")
- .Case("nounroll", "#pragma nounroll")
- .Case("unroll_and_jam", "#pragma unroll_and_jam")
- .Case("nounroll_and_jam", "#pragma nounroll_and_jam")
- .Default("#pragma clang loop");
+ std::string Pragma = "#pragma " + std::string(PragmaName);
S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma;
return nullptr;
}
@@ -106,34 +101,29 @@
LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
LoopHintAttr::OptionType Option;
LoopHintAttr::LoopHintState State;
- if (PragmaNoUnroll) {
- // #pragma nounroll
- Option = LoopHintAttr::Unroll;
- State = LoopHintAttr::Disable;
- } else if (PragmaUnroll) {
- if (ValueExpr) {
- // #pragma unroll N
- Option = LoopHintAttr::UnrollCount;
- State = LoopHintAttr::Numeric;
- } else {
- // #pragma unroll
- Option = LoopHintAttr::Unroll;
- State = LoopHintAttr::Enable;
- }
- } else if (PragmaNoUnrollAndJam) {
- // #pragma nounroll_and_jam
- Option = LoopHintAttr::UnrollAndJam;
- State = LoopHintAttr::Disable;
- } else if (PragmaUnrollAndJam) {
- if (ValueExpr) {
- // #pragma unroll_and_jam N
- Option = LoopHintAttr::UnrollAndJamCount;
- State = LoopHintAttr::Numeric;
- } else {
- // #pragma unroll_and_jam
- Option = LoopHintAttr::UnrollAndJam;
- State = LoopHintAttr::Enable;
- }
+
+ auto SetHints = [&Option, &State](LoopHintAttr::OptionType O,
+ LoopHintAttr::LoopHintState S) {
+ Option = O;
+ State = S;
+ };
+
+ if (PragmaName == "nounroll") {
+ SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
+ } else if (PragmaName == "unroll") {
+ // #pragma unroll N
+ if (ValueExpr)
+ SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
+ else
+ SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
+ } else if (PragmaName == "nounroll_and_jam") {
+ SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Disable);
+ } else if (PragmaName == "unroll_and_jam") {
+ // #pragma unroll_and_jam N
+ if (ValueExpr)
+ SetHints(LoopHintAttr::UnrollAndJamCount, LoopHintAttr::Numeric);
+ else
+ SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable);
} else {
// #pragma clang loop ...
assert(OptionLoc && OptionLoc->Ident &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64471.208888.patch
Type: text/x-patch
Size: 3606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190710/0ce851b1/attachment.bin>
More information about the cfe-commits
mailing list