summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen/Record.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/TableGen/Record.cpp')
-rw-r--r--llvm/lib/TableGen/Record.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index cf70be67e3c..480a002b64a 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -15,9 +15,11 @@
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
@@ -36,8 +38,13 @@
using namespace llvm;
+#define DEBUG_TYPE "tblgen-records"
+
static BumpPtrAllocator Allocator;
+STATISTIC(CodeInitsConstructed,
+ "The total number of unique CodeInits constructed");
+
//===----------------------------------------------------------------------===//
// Type implementations
//===----------------------------------------------------------------------===//
@@ -506,13 +513,20 @@ IntInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
return BitsInit::get(NewBits);
}
-CodeInit *CodeInit::get(StringRef V) {
- static StringMap<CodeInit*, BumpPtrAllocator &> ThePool(Allocator);
+CodeInit *CodeInit::get(StringRef V, const SMLoc &Loc) {
+ static StringSet<BumpPtrAllocator &> ThePool(Allocator);
- auto &Entry = *ThePool.insert(std::make_pair(V, nullptr)).first;
- if (!Entry.second)
- Entry.second = new(Allocator) CodeInit(Entry.getKey());
- return Entry.second;
+ CodeInitsConstructed++;
+
+ // Unlike StringMap, StringSet doesn't accept empty keys.
+ if (V.empty())
+ return new (Allocator) CodeInit("", Loc);
+
+ // Location tracking prevents us from de-duping CodeInits as we're never
+ // called with the same string and same location twice. However, we can at
+ // least de-dupe the strings for a modest saving.
+ auto &Entry = *ThePool.insert(V).first;
+ return new(Allocator) CodeInit(Entry.getKey(), Loc);
}
StringInit *StringInit::get(StringRef V) {
@@ -528,7 +542,7 @@ Init *StringInit::convertInitializerTo(RecTy *Ty) const {
if (isa<StringRecTy>(Ty))
return const_cast<StringInit *>(this);
if (isa<CodeRecTy>(Ty))
- return CodeInit::get(getValue());
+ return CodeInit::get(getValue(), SMLoc());
return nullptr;
}
OpenPOWER on IntegriCloud