LLVM  15.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 "PPCISelLowering.h"
17 #include "PPCSubtarget.h"
18 #include "PPCTargetMachine.h"
24 #include "llvm/Support/Debug.h"
25 
26 #define DEBUG_TYPE "ppc-call-lowering"
27 
28 using namespace llvm;
29 
31  : CallLowering(&TLI) {}
32 
34  const Value *Val, ArrayRef<Register> VRegs,
36  Register SwiftErrorVReg) const {
37  assert(((Val && !VRegs.empty()) || (!Val && VRegs.empty())) &&
38  "Return value without a vreg");
39  if (VRegs.size() > 0)
40  return false;
41 
42  MIRBuilder.buildInstr(PPC::BLR8);
43  return true;
44 }
45 
47  CallLoweringInfo &Info) const {
48  return false;
49 }
50 
52  const Function &F,
54  FunctionLoweringInfo &FLI) const {
55  MachineFunction &MF = MIRBuilder.getMF();
57  const auto &DL = F.getParent()->getDataLayout();
58  auto &TLI = *getTLI<PPCTargetLowering>();
59 
60  // Loop over each arg, set flags and split to single value types
61  SmallVector<ArgInfo, 8> SplitArgs;
62  unsigned I = 0;
63  for (const auto &Arg : F.args()) {
64  if (DL.getTypeStoreSize(Arg.getType()).isZero())
65  continue;
66 
67  ArgInfo OrigArg{VRegs[I], Arg, I};
69  splitToValueTypes(OrigArg, SplitArgs, DL, F.getCallingConv());
70  ++I;
71  }
72 
73  CCAssignFn *AssignFn =
74  TLI.ccAssignFnForCall(F.getCallingConv(), false, F.isVarArg());
75  IncomingValueAssigner ArgAssigner(AssignFn);
76  FormalArgHandler ArgHandler(MIRBuilder, MRI);
77  return determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
78  MIRBuilder, F.getCallingConv(),
79  F.isVarArg());
80 }
81 
82 void PPCIncomingValueHandler::assignValueToReg(Register ValVReg,
83  Register PhysReg,
84  CCValAssign VA) {
85  markPhysRegUsed(PhysReg);
86  IncomingValueHandler::assignValueToReg(ValVReg, PhysReg, VA);
87 }
88 
89 void PPCIncomingValueHandler::assignValueToAddress(Register ValVReg,
90  Register Addr, LLT MemTy,
91  MachinePointerInfo &MPO,
92  CCValAssign &VA) {
93  // define a lambda expression to load value
94  auto BuildLoad = [](MachineIRBuilder &MIRBuilder, MachinePointerInfo &MPO,
95  LLT MemTy, const DstOp &Res, Register Addr) {
97  auto *MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
98  inferAlignFromPtrInfo(MF, MPO));
99  return MIRBuilder.buildLoad(Res, Addr, *MMO);
100  };
101 
102  BuildLoad(MIRBuilder, MPO, MemTy, ValVReg, Addr);
103 }
104 
105 Register PPCIncomingValueHandler::getStackAddress(uint64_t Size, int64_t Offset,
106  MachinePointerInfo &MPO,
107  ISD::ArgFlagsTy Flags) {
108  auto &MFI = MIRBuilder.getMF().getFrameInfo();
109  const bool IsImmutable = !Flags.isByVal();
110  int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
112 
113  // Build Frame Index based on whether the machine is 32-bit or 64-bit
116  MachineInstrBuilder AddrReg = MIRBuilder.buildFrameIndex(FramePtr, FI);
117  StackUsed = std::max(StackUsed, Size + Offset);
118  return AddrReg.getReg(0);
119 }
120 
121 void FormalArgHandler::markPhysRegUsed(unsigned PhysReg) {
122  MIRBuilder.getMRI()->addLiveIn(PhysReg);
123  MIRBuilder.getMBB().addLiveIn(PhysReg);
124 }
llvm::MachineRegisterInfo::addLiveIn
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Definition: MachineRegisterInfo.h:954
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
PPCCallLowering.h
CallLowering.h
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:50
llvm::Function
Definition: Function.h:60
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::MachineIRBuilder::getMRI
MachineRegisterInfo * getMRI()
Getter for MRI.
Definition: MachineIRBuilder.h:287
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:456
llvm::PPCCallLowering::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: PPCCallLowering.cpp:46
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:235
MachineIRBuilder.h
llvm::PPCIncomingValueHandler::StackUsed
uint64_t StackUsed
Definition: PPCCallLowering.h:45
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
F
#define F(x, y, z)
Definition: MD5.cpp:55
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
PPCSubtarget.h
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:650
llvm::codeview::EncodedFramePtrReg::FramePtr
@ FramePtr
llvm::CCValAssign
CCValAssign - Represent assignment of one arg/retval to a location.
Definition: CallingConvLower.h:31
llvm::MachineIRBuilder::buildLoad
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
Definition: MachineIRBuilder.h:888
llvm::ISD::ArgFlagsTy::isByVal
bool isByVal() const
Definition: TargetCallingConv.h:85
llvm::CallLowering::ArgInfo
Definition: CallLowering.h:62
llvm::FormalArgHandler
Definition: M68kCallLowering.h:66
llvm::MachineIRBuilder::getMF
MachineFunction & getMF()
Getter for the function we currently build.
Definition: MachineIRBuilder.h:269
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:175
llvm::LLT::pointer
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
Definition: LowLevelTypeImpl.h:49
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:219
TargetCallingConv.h
llvm::MachineInstrBuilder
Definition: MachineInstrBuilder.h:69
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
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:696
I
#define I(x, y, z)
Definition: MD5.cpp:58
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:294
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:656
llvm::PPCTargetLowering
Definition: PPCISelLowering.h:742
llvm::MachineFunction
Definition: MachineFunction.h:241
llvm::MachineIRBuilder::buildInstr
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
Definition: MachineIRBuilder.h:374
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::ISD::ArgFlagsTy
Definition: TargetCallingConv.h:27
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::PPCCallLowering::PPCCallLowering
PPCCallLowering(const PPCTargetLowering &TLI)
Definition: PPCCallLowering.cpp:30
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:133
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::PPCCallLowering::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: PPCCallLowering.cpp:33
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:376
llvm::MachineIRBuilder::buildFrameIndex
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
Definition: MachineIRBuilder.cpp:135
llvm::PPCCallLowering::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: PPCCallLowering.cpp:51
CallingConvLower.h
MachineFrameInfo.h
llvm::CallLowering::IncomingValueAssigner
Definition: CallLowering.h:214
llvm::CallLowering::CallLoweringInfo
Definition: CallLowering.h:102
llvm::CallLowering::ValueHandler::MIRBuilder
MachineIRBuilder & MIRBuilder
Definition: CallLowering.h:227
PPCISelLowering.h
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:1006
llvm::DstOp
Definition: MachineIRBuilder.h:65
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::MachineFunction::getDataLayout
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Definition: MachineFunction.cpp:287
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:412
llvm::CallLowering
Definition: CallLowering.h:44
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
Debug.h
llvm::AttributeList::FirstArgIndex
@ FirstArgIndex
Definition: Attributes.h:413
PPCTargetMachine.h
llvm::CallLowering::determineAndHandleAssignments
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, ArrayRef< Register > ThisReturnRegs=None) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
Definition: CallLowering.cpp:532
llvm::LLT
Definition: LowLevelTypeImpl.h:39
llvm::CallLowering::setArgFlags
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
Definition: CallLowering.cpp:177