[llvm] [TableGen] Use vectors instead of sets for testing intersection. NFC. (PR #81602)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 05:24:08 PST 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/81602
In a few places we test whether sets (i.e. sorted ranges) intersect by
computing the set_intersection and then testing whether it is empty. For
this purpose it should be more efficient to use a std:vector instead of
a std::set to hold the result of the set_intersection, since insertion
is simpler.
>From 1488662985cc71d1b30fd3d7e55e116111660a5c Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Tue, 13 Feb 2024 13:09:32 +0000
Subject: [PATCH] [TableGen] Use vectors instead of sets for testing
intersection. NFC.
In a few places we test whether sets (i.e. sorted ranges) intersect by
computing the set_intersection and then testing whether it is empty. For
this purpose it should be more efficient to use a std:vector instead of
a std::set to hold the result of the set_intersection, since insertion
is simpler.
---
llvm/utils/TableGen/AsmMatcherEmitter.cpp | 7 +++----
llvm/utils/TableGen/CodeGenRegisters.cpp | 11 +++++------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 9065885618069b..a2122659d4dd27 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -242,11 +242,10 @@ struct ClassInfo {
if (!isRegisterClass() || !RHS.isRegisterClass())
return false;
- RegisterSet Tmp;
- std::insert_iterator<RegisterSet> II(Tmp, Tmp.begin());
+ std::vector<Record *> Tmp;
std::set_intersection(Registers.begin(), Registers.end(),
- RHS.Registers.begin(), RHS.Registers.end(), II,
- LessRecordByID());
+ RHS.Registers.begin(), RHS.Registers.end(),
+ std::back_inserter(Tmp), LessRecordByID());
return !Tmp.empty();
}
diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp
index 25f38648366300..5c74a6f3781222 100644
--- a/llvm/utils/TableGen/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/CodeGenRegisters.cpp
@@ -2034,12 +2034,11 @@ void CodeGenRegBank::computeRegUnitSets() {
// Compare new sets with all original classes.
for (unsigned SearchIdx = (Idx >= NumRegUnitSubSets) ? 0 : Idx + 1;
SearchIdx != EndIdx; ++SearchIdx) {
- std::set<unsigned> Intersection;
- std::set_intersection(RegUnitSets[Idx].Units.begin(),
- RegUnitSets[Idx].Units.end(),
- RegUnitSets[SearchIdx].Units.begin(),
- RegUnitSets[SearchIdx].Units.end(),
- std::inserter(Intersection, Intersection.begin()));
+ std::vector<unsigned> Intersection;
+ std::set_intersection(
+ RegUnitSets[Idx].Units.begin(), RegUnitSets[Idx].Units.end(),
+ RegUnitSets[SearchIdx].Units.begin(),
+ RegUnitSets[SearchIdx].Units.end(), std::back_inserter(Intersection));
if (Intersection.empty())
continue;
More information about the llvm-commits
mailing list