[llvm] [NFC] Use more efficient data structures in SubtargetEmitter (PR #102090)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 05:52:12 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/102090
>From 197a5f48dac2468c5d5a6154838caa415923b6e0 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 5 Aug 2024 18:17:24 -0700
Subject: [PATCH] [NFC] Use more efficient data structures in SubtargetEmitter
- Use StringSet and unorderd_map instead of set and map.
- Add a unit test to check if duplicate names are flagged.
---
llvm/test/TableGen/SubtargetFeatureUniqueNames.td | 10 ++++++++++
llvm/utils/TableGen/SubtargetEmitter.cpp | 8 ++++----
2 files changed, 14 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/TableGen/SubtargetFeatureUniqueNames.td
diff --git a/llvm/test/TableGen/SubtargetFeatureUniqueNames.td b/llvm/test/TableGen/SubtargetFeatureUniqueNames.td
new file mode 100644
index 0000000000000..a482b50b539ed
--- /dev/null
+++ b/llvm/test/TableGen/SubtargetFeatureUniqueNames.td
@@ -0,0 +1,10 @@
+// RUN: not llvm-tblgen -gen-subtarget -I %p/../../include %s 2>&1 | FileCheck %s
+// Verify that subtarget features with same names result in an error.
+
+include "llvm/Target/Target.td"
+
+def MyTarget : Target;
+
+// CHECK: error: Duplicate key in SubtargetFeatureKV: NameA
+def FeatureA : SubtargetFeature<"NameA", "", "", "">;
+def FeatureB : SubtargetFeature<"NameA", "", "", "">;
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 1adefea5b0359..f02b08bafe235 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/MC/MCInstrItineraries.h"
#include "llvm/MC/MCSchedule.h"
#include "llvm/Support/Debug.h"
@@ -31,9 +32,8 @@
#include <cassert>
#include <cstdint>
#include <iterator>
-#include <map>
-#include <set>
#include <string>
+#include <unordered_map>
#include <vector>
using namespace llvm;
@@ -260,7 +260,7 @@ unsigned SubtargetEmitter::FeatureKeyValues(
llvm::sort(FeatureList, LessRecordFieldName());
// Check that there are no duplicate keys
- std::set<StringRef> UniqueKeys;
+ llvm::StringSet<> UniqueKeys;
// Begin feature table
OS << "// Sorted (by key) array of values for CPU features.\n"
@@ -494,7 +494,7 @@ void SubtargetEmitter::EmitStageAndOperandCycleData(
// operand cycles, and pipeline bypass tables. Then add the new Itinerary
// object with computed offsets to the ProcItinLists result.
unsigned StageCount = 1, OperandCycleCount = 1;
- std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
+ std::unordered_map<std::string, unsigned> ItinStageMap, ItinOperandMap;
for (const CodeGenProcModel &ProcModel : SchedModels.procModels()) {
// Add process itinerary to the list.
std::vector<InstrItinerary> &ItinList = ProcItinLists.emplace_back();
More information about the llvm-commits
mailing list