LLVM 24.0.0git
BypassSlowDivision.cpp
Go to the documentation of this file.
1//===- BypassSlowDivision.cpp - Bypass slow division ----------------------===//
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//
9// This file contains an optimization for div and rem on architectures that
10// execute short instructions significantly faster than longer instructions.
11// For example, on Intel Atom 32-bit divides are slow enough that during
12// runtime it is profitable to check the value of the operands, and if they are
13// positive and less than 256 use an unsigned 8-bit divide.
14//
15//===----------------------------------------------------------------------===//
16
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/STLExtras.h"
25#include "llvm/IR/BasicBlock.h"
26#include "llvm/IR/Constants.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/IRBuilder.h"
30#include "llvm/IR/Instruction.h"
32#include "llvm/IR/Type.h"
33#include "llvm/IR/Value.h"
38#include <cassert>
39#include <cstdint>
40
41using namespace llvm;
42
43#define DEBUG_TYPE "bypass-slow-division"
44
45namespace {
46
47struct QuotRemPair {
48 Value *Quotient;
49 Value *Remainder;
50
51 QuotRemPair(Value *InQuotient, Value *InRemainder)
52 : Quotient(InQuotient), Remainder(InRemainder) {}
53};
54
55/// A quotient and remainder, plus a BB from which they logically "originate".
56/// If you use Quotient or Remainder in a Phi node, you should use BB as its
57/// corresponding predecessor.
58struct QuotRemWithBB {
59 BasicBlock *BB = nullptr;
60 Value *Quotient = nullptr;
61 Value *Remainder = nullptr;
62};
63
65using BypassWidthsTy = DenseMap<unsigned, unsigned>;
66using VisitedSetTy = SmallPtrSet<Instruction *, 4>;
67
68enum ValueRange {
69 /// Operand definitely fits into BypassType. No runtime checks are needed.
70 VALRNG_KNOWN_SHORT,
71 /// A runtime check is required, as value range is unknown.
72 VALRNG_UNKNOWN,
73 /// Operand is unlikely to fit into BypassType. The bypassing should be
74 /// disabled.
75 VALRNG_LIKELY_LONG
76};
77
78class FastDivInsertionTask {
79 bool IsValidTask = false;
80 Instruction *SlowDivOrRem = nullptr;
81 IntegerType *BypassType = nullptr;
82 BasicBlock *MainBB = nullptr;
83 DomTreeUpdater *DTU = nullptr;
84 LoopInfo *LI = nullptr;
85 BranchProbabilityInfo *BPI = nullptr;
86
87 BasicBlock *splitMainBB();
88 bool isHashLikeValue(Value *V, VisitedSetTy &Visited);
89 ValueRange getValueRange(Value *Op, VisitedSetTy &Visited);
90 QuotRemWithBB createSlowBB(BasicBlock *Successor);
91 QuotRemWithBB createFastBB(BasicBlock *Successor);
92 QuotRemPair createDivRemPhiNodes(QuotRemWithBB &LHS, QuotRemWithBB &RHS,
93 BasicBlock *PhiBB);
94 Value *insertOperandRuntimeCheck(Value *Op1, Value *Op2);
95 std::optional<QuotRemPair> insertFastDivAndRem();
96
97 bool isSignedOp() {
98 return SlowDivOrRem->getOpcode() == Instruction::SDiv ||
99 SlowDivOrRem->getOpcode() == Instruction::SRem;
100 }
101
102 bool isDivisionOp() {
103 return SlowDivOrRem->getOpcode() == Instruction::SDiv ||
104 SlowDivOrRem->getOpcode() == Instruction::UDiv;
105 }
106
107 Type *getSlowType() { return SlowDivOrRem->getType(); }
108
109public:
110 FastDivInsertionTask(Instruction *I, const BypassWidthsTy &BypassWidths,
111 DomTreeUpdater *DTU, LoopInfo *LI,
113
114 Value *getReplacement(DivCacheTy &Cache);
115};
116
117} // end anonymous namespace
118
119FastDivInsertionTask::FastDivInsertionTask(Instruction *I,
120 const BypassWidthsTy &BypassWidths,
121 DomTreeUpdater *DTU, LoopInfo *LI,
123 : DTU(DTU), LI(LI), BPI(BPI) {
124 switch (I->getOpcode()) {
125 case Instruction::UDiv:
126 case Instruction::SDiv:
127 case Instruction::URem:
128 case Instruction::SRem:
129 SlowDivOrRem = I;
130 break;
131 default:
132 // I is not a div/rem operation.
133 return;
134 }
135
136 // Skip division on vector types. Only optimize integer instructions.
137 IntegerType *SlowType = dyn_cast<IntegerType>(SlowDivOrRem->getType());
138 if (!SlowType)
139 return;
140
141 // Skip if this bitwidth is not bypassed.
142 auto BI = BypassWidths.find(SlowType->getBitWidth());
143 if (BI == BypassWidths.end())
144 return;
145
146 // Get type for div/rem instruction with bypass bitwidth.
147 IntegerType *BT = IntegerType::get(I->getContext(), BI->second);
148 BypassType = BT;
149
150 // The original basic block.
151 MainBB = I->getParent();
152
153 // The instruction is indeed a slow div or rem operation.
154 IsValidTask = true;
155}
156
157/// Reuses previously-computed dividend or remainder from the current BB if
158/// operands and operation are identical. Otherwise calls insertFastDivAndRem to
159/// perform the optimization and caches the resulting dividend and remainder.
160/// If no replacement can be generated, nullptr is returned.
161Value *FastDivInsertionTask::getReplacement(DivCacheTy &Cache) {
162 // First, make sure that the task is valid.
163 if (!IsValidTask)
164 return nullptr;
165
166 // Then, look for a value in Cache.
167 Value *Dividend = SlowDivOrRem->getOperand(0);
168 Value *Divisor = SlowDivOrRem->getOperand(1);
169 DivRemMapKey Key(isSignedOp(), Dividend, Divisor);
170 auto CacheI = Cache.find(Key);
171
172 if (CacheI == Cache.end()) {
173 // If previous instance does not exist, try to insert fast div.
174 std::optional<QuotRemPair> OptResult = insertFastDivAndRem();
175 // Bail out if insertFastDivAndRem has failed.
176 if (!OptResult)
177 return nullptr;
178 CacheI = Cache.insert({Key, *OptResult}).first;
179 }
180
181 QuotRemPair &Value = CacheI->second;
182 return isDivisionOp() ? Value.Quotient : Value.Remainder;
183}
184
185/// Check if a value looks like a hash.
186///
187/// The routine is expected to detect values computed using the most common hash
188/// algorithms. Typically, hash computations end with one of the following
189/// instructions:
190///
191/// 1) MUL with a constant wider than BypassType
192/// 2) XOR instruction
193///
194/// And even if we are wrong and the value is not a hash, it is still quite
195/// unlikely that such values will fit into BypassType.
196///
197/// To detect string hash algorithms like FNV we have to look through PHI-nodes.
198/// It is implemented as a depth-first search for values that look neither long
199/// nor hash-like.
200bool FastDivInsertionTask::isHashLikeValue(Value *V, VisitedSetTy &Visited) {
202 if (!I)
203 return false;
204
205 switch (I->getOpcode()) {
206 case Instruction::Xor:
207 return true;
208 case Instruction::Mul: {
209 // After Constant Hoisting pass, long constants may be represented as
210 // bitcast instructions. As a result, some constants may look like an
211 // instruction at first, and an additional check is necessary to find out if
212 // an operand is actually a constant.
213 Value *Op1 = I->getOperand(1);
214 ConstantInt *C = dyn_cast<ConstantInt>(Op1);
215 if (!C && isa<BitCastInst>(Op1))
216 C = dyn_cast<ConstantInt>(cast<BitCastInst>(Op1)->getOperand(0));
217 return C && C->getValue().getSignificantBits() > BypassType->getBitWidth();
218 }
219 case Instruction::PHI:
220 // Stop IR traversal in case of a crazy input code. This limits recursion
221 // depth.
222 if (Visited.size() >= 16)
223 return false;
224 // Do not visit nodes that have been visited already. We return true because
225 // it means that we couldn't find any value that doesn't look hash-like.
226 if (!Visited.insert(I).second)
227 return true;
228 return llvm::all_of(cast<PHINode>(I)->incoming_values(), [&](Value *V) {
229 // Ignore undef values as they probably don't affect the division
230 // operands.
231 return getValueRange(V, Visited) == VALRNG_LIKELY_LONG ||
233 });
234 default:
235 return false;
236 }
237}
238
239/// Check if an integer value fits into our bypass type.
240ValueRange FastDivInsertionTask::getValueRange(Value *V,
241 VisitedSetTy &Visited) {
242 unsigned ShortLen = BypassType->getBitWidth();
243 unsigned LongLen = V->getType()->getIntegerBitWidth();
244
245 assert(LongLen > ShortLen && "Value type must be wider than BypassType");
246 unsigned HiBits = LongLen - ShortLen;
247
248 const DataLayout &DL = SlowDivOrRem->getDataLayout();
249 KnownBits Known(LongLen);
250
252
253 if (Known.countMinLeadingZeros() >= HiBits)
254 return VALRNG_KNOWN_SHORT;
255
256 if (Known.countMaxLeadingZeros() < HiBits)
257 return VALRNG_LIKELY_LONG;
258
259 // Long integer divisions are often used in hashtable implementations. It's
260 // not worth bypassing such divisions because hash values are extremely
261 // unlikely to have enough leading zeros. The call below tries to detect
262 // values that are unlikely to fit BypassType (including hashes).
263 if (isHashLikeValue(V, Visited))
264 return VALRNG_LIKELY_LONG;
265
266 return VALRNG_UNKNOWN;
267}
268
269// Split MainBB and keep BPI up-to-date if its present.
270BasicBlock *FastDivInsertionTask::splitMainBB() {
272 if (BPI)
273 for (unsigned I = 0, E = MainBB->getTerminator()->getNumSuccessors();
274 I != E; ++I)
275 ExitProbs.push_back(BPI->getEdgeProbability(MainBB, I));
276
277 BasicBlock *SuccessorBB = SplitBlock(MainBB, SlowDivOrRem, DTU, LI);
278 MainBB->back().eraseFromParent();
279
280 if (BPI) {
281 BPI->setEdgeProbability(SuccessorBB, ExitProbs);
282 BPI->eraseBlock(MainBB);
283 }
284 return SuccessorBB;
285}
286
287/// Add new basic block for slow div and rem operations and put it before
288/// SuccessorBB.
289QuotRemWithBB FastDivInsertionTask::createSlowBB(BasicBlock *SuccessorBB) {
290 QuotRemWithBB DivRemPair;
291 DivRemPair.BB = BasicBlock::Create(MainBB->getParent()->getContext(), "",
292 MainBB->getParent(), SuccessorBB);
293 IRBuilder<> Builder(DivRemPair.BB, DivRemPair.BB->begin());
294 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
295
296 Value *Dividend = SlowDivOrRem->getOperand(0);
297 Value *Divisor = SlowDivOrRem->getOperand(1);
298
299 if (isSignedOp()) {
300 DivRemPair.Quotient = Builder.CreateSDiv(Dividend, Divisor);
301 DivRemPair.Remainder = Builder.CreateSRem(Dividend, Divisor);
302 } else {
303 DivRemPair.Quotient = Builder.CreateUDiv(Dividend, Divisor);
304 DivRemPair.Remainder = Builder.CreateURem(Dividend, Divisor);
305 }
306
307 Builder.CreateBr(SuccessorBB);
308 return DivRemPair;
309}
310
311/// Add new basic block for fast div and rem operations and put it before
312/// SuccessorBB.
313QuotRemWithBB FastDivInsertionTask::createFastBB(BasicBlock *SuccessorBB) {
314 QuotRemWithBB DivRemPair;
315 DivRemPair.BB = BasicBlock::Create(MainBB->getParent()->getContext(), "",
316 MainBB->getParent(), SuccessorBB);
317 IRBuilder<> Builder(DivRemPair.BB, DivRemPair.BB->begin());
318 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
319
320 Value *Dividend = SlowDivOrRem->getOperand(0);
321 Value *Divisor = SlowDivOrRem->getOperand(1);
322 Value *ShortDivisorV =
323 Builder.CreateCast(Instruction::Trunc, Divisor, BypassType);
324 Value *ShortDividendV =
325 Builder.CreateCast(Instruction::Trunc, Dividend, BypassType);
326
327 // udiv/urem because this optimization only handles positive numbers.
328 Value *ShortQV = Builder.CreateUDiv(ShortDividendV, ShortDivisorV);
329 Value *ShortRV = Builder.CreateURem(ShortDividendV, ShortDivisorV);
330 DivRemPair.Quotient =
331 Builder.CreateCast(Instruction::ZExt, ShortQV, getSlowType());
332 DivRemPair.Remainder =
333 Builder.CreateCast(Instruction::ZExt, ShortRV, getSlowType());
334 Builder.CreateBr(SuccessorBB);
335
336 return DivRemPair;
337}
338
339/// Creates Phi nodes for result of Div and Rem.
340QuotRemPair FastDivInsertionTask::createDivRemPhiNodes(QuotRemWithBB &LHS,
341 QuotRemWithBB &RHS,
342 BasicBlock *PhiBB) {
343 IRBuilder<> Builder(PhiBB, PhiBB->begin());
344 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
345 PHINode *QuoPhi = Builder.CreatePHI(getSlowType(), 2);
346 QuoPhi->addIncoming(LHS.Quotient, LHS.BB);
347 QuoPhi->addIncoming(RHS.Quotient, RHS.BB);
348 PHINode *RemPhi = Builder.CreatePHI(getSlowType(), 2);
349 RemPhi->addIncoming(LHS.Remainder, LHS.BB);
350 RemPhi->addIncoming(RHS.Remainder, RHS.BB);
351 return QuotRemPair(QuoPhi, RemPhi);
352}
353
354/// Creates a runtime check to test whether both the divisor and dividend fit
355/// into BypassType. The check is inserted at the end of MainBB. True return
356/// value means that the operands fit. Either of the operands may be NULL if it
357/// doesn't need a runtime check.
358Value *FastDivInsertionTask::insertOperandRuntimeCheck(Value *Op1, Value *Op2) {
359 assert((Op1 || Op2) && "Nothing to check");
360 IRBuilder<> Builder(MainBB, MainBB->end());
361 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
362
363 Value *OrV;
364 if (Op1 && Op2)
365 OrV = Builder.CreateOr(Op1, Op2);
366 else
367 OrV = Op1 ? Op1 : Op2;
368
369 // Check whether the operands are larger than the bypass type.
370 Value *AndV = Builder.CreateAnd(
372 BypassType->getBitWidth()));
373
374 // Compare operand values
375 Value *ZeroV = ConstantInt::getSigned(getSlowType(), 0);
376 return Builder.CreateICmpEQ(AndV, ZeroV);
377}
378
379/// Substitutes the div/rem instruction with code that checks the value of the
380/// operands and uses a shorter-faster div/rem instruction when possible.
381std::optional<QuotRemPair> FastDivInsertionTask::insertFastDivAndRem() {
382 Value *Dividend = SlowDivOrRem->getOperand(0);
383 Value *Divisor = SlowDivOrRem->getOperand(1);
384
385 VisitedSetTy SetL;
386 ValueRange DividendRange = getValueRange(Dividend, SetL);
387 if (DividendRange == VALRNG_LIKELY_LONG)
388 return std::nullopt;
389
390 VisitedSetTy SetR;
391 ValueRange DivisorRange = getValueRange(Divisor, SetR);
392 if (DivisorRange == VALRNG_LIKELY_LONG)
393 return std::nullopt;
394
395 bool DividendShort = (DividendRange == VALRNG_KNOWN_SHORT);
396 bool DivisorShort = (DivisorRange == VALRNG_KNOWN_SHORT);
397
398 if (DividendShort && DivisorShort) {
399 // If both operands are known to be short then just replace the long
400 // division with a short one in-place. Since we're not introducing control
401 // flow in this case, narrowing the division is always a win, even if the
402 // divisor is a constant (and will later get replaced by a multiplication).
403
404 IRBuilder<> Builder(SlowDivOrRem);
405 Value *TruncDividend = Builder.CreateTrunc(Dividend, BypassType);
406 Value *TruncDivisor = Builder.CreateTrunc(Divisor, BypassType);
407 Value *TruncDiv = Builder.CreateUDiv(TruncDividend, TruncDivisor);
408 Value *TruncRem = Builder.CreateURem(TruncDividend, TruncDivisor);
409 Value *ExtDiv = Builder.CreateZExt(TruncDiv, getSlowType());
410 Value *ExtRem = Builder.CreateZExt(TruncRem, getSlowType());
411 return QuotRemPair(ExtDiv, ExtRem);
412 }
413
414 if (isa<ConstantInt>(Divisor)) {
415 // If the divisor is not a constant, DAGCombiner will convert it to a
416 // multiplication by a magic constant. It isn't clear if it is worth
417 // introducing control flow to get a narrower multiply.
418 return std::nullopt;
419 }
420
421 // After Constant Hoisting pass, long constants may be represented as
422 // bitcast instructions. As a result, some constants may look like an
423 // instruction at first, and an additional check is necessary to find out if
424 // an operand is actually a constant.
425 if (auto *BCI = dyn_cast<BitCastInst>(Divisor))
426 if (BCI->getParent() == SlowDivOrRem->getParent() &&
427 isa<ConstantInt>(BCI->getOperand(0)))
428 return std::nullopt;
429
430 IRBuilder<> Builder(MainBB, MainBB->end());
431 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
432
433 if (DividendShort && !isSignedOp()) {
434 // If the division is unsigned and Dividend is known to be short, then
435 // either
436 // 1) Divisor is less or equal to Dividend, and the result can be computed
437 // with a short division.
438 // 2) Divisor is greater than Dividend. In this case, no division is needed
439 // at all: The quotient is 0 and the remainder is equal to Dividend.
440 //
441 // So instead of checking at runtime whether Divisor fits into BypassType,
442 // we emit a runtime check to differentiate between these two cases. This
443 // lets us entirely avoid a long div.
444
445 // Split the basic block before the div/rem.
446 BasicBlock *SuccessorBB = splitMainBB();
447 QuotRemWithBB Long;
448 Long.BB = MainBB;
449 Long.Quotient = ConstantInt::get(getSlowType(), 0);
450 Long.Remainder = Dividend;
451 QuotRemWithBB Fast = createFastBB(SuccessorBB);
452 QuotRemPair Result = createDivRemPhiNodes(Fast, Long, SuccessorBB);
453 Value *CmpV = Builder.CreateICmpUGE(Dividend, Divisor);
454 Builder.CreateCondBr(CmpV, Fast.BB, SuccessorBB);
455
456 if (DTU)
457 DTU->applyUpdates({{DominatorTree::Insert, MainBB, Fast.BB},
458 {DominatorTree::Insert, Fast.BB, SuccessorBB}});
459 if (LI) {
460 if (Loop *L = LI->getLoopFor(MainBB))
461 L->addBasicBlockToLoop(Fast.BB, *LI);
462 }
463
464 return Result;
465 }
466
467 // General case. Create both slow and fast div/rem pairs and choose one of
468 // them at runtime.
469
470 // Split the basic block before the div/rem.
471 BasicBlock *SuccessorBB = splitMainBB();
472 QuotRemWithBB Fast = createFastBB(SuccessorBB);
473 QuotRemWithBB Slow = createSlowBB(SuccessorBB);
474 QuotRemPair Result = createDivRemPhiNodes(Fast, Slow, SuccessorBB);
475 Value *CmpV = insertOperandRuntimeCheck(DividendShort ? nullptr : Dividend,
476 DivisorShort ? nullptr : Divisor);
477 Builder.CreateCondBr(CmpV, Fast.BB, Slow.BB);
478 if (DTU)
479 DTU->applyUpdates({{DominatorTree::Insert, MainBB, Fast.BB},
480 {DominatorTree::Insert, MainBB, Slow.BB},
481 {DominatorTree::Insert, Fast.BB, SuccessorBB},
482 {DominatorTree::Insert, Slow.BB, SuccessorBB},
483 {DominatorTree::Delete, MainBB, SuccessorBB}});
484 if (LI) {
485 if (Loop *L = LI->getLoopFor(MainBB)) {
486 L->addBasicBlockToLoop(Fast.BB, *LI);
487 L->addBasicBlockToLoop(Slow.BB, *LI);
488 }
489 }
490 return Result;
491}
492
493/// This optimization identifies DIV/REM instructions in a BB that can be
494/// profitably bypassed and carried out with a shorter, faster divide.
495bool llvm::bypassSlowDivision(BasicBlock *BB,
496 const BypassWidthsTy &BypassWidths,
497 DomTreeUpdater *DTU, LoopInfo *LI,
498 BranchProbabilityInfo *BPI) {
499 DivCacheTy PerBBDivCache;
500
501 bool MadeChange = false;
502 Instruction *Next = &*BB->begin();
503 while (Next != nullptr) {
504 // We may add instructions immediately after I, but we want to skip over
505 // them.
506 Instruction *I = Next;
507 Next = Next->getNextNode();
508
509 // Ignore dead code to save time and avoid bugs.
510 if (I->use_empty())
511 continue;
512
513 FastDivInsertionTask Task(I, BypassWidths, DTU, LI, BPI);
514 if (Value *Replacement = Task.getReplacement(PerBBDivCache)) {
515 I->replaceAllUsesWith(Replacement);
516 I->eraseFromParent();
517 MadeChange = true;
518 }
519 }
520
521 // Above we eagerly create divs and rems, as pairs, so that we can efficiently
522 // create divrem machine instructions. Now erase any unused divs / rems so we
523 // don't leave extra instructions sitting around.
524 for (auto &KV : PerBBDivCache)
525 for (Value *V : {KV.second.Quotient, KV.second.Remainder})
527
528 return MadeChange;
529}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BitTracker BT
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:57
if(PassOpts->AAPipeline)
This file contains some templates that are useful if you are working with the STL at all.
static int isSignedOp(ISD::CondCode Opcode)
For an integer comparison, return 1 if the comparison is a signed operation and 2 if the result is an...
This file defines the SmallPtrSet class.
Value * RHS
Value * LHS
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
Definition APInt.h:283
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:459
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:446
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
const Instruction & back() const
Definition BasicBlock.h:471
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
Analysis providing branch probability information.
LLVM_ABI void eraseBlock(const BasicBlock *BB)
Forget analysis results for the given basic block.
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
LLVM_ABI void setEdgeProbability(const BasicBlock *Src, ArrayRef< BranchProbability > Probs)
Set the raw probabilities for all edges from the given block.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
Definition Constants.h:135
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:353
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:348
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getIntegerBitWidth() const
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:255
const ParentTy * getParent() const
Definition ilist_node.h:34
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
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:535
LLVM_ABI bool bypassSlowDivision(BasicBlock *BB, const DenseMap< unsigned int, unsigned int > &BypassWidth, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BranchProbabilityInfo *BPI=nullptr)
This optimization identifies DIV instructions in a BB that can be profitably bypassed and carried out...
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147