From: Yonghong Song Date: Fri, 23 Feb 2018 23:49:23 +0000 (+0000) Subject: bpf: New calling convention for 32-bit subregisters X-Git-Tag: llvmorg-7.0.0-rc1~12091 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07a7a417537ee0c8021672823c78c4dfa10dc918;p=platform%2Fupstream%2Fllvm.git bpf: New calling convention for 32-bit subregisters This patch add new calling conventions to allow GPR32RegClass as valid register class for arguments and return types. New calling convention will only be choosen when -mattr=+alu32 specified. Signed-off-by: Jiong Wang Reviewed-by: Yonghong Song llvm-svn: 325983 --- diff --git a/llvm/lib/Target/BPF/BPFCallingConv.td b/llvm/lib/Target/BPF/BPFCallingConv.td index 8cec6fa..637f975 100644 --- a/llvm/lib/Target/BPF/BPFCallingConv.td +++ b/llvm/lib/Target/BPF/BPFCallingConv.td @@ -26,4 +26,24 @@ def CC_BPF64 : CallingConv<[ CCAssignToStack<8, 8> ]>; +// Return-value convention when -mattr=+alu32 enabled +def RetCC_BPF32 : CallingConv<[ + CCIfType<[i32], CCAssignToRegWithShadow<[W0], [R0]>>, + CCIfType<[i64], CCAssignToRegWithShadow<[R0], [W0]>> +]>; + +// Calling convention when -mattr=+alu32 enabled +def CC_BPF32 : CallingConv<[ + // Promote i8/i16/i32 args to i64 + CCIfType<[i32], CCAssignToRegWithShadow<[W1, W2, W3, W4, W5], + [R1, R2, R3, R4, R5]>>, + + // All arguments get passed in integer registers if there is space. + CCIfType<[i64], CCAssignToRegWithShadow<[R1, R2, R3, R4, R5], + [W1, W2, W3, W4, W5]>>, + + // Could be assigned to the stack in 8-byte aligned units, but unsupported + CCAssignToStack<8, 8> +]>; + def CSR : CalleeSavedRegs<(add R6, R7, R8, R9, R10)>; diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp index 2966cf7..f9de9ff 100644 --- a/llvm/lib/Target/BPF/BPFISelLowering.cpp +++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp @@ -132,6 +132,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM, MaxStoresPerMemmove = MaxStoresPerMemmoveOptSize = 128; // CPU/Feature control + HasAlu32 = STI.getHasAlu32(); HasJmpExt = STI.getHasJmpExt(); } @@ -189,26 +190,29 @@ SDValue BPFTargetLowering::LowerFormalArguments( // Assign locations to all of the incoming arguments. SmallVector ArgLocs; CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext()); - CCInfo.AnalyzeFormalArguments(Ins, CC_BPF64); + CCInfo.AnalyzeFormalArguments(Ins, getHasAlu32() ? CC_BPF32 : CC_BPF64); for (auto &VA : ArgLocs) { if (VA.isRegLoc()) { // Arguments passed in registers EVT RegVT = VA.getLocVT(); - switch (RegVT.getSimpleVT().SimpleTy) { + MVT::SimpleValueType SimpleTy = RegVT.getSimpleVT().SimpleTy; + switch (SimpleTy) { default: { errs() << "LowerFormalArguments Unhandled argument type: " << RegVT.getEVTString() << '\n'; llvm_unreachable(0); } + case MVT::i32: case MVT::i64: - unsigned VReg = RegInfo.createVirtualRegister(&BPF::GPRRegClass); + unsigned VReg = RegInfo.createVirtualRegister(SimpleTy == MVT::i64 ? + &BPF::GPRRegClass : + &BPF::GPR32RegClass); RegInfo.addLiveIn(VA.getLocReg(), VReg); SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, VReg, RegVT); - // If this is an 8/16/32-bit value, it is really passed promoted to 64 - // bits. Insert an assert[sz]ext to capture this, then truncate to the - // right size. + // If this is an value that has been promoted to wider types, insert an + // assert[sz]ext to capture this, then truncate to the right size. if (VA.getLocInfo() == CCValAssign::SExt) ArgValue = DAG.getNode(ISD::AssertSext, DL, RegVT, ArgValue, DAG.getValueType(VA.getValVT())); @@ -220,6 +224,8 @@ SDValue BPFTargetLowering::LowerFormalArguments( ArgValue = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), ArgValue); InVals.push_back(ArgValue); + + break; } } else { fail(DL, DAG, "defined with too many args"); @@ -264,7 +270,7 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVector ArgLocs; CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext()); - CCInfo.AnalyzeCallOperands(Outs, CC_BPF64); + CCInfo.AnalyzeCallOperands(Outs, getHasAlu32() ? CC_BPF32 : CC_BPF64); unsigned NumBytes = CCInfo.getNextStackOffset(); @@ -388,7 +394,7 @@ BPFTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, } // Analize return values. - CCInfo.AnalyzeReturn(Outs, RetCC_BPF64); + CCInfo.AnalyzeReturn(Outs, getHasAlu32() ? RetCC_BPF32 : RetCC_BPF64); SDValue Flag; SmallVector RetOps(1, Chain); @@ -432,7 +438,7 @@ SDValue BPFTargetLowering::LowerCallResult( return DAG.getCopyFromReg(Chain, DL, 1, Ins[0].VT, InFlag).getValue(1); } - CCInfo.AnalyzeCallResult(Ins, RetCC_BPF64); + CCInfo.AnalyzeCallResult(Ins, getHasAlu32() ? RetCC_BPF32 : RetCC_BPF64); // Copy all of the result registers out of their specified physreg. for (auto &Val : RVLocs) { diff --git a/llvm/lib/Target/BPF/BPFISelLowering.h b/llvm/lib/Target/BPF/BPFISelLowering.h index 6ca2594..399a9a5 100644 --- a/llvm/lib/Target/BPF/BPFISelLowering.h +++ b/llvm/lib/Target/BPF/BPFISelLowering.h @@ -54,10 +54,12 @@ public: EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override; + bool getHasAlu32() const { return HasAlu32; } bool getHasJmpExt() const { return HasJmpExt; } private: // Control Instruction Selection Features + bool HasAlu32; bool HasJmpExt; SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;