From 94498950e69a78049d3b129f78f0db41114af52e Mon Sep 17 00:00:00 2001 From: Shengchen Kan Date: Wed, 5 Apr 2023 17:42:12 +0800 Subject: [PATCH] [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. --- llvm/lib/Target/X86/X86InstrFoldTables.h | 4 ++-- llvm/utils/TableGen/X86FoldTablesEmitter.cpp | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Target/X86/X86InstrFoldTables.h b/llvm/lib/Target/X86/X86InstrFoldTables.h index 384369b..e1458e3 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 ea9e06b..b576e36 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 + CompareInstrsByEnum> FoldTable; // std::vector for each folding table. // Table2Addr - Holds instructions which their memory form performs load+store -- 2.7.4