[LoongArch] Report correct instruction size for PATCHABLE_* - #188228
Merged
Merged
Conversation
This is either the number of nops provided by patchable-function-entry or the size of the xray sled.
Member
|
@llvm/pr-subscribers-backend-loongarch Author: Nikita Popov (nikic) ChangesThis is either the number of nops provided by patchable-function-entry or the size of the xray sled. See for the corresponding lowering code.This came up while working on #187703. Full diff: https://github.com/llvm/llvm-project/pull/188228.diff 1 Files Affected:
diff --git a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
index 2b163d2d62d3a..4b5ce311f7d52 100644
--- a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@@ -263,6 +263,23 @@ unsigned LoongArchInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
if (NumBytes == 0)
NumBytes = 4;
break;
+ case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
+ const MachineFunction *MF = MI.getParent()->getParent();
+ const Function &F = MF->getFunction();
+ if (F.hasFnAttribute("patchable-function-entry")) {
+ unsigned Num;
+ if (F.getFnAttribute("patchable-function-entry")
+ .getValueAsString()
+ .getAsInteger(10, Num))
+ return 0;
+ return Num * 4;
+ }
+ [[fallthrough]];
+ }
+ case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
+ case TargetOpcode::PATCHABLE_TAIL_CALL:
+ // Size of xray sled (branch + 11 nops).
+ return 12 * 4;
}
return NumBytes;
}
|
heiher
approved these changes
Mar 26, 2026
heiher
left a comment
Member
There was a problem hiding this comment.
LGTM. It matches the lowering of these patchable nodes. Thanks!
Aadarsh-Keshri
pushed a commit
to Aadarsh-Keshri/llvm-project
that referenced
this pull request
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is either the number of nops provided by patchable-function-entry or the size of the xray sled.
See
llvm-project/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
Line 214 in 7d39664
This came up while working on #187703.