[flang-commits] [flang] 660c511 - [Flang][flang-omp-report] Switch from std::string to StringRef (where possible)

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Wed Oct 20 00:56:33 PDT 2021


Author: Josh Mottley
Date: 2021-10-20T07:55:44Z
New Revision: 660c511e5b79d3724b8a139c8865c790d77b1f8f

URL: https://github.com/llvm/llvm-project/commit/660c511e5b79d3724b8a139c8865c790d77b1f8f
DIFF: https://github.com/llvm/llvm-project/commit/660c511e5b79d3724b8a139c8865c790d77b1f8f.diff

LOG: [Flang][flang-omp-report] Switch from std::string to StringRef (where possible)

This patch makes the following changes to flang-omp-report:
 - Update 'normalize_clause_name' parameter to use llvm::StringRef instead of
   std::sting.
 - Change usages of std::tolower to llvm::toLower from
   "ADT/StringExtras.h".
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: Leporacanthicus, clementval

Differential Revision: https://reviews.llvm.org/D111980

Added: 
    

Modified: 
    flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
    flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h

Removed: 
    


################################################################################
diff  --git a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
index 08c3f06441a7..ca56e83e88cf 100644
--- a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
+++ b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang-omp-report-visitor.h"
+#include "llvm/ADT/StringExtras.h"
 
 namespace Fortran {
 namespace parser {
@@ -26,23 +27,24 @@ bool operator!=(const LogRecord &a, const LogRecord &b) { return !(a == b); }
 
 std::string OpenMPCounterVisitor::normalize_construct_name(std::string s) {
   std::transform(s.begin(), s.end(), s.begin(),
-      [](unsigned char c) { return std::tolower(c); });
+      [](unsigned char c) { return llvm::toLower(c); });
   return s;
 }
-ClauseInfo OpenMPCounterVisitor::normalize_clause_name(const std::string &s) {
+ClauseInfo OpenMPCounterVisitor::normalize_clause_name(
+    const llvm::StringRef s) {
   std::size_t start = s.find('(');
   std::size_t end = s.find(')');
   std::string clauseName;
-  if (start != std::string::npos && end != std::string::npos) {
+  if (start != llvm::StringRef::npos && end != llvm::StringRef::npos) {
     clauseName = s.substr(0, start);
     clauseDetails = s.substr(start + 1, end - start - 1);
   } else {
     clauseName = s;
   }
   std::transform(clauseName.begin(), clauseName.end(), clauseName.begin(),
-      [](unsigned char c) { return std::tolower(c); });
+      [](unsigned char c) { return llvm::toLower(c); });
   std::transform(clauseDetails.begin(), clauseDetails.end(),
-      clauseDetails.begin(), [](unsigned char c) { return std::tolower(c); });
+      clauseDetails.begin(), [](unsigned char c) { return llvm::toLower(c); });
   return ClauseInfo{clauseName, clauseDetails};
 }
 SourcePosition OpenMPCounterVisitor::getLocation(const OmpWrapperType &w) {

diff  --git a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h
index 034f20f7ca56..4aeb7194a17a 100644
--- a/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h
+++ b/flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h
@@ -14,6 +14,7 @@
 #include "flang/Parser/parsing.h"
 
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 
 #include <deque>
 #include <map>
@@ -48,7 +49,7 @@ using OmpWrapperType =
 
 struct OpenMPCounterVisitor {
   std::string normalize_construct_name(std::string s);
-  ClauseInfo normalize_clause_name(const std::string &s);
+  ClauseInfo normalize_clause_name(const llvm::StringRef s);
   SourcePosition getLocation(const OmpWrapperType &w);
   SourcePosition getLocation(const OpenMPDeclarativeConstruct &c);
   SourcePosition getLocation(const OpenMPConstruct &c);


        


More information about the flang-commits mailing list