aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/InfoByHwMode.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-07-26 19:03:47 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-07-26 19:04:23 +0000
commit7fa27ce4a07f19b07799a767fc29416f3b625afb (patch)
tree27825c83636c4de341eb09a74f49f5d38a15d165 /llvm/utils/TableGen/InfoByHwMode.h
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
downloadsrc-7fa27ce4a07f19b07799a767fc29416f3b625afb.tar.gz
src-7fa27ce4a07f19b07799a767fc29416f3b625afb.zip
Vendor import of llvm-project main llvmorg-17-init-19304-gd0b54bb50e51,vendor/llvm-project/llvmorg-17-init-19304-gd0b54bb50e51
the last commit before the upstream release/17.x branch was created.
Diffstat (limited to 'llvm/utils/TableGen/InfoByHwMode.h')
-rw-r--r--llvm/utils/TableGen/InfoByHwMode.h85
1 files changed, 62 insertions, 23 deletions
diff --git a/llvm/utils/TableGen/InfoByHwMode.h b/llvm/utils/TableGen/InfoByHwMode.h
index 44927d0bf0df..b8a6645baca5 100644
--- a/llvm/utils/TableGen/InfoByHwMode.h
+++ b/llvm/utils/TableGen/InfoByHwMode.h
@@ -16,10 +16,16 @@
#include "CodeGenHwModes.h"
#include "llvm/ADT/SmallSet.h"
-#include "llvm/Support/MachineValueType.h"
-
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/CodeGen/MachineValueType.h"
+#include "llvm/Support/Compiler.h"
+#include <cassert>
+#include <limits>
#include <map>
#include <string>
+#include <tuple>
+#include <utility>
namespace llvm {
@@ -38,18 +44,44 @@ template <typename InfoT>
void union_modes(const InfoByHwMode<InfoT> &A,
const InfoByHwMode<InfoT> &B,
SmallVectorImpl<unsigned> &Modes) {
- SmallSet<unsigned, 4> U;
- for (const auto &P : A)
- U.insert(P.first);
- for (const auto &P : B)
- U.insert(P.first);
- // Make sure that the default mode is last on the list.
+ auto AI = A.begin();
+ auto BI = B.begin();
+
+ // Skip default mode, but remember if we had one.
bool HasDefault = false;
- for (unsigned M : U)
- if (M != DefaultMode)
- Modes.push_back(M);
- else
- HasDefault = true;
+ if (AI != A.end() && AI->first == DefaultMode) {
+ HasDefault = true;
+ ++AI;
+ }
+ if (BI != B.end() && BI->first == DefaultMode) {
+ HasDefault = true;
+ ++BI;
+ }
+
+ while (AI != A.end()) {
+ // If we're done with B, finish A.
+ if (BI == B.end()) {
+ for (; AI != A.end(); ++AI)
+ Modes.push_back(AI->first);
+ break;
+ }
+
+ if (BI->first < AI->first) {
+ Modes.push_back(BI->first);
+ ++BI;
+ } else {
+ Modes.push_back(AI->first);
+ if (AI->first == BI->first)
+ ++BI;
+ ++AI;
+ }
+ }
+
+ // Finish B.
+ for (; BI != B.end(); ++BI)
+ Modes.push_back(BI->first);
+
+ // Make sure that the default mode is last on the list.
if (HasDefault)
Modes.push_back(DefaultMode);
}
@@ -78,20 +110,27 @@ struct InfoByHwMode {
LLVM_ATTRIBUTE_ALWAYS_INLINE
bool hasMode(unsigned M) const { return Map.find(M) != Map.end(); }
LLVM_ATTRIBUTE_ALWAYS_INLINE
- bool hasDefault() const { return hasMode(DefaultMode); }
+ bool hasDefault() const {
+ return !Map.empty() && Map.begin()->first == DefaultMode;
+ }
InfoT &get(unsigned Mode) {
- if (!hasMode(Mode)) {
- assert(hasMode(DefaultMode));
- Map.insert({Mode, Map.at(DefaultMode)});
- }
- return Map.at(Mode);
+ auto F = Map.find(Mode);
+ if (F != Map.end())
+ return F->second;
+
+ // Copy and insert the default mode which should be first.
+ assert(hasDefault());
+ auto P = Map.insert({Mode, Map.begin()->second});
+ return P.first->second;
}
const InfoT &get(unsigned Mode) const {
auto F = Map.find(Mode);
- if (Mode != DefaultMode && F == Map.end())
- F = Map.find(DefaultMode);
- assert(F != Map.end());
+ if (F != Map.end())
+ return F->second;
+ // Get the default mode which should be first.
+ F = Map.begin();
+ assert(F != Map.end() && F->first == DefaultMode);
return F->second;
}
@@ -100,7 +139,7 @@ struct InfoByHwMode {
return Map.size() == 1 && Map.begin()->first == DefaultMode;
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
- InfoT getSimple() const {
+ const InfoT &getSimple() const {
assert(isSimple());
return Map.begin()->second;
}