LLVM: lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

26

27using namespace llvm;

28

29#define DEBUG_TYPE "nvptx-prolog-epilog"

30

31namespace {

33public:

34 static char ID;

36

38

39 StringRef getPassName() const override { return "NVPTX Prolog Epilog Pass"; }

40

41private:

43};

44}

45

47 return new NVPTXPrologEpilogPass();

48}

49

50char NVPTXPrologEpilogPass::ID = 0;

51

53 "NVPTX Prologue/Epilogue Insertion", false, false)

54

59 if (MI.isDebugValue()) {

60

61 MachineOperand &Op = MI.getOperand(OpIdx);

62 assert(MI.isDebugOperand(&Op) &&

63 "Frame indices can only appear as a debug operand in a DBG_VALUE*"

64 " machine instruction");

65 Register Reg;

66 unsigned FrameIdx = Op.getIndex();

67

68 StackOffset Offset = TFI->getFrameIndexReference(MF, FrameIdx, Reg);

69 Op.ChangeToRegister(Reg, false );

70

71 const DIExpression *DIExpr = MI.getDebugExpression();

72 if (MI.isNonListDebugValue()) {

73 DIExpr = TRI.prependOffsetExpression(MI.getDebugExpression(),

74 DIExpression::ApplyOffset, Offset);

75 } else {

76

77

78

79 unsigned DebugOpIndex = MI.getDebugOperandIndex(&Op);

80 SmallVector<uint64_t, 3> Ops;

81 TRI.getOffsetOpcodes(Offset, Ops);

82 DIExpr = DIExpression::appendOpsToArg(DIExpr, Ops, DebugOpIndex);

83 }

84 MI.getDebugExpressionOp().setMetadata(DIExpr);

85 return true;

86 }

87 return false;

88}

89

90bool NVPTXPrologEpilogPass::runOnMachineFunction(MachineFunction &MF) {

91 const TargetSubtargetInfo &STI = MF.getSubtarget();

95

96 calculateFrameObjectOffsets(MF);

97

98 for (MachineBasicBlock &BB : MF) {

100 MachineInstr &MI = *std::prev(I);

101

102 bool RemovedMI = false;

103 for (const auto &[Idx, Op] : enumerate(MI.operands())) {

104 if (Op.isFI())

105 continue;

106

107 if (replaceFrameIndexDebugInstr(MF, MI, Idx))

108 continue;

109

110

111 RemovedMI = TRI.eliminateFrameIndex(MI, 0, Idx, nullptr);

113 if (RemovedMI)

114 break;

115 }

116

117 if (!RemovedMI)

118 --I;

119 }

120 }

121

122

124

126

127 if (I->isReturnBlock())

129 }

130

132}

133

134

136 bool StackGrowsDown, int64_t &Offset,

137 Align &MaxAlign) {

138

139 if (StackGrowsDown)

141

143

144

145

146 MaxAlign = std::max(MaxAlign, Alignment);

147

148

150

151 if (StackGrowsDown) {

153 << "]\n");

155 } else {

157 << "]\n");

160 }

161}

162

163void

164NVPTXPrologEpilogPass::calculateFrameObjectOffsets(MachineFunction &Fn) {

167

168 bool StackGrowsDown =

170

171

173

174

175

176

178 if (StackGrowsDown)

179 LocalAreaOffset = -LocalAreaOffset;

180 assert(LocalAreaOffset >= 0

181 && "Local area offset should be in direction of stack growth");

182 int64_t Offset = LocalAreaOffset;

183

184

185

186

187

188

190 int64_t FixedOff;

191 if (StackGrowsDown) {

192

193

194

196 } else {

197

198

200 }

202 }

203

204

205

207

208

209

210

211

212

213

216

217

219

221

222

225 int64_t FIOffset = (StackGrowsDown ? -Offset : Offset) + Entry.second;

226 LLVM_DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" << FIOffset

227 << "]\n");

229 }

230

232

233 MaxAlign = std::max(Alignment, MaxAlign);

234 }

235

236

237

238

239

243 continue;

245 continue;

246

248 }

249

250

251

253

254

255

258

259

260

261

262

263

264 Align StackAlign;

268 else

270

271

272

274 }

275

276

277 int64_t StackSize = Offset - LocalAreaOffset;

279}

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

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

Register const TargetRegisterInfo * TRI

MachineInstr unsigned OpIdx

Definition NVPTXPrologEpilogPass.cpp:56

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

static void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign)

AdjustStackOffset - Helper function used to adjust the stack frame offset.

MachineInstrBundleIterator< MachineInstr > iterator

The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.

bool hasVarSizedObjects() const

This method may be called any time after instruction selection is complete to determine if the stack ...

bool isObjectPreAllocated(int ObjectIdx) const

Return true if the object was pre-allocated into the local block.

bool adjustsStack() const

Return true if this function adjusts the stack – e.g., when calling another function.

int64_t getLocalFrameObjectCount() const

Return the number of objects allocated into the local object block.

Align getMaxAlign() const

Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...

Align getLocalFrameMaxAlign() const

Return the required alignment of the local object blob.

void setObjectOffset(int ObjectIdx, int64_t SPOffset)

Set the stack frame offset of the specified object.

std::pair< int, int64_t > getLocalFrameObjectMap(int i) const

Get the local offset mapping for a for an object.

uint64_t getMaxCallFrameSize() const

Return the maximum size of a call frame that must be allocated for an outgoing function call.

bool getUseLocalStackAllocationBlock() const

Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...

Align getObjectAlign(int ObjectIdx) const

Return the alignment of the specified stack object.

int64_t getObjectSize(int ObjectIdx) const

Return the size of the specified object.

int64_t getLocalFrameSize() const

Get the size of the local object blob.

int getObjectIndexEnd() const

Return one past the maximum frame object index.

int64_t getObjectOffset(int ObjectIdx) const

Return the assigned stack offset of the specified object from the incoming stack pointer.

void setStackSize(uint64_t Size)

Set the size of the stack.

int getObjectIndexBegin() const

Return the minimum frame object index.

bool isDeadObjectIndex(int ObjectIdx) const

Returns true if the specified index corresponds to a dead object.

MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

MachineFrameInfo & getFrameInfo()

getFrameInfo - Return the frame info object for the current function.

BasicBlockListType::iterator iterator

const MachineBasicBlock & front() const

Representation of each machine instruction.

StringRef - Represent a constant reference to a string, i.e.

Information about stack frame layout on the target.

virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0

virtual bool hasReservedCallFrame(const MachineFunction &MF) const

hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...

Align getTransientStackAlign() const

getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...

int getOffsetOfLocalArea() const

getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...

Align getStackAlign() const

getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...

StackDirection getStackGrowthDirection() const

getStackGrowthDirection - Return the direction the stack grows

virtual bool targetHandlesStackFrameRounding() const

targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...

virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0

emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.

TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...

bool hasStackRealignment(const MachineFunction &MF) const

True if stack realignment is required and still possible.

virtual const TargetFrameLowering * getFrameLowering() const

virtual const TargetRegisterInfo * getRegisterInfo() const =0

Return the target's register information.

constexpr char Align[]

Key for Kernel::Arg::Metadata::mAlign.

unsigned ID

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

This is an optimization pass for GlobalISel generic memory operations.

auto enumerate(FirstRange &&First, RestRanges &&...Rest)

Given two or more input ranges, returns a new range whose values are tuples (A, B,...

MachineFunctionPass * createNVPTXPrologEpilogPass()

Definition NVPTXPrologEpilogPass.cpp:46

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

DWARFExpression::Operation Op

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