[PATCH] D64564: Loop pragma parsing. NFC.
Sjoerd Meijer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 11 06:14:36 PDT 2019
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: samparker, dmgreen, Meinersbur.
Yesterday I was a bit distracted by loop pragma parsing (D64471 <https://reviews.llvm.org/D64471>), but still am a bit today too (this patch).
https://reviews.llvm.org/D64564
Files:
clang/lib/Parse/ParsePragma.cpp
Index: clang/lib/Parse/ParsePragma.cpp
===================================================================
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -1006,18 +1006,14 @@
} // end anonymous namespace
static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
- std::string PragmaString;
- if (PragmaName.getIdentifierInfo()->getName() == "loop") {
- PragmaString = "clang loop ";
- PragmaString += Option.getIdentifierInfo()->getName();
- } else if (PragmaName.getIdentifierInfo()->getName() == "unroll_and_jam") {
- PragmaString = "unroll_and_jam";
- } else {
- assert(PragmaName.getIdentifierInfo()->getName() == "unroll" &&
- "Unexpected pragma name");
- PragmaString = "unroll";
- }
- return PragmaString;
+ std::string Str = PragmaName.getIdentifierInfo()->getName();
+ Str = llvm::StringSwitch<std::string>(Str)
+ .Case("loop", std::string("clang loop ") + Str)
+ .Case("unroll_and_jam", Str)
+ .Case("unroll", Str)
+ .Default("");
+ assert(Str.size() && "Unexpected pragma name");
+ return Str;
}
bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
@@ -1041,12 +1037,12 @@
// Return a valid hint if pragma unroll or nounroll were specified
// without an argument.
- bool PragmaUnroll = PragmaNameInfo->getName() == "unroll";
- bool PragmaNoUnroll = PragmaNameInfo->getName() == "nounroll";
- bool PragmaUnrollAndJam = PragmaNameInfo->getName() == "unroll_and_jam";
- bool PragmaNoUnrollAndJam = PragmaNameInfo->getName() == "nounroll_and_jam";
- if (Toks.empty() && (PragmaUnroll || PragmaNoUnroll || PragmaUnrollAndJam ||
- PragmaNoUnrollAndJam)) {
+ const bool LoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->getName())
+ .Cases("unroll", "nounroll", "unroll_and_jam",
+ "nounroll_and_jam", true)
+ .Default(false);
+
+ if (Toks.empty() && LoopHint) {
ConsumeAnnotationToken();
Hint.Range = Info->PragmaName.getLocation();
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64564.209194.patch
Type: text/x-patch
Size: 2135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190711/9ab60426/attachment.bin>
More information about the cfe-commits
mailing list