LLVM 24.0.0git
TypePromotion.cpp
Go to the documentation of this file.
1//===----- TypePromotion.cpp ----------------------------------------------===//
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/// \file
10/// This is an opcode based type promotion pass for small types that would
11/// otherwise be promoted during legalisation. This works around the limitations
12/// of selection dag for cyclic regions. The search begins from icmp
13/// instructions operands where a tree, consisting of non-wrapping or safe
14/// wrapping instructions, is built, checked and promoted if possible.
15///
16//===----------------------------------------------------------------------===//
17
19#include "llvm/ADT/SetVector.h"
20#include "llvm/ADT/StringRef.h"
23#include "llvm/CodeGen/Passes.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/BasicBlock.h"
29#include "llvm/IR/Constants.h"
30#include "llvm/IR/IRBuilder.h"
31#include "llvm/IR/InstrTypes.h"
32#include "llvm/IR/Instruction.h"
34#include "llvm/IR/Type.h"
35#include "llvm/IR/Value.h"
37#include "llvm/Pass.h"
41
42#define DEBUG_TYPE "type-promotion"
43#define PASS_NAME "Type Promotion"
44
45using namespace llvm;
46
47static cl::opt<bool> DisablePromotion("disable-type-promotion", cl::Hidden,
48 cl::init(false),
49 cl::desc("Disable type promotion pass"));
50
51// The goal of this pass is to enable more efficient code generation for
52// operations on narrow types (i.e. types with < 32-bits) and this is a
53// motivating IR code example:
54//
55// define hidden i32 @cmp(i8 zeroext) {
56// %2 = add i8 %0, -49
57// %3 = icmp ult i8 %2, 3
58// ..
59// }
60//
61// The issue here is that i8 is type-legalized to i32 because i8 is not a
62// legal type. Thus, arithmetic is done in integer-precision, but then the
63// byte value is masked out as follows:
64//
65// t19: i32 = add t4, Constant:i32<-49>
66// t24: i32 = and t19, Constant:i32<255>
67//
68// Consequently, we generate code like this:
69//
70// subs r0, #49
71// uxtb r1, r0
72// cmp r1, #3
73//
74// This shows that masking out the byte value results in generation of
75// the UXTB instruction. This is not optimal as r0 already contains the byte
76// value we need, and so instead we can just generate:
77//
78// sub.w r1, r0, #49
79// cmp r1, #3
80//
81// We achieve this by type promoting the IR to i32 like so for this example:
82//
83// define i32 @cmp(i8 zeroext %c) {
84// %0 = zext i8 %c to i32
85// %c.off = add i32 %0, -49
86// %1 = icmp ult i32 %c.off, 3
87// ..
88// }
89//
90// For this to be valid and legal, we need to prove that the i32 add is
91// producing the same value as the i8 addition, and that e.g. no overflow
92// happens.
93//
94// A brief sketch of the algorithm and some terminology.
95// We pattern match interesting IR patterns:
96// - which have "sources": instructions producing narrow values (i8, i16), and
97// - they have "sinks": instructions consuming these narrow values.
98//
99// We collect all instruction connecting sources and sinks in a worklist, so
100// that we can mutate these instruction and perform type promotion when it is
101// legal to do so.
102
103namespace {
104class IRPromoter {
105 LLVMContext &Ctx;
106 unsigned PromotedWidth = 0;
107 SetVector<Value *> &Visited;
108 SetVector<Value *> &Sources;
111 SmallPtrSetImpl<Instruction *> &InstsToRemove;
112 IntegerType *ExtTy = nullptr;
116
117 void ReplaceAllUsersOfWith(Value *From, Value *To);
118 void ExtendSources();
119 void ConvertTruncs();
120 void PromoteTree();
121 void TruncateSinks();
122 void Cleanup();
123
124public:
125 IRPromoter(LLVMContext &C, unsigned Width, SetVector<Value *> &visited,
128 SmallPtrSetImpl<Instruction *> &instsToRemove)
129 : Ctx(C), PromotedWidth(Width), Visited(visited), Sources(sources),
130 Sinks(sinks), SafeWrap(wrap), InstsToRemove(instsToRemove) {
131 ExtTy = IntegerType::get(Ctx, PromotedWidth);
132 }
133
134 void Mutate();
135};
136
137class TypePromotionImpl {
138 unsigned TypeSize = 0;
139 const TargetLowering *TLI = nullptr;
140 LLVMContext *Ctx = nullptr;
141 unsigned RegisterBitWidth = 0;
142 SmallPtrSet<Value *, 16> AllVisited;
143 SmallPtrSet<Instruction *, 8> SafeToPromote;
144 SmallPtrSet<Instruction *, 4> SafeWrap;
145 SmallPtrSet<Instruction *, 4> InstsToRemove;
146
147 // Does V have the same size result type as TypeSize.
148 bool EqualTypeSize(Value *V);
149 // Does V have the same size, or narrower, result type as TypeSize.
150 bool LessOrEqualTypeSize(Value *V);
151 // Does V have a result type that is wider than TypeSize.
152 bool GreaterThanTypeSize(Value *V);
153 // Does V have a result type that is narrower than TypeSize.
154 bool LessThanTypeSize(Value *V);
155 // Should V be a leaf in the promote tree?
156 bool isSource(Value *V);
157 // Should V be a root in the promotion tree?
158 bool isSink(Value *V);
159 // Should we change the result type of V? It will result in the users of V
160 // being visited.
161 bool shouldPromote(Value *V);
162 // Is I an add or a sub, which isn't marked as nuw, but where a wrapping
163 // result won't affect the computation?
164 bool isSafeWrap(Instruction *I);
165 // Can V have its integer type promoted, or can the type be ignored.
166 bool isSupportedType(Value *V);
167 // Is V an instruction with a supported opcode or another value that we can
168 // handle, such as constants and basic blocks.
169 bool isSupportedValue(Value *V);
170 // Is V an instruction thats result can trivially promoted, or has safe
171 // wrapping.
172 bool isLegalToPromote(Value *V);
173 bool TryToPromote(Value *V, unsigned PromotedWidth, const LoopInfo &LI);
174
175public:
176 bool run(Function &F, const TargetMachine *TM,
177 const TargetTransformInfo &TTI, const LoopInfo &LI);
178};
179
180class TypePromotionLegacy : public FunctionPass {
181public:
182 static char ID;
183
184 TypePromotionLegacy() : FunctionPass(ID) {}
185
186 void getAnalysisUsage(AnalysisUsage &AU) const override {
187 AU.addRequired<LoopInfoWrapperPass>();
188 AU.addRequired<TargetTransformInfoWrapperPass>();
189 AU.addRequired<TargetPassConfig>();
190 AU.setPreservesCFG();
191 }
192
193 StringRef getPassName() const override { return PASS_NAME; }
194
195 bool runOnFunction(Function &F) override;
196};
197
198} // namespace
199
201 unsigned Opc = I->getOpcode();
202 return Opc == Instruction::AShr || Opc == Instruction::SDiv ||
203 Opc == Instruction::SRem || Opc == Instruction::SExt;
204}
205
206bool TypePromotionImpl::EqualTypeSize(Value *V) {
207 return V->getType()->getScalarSizeInBits() == TypeSize;
208}
209
210bool TypePromotionImpl::LessOrEqualTypeSize(Value *V) {
211 return V->getType()->getScalarSizeInBits() <= TypeSize;
212}
213
214bool TypePromotionImpl::GreaterThanTypeSize(Value *V) {
215 return V->getType()->getScalarSizeInBits() > TypeSize;
216}
217
218bool TypePromotionImpl::LessThanTypeSize(Value *V) {
219 return V->getType()->getScalarSizeInBits() < TypeSize;
220}
221
222/// Return true if the given value is a source in the use-def chain, producing
223/// a narrow 'TypeSize' value. These values will be zext to start the promotion
224/// of the tree to i32. We guarantee that these won't populate the upper bits
225/// of the register. ZExt on the loads will be free, and the same for call
226/// return values because we only accept ones that guarantee a zeroext ret val.
227/// Many arguments will have the zeroext attribute too, so those would be free
228/// too.
229bool TypePromotionImpl::isSource(Value *V) {
230 if (!isa<IntegerType>(V->getType()))
231 return false;
232
233 // TODO Allow zext to be sources.
234 if (isa<Argument>(V))
235 return true;
236 else if (isa<LoadInst>(V))
237 return true;
238 else if (auto *Call = dyn_cast<CallInst>(V))
239 return Call->hasRetAttr(Attribute::AttrKind::ZExt);
240 else if (auto *Trunc = dyn_cast<TruncInst>(V))
241 return EqualTypeSize(Trunc);
242 return false;
243}
244
245/// Return true if V will require any promoted values to be truncated for the
246/// the IR to remain valid. We can't mutate the value type of these
247/// instructions.
248bool TypePromotionImpl::isSink(Value *V) {
249 // TODO The truncate also isn't actually necessary because we would already
250 // proved that the data value is kept within the range of the original data
251 // type. We currently remove any truncs inserted for handling zext sinks.
252
253 // Sinks are:
254 // - points where the value in the register is being observed, such as an
255 // icmp, switch or store.
256 // - points where value types have to match, such as calls and returns.
257 // - zext are included to ease the transformation and are generally removed
258 // later on.
259 if (auto *Store = dyn_cast<StoreInst>(V))
260 return LessOrEqualTypeSize(Store->getValueOperand());
261 if (auto *Return = dyn_cast<ReturnInst>(V))
262 return LessOrEqualTypeSize(Return->getReturnValue());
263 if (auto *ZExt = dyn_cast<ZExtInst>(V))
264 return GreaterThanTypeSize(ZExt);
265 if (auto *Switch = dyn_cast<SwitchInst>(V))
266 return LessThanTypeSize(Switch->getCondition());
267 if (auto *ICmp = dyn_cast<ICmpInst>(V))
268 return ICmp->isSigned() || LessThanTypeSize(ICmp->getOperand(0));
269
270 return isa<CallInst>(V);
271}
272
273/// Return whether this instruction can safely wrap.
274bool TypePromotionImpl::isSafeWrap(Instruction *I) {
275 // We can support a potentially wrapping Add/Sub instruction (I) if:
276 // - It is only used by an unsigned icmp.
277 // - The icmp uses a constant.
278 // - The wrapping instruction (I) also uses a constant.
279 //
280 // This a common pattern emitted to check if a value is within a range.
281 //
282 // For example:
283 //
284 // %sub = sub i8 %a, C1
285 // %cmp = icmp ule i8 %sub, C2
286 //
287 // or
288 //
289 // %add = add i8 %a, C1
290 // %cmp = icmp ule i8 %add, C2.
291 //
292 // We will treat an add as though it were a subtract by -C1. To promote
293 // the Add/Sub we will zero extend the LHS and the subtracted amount. For Add,
294 // this means we need to negate the constant, zero extend to RegisterBitWidth,
295 // and negate in the larger type.
296 //
297 // This will produce a value in the range [-zext(C1), zext(X)-zext(C1)] where
298 // C1 is the subtracted amount. This is either a small unsigned number or a
299 // large unsigned number in the promoted type.
300 //
301 // Now we need to correct the compare constant C2. Values >= C1 in the
302 // original add result range have been remapped to large values in the
303 // promoted range. If the compare constant fell into this range we need to
304 // remap it as well. We can do this as -(zext(-C2)).
305 //
306 // For example:
307 //
308 // %sub = sub i8 %a, 2
309 // %cmp = icmp ule i8 %sub, 254
310 //
311 // becomes
312 //
313 // %zext = zext %a to i32
314 // %sub = sub i32 %zext, 2
315 // %cmp = icmp ule i32 %sub, 4294967294
316 //
317 // Another example:
318 //
319 // %sub = sub i8 %a, 1
320 // %cmp = icmp ule i8 %sub, 254
321 //
322 // becomes
323 //
324 // %zext = zext %a to i32
325 // %sub = sub i32 %zext, 1
326 // %cmp = icmp ule i32 %sub, 254
327
328 unsigned Opc = I->getOpcode();
329 if (Opc != Instruction::Add && Opc != Instruction::Sub)
330 return false;
331
332 if (!I->hasOneUse() || !isa<ICmpInst>(*I->user_begin()) ||
333 !isa<ConstantInt>(I->getOperand(1)))
334 return false;
335
336 // Don't support an icmp that deals with sign bits.
337 auto *CI = cast<ICmpInst>(*I->user_begin());
338 if (CI->isSigned() || CI->isEquality())
339 return false;
340
341 ConstantInt *ICmpConstant = nullptr;
342 if (auto *Const = dyn_cast<ConstantInt>(CI->getOperand(0)))
343 ICmpConstant = Const;
344 else if (auto *Const = dyn_cast<ConstantInt>(CI->getOperand(1)))
345 ICmpConstant = Const;
346 else
347 return false;
348
349 const APInt &ICmpConst = ICmpConstant->getValue();
350 APInt OverflowConst = cast<ConstantInt>(I->getOperand(1))->getValue();
351 if (Opc == Instruction::Sub)
352 OverflowConst = -OverflowConst;
353
354 // If the constant is positive, we will end up filling the promoted bits with
355 // all 1s. Make sure that results in a cheap add constant.
356 if (!OverflowConst.isNonPositive()) {
357 // We don't have the true promoted width, just use 64 so we can create an
358 // int64_t for the isLegalAddImmediate call.
359 if (OverflowConst.getBitWidth() >= 64)
360 return false;
361
362 APInt NewConst = -((-OverflowConst).zext(64));
363 if (!TLI->isLegalAddImmediate(NewConst.getSExtValue()))
364 return false;
365 }
366
367 SafeWrap.insert(I);
368
369 if (OverflowConst == 0 || OverflowConst.ugt(ICmpConst)) {
370 LLVM_DEBUG(dbgs() << "IR Promotion: Allowing safe overflow for "
371 << "const of " << *I << "\n");
372 return true;
373 }
374
375 LLVM_DEBUG(dbgs() << "IR Promotion: Allowing safe overflow for "
376 << "const of " << *I << " and " << *CI << "\n");
377 SafeWrap.insert(CI);
378 return true;
379}
380
381bool TypePromotionImpl::shouldPromote(Value *V) {
382 if (!isa<IntegerType>(V->getType()) || isSink(V))
383 return false;
384
385 if (isSource(V))
386 return true;
387
388 auto *I = dyn_cast<Instruction>(V);
389 if (!I)
390 return false;
391
392 if (isa<ICmpInst>(I))
393 return false;
394
395 return true;
396}
397
398/// Return whether we can safely mutate V's type to ExtTy without having to be
399/// concerned with zero extending or truncation.
401 if (GenerateSignBits(I))
402 return false;
403
405 return true;
406
407 return I->hasNoUnsignedWrap();
408}
409
410void IRPromoter::ReplaceAllUsersOfWith(Value *From, Value *To) {
411 SmallVector<Instruction *, 4> Users;
413 bool ReplacedAll = true;
414
415 LLVM_DEBUG(dbgs() << "IR Promotion: Replacing " << *From << " with " << *To
416 << "\n");
417
418 for (Use &U : From->uses()) {
419 auto *User = cast<Instruction>(U.getUser());
420 if (InstTo && User->isIdenticalTo(InstTo)) {
421 ReplacedAll = false;
422 continue;
423 }
424 Users.push_back(User);
425 }
426
427 for (auto *U : Users)
428 U->replaceUsesOfWith(From, To);
429
430 if (ReplacedAll)
431 if (auto *I = dyn_cast<Instruction>(From))
432 InstsToRemove.insert(I);
433}
434
435void IRPromoter::ExtendSources() {
436 IRBuilder<> Builder{Ctx};
437
438 auto InsertZExt = [&](Value *V, BasicBlock::iterator InsertPt) {
439 assert(V->getType() != ExtTy && "zext already extends to i32");
440 LLVM_DEBUG(dbgs() << "IR Promotion: Inserting ZExt for " << *V << "\n");
441 Builder.SetInsertPoint(InsertPt);
442 if (auto *I = dyn_cast<Instruction>(V))
443 Builder.SetCurrentDebugLocation(I->getDebugLoc());
444
445 Value *ZExt = Builder.CreateZExt(V, ExtTy);
446 if (auto *I = dyn_cast<Instruction>(ZExt)) {
447 if (isa<Argument>(V))
448 I->moveBefore(InsertPt);
449 else
450 I->moveAfter(&*InsertPt);
451 NewInsts.insert(I);
452 }
453
454 ReplaceAllUsersOfWith(V, ZExt);
455 };
456
457 // Now, insert extending instructions between the sources and their users.
458 LLVM_DEBUG(dbgs() << "IR Promotion: Promoting sources:\n");
459 for (auto *V : Sources) {
460 LLVM_DEBUG(dbgs() << " - " << *V << "\n");
461 if (auto *I = dyn_cast<Instruction>(V))
462 InsertZExt(I, I->getIterator());
463 else if (auto *Arg = dyn_cast<Argument>(V)) {
464 BasicBlock &BB = Arg->getParent()->front();
465 InsertZExt(Arg, BB.getFirstInsertionPt());
466 } else {
467 llvm_unreachable("unhandled source that needs extending");
468 }
469 Promoted.insert(V);
470 }
471}
472
473void IRPromoter::PromoteTree() {
474 LLVM_DEBUG(dbgs() << "IR Promotion: Mutating the tree..\n");
475
476 // Mutate the types of the instructions within the tree. Here we handle
477 // constant operands.
478 for (auto *V : Visited) {
479 if (Sources.count(V))
480 continue;
481
482 auto *I = cast<Instruction>(V);
483 if (Sinks.count(I))
484 continue;
485
486 for (unsigned i = 0, e = I->getNumOperands(); i < e; ++i) {
487 Value *Op = I->getOperand(i);
488 if ((Op->getType() == ExtTy) || !isa<IntegerType>(Op->getType()))
489 continue;
490
491 if (auto *Const = dyn_cast<ConstantInt>(Op)) {
492 // For subtract, we only need to zext the constant. We only put it in
493 // SafeWrap because SafeWrap.size() is used elsewhere.
494 // For Add and ICmp we need to find how far the constant is from the
495 // top of its original unsigned range and place it the same distance
496 // from the top of its new unsigned range. We can do this by negating
497 // the constant, zero extending it, then negating in the new type.
498 APInt NewConst;
499 if (SafeWrap.contains(I)) {
500 if (I->getOpcode() == Instruction::ICmp)
501 NewConst = -((-Const->getValue()).zext(PromotedWidth));
502 else if (I->getOpcode() == Instruction::Add && i == 1)
503 NewConst = -((-Const->getValue()).zext(PromotedWidth));
504 else
505 NewConst = Const->getValue().zext(PromotedWidth);
506 } else
507 NewConst = Const->getValue().zext(PromotedWidth);
508
509 I->setOperand(i, ConstantInt::get(Const->getContext(), NewConst));
510 } else if (isa<UndefValue>(Op))
511 I->setOperand(i, ConstantInt::get(ExtTy, 0));
512 }
513
514 // For switch, also mutate case values, which are not operands.
515 if (auto *SI = dyn_cast<SwitchInst>(I)) {
516 for (auto Case : SI->cases()) {
517 APInt NewConst = Case.getCaseValue()->getValue().zext(PromotedWidth);
518 Case.setValue(ConstantInt::get(SI->getContext(), NewConst));
519 }
520 }
521
522 // Mutate the result type, unless this is an icmp or switch.
523 if (!isa<ICmpInst>(I) && !isa<SwitchInst>(I)) {
524 I->mutateType(ExtTy);
525 Promoted.insert(I);
526 }
527 }
528}
529
530void IRPromoter::TruncateSinks() {
531 LLVM_DEBUG(dbgs() << "IR Promotion: Fixing up the sinks:\n");
532
533 IRBuilder<> Builder{Ctx};
534
535 auto InsertTrunc = [&](Value *V, Type *TruncTy) -> Instruction * {
536 if (!isa<Instruction>(V) || !isa<IntegerType>(V->getType()))
537 return nullptr;
538
539 if ((!Promoted.count(V) && !NewInsts.count(V)) || Sources.count(V))
540 return nullptr;
541
542 LLVM_DEBUG(dbgs() << "IR Promotion: Creating " << *TruncTy << " Trunc for "
543 << *V << "\n");
545 auto *Trunc = dyn_cast<Instruction>(Builder.CreateTrunc(V, TruncTy));
546 if (Trunc)
547 NewInsts.insert(Trunc);
548 return Trunc;
549 };
550
551 // Fix up any stores or returns that use the results of the promoted
552 // chain.
553 for (auto *I : Sinks) {
554 LLVM_DEBUG(dbgs() << "IR Promotion: For Sink: " << *I << "\n");
555
556 // Handle calls separately as we need to iterate over arg operands.
557 if (auto *Call = dyn_cast<CallInst>(I)) {
558 for (unsigned i = 0; i < Call->arg_size(); ++i) {
559 Value *Arg = Call->getArgOperand(i);
560 Type *Ty = TruncTysMap[Call][i];
561 if (Instruction *Trunc = InsertTrunc(Arg, Ty)) {
562 Trunc->moveBefore(Call->getIterator());
563 Call->setArgOperand(i, Trunc);
564 }
565 }
566 continue;
567 }
568
569 // Special case switches because we need to truncate the condition.
570 if (auto *Switch = dyn_cast<SwitchInst>(I)) {
571 Type *Ty = TruncTysMap[Switch][0];
572 if (Instruction *Trunc = InsertTrunc(Switch->getCondition(), Ty)) {
573 Trunc->moveBefore(Switch->getIterator());
574 Switch->setCondition(Trunc);
575 }
576 continue;
577 }
578
579 // Don't insert a trunc for a zext which can still legally promote.
580 // Nor insert a trunc when the input value to that trunc has the same width
581 // as the zext we are inserting it for. When this happens the input operand
582 // for the zext will be promoted to the same width as the zext's return type
583 // rendering that zext unnecessary. This zext gets removed before the end
584 // of the pass.
585 if (auto ZExt = dyn_cast<ZExtInst>(I))
586 if (ZExt->getType()->getScalarSizeInBits() >= PromotedWidth)
587 continue;
588
589 // Now handle the others.
590 for (unsigned i = 0; i < I->getNumOperands(); ++i) {
591 Type *Ty = TruncTysMap[I][i];
592 if (Instruction *Trunc = InsertTrunc(I->getOperand(i), Ty)) {
593 Trunc->moveBefore(I->getIterator());
594 I->setOperand(i, Trunc);
595 }
596 }
597 }
598}
599
600void IRPromoter::Cleanup() {
601 LLVM_DEBUG(dbgs() << "IR Promotion: Cleanup..\n");
602 // Some zexts will now have become redundant, along with their trunc
603 // operands, so remove them.
604 for (auto *V : Visited) {
605 if (!isa<ZExtInst>(V))
606 continue;
607
608 auto ZExt = cast<ZExtInst>(V);
609 if (ZExt->getDestTy() != ExtTy)
610 continue;
611
612 Value *Src = ZExt->getOperand(0);
613 if (ZExt->getSrcTy() == ZExt->getDestTy()) {
614 LLVM_DEBUG(dbgs() << "IR Promotion: Removing unnecessary cast: " << *ZExt
615 << "\n");
616 ReplaceAllUsersOfWith(ZExt, Src);
617 continue;
618 }
619
620 // We've inserted a trunc for a zext sink, but we already know that the
621 // input is in range, negating the need for the trunc.
622 if (NewInsts.count(Src) && isa<TruncInst>(Src)) {
623 auto *Trunc = cast<TruncInst>(Src);
624 assert(Trunc->getOperand(0)->getType() == ExtTy &&
625 "expected inserted trunc to be operating on i32");
626 ReplaceAllUsersOfWith(ZExt, Trunc->getOperand(0));
627 }
628 }
629
630 for (auto *I : InstsToRemove) {
631 LLVM_DEBUG(dbgs() << "IR Promotion: Removing " << *I << "\n");
632 I->dropAllReferences();
633 }
634}
635
636void IRPromoter::ConvertTruncs() {
637 LLVM_DEBUG(dbgs() << "IR Promotion: Converting truncs..\n");
638 IRBuilder<> Builder{Ctx};
639
640 for (auto *V : Visited) {
641 if (!isa<TruncInst>(V) || Sources.count(V))
642 continue;
643
644 auto *Trunc = cast<TruncInst>(V);
645 Builder.SetInsertPoint(Trunc);
646 IntegerType *SrcTy = cast<IntegerType>(Trunc->getOperand(0)->getType());
647 IntegerType *DestTy = cast<IntegerType>(TruncTysMap[Trunc][0]);
648
649 unsigned NumBits = DestTy->getScalarSizeInBits();
650 ConstantInt *Mask =
651 ConstantInt::get(SrcTy, APInt::getMaxValue(NumBits).getZExtValue());
652 Value *Masked = Builder.CreateAnd(Trunc->getOperand(0), Mask);
653 if (SrcTy->getBitWidth() > ExtTy->getBitWidth())
654 Masked = Builder.CreateTrunc(Masked, ExtTy);
655
656 if (auto *I = dyn_cast<Instruction>(Masked))
657 NewInsts.insert(I);
658
659 ReplaceAllUsersOfWith(Trunc, Masked);
660 }
661}
662
663void IRPromoter::Mutate() {
664 LLVM_DEBUG(dbgs() << "IR Promotion: Promoting use-def chains to "
665 << PromotedWidth << "-bits\n");
666
667 // Cache original types of the values that will likely need truncating
668 for (auto *I : Sinks) {
669 if (auto *Call = dyn_cast<CallInst>(I)) {
670 for (Value *Arg : Call->args())
671 TruncTysMap[Call].push_back(Arg->getType());
672 } else if (auto *Switch = dyn_cast<SwitchInst>(I))
673 TruncTysMap[I].push_back(Switch->getCondition()->getType());
674 else {
675 for (const Value *Op : I->operands())
676 TruncTysMap[I].push_back(Op->getType());
677 }
678 }
679 for (auto *V : Visited) {
680 if (!isa<TruncInst>(V) || Sources.count(V))
681 continue;
682 auto *Trunc = cast<TruncInst>(V);
683 TruncTysMap[Trunc].push_back(Trunc->getDestTy());
684 }
685
686 // Insert zext instructions between sources and their users.
687 ExtendSources();
688
689 // Promote visited instructions, mutating their types in place.
690 PromoteTree();
691
692 // Convert any truncs, that aren't sources, into AND masks.
693 ConvertTruncs();
694
695 // Insert trunc instructions for use by calls, stores etc...
696 TruncateSinks();
697
698 // Finally, remove unecessary zexts and truncs, delete old instructions and
699 // clear the data structures.
700 Cleanup();
701
702 LLVM_DEBUG(dbgs() << "IR Promotion: Mutation complete\n");
703}
704
705/// We disallow booleans to make life easier when dealing with icmps but allow
706/// any other integer that fits in a scalar register. Void types are accepted
707/// so we can handle switches.
708bool TypePromotionImpl::isSupportedType(Value *V) {
709 Type *Ty = V->getType();
710
711 // Allow voids and pointers, these won't be promoted.
712 if (Ty->isVoidTy() || Ty->isPointerTy())
713 return true;
714
715 if (!isa<IntegerType>(Ty) || cast<IntegerType>(Ty)->getBitWidth() == 1 ||
716 cast<IntegerType>(Ty)->getBitWidth() > RegisterBitWidth)
717 return false;
718
719 return LessOrEqualTypeSize(V);
720}
721
722/// We accept most instructions, as well as Arguments and ConstantInsts. We
723/// Disallow casts other than zext and truncs and only allow calls if their
724/// return value is zeroext. We don't allow opcodes that can introduce sign
725/// bits.
726bool TypePromotionImpl::isSupportedValue(Value *V) {
727 if (auto *I = dyn_cast<Instruction>(V)) {
728 switch (I->getOpcode()) {
729 default:
732 case Instruction::GetElementPtr:
733 case Instruction::Store:
734 case Instruction::CondBr:
735 case Instruction::Switch:
736 return true;
737 case Instruction::PHI:
738 case Instruction::Select:
739 case Instruction::Ret:
740 case Instruction::Load:
741 case Instruction::Trunc:
742 return isSupportedType(I);
743 case Instruction::BitCast:
744 return I->getOperand(0)->getType() == I->getType();
745 case Instruction::ZExt:
746 return isSupportedType(I->getOperand(0));
747 case Instruction::ICmp:
748 // Now that we allow small types than TypeSize, only allow icmp of
749 // TypeSize because they will require a trunc to be legalised.
750 // TODO: Allow icmp of smaller types, and calculate at the end
751 // whether the transform would be beneficial.
752 if (isa<PointerType>(I->getOperand(0)->getType()))
753 return true;
754 return EqualTypeSize(I->getOperand(0));
755 case Instruction::Call: {
756 // Special cases for calls as we need to check for zeroext
757 // TODO We should accept calls even if they don't have zeroext, as they
758 // can still be sinks.
759 auto *Call = cast<CallInst>(I);
760 return isSupportedType(Call) &&
761 Call->hasRetAttr(Attribute::AttrKind::ZExt);
762 }
763 }
764 } else if (isa<Constant>(V) && !isa<ConstantExpr>(V)) {
765 return isSupportedType(V);
766 } else if (isa<Argument>(V))
767 return isSupportedType(V);
768
769 return isa<BasicBlock>(V);
770}
771
772/// Check that the type of V would be promoted and that the original type is
773/// smaller than the targeted promoted type. Check that we're not trying to
774/// promote something larger than our base 'TypeSize' type.
775bool TypePromotionImpl::isLegalToPromote(Value *V) {
776 auto *I = dyn_cast<Instruction>(V);
777 if (!I)
778 return true;
779
780 if (SafeToPromote.count(I))
781 return true;
782
783 if (isPromotedResultSafe(I) || isSafeWrap(I)) {
784 SafeToPromote.insert(I);
785 return true;
786 }
787 return false;
788}
789
790bool TypePromotionImpl::TryToPromote(Value *V, unsigned PromotedWidth,
791 const LoopInfo &LI) {
792 Type *OrigTy = V->getType();
793 TypeSize = OrigTy->getPrimitiveSizeInBits().getFixedValue();
794 SafeToPromote.clear();
795 SafeWrap.clear();
796
797 if (!isSupportedValue(V) || !shouldPromote(V) || !isLegalToPromote(V))
798 return false;
799
800 LLVM_DEBUG(dbgs() << "IR Promotion: TryToPromote: " << *V << ", from "
801 << TypeSize << " bits to " << PromotedWidth << "\n");
802
803 SetVector<Value *> WorkList;
804 SetVector<Value *> Sources;
805 SetVector<Instruction *> Sinks;
806 SetVector<Value *> CurrentVisited;
807 WorkList.insert(V);
808
809 // Return true if V was added to the worklist as a supported instruction,
810 // if it was already visited, or if we don't need to explore it (e.g.
811 // pointer values and GEPs), and false otherwise.
812 auto AddLegalInst = [&](Value *V) {
813 if (CurrentVisited.count(V))
814 return true;
815
816 // Skip promoting GEPs as their indices should have already been
817 // canonicalized to pointer width.
819 return false;
820
821 if (!isSupportedValue(V) || (shouldPromote(V) && !isLegalToPromote(V))) {
822 LLVM_DEBUG(dbgs() << "IR Promotion: Can't handle: " << *V << "\n");
823 return false;
824 }
825
826 WorkList.insert(V);
827 return true;
828 };
829
830 // Iterate through, and add to, a tree of operands and users in the use-def.
831 while (!WorkList.empty()) {
832 Value *V = WorkList.pop_back_val();
833 if (CurrentVisited.count(V))
834 continue;
835
836 // Ignore non-instructions, other than arguments.
837 if (!isa<Instruction>(V) && !isSource(V))
838 continue;
839
840 // If we've already visited this value from somewhere, bail now because
841 // the tree has already been explored.
842 // TODO: This could limit the transform, ie if we try to promote something
843 // from an i8 and fail first, before trying an i16.
844 if (!AllVisited.insert(V).second)
845 return false;
846
847 CurrentVisited.insert(V);
848
849 // Calls can be both sources and sinks.
850 if (isSink(V))
851 Sinks.insert(cast<Instruction>(V));
852
853 if (isSource(V))
854 Sources.insert(V);
855
856 if (!isSink(V) && !isSource(V)) {
857 if (auto *I = dyn_cast<Instruction>(V)) {
858 // Visit operands of any instruction visited.
859 for (auto &U : I->operands()) {
860 if (!AddLegalInst(U))
861 return false;
862 }
863 }
864 }
865
866 // Don't visit users of a node which isn't going to be mutated unless its a
867 // source.
868 if (isSource(V) || shouldPromote(V)) {
869 for (Use &U : V->uses()) {
870 if (!AddLegalInst(U.getUser()))
871 return false;
872 }
873 }
874 }
875
876 LLVM_DEBUG({
877 dbgs() << "IR Promotion: Visited nodes:\n";
878 for (auto *I : CurrentVisited)
879 I->dump();
880 });
881
882 unsigned ToPromote = 0;
883 unsigned NonFreeArgs = 0;
884 unsigned NonLoopSources = 0, LoopSinks = 0;
885 SmallPtrSet<BasicBlock *, 4> Blocks;
886 for (auto *CV : CurrentVisited) {
887 if (auto *I = dyn_cast<Instruction>(CV))
888 Blocks.insert(I->getParent());
889
890 if (Sources.count(CV)) {
891 if (auto *Arg = dyn_cast<Argument>(CV))
892 if (!Arg->hasZExtAttr() && !Arg->hasSExtAttr())
893 ++NonFreeArgs;
894 if (!isa<Instruction>(CV) ||
895 !LI.getLoopFor(cast<Instruction>(CV)->getParent()))
896 ++NonLoopSources;
897 continue;
898 }
899
900 if (isa<PHINode>(CV))
901 continue;
902 if (LI.getLoopFor(cast<Instruction>(CV)->getParent()))
903 ++LoopSinks;
904 if (Sinks.count(cast<Instruction>(CV)))
905 continue;
906 ++ToPromote;
907 }
908
909 // DAG optimizations should be able to handle these cases better, especially
910 // for function arguments.
911 if (!isa<PHINode>(V) && !(LoopSinks && NonLoopSources) &&
912 (ToPromote < 2 || (Blocks.size() == 1 && NonFreeArgs > SafeWrap.size())))
913 return false;
914
915 IRPromoter Promoter(*Ctx, PromotedWidth, CurrentVisited, Sources, Sinks,
916 SafeWrap, InstsToRemove);
917 Promoter.Mutate();
918 return true;
919}
920
921bool TypePromotionImpl::run(Function &F, const TargetMachine *TM,
922 const TargetTransformInfo &TTI,
923 const LoopInfo &LI) {
925 return false;
926
927 LLVM_DEBUG(dbgs() << "IR Promotion: Running on " << F.getName() << "\n");
928
929 AllVisited.clear();
930 SafeToPromote.clear();
931 SafeWrap.clear();
932 bool MadeChange = false;
933 const DataLayout &DL = F.getDataLayout();
934 const TargetSubtargetInfo *SubtargetInfo = TM->getSubtargetImpl(F);
935 TLI = SubtargetInfo->getTargetLowering();
936 RegisterBitWidth =
938 Ctx = &F.getContext();
939
940 // Return the preferred integer width of the instruction, or zero if we
941 // shouldn't try.
942 auto GetPromoteWidth = [&](Instruction *I) -> uint32_t {
943 if (!isa<IntegerType>(I->getType()))
944 return 0;
945
946 EVT SrcVT = TLI->getValueType(DL, I->getType());
947 if (SrcVT.isSimple() && TLI->isTypeLegal(SrcVT.getSimpleVT()))
948 return 0;
949
950 if (TLI->getTypeAction(*Ctx, SrcVT) != TargetLowering::TypePromoteInteger)
951 return 0;
952
953 EVT PromotedVT = TLI->getTypeToTransformTo(*Ctx, SrcVT);
954 if (TLI->isSExtCheaperThanZExt(SrcVT, PromotedVT))
955 return 0;
956 if (RegisterBitWidth < PromotedVT.getFixedSizeInBits()) {
957 LLVM_DEBUG(dbgs() << "IR Promotion: Couldn't find target register "
958 << "for promoted type\n");
959 return 0;
960 }
961
962 // TODO: Should we prefer to use RegisterBitWidth instead?
963 return PromotedVT.getFixedSizeInBits();
964 };
965
966 auto BBIsInLoop = [&](BasicBlock *BB) -> bool {
967 for (auto *L : LI)
968 if (L->contains(BB))
969 return true;
970 return false;
971 };
972
973 for (BasicBlock &BB : F) {
974 for (Instruction &I : BB) {
975 if (AllVisited.count(&I))
976 continue;
977
978 if (isa<ZExtInst>(&I) && isa<PHINode>(I.getOperand(0)) &&
979 isa<IntegerType>(I.getType()) && BBIsInLoop(&BB)) {
980 LLVM_DEBUG(dbgs() << "IR Promotion: Searching from: "
981 << *I.getOperand(0) << "\n");
982 EVT ZExtVT = TLI->getValueType(DL, I.getType());
983 Instruction *Phi = static_cast<Instruction *>(I.getOperand(0));
984 auto PromoteWidth = ZExtVT.getFixedSizeInBits();
985 if (RegisterBitWidth < PromoteWidth) {
986 LLVM_DEBUG(dbgs() << "IR Promotion: Couldn't find target "
987 << "register for ZExt type\n");
988 continue;
989 }
990 MadeChange |= TryToPromote(Phi, PromoteWidth, LI);
991 } else if (auto *ICmp = dyn_cast<ICmpInst>(&I)) {
992 // Search up from icmps to try to promote their operands.
993 // Skip signed or pointer compares
994 if (ICmp->isSigned())
995 continue;
996
997 LLVM_DEBUG(dbgs() << "IR Promotion: Searching from: " << *ICmp << "\n");
998
999 for (auto &Op : ICmp->operands()) {
1000 if (auto *OpI = dyn_cast<Instruction>(Op)) {
1001 if (auto PromotedWidth = GetPromoteWidth(OpI)) {
1002 MadeChange |= TryToPromote(OpI, PromotedWidth, LI);
1003 break;
1004 }
1005 }
1006 }
1007 }
1008 }
1009 if (!InstsToRemove.empty()) {
1010 for (auto *I : InstsToRemove)
1011 I->eraseFromParent();
1012 InstsToRemove.clear();
1013 }
1014 }
1015
1016 AllVisited.clear();
1017 SafeToPromote.clear();
1018 SafeWrap.clear();
1019
1020 return MadeChange;
1021}
1022
1023INITIALIZE_PASS_BEGIN(TypePromotionLegacy, DEBUG_TYPE, PASS_NAME, false, false)
1024INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
1025INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
1026INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
1027INITIALIZE_PASS_END(TypePromotionLegacy, DEBUG_TYPE, PASS_NAME, false, false)
1028
1029char TypePromotionLegacy::ID = 0;
1030
1031bool TypePromotionLegacy::runOnFunction(Function &F) {
1032 if (skipFunction(F))
1033 return false;
1034
1035 auto &TPC = getAnalysis<TargetPassConfig>();
1036 auto *TM = &TPC.getTM<TargetMachine>();
1037 auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
1038 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
1039
1040 TypePromotionImpl TP;
1041 return TP.run(F, TM, TTI, LI);
1042}
1043
1045 return new TypePromotionLegacy();
1046}
1047
1050 auto &TTI = AM.getResult<TargetIRAnalysis>(F);
1051 auto &LI = AM.getResult<LoopAnalysis>(F);
1052 TypePromotionImpl TP;
1053
1054 bool Changed = TP.run(F, TM, TTI, LI);
1055 if (!Changed)
1056 return PreservedAnalyses::all();
1057
1060 return PA;
1061}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isSupportedType(const DataLayout &DL, const ARMTargetLowering &TLI, Type *T)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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
ManagedStatic< HTTPClientCleanup > Cleanup
iv Induction Variable Users
Definition IVUsers.cpp:48
#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
This file implements a set that has insertion order iteration characteristics.
#define LLVM_DEBUG(...)
Definition Debug.h:119
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
static bool isPromotedResultSafe(Instruction *I)
Return whether we can safely mutate V's type to ExtTy without having to be concerned with zero extend...
static cl::opt< bool > DisablePromotion("disable-type-promotion", cl::Hidden, cl::init(false), cl::desc("Disable type promotion pass"))
static bool GenerateSignBits(Instruction *I)
#define PASS_NAME
Defines an IR pass for type promotion.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition APInt.cpp:1055
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition APInt.h:207
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Definition APInt.h:1191
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1513
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
Definition APInt.h:362
int64_t getSExtValue() const
Get sign extended value.
Definition APInt.h:1587
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:275
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
void SetCurrentDebugLocation(const DebugLoc &L)
Set location information used by debugging information.
Definition IRBuilder.h:221
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition IRBuilder.h:2121
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1570
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Definition IRBuilder.h:2107
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition IRBuilder.h:181
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.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Analysis pass that exposes the LoopInfo for a function.
Definition LoopInfo.h:587
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
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 & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
A vector that has set insertion semantics.
Definition SetVector.h:57
size_type count(const_arg_type key) const
Count the number of elements of a given key in the SetVector.
Definition SetVector.h:268
bool empty() const
Determine if the SetVector is empty or not.
Definition SetVector.h:100
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
value_type pop_back_val()
Definition SetVector.h:285
size_type size() const
Definition SmallPtrSet.h:99
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Analysis pass providing the TargetTransformInfo.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy) const
Return true if sign-extension from FromTy to ToTy is cheaper than zero-extension.
virtual EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
virtual bool isLegalAddImmediate(int64_t) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
virtual const TargetLowering * getTargetLowering() const
LLVM_ABI TypeSize getRegisterBitWidth(RegisterKind K) const
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:282
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:197
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:232
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:141
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
iterator_range< use_iterator > uses()
Definition Value.h:380
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
self_iterator getIterator()
Definition ilist_node.h:123
CallInst * Call
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
initializer< Ty > init(const Ty &Val)
@ Switch
The "resume-switch" lowering, where there are separate resume and destroy functions that are shared b...
Definition CoroShape.h:32
DXILDebugInfoMap run(Module &M)
@ User
could "use" a pointer
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
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 bool isLegalToPromote(const CallBase &CB, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
LLVM_ABI FunctionPass * createTypePromotionLegacyPass()
Create IR Type Promotion pass.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Store
The extracted value is stored (ExtractElement only).
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
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
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVMAttributeRef wrap(Attribute Attr)
Definition Attributes.h:392
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:145
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:339
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition ValueTypes.h:404