15
15
// /
16
16
// ===----------------------------------------------------------------------===//
17
17
18
- #include " llvm/Pass.h"
19
18
#include " llvm/PassRegistry.h"
20
19
#include " llvm/PassSupport.h"
21
20
#include " llvm/ADT/Statistic.h"
36
35
#include " llvm/IR/Value.h"
37
36
#include " llvm/Support/Debug.h"
38
37
#include " llvm/Transforms/Scalar.h"
39
- #include " llvm/Transforms/Utils.h"
40
38
#include " llvm/Transforms/Utils/BasicBlockUtils.h"
41
39
#include " llvm/Transforms/Utils/Local.h"
42
- #include " llvm/Transforms/Utils/LoopUtils.h"
43
40
44
41
#define DEBUG_TYPE " hardware-loops"
45
42
@@ -112,7 +109,6 @@ namespace {
112
109
const DataLayout *DL = nullptr ;
113
110
const TargetTransformInfo *TTI = nullptr ;
114
111
DominatorTree *DT = nullptr ;
115
- bool PreserveLCSSA = false ;
116
112
AssumptionCache *AC = nullptr ;
117
113
TargetLibraryInfo *LibInfo = nullptr ;
118
114
Module *M = nullptr ;
@@ -184,7 +180,6 @@ bool HardwareLoops::runOnFunction(Function &F) {
184
180
DL = &F.getParent ()->getDataLayout ();
185
181
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
186
182
LibInfo = TLIP ? &TLIP->getTLI () : nullptr ;
187
- PreserveLCSSA = mustPreserveAnalysisID (LCSSAID);
188
183
AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F);
189
184
M = F.getParent ();
190
185
@@ -230,25 +225,19 @@ bool HardwareLoops::TryConvertLoop(Loop *L) {
230
225
231
226
bool HardwareLoops::TryConvertLoop (HardwareLoopInfo &HWLoopInfo) {
232
227
233
- Loop *L = HWLoopInfo. L ;
234
- LLVM_DEBUG ( dbgs () << " HWLoops: Try to convert profitable loop: " << *L);
228
+ LLVM_DEBUG ( dbgs () << " HWLoops: Try to convert profitable loop: "
229
+ << *HWLoopInfo. L );
235
230
236
231
if (!HWLoopInfo.isHardwareLoopCandidate (*SE, *LI, *DT, ForceNestedLoop,
237
- ForceHardwareLoopPHI))
232
+ ForceHardwareLoopPHI,
233
+ ForceGuardLoopEntry))
238
234
return false ;
239
235
240
236
assert (
241
237
(HWLoopInfo.ExitBlock && HWLoopInfo.ExitBranch && HWLoopInfo.ExitCount ) &&
242
238
" Hardware Loop must have set exit info." );
243
239
244
- BasicBlock *Preheader = L->getLoopPreheader ();
245
-
246
- // If we don't have a preheader, then insert one.
247
- if (!Preheader)
248
- Preheader = InsertPreheaderForLoop (L, DT, LI, nullptr , PreserveLCSSA);
249
- if (!Preheader)
250
- return false ;
251
-
240
+ // Now start to converting...
252
241
HardwareLoop HWLoop (HWLoopInfo, *SE, *DL);
253
242
HWLoop.Create ();
254
243
++NumHWLoops;
@@ -257,10 +246,10 @@ bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
257
246
258
247
void HardwareLoop::Create () {
259
248
LLVM_DEBUG (dbgs () << " HWLoops: Converting loop..\n " );
260
-
249
+
261
250
Value *LoopCountInit = InitLoopCount ();
262
- if (!LoopCountInit)
263
- return ;
251
+
252
+ assert (LoopCountInit && " Hardware Loop must have a loop count " ) ;
264
253
265
254
InsertIterationSetup (LoopCountInit);
266
255
@@ -320,32 +309,22 @@ Value *HardwareLoop::InitLoopCount() {
320
309
// loop counter and tests that is not zero?
321
310
322
311
SCEVExpander SCEVE (SE, DL, " loopcnt" );
323
- if (!ExitCount->getType ()->isPointerTy () &&
324
- ExitCount->getType () != CountType)
325
- ExitCount = SE.getZeroExtendExpr (ExitCount, CountType);
326
-
327
- ExitCount = SE.getAddExpr (ExitCount, SE.getOne (CountType));
328
312
329
313
// If we're trying to use the 'test and set' form of the intrinsic, we need
330
314
// to replace a conditional branch that is controlling entry to the loop. It
331
315
// is likely (guaranteed?) that the preheader has an unconditional branch to
332
316
// the loop header, so also check if it has a single predecessor.
333
317
if (SE.isLoopEntryGuardedByCond (L, ICmpInst::ICMP_NE, ExitCount,
334
- SE.getZero (ExitCount->getType ()))) {
335
- LLVM_DEBUG (dbgs () << " - Attempting to use test.set counter.\n " );
318
+ SE.getZero (ExitCount->getType ())))
336
319
UseLoopGuard |= ForceGuardLoopEntry;
337
- } else
320
+ else
338
321
UseLoopGuard = false ;
339
322
340
323
BasicBlock *BB = L->getLoopPreheader ();
341
324
if (UseLoopGuard && BB->getSinglePredecessor () &&
342
- cast<BranchInst>(BB->getTerminator ())->isUnconditional ())
325
+ cast<BranchInst>(BB->getTerminator ())->isUnconditional ()) {
326
+ LLVM_DEBUG (dbgs () << " - Attempting to use test.set counter.\n " );
343
327
BB = BB->getSinglePredecessor ();
344
-
345
- if (!isSafeToExpandAt (ExitCount, BB->getTerminator (), SE)) {
346
- LLVM_DEBUG (dbgs () << " - Bailing, unsafe to expand ExitCount "
347
- << *ExitCount << " \n " );
348
- return nullptr ;
349
328
}
350
329
351
330
Value *Count = SCEVE.expandCodeFor (ExitCount, CountType,
0 commit comments