[llvm] r295716 - [ARM] GlobalISel: Lower calls to void() functions
Diana Picus via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 03:49:51 PST 2017
Hi,
On 21 February 2017 at 12:34, Diana Picus via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: rovka
> Date: Tue Feb 21 05:33:59 2017
> New Revision: 295716
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295716&view=rev
> Log:
> [ARM] GlobalISel: Lower calls to void() functions
>
> For now, we hardcode a BLX instruction, and generate an ADJCALLSTACKDOWN/UP pair
> with amount 0.
>
> Modified:
> llvm/trunk/lib/Target/ARM/ARMCallLowering.cpp
> llvm/trunk/lib/Target/ARM/ARMCallLowering.h
> llvm/trunk/test/CodeGen/ARM/GlobalISel/arm-irtranslator.ll
>
> Modified: llvm/trunk/lib/Target/ARM/ARMCallLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMCallLowering.cpp?rev=295716&r1=295715&r2=295716&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMCallLowering.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMCallLowering.cpp Tue Feb 21 05:33:59 2017
> @@ -304,3 +304,38 @@ bool ARMCallLowering::lowerFormalArgumen
> AssignFn);
> return handleAssignments(MIRBuilder, ArgInfos, ArgHandler);
> }
> +
> +bool ARMCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
> + const MachineOperand &Callee,
> + const ArgInfo &OrigRet,
> + ArrayRef<ArgInfo> OrigArgs) const {
> + const MachineFunction &MF = MIRBuilder.getMF();
> + const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
> +
> + if (MF.getSubtarget<ARMSubtarget>().genLongCalls())
> + return false;
> +
> + // FIXME: Support calling functions with arguments.
> + if (OrigArgs.size() > 0)
> + return false;
> +
> + // FIXME: Support calling functions with return types.
> + if (!OrigRet.Ty->isVoidTy())
> + return false;
> +
> + MIRBuilder.buildInstr(ARM::ADJCALLSTACKDOWN)
> + .addImm(0)
> + .add(predOps(ARMCC::AL));
> +
> + MIRBuilder.buildInstr(ARM::BLX)
Is there any particular reason why we don't have a G_CALL and G_RET
operator? I think it would be nicer to generate a G_CALL here and let
the instruction selector decide which particular incantation to use.
What do you guys think?
> + .add(Callee)
> + // FIXME: Don't hardcode the calling conv here...
> + .addRegMask(TRI->getCallPreservedMask(MF, CallingConv::ARM_AAPCS));
On AArch64 we get the calling convention from the MIRBuilder, but IIUC
that's the calling convention of the caller, which may be different
from that of the call. Is that a bug?
> +
> + MIRBuilder.buildInstr(ARM::ADJCALLSTACKUP)
> + .addImm(0)
> + .addImm(0)
> + .add(predOps(ARMCC::AL));
> +
> + return true;
> +}
>
> Modified: llvm/trunk/lib/Target/ARM/ARMCallLowering.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMCallLowering.h?rev=295716&r1=295715&r2=295716&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMCallLowering.h (original)
> +++ llvm/trunk/lib/Target/ARM/ARMCallLowering.h Tue Feb 21 05:33:59 2017
> @@ -34,6 +34,10 @@ public:
> bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F,
> ArrayRef<unsigned> VRegs) const override;
>
> + bool lowerCall(MachineIRBuilder &MIRBuilder, const MachineOperand &Callee,
> + const ArgInfo &OrigRet,
> + ArrayRef<ArgInfo> OrigArgs) const override;
> +
> private:
> bool lowerReturnVal(MachineIRBuilder &MIRBuilder, const Value *Val,
> unsigned VReg, MachineInstrBuilder &Ret) const;
>
> Modified: llvm/trunk/test/CodeGen/ARM/GlobalISel/arm-irtranslator.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/GlobalISel/arm-irtranslator.ll?rev=295716&r1=295715&r2=295716&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/ARM/GlobalISel/arm-irtranslator.ll (original)
> +++ llvm/trunk/test/CodeGen/ARM/GlobalISel/arm-irtranslator.ll Tue Feb 21 05:33:59 2017
> @@ -335,3 +335,26 @@ entry:
> %v = fadd double %p0, %p1
> ret double %v
> }
> +
> +define arm_aapcscc void @test_indirect_call(void() *%fptr) {
> +; CHECK-LABEL: name: test_indirect_call
> +; CHECK: [[FPTR:%[0-9]+]](p0) = COPY %r0
> +; CHECK: ADJCALLSTACKDOWN 0, 14, _, implicit-def %sp, implicit %sp
> +; CHECK: BLX [[FPTR]](p0), csr_aapcs, implicit-def %lr, implicit %sp
> +; CHECK: ADJCALLSTACKUP 0, 0, 14, _, implicit-def %sp, implicit %sp
> +entry:
> + notail call arm_aapcscc void %fptr()
> + ret void
> +}
> +
> +declare arm_aapcscc void @call_target()
> +
> +define arm_aapcscc void @test_direct_call() {
> +; CHECK-LABEL: name: test_direct_call
> +; CHECK: ADJCALLSTACKDOWN 0, 14, _, implicit-def %sp, implicit %sp
> +; CHECK: BLX @call_target, csr_aapcs, implicit-def %lr, implicit %sp
> +; CHECK: ADJCALLSTACKUP 0, 0, 14, _, implicit-def %sp, implicit %sp
> +entry:
> + notail call arm_aapcscc void @call_target()
> + ret void
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list