forked from cgeyer/llvm-cbg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbgHWLoop.cpp
643 lines (533 loc) · 21.6 KB
/
cbgHWLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
/*
* cbgHWLoop.cpp
*
* Created on: Nov 1, 2011
* Author: cbg
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*/
#include "cbg.h"
#include "cbgInstrInfo.h"
#include "PredecessorList.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include <vector>
#include <list>
#include <iostream>
#if 0
#define DD_PRINT(func) {\
std::cerr << func << std::endl; \
}
#else
#define DD_PRINT(func)
#endif
using namespace llvm;
namespace {
class HWLoopPass : public MachineFunctionPass {
public:
typedef PredecessorList::MBB_list MBB_list;
static char ID;
struct LoopBounds {
bool isValidLoop;
bool needsIncrement;
MachineOperand LoopBound;
unsigned IndexVar;
};
private:
static bool isIncrement(const MachineInstr &instr);
static bool isDecrement(const MachineInstr &instr);
static bool isNoDestination(unsigned regNumber,
MachineBasicBlock &MBB,
MachineBasicBlock::reverse_iterator &mbb_iter);
static bool machineBasicBlockInSet(MachineBasicBlock* const &MBB, MBB_list &mbb_set);
static LoopBounds findLoopBound(MachineBasicBlock &MBB);
static void updatePredecessors(MachineBasicBlock* newMBB, MachineBasicBlock* MBB);
protected:
TargetMachine &TM;
unsigned LoopDepth;
unsigned LoopCount;
bool RemoveIndexVar;
virtual MBB_list getPossibleLoops(MachineBasicBlock &MBB) const;
virtual void insertSingleHWLoop(MachineBasicBlock &MBB, MachineOperand &MO, bool needsIncrement);
virtual void removeIndexVar(MachineBasicBlock &MBB, unsigned regNumber);
virtual void removeConditionalBranch(MachineBasicBlock &MBB);
public:
explicit HWLoopPass(TargetMachine &tm, unsigned loopDepth, bool rIndexVar) : MachineFunctionPass(ID), TM(tm),
LoopDepth(loopDepth),
LoopCount(0),
RemoveIndexVar(rIndexVar) {}
/*virtual bool doInitialization(Loop* loop, LPPassManager &LPM) { DD_PRINT(__func__); return false; }
virtual bool runOnLoop(Loop* loop, LPPassManager &LPM);
virtual bool doFinalization() { DD_PRINT(__func__); return false; }*/
bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
bool runOnMachineFunction(MachineFunction &F);
virtual const char *getPassName() const {
return "CBG HWloop pass";
}
};
char HWLoopPass::ID = 0;
}
/**
* @brief Returns whether a given MBB is already saved in the given list.
* @param MBB Given machine basic block to check.
* @param mbb_set Given list (set) of machine basic blocks.
* @return True if machine basic block is already part of the list, false otherwise.
*/
bool HWLoopPass::machineBasicBlockInSet(MachineBasicBlock* const &MBB, MBB_list &mbb_set) {
MBB_list::iterator mbb_iterator;
for (mbb_iterator = mbb_set.begin(); mbb_iterator != mbb_set.end(); ++mbb_iterator) {
if ((*mbb_iterator)->getNumber() == MBB->getNumber()) {
return true;
}
}
return false;
}
/**
* @brief Finds out all MBBs which may be involved in the smallest possible loop
* starting from MBB.
* @param MBB
* @return A list of MBBs which are part of the loop.
*/
HWLoopPass::MBB_list HWLoopPass::getPossibleLoops(MachineBasicBlock &MBB) const {
MBB_list possible_loops;
MBB_list all_successors;
MachineBasicBlock::succ_iterator s_iter;
MachineBasicBlock::succ_iterator s_end_iter = MBB.succ_end();
PredecessorList all_predecessors;
bool foundLoop;
// return empty vector if BB has no successor
if (MBB.succ_empty()) {
return possible_loops;
}
// insert current basic block as "root element" into predecessor
all_predecessors.insertRoot(&MBB);
// init successor set
for (s_iter = MBB.succ_begin(); s_iter != s_end_iter; ++s_iter) {
all_successors.push_back(*s_iter);
all_predecessors.insertSuccessor(*s_iter, &MBB);
if (((*s_iter)->getNumber() == MBB.getNumber()) && (!machineBasicBlockInSet(&MBB, possible_loops))) {
possible_loops.push_back(&MBB);
// we have found a small basic block loop => ignore bigger ones
return possible_loops;
}
}
// add all successors to successor set
for (MBB_list::iterator suc_it = all_successors.begin();
suc_it != all_successors.end();
++suc_it) {
foundLoop = false;
s_end_iter = (*suc_it)->succ_end();
for (s_iter = (*suc_it)->succ_begin(); s_iter != s_end_iter; ++s_iter) {
// in any case, add predecessor to set
all_predecessors.insertSuccessor(*s_iter, const_cast<const MachineBasicBlock*&>(*suc_it));
// if successor of node in successor set is current BB, we have found a loop
if ((*s_iter)->getNumber() == MBB.getNumber()) {
possible_loops = all_predecessors.getPredecessors(const_cast<const MachineBasicBlock*&>(*suc_it));
foundLoop = true;
break;
} else {
// otherwise we have to add it to the successor set
if (!machineBasicBlockInSet(*s_iter, all_successors)) {
all_successors.push_back(*s_iter);
}
}
}
// we have found a loop, so exit current for loop
if (foundLoop) {
break;
}
}
return possible_loops;
}
/**
* @brief Changes the successor value of the predecessors of the old machine basic block,
* including jump labels.
* @param newMBB Inserted machine basic block, representing the hwloop initialization.
* @param MBB Old machine basic block, representing the simple loop.
*/
void HWLoopPass::updatePredecessors(MachineBasicBlock* newMBB, MachineBasicBlock* MBB) {
std::vector<MachineBasicBlock*> predecessors;
MachineBasicBlock::pred_iterator pred_iter;
for (pred_iter = MBB->pred_begin();
pred_iter != MBB->pred_end();
++pred_iter) {
// add all predecessors except own basic block to set
if (*pred_iter != MBB) {
predecessors.push_back(*pred_iter);
}
}
for (pred_iter = predecessors.begin();
pred_iter != predecessors.end();
++pred_iter) {
(*pred_iter)->removeSuccessor(MBB);
(*pred_iter)->addSuccessor(newMBB);
// update branch targets to old basic block
for (MachineBasicBlock::iterator instr_it = (*pred_iter)->begin();
instr_it != (*pred_iter)->end();
++instr_it) {
if ((instr_it->getOpcode() == CBG::BA) || (instr_it->getOpcode() == CBG::BCOND)) {
if (instr_it->getOperand(0).getMBB() == MBB) {
instr_it->getOperand(0).setMBB(newMBB);
}
}
// update hwloop branch targets
if (instr_it->getOpcode() == CBG::HWLOOPinit) {
if (instr_it->getOperand(1).isMBB() && instr_it->getOperand(1).getMBB() == MBB) {
instr_it->getOperand(1).setMBB(newMBB);
}
}
}
}
}
/**
* @brief Inserts a hwloop instruction before the given machine basic block.
* @param MBB The machine basic block representing the simple loop before which
* the hwloop instructions have to be inserted.
* @param MO The machine operand respresenting the loop bound. May either be an
* immediate or a register value.
* @param needsIncrement This boolean indicates, whether the given loop bound register in MO
* has to be incremented before initialization. (Compare while
* (index < loopbound) vs. (index <= loopbound)).
*/
void HWLoopPass::insertSingleHWLoop(MachineBasicBlock &MBB, MachineOperand &MO, bool needsIncrement) {
// get current function
MachineFunction *F = MBB.getParent();
const BasicBlock *LLVM_BB = MBB.getBasicBlock();
// if we have to increment the loop bound register, we have
// have to find an unused register
TargetRegisterClass::iterator reg_iter;
// create new machine basic block in current function
MachineBasicBlock* newMBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineFunction::iterator func_it = F->begin();
MachineInstrBuilder mi;
DebugLoc dbg_loc = newMBB->begin()->getDebugLoc();
// search current basic block
while ((*func_it).getNumber() != MBB.getNumber()) {
++func_it;
}
++func_it;
// insert new basic block in current position
F->insert(func_it, newMBB);
newMBB->moveBefore(&MBB);
// initialize all howloop registers:
mi = BuildMI(*newMBB, newMBB->end(), dbg_loc, TM.getInstrInfo()->get(CBG::HWLOOPinit));
mi.addReg(CBG::HWLOOP1, RegState::Define).addMBB(&MBB);
mi = BuildMI(*newMBB, newMBB->end(), dbg_loc, TM.getInstrInfo()->get(CBG::HWLOOPinit));
mi.addReg(CBG::HWLOOP2, RegState::Define).addMBB(MBB.getNextNode());
// if the needsIncrement boolean is set, we have to increment
// the register value before using it
if (needsIncrement) {
// get next free register number
reg_iter = CBG::IntRegsRegisterClass->allocation_order_begin(*F);
while (MBB.isLiveIn(*reg_iter)) {
++reg_iter;
}
mi = BuildMI(*newMBB, newMBB->end(), dbg_loc, TM.getInstrInfo()->get(CBG::ADDri));
mi.addReg(*reg_iter, RegState::Define).addReg(MO.getReg()).addImm(1);
mi = BuildMI(*newMBB, newMBB->end(), dbg_loc, TM.getInstrInfo()->get(CBG::HWLOOPinit));
mi.addReg(CBG::HWLOOP3, RegState::Define).addReg(*reg_iter, RegState::Kill);
} else {
mi = BuildMI(*newMBB, newMBB->end(), dbg_loc, TM.getInstrInfo()->get(CBG::HWLOOPinit));
mi.addReg(CBG::HWLOOP3, RegState::Define).addOperand(MO);
}
// insert hardware loop instruction at end of new block
mi = BuildMI(*newMBB, newMBB->end(), dbg_loc, TM.getInstrInfo()->get(CBG::HWLOOP));
// update all predecessors of old block
updatePredecessors(newMBB, &MBB);
newMBB->addSuccessor(&MBB);
newMBB->addSuccessor(MBB.getNextNode());
F->RenumberBlocks(newMBB);
}
/**
* @brief Checks, whether the current instruction simply increments
* a register by adding "1".
* @param instr Machine instruction to check.
* @return True, if the register is incrementend, false otherwise.
*/
bool HWLoopPass::isIncrement(const MachineInstr &instr) {
int opCode = instr.getOpcode();
int incrementValue;
bool isIncrement = false;
// we only allow ADDri and SUBri to be valid
// incremental instructions
if (opCode == CBG::ADDri) {
// if we have an ADDri instruction, the increment
// value has to be +1
incrementValue = instr.getOperand(2).getImm();
if (incrementValue == 1) {
isIncrement = true;
}
} else if (opCode == CBG::SUBri) {
// if we have a SUBri instruction, the increment
// value has to be -1
incrementValue = instr.getOperand(2).getImm();
if (incrementValue == -1) {
isIncrement = true;
}
}
// else => we have no increment instruction
return isIncrement;
}
/**
* @brief Checks, whether the current instruction simply decrements
* a register by subtracting "1".
* @param instr Machine instruction to check.
* @return True, if the register is decrementend, false otherwise.
*/
bool HWLoopPass::isDecrement(const MachineInstr &instr) {
int opCode = instr.getOpcode();
int decrementValue;
bool isDecrement = false;
// we only allow ADDri and SUBri to be valid
// incremental instructions
if (opCode == CBG::ADDri) {
// if we have an ADDri instruction, the decrement
// value has to be -1
decrementValue = instr.getOperand(2).getImm();
if (decrementValue == -1) {
isDecrement = true;
}
} else if (opCode == CBG::SUBri) {
// if we have a SUBri instruction, the decrement
// value has to be 1
decrementValue = instr.getOperand(2).getImm();
if (decrementValue == 1) {
isDecrement = true;
}
}
// else => we have no increment instruction
return isDecrement;
}
/**
* @brief Checks, whether the given register number is no destination register of any
* previous instruction within the current machine basic block.
* @param regNumber Register number to check.
* @param MBB Current machine basic block.
* @param mbb_iter Reverse iterater, indicating the last instruction within the
* current machine basic block where check has to start.
* @return True if the current register is no destination register in any previous
* instruction of the current machine basic block, false otherwise.
*/
bool HWLoopPass::isNoDestination(unsigned regNumber,
MachineBasicBlock &MBB,
MachineBasicBlock::reverse_iterator &mbb_iter) {
bool isNoDestination = true;
// check the whole basic block whether the given register
// is the destination of any instruction
for (; mbb_iter != MBB.rend(); ++mbb_iter) {
// only check if the destination is a valid register
if (mbb_iter->getNumOperands() > 0 && mbb_iter->getOperand(0).isReg()) {
// if the destination register of current instruction
// is equal to given regNumber, we have to stop
if (mbb_iter->getOperand(0).getReg() == regNumber) {
isNoDestination = false;
break;
}
}
}
return isNoDestination;
}
/**
* @brief Tries to guess the index variable (register) and loop bound (register or
* immediate) of the given MBB which has to be a loop.
* @param MBB Block to check.
* @return A struct which indicates whether the block is a valid loop we can handle,
* whether the loop bound has to be incremented, the loop bound as machine
* operand and the register number of the index variable.
*/
HWLoopPass::LoopBounds HWLoopPass::findLoopBound(MachineBasicBlock &MBB) {
MachineBasicBlock::reverse_iterator mbb_iter = MBB.rbegin();
MachineBasicBlock::reverse_iterator mbb_tmp_iter;
MachineBasicBlock::reverse_iterator mbb_tmp_iter2;
MachineOperand* possibleLoopBound;
MachineOperand* possibleIndexVar;
unsigned branchCond = 0;
MachineOperand LoopBound = MachineOperand::CreateImm(0);
unsigned IndexVar = 0;
LoopBounds returnValue = {false, false, LoopBound, IndexVar};
unsigned OpCode;
// (1) last instruction has to be a conditional branch with target to
// current basic block
if ((mbb_iter->getOpcode() == CBG::BCOND) &&
(mbb_iter->getOperand(0).getMBB() == &MBB)) {
branchCond = mbb_iter->getOperand(1).getImm();
do {
++mbb_iter;
OpCode = mbb_iter->getOpcode();
if (OpCode == CBG::SUBCCri || OpCode == CBG::SUBCCrr || OpCode == CBG::ADDCCri || OpCode == CBG::ADDCCrr) {
break;
}
} while (mbb_iter != MBB.rend());
// std::cerr << "Last instruction of BB#" << MBB.getNumber() << " was conditional branch." << std::endl;
// std::cerr << "Opcode of second last instruction: " << mbb_iter->getOpcode() << std::endl;
// (2) second last instruction only can be a SUBCCrx
if ((mbb_iter != MBB.rend()) &&
((mbb_iter->getOpcode() == CBG::SUBCCri) || (mbb_iter->getOpcode() == CBG::SUBCCrr))) {
// std::cerr << "Second last instruction was SUBCCrx." << std::endl;
// result of compare operation will be ignored
if (mbb_iter->getOperand(0).isDead()) {
// std::cerr << "Result of compare operation will not be used any more." << std::endl;
possibleIndexVar = &(mbb_iter->getOperand(1));
possibleLoopBound = &(mbb_iter->getOperand(2));
++mbb_iter;
while (mbb_iter != MBB.rend()) {
OpCode = mbb_iter->getOpcode();
if (OpCode == CBG::SUBri || OpCode == CBG::SUBrr || OpCode == CBG::ADDri || OpCode == CBG::ADDrr) {
break;
}
++mbb_iter;
}
if (mbb_iter != MBB.rend()) {
// (3) src1 register may only be the destination of a predecessing increment or decrement
// (3)(a) if idx is decremented, we only allow immediates to be loop bounds
if ( isDecrement(*mbb_iter) &&
possibleLoopBound->isImm() &&
(possibleLoopBound->getImm() <= 0)) {
mbb_tmp_iter = mbb_iter;
++mbb_tmp_iter;
if (isNoDestination(possibleIndexVar->getReg(), MBB, mbb_tmp_iter)) {
// if immediate is less that 0, we simply have to change sign
if (possibleLoopBound->getImm() < 0) {
// std::cerr << "Found constant loop bound " << (-1 * possibleLoopBound->getImm()) << std::endl;
returnValue.LoopBound.setImm(-1 * possibleLoopBound->getImm());
returnValue.IndexVar = possibleIndexVar->getReg();
} else {
// if immediate is zero, index variable contains loop bound
// std::cerr << "Found loop bound in register " << possibleIndexVar->getReg() << std::endl;
returnValue.LoopBound.ChangeToRegister(possibleIndexVar->getReg(), false);
returnValue.IndexVar = possibleIndexVar->getReg();
if (branchCond == CBGCC::ICC_LE) {
returnValue.needsIncrement = true;
}
}
returnValue.isValidLoop = true;
}
}
// (3)(b) if idx is incremented and compared with constant
else if( isIncrement(*mbb_iter) &&
possibleLoopBound->isImm() &&
(possibleLoopBound->getImm() > 0)) {
mbb_tmp_iter = mbb_iter;
++mbb_tmp_iter;
if (isNoDestination(possibleIndexVar->getReg(), MBB, mbb_tmp_iter)) {
// std::cerr << "Found constant loop bound " << possibleLoopBound->getImm() << std::endl;
returnValue.LoopBound.setImm(possibleLoopBound->getImm());
returnValue.IndexVar = possibleIndexVar->getReg();
returnValue.isValidLoop = true;
}
}
// (3)(c) if idx is incremented and compared with a constant register
else if( isIncrement(*mbb_iter) &&
possibleLoopBound->isReg()) {
mbb_tmp_iter = mbb_iter;
++mbb_tmp_iter;
mbb_tmp_iter2 = mbb_tmp_iter;
// neither index variable, nor loop bound register may be used as
// destination register
if (isNoDestination(possibleIndexVar->getReg(), MBB, mbb_tmp_iter) &&
isNoDestination(possibleLoopBound->getReg(), MBB, mbb_tmp_iter2)) {
// std::cerr << "Found register loop bound in register " << possibleLoopBound->getReg() << std::endl;
returnValue.LoopBound.ChangeToRegister(possibleLoopBound->getReg(), false);
returnValue.IndexVar = possibleIndexVar->getReg();
returnValue.isValidLoop = true;
if (branchCond == CBGCC::ICC_LE) {
returnValue.needsIncrement = true;
}
}
}
}
}
}
}
return returnValue;
}
/**
* @brief Removes last conditional branch at the end of the given machine basic block.
* @param MBB Machine basic block to check.
*/
void HWLoopPass::removeConditionalBranch(MachineBasicBlock &MBB) {
MachineBasicBlock::reverse_iterator mbb_iter;
// remove last two instructions (conditional branch and compare)
MBB.rbegin()->eraseFromParent();
mbb_iter = MBB.rbegin();
while (mbb_iter != MBB.rend()) {
if (mbb_iter->getOpcode() == CBG::SUBCCri || mbb_iter->getOpcode() == CBG::SUBCCrr) {
mbb_iter->eraseFromParent();
break;
}
++mbb_iter;
}
}
/**
* @brief Tries to remove all instructions of the given basic block where the
* index register is involved if this is possible.
* @param MBB Machine basic block to check.
* @param regNumber Register number containing the index variable.
*/
void HWLoopPass::removeIndexVar(MachineBasicBlock &MBB, unsigned regNumber) {
MachineBasicBlock::reverse_iterator mbb_iter;
bool isUsed = false;
// check, whether loop index is used as input for any other value
for (mbb_iter = MBB.rbegin(); mbb_iter != MBB.rend(); ++mbb_iter) {
for (unsigned numOps = 1; numOps < mbb_iter->getNumOperands(); ++numOps) {
if ( mbb_iter->getOperand(numOps).isReg() &&
(mbb_iter->getOperand(numOps).getReg() == regNumber)) {
if (!isDecrement(*mbb_iter) && !isIncrement(*mbb_iter)) {
isUsed = true;
break;
}
}
}
if (isUsed) {
break;
}
}
// we can remove last increment/decrement instruction, if index var is not used
if (!isUsed) {
for (mbb_iter = MBB.rbegin(); mbb_iter != MBB.rend(); ++mbb_iter) {
if ( mbb_iter->getOperand(0).isReg() &&
(mbb_iter->getOperand(0).getReg() == regNumber)) {
if (isDecrement(*mbb_iter) || isIncrement(*mbb_iter)) {
mbb_iter->eraseFromParent();
break;
}
}
}
}
}
bool HWLoopPass::runOnMachineFunction(MachineFunction &F) {
bool Changed = false;
MBB_list possible_loops;
for (MachineFunction::iterator FI = F.begin(), FE = F.end();
FI != FE; ++FI) {
possible_loops = getPossibleLoops(*FI);
if (possible_loops.size() == 1) {
// std::cerr << "Found loop candidate..." << std::endl;
// FI->dump();
Changed |= runOnMachineBasicBlock(*FI);
}
}
return Changed;
}
bool HWLoopPass::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
LoopBounds loopOperand = findLoopBound(MBB);
// std::cerr << "Valid loop: " << loopOperand.isValidLoop << std::endl;
if (loopOperand.isValidLoop) {
insertSingleHWLoop(MBB, loopOperand.LoopBound, loopOperand.needsIncrement);
removeConditionalBranch(MBB);
// only remove index variable if option is specified
if (RemoveIndexVar) {
removeIndexVar(MBB, loopOperand.IndexVar);
}
return true;
}
return false;
}
FunctionPass* llvm::createcbgHWLoopPass(TargetMachine &tm, unsigned loopDepth, bool rIndexVar) {
DD_PRINT(__func__);
return new HWLoopPass(tm, loopDepth, rIndexVar);
}