diff options
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 246 | 
1 files changed, 139 insertions, 107 deletions
| diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 1aa8df29af3b..5f6b6010cae2 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -157,31 +157,36 @@ static cl::opt<unsigned> SwitchPeelThreshold(  // store [4096 x i8] %data, [4096 x i8]* %buffer  static const unsigned MaxParallelChains = 64; -// True if the Value passed requires ABI mangling as it is a parameter to a -// function or a return value from a function which is not an intrinsic. -static bool isABIRegCopy(const Value *V) { -  const bool IsRetInst = V && isa<ReturnInst>(V); -  const bool IsCallInst = V && isa<CallInst>(V); -  const bool IsInLineAsm = -      IsCallInst && static_cast<const CallInst *>(V)->isInlineAsm(); -  const bool IsIndirectFunctionCall = -      IsCallInst && !IsInLineAsm && -      !static_cast<const CallInst *>(V)->getCalledFunction(); -  // It is possible that the call instruction is an inline asm statement or an -  // indirect function call in which case the return value of -  // getCalledFunction() would be nullptr. -  const bool IsInstrinsicCall = -      IsCallInst && !IsInLineAsm && !IsIndirectFunctionCall && -      static_cast<const CallInst *>(V)->getCalledFunction()->getIntrinsicID() != -          Intrinsic::not_intrinsic; - -  return IsRetInst || (IsCallInst && (!IsInLineAsm && !IsInstrinsicCall)); +// Return the calling convention if the Value passed requires ABI mangling as it +// is a parameter to a function or a return value from a function which is not +// an intrinsic. +static Optional<CallingConv::ID> getABIRegCopyCC(const Value *V) { +  if (auto *R = dyn_cast<ReturnInst>(V)) +    return R->getParent()->getParent()->getCallingConv(); + +  if (auto *CI = dyn_cast<CallInst>(V)) { +    const bool IsInlineAsm = CI->isInlineAsm(); +    const bool IsIndirectFunctionCall = +        !IsInlineAsm && !CI->getCalledFunction(); + +    // It is possible that the call instruction is an inline asm statement or an +    // indirect function call in which case the return value of +    // getCalledFunction() would be nullptr. +    const bool IsInstrinsicCall = +        !IsInlineAsm && !IsIndirectFunctionCall && +        CI->getCalledFunction()->getIntrinsicID() != Intrinsic::not_intrinsic; + +    if (!IsInlineAsm && !IsInstrinsicCall) +      return CI->getCallingConv(); +  } + +  return None;  }  static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,                                        const SDValue *Parts, unsigned NumParts,                                        MVT PartVT, EVT ValueVT, const Value *V, -                                      bool IsABIRegCopy); +                                      Optional<CallingConv::ID> CC);  /// getCopyFromParts - Create a value that contains the specified legal parts  /// combined into the value they represent.  If the parts combine to a type @@ -191,11 +196,11 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,  static SDValue getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL,                                  const SDValue *Parts, unsigned NumParts,                                  MVT PartVT, EVT ValueVT, const Value *V, -                                Optional<ISD::NodeType> AssertOp = None, -                                bool IsABIRegCopy = false) { +                                Optional<CallingConv::ID> CC = None, +                                Optional<ISD::NodeType> AssertOp = None) {    if (ValueVT.isVector()) -    return getCopyFromPartsVector(DAG, DL, Parts, NumParts, -                                  PartVT, ValueVT, V, IsABIRegCopy); +    return getCopyFromPartsVector(DAG, DL, Parts, NumParts, PartVT, ValueVT, V, +                                  CC);    assert(NumParts > 0 && "No parts to assemble!");    const TargetLowering &TLI = DAG.getTargetLoweringInfo(); @@ -236,8 +241,8 @@ static SDValue getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL,          // Assemble the trailing non-power-of-2 part.          unsigned OddParts = NumParts - RoundParts;          EVT OddVT = EVT::getIntegerVT(*DAG.getContext(), OddParts * PartBits); -        Hi = getCopyFromParts(DAG, DL, -                              Parts + RoundParts, OddParts, PartVT, OddVT, V); +        Hi = getCopyFromParts(DAG, DL, Parts + RoundParts, OddParts, PartVT, +                              OddVT, V, CC);          // Combine the round and odd parts.          Lo = Val; @@ -267,7 +272,7 @@ static SDValue getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL,        assert(ValueVT.isFloatingPoint() && PartVT.isInteger() &&               !PartVT.isVector() && "Unexpected split");        EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), ValueVT.getSizeInBits()); -      Val = getCopyFromParts(DAG, DL, Parts, NumParts, PartVT, IntVT, V); +      Val = getCopyFromParts(DAG, DL, Parts, NumParts, PartVT, IntVT, V, CC);      }    } @@ -340,9 +345,11 @@ static void diagnosePossiblyInvalidConstraint(LLVMContext &Ctx, const Value *V,  static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,                                        const SDValue *Parts, unsigned NumParts,                                        MVT PartVT, EVT ValueVT, const Value *V, -                                      bool IsABIRegCopy) { +                                      Optional<CallingConv::ID> CallConv) {    assert(ValueVT.isVector() && "Not a vector value");    assert(NumParts > 0 && "No parts to assemble!"); +  const bool IsABIRegCopy = CallConv.hasValue(); +    const TargetLowering &TLI = DAG.getTargetLoweringInfo();    SDValue Val = Parts[0]; @@ -355,8 +362,8 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,      if (IsABIRegCopy) {        NumRegs = TLI.getVectorTypeBreakdownForCallingConv( -          *DAG.getContext(), ValueVT, IntermediateVT, NumIntermediates, -          RegisterVT); +          *DAG.getContext(), CallConv.getValue(), ValueVT, IntermediateVT, +          NumIntermediates, RegisterVT);      } else {        NumRegs =            TLI.getVectorTypeBreakdown(*DAG.getContext(), ValueVT, IntermediateVT, @@ -470,7 +477,8 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,  static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &dl,                                   SDValue Val, SDValue *Parts, unsigned NumParts, -                                 MVT PartVT, const Value *V, bool IsABIRegCopy); +                                 MVT PartVT, const Value *V, +                                 Optional<CallingConv::ID> CallConv);  /// getCopyToParts - Create a series of nodes that contain the specified value  /// split into legal parts.  If the parts contain more bits than Val, then, for @@ -478,14 +486,14 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &dl,  static void getCopyToParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val,                             SDValue *Parts, unsigned NumParts, MVT PartVT,                             const Value *V, -                           ISD::NodeType ExtendKind = ISD::ANY_EXTEND, -                           bool IsABIRegCopy = false) { +                           Optional<CallingConv::ID> CallConv = None, +                           ISD::NodeType ExtendKind = ISD::ANY_EXTEND) {    EVT ValueVT = Val.getValueType();    // Handle the vector case separately.    if (ValueVT.isVector())      return getCopyToPartsVector(DAG, DL, Val, Parts, NumParts, PartVT, V, -                                IsABIRegCopy); +                                CallConv);    unsigned PartBits = PartVT.getSizeInBits();    unsigned OrigNumParts = NumParts; @@ -564,7 +572,8 @@ static void getCopyToParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val,      unsigned OddParts = NumParts - RoundParts;      SDValue OddVal = DAG.getNode(ISD::SRL, DL, ValueVT, Val,                                   DAG.getIntPtrConstant(RoundBits, DL)); -    getCopyToParts(DAG, DL, OddVal, Parts + RoundParts, OddParts, PartVT, V); +    getCopyToParts(DAG, DL, OddVal, Parts + RoundParts, OddParts, PartVT, V, +                   CallConv);      if (DAG.getDataLayout().isBigEndian())        // The odd parts were reversed by getCopyToParts - unreverse them. @@ -605,16 +614,16 @@ static void getCopyToParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val,      std::reverse(Parts, Parts + OrigNumParts);  } -  /// getCopyToPartsVector - Create a series of nodes that contain the specified  /// value split into legal parts.  static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,                                   SDValue Val, SDValue *Parts, unsigned NumParts,                                   MVT PartVT, const Value *V, -                                 bool IsABIRegCopy) { +                                 Optional<CallingConv::ID> CallConv) {    EVT ValueVT = Val.getValueType();    assert(ValueVT.isVector() && "Not a vector");    const TargetLowering &TLI = DAG.getTargetLoweringInfo(); +  const bool IsABIRegCopy = CallConv.hasValue();    if (NumParts == 1) {      EVT PartEVT = PartVT; @@ -679,8 +688,8 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,    unsigned NumRegs;    if (IsABIRegCopy) {      NumRegs = TLI.getVectorTypeBreakdownForCallingConv( -        *DAG.getContext(), ValueVT, IntermediateVT, NumIntermediates, -        RegisterVT); +        *DAG.getContext(), CallConv.getValue(), ValueVT, IntermediateVT, +        NumIntermediates, RegisterVT);    } else {      NumRegs =          TLI.getVectorTypeBreakdown(*DAG.getContext(), ValueVT, IntermediateVT, @@ -720,7 +729,7 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,      // If the register was not expanded, promote or copy the value,      // as appropriate.      for (unsigned i = 0; i != NumParts; ++i) -      getCopyToParts(DAG, DL, Ops[i], &Parts[i], 1, PartVT, V); +      getCopyToParts(DAG, DL, Ops[i], &Parts[i], 1, PartVT, V, CallConv);    } else if (NumParts > 0) {      // If the intermediate type was expanded, split each the value into      // legal parts. @@ -729,29 +738,32 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,             "Must expand into a divisible number of parts!");      unsigned Factor = NumParts / NumIntermediates;      for (unsigned i = 0; i != NumIntermediates; ++i) -      getCopyToParts(DAG, DL, Ops[i], &Parts[i*Factor], Factor, PartVT, V); +      getCopyToParts(DAG, DL, Ops[i], &Parts[i * Factor], Factor, PartVT, V, +                     CallConv);    }  }  RegsForValue::RegsForValue(const SmallVector<unsigned, 4> ®s, MVT regvt, -                           EVT valuevt, bool IsABIMangledValue) +                           EVT valuevt, Optional<CallingConv::ID> CC)      : ValueVTs(1, valuevt), RegVTs(1, regvt), Regs(regs), -      RegCount(1, regs.size()), IsABIMangled(IsABIMangledValue) {} +      RegCount(1, regs.size()), CallConv(CC) {}  RegsForValue::RegsForValue(LLVMContext &Context, const TargetLowering &TLI,                             const DataLayout &DL, unsigned Reg, Type *Ty, -                           bool IsABIMangledValue) { +                           Optional<CallingConv::ID> CC) {    ComputeValueVTs(TLI, DL, Ty, ValueVTs); -  IsABIMangled = IsABIMangledValue; +  CallConv = CC;    for (EVT ValueVT : ValueVTs) { -    unsigned NumRegs = IsABIMangledValue -                           ? TLI.getNumRegistersForCallingConv(Context, ValueVT) -                           : TLI.getNumRegisters(Context, ValueVT); -    MVT RegisterVT = IsABIMangledValue -                         ? TLI.getRegisterTypeForCallingConv(Context, ValueVT) -                         : TLI.getRegisterType(Context, ValueVT); +    unsigned NumRegs = +        isABIMangled() +            ? TLI.getNumRegistersForCallingConv(Context, CC.getValue(), ValueVT) +            : TLI.getNumRegisters(Context, ValueVT); +    MVT RegisterVT = +        isABIMangled() +            ? TLI.getRegisterTypeForCallingConv(Context, CC.getValue(), ValueVT) +            : TLI.getRegisterType(Context, ValueVT);      for (unsigned i = 0; i != NumRegs; ++i)        Regs.push_back(Reg + i);      RegVTs.push_back(RegisterVT); @@ -777,9 +789,10 @@ SDValue RegsForValue::getCopyFromRegs(SelectionDAG &DAG,      // Copy the legal parts from the registers.      EVT ValueVT = ValueVTs[Value];      unsigned NumRegs = RegCount[Value]; -    MVT RegisterVT = IsABIMangled -      ? TLI.getRegisterTypeForCallingConv(*DAG.getContext(), RegVTs[Value]) -      : RegVTs[Value]; +    MVT RegisterVT = isABIMangled() ? TLI.getRegisterTypeForCallingConv( +                                          *DAG.getContext(), +                                          CallConv.getValue(), RegVTs[Value]) +                                    : RegVTs[Value];      Parts.resize(NumRegs);      for (unsigned i = 0; i != NumRegs; ++i) { @@ -837,8 +850,8 @@ SDValue RegsForValue::getCopyFromRegs(SelectionDAG &DAG,                               RegisterVT, P, DAG.getValueType(FromVT));      } -    Values[Value] = getCopyFromParts(DAG, dl, Parts.begin(), -                                     NumRegs, RegisterVT, ValueVT, V); +    Values[Value] = getCopyFromParts(DAG, dl, Parts.begin(), NumRegs, +                                     RegisterVT, ValueVT, V, CallConv);      Part += NumRegs;      Parts.clear();    } @@ -859,15 +872,16 @@ void RegsForValue::getCopyToRegs(SDValue Val, SelectionDAG &DAG,    for (unsigned Value = 0, Part = 0, e = ValueVTs.size(); Value != e; ++Value) {      unsigned NumParts = RegCount[Value]; -    MVT RegisterVT = IsABIMangled -      ? TLI.getRegisterTypeForCallingConv(*DAG.getContext(), RegVTs[Value]) -      : RegVTs[Value]; +    MVT RegisterVT = isABIMangled() ? TLI.getRegisterTypeForCallingConv( +                                          *DAG.getContext(), +                                          CallConv.getValue(), RegVTs[Value]) +                                    : RegVTs[Value];      if (ExtendKind == ISD::ANY_EXTEND && TLI.isZExtFree(Val, RegisterVT))        ExtendKind = ISD::ZERO_EXTEND; -    getCopyToParts(DAG, dl, Val.getValue(Val.getResNo() + Value), -                   &Parts[Part], NumParts, RegisterVT, V, ExtendKind); +    getCopyToParts(DAG, dl, Val.getValue(Val.getResNo() + Value), &Parts[Part], +                   NumParts, RegisterVT, V, CallConv, ExtendKind);      Part += NumParts;    } @@ -1164,7 +1178,7 @@ SDValue SelectionDAGBuilder::getCopyFromRegs(const Value *V, Type *Ty) {      unsigned InReg = It->second;      RegsForValue RFV(*DAG.getContext(), DAG.getTargetLoweringInfo(), -                     DAG.getDataLayout(), InReg, Ty, isABIRegCopy(V)); +                     DAG.getDataLayout(), InReg, Ty, getABIRegCopyCC(V));      SDValue Chain = DAG.getEntryNode();      Result = RFV.getCopyFromRegs(DAG, FuncInfo, getCurSDLoc(), Chain, nullptr,                                   V); @@ -1355,7 +1369,7 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {      unsigned InReg = FuncInfo.InitializeRegForValue(Inst);      RegsForValue RFV(*DAG.getContext(), TLI, DAG.getDataLayout(), InReg, -                     Inst->getType(), isABIRegCopy(V)); +                     Inst->getType(), getABIRegCopyCC(V));      SDValue Chain = DAG.getEntryNode();      return RFV.getCopyFromRegs(DAG, FuncInfo, getCurSDLoc(), Chain, nullptr, V);    } @@ -1589,12 +1603,14 @@ void SelectionDAGBuilder::visitRet(const ReturnInst &I) {          if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger())            VT = TLI.getTypeForExtReturn(Context, VT, ExtendKind); -        unsigned NumParts = TLI.getNumRegistersForCallingConv(Context, VT); -        MVT PartVT = TLI.getRegisterTypeForCallingConv(Context, VT); +        CallingConv::ID CC = F->getCallingConv(); + +        unsigned NumParts = TLI.getNumRegistersForCallingConv(Context, CC, VT); +        MVT PartVT = TLI.getRegisterTypeForCallingConv(Context, CC, VT);          SmallVector<SDValue, 4> Parts(NumParts);          getCopyToParts(DAG, getCurSDLoc(),                         SDValue(RetOp.getNode(), RetOp.getResNo() + j), -                       &Parts[0], NumParts, PartVT, &I, ExtendKind, true); +                       &Parts[0], NumParts, PartVT, &I, CC, ExtendKind);          // 'inreg' on function refers to return value          ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy(); @@ -4929,7 +4945,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(      if (VMI != FuncInfo.ValueMap.end()) {        const auto &TLI = DAG.getTargetLoweringInfo();        RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), VMI->second, -                       V->getType(), isABIRegCopy(V)); +                       V->getType(), getABIRegCopyCC(V));        if (RFV.occupiesMultipleRegs()) {          unsigned Offset = 0;          for (auto RegAndSize : RFV.getRegsAndSizes()) { @@ -4971,7 +4987,7 @@ SDDbgValue *SelectionDAGBuilder::getDbgValue(SDValue N,                                               unsigned DbgSDNodeOrder) {    if (auto *FISDN = dyn_cast<FrameIndexSDNode>(N.getNode())) {      // Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can describe -    // stack slot locations.  +    // stack slot locations.      //      // Consider "int x = 0; int *px = &x;". There are two kinds of interesting      // debug values here after optimization: @@ -5288,7 +5304,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {          // The PHI node may be split up into several MI PHI nodes (in          // FunctionLoweringInfo::set).          RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), Reg, -                         V->getType(), false); +                         V->getType(), None);          if (RFV.occupiesMultipleRegs()) {            unsigned Offset = 0;            unsigned BitsToDescribe = 0; @@ -7182,10 +7198,11 @@ static SDValue getAddressForMemoryInput(SDValue Chain, const SDLoc &Location,  /// uses features that we can't model on machineinstrs, we have SDISel do the  /// allocation.  This produces generally horrible, but correct, code.  /// -///   OpInfo describes the operand. +///   OpInfo describes the operand +///   RefOpInfo describes the matching operand if any, the operand otherwise  static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI, -                                 const SDLoc &DL, -                                 SDISelAsmOperandInfo &OpInfo) { +                                 const SDLoc &DL, SDISelAsmOperandInfo &OpInfo, +                                 SDISelAsmOperandInfo &RefOpInfo) {    LLVMContext &Context = *DAG.getContext();    MachineFunction &MF = DAG.getMachineFunction(); @@ -7195,8 +7212,8 @@ static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI,    // If this is a constraint for a single physreg, or a constraint for a    // register class, find it.    std::pair<unsigned, const TargetRegisterClass *> PhysReg = -      TLI.getRegForInlineAsmConstraint(&TRI, OpInfo.ConstraintCode, -                                       OpInfo.ConstraintVT); +      TLI.getRegForInlineAsmConstraint(&TRI, RefOpInfo.ConstraintCode, +                                       RefOpInfo.ConstraintVT);    unsigned NumRegs = 1;    if (OpInfo.ConstraintVT != MVT::Other) { @@ -7238,6 +7255,11 @@ static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI,      NumRegs = TLI.getNumRegisters(Context, OpInfo.ConstraintVT);    } +  // No need to allocate a matching input constraint since the constraint it's +  // matching to has already been allocated. +  if (OpInfo.isMatchingInputConstraint()) +    return; +    MVT RegVT;    EVT ValueVT = OpInfo.ConstraintVT; @@ -7486,19 +7508,27 @@ void SelectionDAGBuilder::visitInlineAsm(ImmutableCallSite CS) {      // If this constraint is for a specific register, allocate it before      // anything else. -    if (OpInfo.ConstraintType == TargetLowering::C_Register) -      GetRegistersForValue(DAG, TLI, getCurSDLoc(), OpInfo); +    SDISelAsmOperandInfo &RefOpInfo = +        OpInfo.isMatchingInputConstraint() +            ? ConstraintOperands[OpInfo.getMatchedOperand()] +            : ConstraintOperands[i]; +    if (RefOpInfo.ConstraintType == TargetLowering::C_Register) +      GetRegistersForValue(DAG, TLI, getCurSDLoc(), OpInfo, RefOpInfo);    }    // Third pass - Loop over all of the operands, assigning virtual or physregs    // to register class operands.    for (unsigned i = 0, e = ConstraintOperands.size(); i != e; ++i) {      SDISelAsmOperandInfo &OpInfo = ConstraintOperands[i]; +    SDISelAsmOperandInfo &RefOpInfo = +        OpInfo.isMatchingInputConstraint() +            ? ConstraintOperands[OpInfo.getMatchedOperand()] +            : ConstraintOperands[i];      // C_Register operands have already been allocated, Other/Memory don't need      // to be. -    if (OpInfo.ConstraintType == TargetLowering::C_RegisterClass) -      GetRegistersForValue(DAG, TLI, getCurSDLoc(), OpInfo); +    if (RefOpInfo.ConstraintType == TargetLowering::C_RegisterClass) +      GetRegistersForValue(DAG, TLI, getCurSDLoc(), OpInfo, RefOpInfo);    }    // AsmNodeOperands - The operands for the ISD::INLINEASM node. @@ -8289,7 +8319,7 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {    }    SmallVector<ISD::OutputArg, 4> Outs; -  GetReturnInfo(CLI.RetTy, getReturnAttrs(CLI), Outs, *this, DL); +  GetReturnInfo(CLI.CallConv, CLI.RetTy, getReturnAttrs(CLI), Outs, *this, DL);    bool CanLowerReturn =        this->CanLowerReturn(CLI.CallConv, CLI.DAG.getMachineFunction(), @@ -8305,7 +8335,8 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {      unsigned Align = DL.getPrefTypeAlignment(CLI.RetTy);      MachineFunction &MF = CLI.DAG.getMachineFunction();      DemoteStackIdx = MF.getFrameInfo().CreateStackObject(TySize, Align, false); -    Type *StackSlotPtrType = PointerType::getUnqual(CLI.RetTy); +    Type *StackSlotPtrType = PointerType::get(CLI.RetTy, +                                              DL.getAllocaAddrSpace());      DemoteStackSlot = CLI.DAG.getFrameIndex(DemoteStackIdx, getFrameIndexTy(DL));      ArgListEntry Entry; @@ -8331,10 +8362,10 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {    } else {      for (unsigned I = 0, E = RetTys.size(); I != E; ++I) {        EVT VT = RetTys[I]; -      MVT RegisterVT = -          getRegisterTypeForCallingConv(CLI.RetTy->getContext(), VT); -      unsigned NumRegs = -          getNumRegistersForCallingConv(CLI.RetTy->getContext(), VT); +      MVT RegisterVT = getRegisterTypeForCallingConv(CLI.RetTy->getContext(), +                                                     CLI.CallConv, VT); +      unsigned NumRegs = getNumRegistersForCallingConv(CLI.RetTy->getContext(), +                                                       CLI.CallConv, VT);        for (unsigned i = 0; i != NumRegs; ++i) {          ISD::InputArg MyFlags;          MyFlags.VT = RegisterVT; @@ -8443,9 +8474,10 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {          Flags.setInConsecutiveRegs();        Flags.setOrigAlign(OriginalAlignment); -      MVT PartVT = getRegisterTypeForCallingConv(CLI.RetTy->getContext(), VT); -      unsigned NumParts = -          getNumRegistersForCallingConv(CLI.RetTy->getContext(), VT); +      MVT PartVT = getRegisterTypeForCallingConv(CLI.RetTy->getContext(), +                                                 CLI.CallConv, VT); +      unsigned NumParts = getNumRegistersForCallingConv(CLI.RetTy->getContext(), +                                                        CLI.CallConv, VT);        SmallVector<SDValue, 4> Parts(NumParts);        ISD::NodeType ExtendKind = ISD::ANY_EXTEND; @@ -8477,7 +8509,7 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {        }        getCopyToParts(CLI.DAG, CLI.DL, Op, &Parts[0], NumParts, PartVT, -                     CLI.CS.getInstruction(), ExtendKind, true); +                     CLI.CS.getInstruction(), CLI.CallConv, ExtendKind);        for (unsigned j = 0; j != NumParts; ++j) {          // if it isn't first piece, alignment must be 1 @@ -8577,14 +8609,14 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {      unsigned CurReg = 0;      for (unsigned I = 0, E = RetTys.size(); I != E; ++I) {        EVT VT = RetTys[I]; -      MVT RegisterVT = -          getRegisterTypeForCallingConv(CLI.RetTy->getContext(), VT); -      unsigned NumRegs = -          getNumRegistersForCallingConv(CLI.RetTy->getContext(), VT); +      MVT RegisterVT = getRegisterTypeForCallingConv(CLI.RetTy->getContext(), +                                                     CLI.CallConv, VT); +      unsigned NumRegs = getNumRegistersForCallingConv(CLI.RetTy->getContext(), +                                                       CLI.CallConv, VT);        ReturnValues.push_back(getCopyFromParts(CLI.DAG, CLI.DL, &InVals[CurReg],                                                NumRegs, RegisterVT, VT, nullptr, -                                              AssertOp, true)); +                                              CLI.CallConv, AssertOp));        CurReg += NumRegs;      } @@ -8623,8 +8655,8 @@ SelectionDAGBuilder::CopyValueToVirtualRegister(const Value *V, unsigned Reg) {    // If this is an InlineAsm we have to match the registers required, not the    // notional registers required by the type. -  RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), Reg, -                   V->getType(), isABIRegCopy(V)); +  RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), Reg, V->getType(), +                   getABIRegCopyCC(V));    SDValue Chain = DAG.getEntryNode();    ISD::NodeType ExtendType = (FuncInfo.PreferredExtendType.find(V) == @@ -8937,10 +8969,10 @@ void SelectionDAGISel::LowerArguments(const Function &F) {        if (ArgCopyElisionCandidates.count(&Arg))          Flags.setCopyElisionCandidate(); -      MVT RegisterVT = -          TLI->getRegisterTypeForCallingConv(*CurDAG->getContext(), VT); -      unsigned NumRegs = -          TLI->getNumRegistersForCallingConv(*CurDAG->getContext(), VT); +      MVT RegisterVT = TLI->getRegisterTypeForCallingConv( +          *CurDAG->getContext(), F.getCallingConv(), VT); +      unsigned NumRegs = TLI->getNumRegistersForCallingConv( +          *CurDAG->getContext(), F.getCallingConv(), VT);        for (unsigned i = 0; i != NumRegs; ++i) {          ISD::InputArg MyFlags(Flags, RegisterVT, VT, isArgValueUsed,                                ArgNo, PartBase+i*RegisterVT.getStoreSize()); @@ -8995,8 +9027,8 @@ void SelectionDAGISel::LowerArguments(const Function &F) {      MVT VT = ValueVTs[0].getSimpleVT();      MVT RegVT = TLI->getRegisterType(*CurDAG->getContext(), VT);      Optional<ISD::NodeType> AssertOp = None; -    SDValue ArgValue = getCopyFromParts(DAG, dl, &InVals[0], 1, -                                        RegVT, VT, nullptr, AssertOp); +    SDValue ArgValue = getCopyFromParts(DAG, dl, &InVals[0], 1, RegVT, VT, +                                        nullptr, F.getCallingConv(), AssertOp);      MachineFunction& MF = SDB->DAG.getMachineFunction();      MachineRegisterInfo& RegInfo = MF.getRegInfo(); @@ -9046,10 +9078,10 @@ void SelectionDAGISel::LowerArguments(const Function &F) {      for (unsigned Val = 0; Val != NumValues; ++Val) {        EVT VT = ValueVTs[Val]; -      MVT PartVT = -          TLI->getRegisterTypeForCallingConv(*CurDAG->getContext(), VT); -      unsigned NumParts = -          TLI->getNumRegistersForCallingConv(*CurDAG->getContext(), VT); +      MVT PartVT = TLI->getRegisterTypeForCallingConv(*CurDAG->getContext(), +                                                      F.getCallingConv(), VT); +      unsigned NumParts = TLI->getNumRegistersForCallingConv( +          *CurDAG->getContext(), F.getCallingConv(), VT);        // Even an apparant 'unused' swifterror argument needs to be returned. So        // we do generate a copy for it that can be used on return from the @@ -9062,8 +9094,8 @@ void SelectionDAGISel::LowerArguments(const Function &F) {            AssertOp = ISD::AssertZext;          ArgValues.push_back(getCopyFromParts(DAG, dl, &InVals[i], NumParts, -                                             PartVT, VT, nullptr, AssertOp, -                                             true)); +                                             PartVT, VT, nullptr, +                                             F.getCallingConv(), AssertOp));        }        i += NumParts; | 
