1 //=== CSKYCallingConv.h - CSKY Custom Calling Convention Routines -*-C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the custom routines for the CSKY Calling Convention that
10 // aren't done by tablegen.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_CSKY_CSKYCALLINGCONV_H
15 #define LLVM_LIB_TARGET_CSKY_CSKYCALLINGCONV_H
16 
17 #include "CSKY.h"
18 #include "CSKYSubtarget.h"
19 #include "llvm/CodeGen/CallingConvLower.h"
20 #include "llvm/CodeGen/TargetInstrInfo.h"
21 #include "llvm/IR/CallingConv.h"
22 
23 namespace llvm {
24 
25 static bool CC_CSKY_ABIV2_SOFT_64(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
26                                   CCValAssign::LocInfo &LocInfo,
27                                   ISD::ArgFlagsTy &ArgFlags, CCState &State) {
28 
29   static const MCPhysReg ArgGPRs[] = {CSKY::R0, CSKY::R1, CSKY::R2, CSKY::R3};
30   Register Reg = State.AllocateReg(ArgGPRs);
31   LocVT = MVT::i32;
32   if (!Reg) {
33     unsigned StackOffset = State.AllocateStack(8, Align(4));
34     State.addLoc(
35         CCValAssign::getMem(ValNo, ValVT, StackOffset, LocVT, LocInfo));
36     return true;
37   }
38   if (!State.AllocateReg(ArgGPRs))
39     State.AllocateStack(4, Align(4));
40   State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
41   return true;
42 }
43 
44 static bool Ret_CSKY_ABIV2_SOFT_64(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
45                                    CCValAssign::LocInfo &LocInfo,
46                                    ISD::ArgFlagsTy &ArgFlags, CCState &State) {
47 
48   static const MCPhysReg ArgGPRs[] = {CSKY::R0, CSKY::R1};
49   Register Reg = State.AllocateReg(ArgGPRs);
50   LocVT = MVT::i32;
51   if (!Reg)
52     return false;
53 
54   if (!State.AllocateReg(ArgGPRs))
55     return false;
56 
57   State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
58   return true;
59 }
60 
61 } // namespace llvm
62 
63 #endif
64