LLVM  14.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"
23 #include "llvm/Support/Debug.h"
24 
25 #define DEBUG_TYPE "ppc-call-lowering"
26 
27 using namespace llvm;
28 
30  : CallLowering(&TLI) {}
31 
33  const Value *Val, ArrayRef<Register> VRegs,
35  Register SwiftErrorVReg) const {
36  assert(((Val && !VRegs.empty()) || (!Val && VRegs.empty())) &&
37  "Return value without a vreg");
38  if (VRegs.size() > 0)
39  return false;
40 
41  MIRBuilder.buildInstr(PPC::BLR8);
42  return true;
43 }
44 
46  CallLoweringInfo &Info) const {
47  return false;
48 }
49 
51  const Function &F,
53  FunctionLoweringInfo &FLI) const {
54  MachineFunction &MF = MIRBuilder.getMF();
56  const auto &DL = F.getParent()->getDataLayout();
57  auto &TLI = *getTLI<PPCTargetLowering>();
58 
59  // Loop over each arg, set flags and split to single value types
60  SmallVector<ArgInfo, 8> SplitArgs;
61  unsigned I = 0;
62  for (const auto &Arg : F.args()) {
63  if (DL.getTypeStoreSize(Arg.getType()).isZero())
64  continue;
65 
66  ArgInfo OrigArg{VRegs[I], Arg, I};
68  splitToValueTypes(OrigArg, SplitArgs, DL, F.getCallingConv());
69  ++I;
70  }
71 
72  CCAssignFn *AssignFn =
73  TLI.ccAssignFnForCall(F.getCallingConv(), false, F.isVarArg());
74  IncomingValueAssigner ArgAssigner(AssignFn);
75  FormalArgHandler ArgHandler(MIRBuilder, MRI);
76  return determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
77  MIRBuilder, F.getCallingConv(),
78  F.isVarArg());
79 }
80 
81 void PPCIncomingValueHandler::assignValueToReg(Register ValVReg,
82  Register PhysReg,
83  CCValAssign VA) {
84  markPhysRegUsed(PhysReg);
85  IncomingValueHandler::assignValueToReg(ValVReg, PhysReg, VA);
86 }
87 
88 void PPCIncomingValueHandler::assignValueToAddress(Register ValVReg,
89  Register Addr, LLT MemTy,
90  MachinePointerInfo &MPO,
91  CCValAssign &VA) {
92  // define a lambda expression to load value
93  auto BuildLoad = [](MachineIRBuilder &MIRBuilder, MachinePointerInfo &MPO,
94  LLT MemTy, const DstOp &Res, Register Addr) {
96  auto *MMO = MF.getMachineMemOperand(MPO, MachineMemOperand::MOLoad, MemTy,
97  inferAlignFromPtrInfo(MF, MPO));
98  return MIRBuilder.buildLoad(Res, Addr, *MMO);
99  };
100 
101  BuildLoad(MIRBuilder, MPO, MemTy, ValVReg, Addr);
102 }
103 
104 Register PPCIncomingValueHandler::getStackAddress(uint64_t Size, int64_t Offset,
105  MachinePointerInfo &MPO,
106  ISD::ArgFlagsTy Flags) {
107  auto &MFI = MIRBuilder.getMF().getFrameInfo();
108  const bool IsImmutable = !Flags.isByVal();
109  int FI = MFI.CreateFixedObject(Size, Offset, IsImmutable);
111 
112  // Build Frame Index based on whether the machine is 32-bit or 64-bit
115  MachineInstrBuilder AddrReg = MIRBuilder.buildFrameIndex(FramePtr, FI);
117  return AddrReg.getReg(0);
118 }
119 
120 void FormalArgHandler::markPhysRegUsed(unsigned PhysReg) {
121  MIRBuilder.getMRI()->addLiveIn(PhysReg);
122  MIRBuilder.getMBB().addLiveIn(PhysReg);
123 }
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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
PPCCallLowering.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::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:434
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:45
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
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:158
F
#define F(x, y, z)
Definition: MD5.cpp:56
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
PPCSubtarget.h
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:651
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::MachineIRBuilder::getMF
MachineFunction & getMF()
Getter for the function we currently build.
Definition: MachineIRBuilder.h:262
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::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:686
I
#define I(x, y, z)
Definition: MD5.cpp:59
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:287
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:657
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:367
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:29
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:135
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:32
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::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:50
CallingConvLower.h
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::CallLowering::IncomingValueAssigner
Definition: CallLowering.h:213
llvm::CallLowering::CallLoweringInfo
Definition: CallLowering.h:101
llvm::CallLowering::ValueHandler::MIRBuilder
MachineIRBuilder & MIRBuilder
Definition: CallLowering.h:226
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:1008
llvm::DstOp
Definition: MachineIRBuilder.h:58
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
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:264
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
llvm::CallLowering
Definition: CallLowering.h:43
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
Debug.h
llvm::AttributeList::FirstArgIndex
@ FirstArgIndex
Definition: Attributes.h:403
PPCTargetMachine.h
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