Skip to content

[MC][AsmPrinter] Introduce llvm_reg_offset pseudo cfi instruction. #125104

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

Closed
wants to merge 1 commit into from

Conversation

mgudim
Copy link
Contributor

@mgudim mgudim commented Jan 30, 2025

Some targets which have scalable vectors (AArch64, RISCV) emit cfi escape expression of the form "deref(FrameReg + Offset)". Now instead of explicitly building up the expression, we can just emit the llvm_reg_offset.

Also, we will need to handle such escape expressions in CFIInstrInserter. Without this pseudo, we would have to try to decode the escape expression inside the CFIInstrInserter. Now, when we have this pseudo, we can understand such escape expressions without decoding.

Expr.push_back(dwarf::DW_OP_consts);
Expr.append(Buffer, Buffer + encodeSLEB128(Offset, Buffer));
Expr.push_back((uint8_t)dwarf::DW_OP_bregx);
Expr.append(Buffer, Buffer + encodeULEB128(FrameReg, Buffer));
Copy link
Collaborator

@topperc topperc Jan 30, 2025

Choose a reason for hiding this comment

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

Is this using llvm's internal numbering for registers? That's not stable across releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's using DwarfEH register numbers like all other CFIs

Copy link
Contributor

Choose a reason for hiding this comment

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

I see other code does stuff like this:

if (!IsEH)
  Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);

Do we need to do something similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find a good way to pass IsEH. However currently, when we are emitting the same escape elsewhere we don't care about IsEH, so if in this patch if we ignore IsEH things should work the way they are now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need MRI->getDwarfRegNumFromDwarfEHRegNum(FrameReg);`?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't think so

Copy link

github-actions bot commented Feb 5, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mgudim mgudim force-pushed the cfi_reg_offset branch 2 times, most recently from 3405801 to 6dd7dd8 Compare February 6, 2025 17:59
#CHECK-LABEL: func:
#CHECK: .cfi_startproc
#CHECK: .cfi_escape 0x10, 0x01, 0x06, 0x11, 0x56, 0x92, 0x02, 0x00, 0x22
#COM: CHECK: ret
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these COM? If not needed should they be removed?

@@ -265,6 +265,8 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
case MCCFIInstruction::OpLabel:
case MCCFIInstruction::OpValOffset:
break;
case MCCFIInstruction::OpLLVMRegOffset:
llvm_unreachable("Can't handle llvm_reg_offset yet!");
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the impact of not handling this yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing emits OpLLVMRegOffset yet, I just added this to avoid a warning.

@michaelmaitland
Copy link
Contributor

Can you please post the shrink wrapping PRs that stack on this one? It is difficult to understand why this change is needed without the additional context.

@mgudim
Copy link
Contributor Author

mgudim commented Mar 18, 2025

Can you please post the shrink wrapping PRs that stack on this one? It is difficult to understand why this change is needed without the additional context.

@michaelmaitland
see #131845
In RISCVFrameLowering.cpp : 849 we emit cfi_reg_offset. These need to be handled by CFIInstrInserter in lines 269 (also see line 471)

Some targets which have scalable vectors (AArch64, RISCV) emit cfi
escape expression of the form "deref(FrameReg + Offset)". Now instead of
explicitly building up the expression, we can just emit the
llvm_reg_offset.

Also, we will need to handle such escape expressions in CFIInstrInserter. Without this pseudo, we would have to try to decode the escape expression inside the CFIInstrInserter. Now, when we have this pseudo, we can understand such escape expressions without decoding.
@mgudim mgudim closed this May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants