LLVM  14.0.0git
M68kCallLowering.cpp
Go to the documentation of this file.
1 //===-- M68kCallLowering.cpp - Call lowering -------------------*- 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 implements the lowering of LLVM calls to machine code calls for
11 /// GlobalISel.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "M68kCallLowering.h"
16 #include "M68kISelLowering.h"
17 #include "M68kInstrInfo.h"
18 #include "M68kSubtarget.h"
19 #include "M68kTargetMachine.h"
24 
25 using namespace llvm;
26 
28  : CallLowering(&TLI) {}
29 
33  : OutgoingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
34 
35  void assignValueToReg(Register ValVReg, Register PhysReg,
36  CCValAssign VA) override {
37  MIB.addUse(PhysReg, RegState::Implicit);
38  Register ExtReg = extendRegister(ValVReg, VA);
39  MIRBuilder.buildCopy(PhysReg, ExtReg);
40  }
41 
43  MachinePointerInfo &MPO, CCValAssign &VA) override {
44  llvm_unreachable("unimplemented");
45  }
46 
48  MachinePointerInfo &MPO,
49  ISD::ArgFlagsTy Flags) override {
50  llvm_unreachable("unimplemented");
51  }
52 
54 };
56  const Value *Val, ArrayRef<Register> VRegs,
58  Register SwiftErrorVReg) const {
59 
60  auto MIB = MIRBuilder.buildInstrNoInsert(M68k::RTS);
61  bool Success = true;
62  MachineFunction &MF = MIRBuilder.getMF();
63  const Function &F = MF.getFunction();
65  const M68kTargetLowering &TLI = *getTLI<M68kTargetLowering>();
66  CCAssignFn *AssignFn =
67  TLI.getCCAssignFn(F.getCallingConv(), true, F.isVarArg());
68  auto &DL = F.getParent()->getDataLayout();
69  if (!VRegs.empty()) {
70  SmallVector<ArgInfo, 8> SplitArgs;
71  ArgInfo OrigArg{VRegs, Val->getType(), 0};
73  splitToValueTypes(OrigArg, SplitArgs, DL, F.getCallingConv());
74  OutgoingValueAssigner ArgAssigner(AssignFn);
75  OutgoingArgHandler ArgHandler(MIRBuilder, MRI, MIB);
76  Success = determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
77  MIRBuilder, F.getCallingConv(),
78  F.isVarArg());
79  }
80  MIRBuilder.insertInstr(MIB);
81  return Success;
82 }
83 
85  const Function &F,
87  FunctionLoweringInfo &FLI) const {
88  MachineFunction &MF = MIRBuilder.getMF();
90  const auto &DL = F.getParent()->getDataLayout();
91  auto &TLI = *getTLI<M68kTargetLowering>();
92 
93  SmallVector<ArgInfo, 8> SplitArgs;
94  unsigned I = 0;
95  for (const auto &Arg : F.args()) {
96  ArgInfo OrigArg{VRegs[I], Arg.getType(), I};
98  splitToValueTypes(OrigArg, SplitArgs, DL, F.getCallingConv());
99  ++I;
100  }
101 
102  CCAssignFn *AssignFn =
103  TLI.getCCAssignFn(F.getCallingConv(), false, F.isVarArg());
104  IncomingValueAssigner ArgAssigner(AssignFn);
105  FormalArgHandler ArgHandler(MIRBuilder, MRI);
106  return determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
107  MIRBuilder, F.getCallingConv(),
108  F.isVarArg());
109 }
110 
111 void M68kIncomingValueHandler::assignValueToReg(Register ValVReg,
112  Register PhysReg,
113  CCValAssign VA) {
114  MIRBuilder.getMRI()->addLiveIn(PhysReg);
115  MIRBuilder.getMBB().addLiveIn(PhysReg);
116  IncomingValueHandler::assignValueToReg(ValVReg, PhysReg, VA);
117 }
118 
119 void M68kIncomingValueHandler::assignValueToAddress(Register ValVReg,
120  Register Addr,
121  LLT MemTy,
122  MachinePointerInfo &MPO,
123  CCValAssign &VA) {
125  auto *MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
126  inferAlignFromPtrInfo(MF, MPO));
127  MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
128 }
129 
130 Register M68kIncomingValueHandler::getStackAddress(uint64_t Size,
131  int64_t Offset,
132  MachinePointerInfo &MPO,
133  ISD::ArgFlagsTy Flags) {
134  auto &MFI = MIRBuilder.getMF().getFrameInfo();
135  const bool IsImmutable = !Flags.isByVal();
136  int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
138 
139  // Build Frame Index
142  MachineInstrBuilder AddrReg = MIRBuilder.buildFrameIndex(FramePtr, FI);
144  return AddrReg.getReg(0);
145 }
146 
148  CallLoweringInfo &Info) const {
149  return false;
150 }
151 
152 bool M68kCallLowering::enableBigEndian() const { return true; }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MachineRegisterInfo::addLiveIn
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Definition: MachineRegisterInfo.h:957
llvm::M68kTargetLowering::getCCAssignFn
CCAssignFn * getCCAssignFn(CallingConv::ID CC, bool Return, bool IsVarArg) const
Definition: M68kISelLowering.cpp:3419
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
OutgoingArgHandler::getStackAddress
Register getStackAddress(uint64_t Size, int64_t Offset, MachinePointerInfo &MPO, ISD::ArgFlagsTy Flags) override
Materialize a VReg containing the address of the specified stack-based object.
Definition: M68kCallLowering.cpp:47
M68kTargetMachine.h
CallLowering.h
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::Function
Definition: Function.h:62
llvm::RegState::Implicit
@ Implicit
Not emitted register (e.g. carry, or temporary result).
Definition: MachineInstrBuilder.h:46
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::MachineIRBuilder::getMRI
MachineRegisterInfo * getMRI()
Getter for MRI.
Definition: MachineIRBuilder.h:280
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition: MachineFunction.cpp:431
OutgoingArgHandler::MIB
MachineInstrBuilder MIB
Definition: M68kCallLowering.cpp:53
llvm::CallLowering::OutgoingValueHandler
Base class for ValueHandlers used for arguments passed to a function call, or for return values.
Definition: CallLowering.h:329
OutgoingArgHandler::assignValueToReg
void assignValueToReg(Register ValVReg, Register PhysReg, CCValAssign VA) override
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
Definition: M68kCallLowering.cpp:35
llvm::CallLowering::splitToValueTypes
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< uint64_t > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
Definition: CallLowering.cpp:212
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MachineIRBuilder::buildInstrNoInsert
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
Definition: MachineIRBuilder.cpp:40
MachineIRBuilder.h
llvm::M68kCallLowering::lowerCall
bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
Definition: M68kCallLowering.cpp:147
OutgoingArgHandler
Definition: M68kCallLowering.cpp:30
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
F
#define F(x, y, z)
Definition: MD5.cpp:56
M68kInstrInfo.h
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::M68kCallLowering::enableBigEndian
bool enableBigEndian() const override
For targets which want to use big-endian can enable it with enableBigEndian() hook.
Definition: M68kCallLowering.cpp:152
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:644
llvm::codeview::EncodedFramePtrReg::FramePtr
@ FramePtr
llvm::CCValAssign
CCValAssign - Represent assignment of one arg/retval to a location.
Definition: CallingConvLower.h:33
llvm::MachineIRBuilder::buildLoad
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
Definition: MachineIRBuilder.h:832
llvm::ISD::ArgFlagsTy::isByVal
bool isByVal() const
Definition: TargetCallingConv.h:85
llvm::CallLowering::ArgInfo
Definition: CallLowering.h:61
llvm::FormalArgHandler
Definition: M68kCallLowering.h:65
llvm::CallLowering::OutgoingValueAssigner
Definition: CallLowering.h:219
llvm::MachineIRBuilder::getMF
MachineFunction & getMF()
Getter for the function we currently build.
Definition: MachineIRBuilder.h:262
M68kISelLowering.h
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::MachineInstrBuilder::getReg
Register getReg(unsigned Idx) const
Get the register for the operand index.
Definition: MachineInstrBuilder.h:94
llvm::CCAssignFn
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
Definition: CallingConvLower.h:177
llvm::LLT::pointer
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
Definition: LowLevelTypeImpl.h:50
llvm::AttributeList::ReturnIndex
@ ReturnIndex
Definition: Attributes.h:402
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:212
TargetCallingConv.h
llvm::MachineInstrBuilder
Definition: MachineInstrBuilder.h:69
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition: MachineMemOperand.h:38
llvm::inferAlignFromPtrInfo
Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
Definition: Utils.cpp:678
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::FunctionLoweringInfo
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Definition: FunctionLoweringInfo.h:52
llvm::MachineIRBuilder::getMBB
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
Definition: MachineIRBuilder.h:287
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:650
llvm::M68kCallLowering::lowerFormalArguments
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register >> VRegs, FunctionLoweringInfo &FLI) const override
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
Definition: M68kCallLowering.cpp:84
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::MachineIRBuilder::insertInstr
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
Definition: MachineIRBuilder.cpp:45
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::ISD::ArgFlagsTy
Definition: TargetCallingConv.h:27
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:135
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::MachineBasicBlock::addLiveIn
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
Definition: MachineBasicBlock.h:367
llvm::MachineIRBuilder::buildFrameIndex
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
Definition: MachineIRBuilder.cpp:137
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:600
CallingConvLower.h
llvm::M68kTargetLowering
Definition: M68kISelLowering.h:116
Success
#define Success
Definition: AArch64Disassembler.cpp:260
llvm::CallLowering::determineAndHandleAssignments
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, Register ThisReturnReg=Register()) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
Definition: CallLowering.cpp:523
llvm::M68kCallLowering::lowerReturn
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI, Register SwiftErrorVReg) const override
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
Definition: M68kCallLowering.cpp:55
llvm::CallLowering::IncomingValueAssigner
Definition: CallLowering.h:213
llvm::CallLowering::CallLoweringInfo
Definition: CallLowering.h:101
llvm::CallLowering::ValueHandler::MIRBuilder
MachineIRBuilder & MIRBuilder
Definition: CallLowering.h:226
llvm::MachinePointerInfo::getFixedStack
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Definition: MachineOperand.cpp:1008
llvm::M68kCallLowering::M68kCallLowering
M68kCallLowering(const M68kTargetLowering &TLI)
Definition: M68kCallLowering.cpp:27
M68kSubtarget.h
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
OutgoingArgHandler::OutgoingArgHandler
OutgoingArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, MachineInstrBuilder MIB)
Definition: M68kCallLowering.cpp:31
llvm::MachineFunction::getDataLayout
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Definition: MachineFunction.cpp:261
OutgoingArgHandler::assignValueToAddress
void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy, MachinePointerInfo &MPO, CCValAssign &VA) override
The specified value has been assigned to a stack location.
Definition: M68kCallLowering.cpp:42
llvm::DataLayout::getPointerSizeInBits
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Definition: DataLayout.h:409
M68kCallLowering.h
llvm::M68kIncomingValueHandler::StackUsed
uint64_t StackUsed
Definition: M68kCallLowering.h:51
llvm::CallLowering
Definition: CallLowering.h:43
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::AttributeList::FirstArgIndex
@ FirstArgIndex
Definition: Attributes.h:404
llvm::LLT
Definition: LowLevelTypeImpl.h:40
llvm::CallLowering::setArgFlags
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
Definition: CallLowering.cpp:154