Skip to content

[BOLT] Move ADRRelaxationPass #101371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged

[BOLT] Move ADRRelaxationPass #101371

merged 1 commit into from
Aug 7, 2024

Conversation

yota9
Copy link
Member

@yota9 yota9 commented Jul 31, 2024

For non-simple functions we need nop instruction to be presented to
transform ADR to ADRP+ADD sequence, so run this pass before remove nops
pass.

For non-simple functions we need nop instruction to be presented to
transform ADR to ADRP+ADD sequence, so run this pass before remove nops
pass.
@yota9 yota9 added the BOLT label Jul 31, 2024
@yota9 yota9 requested a review from dcci as a code owner July 31, 2024 17:34
@yota9 yota9 requested a review from mtvec July 31, 2024 17:34
@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2024

@llvm/pr-subscribers-bolt

Author: Vladislav Khmelevsky (yota9)

Changes

For non-simple functions we need nop instruction to be presented to
transform ADR to ADRP+ADD sequence, so run this pass before remove nops
pass.


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

1 Files Affected:

  • (modified) bolt/lib/Rewrite/BinaryPassManager.cpp (+2-2)
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp b/bolt/lib/Rewrite/BinaryPassManager.cpp
index 5dfef0b71cc79..dadb1f4d833b0 100644
--- a/bolt/lib/Rewrite/BinaryPassManager.cpp
+++ b/bolt/lib/Rewrite/BinaryPassManager.cpp
@@ -357,6 +357,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
 
     Manager.registerPass(
         std::make_unique<VeneerElimination>(PrintVeneerElimination));
+
+    Manager.registerPass(std::make_unique<ADRRelaxationPass>());
   }
 
   if (BC.isRISCV()) {
@@ -490,8 +492,6 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
   Manager.registerPass(std::make_unique<ReorderData>());
 
   if (BC.isAArch64()) {
-    Manager.registerPass(std::make_unique<ADRRelaxationPass>());
-
     // Tighten branches according to offset differences between branch and
     // targets. No extra instructions after this pass, otherwise we may have
     // relocations out of range and crash during linking.

Copy link
Contributor

@peterwaller-arm peterwaller-arm left a comment

Choose a reason for hiding this comment

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

LGTM. I also wonder aloud if RemoveNops could be moved down, I don't see documentation suggesting what it is constrained by or if any other pass depends on it.

The other incidental observation is that passes mix runOnFunctions() { if (!BC.isX86()) return; ... } and having if (arch) Manager.registerPass in BinaryPassManager. Is there a rationale for each? I'm new here but from my perspective it would be easier to follow what's going on if the passes relevant to each architecture were clear from runAllPasses(). I'm not asking for this to be changed in now but do you concur that arch conditions could be hoisted out of the individual passes to make it clearer? Or is the status quo preferred?

@yota9
Copy link
Member Author

yota9 commented Aug 6, 2024

Well I think there is no documentation that would tell about pass order in BOLT. When creating new pass you need to consider yourself in which order it would be run. I've decided to run it on latter stage since there is no real difference where to put it and when remove ADR instructions. The pros to run it later is that it would also remove created adr instructions by bolt (if any). But we are not creating them and we don't have to create, any addresses on this stage should use adrp+add. And one of the cons found now is basically that nop instructions sometimes could be removed (also in my mind they really shouldn't due to #101964). (Originally this pass didn't even remove nops so I didn't even think about such problems). Anyway there is no harm on moving this up as I said BOLT should avoid creating ADR instructions by it self and it doesn't really matter when we would replace them, so let's replace from the beginning.

@yota9
Copy link
Member Author

yota9 commented Aug 6, 2024

As for inconsistency - basically I agree. Currently I don't think there is some kind of code style here, this is of the minor thing to decide later with meta team

@yota9 yota9 merged commit 750b12f into llvm:main Aug 7, 2024
8 checks passed
yota9 added a commit to yota9/llvm-project that referenced this pull request Aug 7, 2024
This reverts commit 750b12f.
The pass should run after splitting phase, but before nop removal
yota9 added a commit that referenced this pull request Aug 7, 2024
This reverts commit 750b12f.
The pass should run after splitting phase, but before nop removal
@maksfb
Copy link
Contributor

maksfb commented Aug 20, 2024

As for inconsistency - basically I agree. Currently I don't think there is some kind of code style here, this is of the minor thing to decide later with meta team

I second that sentiment. Feel free to hoist arch checks to pass registry.

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.

4 participants