[llvm] 9449895 - [X86][mem-fold][NFC] Refine code
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 02:55:14 PDT 2023
Author: Shengchen Kan
Date: 2023-04-05T17:54:58+08:00
New Revision: 94498950e69a78049d3b129f78f0db41114af52e
URL: https://github.com/llvm/llvm-project/commit/94498950e69a78049d3b129f78f0db41114af52e
DIFF: https://github.com/llvm/llvm-project/commit/94498950e69a78049d3b129f78f0db41114af52e.diff
LOG: [X86][mem-fold][NFC] Refine code
1. Use `unsigned` for `KeyOp` and `DstOp` b/c `Opcode` is of type `unsigned`.
2. Align the comparator used in X86FoldTablesEmitter.cpp with the one in
CodeGenTarget::ComputeInstrsByEnum.
Added:
Modified:
llvm/lib/Target/X86/X86InstrFoldTables.h
llvm/utils/TableGen/X86FoldTablesEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86InstrFoldTables.h b/llvm/lib/Target/X86/X86InstrFoldTables.h
index 384369b9560ac..e1458e383fa78 100644
--- a/llvm/lib/Target/X86/X86InstrFoldTables.h
+++ b/llvm/lib/Target/X86/X86InstrFoldTables.h
@@ -21,8 +21,8 @@ namespace llvm {
// This struct is used for both the folding and unfold tables. They KeyOp
// is used to determine the sorting order.
struct X86MemoryFoldTableEntry {
- uint16_t KeyOp;
- uint16_t DstOp;
+ unsigned KeyOp;
+ unsigned DstOp;
uint16_t Flags;
bool operator<(const X86MemoryFoldTableEntry &RHS) const {
diff --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
index ea9e06b15405e..b576e36a52813 100644
--- a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
+++ b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
@@ -109,22 +109,23 @@ class X86FoldTablesEmitter {
};
- struct CodeGenInstructionComparator {
- // Comparator function
+ // NOTE: We check the fold tables are sorted in X86InstrFoldTables.cpp by the enum of the
+ // instruction, which is computed in CodeGenTarget::ComputeInstrsByEnum. So we should
+ // use the same comparator here.
+ // FIXME: Could we share the code with CodeGenTarget::ComputeInstrsByEnum?
+ struct CompareInstrsByEnum {
bool operator()(const CodeGenInstruction *LHS,
const CodeGenInstruction *RHS) const {
assert(LHS && RHS && "LHS and RHS shouldn't be nullptr");
- bool LHSpseudo = LHS->TheDef->getValueAsBit("isPseudo");
- bool RHSpseudo = RHS->TheDef->getValueAsBit("isPseudo");
- if (LHSpseudo != RHSpseudo)
- return LHSpseudo;
-
- return LHS->TheDef->getName() < RHS->TheDef->getName();
+ const auto &D1 = *LHS->TheDef;
+ const auto &D2 = *RHS->TheDef;
+ return std::make_tuple(!D1.getValueAsBit("isPseudo"), D1.getName()) <
+ std::make_tuple(!D2.getValueAsBit("isPseudo"), D2.getName());
}
};
typedef std::map<const CodeGenInstruction *, X86FoldTableEntry,
- CodeGenInstructionComparator>
+ CompareInstrsByEnum>
FoldTable;
// std::vector for each folding table.
// Table2Addr - Holds instructions which their memory form performs load+store
More information about the llvm-commits
mailing list