LLVM: lib/Target/ARM/ARMBlockPlacement.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

23

24using namespace llvm;

25

26#define DEBUG_TYPE "arm-block-placement"

27#define DEBUG_PREFIX "ARM Block Placement: "

28

29namespace llvm {

31private:

33 std::unique_ptr BBUtils = nullptr;

35

37

38public:

39 static char ID;

41

48

52 }

53};

54

55}

56

59}

60

62

64 false)

65

69 return &Terminator;

70 }

71 return nullptr;

72}

73

74

75

78 if (!Predecessor)

79 return nullptr;

80 MachineInstr *WlsInstr = findWLSInBlock(Predecessor);

81 if (WlsInstr)

82 return WlsInstr;

83 if (Predecessor->pred_size() == 1)

84 return findWLSInBlock(*Predecessor->pred_begin());

85 return nullptr;

86}

87

88

89

91

92

93

94

95

96

97

98

101 assert(WLS->getNextNode() == &Preheader->back());

105

106

107 WLS->getOperand(1).setIsKill(false);

108 if (WLS->getOpcode() == ARM::t2WhileLoopStartTP)

109 WLS->getOperand(2).setIsKill(false);

110

111

115

117 NewBlock->insert(NewBlock->end(), Br);

118

121

122

124 BuildMI(*NewBlock, Br, WLS->getDebugLoc(),

125 TII->get(WLS->getOpcode() == ARM::t2WhileLoopStartTP

126 ? ARM::t2DoLoopStartTP

127 : ARM::t2DoLoopStart));

128 MIB.add(WLS->getOperand(0));

129 MIB.add(WLS->getOperand(1));

130 if (WLS->getOpcode() == ARM::t2WhileLoopStartTP)

131 MIB.add(WLS->getOperand(2));

132

134 << "Reverting While Loop to Do Loop: " << *WLS << "\n");

135

137

140

142 BBUtils->computeAllBlockSizes();

143 BBUtils->adjustBBOffsetsAfter(Preheader);

144

145 return true;

146}

147

148

149

150

151

152

153

156 if (!WlsInstr)

157 return false;

158

161

162

164 return false;

166 return false;

170

171

172

173

174

175

176

177

178

179

180

182 ++It) {

186 continue;

188

189

190 if (WLSTarget == Predecessor) {

192 << "it would convert a WLS from forward to a "

193 << "backwards branching WLS\n");

194 RevertedWhileLoops.push_back(WlsInstr);

195 return false;

196 }

197 }

198 }

199

201 return true;

202}

203

204

205

207 bool Changed = false;

208 for (auto *InnerML : *ML)

211}

212

215 return false;

217 if (!ST.hasLOB())

218 return false;

220 MLI = &getAnalysis().getLI();

221 TII = static_cast<const ARMBaseInstrInfo *>(ST.getInstrInfo());

222 BBUtils = std::make_unique(MF);

224 BBUtils->computeAllBlockSizes();

225 BBUtils->adjustBBOffsetsAfter(&MF.front());

226 bool Changed = false;

227 RevertedWhileLoops.clear();

228

229

230 for (auto *ML : *MLI)

232

233

234 for (auto *WlsInstr : RevertedWhileLoops)

236

237 return Changed;

238}

239

242 return BBUtils->getOffsetOf(Other) > BBUtils->getOffsetOf(BB);

243}

244

245

249 << Before->getName() << "\n");

251 assert(BBPrevious && "Cannot move the function entry basic block");

253

256 "Cannot move the given block to before the function entry block");

259

260

261

262

265 << From->getName() << " to " << To->getName() << "\n");

267 "'To' is expected to be a successor of 'From'");

273 Terminator.isReturn()))

274 return;

275

276

278 BuildMI(From, Terminator.getDebugLoc(), TII->get(ARM::t2B));

281 MIB.addReg(ARM::NoRegister);

283 << From->getName() << " to " << To->getName() << ": "

285 };

286

287

289 FixFallthrough(BBPrevious, BB);

290

292 FixFallthrough(BeforePrev, Before);

293

295 FixFallthrough(BB, BBNext);

296

297 F->RenumberBlocks();

298 BBUtils->computeAllBlockSizes();

299 BBUtils->adjustBBOffsetsAfter(BB);

300}

static MachineInstr * findWLS(MachineLoop *ML)

Find WhileLoopStart in the loop predecessor BB or otherwise in its only predecessor.

BlockVerifier::State From

This file implements the LivePhysRegs utility for tracking liveness of physical registers.

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

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

bool isPredicated(const MachineInstr &MI) const override

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

bool runOnMachineFunction(MachineFunction &MF) override

runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...

bool revertWhileToDoLoop(MachineInstr *WLS)

void moveBasicBlock(MachineBasicBlock *BB, MachineBasicBlock *Before)

bool fixBackwardsWLS(MachineLoop *ML)

Checks if loop has a backwards branching WLS, and if possible, fixes it.

bool blockIsBefore(MachineBasicBlock *BB, MachineBasicBlock *Other)

bool processPostOrderLoops(MachineLoop *ML)

Updates ordering (of WLS BB and their loopExits) in inner loops first Returns true if any change was ...

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

FunctionPass class - This class is used to implement most global optimizations.

bool skipFunction(const Function &F) const

Optional passes call this function to check whether the pass should be skipped.

A set of physical registers with utility functions to track liveness when walking backward/forward th...

unsigned pred_size() const

void moveBefore(MachineBasicBlock *NewAfter)

Move 'this' block before or after the specified block.

void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)

Replace successor OLD with NEW and update probability info.

instr_iterator insert(instr_iterator I, MachineInstr *M)

Insert MI into the instruction list before I, possibly inside a bundle.

const BasicBlock * getBasicBlock() const

Return the LLVM basic block that this instance corresponded to originally.

void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())

Add Succ as a successor of this MachineBasicBlock.

pred_iterator pred_begin()

const MachineFunction * getParent() const

Return the MachineFunction containing this basic block.

std::string getFullName() const

Return a formatted string to identify this block and its parent function.

iterator_range< iterator > terminators()

bool isSuccessor(const MachineBasicBlock *MBB) const

Return true if the specified MBB is a successor of this block.

StringRef getName() const

Return the name of the corresponding LLVM basic block, or an empty string.

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

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

const TargetSubtargetInfo & getSubtarget() const

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

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

Function & getFunction()

Return the LLVM function that this machine code represents.

void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)

RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.

const MachineBasicBlock & front() const

MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)

CreateMachineBasicBlock - Allocate a new MachineBasicBlock.

void insert(iterator MBBI, MachineBasicBlock *MBB)

const MachineInstrBuilder & addImm(int64_t Val) const

Add a new immediate operand.

const MachineInstrBuilder & add(const MachineOperand &MO) const

const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const

Add a new virtual register operand.

const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const

MachineInstr * getInstr() const

If conversion operators fail, use this method to get the MachineInstr explicitly.

Representation of each machine instruction.

unsigned getOpcode() const

Returns the opcode of this MachineInstr.

MachineInstr * removeFromParent()

Unlink 'this' from the containing basic block, and return it without deleting it.

const MachineBasicBlock * getParent() const

const MachineOperand & getOperand(unsigned i) const

MachineBasicBlock * getMBB() const

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

self_iterator getIterator()

NodeTy * getNextNode()

Get the next node, or nullptr for the list tail.

This is an optimization pass for GlobalISel generic memory operations.

MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)

Builder interface. Specify how to create the initial instruction itself.

static bool isIndirectBranchOpcode(int Opc)

static bool isJumpTableBranchOpcode(int Opc)

FunctionPass * createARMBlockPlacementPass()

raw_ostream & dbgs()

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

void RevertWhileLoopStartLR(MachineInstr *MI, const TargetInstrInfo *TII, unsigned BrOpc=ARM::t2Bcc, bool UseCmp=false)

static bool isUncondBranchOpcode(int Opc)

MachineBasicBlock * getWhileLoopStartTargetBB(const MachineInstr &MI)

static bool isWhileLoopStart(const MachineInstr &MI)

void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)

Convenience function combining computeLiveIns() and addLiveIns().