This is an archive of the discontinued LLVM Phabricator instance.

Add a nop instruction if a section starts with landing pad for function splitter
ClosedPublic

Authored by iamarchit123 on Jul 19 2022, 5:04 PM.

Details

Summary

This change adds a nop instruction if section starts with landing pad. This change is like D73739 which avoids zero offset landing pad in basic block sections.

Detailed description:
The current machine functions splitter can create ˜sections which start with a landing pad themselves. This places landing pad at offset zero from LPStart.

	.section	.text.split.foo10,"ax",@progbits
foo10.cold:                             # %lpad
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception5
	.cfi_def_cfa %rsp, 16
.Ltmp11: <--- This is a Landing pad and also LP Start as it is start of this section
	movq	%rax, %rdi <--- first instruction is at offest 0 from LPStart
	callq	_Unwind_Resume@PLT

This will cause landing pad entries to become zero (.Ltmp11-foo10.cold)

.Lcst_begin4:
	.uleb128 .Ltmp9-.Lfunc_begin2           # >> Call Site 1 <<
	.uleb128 .Ltmp10-.Ltmp9                 #   Call between .Ltmp9 and .Ltmp10
	.uleb128 .Ltmp11-foo10.cold  <---This is zero           #     jumps to .Ltmp11
	.byte	3                               #   On action: 2
	.uleb128 .Ltmp10-.Lfunc_begin2          # >> Call Site 2 <<
	.uleb128 .Lfunc_end9-.Ltmp10            #   Call between .Ltmp10 and .Lfunc_end9
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.p2align	2

The C++ ABI somehow assumes that no landing pads point directly to LPStart (which works in the normal case since the function begin is never a landing pad), and uses LP.offset = 0 to specify no landing pad. This change adds a nop instruction at start of such sections so that such a case could be avoided. Output:

	.section	.text.split.foo10,"ax",@progbits
foo10.cold:                             # %lpad
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception5
	.cfi_def_cfa %rsp, 16
	nop <--- new instruction that is added
.Ltmp11:
	movq	%rax, %rdi
	callq	_Unwind_Resume@PLT

Diff Detail

Event Timeline

iamarchit123 created this revision.Jul 19 2022, 5:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 5:04 PM
iamarchit123 requested review of this revision.Jul 19 2022, 5:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 5:04 PM
iamarchit123 retitled this revision from Add a nop instruction if a section starts with landing pad. to Add a nop instruction if a section starts with landing pad for function splitter.Jul 19 2022, 5:11 PM
iamarchit123 edited the summary of this revision. (Show Details)
iamarchit123 added reviewers: modimo, snehasish.

This change avoids zero offset landing pad with machine function splitter

snehasish accepted this revision.Jul 19 2022, 6:25 PM

lgtm

llvm/test/CodeGen/X86/machine-function-splitter.ll
247

Is this an unterminated sentence or is it meant to be part of the prior line?

This revision is now accepted and ready to land.Jul 19 2022, 6:25 PM
iamarchit123 added inline comments.Jul 20 2022, 7:47 PM
llvm/test/CodeGen/X86/machine-function-splitter.ll
247

Part of the previous statement

iamarchit123 edited the summary of this revision. (Show Details)

Minor comment correction.

iamarchit123 marked an inline comment as done and an inline comment as not done.Jul 20 2022, 8:03 PM
modimo accepted this revision.Jul 21 2022, 4:20 PM

LGTM aside from minor nit.

llvm/test/CodeGen/X86/machine-function-splitter.ll
246

nit: s/begining/beginning/d

Correct minor spelling mistakes

iamarchit123 marked an inline comment as done.Jul 22 2022, 2:06 PM
rahmanl accepted this revision.Jul 22 2022, 2:22 PM
rahmanl added inline comments.
llvm/test/CodeGen/X86/machine-function-splitter.ll
246

Fix minor gramatical mistake.

iamarchit123 marked an inline comment as done.Jul 22 2022, 2:46 PM
This revision was landed with ongoing or failed builds.Jul 22 2022, 3:20 PM
This revision was automatically updated to reflect the committed changes.