Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/M68kCallingConv.h
35267 views
//===-- M68kCallingConv.h - M68k Custom CC Routines -------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file contains the custom routines for the M68k Calling Convention10/// that aren't done by tablegen.11///12//===----------------------------------------------------------------------===//1314#ifndef LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H15#define LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H1617#include "MCTargetDesc/M68kMCTargetDesc.h"1819#include "llvm/CodeGen/CallingConvLower.h"20#include "llvm/IR/CallingConv.h"21#include "llvm/IR/Function.h"2223namespace llvm {2425/// Custom state to propagate llvm type info to register CC assigner26struct M68kCCState : public CCState {27ArrayRef<Type *> ArgTypeList;2829M68kCCState(ArrayRef<Type *> ArgTypes, CallingConv::ID CC, bool IsVarArg,30MachineFunction &MF, SmallVectorImpl<CCValAssign> &Locs,31LLVMContext &C)32: CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {}33};3435/// NOTE this function is used to select registers for formal arguments and call36/// FIXME: Handling on pointer arguments is not complete37inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT,38CCValAssign::LocInfo &LocInfo,39ISD::ArgFlagsTy &ArgFlags, CCState &State) {40const M68kCCState &CCInfo = static_cast<M68kCCState &>(State);4142static const MCPhysReg DataRegList[] = {M68k::D0, M68k::D1, M68k::A0,43M68k::A1};4445// Address registers have %a register priority46static const MCPhysReg AddrRegList[] = {47M68k::A0,48M68k::A1,49M68k::D0,50M68k::D1,51};5253const auto &ArgTypes = CCInfo.ArgTypeList;54auto I = ArgTypes.begin(), End = ArgTypes.end();55int No = ValNo;56while (No > 0 && I != End) {57No -= (*I)->isIntegerTy(64) ? 2 : 1;58++I;59}6061bool IsPtr = I != End && (*I)->isPointerTy();6263unsigned Reg =64IsPtr ? State.AllocateReg(AddrRegList) : State.AllocateReg(DataRegList);6566if (Reg) {67State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));68return true;69}7071return false;72}7374} // namespace llvm7576#endif // LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H777879