llvm.org GIT mirror llvm / 093b780
[RISCV][NFC] Refactor LocVT<->ValVT converstion in RISCVISelLowering There was some duplicated logic for using the LocInfo of a CCValAssign in order to convert from the ValVT to LocVT or vice versa. Resolve this by factoring out convertLocVTFromValVT from unpackFromRegLoc. Also rename packIntoRegLoc to the more appropriate convertValVTToLocVT and call these helper functions consistently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343737 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Bradbury 1 year, 8 months ago
1 changed file(s) with 33 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
867867 }
868868 }
869869
870 // Convert Val to a ValVT. Should not be called for CCValAssign::Indirect
871 // values.
872 static SDValue convertLocVTToValVT(SelectionDAG &DAG, SDValue Val,
873 const CCValAssign &VA, const SDLoc &DL) {
874 switch (VA.getLocInfo()) {
875 default:
876 llvm_unreachable("Unexpected CCValAssign::LocInfo");
877 case CCValAssign::Full:
878 break;
879 case CCValAssign::BCvt:
880 Val = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), Val);
881 break;
882 }
883 return Val;
884 }
885
870886 // The caller is responsible for loading the full value if the argument is
871887 // passed with CCValAssign::Indirect.
872888 static SDValue unpackFromRegLoc(SelectionDAG &DAG, SDValue Chain,
874890 MachineFunction &MF = DAG.getMachineFunction();
875891 MachineRegisterInfo &RegInfo = MF.getRegInfo();
876892 EVT LocVT = VA.getLocVT();
877 EVT ValVT = VA.getValVT();
878893 SDValue Val;
879894
880895 unsigned VReg = RegInfo.createVirtualRegister(&RISCV::GPRRegClass);
881896 RegInfo.addLiveIn(VA.getLocReg(), VReg);
882897 Val = DAG.getCopyFromReg(Chain, DL, VReg, LocVT);
898
899 if (VA.getLocInfo() == CCValAssign::Indirect)
900 return Val;
901
902 return convertLocVTToValVT(DAG, Val, VA, DL);
903 }
904
905 static SDValue convertValVTToLocVT(SelectionDAG &DAG, SDValue Val,
906 const CCValAssign &VA, const SDLoc &DL) {
907 EVT LocVT = VA.getLocVT();
883908
884909 switch (VA.getLocInfo()) {
885910 default:
886911 llvm_unreachable("Unexpected CCValAssign::LocInfo");
887912 case CCValAssign::Full:
888 case CCValAssign::Indirect:
889913 break;
890914 case CCValAssign::BCvt:
891 Val = DAG.getNode(ISD::BITCAST, DL, ValVT, Val);
915 Val = DAG.getNode(ISD::BITCAST, DL, LocVT, Val);
892916 break;
893917 }
894918 return Val;
12901314
12911315 // Promote the value if needed.
12921316 // For now, only handle fully promoted and indirect arguments.
1293 switch (VA.getLocInfo()) {
1294 case CCValAssign::Full:
1295 break;
1296 case CCValAssign::BCvt:
1297 ArgValue = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), ArgValue);
1298 break;
1299 case CCValAssign::Indirect: {
1317 if (VA.getLocInfo() == CCValAssign::Indirect) {
13001318 // Store the argument in a stack slot and pass its address.
13011319 SDValue SpillSlot = DAG.CreateStackTemporary(Outs[i].ArgVT);
13021320 int FI = cast(SpillSlot)->getIndex();
13181336 ++i;
13191337 }
13201338 ArgValue = SpillSlot;
1321 break;
1322 }
1323 default:
1324 llvm_unreachable("Unknown loc info!");
1339 } else {
1340 ArgValue = convertValVTToLocVT(DAG, ArgValue, VA, DL);
13251341 }
13261342
13271343 // Use local copy if it is a byval arg.
14231439 // Glue the RetValue to the end of the call sequence
14241440 Chain = RetValue.getValue(1);
14251441 Glue = RetValue.getValue(2);
1442
14261443 if (VA.getLocVT() == MVT::i32 && VA.getValVT() == MVT::f64) {
14271444 assert(VA.getLocReg() == ArgGPRs[0] && "Unexpected reg assignment");
14281445 SDValue RetValue2 =
14331450 RetValue2);
14341451 }
14351452
1436 switch (VA.getLocInfo()) {
1437 default:
1438 llvm_unreachable("Unknown loc info!");
1439 case CCValAssign::Full:
1440 break;
1441 case CCValAssign::BCvt:
1442 RetValue = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), RetValue);
1443 break;
1444 }
1453 RetValue = convertLocVTToValVT(DAG, RetValue, VA, DL);
14451454
14461455 InVals.push_back(RetValue);
14471456 }
14621471 return false;
14631472 }
14641473 return true;
1465 }
1466
1467 static SDValue packIntoRegLoc(SelectionDAG &DAG, SDValue Val,
1468 const CCValAssign &VA, const SDLoc &DL) {
1469 EVT LocVT = VA.getLocVT();
1470
1471 switch (VA.getLocInfo()) {
1472 default:
1473 llvm_unreachable("Unexpected CCValAssign::LocInfo");
1474 case CCValAssign::Full:
1475 break;
1476 case CCValAssign::BCvt:
1477 Val = DAG.getNode(ISD::BITCAST, DL, LocVT, Val);
1478 break;
1479 }
1480 return Val;
14811474 }
14821475
14831476 SDValue
15221515 RetOps.push_back(DAG.getRegister(RegHi, MVT::i32));
15231516 } else {
15241517 // Handle a 'normal' return.
1525 Val = packIntoRegLoc(DAG, Val, VA, DL);
1518 Val = convertValVTToLocVT(DAG, Val, VA, DL);
15261519 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Val, Glue);
15271520
15281521 // Guarantee that all emitted copies are stuck together.