[clang-tools-extra] 39c9c12 - [clang-tools-extra] reimplement PreprocessorTracker in terms of StringSet.

2020-04-16 Thread Chris Lattner via cfe-commits

Author: Chris Lattner
Date: 2020-04-16T12:57:43-07:00
New Revision: 39c9c12b76da27bd52ca1b82c3d39d9c9b59ad0f

URL: 
https://github.com/llvm/llvm-project/commit/39c9c12b76da27bd52ca1b82c3d39d9c9b59ad0f
DIFF: 
https://github.com/llvm/llvm-project/commit/39c9c12b76da27bd52ca1b82c3d39d9c9b59ad0f.diff

LOG: [clang-tools-extra] reimplement PreprocessorTracker in terms of StringSet.

Summary:
PreprocessorTracker is the last user of the old StringPool class, which
isn't super loved and isn't a great improvement over a plan StringSet.
Once this goes in we can remove StringPool entirely.

This is as discussed on cfe-dev.

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/modularize/PreprocessorTracker.cpp

Removed: 




diff  --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp 
b/clang-tools-extra/modularize/PreprocessorTracker.cpp
index 26c2923c2983..f8ab2c8067c0 100644
--- a/clang-tools-extra/modularize/PreprocessorTracker.cpp
+++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp
@@ -243,19 +243,19 @@
 //
 //======//
 
-#include "clang/Lex/LexDiagnostic.h"
 #include "PreprocessorTracker.h"
+#include "ModularizeUtilities.h"
+#include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "llvm/ADT/SmallSet.h"
-#include "llvm/Support/StringPool.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/raw_ostream.h"
-#include "ModularizeUtilities.h"
 
 namespace Modularize {
 
 // Some handle types
-typedef llvm::PooledStringPtr StringHandle;
+typedef llvm::StringRef StringHandle;
 
 typedef int HeaderHandle;
 const HeaderHandle HeaderHandleInvalid = -1;
@@ -463,19 +463,6 @@ ConditionValueKindStrings[] = {
   "(not evaluated)", "false", "true"
 };
 
-bool operator<(const StringHandle &H1, const StringHandle &H2) {
-  const char *S1 = (H1 ? *H1 : "");
-  const char *S2 = (H2 ? *H2 : "");
-  int Diff = strcmp(S1, S2);
-  return Diff < 0;
-}
-bool operator>(const StringHandle &H1, const StringHandle &H2) {
-  const char *S1 = (H1 ? *H1 : "");
-  const char *S2 = (H2 ? *H2 : "");
-  int Diff = strcmp(S1, S2);
-  return Diff > 0;
-}
-
 // Preprocessor item key.
 //
 // This class represents a location in a source file, for use
@@ -922,7 +909,9 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
   }
 
   // Lookup/add string.
-  StringHandle addString(llvm::StringRef Str) { return Strings.intern(Str); }
+  StringHandle addString(llvm::StringRef Str) {
+return Strings.insert(Str).first->first();
+  }
 
   // Convert to a canonical path.
   std::string getCanonicalPath(llvm::StringRef path) const {
@@ -950,7 +939,7 @@ class PreprocessorTrackerImpl : public PreprocessorTracker {
 HeaderHandle H = 0;
 for (auto I = HeaderPaths.begin(), E = HeaderPaths.end(); I != E;
  ++I, ++H) {
-  if (**I == CanonicalPath)
+  if (*I == CanonicalPath)
 return H;
 }
 return HeaderHandleInvalid;
@@ -1143,10 +1132,10 @@ class PreprocessorTrackerImpl : public 
PreprocessorTracker {
   // Tell caller we found one or more errors.
   ReturnValue = true;
   // Start the error message.
-  OS << *MacroExpTracker.InstanceSourceLine;
+  OS << MacroExpTracker.InstanceSourceLine;
   if (ItemKey.Column > 0)
 OS << std::string(ItemKey.Column - 1, ' ') << "^\n";
-  OS << "error: Macro instance '" << *MacroExpTracker.MacroUnexpanded
+  OS << "error: Macro instance '" << MacroExpTracker.MacroUnexpanded
  << "' has 
diff erent values in this header, depending on how it was "
 "included.\n";
   // Walk all the instances.
@@ -1154,8 +1143,8 @@ class PreprocessorTrackerImpl : public 
PreprocessorTracker {
 EMT = MacroExpTracker.MacroExpansionInstances.end();
IMT != EMT; ++IMT) {
 MacroExpansionInstance &MacroInfo = *IMT;
-OS << "  '" << *MacroExpTracker.MacroUnexpanded << "' expanded to: '"
-   << *MacroInfo.MacroExpanded
+OS << "  '" << MacroExpTracker.MacroUnexpanded << "' expanded to: '"
+   << MacroInfo.MacroExpanded
<< "' with respect to these inclusion paths:\n";
 // Walk all the inclusion path hierarchies.
 for (auto IIP = MacroInfo.InclusionPathHandles.begin(),
@@ -1165,7 +1154,7 @@ class PreprocessorTrackerImpl : public 
PreprocessorTracker {
   auto Count = (int)ip.size();
   for (int Index = 0; Index < Count; ++Index) {
 HeaderHandle H = ip[Index];
-OS << std::string((Index * 2) + 4, ' ') << *getHeaderFilePath(H)
+OS << std::string((Index * 2) + 4, ' ') << getHeaderFilePath(H)
<< "\n";
   }
 }
@@ -1173,7 +1162,7 @@ class PreprocessorTrackerImpl : pu

[clang] 919dcc7 - [SourceMgr] Tidy up the SourceMgr header file to include less stuff.

2020-04-25 Thread Chris Lattner via cfe-commits

Author: Chris Lattner
Date: 2020-04-25T21:18:59-07:00
New Revision: 919dcc7f6858cf0d9a7442673acafdf495e46c7a

URL: 
https://github.com/llvm/llvm-project/commit/919dcc7f6858cf0d9a7442673acafdf495e46c7a
DIFF: 
https://github.com/llvm/llvm-project/commit/919dcc7f6858cf0d9a7442673acafdf495e46c7a.diff

LOG: [SourceMgr] Tidy up the SourceMgr header file to include less stuff.

Summary:
Specifically make some simple refactorings to get PointerUnion.h and
Twine.h out of the public includes.  While here, trim out a lot of
transitive includes as well.

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

Added: 


Modified: 
clang/include/clang/Basic/FileManager.h
llvm/include/llvm/Support/SourceMgr.h
llvm/lib/Support/SourceMgr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index b481f5846936..089304e1d1e6 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -18,6 +18,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"

diff  --git a/llvm/include/llvm/Support/SourceMgr.h 
b/llvm/include/llvm/Support/SourceMgr.h
index 3255e143d56b..a0bd3ca2e0c1 100644
--- a/llvm/include/llvm/Support/SourceMgr.h
+++ b/llvm/include/llvm/Support/SourceMgr.h
@@ -15,19 +15,9 @@
 #ifndef LLVM_SUPPORT_SOURCEMGR_H
 #define LLVM_SUPPORT_SOURCEMGR_H
 
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/None.h"
-#include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SMLoc.h"
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
 
 namespace llvm {
@@ -57,21 +47,17 @@ class SourceMgr {
 /// The memory buffer for the file.
 std::unique_ptr Buffer;
 
-/// Helper type for OffsetCache below: since we're storing many offsets
-/// into relatively small files (often smaller than 2^8 or 2^16 bytes),
-/// we select the offset vector element type dynamically based on the
-/// size of Buffer.
-using VariableSizeOffsets =
-PointerUnion *, std::vector *,
- std::vector *, std::vector *>;
-
 /// Vector of offsets into Buffer at which there are line-endings
 /// (lazily populated). Once populated, the '\n' that marks the end of
 /// line number N from [1..] is at Buffer[OffsetCache[N-1]]. Since
 /// these offsets are in sorted (ascending) order, they can be
 /// binary-searched for the first one after any given offset (eg. an
 /// offset corresponding to a particular SMLoc).
-mutable VariableSizeOffsets OffsetCache;
+///
+/// Since we're storing offsets into relatively small files (often smaller
+/// than 2^8 or 2^16 bytes), we select the offset vector element type
+/// dynamically based on the size of Buffer.
+mutable void *OffsetCache = nullptr;
 
 /// Look up a given \p Ptr in in the buffer, determining which line it came
 /// from.
@@ -196,14 +182,14 @@ class SourceMgr {
   /// \param ShowColors Display colored messages if output is a terminal and
   /// the default error handler is used.
   void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine 
&Msg,
-ArrayRef Ranges = None,
-ArrayRef FixIts = None,
+ArrayRef Ranges = {},
+ArrayRef FixIts = {},
 bool ShowColors = true) const;
 
   /// Emits a diagnostic to llvm::errs().
   void PrintMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
-ArrayRef Ranges = None,
-ArrayRef FixIts = None,
+ArrayRef Ranges = {},
+ArrayRef FixIts = {},
 bool ShowColors = true) const;
 
   /// Emits a manually-constructed diagnostic to the given output stream.
@@ -219,8 +205,8 @@ class SourceMgr {
   /// \param Msg If non-null, the kind of message (e.g., "error") which is
   /// prefixed to the message.
   SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
-  ArrayRef Ranges = None,
-  ArrayRef FixIts = None) const;
+  ArrayRef Ranges = {},
+  ArrayRef FixIts = {}) const;
 
   /// Prints the names of included files and the line of the file they were
   /// included from. A diagnostic handler can use this before printing its
@@ -238,17 +224,10 @@ class SMFixIt {
   std::string Text;
 
 public:
-  // FIXME: Twine.str() is not very efficient.
-  SMFixIt(SMLoc Loc, const Twine &Insertion)
- 

Re: [PATCH] D23546: Remove excessive padding from LineNoCacheTy

2016-08-16 Thread Chris Lattner via cfe-commits
lattner resigned from this revision.
lattner removed a reviewer: lattner.
lattner added a comment.

Seems obvious to me, but it would be best to find another reviewer, I haven't 
worked on this code for some time.


https://reviews.llvm.org/D23546



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22463: [RFC] Moving to GitHub Proposal: NOT DECISION!

2016-07-18 Thread Chris Lattner via cfe-commits
lattner added a subscriber: lattner.
lattner added a comment.

Please send this to llvm-dev for discussion when it converges, thanks!


https://reviews.llvm.org/D22463



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits