Skip to content

Conversation

@s-barannikov
Copy link
Contributor

@s-barannikov s-barannikov commented Aug 22, 2025

Target.getInstructions() is called by virtually 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.

This makes the loop run 10x faster.
@llvmbot
Copy link
Member

llvmbot commented Aug 22, 2025

@llvm/pr-subscribers-tablegen

Author: Sergei Barannikov (s-barannikov)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/154871.diff

1 Files Affected:

  • (modified) llvm/utils/TableGen/Common/CodeGenTarget.cpp (+2-2)
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.

@s-barannikov s-barannikov requested a review from jurahul August 23, 2025 04:30
Copy link
Contributor

@jurahul jurahul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find! LGTM

@s-barannikov s-barannikov merged commit 7dbdb66 into llvm:main Aug 25, 2025
11 checks passed
@s-barannikov s-barannikov deleted the tablegen/speedup-get-instructions branch August 25, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants