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
40using namespace llvm;
41
42#define DEBUG_TYPE "bypass-slow-division"
43
44namespace {
45
46struct QuotRemPair {
47 Value *Quotient;
48 Value *Remainder;
49
50 QuotRemPair(Value *InQuotient, Value *InRemainder)
51 : Quotient(InQuotient), Remainder(InRemainder) {}
52};
53
54/// A quotient and remainder, plus a BB from which they logically "originate".
55/// If you use Quotient or Remainder in a Phi node, you should use BB as its
56/// corresponding predecessor.
57struct QuotRemWithBB {
58 BasicBlock *BB = nullptr;
59 Value *Quotient = nullptr;
60 Value *Remainder = nullptr;
61};
62
64using BypassWidthsTy = DenseMap<unsigned, unsigned>;
65using VisitedSetTy = SmallPtrSet<Instruction *, 4>;
66
67enum ValueRange {
68 /// Operand definitely fits into BypassType. No runtime checks are needed.
69 VALRNG_KNOWN_SHORT,
70 /// A runtime check is required, as value range is unknown.
71 VALRNG_UNKNOWN,
72 /// Operand is unlikely to fit into BypassType. The bypassing should be
73 /// disabled.
74 VALRNG_LIKELY_LONG
75};
76
77class FastDivInsertionTask {
78 bool IsValidTask = false;
79 Instruction *SlowDivOrRem = nullptr;
80 IntegerType *BypassType = nullptr;
81 BasicBlock *MainBB = nullptr;
82 DomTreeUpdater *DTU = nullptr;
83 LoopInfo *LI = nullptr;
84 BranchProbabilityInfo *BPI = nullptr;
85
86 BasicBlock *splitMainBB();
87 bool isHashLikeValue(Value *V, VisitedSetTy &Visited);
88 ValueRange getValueRange(Value *Op, VisitedSetTy &Visited);
89 QuotRemWithBB createSlowBB(BasicBlock *Successor);
90 QuotRemWithBB createFastBB(BasicBlock *Successor);
91 QuotRemPair createDivRemPhiNodes(QuotRemWithBB &LHS, QuotRemWithBB &RHS,
92 BasicBlock *PhiBB);
93 Value *insertOperandRuntimeCheck(Value *Op1, Value *Op2);
94 std::optional<QuotRemPair> insertFastDivAndRem();
95
96 bool isSignedOp() {
97 return SlowDivOrRem->getOpcode() == Instruction::SDiv ||
98 SlowDivOrRem->getOpcode() == Instruction::SRem;
99 }
100
101 bool isDivisionOp() {
102 return SlowDivOrRem->getOpcode() == Instruction::SDiv ||
103 SlowDivOrRem->getOpcode() == Instruction::UDiv;
104 }
105
106 Type *getSlowType() { return SlowDivOrRem->getType(); }
107
108public:
109 FastDivInsertionTask(Instruction *I, const BypassWidthsTy &BypassWidths,
110 DomTreeUpdater *DTU, LoopInfo *LI,
112
113 Value *getReplacement(DivCacheTy &Cache);
114};
115
116} // end anonymous namespace
117
118FastDivInsertionTask::FastDivInsertionTask(Instruction *I,
119 const BypassWidthsTy &BypassWidths,
120 DomTreeUpdater *DTU, LoopInfo *LI,
122 : DTU(DTU), LI(LI), BPI(BPI) {
123 switch (I->getOpcode()) {
124 case Instruction::UDiv:
125 case Instruction::SDiv:
126 case Instruction::URem:
127 case Instruction::SRem:
128 SlowDivOrRem = I;
129 break;
130 default:
131 // I is not a div/rem operation.
132 return;
133 }
134
135 // Skip division on vector types. Only optimize integer instructions.
136 IntegerType *SlowType = dyn_cast<IntegerType>(SlowDivOrRem->getType());
137 if (!SlowType)
138 return;
139
140 // Skip if this bitwidth is not bypassed.
141 auto BI = BypassWidths.find(SlowType->getBitWidth());
142 if (BI == BypassWidths.end())
143 return;
144
145 // Get type for div/rem instruction with bypass bitwidth.
146 IntegerType *BT = IntegerType::get(I->getContext(), BI->second);
147 BypassType = BT;
148
149 // The original basic block.
150 MainBB = I->getParent();
151
152 // The instruction is indeed a slow div or rem operation.
153 IsValidTask = true;
154}
155
156/// Reuses previously-computed dividend or remainder from the current BB if
157/// operands and operation are identical. Otherwise calls insertFastDivAndRem to
158/// perform the optimization and caches the resulting dividend and remainder.
159/// If no replacement can be generated, nullptr is returned.
160Value *FastDivInsertionTask::getReplacement(DivCacheTy &Cache) {
161 // First, make sure that the task is valid.
162 if (!IsValidTask)
163 return nullptr;
164
165 // Then, look for a value in Cache.
166 Value *Dividend = SlowDivOrRem->getOperand(0);
167 Value *Divisor = SlowDivOrRem->getOperand(1);
168 DivRemMapKey Key(isSignedOp(), Dividend, Divisor);
169 auto CacheI = Cache.find(Key);
170
171 if (CacheI == Cache.end()) {
172 // If previous instance does not exist, try to insert fast div.
173 std::optional<QuotRemPair> OptResult = insertFastDivAndRem();
174 // Bail out if insertFastDivAndRem has failed.
175 if (!OptResult)
176 return nullptr;
177 CacheI = Cache.insert({Key, *OptResult}).first;
178 }
179
180 QuotRemPair &Value = CacheI->second;
181 return isDivisionOp() ? Value.Quotient : Value.Remainder;
182}
183
184/// Check if a value looks like a hash.
185///
186/// The routine is expected to detect values computed using the most common hash
187/// algorithms. Typically, hash computations end with one of the following
188/// instructions:
189///
190/// 1) MUL with a constant wider than BypassType
191/// 2) XOR instruction
192///
193/// And even if we are wrong and the value is not a hash, it is still quite
194/// unlikely that such values will fit into BypassType.
195///
196/// To detect string hash algorithms like FNV we have to look through PHI-nodes.
197/// It is implemented as a depth-first search for values that look neither long
198/// nor hash-like.
199bool FastDivInsertionTask::isHashLikeValue(Value *V, VisitedSetTy &Visited) {
201 if (!I)
202 return false;
203
204 switch (I->getOpcode()) {
205 case Instruction::Xor:
206 return true;
207 case Instruction::Mul: {
208 // After Constant Hoisting pass, long constants may be represented as
209 // bitcast instructions. As a result, some constants may look like an
210 // instruction at first, and an additional check is necessary to find out if
211 // an operand is actually a constant.
212 Value *Op1 = I->getOperand(1);
213 ConstantInt *C = dyn_cast<ConstantInt>(Op1);
214 if (!C && isa<BitCastInst>(Op1))
215 C = dyn_cast<ConstantInt>(cast<BitCastInst>(Op1)->getOperand(0));
216 return C && C->getValue().getSignificantBits() > BypassType->getBitWidth();
217 }
218 case Instruction::PHI:
219 // Stop IR traversal in case of a crazy input code. This limits recursion
220 // depth.
221 if (Visited.size() >= 16)
222 return false;
223 // Do not visit nodes that have been visited already. We return true because
224 // it means that we couldn't find any value that doesn't look hash-like.
225 if (!Visited.insert(I).second)
226 return true;
227 return llvm::all_of(cast<PHINode>(I)->incoming_values(), [&](Value *V) {
228 // Ignore undef values as they probably don't affect the division
229 // operands.
230 return getValueRange(V, Visited) == VALRNG_LIKELY_LONG ||
232 });
233 default:
234 return false;
235 }
236}
237
238/// Check if an integer value fits into our bypass type.
239ValueRange FastDivInsertionTask::getValueRange(Value *V,
240 VisitedSetTy &Visited) {
241 unsigned ShortLen = BypassType->getBitWidth();
242 unsigned LongLen = V->getType()->getIntegerBitWidth();
243
244 assert(LongLen > ShortLen && "Value type must be wider than BypassType");
245 unsigned HiBits = LongLen - ShortLen;
246
247 const DataLayout &DL = SlowDivOrRem->getDataLayout();
248 KnownBits Known(LongLen);
249
251
252 if (Known.countMinLeadingZeros() >= HiBits)
253 return VALRNG_KNOWN_SHORT;
254
255 if (Known.countMaxLeadingZeros() < HiBits)
256 return VALRNG_LIKELY_LONG;
257
258 // Long integer divisions are often used in hashtable implementations. It's
259 // not worth bypassing such divisions because hash values are extremely
260 // unlikely to have enough leading zeros. The call below tries to detect
261 // values that are unlikely to fit BypassType (including hashes).
262 if (isHashLikeValue(V, Visited))
263 return VALRNG_LIKELY_LONG;
264
265 return VALRNG_UNKNOWN;
266}
267
268// Split MainBB and keep BPI up-to-date if its present.
269BasicBlock *FastDivInsertionTask::splitMainBB() {
271 if (BPI)
272 for (unsigned I = 0, E = MainBB->getTerminator()->getNumSuccessors();
273 I != E; ++I)
274 ExitProbs.push_back(BPI->getEdgeProbability(MainBB, I));
275
276 BasicBlock *SuccessorBB = SplitBlock(MainBB, SlowDivOrRem, DTU, LI);
277 MainBB->back().eraseFromParent();
278
279 if (BPI) {
280 BPI->setEdgeProbability(SuccessorBB, ExitProbs);
281 BPI->eraseBlock(MainBB);
282 }
283 return SuccessorBB;
284}
285
286/// Add new basic block for slow div and rem operations and put it before
287/// SuccessorBB.
288QuotRemWithBB FastDivInsertionTask::createSlowBB(BasicBlock *SuccessorBB) {
289 QuotRemWithBB DivRemPair;
290 DivRemPair.BB = BasicBlock::Create(MainBB->getParent()->getContext(), "",
291 MainBB->getParent(), SuccessorBB);
292 IRBuilder<> Builder(DivRemPair.BB, DivRemPair.BB->begin());
293 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
294
295 Value *Dividend = SlowDivOrRem->getOperand(0);
296 Value *Divisor = SlowDivOrRem->getOperand(1);
297
298 if (isSignedOp()) {
299 DivRemPair.Quotient = Builder.CreateSDiv(Dividend, Divisor);
300 DivRemPair.Remainder = Builder.CreateSRem(Dividend, Divisor);
301 } else {
302 DivRemPair.Quotient = Builder.CreateUDiv(Dividend, Divisor);
303 DivRemPair.Remainder = Builder.CreateURem(Dividend, Divisor);
304 }
305
306 Builder.CreateBr(SuccessorBB);
307 return DivRemPair;
308}
309
310/// Add new basic block for fast div and rem operations and put it before
311/// SuccessorBB.
312QuotRemWithBB FastDivInsertionTask::createFastBB(BasicBlock *SuccessorBB) {
313 QuotRemWithBB DivRemPair;
314 DivRemPair.BB = BasicBlock::Create(MainBB->getParent()->getContext(), "",
315 MainBB->getParent(), SuccessorBB);
316 IRBuilder<> Builder(DivRemPair.BB, DivRemPair.BB->begin());
317 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
318
319 Value *Dividend = SlowDivOrRem->getOperand(0);
320 Value *Divisor = SlowDivOrRem->getOperand(1);
321 Value *ShortDivisorV =
322 Builder.CreateCast(Instruction::Trunc, Divisor, BypassType);
323 Value *ShortDividendV =
324 Builder.CreateCast(Instruction::Trunc, Dividend, BypassType);
325
326 // udiv/urem because this optimization only handles positive numbers.
327 Value *ShortQV = Builder.CreateUDiv(ShortDividendV, ShortDivisorV);
328 Value *ShortRV = Builder.CreateURem(ShortDividendV, ShortDivisorV);
329 DivRemPair.Quotient =
330 Builder.CreateCast(Instruction::ZExt, ShortQV, getSlowType());
331 DivRemPair.Remainder =
332 Builder.CreateCast(Instruction::ZExt, ShortRV, getSlowType());
333 Builder.CreateBr(SuccessorBB);
334
335 return DivRemPair;
336}
337
338/// Creates Phi nodes for result of Div and Rem.
339QuotRemPair FastDivInsertionTask::createDivRemPhiNodes(QuotRemWithBB &LHS,
340 QuotRemWithBB &RHS,
341 BasicBlock *PhiBB) {
342 IRBuilder<> Builder(PhiBB, PhiBB->begin());
343 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
344 PHINode *QuoPhi = Builder.CreatePHI(getSlowType(), 2);
345 QuoPhi->addIncoming(LHS.Quotient, LHS.BB);
346 QuoPhi->addIncoming(RHS.Quotient, RHS.BB);
347 PHINode *RemPhi = Builder.CreatePHI(getSlowType(), 2);
348 RemPhi->addIncoming(LHS.Remainder, LHS.BB);
349 RemPhi->addIncoming(RHS.Remainder, RHS.BB);
350 return QuotRemPair(QuoPhi, RemPhi);
351}
352
353/// Creates a runtime check to test whether both the divisor and dividend fit
354/// into BypassType. The check is inserted at the end of MainBB. True return
355/// value means that the operands fit. Either of the operands may be NULL if it
356/// doesn't need a runtime check.
357Value *FastDivInsertionTask::insertOperandRuntimeCheck(Value *Op1, Value *Op2) {
358 assert((Op1 || Op2) && "Nothing to check");
359 IRBuilder<> Builder(MainBB, MainBB->end());
360 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
361
362 Value *OrV;
363 if (Op1 && Op2)
364 OrV = Builder.CreateOr(Op1, Op2);
365 else
366 OrV = Op1 ? Op1 : Op2;
367
368 // Check whether the operands are larger than the bypass type.
369 Value *AndV = Builder.CreateAnd(
371 BypassType->getBitWidth()));
372
373 // Compare operand values
374 Value *ZeroV = ConstantInt::getSigned(getSlowType(), 0);
375 return Builder.CreateICmpEQ(AndV, ZeroV);
376}
377
378/// Substitutes the div/rem instruction with code that checks the value of the
379/// operands and uses a shorter-faster div/rem instruction when possible.
380std::optional<QuotRemPair> FastDivInsertionTask::insertFastDivAndRem() {
381 Value *Dividend = SlowDivOrRem->getOperand(0);
382 Value *Divisor = SlowDivOrRem->getOperand(1);
383
384 VisitedSetTy SetL;
385 ValueRange DividendRange = getValueRange(Dividend, SetL);
386 if (DividendRange == VALRNG_LIKELY_LONG)
387 return std::nullopt;
388
389 VisitedSetTy SetR;
390 ValueRange DivisorRange = getValueRange(Divisor, SetR);
391 if (DivisorRange == VALRNG_LIKELY_LONG)
392 return std::nullopt;
393
394 bool DividendShort = (DividendRange == VALRNG_KNOWN_SHORT);
395 bool DivisorShort = (DivisorRange == VALRNG_KNOWN_SHORT);
396
397 if (DividendShort && DivisorShort) {
398 // If both operands are known to be short then just replace the long
399 // division with a short one in-place. Since we're not introducing control
400 // flow in this case, narrowing the division is always a win, even if the
401 // divisor is a constant (and will later get replaced by a multiplication).
402
403 IRBuilder<> Builder(SlowDivOrRem);
404 Value *TruncDividend = Builder.CreateTrunc(Dividend, BypassType);
405 Value *TruncDivisor = Builder.CreateTrunc(Divisor, BypassType);
406 Value *TruncDiv = Builder.CreateUDiv(TruncDividend, TruncDivisor);
407 Value *TruncRem = Builder.CreateURem(TruncDividend, TruncDivisor);
408 Value *ExtDiv = Builder.CreateZExt(TruncDiv, getSlowType());
409 Value *ExtRem = Builder.CreateZExt(TruncRem, getSlowType());
410 return QuotRemPair(ExtDiv, ExtRem);
411 }
412
413 if (isa<ConstantInt>(Divisor)) {
414 // If the divisor is not a constant, DAGCombiner will convert it to a
415 // multiplication by a magic constant. It isn't clear if it is worth
416 // introducing control flow to get a narrower multiply.
417 return std::nullopt;
418 }
419
420 // After Constant Hoisting pass, long constants may be represented as
421 // bitcast instructions. As a result, some constants may look like an
422 // instruction at first, and an additional check is necessary to find out if
423 // an operand is actually a constant.
424 if (auto *BCI = dyn_cast<BitCastInst>(Divisor))
425 if (BCI->getParent() == SlowDivOrRem->getParent() &&
426 isa<ConstantInt>(BCI->getOperand(0)))
427 return std::nullopt;
428
429 IRBuilder<> Builder(MainBB, MainBB->end());
430 Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc());
431
432 if (DividendShort && !isSignedOp()) {
433 // If the division is unsigned and Dividend is known to be short, then
434 // either
435 // 1) Divisor is less or equal to Dividend, and the result can be computed
436 // with a short division.
437 // 2) Divisor is greater than Dividend. In this case, no division is needed
438 // at all: The quotient is 0 and the remainder is equal to Dividend.
439 //
440 // So instead of checking at runtime whether Divisor fits into BypassType,
441 // we emit a runtime check to differentiate between these two cases. This
442 // lets us entirely avoid a long div.
443
444 // Split the basic block before the div/rem.
445 BasicBlock *SuccessorBB = splitMainBB();
446 QuotRemWithBB Long;
447 Long.BB = MainBB;
448 Long.Quotient = ConstantInt::get(getSlowType(), 0);
449 Long.Remainder = Dividend;
450 QuotRemWithBB Fast = createFastBB(SuccessorBB);
451 QuotRemPair Result = createDivRemPhiNodes(Fast, Long, SuccessorBB);
452 Value *CmpV = Builder.CreateICmpUGE(Dividend, Divisor);
453 Builder.CreateCondBr(CmpV, Fast.BB, SuccessorBB);
454
455 if (DTU)
456 DTU->applyUpdates({{DominatorTree::Insert, MainBB, Fast.BB},
457 {DominatorTree::Insert, Fast.BB, SuccessorBB}});
458 if (LI) {
459 if (Loop *L = LI->getLoopFor(MainBB))
460 L->addBasicBlockToLoop(Fast.BB, *LI);
461 }
462
463 return Result;
464 }
465
466 // General case. Create both slow and fast div/rem pairs and choose one of
467 // them at runtime.
468
469 // Split the basic block before the div/rem.
470 BasicBlock *SuccessorBB = splitMainBB();
471 QuotRemWithBB Fast = createFastBB(SuccessorBB);
472 QuotRemWithBB Slow = createSlowBB(SuccessorBB);
473 QuotRemPair Result = createDivRemPhiNodes(Fast, Slow, SuccessorBB);
474 Value *CmpV = insertOperandRuntimeCheck(DividendShort ? nullptr : Dividend,
475 DivisorShort ? nullptr : Divisor);
476 Builder.CreateCondBr(CmpV, Fast.BB, Slow.BB);
477 if (DTU)
478 DTU->applyUpdates({{DominatorTree::Insert, MainBB, Fast.BB},
479 {DominatorTree::Insert, MainBB, Slow.BB},
480 {DominatorTree::Insert, Fast.BB, SuccessorBB},
481 {DominatorTree::Insert, Slow.BB, SuccessorBB},
482 {DominatorTree::Delete, MainBB, SuccessorBB}});
483 if (LI) {
484 if (Loop *L = LI->getLoopFor(MainBB)) {
485 L->addBasicBlockToLoop(Fast.BB, *LI);
486 L->addBasicBlockToLoop(Slow.BB, *LI);
487 }
488 }
489 return Result;
490}
491
492/// This optimization identifies DIV/REM instructions in a BB that can be
493/// profitably bypassed and carried out with a shorter, faster divide.
494bool llvm::bypassSlowDivision(BasicBlock *BB,
495 const BypassWidthsTy &BypassWidths,
496 DomTreeUpdater *DTU, LoopInfo *LI,
497 BranchProbabilityInfo *BPI) {
498 DivCacheTy PerBBDivCache;
499
500 bool MadeChange = false;
501 Instruction *Next = &*BB->begin();
502 while (Next != nullptr) {
503 // We may add instructions immediately after I, but we want to skip over
504 // them.
505 Instruction *I = Next;
506 Next = Next->getNextNode();
507
508 // Ignore dead code to save time and avoid bugs.
509 if (I->use_empty())
510 continue;
511
512 FastDivInsertionTask Task(I, BypassWidths, DTU, LI, BPI);
513 if (Value *Replacement = Task.getReplacement(PerBBDivCache)) {
514 I->replaceAllUsesWith(Replacement);
515 I->eraseFromParent();
516 MadeChange = true;
517 }
518 }
519
520 // Above we eagerly create divs and rems, as pairs, so that we can efficiently
521 // create divrem machine instructions. Now erase any unused divs / rems so we
522 // don't leave extra instructions sitting around.
523 for (auto &KV : PerBBDivCache)
524 for (Value *V : {KV.second.Quotient, KV.second.Remainder})
526
527 return MadeChange;
528}
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:356
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:522
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.
@ Fast
Assign the register banks as fast as possible (default).
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