-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AArch64] Implement -fno-plt for SelectionDAG/GlobalISel #78890
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
Changes from 2 commits
549e4ea
3fb6535
d1e4789
de93d86
00873f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -144,9 +144,16 @@ bool CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &CB, | |||||||||
// Try looking through a bitcast from one function type to another. | ||||||||||
// Commonly happens with calls to objc_msgSend(). | ||||||||||
const Value *CalleeV = CB.getCalledOperand()->stripPointerCasts(); | ||||||||||
if (const Function *F = dyn_cast<Function>(CalleeV)) | ||||||||||
Info.Callee = MachineOperand::CreateGA(F, 0); | ||||||||||
else if (isa<GlobalIFunc>(CalleeV) || isa<GlobalAlias>(CalleeV)) { | ||||||||||
if (const Function *F = dyn_cast<Function>(CalleeV)) { | ||||||||||
if (F->hasFnAttribute(Attribute::NonLazyBind)) { | ||||||||||
auto Reg = | ||||||||||
MRI.createGenericVirtualRegister(getLLTForType(*F->getType(), DL)); | ||||||||||
MIRBuilder.buildGlobalValue(Reg, F); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After clang-format, this becomes
which is not shorter... In addition, the new code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the getLLTForType to a variable to make the line shorter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raw MRI.createGenericVirtualRegister calls should be purged whenever possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in de93d86 ! |
||||||||||
Info.Callee = MachineOperand::CreateReg(Reg, false); | ||||||||||
} else { | ||||||||||
Info.Callee = MachineOperand::CreateGA(F, 0); | ||||||||||
} | ||||||||||
} else if (isa<GlobalIFunc>(CalleeV) || isa<GlobalAlias>(CalleeV)) { | ||||||||||
// IR IFuncs and Aliases can't be forward declared (only defined), so the | ||||||||||
// callee must be in the same TU and therefore we can direct-call it without | ||||||||||
// worrying about it being out of range. | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1293,8 +1293,19 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, | |
!Subtarget.noBTIAtReturnTwice() && | ||
MF.getInfo<AArch64FunctionInfo>()->branchTargetEnforcement()) | ||
Opc = AArch64::BLR_BTI; | ||
else | ||
else { | ||
// For an intrinsic call (e.g. memset), use GOT if "RtLibUseGOT" (-fno-plt) | ||
// is set. | ||
if (Info.Callee.isSymbol() && F.getParent()->getRtLibUseGOT()) { | ||
auto Reg = | ||
MRI.createGenericVirtualRegister(getLLTForType(*F.getType(), DL)); | ||
auto MIB = MIRBuilder.buildInstr(TargetOpcode::G_GLOBAL_VALUE); | ||
DstOp(Reg).addDefToMIB(MRI, MIB); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use buildGlobalValue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is to handle library calls. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing overload then, should try to avoid raw buildInstr calls when possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you propose a new MachineIRBuilder API? This is a special use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. You lose CSE of these values by not going through the complete buildInstr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It seems that only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using raw buildInstr is a worse API. Please just add the new overload There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree. I think adding a function similar to I slightly simplified the code in the just-pushed commit. |
||
MIB.addExternalSymbol(Info.Callee.getSymbolName(), AArch64II::MO_GOT); | ||
Info.Callee = MachineOperand::CreateReg(Reg, false); | ||
} | ||
Opc = getCallOpcode(MF, Info.Callee.isReg(), false); | ||
} | ||
|
||
auto MIB = MIRBuilder.buildInstrNoInsert(Opc); | ||
unsigned CalleeOpNo = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,17 +201,27 @@ define dso_local void @rv_marker_3() personality ptr @__gxx_personality_v0 { | |
; GISEL-NEXT: bl _objc_object | ||
; GISEL-NEXT: Ltmp1: | ||
; GISEL-NEXT: ; %bb.1: ; %invoke.cont | ||
; GISEL-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload | ||
; GISEL-NEXT: Lloh0: | ||
; GISEL-NEXT: adrp x1, _objc_release@GOTPAGE | ||
; GISEL-NEXT: mov x0, x19 | ||
; GISEL-NEXT: Lloh1: | ||
; GISEL-NEXT: ldr x1, [x1, _objc_release@GOTPAGEOFF] | ||
; GISEL-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload | ||
; GISEL-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload | ||
; GISEL-NEXT: b _objc_release | ||
; GISEL-NEXT: br x1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fhahn, @TNorthover do these sound OK to you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ping:) @fhahn @TNorthover |
||
; GISEL-NEXT: LBB3_2: ; %lpad | ||
; GISEL-NEXT: Ltmp2: | ||
; GISEL-NEXT: Lloh2: | ||
; GISEL-NEXT: adrp x8, _objc_release@GOTPAGE | ||
; GISEL-NEXT: mov x20, x0 | ||
; GISEL-NEXT: mov x0, x19 | ||
; GISEL-NEXT: bl _objc_release | ||
; GISEL-NEXT: Lloh3: | ||
; GISEL-NEXT: ldr x8, [x8, _objc_release@GOTPAGEOFF] | ||
; GISEL-NEXT: blr x8 | ||
; GISEL-NEXT: mov x0, x20 | ||
; GISEL-NEXT: bl __Unwind_Resume | ||
; GISEL-NEXT: .loh AdrpLdrGot Lloh0, Lloh1 | ||
; GISEL-NEXT: .loh AdrpLdrGot Lloh2, Lloh3 | ||
; GISEL-NEXT: Lfunc_end0: | ||
; GISEL-NEXT: .cfi_endproc | ||
; GISEL-NEXT: .section __TEXT,__gcc_except_tab | ||
|
@@ -352,8 +362,12 @@ define dso_local void @rv_marker_4() personality ptr @__gxx_personality_v0 { | |
; GISEL-NEXT: bl _objc_object | ||
; GISEL-NEXT: Ltmp7: | ||
; GISEL-NEXT: ; %bb.2: ; %invoke.cont2 | ||
; GISEL-NEXT: Lloh4: | ||
; GISEL-NEXT: adrp x8, _objc_release@GOTPAGE | ||
; GISEL-NEXT: mov x0, x19 | ||
; GISEL-NEXT: bl _objc_release | ||
; GISEL-NEXT: Lloh5: | ||
; GISEL-NEXT: ldr x8, [x8, _objc_release@GOTPAGEOFF] | ||
; GISEL-NEXT: blr x8 | ||
; GISEL-NEXT: add x0, sp, #15 | ||
; GISEL-NEXT: bl __ZN1SD1Ev | ||
; GISEL-NEXT: ldp x29, x30, [sp, #32] ; 16-byte Folded Reload | ||
|
@@ -362,9 +376,13 @@ define dso_local void @rv_marker_4() personality ptr @__gxx_personality_v0 { | |
; GISEL-NEXT: ret | ||
; GISEL-NEXT: LBB4_3: ; %lpad1 | ||
; GISEL-NEXT: Ltmp8: | ||
; GISEL-NEXT: Lloh6: | ||
; GISEL-NEXT: adrp x8, _objc_release@GOTPAGE | ||
; GISEL-NEXT: mov x20, x0 | ||
; GISEL-NEXT: mov x0, x19 | ||
; GISEL-NEXT: bl _objc_release | ||
; GISEL-NEXT: Lloh7: | ||
; GISEL-NEXT: ldr x8, [x8, _objc_release@GOTPAGEOFF] | ||
; GISEL-NEXT: blr x8 | ||
; GISEL-NEXT: b LBB4_5 | ||
; GISEL-NEXT: LBB4_4: ; %lpad | ||
; GISEL-NEXT: Ltmp5: | ||
|
@@ -374,6 +392,8 @@ define dso_local void @rv_marker_4() personality ptr @__gxx_personality_v0 { | |
; GISEL-NEXT: bl __ZN1SD1Ev | ||
; GISEL-NEXT: mov x0, x20 | ||
; GISEL-NEXT: bl __Unwind_Resume | ||
; GISEL-NEXT: .loh AdrpLdrGot Lloh4, Lloh5 | ||
; GISEL-NEXT: .loh AdrpLdrGot Lloh6, Lloh7 | ||
; GISEL-NEXT: Lfunc_end1: | ||
; GISEL-NEXT: .cfi_endproc | ||
; GISEL-NEXT: .section __TEXT,__gcc_except_tab | ||
|
@@ -467,9 +487,9 @@ define dso_local ptr @rv_marker_5_indirect_call() { | |
; GISEL-NEXT: .cfi_offset w29, -16 | ||
; GISEL-NEXT: .cfi_offset w19, -24 | ||
; GISEL-NEXT: .cfi_offset w20, -32 | ||
; GISEL-NEXT: Lloh0: | ||
; GISEL-NEXT: Lloh8: | ||
; GISEL-NEXT: adrp x8, _fptr@PAGE | ||
; GISEL-NEXT: Lloh1: | ||
; GISEL-NEXT: Lloh9: | ||
; GISEL-NEXT: ldr x8, [x8, _fptr@PAGEOFF] | ||
; GISEL-NEXT: blr x8 | ||
; GISEL-NEXT: mov x29, x29 | ||
|
@@ -480,7 +500,7 @@ define dso_local ptr @rv_marker_5_indirect_call() { | |
; GISEL-NEXT: mov x0, x19 | ||
; GISEL-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload | ||
; GISEL-NEXT: ret | ||
; GISEL-NEXT: .loh AdrpLdr Lloh0, Lloh1 | ||
; GISEL-NEXT: .loh AdrpLdr Lloh8, Lloh9 | ||
entry: | ||
%0 = load ptr, ptr @fptr, align 8 | ||
%call = call ptr %0() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ] | ||
|
Uh oh!
There was an error while loading. Please reload this page.