LLVM 24.0.0git
HardwareLoops.cpp
Go to the documentation of this file.
1//===-- HardwareLoops.cpp - Target Independent Hardware Loops --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// Insert hardware loop intrinsics into loops which are deemed profitable by
10/// the target, by querying TargetTransformInfo. A hardware loop comprises of
11/// two intrinsics: one, outside the loop, to set the loop iteration count and
12/// another, in the exit block, to decrement the counter. The decremented value
13/// can either be carried through the loop via a phi or handled in some opaque
14/// way by the target.
15///
16//===----------------------------------------------------------------------===//
17
19#include "CodeGenOptions.h"
20#include "llvm/ADT/Statistic.h"
28#include "llvm/CodeGen/Passes.h"
29#include "llvm/IR/BasicBlock.h"
30#include "llvm/IR/Constants.h"
31#include "llvm/IR/Dominators.h"
32#include "llvm/IR/IRBuilder.h"
34#include "llvm/IR/Value.h"
36#include "llvm/Pass.h"
37#include "llvm/Support/Debug.h"
43
44#define DEBUG_TYPE "hardware-loops"
45
46#define HW_LOOPS_NAME "Hardware Loop Insertion"
47
48using namespace llvm;
49
50STATISTIC(NumHWLoops, "Number of loops converted to hardware loops");
51
52#ifndef NDEBUG
53static void debugHWLoopFailure(const StringRef DebugMsg,
54 Instruction *I) {
55 dbgs() << "HWLoops: " << DebugMsg;
56 if (I)
57 dbgs() << ' ' << *I;
58 else
59 dbgs() << '.';
60 dbgs() << '\n';
61}
62#endif
63
66 BasicBlock *CodeRegion = L->getHeader();
67 DebugLoc DL = L->getStartLoc();
68
69 if (I) {
70 CodeRegion = I->getParent();
71 // If there is no debug location attached to the instruction, revert back to
72 // using the loop's.
73 if (I->getDebugLoc())
74 DL = I->getDebugLoc();
75 }
76
77 OptimizationRemarkAnalysis R(DEBUG_TYPE, RemarkName, DL, CodeRegion);
78 R << "hardware-loop not created: ";
79 return R;
80}
81
82namespace {
83
84 void reportHWLoopFailure(const StringRef Msg, const StringRef ORETag,
85 OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I = nullptr) {
87 ORE->emit(createHWLoopAnalysis(ORETag, TheLoop, I) << Msg);
88 }
89
90 class HardwareLoopsLegacy : public FunctionPass {
91 public:
92 static char ID;
93
94 HardwareLoopsLegacy() : FunctionPass(ID) {}
95
96 bool runOnFunction(Function &F) override;
97
98 void getAnalysisUsage(AnalysisUsage &AU) const override {
99 AU.addRequired<LoopInfoWrapperPass>();
100 AU.addPreserved<LoopInfoWrapperPass>();
101 AU.addRequired<DominatorTreeWrapperPass>();
102 AU.addPreserved<DominatorTreeWrapperPass>();
103 AU.addRequired<ScalarEvolutionWrapperPass>();
104 AU.addPreserved<ScalarEvolutionWrapperPass>();
105 AU.addRequired<AssumptionCacheTracker>();
106 AU.addRequired<TargetTransformInfoWrapperPass>();
107 AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
108 AU.addPreserved<BranchProbabilityInfoWrapperPass>();
109 }
110 };
111
112 class HardwareLoopsImpl {
113 public:
114 HardwareLoopsImpl(ScalarEvolution &SE, LoopInfo &LI, bool PreserveLCSSA,
115 DominatorTree &DT, const TargetTransformInfo &TTI,
116 TargetLibraryInfo *TLI, AssumptionCache &AC,
117 OptimizationRemarkEmitter *ORE, HardwareLoopOptions &Opts)
118 : SE(SE), LI(LI), PreserveLCSSA(PreserveLCSSA), DT(DT), TTI(TTI),
119 TLI(TLI), AC(AC), ORE(ORE), Opts(Opts) {}
120
121 bool run(Function &F);
122
123 private:
124 // Try to convert the given Loop into a hardware loop.
125 bool TryConvertLoop(Loop *L, LLVMContext &Ctx);
126
127 // Given that the target believes the loop to be profitable, try to
128 // convert it.
129 bool TryConvertLoop(HardwareLoopInfo &HWLoopInfo);
130
131 ScalarEvolution &SE;
132 LoopInfo &LI;
133 bool PreserveLCSSA;
134 DominatorTree &DT;
135 const TargetTransformInfo &TTI;
136 TargetLibraryInfo *TLI = nullptr;
137 AssumptionCache &AC;
138 OptimizationRemarkEmitter *ORE;
139 HardwareLoopOptions &Opts;
140 bool MadeChange = false;
141 };
142
143 class HardwareLoop {
144 // Expand the trip count scev into a value that we can use.
145 Value *InitLoopCount();
146
147 // Insert the set_loop_iteration intrinsic.
148 Value *InsertIterationSetup(Value *LoopCountInit);
149
150 // Insert the loop_decrement intrinsic.
151 void InsertLoopDec();
152
153 // Insert the loop_decrement_reg intrinsic.
154 Instruction *InsertLoopRegDec(Value *EltsRem);
155
156 // If the target requires the counter value to be updated in the loop,
157 // insert a phi to hold the value. The intended purpose is for use by
158 // loop_decrement_reg.
159 PHINode *InsertPHICounter(Value *NumElts, Value *EltsRem);
160
161 // Create a new cmp, that checks the returned value of loop_decrement*,
162 // and update the exit branch to use it.
163 void UpdateBranch(Value *EltsRem);
164
165 public:
166 HardwareLoop(HardwareLoopInfo &Info, ScalarEvolution &SE,
167 OptimizationRemarkEmitter *ORE, HardwareLoopOptions &Opts)
168 : SE(SE), ORE(ORE), Opts(Opts), L(Info.L), ExitCount(Info.ExitCount),
169 CountType(Info.CountType), ExitBranch(Info.ExitBranch),
170 LoopDecrement(Info.LoopDecrement), UsePHICounter(Info.CounterInReg),
171 UseLoopGuard(Info.PerformEntryTest) {}
172
173 void Create();
174
175 private:
176 ScalarEvolution &SE;
177 OptimizationRemarkEmitter *ORE = nullptr;
178 HardwareLoopOptions &Opts;
179 Loop *L = nullptr;
180 const SCEV *ExitCount = nullptr;
181 Type *CountType = nullptr;
182 CondBrInst *ExitBranch = nullptr;
183 Value *LoopDecrement = nullptr;
184 bool UsePHICounter = false;
185 bool UseLoopGuard = false;
186 BasicBlock *BeginBB = nullptr;
187 };
188}
189
190char HardwareLoopsLegacy::ID = 0;
191
192bool HardwareLoopsLegacy::runOnFunction(Function &F) {
193 if (skipFunction(F))
194 return false;
195
196 LLVM_DEBUG(dbgs() << "HWLoops: Running on " << F.getName() << "\n");
197
198 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
199 auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
200 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
201 auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
202 auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
203 auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
204 auto *TLI = TLIP ? &TLIP->getTLI(F) : nullptr;
205 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
206 bool PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
207
208 const CodeGenOptions &CGOpts = getCodeGenOptions(F);
209 HardwareLoopOptions Opts;
210 Opts.Force = toOptional(CGOpts.force_hardware_loops);
211 Opts.ForcePhi = toOptional(CGOpts.force_hardware_loop_phi);
212 Opts.ForceNested = toOptional(CGOpts.force_nested_hardware_loop);
213 Opts.ForceGuard = toOptional(CGOpts.force_hardware_loop_guard);
214 Opts.Decrement = CGOpts.hardware_loop_decrement;
215 Opts.Bitwidth = CGOpts.hardware_loop_counter_bitwidth;
216
217 HardwareLoopsImpl Impl(SE, LI, PreserveLCSSA, DT, TTI, TLI, AC, ORE, Opts);
218 return Impl.run(F);
219}
220
223 auto &LI = AM.getResult<LoopAnalysis>(F);
224 auto &SE = AM.getResult<ScalarEvolutionAnalysis>(F);
225 auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
226 auto &TTI = AM.getResult<TargetIRAnalysis>(F);
227 auto *TLI = &AM.getResult<TargetLibraryAnalysis>(F);
228 auto &AC = AM.getResult<AssumptionAnalysis>(F);
230
231 HardwareLoopsImpl Impl(SE, LI, true, DT, TTI, TLI, AC, ORE, Opts);
232 bool Changed = Impl.run(F);
233 if (!Changed)
234 return PreservedAnalyses::all();
235
241 return PA;
242}
243
244bool HardwareLoopsImpl::run(Function &F) {
245 LLVMContext &Ctx = F.getContext();
246 for (Loop *L : LI)
247 if (L->isOutermost())
248 TryConvertLoop(L, Ctx);
249 return MadeChange;
250}
251
252// Return true if the search should stop, which will be when an inner loop is
253// converted and the parent loop doesn't support containing a hardware loop.
254bool HardwareLoopsImpl::TryConvertLoop(Loop *L, LLVMContext &Ctx) {
255 // Process nested loops first.
256 bool AnyChanged = false;
257 for (Loop *SL : *L)
258 AnyChanged |= TryConvertLoop(SL, Ctx);
259 if (AnyChanged) {
260 reportHWLoopFailure("nested hardware-loops not supported", "HWLoopNested",
261 ORE, L);
262 return true; // Stop search.
263 }
264
265 LLVM_DEBUG(dbgs() << "HWLoops: Loop " << L->getHeader()->getName() << "\n");
266
267 HardwareLoopInfo HWLoopInfo(L);
268 if (!HWLoopInfo.canAnalyze(LI)) {
269 reportHWLoopFailure("cannot analyze loop, irreducible control flow",
270 "HWLoopCannotAnalyze", ORE, L);
271 return false;
272 }
273
274 if (!Opts.Force &&
275 !TTI.isHardwareLoopProfitable(L, SE, AC, TLI, HWLoopInfo)) {
276 reportHWLoopFailure("it's not profitable to create a hardware-loop",
277 "HWLoopNotProfitable", ORE, L);
278 return false;
279 }
280
281 // Allow overriding of the counter width and loop decrement value.
282 if (Opts.Bitwidth.has_value()) {
283 HWLoopInfo.CountType = IntegerType::get(Ctx, Opts.Bitwidth.value());
284 }
285
286 if (Opts.Decrement.has_value())
287 HWLoopInfo.LoopDecrement =
288 ConstantInt::get(HWLoopInfo.CountType, Opts.Decrement.value());
289
290 MadeChange |= TryConvertLoop(HWLoopInfo);
291 return MadeChange && (!HWLoopInfo.IsNestingLegal && !Opts.ForceNested);
292}
293
294bool HardwareLoopsImpl::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
295
296 Loop *L = HWLoopInfo.L;
297 LLVM_DEBUG(dbgs() << "HWLoops: Try to convert profitable loop: " << *L);
298
299 if (!HWLoopInfo.isHardwareLoopCandidate(SE, LI, DT, Opts.getForceNested(),
300 Opts.getForcePhi())) {
301 // TODO: there can be many reasons a loop is not considered a
302 // candidate, so we should let isHardwareLoopCandidate fill in the
303 // reason and then report a better message here.
304 reportHWLoopFailure("loop is not a candidate", "HWLoopNoCandidate", ORE, L);
305 return false;
306 }
307
308 assert(
309 (HWLoopInfo.ExitBlock && HWLoopInfo.ExitBranch && HWLoopInfo.ExitCount) &&
310 "Hardware Loop must have set exit info.");
311
312 BasicBlock *Preheader = L->getLoopPreheader();
313
314 // If we don't have a preheader, then insert one.
315 if (!Preheader)
316 Preheader = InsertPreheaderForLoop(L, &DT, &LI, nullptr, PreserveLCSSA);
317 if (!Preheader)
318 return false;
319
320 HardwareLoop HWLoop(HWLoopInfo, SE, ORE, Opts);
321 HWLoop.Create();
322 ++NumHWLoops;
323 return true;
324}
325
326void HardwareLoop::Create() {
327 LLVM_DEBUG(dbgs() << "HWLoops: Converting loop..\n");
328
329 Value *LoopCountInit = InitLoopCount();
330 if (!LoopCountInit) {
331 reportHWLoopFailure("could not safely create a loop count expression",
332 "HWLoopNotSafe", ORE, L);
333 return;
334 }
335
336 Value *Setup = InsertIterationSetup(LoopCountInit);
337
338 if (UsePHICounter || Opts.ForcePhi) {
339 Instruction *LoopDec = InsertLoopRegDec(LoopCountInit);
340 Value *EltsRem = InsertPHICounter(Setup, LoopDec);
341 LoopDec->setOperand(0, EltsRem);
342 UpdateBranch(LoopDec);
343 } else
344 InsertLoopDec();
345
346 // Run through the basic blocks of the loop and see if any of them have dead
347 // PHIs that can be removed.
348 for (auto *I : L->blocks())
350}
351
352static bool CanGenerateTest(Loop *L, Value *Count) {
353 BasicBlock *Preheader = L->getLoopPreheader();
354 if (!Preheader->getSinglePredecessor())
355 return false;
356
357 BasicBlock *Pred = Preheader->getSinglePredecessor();
358 auto *BI = dyn_cast<CondBrInst>(Pred->getTerminator());
359 if (!BI || !isa<ICmpInst>(BI->getCondition()))
360 return false;
361
362 // Check that the icmp is checking for equality of Count and zero and that
363 // a non-zero value results in entering the loop.
364 auto ICmp = cast<ICmpInst>(BI->getCondition());
365 LLVM_DEBUG(dbgs() << " - Found condition: " << *ICmp << "\n");
366 if (!ICmp->isEquality())
367 return false;
368
369 auto IsCompareZero = [](ICmpInst *ICmp, Value *Count, unsigned OpIdx) {
370 if (auto *Const = dyn_cast<ConstantInt>(ICmp->getOperand(OpIdx)))
371 return Const->isZero() && ICmp->getOperand(OpIdx ^ 1) == Count;
372 return false;
373 };
374
375 // Check if Count is a zext.
376 Value *CountBefZext =
377 isa<ZExtInst>(Count) ? cast<ZExtInst>(Count)->getOperand(0) : nullptr;
378
379 if (!IsCompareZero(ICmp, Count, 0) && !IsCompareZero(ICmp, Count, 1) &&
380 !IsCompareZero(ICmp, CountBefZext, 0) &&
381 !IsCompareZero(ICmp, CountBefZext, 1))
382 return false;
383
384 unsigned SuccIdx = ICmp->getPredicate() == ICmpInst::ICMP_NE ? 0 : 1;
385 if (BI->getSuccessor(SuccIdx) != Preheader)
386 return false;
387
388 return true;
389}
390
391Value *HardwareLoop::InitLoopCount() {
392 LLVM_DEBUG(dbgs() << "HWLoops: Initialising loop counter value:\n");
393 // Can we replace a conditional branch with an intrinsic that sets the
394 // loop counter and tests that is not zero?
395
396 SCEVExpander SCEVE(SE, "loopcnt");
397 if (!ExitCount->getType()->isPointerTy() &&
398 ExitCount->getType() != CountType)
399 ExitCount = SE.getZeroExtendExpr(ExitCount, CountType);
400
401 ExitCount = SE.getAddExpr(ExitCount, SE.getOne(CountType));
402
403 // If we're trying to use the 'test and set' form of the intrinsic, we need
404 // to replace a conditional branch that is controlling entry to the loop. It
405 // is likely (guaranteed?) that the preheader has an unconditional branch to
406 // the loop header, so also check if it has a single predecessor.
407 if (SE.isLoopEntryGuardedByCond(L, ICmpInst::ICMP_NE, ExitCount,
408 SE.getZero(ExitCount->getType()))) {
409 LLVM_DEBUG(dbgs() << " - Attempting to use test.set counter.\n");
410 if (Opts.ForceGuard)
411 UseLoopGuard = true;
412 } else
413 UseLoopGuard = false;
414
415 BasicBlock *BB = L->getLoopPreheader();
416 if (UseLoopGuard && BB->getSinglePredecessor() &&
418 BasicBlock *Predecessor = BB->getSinglePredecessor();
419 // If it's not safe to create a while loop then don't force it and create a
420 // do-while loop instead
421 if (!SCEVE.isSafeToExpandAt(ExitCount, Predecessor->getTerminator()))
422 UseLoopGuard = false;
423 else
424 BB = Predecessor;
425 }
426
427 if (!SCEVE.isSafeToExpandAt(ExitCount, BB->getTerminator())) {
428 LLVM_DEBUG(dbgs() << "- Bailing, unsafe to expand ExitCount "
429 << *ExitCount << "\n");
430 return nullptr;
431 }
432
433 Value *Count = SCEVE.expandCodeFor(ExitCount, CountType,
434 BB->getTerminator());
435
436 // FIXME: We've expanded Count where we hope to insert the counter setting
437 // intrinsic. But, in the case of the 'test and set' form, we may fallback to
438 // the just 'set' form and in which case the insertion block is most likely
439 // different. It means there will be instruction(s) in a block that possibly
440 // aren't needed. The isLoopEntryGuardedByCond is trying to avoid this issue,
441 // but it's doesn't appear to work in all cases.
442
443 UseLoopGuard = UseLoopGuard && CanGenerateTest(L, Count);
444 BeginBB = UseLoopGuard ? BB : L->getLoopPreheader();
445 LLVM_DEBUG(dbgs() << " - Loop Count: " << *Count << "\n"
446 << " - Expanded Count in " << BB->getName() << "\n"
447 << " - Will insert set counter intrinsic into: "
448 << BeginBB->getName() << "\n");
449 return Count;
450}
451
452Value* HardwareLoop::InsertIterationSetup(Value *LoopCountInit) {
453 IRBuilder<> Builder(BeginBB->getTerminator());
454 if (BeginBB->getParent()->getAttributes().hasFnAttr(Attribute::StrictFP))
455 Builder.setIsFPConstrained(true);
456 Type *Ty = LoopCountInit->getType();
457 bool UsePhi = UsePHICounter || Opts.ForcePhi;
458 Intrinsic::ID ID = UseLoopGuard
459 ? (UsePhi ? Intrinsic::test_start_loop_iterations
460 : Intrinsic::test_set_loop_iterations)
461 : (UsePhi ? Intrinsic::start_loop_iterations
462 : Intrinsic::set_loop_iterations);
463 Value *LoopSetup = Builder.CreateIntrinsic(ID, Ty, LoopCountInit);
464
465 // Use the return value of the intrinsic to control the entry of the loop.
466 if (UseLoopGuard) {
467 Value *SetCount =
468 UsePhi ? Builder.CreateExtractValue(LoopSetup, 1) : LoopSetup;
469 auto *LoopGuard = cast<CondBrInst>(BeginBB->getTerminator());
470 LoopGuard->setCondition(SetCount);
471 if (LoopGuard->getSuccessor(0) != L->getLoopPreheader())
472 LoopGuard->swapSuccessors();
473 }
474 LLVM_DEBUG(dbgs() << "HWLoops: Inserted loop counter: " << *LoopSetup
475 << "\n");
476 if (UsePhi && UseLoopGuard)
477 LoopSetup = Builder.CreateExtractValue(LoopSetup, 0);
478 return !UsePhi ? LoopCountInit : LoopSetup;
479}
480
481void HardwareLoop::InsertLoopDec() {
482 IRBuilder<> CondBuilder(ExitBranch);
483 if (ExitBranch->getParent()->getParent()->getAttributes().hasFnAttr(
484 Attribute::StrictFP))
485 CondBuilder.setIsFPConstrained(true);
486
487 Value *Ops[] = { LoopDecrement };
488 Value *NewCond = CondBuilder.CreateIntrinsic(Intrinsic::loop_decrement,
489 LoopDecrement->getType(), Ops);
490 Value *OldCond = ExitBranch->getCondition();
491 ExitBranch->setCondition(NewCond);
492
493 // The false branch must exit the loop.
494 if (!L->contains(ExitBranch->getSuccessor(0)))
495 ExitBranch->swapSuccessors();
496
497 // The old condition may be dead now, and may have even created a dead PHI
498 // (the original induction variable).
500
501 LLVM_DEBUG(dbgs() << "HWLoops: Inserted loop dec: " << *NewCond << "\n");
502}
503
504Instruction* HardwareLoop::InsertLoopRegDec(Value *EltsRem) {
505 IRBuilder<> CondBuilder(ExitBranch);
506 if (ExitBranch->getParent()->getParent()->getAttributes().hasFnAttr(
507 Attribute::StrictFP))
508 CondBuilder.setIsFPConstrained(true);
509
510 Value *Ops[] = { EltsRem, LoopDecrement };
511 Value *Call = CondBuilder.CreateIntrinsic(Intrinsic::loop_decrement_reg,
512 {EltsRem->getType()}, Ops);
513
514 LLVM_DEBUG(dbgs() << "HWLoops: Inserted loop dec: " << *Call << "\n");
515 return cast<Instruction>(Call);
516}
517
518PHINode* HardwareLoop::InsertPHICounter(Value *NumElts, Value *EltsRem) {
519 BasicBlock *Preheader = L->getLoopPreheader();
520 BasicBlock *Header = L->getHeader();
521 BasicBlock *Latch = ExitBranch->getParent();
522 IRBuilder<> Builder(Header->getFirstNonPHIIt());
523 PHINode *Index = Builder.CreatePHI(NumElts->getType(), 2);
524 Index->addIncoming(NumElts, Preheader);
525 Index->addIncoming(EltsRem, Latch);
526 LLVM_DEBUG(dbgs() << "HWLoops: PHI Counter: " << *Index << "\n");
527 return Index;
528}
529
530void HardwareLoop::UpdateBranch(Value *EltsRem) {
531 IRBuilder<> CondBuilder(ExitBranch);
532 Value *NewCond =
533 CondBuilder.CreateICmpNE(EltsRem, ConstantInt::get(EltsRem->getType(), 0));
534 Value *OldCond = ExitBranch->getCondition();
535 ExitBranch->setCondition(NewCond);
536
537 // The false branch must exit the loop.
538 if (!L->contains(ExitBranch->getSuccessor(0)))
539 ExitBranch->swapSuccessors();
540
541 // The old condition may be dead now, and may have even created a dead PHI
542 // (the original induction variable).
544}
545
546INITIALIZE_PASS_BEGIN(HardwareLoopsLegacy, DEBUG_TYPE, HW_LOOPS_NAME, false, false)
547INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
548INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
549INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
550INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
551INITIALIZE_PASS_END(HardwareLoopsLegacy, DEBUG_TYPE, HW_LOOPS_NAME, false, false)
552
553FunctionPass *llvm::createHardwareLoopsLegacyPass() { return new HardwareLoopsLegacy(); }
const TargetLowering & TLI
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runOnFunction(Function &F, bool PostInlining)
#define DEBUG_TYPE
#define HW_LOOPS_NAME
static OptimizationRemarkAnalysis createHWLoopAnalysis(StringRef RemarkName, Loop *L, Instruction *I)
static void debugHWLoopFailure(const StringRef DebugMsg, Instruction *I)
static bool CanGenerateTest(Loop *L, Value *Count)
Defines an IR pass for the creation of hardware loops.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
const char * Msg
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:170
#define LLVM_DEBUG(...)
Definition Debug.h:119
This pass exposes codegen information to IR-level passes.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
A function analysis which provides an AssumptionCache.
LLVM Basic Block Representation.
Definition BasicBlock.h:61
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:212
LLVM_ABI const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:236
Analysis pass which computes BranchProbabilityInfo.
@ ICMP_NE
not equal
Definition InstrTypes.h:762
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:828
LLVM_ABI void swapSuccessors()
Swap the successors of this branch instruction.
void setCondition(Value *V)
Value * getCondition() const
BasicBlock * getSuccessor(unsigned i) const
A debug info location.
Definition DebugLoc.h:126
Analysis pass which computes a DominatorTree.
Definition Dominators.h:241
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition Function.h:329
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This instruction compares its operands according to the predicate given to the constructor.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Analysis pass that exposes the LoopInfo for a function.
Definition LoopInfo.h:598
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Diagnostic information for optimization analysis remarks.
The optimization diagnostic interface.
LLVM_ABI void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
Type * getType() const
Return the LLVM type of this SCEV expression.
Analysis pass that exposes the ScalarEvolution for a function.
LLVM_ABI bool isLoopEntryGuardedByCond(const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Test whether entry to the loop is protected by a conditional between LHS and RHS.
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
LLVM_ABI SCEVUse getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
LLVM_ABI SCEVUse getZeroExtendExpr(SCEVUse Op, Type *Ty, unsigned Depth=0)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Analysis pass providing the TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
LLVM_ABI bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const
Query the target whether it would be profitable to convert the given loop into a hardware loop.
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
void setOperand(unsigned i, Value *Val)
Definition User.h:212
Value * getOperand(unsigned i) const
Definition User.h:207
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
const ParentTy * getParent() const
Definition ilist_node.h:34
CallInst * Call
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI BasicBlock * InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
InsertPreheaderForLoop - Once we discover that a loop doesn't have a preheader, this method is called...
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
Definition Local.cpp:522
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, SmallPtrSetImpl< PHINode * > *KnownNonDeadPHIs=nullptr)
Examine each PHI in the given block and delete it if it is dead.
LLVM_ABI char & LCSSAID
Definition LCSSA.cpp:545
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
TargetTransformInfo TTI
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
constexpr std::optional< bool > toOptional(BoolOrDefault X)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI FunctionPass * createHardwareLoopsLegacyPass()
Create Hardware Loop pass.
const CodeGenOptions & getCodeGenOptions(const LLVMContext &C)
LLVM_ABI bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop=false, bool ForceHardwareLoopPHI=false)
std::optional< bool > Force
std::optional< bool > ForceGuard
std::optional< unsigned > Decrement
std::optional< unsigned > Bitwidth
std::optional< bool > ForcePhi
std::optional< bool > ForceNested