Skip to content

[RISC-V] Add SMLoc info for fixup. [NFCI] #142054

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fpetrogalli
Copy link
Member

This makes sure that potential error messages attached to the fixups being created are linked to the source code that triggered the split.

This makes sure that potential error messages attached to the fixups
being created are linked to the source code that triggered the split.
@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Francesco Petrogalli (fpetrogalli)

Changes

This makes sure that potential error messages attached to the fixups being created are linked to the source code that triggered the split.


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

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp (+3-2)
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 963501db118e7..7b15a01dcf9ec 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -645,8 +645,9 @@ bool RISCVAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
     }
     MCValue A = MCValue::get(Target.getAddSym(), nullptr, Target.getConstant());
     MCValue B = MCValue::get(Target.getSubSym());
-    auto FA = MCFixup::create(Fixup.getOffset(), nullptr, TA);
-    auto FB = MCFixup::create(Fixup.getOffset(), nullptr, TB);
+    const SMLoc Loc = Fixup.getLoc();
+    auto FA = MCFixup::create(Fixup.getOffset(), nullptr, TA, Loc);
+    auto FB = MCFixup::create(Fixup.getOffset(), nullptr, TB, Loc);
     Asm->getWriter().recordRelocation(F, FA, A, FixedValueA);
     Asm->getWriter().recordRelocation(F, FB, B, FixedValueB);
     FixedValue = FixedValueA - FixedValueB;

@MaskRay
Copy link
Member

MaskRay commented May 30, 2025

I actually plan to remove SMLoc from MCFixup to reduce its size, as the SMLoc can typically be retrieved from MCExpr *MCFixup::Value.

I also considered removing SMLoc from MCExpr. https://llvm-compile-time-tracker.com/compare.php?from=193135c80019a01e08014b5727088b860a09f493&to=b8a413de2798260fabf6b5650fc22c803fa13831&stat=max-rss&linkStats=on

The saving is actually quite decent for a -g build, but some folks might need the MCExpr loc.

stage1-ReleaseLTO-g (link only):

Benchmark | Old | New

-- | -- | --
kimwitu++ | 248MiB | 242MiB (-2.52%)
sqlite3 | 221MiB | 216MiB (-2.43%)
consumer-typeset | 162MiB | 158MiB (-2.26%)
Bullet | 208MiB | 204MiB (-1.81%)
tramp3d-v4 | 624MiB | 616MiB (-1.32%)
mafft | 122MiB | 123MiB (+1.08%)
ClamAV | 230MiB | 224MiB (-2.61%)
lencod | 277MiB | 270MiB (-2.63%)
SPASS | 289MiB | 284MiB (-1.67%)
7zip | 467MiB | 454MiB (-2.84%)
geomean | 256MiB | 251MiB (-1.91%)


I think we should remove SMLoc from either MCFixup or MCExpr. If we end up updating MCFixup, this change will be rewritten.

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

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

.

@fpetrogalli
Copy link
Member Author

I actually plan to remove SMLoc from MCFixup to reduce its size, as the SMLoc can typically be retrieved from MCExpr *MCFixup::Value.

I also considered removing SMLoc from MCExpr. https://llvm-compile-time-tracker.com/compare.php?from=193135c80019a01e08014b5727088b860a09f493&to=b8a413de2798260fabf6b5650fc22c803fa13831&stat=max-rss&linkStats=on

The saving is actually quite decent for a -g build, but some folks might need the MCExpr loc.

stage1-ReleaseLTO-g (link only):

Benchmark | Old | New
-- | -- | -- kimwitu++ | 248MiB | 242MiB (-2.52%) sqlite3 | 221MiB | 216MiB (-2.43%) consumer-typeset | 162MiB | 158MiB (-2.26%) Bullet | 208MiB | 204MiB (-1.81%) tramp3d-v4 | 624MiB | 616MiB (-1.32%) mafft | 122MiB | 123MiB (+1.08%) ClamAV | 230MiB | 224MiB (-2.61%) lencod | 277MiB | 270MiB (-2.63%) SPASS | 289MiB | 284MiB (-1.67%) 7zip | 467MiB | 454MiB (-2.84%) geomean | 256MiB | 251MiB (-1.91%)

I don't understand how SMLoc is saving size on these non-LLVM executable.

I think we should remove SMLoc from either MCFixup or MCExpr. If we end up updating MCFixup, this change will be rewritten.

I don't have preferences, as long as we can still prompt errors that point to the line that is causing the error.

Some context on why I created this MR. I am currently debugging some failures in the relocations for Macho-O, adding these SMLoc helped me out to figure out what was wrong. I can keep these changes locally if you don't find them useful. Even if we merged this change, I don't have a regression test for it (other than the failure I am debugging, which of course I cannot upstream as it is), so if you end up removing it in the cleanup, nobody will notice.

@MaskRay
Copy link
Member

MaskRay commented May 31, 2025

I actually plan to remove SMLoc from MCFixup to reduce its size, as the SMLoc can typically be retrieved from MCExpr *MCFixup::Value.
I also considered removing SMLoc from MCExpr. llvm-compile-time-tracker.com/compare.php?from=193135c80019a01e08014b5727088b860a09f493&to=b8a413de2798260fabf6b5650fc22c803fa13831&stat=max-rss&linkStats=on
The saving is actually quite decent for a -g build, but some folks might need the MCExpr loc.

stage1-ReleaseLTO-g (link only):

Benchmark | Old | New
-- | -- | -- kimwitu++ | 248MiB | 242MiB (-2.52%) sqlite3 | 221MiB | 216MiB (-2.43%) consumer-typeset | 162MiB | 158MiB (-2.26%) Bullet | 208MiB | 204MiB (-1.81%) tramp3d-v4 | 624MiB | 616MiB (-1.32%) mafft | 122MiB | 123MiB (+1.08%) ClamAV | 230MiB | 224MiB (-2.61%) lencod | 277MiB | 270MiB (-2.63%) SPASS | 289MiB | 284MiB (-1.67%) 7zip | 467MiB | 454MiB (-2.84%) geomean | 256MiB | 251MiB (-1.91%)

I don't understand how SMLoc is saving size on these non-LLVM executable.

This page demonstrates that a stage1 build of LLVM with my commit applied (removing SMLoc from MCExpr), will use less memory when building these llvm-test-suite projects.
The saving is quite high, but as mentioned, we might not proceed as the MCExpr location can be useful.

If we keep MCExpr location, we can remove the MCFixup location or repurose the field for something else (perhaps more similar to GNU Assembler).

I think we should remove SMLoc from either MCFixup or MCExpr. If we end up updating MCFixup, this change will be rewritten.

I don't have preferences, as long as we can still prompt errors that point to the line that is causing the error.

Some context on why I created this MR. I am currently debugging some failures in the relocations for Macho-O, adding these SMLoc helped me out to figure out what was wrong. I can keep these changes locally if you don't find them useful. Even if we merged this change, I don't have a regression test for it (other than the failure I am debugging, which of course I cannot upstream as it is), so if you end up removing it in the cleanup, nobody will notice.

@fpetrogalli
Copy link
Member Author

I actually plan to remove SMLoc from MCFixup to reduce its size, as the SMLoc can typically be retrieved from MCExpr *MCFixup::Value.
I also considered removing SMLoc from MCExpr. llvm-compile-time-tracker.com/compare.php?from=193135c80019a01e08014b5727088b860a09f493&to=b8a413de2798260fabf6b5650fc22c803fa13831&stat=max-rss&linkStats=on
The saving is actually quite decent for a -g build, but some folks might need the MCExpr loc.

stage1-ReleaseLTO-g (link only):

Benchmark | Old | New
-- | -- | -- kimwitu++ | 248MiB | 242MiB (-2.52%) sqlite3 | 221MiB | 216MiB (-2.43%) consumer-typeset | 162MiB | 158MiB (-2.26%) Bullet | 208MiB | 204MiB (-1.81%) tramp3d-v4 | 624MiB | 616MiB (-1.32%) mafft | 122MiB | 123MiB (+1.08%) ClamAV | 230MiB | 224MiB (-2.61%) lencod | 277MiB | 270MiB (-2.63%) SPASS | 289MiB | 284MiB (-1.67%) 7zip | 467MiB | 454MiB (-2.84%) geomean | 256MiB | 251MiB (-1.91%)

I don't understand how SMLoc is saving size on these non-LLVM executable.

This page demonstrates that a stage1 build of LLVM with my commit applied (removing SMLoc from MCExpr), will use less memory when building these llvm-test-suite projects. The saving is quite high, but as mentioned, we might not proceed as the MCExpr location can be useful.

If we keep MCExpr location, we can remove the MCFixup location or repurose the field for something else (perhaps more similar to GNU Assembler).

Thanks for the explanation. Let me summarize:

  1. Removing SMLoc from MCExpr would save a lot of memory for a stage1 build of LLVM...
  2. ... but we cannot remove it because it is essential to MCExpr.
  3. We could remove SMLoc from MCFixup because there is potential to save memory (do you have numbers?)

I don't have anything against removing SMLoc from MCFixup, but I found the changes in this MR useful for my own development process. I think we should get them in: if you end up removing SMLoc from MCFixup, the functionality provided by this change will likely still be there via MCExpr and the link it has with MCFixup.

@MaskRay
Copy link
Member

MaskRay commented Jun 7, 2025

I actually plan to remove SMLoc from MCFixup to reduce its size, as the SMLoc can typically be retrieved from MCExpr *MCFixup::Value.
I also considered removing SMLoc from MCExpr. llvm-compile-time-tracker.com/compare.php?from=193135c80019a01e08014b5727088b860a09f493&to=b8a413de2798260fabf6b5650fc22c803fa13831&stat=max-rss&linkStats=on
The saving is actually quite decent for a -g build, but some folks might need the MCExpr loc.

stage1-ReleaseLTO-g (link only):

Benchmark | Old | New
-- | -- | -- kimwitu++ | 248MiB | 242MiB (-2.52%) sqlite3 | 221MiB | 216MiB (-2.43%) consumer-typeset | 162MiB | 158MiB (-2.26%) Bullet | 208MiB | 204MiB (-1.81%) tramp3d-v4 | 624MiB | 616MiB (-1.32%) mafft | 122MiB | 123MiB (+1.08%) ClamAV | 230MiB | 224MiB (-2.61%) lencod | 277MiB | 270MiB (-2.63%) SPASS | 289MiB | 284MiB (-1.67%) 7zip | 467MiB | 454MiB (-2.84%) geomean | 256MiB | 251MiB (-1.91%)

I don't understand how SMLoc is saving size on these non-LLVM executable.

This page demonstrates that a stage1 build of LLVM with my commit applied (removing SMLoc from MCExpr), will use less memory when building these llvm-test-suite projects. The saving is quite high, but as mentioned, we might not proceed as the MCExpr location can be useful.
If we keep MCExpr location, we can remove the MCFixup location or repurose the field for something else (perhaps more similar to GNU Assembler).

Thanks for the explanation. Let me summarize:

  1. Removing SMLoc from MCExpr would save a lot of memory for a stage1 build of LLVM...
  2. ... but we cannot remove it because it is essential to MCExpr.
  3. We could remove SMLoc from MCFixup because there is potential to save memory (do you have numbers?)

I don't have anything against removing SMLoc from MCFixup, but I found the changes in this MR useful for my own development process. I think we should get them in: if you end up removing SMLoc from MCFixup, the functionality provided by this change will likely still be there via MCExpr and the link it has with MCFixup.

In your development process, can you use the SMLoc from MCFixup::Value instead?

I plan to do so and remove MCFixup::Loc soon.

MCFixup::Value being nullptr is a very uncommon special case (used by RISCVAsmBackend as a minor optimization).
Using rr, setting a watchpoing, and reverse-continue is much better than relying on the unreliable SMLoc...

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

Successfully merging this pull request may close these issues.

4 participants