Skip to content

Conversation

@Zararest
Copy link

@Zararest Zararest commented Nov 5, 2025

There is an issue with using PBQP register allocator in clang that doesn't have AArch64 target:
https://groups.google.com/g/llvm-dev/c/ZIvatINBENo

This change links PBQP regalloc to all LLVM targets.

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category llvm:codegen labels Nov 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-clang

Author: Ivan Shumakov (Zararest)

Changes

There is an issue with using PBQP register allocator in clang that doesn't have AArch64 target:
https://groups.google.com/g/llvm-dev/c/ZIvatINBENo

This change links PBQP regalloc to all LLVM targets.


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

4 Files Affected:

  • (added) clang/test/CodeGen/PBQP-regalloc-all-targets.c (+8)
  • (modified) llvm/include/llvm/InitializePasses.h (+1)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (+1)
  • (modified) llvm/lib/CodeGen/RegAllocPBQP.cpp (+3)
diff --git a/clang/test/CodeGen/PBQP-regalloc-all-targets.c b/clang/test/CodeGen/PBQP-regalloc-all-targets.c
new file mode 100644
index 0000000000000..c316423f4886c
--- /dev/null
+++ b/clang/test/CodeGen/PBQP-regalloc-all-targets.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -triple x86_64 -O2 \
+// RUN:  -mllvm -regalloc=pbqp \
+// RUN:  -mllvm --print-changed -S |& FileCheck %s
+// CHECK: IR Dump After PBQP Register Allocator (regallocpbqp) on foo
+
+extern int foo(int a, int b) {
+  return a + b;
+}
\ No newline at end of file
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 88272f053c114..858fd256f8c6e 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -269,6 +269,7 @@ LLVM_ABI void initializeReassociateLegacyPassPass(PassRegistry &);
 LLVM_ABI void
 initializeRegAllocEvictionAdvisorAnalysisLegacyPass(PassRegistry &);
 LLVM_ABI void initializeRegAllocFastPass(PassRegistry &);
+LLVM_ABI void initializeRegAllocPBQPPass(PassRegistry &);
 LLVM_ABI void
 initializeRegAllocPriorityAdvisorAnalysisLegacyPass(PassRegistry &);
 LLVM_ABI void initializeRegAllocScoringPass(PassRegistry &);
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 9e0cb3bf44906..df6a12324887b 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -114,6 +114,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeRAGreedyLegacyPass(Registry);
   initializeReachingDefInfoWrapperPassPass(Registry);
   initializeRegAllocFastPass(Registry);
+  initializeRegAllocPBQPPass(Registry);
   initializeRegUsageInfoCollectorLegacyPass(Registry);
   initializeRegUsageInfoPropagationLegacyPass(Registry);
   initializeRegisterCoalescerLegacyPass(Registry);
diff --git a/llvm/lib/CodeGen/RegAllocPBQP.cpp b/llvm/lib/CodeGen/RegAllocPBQP.cpp
index 048cd21db062d..a4d859650300c 100644
--- a/llvm/lib/CodeGen/RegAllocPBQP.cpp
+++ b/llvm/lib/CodeGen/RegAllocPBQP.cpp
@@ -946,6 +946,9 @@ void PBQP::RegAlloc::PBQPRAGraph::printDot(raw_ostream &OS) const {
   OS << "}\n";
 }
 
+INITIALIZE_PASS(RegAllocPBQP, "regallocpbqp", "PBQP Register Allocator", false,
+                false)
+
 FunctionPass *llvm::createPBQPRegisterAllocator(char *customPassID) {
   return new RegAllocPBQP(customPassID);
 }

@Zararest
Copy link
Author

Zararest commented Nov 5, 2025

@lhames could you, please, review these changes or give a hint who I should tag
(My tag is based on a mention in the llvm discussion from the first comment of this PR)

@lhames
Copy link
Contributor

lhames commented Nov 10, 2025

@Zararest -- seems reasonable to me. I believe that we used to offer it on all platforms.

Out of interest: Did you check what this does to the size of the clang binary?

@Zararest
Copy link
Author

Here are sizes of a clang binary before and after current commit:

clang release X86 target: 
100391336 bytes -> 100474456 bytes
+0.082%

Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me. Thanks @Zararest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category llvm:codegen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants