[llvm] [TableGen] Avoid field lookup in a performance critical place (NFC) (PR #154871)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 18:57:23 PDT 2025


https://github.com/s-barannikov created https://github.com/llvm/llvm-project/pull/154871

`Target.getInstructions()` is called by basically all TableGen backends. It is slow, and one of the two factors is the use of an expensive predicate in `llvm::sort`. This change speeds up sorting by 10x.


>From c727635dfa3f525182f63d8468adc792e7a04194 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 22 Aug 2025 04:44:07 +0300
Subject: [PATCH] [TableGen] Avoid field lookup in a critical loop (NFC)

This makes the loop run 10x faster.
---
 llvm/utils/TableGen/Common/CodeGenTarget.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/utils/TableGen/Common/CodeGenTarget.cpp b/llvm/utils/TableGen/Common/CodeGenTarget.cpp
index a9002c5860fa3..8982927eeefcf 100644
--- a/llvm/utils/TableGen/Common/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenTarget.cpp
@@ -270,8 +270,8 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
         const Record &D2 = *Rec2->TheDef;
         // Sort all pseudo instructions before non-pseudo ones, and sort by name
         // within.
-        return std::tuple(!D1.getValueAsBit("isPseudo"), D1.getName()) <
-               std::tuple(!D2.getValueAsBit("isPseudo"), D2.getName());
+        return std::tuple(!Rec1->isPseudo, D1.getName()) <
+               std::tuple(!Rec2->isPseudo, D2.getName());
       });
 
   // Assign an enum value to each instruction according to the sorted order.



More information about the llvm-commits mailing list