Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/M68kCallingConv.h
35267 views
1
//===-- M68kCallingConv.h - M68k Custom CC 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
/// \file
10
/// This file contains the custom routines for the M68k Calling Convention
11
/// that aren't done by tablegen.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H
16
#define LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H
17
18
#include "MCTargetDesc/M68kMCTargetDesc.h"
19
20
#include "llvm/CodeGen/CallingConvLower.h"
21
#include "llvm/IR/CallingConv.h"
22
#include "llvm/IR/Function.h"
23
24
namespace llvm {
25
26
/// Custom state to propagate llvm type info to register CC assigner
27
struct M68kCCState : public CCState {
28
ArrayRef<Type *> ArgTypeList;
29
30
M68kCCState(ArrayRef<Type *> ArgTypes, CallingConv::ID CC, bool IsVarArg,
31
MachineFunction &MF, SmallVectorImpl<CCValAssign> &Locs,
32
LLVMContext &C)
33
: CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {}
34
};
35
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);
42
43
static const MCPhysReg DataRegList[] = {M68k::D0, M68k::D1, M68k::A0,
44
M68k::A1};
45
46
// Address registers have %a register priority
47
static const MCPhysReg AddrRegList[] = {
48
M68k::A0,
49
M68k::A1,
50
M68k::D0,
51
M68k::D1,
52
};
53
54
const auto &ArgTypes = CCInfo.ArgTypeList;
55
auto I = ArgTypes.begin(), End = ArgTypes.end();
56
int No = ValNo;
57
while (No > 0 && I != End) {
58
No -= (*I)->isIntegerTy(64) ? 2 : 1;
59
++I;
60
}
61
62
bool IsPtr = I != End && (*I)->isPointerTy();
63
64
unsigned Reg =
65
IsPtr ? State.AllocateReg(AddrRegList) : State.AllocateReg(DataRegList);
66
67
if (Reg) {
68
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
69
return true;
70
}
71
72
return false;
73
}
74
75
} // namespace llvm
76
77
#endif // LLVM_LIB_TARGET_M68K_M68KCALLINGCONV_H
78
79