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

53};

54

55}

56

60

62

64 false)

65

67 for (auto &Terminator : MBB->terminators()) {

68 if (isWhileLoopStart(Terminator))

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

105

106

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

110

111

115

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

118

121

122

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

126 ? ARM::t2DoLoopStartTP

127 : ARM::t2DoLoopStart));

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

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) {

184 for (auto &Terminator : MBB->terminators()) {

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

208 for (auto *InnerML : *ML)

211}

212

215 return false;

217 if (!ST.hasLOB())

218 return false;

221 TII = ST.getInstrInfo();

222 BBUtils = std::make_unique(MF);

224 BBUtils->computeAllBlockSizes();

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

227 RevertedWhileLoops.clear();

228

229

230 for (auto *ML : *MLI)

232

233

234 for (auto *WlsInstr : RevertedWhileLoops)

236

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'");

269 if (!TII->isPredicated(Terminator) &&

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}

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

static MachineInstr * findWLS(MachineLoop *ML)

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

Definition ARMBlockPlacement.cpp:76

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

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

ARMBlockPlacement()

Definition ARMBlockPlacement.cpp:40

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...

Definition ARMBlockPlacement.cpp:49

bool runOnMachineFunction(MachineFunction &MF) override

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

Definition ARMBlockPlacement.cpp:213

static char ID

Definition ARMBlockPlacement.cpp:39

bool revertWhileToDoLoop(MachineInstr *WLS)

Definition ARMBlockPlacement.cpp:90

void moveBasicBlock(MachineBasicBlock *BB, MachineBasicBlock *Before)

Definition ARMBlockPlacement.cpp:246

bool fixBackwardsWLS(MachineLoop *ML)

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

Definition ARMBlockPlacement.cpp:154

bool blockIsBefore(MachineBasicBlock *BB, MachineBasicBlock *Other)

Definition ARMBlockPlacement.cpp:240

bool processPostOrderLoops(MachineLoop *ML)

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

Definition ARMBlockPlacement.cpp:206

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...

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

unsigned pred_size() const

LLVM_ABI void moveBefore(MachineBasicBlock *NewAfter)

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

LLVM_ABI void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)

Replace successor OLD with NEW and update probability info.

LLVM_ABI 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.

LLVM_ABI 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.

LLVM_ABI std::string getFullName() const

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

iterator_range< iterator > terminators()

LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const

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

LLVM_ABI StringRef getName() const

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

MachineFunctionPass(char &ID)

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)

CreateMachineInstr - Allocate a new MachineInstr.

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.

LLVM_ABI MachineInstr * removeFromParent()

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

const MachineBasicBlock * getParent() const

const DebugLoc & getDebugLoc() const

Returns the debug location id of this MachineInstr.

const MachineOperand & getOperand(unsigned i) const

MachineBasicBlock * getMBB() const

void setIsKill(bool Val=true)

AnalysisType & getAnalysis() const

getAnalysis() - This function is used by subclasses to get to the analysis information ...

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()

Definition ARMBlockPlacement.cpp:57

LLVM_ABI 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().