From 880afa1c5d1b099eed5034340a67e56b9dda4c09 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Tue, 13 Feb 2024 13:44:31 +0000 Subject: [TableGen] Use vectors instead of sets for testing intersection. NFC. (#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. --- 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 9065885..a212265 100644 --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -242,11 +242,10 @@ public: if (!isRegisterClass() || !RHS.isRegisterClass()) return false; - RegisterSet Tmp; - std::insert_iterator II(Tmp, Tmp.begin()); + std::vector 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 25f3864..5c74a6f 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 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 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; -- cgit v1.1