1 //===-- M68kCallingConv.h - M68k Custom CC Routines -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file contains the custom routines for the M68k Calling Convention
11 /// that aren't done by tablegen.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H
16 #define LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H
18 #include "MCTargetDesc/M68kMCTargetDesc.h"
20 #include "llvm/CodeGen/CallingConvLower.h"
21 #include "llvm/IR/CallingConv.h"
22 #include "llvm/IR/Function.h"
26 /// Custom state to propagate llvm type info to register CC assigner
27 struct M68kCCState : public CCState {
28 ArrayRef<Type *> ArgTypeList;
30 M68kCCState(ArrayRef<Type *> ArgTypes, CallingConv::ID CC, bool IsVarArg,
31 MachineFunction &MF, SmallVectorImpl<CCValAssign> &Locs,
33 : CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {}
36 /// NOTE this function is used to select registers for formal arguments and call
37 /// FIXME: Handling on pointer arguments is not complete
38 inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
39 CCValAssign::LocInfo &LocInfo,
40 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
41 const M68kCCState &CCInfo = static_cast<M68kCCState &>(State);
43 static const MCPhysReg DataRegList[] = {M68k::D0, M68k::D1, M68k::A0,
46 // Address registers have %a register priority
47 static const MCPhysReg AddrRegList[] = {
54 const auto &ArgTypes = CCInfo.ArgTypeList;
55 auto I = ArgTypes.begin(), End = ArgTypes.end();
57 while (No > 0 && I != End) {
58 No -= (*I)->isIntegerTy(64) ? 2 : 1;
62 bool IsPtr = I != End && (*I)->isPointerTy();
65 IsPtr ? State.AllocateReg(AddrRegList) : State.AllocateReg(DataRegList);
68 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
77 #endif // LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H