29 #ifndef LLVM_BUILD_GLOBAL_ISEL
30 #error "This shouldn't be built without GISel"
44 auto StructT = cast<StructType>(
T);
45 for (
unsigned i = 1, e = StructT->getNumElements(); i != e; ++i)
46 if (StructT->getElementType(i) != StructT->getElementType(0))
62 return VTSize == 1 || VTSize == 8 || VTSize == 16 || VTSize == 32;
71 : ValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB), StackSize(0) {}
73 unsigned getStackAddress(uint64_t
Size, int64_t
Offset,
75 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
80 unsigned SPReg =
MRI.createGenericVirtualRegister(p0);
81 MIRBuilder.buildCopy(SPReg, ARM::SP);
83 unsigned OffsetReg =
MRI.createGenericVirtualRegister(s32);
84 MIRBuilder.buildConstant(OffsetReg, Offset);
86 unsigned AddrReg =
MRI.createGenericVirtualRegister(p0);
87 MIRBuilder.buildGEP(AddrReg, SPReg, OffsetReg);
93 void assignValueToReg(
unsigned ValVReg,
unsigned PhysReg,
101 unsigned ExtReg = extendRegister(ValVReg, VA);
102 MIRBuilder.buildCopy(PhysReg, ExtReg);
106 void assignValueToAddress(
unsigned ValVReg,
unsigned Addr, uint64_t Size,
108 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
111 unsigned ExtReg = extendRegister(ValVReg, VA);
112 auto MMO = MIRBuilder.getMF().getMachineMemOperand(
115 MIRBuilder.buildStore(ExtReg, Addr, *MMO);
125 assert(NextVA.needsCustom() &&
"Value doesn't need custom handling");
129 "Values belong to different arguments");
132 assert(NextVA.isRegLoc() &&
"Value should be in reg");
134 unsigned NewRegs[] = {
MRI.createGenericVirtualRegister(
LLT::scalar(32)),
136 MIRBuilder.buildUnmerge(NewRegs, Arg.
Reg);
138 bool IsLittle = MIRBuilder.getMF().getSubtarget<
ARMSubtarget>().isLittle();
142 assignValueToReg(NewRegs[0], VA.
getLocReg(), VA);
143 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
148 bool assignArg(
unsigned ValNo,
MVT ValVT,
MVT LocVT,
151 if (AssignFn(ValNo, ValVT, LocVT, LocInfo, Info.
Flags, State))
164 void ARMCallLowering::splitToValueTypes(
177 if (SplitVTs.
size() == 1) {
180 auto Flags = OrigArg.Flags;
182 Flags.setOrigAlign(OriginalAlignment);
188 unsigned FirstRegIdx = SplitArgs.
size();
189 for (
unsigned i = 0, e = SplitVTs.
size(); i != e; ++i) {
190 EVT SplitVT = SplitVTs[i];
192 auto Flags = OrigArg.Flags;
195 Flags.setOrigAlign(OriginalAlignment);
197 bool NeedsConsecutiveRegisters =
200 if (NeedsConsecutiveRegisters) {
201 Flags.setInConsecutiveRegs();
203 Flags.setInConsecutiveRegsLast();
208 SplitTy,
Flags, OrigArg.IsFixed});
211 for (
unsigned i = 0; i < Offsets.
size(); ++i)
212 PerformArgSplit(SplitArgs[FirstRegIdx + i].
Reg, Offsets[i] * 8);
218 const Value *Val,
unsigned VReg,
224 auto &MF = MIRBuilder.
getMF();
228 auto &TLI = *getTLI<ARMTargetLowering>();
234 ArgInfo RetInfo(VReg, Val->
getType());
236 splitToValueTypes(RetInfo, SplitVTs, MF, [&](
unsigned Reg, uint64_t Offset) {
246 OutgoingValueHandler RetHandler(MIRBuilder, MF.
getRegInfo(),
Ret, AssignFn);
251 const Value *Val,
unsigned VReg)
const {
252 assert(!Val == !VReg &&
"Return value without a vreg");
256 if (!lowerReturnVal(MIRBuilder, Val, VReg, Ret))
269 : ValueHandler(MIRBuilder, MRI, AssignFn) {}
271 unsigned getStackAddress(uint64_t Size, int64_t Offset,
273 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
288 void assignValueToAddress(
unsigned ValVReg,
unsigned Addr, uint64_t Size,
290 assert((Size == 1 || Size == 2 || Size == 4 || Size == 8) &&
301 buildLoad(LoadVReg, Addr, Size, 0, MPO);
305 buildLoad(ValVReg, Addr, Size, 0, MPO);
309 void buildLoad(
unsigned Val,
unsigned Addr, uint64_t Size,
unsigned Alignment,
316 void assignValueToReg(
unsigned ValVReg,
unsigned PhysReg,
326 markPhysRegUsed(PhysReg);
330 unsigned assignCustomValue(
const ARMCallLowering::ArgInfo &Arg,
337 assert(NextVA.needsCustom() &&
"Value doesn't need custom handling");
341 "Values belong to different arguments");
344 assert(NextVA.isRegLoc() &&
"Value should be in reg");
349 assignValueToReg(NewRegs[0], VA.
getLocReg(), VA);
350 assignValueToReg(NewRegs[1], NextVA.getLocReg(), NextVA);
364 virtual void markPhysRegUsed(
unsigned PhysReg) = 0;
370 : IncomingValueHandler(MIRBuilder, MRI, AssignFn) {}
372 void markPhysRegUsed(
unsigned PhysReg)
override {
388 auto &MF = MIRBuilder.
getMF();
389 auto &MBB = MIRBuilder.
getMBB();
391 auto &TLI = *getTLI<ARMTargetLowering>();
395 if (Subtarget->isThumb())
398 for (
auto &Arg : F.
args())
405 FormalArgHandler ArgHandler(MIRBuilder, MIRBuilder.
getMF().
getRegInfo(),
411 for (
auto &Arg : F.
args()) {
412 ArgInfo AInfo(VRegs[Idx], Arg.getType());
417 splitToValueTypes(AInfo, ArgInfos, MF, [&](
unsigned Reg, uint64_t Offset) {
421 if (!SplitRegs.
empty())
437 : IncomingValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB) {}
439 void markPhysRegUsed(
unsigned PhysReg)
override {
453 const auto &TLI = *getTLI<ARMTargetLowering>();
462 auto CallSeqStart = MIRBuilder.
buildInstr(ARM::ADJCALLSTACKDOWN);
468 if (Callee.
isReg()) {
469 auto CalleeReg = Callee.
getReg();
472 MF, *TRI, MRI, *STI.getInstrInfo(), *STI.getRegBankInfo(),
473 *MIB.getInstr(), MIB->getDesc(), CalleeReg, 0));
477 for (
auto Arg : OrigArgs) {
485 splitToValueTypes(Arg, ArgInfos, MF, [&](
unsigned Reg, uint64_t Offset) {
494 OutgoingValueHandler ArgHandler(MIRBuilder, MRI, MIB, ArgAssignFn);
507 splitToValueTypes(OrigRet, ArgInfos, MF,
508 [&](
unsigned Reg, uint64_t Offset) {
513 CallReturnHandler RetHandler(MIRBuilder, MRI, MIB, RetAssignFn);
517 if (!SplitRegs.
empty()) {
529 .
addImm(ArgHandler.StackSize)
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
LocInfo getLocInfo() const
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, unsigned Reg, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, MachineInstrBuilder MIB, CCAssignFn *AssignFn)
const MachineInstrBuilder & add(const MachineOperand &MO) const
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...
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
unsigned getSizeInBits() const
static const MCPhysReg VRegs[32]
MachineInstrBuilder buildTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_TRUNC Op.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
unsigned createGenericVirtualRegister(LLT Ty)
Create and return a new generic virtual register with low-level type Ty.
unsigned getValNo() const
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool isVarArg) const
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool isVector() const
Return true if this is a vector value type.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val, unsigned VReg) const override
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
ARMCallLowering(const ARMTargetLowering &TLI)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
CCAssignFn * CCAssignFnForReturn(CallingConv::ID CC, bool isVarArg) const
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned 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.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool isInteger() const
Return true if this is an integer or a vector integer type.
LLVM_NODISCARD bool empty() const
unsigned getLocReg() const
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
bool isArrayTy() const
True if this is an instance of ArrayType.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset)
Stack pointer relative access.
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< unsigned > VRegs) const override
This hook must be implemented to lower the incoming (formal) arguments, described by Args...
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Helper class to build MachineInstr.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
unsigned getNextStackOffset() const
getNextStackOffset - Return the next stack offset such that all stack slots satisfy their alignment r...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Argument handling is mostly uniform between the four places that make these decisions: function forma...
This class contains a discriminated union of information about pointers in memory operands...
const ARMSubtarget * getSubtarget() const
MachineInstrBuilder buildFrameIndex(unsigned Res, int Idx)
Build and insert Res<def> = G_FRAME_INDEX Idx.
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
The memory access writes data.
bool genLongCalls() const
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
CCState - This class holds information needed while lowering arguments and return values...
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res<def> = COPY Op.
CCValAssign - Represent assignment of one arg/retval to a location.
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
This file declares the MachineIRBuilder class.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
virtual const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const
Return a mask of call-preserved registers for the given calling convention on the current function...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool isStructTy() const
True if this is an instance of StructType.
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static std::vector< std::string > Flags
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
void emplace_back(ArgTypes &&...Args)
bool handleAssignments(MachineIRBuilder &MIRBuilder, ArrayRef< ArgInfo > Args, ValueHandler &Callback) const
Invoke Handler::assignArg on each of the given Args and then use Callback to move them to the assigne...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setArgFlags(ArgInfo &Arg, unsigned OpNum, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
static bool isSupportedType(const DataLayout &DL, const ARMTargetLowering &TLI, Type *T)
MachineInstrBuilder buildUnmerge(ArrayRef< unsigned > Res, unsigned Op)
Build and insert Res0<def>, ...
unsigned getReg() const
getReg - Returns the register number.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
bool lowerCall(MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, const MachineOperand &Callee, const ArgInfo &OrigRet, ArrayRef< ArgInfo > OrigArgs) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
LLVM Value Representation.
static LLT pointer(uint16_t AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space (defaulting to 0).
MachineInstrBuilder buildLoad(unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res<def> = G_LOAD Addr, MMO.
bool functionArgumentNeedsConsecutiveRegisters(Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override
Returns true if an argument of type Ty needs to be passed in a contiguous block of registers in calli...
This file describes how to lower LLVM calls to machine code calls.
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res<def> = G_MERGE_VALUES Op0, ...
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
iterator_range< arg_iterator > args()
bool isVoidTy() const
Return true if this is 'void'.