LLVM: include/llvm/CodeGen/GlobalISel/CallLowering.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H

15#define LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H

16

29#include

30#include

31

32namespace llvm {

33

34class AttributeList;

44

47

48 virtual void anchor();

49public:

60

63

64

65

67

68

69

70

71

73

74

76

77

79

85 if (Regs.empty() && Flags.empty())

87

88 assert(((Ty->isVoidTy() || Ty->isEmptyTy()) ==

89 (Regs.empty() || Regs[0] == 0)) &&

90 "only void types should have no register");

91 }

92

96

98 };

99

104

106

108

109

110

112

113

115

116

118

119

120

122

123

125

126

128

130

131

132 std::optional PAI;

133

134

136

137

138

140

141

142

144

145

147

148

150

151

153

154

156

157

159

160

162

164 };

165

166

167

168

169

170

171

172

173

174

177 CCAssignFn *AssignFnVarArg_ = nullptr)

179 IsIncomingArgumentHandler(IsIncoming) {

180

181

182

185 }

186

188

189

190

192 return IsIncomingArgumentHandler;

193 }

194

195

196

197

198

202 if (getAssignFn(State.isVarArg())(ValNo, ValVT, LocVT, LocInfo, Flags,

203 Info.Ty, State))

204 return true;

205 StackSize = State.getStackSize();

206 return false;

207 }

208

209

211

212

213

215

216

218

219

220

224

225 private:

226 const bool IsIncomingArgumentHandler;

227 virtual void anchor();

228 };

229

235

241

246

251

253

254

255

259

260

261

262

263

264

268

269

270

271

272

273

277

278

279

280

283

284

285

286

290

291

292

293

300

301

302

303

304

305

306

307

309 std::function<void()> *Thunk = nullptr) {

310

311

313 }

314

315

316

317 void

322

323

324

326 unsigned MaxSizeBits = 0);

327 };

328

329

330

334

335

336

338 LLT NarrowTy);

339

340

343 };

344

345

346

351

352protected:

353

357

358

359 template

360 const XXXTargetLowering *getTLI() const {

361 return static_cast<const XXXTargetLowering *>(TLI);

362 }

363

364

365

367 unsigned ArgIdx) const;

368

369

371

372

373

375 const AttributeList &Attrs,

376 unsigned OpIdx) const;

377

378 template

380 const FuncInfoTy &FuncInfo) const;

381

382

383

384

385

386

387

388 void splitToValueTypes(const ArgInfo &OrigArgInfo,

392

393

394

395

396

397

398

399

400

401

402

403

404 bool determineAssignments(ValueAssigner &Assigner,

407

408

409

410

411

412 bool

413 determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner,

418

419

420

421

422 bool handleAssignments(ValueHandler &Handler, SmallVectorImpl &Args,

423 CCState &CCState,

424 SmallVectorImpl &ArgLocs,

425 MachineIRBuilder &MIRBuilder,

426 ArrayRef ThisReturnRegs = {}) const;

427

428

429

430

431 bool parametersInCSRMatch(const MachineRegisterInfo &MRI,

432 const uint32_t *CallerPreservedMask,

433 const SmallVectorImpl &ArgLocs,

434 const SmallVectorImpl &OutVals) const;

435

436

437

438

439

440

441

442

443

444

445

446 bool resultsCompatible(CallLoweringInfo &Info, MachineFunction &MF,

447 SmallVectorImpl &InArgs,

448 ValueAssigner &CalleeAssigner,

449 ValueAssigner &CallerAssigner) const;

450

451public:

454

455

456

457

461

462

463

464

467 int FI) const;

468

469

470

473

474

475

476

477 void insertSRetIncomingArgument(const Function &F,

481

482

483

484 void insertSRetOutgoingArgument(MachineIRBuilder &MIRBuilder,

486 CallLoweringInfo &Info) const;

487

488

489

492

493

494

495 void getReturnInfo(CallingConv::ID CallConv, Type *RetTy, AttributeList Attrs,

498

499

500

501

502 bool checkReturnTypeForCallConv(MachineFunction &MF) const;

503

504

505

506

509 bool IsVarArg) const {

510 return true;

511 }

512

513

514

515

516

517

518

519

520

521

522

525 Register SwiftErrorVReg) const {

527 assert(SwiftErrorVReg == 0 && "attempt to use unsupported swifterror");

528 return lowerReturn(MIRBuilder, Val, VRegs, FLI);

529 }

530 return false;

531 }

532

533

534

540

544

545

546

547

548

549

550

551

552

553

554

561

562

563

564

565

566

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

599 std::optional PAI, Register ConvergenceCtrlToken,

600 std::function<Register()> GetCalleeReg) const;

601

602

603

605

606

607

609};

610

613 const DataLayout &DL,

614 const Function &FuncInfo) const;

615

618 const DataLayout &DL,

619 const CallBase &FuncInfo) const;

620}

621

622#endif

unsigned const MachineRegisterInfo * MRI

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Analysis containing CSE Info

Implement a low-level type suitable for MachineInstr level instruction selection.

Promote Memory to Register

MachineInstr unsigned OpIdx

This file defines the SmallVector class.

static SymbolRef::Type getType(const Symbol *Sym)

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

CCState - This class holds information needed while lowering arguments and return values.

CCValAssign - Represent assignment of one arg/retval to a location.

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

virtual ~CallLowering()=default

virtual bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const

This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...

Definition CallLowering.h:555

virtual bool canLowerReturn(MachineFunction &MF, CallingConv::ID CallConv, SmallVectorImpl< BaseArgInfo > &Outs, bool IsVarArg) const

This hook must be implemented to check whether the return values described by Outs can fit into the r...

Definition CallLowering.h:507

virtual bool isTypeIsValidForThisReturn(EVT Ty) const

For targets which support the "returned" parameter attribute, returns true if the given type is a val...

Definition CallLowering.h:608

virtual bool enableBigEndian() const

For targets which want to use big-endian can enable it with enableBigEndian() hook.

Definition CallLowering.h:604

virtual bool supportSwiftError() const

Definition CallLowering.h:458

CallLowering(const TargetLowering *TLI)

Definition CallLowering.h:452

virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI, Register SwiftErrorVReg) const

This hook must be implemented to lower outgoing return values, described by Val, into the specified v...

Definition CallLowering.h:523

virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI) const

This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...

Definition CallLowering.h:535

const TargetLowering * getTLI() const

Getter for generic TargetLowering class.

Definition CallLowering.h:354

const XXXTargetLowering * getTLI() const

Getter for target specific TargetLowering class.

Definition CallLowering.h:360

virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const

This hook must be implemented to lower the given call instruction, including argument and return valu...

Definition CallLowering.h:567

void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const

virtual bool fallBackToDAGISel(const MachineFunction &MF) const

Definition CallLowering.h:541

This is the shared class of boolean and integer constants.

A parsed version of the target data layout string in and methods for querying it.

FunctionLoweringInfo - This contains information that is global to a function that is used when lower...

Helper class to build MachineInstr.

MachineOperand class - Representation of each machine instruction operand.

static MachineOperand CreateImm(int64_t Val)

MachineRegisterInfo - Keep track of information for virtual and physical registers,...

Wrapper class representing virtual and physical registers.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...

The instances of the Type class are immutable: once they are created, they are never changed.

LLVM Value Representation.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

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.

This struct is a compact representation of a valid (non-zero power of two) alignment.

Helper struct shared between Function Specialization and SCCP Solver.

Definition CallLowering.h:61

const Value * OrigValue

Optionally track the original IR value for the argument.

Definition CallLowering.h:72

SmallVector< Register, 4 > Regs

Definition CallLowering.h:62

SmallVector< Register, 2 > OrigRegs

Definition CallLowering.h:66

unsigned OrigArgIndex

Index original Function's argument.

Definition CallLowering.h:75

ArgInfo(ArrayRef< Register > Regs, Type *Ty, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), const Value *OrigValue=nullptr)

Definition CallLowering.h:80

ArgInfo(ArrayRef< Register > Regs, const Value &OrigValue, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >())

Definition CallLowering.h:93

static const unsigned NoArgIndex

Sentinel value for implicit machine-level input arguments.

Definition CallLowering.h:78

SmallVector< ISD::ArgFlagsTy, 4 > Flags

Definition CallLowering.h:52

Type * Ty

Definition CallLowering.h:51

BaseArgInfo()

Definition CallLowering.h:58

BaseArgInfo(Type *Ty, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >())

Definition CallLowering.h:54

Definition CallLowering.h:105

bool IsVarArg

True if the call is to a vararg function.

Definition CallLowering.h:146

bool IsMustTailCall

True if the call must be tail call optimized.

Definition CallLowering.h:135

bool IsTailCall

True if the call passes all target-independent checks for tail call optimization.

Definition CallLowering.h:139

MachineOperand Callee

Destination of the call.

Definition CallLowering.h:111

bool CanLowerReturn

True if the function's return value can be lowered to registers.

Definition CallLowering.h:149

ArgInfo OrigRet

Descriptor for the return type of the function.

Definition CallLowering.h:114

MDNode * KnownCallees

Definition CallLowering.h:129

const ConstantInt * CFIType

Expected type identifier for indirect calls with a CFI check.

Definition CallLowering.h:158

CallingConv::ID CallConv

Calling convention to be used for the call.

Definition CallLowering.h:107

Register ConvergenceCtrlToken

Valid if the call is a controlled convergent operation.

Definition CallLowering.h:124

const CallBase * CB

Original IR callsite corresponding to this call, if available.

Definition CallLowering.h:127

Register DemoteRegister

VReg to hold the hidden sret parameter.

Definition CallLowering.h:152

bool IsConvergent

True if this call results in convergent operations.

Definition CallLowering.h:161

std::optional< PtrAuthInfo > PAI

The auth-call information in the "ptrauth" bundle, if present.

Definition CallLowering.h:132

int DemoteStackIndex

The stack index for sret demotion.

Definition CallLowering.h:155

Register SwiftErrorVReg

Valid if the call has a swifterror inout parameter, and contains the vreg that the swifterror should ...

Definition CallLowering.h:121

GlobalValue * DeactivationSymbol

Definition CallLowering.h:163

SmallVector< ArgInfo, 32 > OrigArgs

List of descriptors of the arguments passed to the function.

Definition CallLowering.h:117

bool LoweredTailCall

True if the call was lowered as a tail call.

Definition CallLowering.h:143

IncomingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)

Definition CallLowering.h:231

IncomingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)

Definition CallLowering.h:332

OutgoingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)

Definition CallLowering.h:237

OutgoingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)

Definition CallLowering.h:348

Definition CallLowering.h:100

Register Discriminator

Definition CallLowering.h:102

uint64_t Key

Definition CallLowering.h:101

CCAssignFn * getAssignFn(bool IsVarArg) const

Select the appropriate assignment function depending on whether this is a variadic call.

Definition CallLowering.h:221

CCAssignFn * AssignFn

Assignment function to use for a general call.

Definition CallLowering.h:210

bool isIncomingArgumentHandler() const

Returns true if the handler is dealing with incoming arguments, i.e.

Definition CallLowering.h:191

ValueAssigner(bool IsIncoming, CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)

Definition CallLowering.h:176

CCAssignFn * AssignFnVarArg

Assignment function to use for a variadic call.

Definition CallLowering.h:214

virtual bool assignArg(unsigned ValNo, EVT OrigVT, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, const ArgInfo &Info, ISD::ArgFlagsTy Flags, CCState &State)

Wrap call to (typically tablegenerated CCAssignFn).

Definition CallLowering.h:199

uint64_t StackSize

The size of the currently allocated portion of the stack.

Definition CallLowering.h:217

virtual ~ValueAssigner()=default

MachineIRBuilder & MIRBuilder

Definition CallLowering.h:243

virtual ~ValueHandler()=default

MachineRegisterInfo & MRI

Definition CallLowering.h:244

const bool IsIncomingArgumentHandler

Definition CallLowering.h:245

virtual Register getStackAddress(uint64_t MemSize, int64_t Offset, MachinePointerInfo &MPO, ISD::ArgFlagsTy Flags)=0

Materialize a VReg containing the address of the specified stack-based object.

virtual void assignValueToAddress(const ArgInfo &Arg, unsigned ValRegIndex, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)

An overload which takes an ArgInfo if additional information about the arg is needed.

Definition CallLowering.h:294

virtual LLT getStackValueStoreType(const DataLayout &DL, const CCValAssign &VA, ISD::ArgFlagsTy Flags) const

Return the in-memory size to write for the argument at VA.

bool isIncomingArgumentHandler() const

Returns true if the handler is dealing with incoming arguments, i.e.

Definition CallLowering.h:256

virtual void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)=0

The specified value has been assigned to a stack location.

virtual unsigned assignCustomValue(ArgInfo &Arg, ArrayRef< CCValAssign > VAs, std::function< void()> *Thunk=nullptr)

Handle custom values, which may be passed into one or more of VAs.

Definition CallLowering.h:308

virtual void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA)=0

The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...

ValueHandler(bool IsIncoming, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)

Definition CallLowering.h:247

This class contains a discriminated union of information about pointers in memory operands,...