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
23namespace llvm {
24
25static 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(Size: 8, Alignment: Align(4));
34 State.addLoc(
35 V: CCValAssign::getMem(ValNo, ValVT, Offset: StackOffset, LocVT, HTP: LocInfo));
36 return true;
37 }
38 if (!State.AllocateReg(ArgGPRs))
39 State.AllocateStack(Size: 4, Alignment: Align(4));
40 State.addLoc(V: CCValAssign::getReg(ValNo, ValVT, RegNo: Reg, LocVT, HTP: LocInfo));
41 return true;
42}
43
44static 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(V: CCValAssign::getReg(ValNo, ValVT, RegNo: Reg, LocVT, HTP: LocInfo));
58 return true;
59}
60
61} // namespace llvm
62
63#endif
64

source code of llvm/lib/Target/CSKY/CSKYCallingConv.h