@@ -126,9 +126,9 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
126126 setOperationAction (ISD::SMUL_LOHI, VT, Expand);
127127 setOperationAction (ISD::ROTR, VT, Expand);
128128 setOperationAction (ISD::ROTL, VT, Expand);
129- setOperationAction (ISD::SHL_PARTS, VT, Expand );
130- setOperationAction (ISD::SRL_PARTS, VT, Expand );
131- setOperationAction (ISD::SRA_PARTS, VT, Expand );
129+ setOperationAction (ISD::SHL_PARTS, VT, Custom );
130+ setOperationAction (ISD::SRL_PARTS, VT, Custom );
131+ setOperationAction (ISD::SRA_PARTS, VT, Custom );
132132 setOperationAction (ISD::CTPOP, VT, Expand);
133133 setOperationAction (ISD::CTTZ, VT, Expand);
134134 setOperationAction (ISD::CTLZ, VT, Expand);
@@ -363,6 +363,10 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
363363 case ISD::SDIV:
364364 case ISD::SREM:
365365 return LowerSDIVSREM (Op, DAG);
366+ case ISD::SHL_PARTS:
367+ case ISD::SRL_PARTS:
368+ case ISD::SRA_PARTS:
369+ return LowerShiftParts (Op, DAG);
366370 case ISD::DYNAMIC_STACKALLOC:
367371 return LowerDYNAMIC_STACKALLOC (Op, DAG);
368372 case ISD::ATOMIC_LOAD:
@@ -448,9 +452,6 @@ SDValue BPFTargetLowering::LowerFormalArguments(
448452 fail (DL, DAG, " stack arguments are not supported" );
449453 if (IsVarArg)
450454 fail (DL, DAG, " variadic functions are not supported" );
451- if (MF.getFunction ().hasStructRetAttr ())
452- fail (DL, DAG, " aggregate returns are not supported" );
453-
454455 return Chain;
455456}
456457
@@ -565,12 +566,13 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
565566 Callee = DAG.getTargetGlobalAddress (G->getGlobal (), CLI.DL , PtrVT,
566567 G->getOffset (), 0 );
567568 } else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee)) {
568- if (StringRef (E->getSymbol ()) != BPF_TRAP) {
569- Callee = DAG.getTargetExternalSymbol (E->getSymbol (), PtrVT, 0 );
570- fail (CLI.DL , DAG,
571- Twine (" A call to built-in function '" + StringRef (E->getSymbol ()) +
572- " ' is not supported." ));
573- }
569+ Callee = DAG.getTargetExternalSymbol (E->getSymbol (), PtrVT, 0 );
570+ StringRef Sym = E->getSymbol ();
571+ if (Sym != BPF_TRAP && Sym != " __multi3" && Sym != " __divti3" &&
572+ Sym != " __modti3" && Sym != " __udivti3" && Sym != " __umodti3" )
573+ fail (
574+ CLI.DL , DAG,
575+ Twine (" A call to built-in function '" + Sym + " ' is not supported." ));
574576 }
575577
576578 // Returns a chain & a flag for retval copy to use.
@@ -633,11 +635,6 @@ BPFTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
633635 // CCState - Info about the registers and stack slot.
634636 CCState CCInfo (CallConv, IsVarArg, MF, RVLocs, *DAG.getContext ());
635637
636- if (MF.getFunction ().getReturnType ()->isAggregateType ()) {
637- fail (DL, DAG, " aggregate returns are not supported" );
638- return DAG.getNode (Opc, DL, MVT::Other, Chain);
639- }
640-
641638 // Analize return values.
642639 CCInfo.AnalyzeReturn (Outs, getHasAlu32 () ? RetCC_BPF32 : RetCC_BPF64);
643640
@@ -677,13 +674,6 @@ SDValue BPFTargetLowering::LowerCallResult(
677674 SmallVector<CCValAssign, 16 > RVLocs;
678675 CCState CCInfo (CallConv, IsVarArg, MF, RVLocs, *DAG.getContext ());
679676
680- if (Ins.size () > 1 ) {
681- fail (DL, DAG, " only small returns supported" );
682- for (auto &In : Ins)
683- InVals.push_back (DAG.getConstant (0 , DL, In.VT ));
684- return DAG.getCopyFromReg (Chain, DL, 1 , Ins[0 ].VT , InGlue).getValue (1 );
685- }
686-
687677 CCInfo.AnalyzeCallResult (Ins, getHasAlu32 () ? RetCC_BPF32 : RetCC_BPF64);
688678
689679 // Copy all of the result registers out of their specified physreg.
@@ -718,6 +708,13 @@ SDValue BPFTargetLowering::LowerSDIVSREM(SDValue Op, SelectionDAG &DAG) const {
718708 return DAG.getUNDEF (Op->getValueType (0 ));
719709}
720710
711+ SDValue BPFTargetLowering::LowerShiftParts (SDValue Op,
712+ SelectionDAG &DAG) const {
713+ SDValue Lo, Hi;
714+ expandShiftParts (Op.getNode (), Lo, Hi, DAG);
715+ return DAG.getMergeValues ({Lo, Hi}, SDLoc (Op));
716+ }
717+
721718SDValue BPFTargetLowering::LowerDYNAMIC_STACKALLOC (SDValue Op,
722719 SelectionDAG &DAG) const {
723720 SDLoc DL (Op);
@@ -1196,3 +1193,12 @@ bool BPFTargetLowering::isLegalAddressingMode(const DataLayout &DL,
11961193
11971194 return true ;
11981195}
1196+
1197+ bool BPFTargetLowering::CanLowerReturn (
1198+ CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg,
1199+ const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
1200+ const Type *RetTy) const {
1201+ SmallVector<CCValAssign, 16 > RVLocs;
1202+ CCState CCInfo (CallConv, IsVarArg, MF, RVLocs, Context);
1203+ return CCInfo.CheckReturn (Outs, getHasAlu32 () ? RetCC_BPF32 : RetCC_BPF64);
1204+ }
0 commit comments