1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|*                                                                            *|
3|* Calling Convention Implementation Fragment                                 *|
4|*                                                                            *|
5|* Automatically generated file, do not edit!                                 *|
6|*                                                                            *|
7\*===----------------------------------------------------------------------===*/
8
9static bool CC_Mips(unsigned ValNo, MVT ValVT,
10                    MVT LocVT, CCValAssign::LocInfo LocInfo,
11                    ISD::ArgFlagsTy ArgFlags, CCState &State);
12static bool CC_Mips16RetHelper(unsigned ValNo, MVT ValVT,
13                               MVT LocVT, CCValAssign::LocInfo LocInfo,
14                               ISD::ArgFlagsTy ArgFlags, CCState &State);
15static bool CC_MipsN(unsigned ValNo, MVT ValVT,
16                     MVT LocVT, CCValAssign::LocInfo LocInfo,
17                     ISD::ArgFlagsTy ArgFlags, CCState &State);
18static bool CC_MipsN_FastCC(unsigned ValNo, MVT ValVT,
19                            MVT LocVT, CCValAssign::LocInfo LocInfo,
20                            ISD::ArgFlagsTy ArgFlags, CCState &State);
21static bool CC_MipsN_SoftFloat(unsigned ValNo, MVT ValVT,
22                               MVT LocVT, CCValAssign::LocInfo LocInfo,
23                               ISD::ArgFlagsTy ArgFlags, CCState &State);
24static bool CC_MipsN_VarArg(unsigned ValNo, MVT ValVT,
25                            MVT LocVT, CCValAssign::LocInfo LocInfo,
26                            ISD::ArgFlagsTy ArgFlags, CCState &State);
27static bool CC_MipsO32(unsigned ValNo, MVT ValVT,
28                       MVT LocVT, CCValAssign::LocInfo LocInfo,
29                       ISD::ArgFlagsTy ArgFlags, CCState &State);
30static bool CC_MipsO32_FP(unsigned ValNo, MVT ValVT,
31                          MVT LocVT, CCValAssign::LocInfo LocInfo,
32                          ISD::ArgFlagsTy ArgFlags, CCState &State);
33static bool CC_MipsO32_FastCC(unsigned ValNo, MVT ValVT,
34                              MVT LocVT, CCValAssign::LocInfo LocInfo,
35                              ISD::ArgFlagsTy ArgFlags, CCState &State);
36static bool CC_Mips_ByVal(unsigned ValNo, MVT ValVT,
37                          MVT LocVT, CCValAssign::LocInfo LocInfo,
38                          ISD::ArgFlagsTy ArgFlags, CCState &State);
39static bool CC_Mips_FastCC(unsigned ValNo, MVT ValVT,
40                           MVT LocVT, CCValAssign::LocInfo LocInfo,
41                           ISD::ArgFlagsTy ArgFlags, CCState &State);
42static bool CC_Mips_FixedArg(unsigned ValNo, MVT ValVT,
43                             MVT LocVT, CCValAssign::LocInfo LocInfo,
44                             ISD::ArgFlagsTy ArgFlags, CCState &State);
45static bool CC_Mips_VarArg(unsigned ValNo, MVT ValVT,
46                           MVT LocVT, CCValAssign::LocInfo LocInfo,
47                           ISD::ArgFlagsTy ArgFlags, CCState &State);
48static bool RetCC_F128(unsigned ValNo, MVT ValVT,
49                       MVT LocVT, CCValAssign::LocInfo LocInfo,
50                       ISD::ArgFlagsTy ArgFlags, CCState &State);
51static bool RetCC_F128HardFloat(unsigned ValNo, MVT ValVT,
52                                MVT LocVT, CCValAssign::LocInfo LocInfo,
53                                ISD::ArgFlagsTy ArgFlags, CCState &State);
54static bool RetCC_F128SoftFloat(unsigned ValNo, MVT ValVT,
55                                MVT LocVT, CCValAssign::LocInfo LocInfo,
56                                ISD::ArgFlagsTy ArgFlags, CCState &State);
57static bool RetCC_Mips(unsigned ValNo, MVT ValVT,
58                       MVT LocVT, CCValAssign::LocInfo LocInfo,
59                       ISD::ArgFlagsTy ArgFlags, CCState &State);
60static bool RetCC_MipsN(unsigned ValNo, MVT ValVT,
61                        MVT LocVT, CCValAssign::LocInfo LocInfo,
62                        ISD::ArgFlagsTy ArgFlags, CCState &State);
63static bool RetCC_MipsO32(unsigned ValNo, MVT ValVT,
64                          MVT LocVT, CCValAssign::LocInfo LocInfo,
65                          ISD::ArgFlagsTy ArgFlags, CCState &State);
66
67
68static bool CC_Mips(unsigned ValNo, MVT ValVT,
69                    MVT LocVT, CCValAssign::LocInfo LocInfo,
70                    ISD::ArgFlagsTy ArgFlags, CCState &State) {
71
72  if (State.isVarArg()) {
73    if (!static_cast<MipsCCState *>(&State)->IsCallOperandFixed(ValNo)) {
74      if (!CC_Mips_VarArg(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
75        return false;
76    }
77  }
78
79  if (!CC_Mips_FixedArg(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
80    return false;
81
82  return true;  // CC didn't match.
83}
84
85
86static bool CC_Mips16RetHelper(unsigned ValNo, MVT ValVT,
87                               MVT LocVT, CCValAssign::LocInfo LocInfo,
88                               ISD::ArgFlagsTy ArgFlags, CCState &State) {
89
90  if (ArgFlags.isByVal()) {
91    if (!CC_Mips_ByVal(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
92      return false;
93  }
94
95  if (LocVT == MVT::i32) {
96    static const MCPhysReg RegList1[] = {
97      Mips::V0, Mips::V1, Mips::A0, Mips::A1
98    };
99    if (unsigned Reg = State.AllocateReg(RegList1)) {
100      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
101      return false;
102    }
103  }
104
105  return true;  // CC didn't match.
106}
107
108
109static bool CC_MipsN(unsigned ValNo, MVT ValVT,
110                     MVT LocVT, CCValAssign::LocInfo LocInfo,
111                     ISD::ArgFlagsTy ArgFlags, CCState &State) {
112
113  if (LocVT == MVT::i8 ||
114      LocVT == MVT::i16 ||
115      LocVT == MVT::i32 ||
116      LocVT == MVT::i64) {
117    if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isLittle()) {
118      if (ArgFlags.isInReg()) {
119        LocVT = MVT::i64;
120        if (ArgFlags.isSExt())
121                LocInfo = CCValAssign::SExtUpper;
122        else if (ArgFlags.isZExt())
123                LocInfo = CCValAssign::ZExtUpper;
124        else
125                LocInfo = CCValAssign::AExtUpper;
126      }
127    }
128  }
129
130  if (LocVT == MVT::i8 ||
131      LocVT == MVT::i16 ||
132      LocVT == MVT::i32) {
133    if (!static_cast<MipsCCState *>(&State)->WasOriginalArgFloat(ValNo)) {
134      LocVT = MVT::i64;
135      if (ArgFlags.isSExt())
136            LocInfo = CCValAssign::SExt;
137      else if (ArgFlags.isZExt())
138            LocInfo = CCValAssign::ZExt;
139      else
140            LocInfo = CCValAssign::AExt;
141    }
142  }
143
144  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).useSoftFloat()) {
145    if (LocVT == MVT::i32) {
146      if (!CC_MipsN_SoftFloat(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
147        return false;
148    }
149  }
150
151  if (LocVT == MVT::i64) {
152    static const MCPhysReg RegList1[] = {
153      Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64
154    };
155    static const MCPhysReg RegList2[] = {
156      Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64
157    };
158    if (unsigned Reg = State.AllocateReg(RegList1, RegList2)) {
159      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
160      return false;
161    }
162  }
163
164  if (LocVT == MVT::f32) {
165    static const MCPhysReg RegList3[] = {
166      Mips::F12, Mips::F13, Mips::F14, Mips::F15, Mips::F16, Mips::F17, Mips::F18, Mips::F19
167    };
168    static const MCPhysReg RegList4[] = {
169      Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64
170    };
171    if (unsigned Reg = State.AllocateReg(RegList3, RegList4)) {
172      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
173      return false;
174    }
175  }
176
177  if (LocVT == MVT::f64) {
178    static const MCPhysReg RegList5[] = {
179      Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64
180    };
181    static const MCPhysReg RegList6[] = {
182      Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64
183    };
184    if (unsigned Reg = State.AllocateReg(RegList5, RegList6)) {
185      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
186      return false;
187    }
188  }
189
190  if (LocVT == MVT::f32) {
191    unsigned Offset7 = State.AllocateStack(4, 8);
192    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset7, LocVT, LocInfo));
193    return false;
194  }
195
196  if (LocVT == MVT::i64 ||
197      LocVT == MVT::f64) {
198    unsigned Offset8 = State.AllocateStack(8, 8);
199    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset8, LocVT, LocInfo));
200    return false;
201  }
202
203  return true;  // CC didn't match.
204}
205
206
207static bool CC_MipsN_FastCC(unsigned ValNo, MVT ValVT,
208                            MVT LocVT, CCValAssign::LocInfo LocInfo,
209                            ISD::ArgFlagsTy ArgFlags, CCState &State) {
210
211  if (LocVT == MVT::i64) {
212    static const MCPhysReg RegList1[] = {
213      Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64, Mips::T4_64, Mips::T5_64, Mips::T6_64, Mips::T7_64, Mips::T8_64, Mips::V1_64
214    };
215    if (unsigned Reg = State.AllocateReg(RegList1)) {
216      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
217      return false;
218    }
219  }
220
221  if (LocVT == MVT::f64) {
222    static const MCPhysReg RegList2[] = {
223      Mips::D0_64, Mips::D1_64, Mips::D2_64, Mips::D3_64, Mips::D4_64, Mips::D5_64, Mips::D6_64, Mips::D7_64, Mips::D8_64, Mips::D9_64, Mips::D10_64, Mips::D11_64, Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64
224    };
225    if (unsigned Reg = State.AllocateReg(RegList2)) {
226      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
227      return false;
228    }
229  }
230
231  if (LocVT == MVT::i64 ||
232      LocVT == MVT::f64) {
233    unsigned Offset3 = State.AllocateStack(8, 8);
234    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset3, LocVT, LocInfo));
235    return false;
236  }
237
238  return true;  // CC didn't match.
239}
240
241
242static bool CC_MipsN_SoftFloat(unsigned ValNo, MVT ValVT,
243                               MVT LocVT, CCValAssign::LocInfo LocInfo,
244                               ISD::ArgFlagsTy ArgFlags, CCState &State) {
245
246  static const MCPhysReg RegList1[] = {
247    Mips::A0, Mips::A1, Mips::A2, Mips::A3, Mips::T0, Mips::T1, Mips::T2, Mips::T3
248  };
249  static const MCPhysReg RegList2[] = {
250    Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64
251  };
252  if (unsigned Reg = State.AllocateReg(RegList1, RegList2)) {
253    State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
254    return false;
255  }
256
257  unsigned Offset3 = State.AllocateStack(4, 8);
258  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset3, LocVT, LocInfo));
259  return false;
260
261  return true;  // CC didn't match.
262}
263
264
265static bool CC_MipsN_VarArg(unsigned ValNo, MVT ValVT,
266                            MVT LocVT, CCValAssign::LocInfo LocInfo,
267                            ISD::ArgFlagsTy ArgFlags, CCState &State) {
268
269  if (LocVT == MVT::i8 ||
270      LocVT == MVT::i16 ||
271      LocVT == MVT::i32 ||
272      LocVT == MVT::i64) {
273    if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isLittle()) {
274      if (ArgFlags.isInReg()) {
275        LocVT = MVT::i64;
276        if (ArgFlags.isSExt())
277                LocInfo = CCValAssign::SExtUpper;
278        else if (ArgFlags.isZExt())
279                LocInfo = CCValAssign::ZExtUpper;
280        else
281                LocInfo = CCValAssign::AExtUpper;
282      }
283    }
284  }
285
286  if (LocVT == MVT::i8 ||
287      LocVT == MVT::i16 ||
288      LocVT == MVT::i32) {
289    LocVT = MVT::i64;
290    if (ArgFlags.isSExt())
291        LocInfo = CCValAssign::SExt;
292    else if (ArgFlags.isZExt())
293        LocInfo = CCValAssign::ZExt;
294    else
295        LocInfo = CCValAssign::AExt;
296  }
297
298  if (LocVT == MVT::f32) {
299    static const MCPhysReg RegList1[] = {
300      Mips::A0, Mips::A1, Mips::A2, Mips::A3, Mips::T0, Mips::T1, Mips::T2, Mips::T3
301    };
302    if (unsigned Reg = State.AllocateReg(RegList1)) {
303      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
304      return false;
305    }
306  }
307
308  if (LocVT == MVT::i64 ||
309      LocVT == MVT::f64) {
310    static const MCPhysReg RegList2[] = {
311      Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64
312    };
313    if (unsigned Reg = State.AllocateReg(RegList2)) {
314      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
315      return false;
316    }
317  }
318
319  if (LocVT == MVT::f32) {
320    unsigned Offset3 = State.AllocateStack(4, 8);
321    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset3, LocVT, LocInfo));
322    return false;
323  }
324
325  if (LocVT == MVT::i64 ||
326      LocVT == MVT::f64) {
327    unsigned Offset4 = State.AllocateStack(8, 8);
328    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset4, LocVT, LocInfo));
329    return false;
330  }
331
332  return true;  // CC didn't match.
333}
334
335
336static bool CC_MipsO32(unsigned ValNo, MVT ValVT,
337                       MVT LocVT, CCValAssign::LocInfo LocInfo,
338                       ISD::ArgFlagsTy ArgFlags, CCState &State) {
339
340  if (LocVT == MVT::i1 ||
341      LocVT == MVT::i8 ||
342      LocVT == MVT::i16) {
343    LocVT = MVT::i32;
344    if (ArgFlags.isSExt())
345        LocInfo = CCValAssign::SExt;
346    else if (ArgFlags.isZExt())
347        LocInfo = CCValAssign::ZExt;
348    else
349        LocInfo = CCValAssign::AExt;
350  }
351
352  if (LocVT == MVT::i32 ||
353      LocVT == MVT::f32) {
354    unsigned Offset1 = State.AllocateStack(4, 4);
355    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset1, LocVT, LocInfo));
356    return false;
357  }
358
359  if (LocVT == MVT::f64) {
360    unsigned Offset2 = State.AllocateStack(8, 8);
361    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset2, LocVT, LocInfo));
362    return false;
363  }
364
365  return true;  // CC didn't match.
366}
367
368
369static bool CC_MipsO32_FP(unsigned ValNo, MVT ValVT,
370                          MVT LocVT, CCValAssign::LocInfo LocInfo,
371                          ISD::ArgFlagsTy ArgFlags, CCState &State) {
372
373  if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
374    if (!CC_MipsO32_FP32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
375      return false;
376  }
377
378  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
379    if (!CC_MipsO32_FP64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
380      return false;
381  }
382
383  return true;  // CC didn't match.
384}
385
386
387static bool CC_MipsO32_FastCC(unsigned ValNo, MVT ValVT,
388                              MVT LocVT, CCValAssign::LocInfo LocInfo,
389                              ISD::ArgFlagsTy ArgFlags, CCState &State) {
390
391  if (LocVT == MVT::f64) {
392    if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
393      static const MCPhysReg RegList1[] = {
394        Mips::D0, Mips::D1, Mips::D2, Mips::D3, Mips::D4, Mips::D5, Mips::D6, Mips::D7, Mips::D8, Mips::D9
395      };
396      if (unsigned Reg = State.AllocateReg(RegList1)) {
397        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
398        return false;
399      }
400    }
401  }
402
403  if (LocVT == MVT::f64) {
404    if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
405      if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).useOddSPReg()) {
406        static const MCPhysReg RegList2[] = {
407          Mips::D0_64, Mips::D1_64, Mips::D2_64, Mips::D3_64, Mips::D4_64, Mips::D5_64, Mips::D6_64, Mips::D7_64, Mips::D8_64, Mips::D9_64, Mips::D10_64, Mips::D11_64, Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64
408        };
409        if (unsigned Reg = State.AllocateReg(RegList2)) {
410          State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
411          return false;
412        }
413      }
414    }
415  }
416
417  if (LocVT == MVT::f64) {
418    if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
419      if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).noOddSPReg()) {
420        static const MCPhysReg RegList3[] = {
421          Mips::D0_64, Mips::D2_64, Mips::D4_64, Mips::D6_64, Mips::D8_64, Mips::D10_64, Mips::D12_64, Mips::D14_64, Mips::D16_64, Mips::D18_64
422        };
423        if (unsigned Reg = State.AllocateReg(RegList3)) {
424          State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
425          return false;
426        }
427      }
428    }
429  }
430
431  if (LocVT == MVT::f64) {
432    unsigned Offset4 = State.AllocateStack(8, 8);
433    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset4, LocVT, LocInfo));
434    return false;
435  }
436
437  return true;  // CC didn't match.
438}
439
440
441static bool CC_Mips_ByVal(unsigned ValNo, MVT ValVT,
442                          MVT LocVT, CCValAssign::LocInfo LocInfo,
443                          ISD::ArgFlagsTy ArgFlags, CCState &State) {
444
445  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isABI_O32()) {
446    if (ArgFlags.isByVal()) {
447      State.HandleByVal(ValNo, ValVT, LocVT, LocInfo, 4, 4, ArgFlags);
448      return false;
449    }
450  }
451
452  if (ArgFlags.isByVal()) {
453    State.HandleByVal(ValNo, ValVT, LocVT, LocInfo, 8, 8, ArgFlags);
454    return false;
455  }
456
457  return true;  // CC didn't match.
458}
459
460
461static bool CC_Mips_FastCC(unsigned ValNo, MVT ValVT,
462                           MVT LocVT, CCValAssign::LocInfo LocInfo,
463                           ISD::ArgFlagsTy ArgFlags, CCState &State) {
464
465  if (ArgFlags.isByVal()) {
466    State.HandleByVal(ValNo, ValVT, LocVT, LocInfo, 4, 4, ArgFlags);
467    return false;
468  }
469
470  if (LocVT == MVT::i8 ||
471      LocVT == MVT::i16) {
472    LocVT = MVT::i32;
473    if (ArgFlags.isSExt())
474        LocInfo = CCValAssign::SExt;
475    else if (ArgFlags.isZExt())
476        LocInfo = CCValAssign::ZExt;
477    else
478        LocInfo = CCValAssign::AExt;
479  }
480
481  if (LocVT == MVT::i32) {
482    if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isTargetNaCl()) {
483      static const MCPhysReg RegList1[] = {
484        Mips::A0, Mips::A1, Mips::A2, Mips::A3, Mips::T0, Mips::T1, Mips::T2, Mips::T3, Mips::T4, Mips::T5, Mips::T6, Mips::T7, Mips::T8, Mips::V1
485      };
486      if (unsigned Reg = State.AllocateReg(RegList1)) {
487        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
488        return false;
489      }
490    }
491  }
492
493  if (LocVT == MVT::i32) {
494    if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isTargetNaCl()) {
495      static const MCPhysReg RegList2[] = {
496        Mips::A0, Mips::A1, Mips::A2, Mips::A3, Mips::T0, Mips::T1, Mips::T2, Mips::T3, Mips::T4, Mips::T5, Mips::V1
497      };
498      if (unsigned Reg = State.AllocateReg(RegList2)) {
499        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
500        return false;
501      }
502    }
503  }
504
505  if (LocVT == MVT::f32) {
506    if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).useOddSPReg()) {
507      static const MCPhysReg RegList3[] = {
508        Mips::F0, Mips::F1, Mips::F2, Mips::F3, Mips::F4, Mips::F5, Mips::F6, Mips::F7, Mips::F8, Mips::F9, Mips::F10, Mips::F11, Mips::F12, Mips::F13, Mips::F14, Mips::F15, Mips::F16, Mips::F17, Mips::F18, Mips::F19
509      };
510      if (unsigned Reg = State.AllocateReg(RegList3)) {
511        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
512        return false;
513      }
514    }
515  }
516
517  if (LocVT == MVT::f32) {
518    if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).noOddSPReg()) {
519      static const MCPhysReg RegList4[] = {
520        Mips::F0, Mips::F2, Mips::F4, Mips::F6, Mips::F8, Mips::F10, Mips::F12, Mips::F14, Mips::F16, Mips::F18
521      };
522      if (unsigned Reg = State.AllocateReg(RegList4)) {
523        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
524        return false;
525      }
526    }
527  }
528
529  if (LocVT == MVT::i32 ||
530      LocVT == MVT::f32) {
531    unsigned Offset5 = State.AllocateStack(4, 4);
532    State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset5, LocVT, LocInfo));
533    return false;
534  }
535
536  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isABI_O32()) {
537    if (!CC_MipsO32_FastCC(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
538      return false;
539  }
540
541  if (!CC_MipsN_FastCC(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
542    return false;
543
544  return true;  // CC didn't match.
545}
546
547
548static bool CC_Mips_FixedArg(unsigned ValNo, MVT ValVT,
549                             MVT LocVT, CCValAssign::LocInfo LocInfo,
550                             ISD::ArgFlagsTy ArgFlags, CCState &State) {
551
552  if (State.getCallingConv() != CallingConv::Fast) {
553    if (static_cast<MipsCCState *>(&State)->getSpecialCallingConv() == MipsCCState::Mips16RetHelperConv) {
554      if (!CC_Mips16RetHelper(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
555        return false;
556    }
557  }
558
559  if (ArgFlags.isByVal()) {
560    if (!CC_Mips_ByVal(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
561      return false;
562  }
563
564  if (LocVT == MVT::i64) {
565    if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).useSoftFloat()) {
566      if (static_cast<MipsCCState *>(&State)->WasOriginalArgF128(ValNo)) {
567        LocVT = MVT::f64;
568        LocInfo = CCValAssign::BCvt;
569      }
570    }
571  }
572
573  if (State.getCallingConv() == CallingConv::Fast) {
574    if (!CC_Mips_FastCC(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
575      return false;
576  }
577
578  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isABI_O32()) {
579    if (!CC_MipsO32_FP(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
580      return false;
581  }
582
583  if (!CC_MipsN(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
584    return false;
585
586  return true;  // CC didn't match.
587}
588
589
590static bool CC_Mips_VarArg(unsigned ValNo, MVT ValVT,
591                           MVT LocVT, CCValAssign::LocInfo LocInfo,
592                           ISD::ArgFlagsTy ArgFlags, CCState &State) {
593
594  if (ArgFlags.isByVal()) {
595    if (!CC_Mips_ByVal(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
596      return false;
597  }
598
599  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isABI_O32()) {
600    if (!CC_MipsO32_FP(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
601      return false;
602  }
603
604  if (!CC_MipsN_VarArg(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
605    return false;
606
607  return true;  // CC didn't match.
608}
609
610
611static bool RetCC_F128(unsigned ValNo, MVT ValVT,
612                       MVT LocVT, CCValAssign::LocInfo LocInfo,
613                       ISD::ArgFlagsTy ArgFlags, CCState &State) {
614
615  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).useSoftFloat()) {
616    if (LocVT == MVT::i64) {
617      if (!RetCC_F128SoftFloat(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
618        return false;
619    }
620  }
621
622  if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).useSoftFloat()) {
623    if (LocVT == MVT::i64) {
624      if (!RetCC_F128HardFloat(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
625        return false;
626    }
627  }
628
629  return true;  // CC didn't match.
630}
631
632
633static bool RetCC_F128HardFloat(unsigned ValNo, MVT ValVT,
634                                MVT LocVT, CCValAssign::LocInfo LocInfo,
635                                ISD::ArgFlagsTy ArgFlags, CCState &State) {
636
637  LocVT = MVT::f64;
638  LocInfo = CCValAssign::BCvt;
639
640  if (ArgFlags.isInReg()) {
641    static const MCPhysReg RegList1[] = {
642      Mips::D0_64, Mips::D1_64
643    };
644    if (unsigned Reg = State.AllocateReg(RegList1)) {
645      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
646      return false;
647    }
648  }
649
650  static const MCPhysReg RegList2[] = {
651    Mips::D0_64, Mips::D2_64
652  };
653  if (unsigned Reg = State.AllocateReg(RegList2)) {
654    State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
655    return false;
656  }
657
658  return true;  // CC didn't match.
659}
660
661
662static bool RetCC_F128SoftFloat(unsigned ValNo, MVT ValVT,
663                                MVT LocVT, CCValAssign::LocInfo LocInfo,
664                                ISD::ArgFlagsTy ArgFlags, CCState &State) {
665
666  static const MCPhysReg RegList1[] = {
667    Mips::V0_64, Mips::A0_64
668  };
669  if (unsigned Reg = State.AllocateReg(RegList1)) {
670    State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
671    return false;
672  }
673
674  return true;  // CC didn't match.
675}
676
677
678static bool RetCC_Mips(unsigned ValNo, MVT ValVT,
679                       MVT LocVT, CCValAssign::LocInfo LocInfo,
680                       ISD::ArgFlagsTy ArgFlags, CCState &State) {
681
682  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isABI_N32()) {
683    if (!RetCC_MipsN(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
684      return false;
685  }
686
687  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isABI_N64()) {
688    if (!RetCC_MipsN(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
689      return false;
690  }
691
692  if (!RetCC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
693    return false;
694
695  return true;  // CC didn't match.
696}
697
698
699static bool RetCC_MipsN(unsigned ValNo, MVT ValVT,
700                        MVT LocVT, CCValAssign::LocInfo LocInfo,
701                        ISD::ArgFlagsTy ArgFlags, CCState &State) {
702
703  if (LocVT == MVT::i64) {
704    if (static_cast<MipsCCState *>(&State)->WasOriginalArgF128(ValNo)) {
705      if (!RetCC_F128(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
706        return false;
707    }
708  }
709
710  if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isLittle()) {
711    if (LocVT == MVT::i8 ||
712        LocVT == MVT::i16 ||
713        LocVT == MVT::i32 ||
714        LocVT == MVT::i64) {
715      if (ArgFlags.isInReg()) {
716        LocVT = MVT::i64;
717        if (ArgFlags.isSExt())
718                LocInfo = CCValAssign::SExt;
719        else if (ArgFlags.isZExt())
720                LocInfo = CCValAssign::ZExt;
721        else
722                LocInfo = CCValAssign::AExt;
723      }
724    }
725  }
726
727  if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isLittle()) {
728    if (LocVT == MVT::i8 ||
729        LocVT == MVT::i16 ||
730        LocVT == MVT::i32 ||
731        LocVT == MVT::i64) {
732      if (ArgFlags.isInReg()) {
733        LocVT = MVT::i64;
734        if (ArgFlags.isSExt())
735                LocInfo = CCValAssign::SExtUpper;
736        else if (ArgFlags.isZExt())
737                LocInfo = CCValAssign::ZExtUpper;
738        else
739                LocInfo = CCValAssign::AExtUpper;
740      }
741    }
742  }
743
744  if (LocVT == MVT::i64) {
745    static const MCPhysReg RegList1[] = {
746      Mips::V0_64, Mips::V1_64
747    };
748    if (unsigned Reg = State.AllocateReg(RegList1)) {
749      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
750      return false;
751    }
752  }
753
754  if (LocVT == MVT::f32) {
755    static const MCPhysReg RegList2[] = {
756      Mips::F0, Mips::F2
757    };
758    if (unsigned Reg = State.AllocateReg(RegList2)) {
759      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
760      return false;
761    }
762  }
763
764  if (LocVT == MVT::f64) {
765    static const MCPhysReg RegList3[] = {
766      Mips::D0_64, Mips::D2_64
767    };
768    if (unsigned Reg = State.AllocateReg(RegList3)) {
769      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
770      return false;
771    }
772  }
773
774  return true;  // CC didn't match.
775}
776
777
778static bool RetCC_MipsO32(unsigned ValNo, MVT ValVT,
779                          MVT LocVT, CCValAssign::LocInfo LocInfo,
780                          ISD::ArgFlagsTy ArgFlags, CCState &State) {
781
782  if (LocVT == MVT::i1 ||
783      LocVT == MVT::i8 ||
784      LocVT == MVT::i16) {
785    LocVT = MVT::i32;
786    if (ArgFlags.isSExt())
787        LocInfo = CCValAssign::SExt;
788    else if (ArgFlags.isZExt())
789        LocInfo = CCValAssign::ZExt;
790    else
791        LocInfo = CCValAssign::AExt;
792  }
793
794  if (!static_cast<MipsCCState *>(&State)->WasOriginalRetVectorFloat(ValNo)) {
795    if (LocVT == MVT::i32) {
796      static const MCPhysReg RegList1[] = {
797        Mips::V0, Mips::V1, Mips::A0, Mips::A1
798      };
799      if (unsigned Reg = State.AllocateReg(RegList1)) {
800        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
801        return false;
802      }
803    }
804  }
805
806  if (LocVT == MVT::f32) {
807    static const MCPhysReg RegList2[] = {
808      Mips::F0, Mips::F2
809    };
810    if (unsigned Reg = State.AllocateReg(RegList2)) {
811      State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
812      return false;
813    }
814  }
815
816  if (LocVT == MVT::f64) {
817    if (static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
818      static const MCPhysReg RegList3[] = {
819        Mips::D0_64, Mips::D2_64
820      };
821      if (unsigned Reg = State.AllocateReg(RegList3)) {
822        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
823        return false;
824      }
825    }
826  }
827
828  if (LocVT == MVT::f64) {
829    if (!static_cast<const MipsSubtarget&>(State.getMachineFunction().getSubtarget()).isFP64bit()) {
830      static const MCPhysReg RegList4[] = {
831        Mips::D0, Mips::D1
832      };
833      if (unsigned Reg = State.AllocateReg(RegList4)) {
834        State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
835        return false;
836      }
837    }
838  }
839
840  return true;  // CC didn't match.
841}
842