LLVM 23.0.0git
PPCCallLowering.cpp
Go to the documentation of this file.
1//===-- PPCCallLowering.h - Call lowering for GlobalISel -------*- 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 "PPCCallLowering.h"
16#include "PPCCallingConv.h"
17#include "PPCISelLowering.h"
23
24#define DEBUG_TYPE "ppc-call-lowering"
25
26using namespace llvm;
27
28namespace {
29
30struct OutgoingArgHandler : public CallLowering::OutgoingValueHandler {
31 OutgoingArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
33 : OutgoingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
34
35 void assignValueToReg(Register ValVReg, Register PhysReg,
36 const CCValAssign &VA,
37 ISD::ArgFlagsTy Flags = {}) override;
38 void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy,
39 const MachinePointerInfo &MPO,
40 const CCValAssign &VA) override;
41 Register getStackAddress(uint64_t Size, int64_t Offset,
43 ISD::ArgFlagsTy Flags) override;
44
46};
47} // namespace
48
49void OutgoingArgHandler::assignValueToReg(Register ValVReg, Register PhysReg,
50 const CCValAssign &VA,
51 ISD::ArgFlagsTy Flags) {
52 MIB.addUse(PhysReg, RegState::Implicit);
53 Register ExtReg = extendRegister(ValVReg, VA);
54 MIRBuilder.buildCopy(PhysReg, ExtReg);
55}
56
57void OutgoingArgHandler::assignValueToAddress(Register ValVReg, Register Addr,
58 LLT MemTy,
59 const MachinePointerInfo &MPO,
60 const CCValAssign &VA) {
61 llvm_unreachable("unimplemented");
62}
63
64Register OutgoingArgHandler::getStackAddress(uint64_t Size, int64_t Offset,
65 MachinePointerInfo &MPO,
66 ISD::ArgFlagsTy Flags) {
67 llvm_unreachable("unimplemented");
68}
69
72
74 const Value *Val, ArrayRef<Register> VRegs,
76 Register SwiftErrorVReg) const {
77 auto MIB = MIRBuilder.buildInstrNoInsert(PPC::BLR8);
78 bool Success = true;
79 MachineFunction &MF = MIRBuilder.getMF();
80 const Function &F = MF.getFunction();
82 auto &DL = F.getDataLayout();
83 if (!VRegs.empty()) {
84 // Setup the information about the return value.
85 ArgInfo OrigArg{VRegs, Val->getType(), 0};
86 setArgFlags(OrigArg, AttributeList::ReturnIndex, DL, F);
87
88 // Split the return value into consecutive registers if needed.
90 splitToValueTypes(OrigArg, SplitArgs, DL, F.getCallingConv());
91
92 // Use the calling convention callback to determine type and location of
93 // return value.
95
96 // Handler to move the return value into the correct location.
97 OutgoingArgHandler ArgHandler(MIRBuilder, MRI, MIB);
98
99 // Iterate over all return values, and move them to the assigned location.
100 Success = determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
101 MIRBuilder, F.getCallingConv(),
102 F.isVarArg());
103 }
104 MIRBuilder.insertInstr(MIB);
105 return Success;
106}
107
109 CallLoweringInfo &Info) const {
110 return false;
111}
112
114 const Function &F,
116 FunctionLoweringInfo &FLI) const {
117 MachineFunction &MF = MIRBuilder.getMF();
119 const auto &DL = F.getDataLayout();
120 auto &TLI = *getTLI<PPCTargetLowering>();
121
122 // Loop over each arg, set flags and split to single value types
123 SmallVector<ArgInfo, 8> SplitArgs;
124 unsigned I = 0;
125 for (const auto &Arg : F.args()) {
126 if (DL.getTypeStoreSize(Arg.getType()).isZero())
127 continue;
128
129 ArgInfo OrigArg{VRegs[I], Arg, I};
130 setArgFlags(OrigArg, I + AttributeList::FirstArgIndex, DL, F);
131 splitToValueTypes(OrigArg, SplitArgs, DL, F.getCallingConv());
132 ++I;
133 }
134
135 CCAssignFn *AssignFn =
136 TLI.ccAssignFnForCall(F.getCallingConv(), false, F.isVarArg());
137 IncomingValueAssigner ArgAssigner(AssignFn);
138 FormalArgHandler ArgHandler(MIRBuilder, MRI);
139 return determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
140 MIRBuilder, F.getCallingConv(),
141 F.isVarArg());
142}
143
144void PPCIncomingValueHandler::assignValueToReg(Register ValVReg,
145 Register PhysReg,
146 const CCValAssign &VA,
147 ISD::ArgFlagsTy Flags) {
148 markPhysRegUsed(PhysReg);
149 IncomingValueHandler::assignValueToReg(ValVReg, PhysReg, VA);
150}
151
152void PPCIncomingValueHandler::assignValueToAddress(
153 Register ValVReg, Register Addr, LLT MemTy, const MachinePointerInfo &MPO,
154 const CCValAssign &VA) {
155 // define a lambda expression to load value
156 auto BuildLoad = [](MachineIRBuilder &MIRBuilder,
157 const MachinePointerInfo &MPO, LLT MemTy,
158 const DstOp &Res, Register Addr) {
160 auto *MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
161 inferAlignFromPtrInfo(MF, MPO));
162 return MIRBuilder.buildLoad(Res, Addr, *MMO);
163 };
164
165 BuildLoad(MIRBuilder, MPO, MemTy, ValVReg, Addr);
166}
167
168Register PPCIncomingValueHandler::getStackAddress(uint64_t Size, int64_t Offset,
170 ISD::ArgFlagsTy Flags) {
171 auto &MFI = MIRBuilder.getMF().getFrameInfo();
172 const bool IsImmutable = !Flags.isByVal();
173 int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
175
176 // Build Frame Index based on whether the machine is 32-bit or 64-bit
177 llvm::LLT FramePtr = LLT::pointer(
178 0, MIRBuilder.getMF().getDataLayout().getPointerSizeInBits());
179 MachineInstrBuilder AddrReg = MIRBuilder.buildFrameIndex(FramePtr, FI);
180 StackUsed = std::max(StackUsed, Size + Offset);
181 return AddrReg.getReg(0);
182}
183
184void FormalArgHandler::markPhysRegUsed(unsigned PhysReg) {
185 MIRBuilder.getMRI()->addLiveIn(PhysReg);
186 MIRBuilder.getMBB().addLiveIn(PhysReg);
187}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file describes how to lower LLVM calls to machine code calls.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file declares the MachineIRBuilder class.
Promote Memory to Register
Definition Mem2Reg.cpp:110
This file describes how to lower LLVM calls to machine code calls.
static const unsigned FramePtr
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool empty() const
empty - Check if the array is empty.
Definition ArrayRef.h:137
CCValAssign - Represent assignment of one arg/retval to a location.
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< TypeSize > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, ArrayRef< Register > ThisReturnRegs={}) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
CallLowering(const TargetLowering *TLI)
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, 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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
Register getReg(unsigned Idx) const
Get the register for the operand index.
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
@ MOLoad
The memory access reads data.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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...
bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
PPCCallLowering(const PPCTargetLowering &TLI)
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,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
bool RetCC_PPC(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
@ Success
The lock was released successfully.
LLVM_ABI Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
Definition Utils.cpp:900
Base class for ValueHandlers used for arguments passed to a function call, or for return values.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.