LLVM 24.0.0git
Instructions.cpp
Go to the documentation of this file.
1//===- Instructions.cpp - Implement the LLVM instructions -----------------===//
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 implements all of the non-inline methods for the LLVM instruction
10// classes.
11//
12//===----------------------------------------------------------------------===//
13
15#include "LLVMContextImpl.h"
18#include "llvm/ADT/Twine.h"
19#include "llvm/IR/Attributes.h"
20#include "llvm/IR/BasicBlock.h"
21#include "llvm/IR/Constant.h"
23#include "llvm/IR/Constants.h"
24#include "llvm/IR/DataLayout.h"
26#include "llvm/IR/Function.h"
27#include "llvm/IR/InstrTypes.h"
28#include "llvm/IR/Instruction.h"
29#include "llvm/IR/Intrinsics.h"
30#include "llvm/IR/LLVMContext.h"
31#include "llvm/IR/MDBuilder.h"
32#include "llvm/IR/Metadata.h"
33#include "llvm/IR/Module.h"
34#include "llvm/IR/Operator.h"
37#include "llvm/IR/Type.h"
38#include "llvm/IR/Value.h"
46#include "llvm/Support/ModRef.h"
48#include <algorithm>
49#include <cassert>
50#include <cstdint>
51#include <optional>
52#include <vector>
53
54using namespace llvm;
55
57 "disable-i2p-p2i-opt", cl::init(false),
58 cl::desc("Disables inttoptr/ptrtoint roundtrip optimization"));
59
60//===----------------------------------------------------------------------===//
61// AllocaInst Class
62//===----------------------------------------------------------------------===//
63
65 return DL.getTypeAllocSize(getAllocatedType());
66}
67
68std::optional<TypeSize>
71 // Zero-sized types can return early since 0 * N = 0 for any array size N.
72 if (Size.isZero())
73 return Size;
74 if (isArrayAllocation()) {
76 if (!C)
77 return std::nullopt;
78 std::optional<uint64_t> NumElements = C->getValue().tryZExtValue();
79 if (!NumElements)
80 return std::nullopt;
81 assert(!Size.isScalable() && "Array elements cannot have a scalable size");
82 auto CheckedProd =
83 checkedMulUnsigned(Size.getKnownMinValue(), *NumElements);
84 if (!CheckedProd)
85 return std::nullopt;
86 return TypeSize::getFixed(*CheckedProd);
87 }
88 return Size;
89}
90
91std::optional<TypeSize>
93 std::optional<TypeSize> Size = getAllocationSize(DL);
94 if (!Size)
95 return std::nullopt;
96 auto CheckedProd = checkedMulUnsigned(Size->getKnownMinValue(),
97 static_cast<TypeSize::ScalarTy>(8));
98 if (!CheckedProd)
99 return std::nullopt;
100 return TypeSize::get(*CheckedProd, Size->isScalable());
101}
102
103//===----------------------------------------------------------------------===//
104// SelectInst Class
105//===----------------------------------------------------------------------===//
106
107/// areInvalidOperands - Return a string if the specified operands are invalid
108/// for a select operation, otherwise return null.
109const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
110 if (Op1->getType() != Op2->getType())
111 return "both values to select must have same type";
112
113 if (Op1->getType()->isTokenTy())
114 return "select values cannot have token type";
115
116 if (VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
117 // Vector select.
118 if (VT->getElementType() != Type::getInt1Ty(Op0->getContext()))
119 return "vector select condition element type must be i1";
121 if (!ET)
122 return "selected values for vector select must be vectors";
123 if (ET->getElementCount() != VT->getElementCount())
124 return "vector select requires selected vectors to have "
125 "the same vector length as select condition";
126 } else if (Op0->getType() != Type::getInt1Ty(Op0->getContext())) {
127 return "select condition must be i1 or <n x i1>";
128 }
129 return nullptr;
130}
131
132//===----------------------------------------------------------------------===//
133// PHINode Class
134//===----------------------------------------------------------------------===//
135
136PHINode::PHINode(const PHINode &PN)
137 : Instruction(PN.getType(), Instruction::PHI, AllocMarker),
138 ReservedSpace(PN.getNumOperands()) {
141 std::copy(PN.op_begin(), PN.op_end(), op_begin());
142 copyIncomingBlocks(make_range(PN.block_begin(), PN.block_end()));
143 FMF = PN.FMF;
144}
145
146// removeIncomingValue - Remove an incoming value. This is useful if a
147// predecessor basic block is deleted.
148Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
149 Value *Removed = getIncomingValue(Idx);
150 // Swap with the end of the list.
151 unsigned Last = getNumOperands() - 1;
152 if (Idx != Last) {
155 }
156
157 // Nuke the last value.
158 Op<-1>().set(nullptr);
160
161 // If the PHI node is dead, because it has zero entries, nuke it now.
162 if (getNumOperands() == 0 && DeletePHIIfEmpty) {
163 // If anyone is using this PHI, make them use a dummy value instead...
166 }
167 return Removed;
168}
169
170void PHINode::removeIncomingValueIf(function_ref<bool(unsigned)> Predicate,
171 bool DeletePHIIfEmpty) {
172 unsigned NumOps = getNumIncomingValues();
173
174 // Loop backwards in case the predicate is purely index based.
175 for (unsigned Idx = NumOps; Idx-- > 0;) {
176 if (Predicate(Idx)) {
177 unsigned LastIdx = NumOps - 1;
178 if (Idx != LastIdx) {
179 setIncomingValue(Idx, getIncomingValue(LastIdx));
180 setIncomingBlock(Idx, getIncomingBlock(LastIdx));
181 }
182 getOperandUse(LastIdx).set(nullptr);
183 NumOps--;
184 }
185 }
186
188
189 // If the PHI node is dead, because it has zero entries, nuke it now.
190 if (getNumOperands() == 0 && DeletePHIIfEmpty) {
191 // If anyone is using this PHI, make them use a dummy value instead...
194 }
195}
196
197/// growOperands - grow operands - This grows the operand list in response
198/// to a push_back style of operation. This grows the number of ops by 1.5
199/// times.
200///
201void PHINode::growOperands() {
202 unsigned e = getNumOperands();
203 unsigned NumOps = e + e / 2;
204 if (NumOps < 2) NumOps = 2; // 2 op PHI nodes are VERY common.
205
206 ReservedSpace = NumOps;
207 growHungoffUses(ReservedSpace, /*WithExtraValues=*/true);
208}
209
210/// hasConstantValue - If the specified PHI node always merges together the same
211/// value, return the value, otherwise return null.
213 // Exploit the fact that phi nodes always have at least one entry.
214 Value *ConstantValue = getIncomingValue(0);
215 for (unsigned i = 1, e = getNumIncomingValues(); i != e; ++i)
216 if (getIncomingValue(i) != ConstantValue && getIncomingValue(i) != this) {
217 if (ConstantValue != this)
218 return nullptr; // Incoming values not all the same.
219 // The case where the first value is this PHI.
220 ConstantValue = getIncomingValue(i);
221 }
222 if (ConstantValue == this)
223 return PoisonValue::get(getType());
224 return ConstantValue;
225}
226
227/// hasConstantOrUndefValue - Whether the specified PHI node always merges
228/// together the same value, assuming that undefs result in the same value as
229/// non-undefs.
230/// Unlike \ref hasConstantValue, this does not return a value because the
231/// unique non-undef incoming value need not dominate the PHI node.
233 Value *ConstantValue = nullptr;
234 for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) {
235 Value *Incoming = getIncomingValue(i);
236 if (Incoming != this && !isa<UndefValue>(Incoming)) {
237 if (ConstantValue && ConstantValue != Incoming)
238 return false;
239 ConstantValue = Incoming;
240 }
241 }
242 return true;
243}
244
245//===----------------------------------------------------------------------===//
246// LandingPadInst Implementation
247//===----------------------------------------------------------------------===//
248
249LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
250 const Twine &NameStr,
251 InsertPosition InsertBefore)
252 : Instruction(RetTy, Instruction::LandingPad, AllocMarker, InsertBefore) {
253 init(NumReservedValues, NameStr);
254}
255
256LandingPadInst::LandingPadInst(const LandingPadInst &LP)
257 : Instruction(LP.getType(), Instruction::LandingPad, AllocMarker),
258 ReservedSpace(LP.getNumOperands()) {
261 Use *OL = getOperandList();
262 const Use *InOL = LP.getOperandList();
263 for (unsigned I = 0, E = ReservedSpace; I != E; ++I)
264 OL[I] = InOL[I];
265
266 setCleanup(LP.isCleanup());
267}
268
269LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
270 const Twine &NameStr,
271 InsertPosition InsertBefore) {
272 return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertBefore);
273}
274
275void LandingPadInst::init(unsigned NumReservedValues, const Twine &NameStr) {
276 ReservedSpace = NumReservedValues;
277 allocHungoffUses(ReservedSpace);
279 setName(NameStr);
280 setCleanup(false);
281}
282
283/// growOperands - grow operands - This grows the operand list in response to a
284/// push_back style of operation. This grows the number of ops by 2 times.
285void LandingPadInst::growOperands(unsigned Size) {
286 unsigned e = getNumOperands();
287 if (ReservedSpace >= e + Size) return;
288 ReservedSpace = (std::max(e, 1U) + Size / 2) * 2;
289 growHungoffUses(ReservedSpace);
290}
291
293 unsigned OpNo = getNumOperands();
294 growOperands(1);
295 assert(OpNo < ReservedSpace && "Growing didn't work!");
297 getOperandList()[OpNo] = Val;
298}
299
300//===----------------------------------------------------------------------===//
301// CallBase Implementation
302//===----------------------------------------------------------------------===//
303
305 InsertPosition InsertPt) {
306 switch (CB->getOpcode()) {
307 case Instruction::Call:
308 return CallInst::Create(cast<CallInst>(CB), Bundles, InsertPt);
309 case Instruction::Invoke:
310 return InvokeInst::Create(cast<InvokeInst>(CB), Bundles, InsertPt);
311 case Instruction::CallBr:
312 return CallBrInst::Create(cast<CallBrInst>(CB), Bundles, InsertPt);
313 default:
314 llvm_unreachable("Unknown CallBase sub-class!");
315 }
316}
317
319 InsertPosition InsertPt) {
321 for (unsigned i = 0, e = CI->getNumOperandBundles(); i < e; ++i) {
322 auto ChildOB = CI->getOperandBundleAt(i);
323 if (ChildOB.getTagName() != OpB.getTag())
324 OpDefs.emplace_back(ChildOB);
325 }
326 OpDefs.emplace_back(OpB);
327 return CallBase::Create(CI, OpDefs, InsertPt);
328}
329
331
333 assert(getOpcode() == Instruction::CallBr && "Unexpected opcode!");
334 return cast<CallBrInst>(this)->getNumIndirectDests() + 1;
335}
336
338 const Value *V = getCalledOperand();
339 if (isa<Function>(V) || isa<Constant>(V))
340 return false;
341 return !isInlineAsm();
342}
343
344/// Tests if this call site must be tail call optimized. Only a CallInst can
345/// be tail call optimized.
347 if (auto *CI = dyn_cast<CallInst>(this))
348 return CI->isMustTailCall();
349 return false;
350}
351
352/// Tests if this call site is marked as a tail call.
354 if (auto *CI = dyn_cast<CallInst>(this))
355 return CI->isTailCall();
356 return false;
357}
358
361 return F->getIntrinsicID();
363}
364
366 FPClassTest Mask = Attrs.getRetNoFPClass();
367
368 if (const Function *F = getCalledFunction())
369 Mask |= F->getAttributes().getRetNoFPClass();
370 return Mask;
371}
372
374 FPClassTest Mask = Attrs.getParamNoFPClass(i);
375
376 if (const Function *F = getCalledFunction())
377 Mask |= F->getAttributes().getParamNoFPClass(i);
378 return Mask;
379}
380
381std::optional<ConstantRange> CallBase::getRange() const {
382 Attribute CallAttr = Attrs.getRetAttr(Attribute::Range);
384 if (const Function *F = getCalledFunction())
385 FnAttr = F->getRetAttribute(Attribute::Range);
386
387 if (CallAttr.isValid() && FnAttr.isValid())
388 return CallAttr.getRange().intersectWith(FnAttr.getRange());
389 if (CallAttr.isValid())
390 return CallAttr.getRange();
391 if (FnAttr.isValid())
392 return FnAttr.getRange();
393 return std::nullopt;
394}
395
397 if (hasRetAttr(Attribute::NonNull))
398 return true;
399
400 if (getRetDereferenceableBytes() > 0 &&
402 return true;
403
404 return false;
405}
406
408 unsigned Index;
409
410 if (Attrs.hasAttrSomewhere(Kind, &Index))
411 return getArgOperand(Index - AttributeList::FirstArgIndex);
412 if (const Function *F = getCalledFunction())
413 if (F->getAttributes().hasAttrSomewhere(Kind, &Index))
414 return getArgOperand(Index - AttributeList::FirstArgIndex);
415
416 return nullptr;
417}
418
419/// Determine whether the argument or parameter has the given attribute.
420bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
421 assert(ArgNo < arg_size() && "Param index out of bounds!");
422
423 if (Attrs.hasParamAttr(ArgNo, Kind))
424 return true;
425
426 const Function *F = getCalledFunction();
427 if (!F)
428 return false;
429
430 if (!F->getAttributes().hasParamAttr(ArgNo, Kind))
431 return false;
432
433 // Take into account mod/ref by operand bundles.
434 switch (Kind) {
435 case Attribute::ReadNone:
437 case Attribute::ReadOnly:
439 case Attribute::WriteOnly:
440 return !hasReadingOperandBundles();
441 default:
442 return true;
443 }
444}
445
447 bool AllowUndefOrPoison) const {
449 "Argument must be a pointer");
450 if (paramHasAttr(ArgNo, Attribute::NonNull) &&
451 (AllowUndefOrPoison || paramHasAttr(ArgNo, Attribute::NoUndef)))
452 return true;
453
454 if (paramHasAttr(ArgNo, Attribute::Dereferenceable) &&
456 getCaller(),
458 return true;
459
460 return false;
461}
462
463bool CallBase::hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const {
465 return F->getAttributes().hasFnAttr(Kind);
466
467 return false;
468}
469
470bool CallBase::hasFnAttrOnCalledFunction(StringRef Kind) const {
472 return F->getAttributes().hasFnAttr(Kind);
473
474 return false;
475}
476
477template <typename AK>
478Attribute CallBase::getFnAttrOnCalledFunction(AK Kind) const {
479 if constexpr (std::is_same_v<AK, Attribute::AttrKind>) {
480 // getMemoryEffects() correctly combines memory effects from the call-site,
481 // operand bundles and function.
482 assert(Kind != Attribute::Memory && "Use getMemoryEffects() instead");
483 }
484
486 return F->getAttributes().getFnAttr(Kind);
487
488 return Attribute();
489}
490
491template LLVM_ABI Attribute
492CallBase::getFnAttrOnCalledFunction(Attribute::AttrKind Kind) const;
493template LLVM_ABI Attribute
494CallBase::getFnAttrOnCalledFunction(StringRef Kind) const;
495
496template <typename AK>
497Attribute CallBase::getParamAttrOnCalledFunction(unsigned ArgNo,
498 AK Kind) const {
500
501 if (auto *F = dyn_cast<Function>(V))
502 return F->getAttributes().getParamAttr(ArgNo, Kind);
503
504 return Attribute();
505}
506template LLVM_ABI Attribute CallBase::getParamAttrOnCalledFunction(
507 unsigned ArgNo, Attribute::AttrKind Kind) const;
508template LLVM_ABI Attribute
509CallBase::getParamAttrOnCalledFunction(unsigned ArgNo, StringRef Kind) const;
510
513 for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
515}
516
519 const unsigned BeginIndex) {
520 auto It = op_begin() + BeginIndex;
521 for (auto &B : Bundles)
522 It = std::copy(B.input_begin(), B.input_end(), It);
523
524 auto *ContextImpl = getContext().pImpl;
525 auto BI = Bundles.begin();
526 unsigned CurrentIndex = BeginIndex;
527
528 for (auto &BOI : bundle_op_infos()) {
529 assert(BI != Bundles.end() && "Incorrect allocation?");
530
531 BOI.Tag = ContextImpl->getOrInsertBundleTag(BI->getTag());
532 BOI.Begin = CurrentIndex;
533 BOI.End = CurrentIndex + BI->input_size();
534 CurrentIndex = BOI.End;
535 BI++;
536 }
537
538 assert(BI == Bundles.end() && "Incorrect allocation?");
539
540 return It;
541}
542
544 /// When there isn't many bundles, we do a simple linear search.
545 /// Else fallback to a binary-search that use the fact that bundles usually
546 /// have similar number of argument to get faster convergence.
548 for (auto &BOI : bundle_op_infos())
549 if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
550 return BOI;
551
552 llvm_unreachable("Did not find operand bundle for operand!");
553 }
554
555 assert(OpIdx >= arg_size() && "the Idx is not in the operand bundles");
557 OpIdx < std::prev(bundle_op_info_end())->End &&
558 "The Idx isn't in the operand bundle");
559
560 /// We need a decimal number below and to prevent using floating point numbers
561 /// we use an intergal value multiplied by this constant.
562 constexpr unsigned NumberScaling = 1024;
563
566 bundle_op_iterator Current = Begin;
567
568 while (Begin != End) {
569 unsigned ScaledOperandPerBundle =
570 NumberScaling * (std::prev(End)->End - Begin->Begin) / (End - Begin);
571 Current = Begin + (((OpIdx - Begin->Begin) * NumberScaling) /
572 ScaledOperandPerBundle);
573 if (Current >= End)
574 Current = std::prev(End);
575 assert(Current < End && Current >= Begin &&
576 "the operand bundle doesn't cover every value in the range");
577 if (OpIdx >= Current->Begin && OpIdx < Current->End)
578 break;
579 if (OpIdx >= Current->End)
580 Begin = Current + 1;
581 else
582 End = Current;
583 }
584
585 assert(OpIdx >= Current->Begin && OpIdx < Current->End &&
586 "the operand bundle doesn't cover every value in the range");
587 return *Current;
588}
589
592 InsertPosition InsertPt) {
593 if (CB->getOperandBundle(ID))
594 return CB;
595
597 CB->getOperandBundlesAsDefs(Bundles);
598 Bundles.push_back(OB);
599 return Create(CB, Bundles, InsertPt);
600}
601
603 InsertPosition InsertPt) {
605 bool CreateNew = false;
606
607 for (unsigned I = 0, E = CB->getNumOperandBundles(); I != E; ++I) {
608 auto Bundle = CB->getOperandBundleAt(I);
609 if (Bundle.getTagID() == ID) {
610 CreateNew = true;
611 continue;
612 }
613 Bundles.emplace_back(Bundle);
614 }
615
616 return CreateNew ? Create(CB, Bundles, InsertPt) : CB;
617}
618
620 InsertPosition InsertPt) {
621 auto OpBundleCount = CB->getNumOperandBundles();
622 assert(Offset < OpBundleCount &&
623 "Trying to remove non-existant operand bundle");
625 Bundles.reserve(OpBundleCount - 1);
626 size_t I = 0;
627 for (; I != Offset; ++I)
628 Bundles.emplace_back(CB->getOperandBundleAt(I));
629 ++I;
630 for (; I != OpBundleCount; ++I)
631 Bundles.emplace_back(CB->getOperandBundleAt(I));
632 return Create(CB, Bundles, InsertPt);
633}
634
636 // Implementation note: this is a conservative implementation of operand
637 // bundle semantics, where *any* non-assume operand bundle (other than
638 // ptrauth) forces a callsite to be at least readonly.
643 getIntrinsicID() != Intrinsic::assume;
644}
645
654
656 MemoryEffects ME = getAttributes().getMemoryEffects();
657 if (auto *Fn = dyn_cast<Function>(getCalledOperand())) {
658 MemoryEffects FnME = Fn->getMemoryEffects();
659 if (hasOperandBundles()) {
660 // TODO: Add a method to get memory effects for operand bundles instead.
662 FnME |= MemoryEffects::readOnly();
664 FnME |= MemoryEffects::writeOnly();
665 }
666 if (isVolatile()) {
667 // Volatile operations also access inaccessible memory.
669 }
670 ME &= FnME;
671 }
672 return ME;
673}
677
678/// Determine if the function does not access memory.
685
686/// Determine if the function does not access or only reads memory.
693
694/// Determine if the function does not access or only writes memory.
701
702/// Determine if the call can access memmory only using pointers based
703/// on its arguments.
710
711/// Determine if the function may only access memory that is
712/// inaccessible from the IR.
719
720/// Determine if the function may only access memory that is
721/// either inaccessible from the IR or pointed to by its arguments.
729
731 if (OpNo < arg_size()) {
732 // If the argument is passed byval, the callee does not have access to the
733 // original pointer and thus cannot capture it.
734 if (isByValArgument(OpNo))
735 return CaptureInfo::none();
736
738 if (auto *Fn = dyn_cast<Function>(getCalledOperand()))
739 CI &= Fn->getAttributes().getParamAttrs(OpNo).getCaptureInfo();
740 return CI;
741 }
742
743 // Bundles on assumes are captures(none).
744 if (getIntrinsicID() == Intrinsic::assume)
745 return CaptureInfo::none();
746
747 // deopt operand bundles are captures(none)
748 auto &BOI = getBundleOpInfoForOperand(OpNo);
749 auto OBU = operandBundleFromBundleOpInfo(BOI);
750 return OBU.isDeoptOperandBundle() ? CaptureInfo::none() : CaptureInfo::all();
751}
752
754 for (unsigned I = 0, E = arg_size(); I < E; ++I) {
756 continue;
757
759 if (auto *Fn = dyn_cast<Function>(getCalledOperand()))
760 CI &= Fn->getAttributes().getParamAttrs(I).getCaptureInfo();
762 return true;
763 }
764 return false;
765}
766
767//===----------------------------------------------------------------------===//
768// CallInst Implementation
769//===----------------------------------------------------------------------===//
770
771void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
772 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
773 this->FTy = FTy;
774 assert(getNumOperands() == Args.size() + CountBundleInputs(Bundles) + 1 &&
775 "NumOperands not set up?");
776
777#ifndef NDEBUG
778 assert((Args.size() == FTy->getNumParams() ||
779 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
780 "Calling a function with bad signature!");
781
782 for (unsigned i = 0; i != Args.size(); ++i)
783 assert((i >= FTy->getNumParams() ||
784 FTy->getParamType(i) == Args[i]->getType()) &&
785 "Calling a function with a bad signature!");
786#endif
787
788 // Set operands in order of their index to match use-list-order
789 // prediction.
790 llvm::copy(Args, op_begin());
791 setCalledOperand(Func);
792
793 auto It = populateBundleOperandInfos(Bundles, Args.size());
794 (void)It;
795 assert(It + 1 == op_end() && "Should add up!");
796
797 setName(NameStr);
798}
799
800void CallInst::init(FunctionType *FTy, Value *Func, const Twine &NameStr) {
801 this->FTy = FTy;
802 assert(getNumOperands() == 1 && "NumOperands not set up?");
803 setCalledOperand(Func);
804
805 assert(FTy->getNumParams() == 0 && "Calling a function with bad signature");
806
807 setName(NameStr);
808}
809
810CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
811 AllocInfo AllocInfo, InsertPosition InsertBefore)
812 : CallBase(Ty->getReturnType(), Instruction::Call, AllocInfo,
813 InsertBefore) {
814 init(Ty, Func, Name);
815}
816
817CallInst::CallInst(const CallInst &CI, AllocInfo AllocInfo)
818 : CallBase(CI.Attrs, CI.FTy, CI.getType(), Instruction::Call, AllocInfo) {
820 "Wrong number of operands allocated");
821 setTailCallKind(CI.getTailCallKind());
823
824 std::copy(CI.op_begin(), CI.op_end(), op_begin());
825 std::copy(CI.bundle_op_info_begin(), CI.bundle_op_info_end(),
827 FMF = CI.FMF;
828}
829
831 InsertPosition InsertPt) {
832 std::vector<Value *> Args(CI->arg_begin(), CI->arg_end());
833
834 auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledOperand(),
835 Args, OpB, CI->getName(), InsertPt);
836 NewCI->setTailCallKind(CI->getTailCallKind());
837 NewCI->setCallingConv(CI->getCallingConv());
838 NewCI->FMF = CI->FMF;
839 NewCI->setAttributes(CI->getAttributes());
840 NewCI->setDebugLoc(CI->getDebugLoc());
841 return NewCI;
842}
843
844// Update profile weight for call instruction by scaling it using the ratio
845// of S/T. The meaning of "branch_weights" meta data for call instruction is
846// transfered to represent call count.
847void CallInst::updateProfWeight(uint64_t S, uint64_t T) {
848 if (T == 0) {
849 LLVM_DEBUG(dbgs() << "Attempting to update profile weights will result in "
850 "div by 0. Ignoring. Likely the function "
851 << getParent()->getParent()->getName()
852 << " has 0 entry count, and contains call instructions "
853 "with non-zero prof info.");
854 return;
855 }
856 scaleProfData(*this, S, T);
857}
858
859//===----------------------------------------------------------------------===//
860// InvokeInst Implementation
861//===----------------------------------------------------------------------===//
862
863void InvokeInst::init(FunctionType *FTy, Value *Fn, BasicBlock *IfNormal,
864 BasicBlock *IfException, ArrayRef<Value *> Args,
866 const Twine &NameStr) {
867 this->FTy = FTy;
868
870 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)) &&
871 "NumOperands not set up?");
872
873#ifndef NDEBUG
874 assert(((Args.size() == FTy->getNumParams()) ||
875 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
876 "Invoking a function with bad signature");
877
878 for (unsigned i = 0, e = Args.size(); i != e; i++)
879 assert((i >= FTy->getNumParams() ||
880 FTy->getParamType(i) == Args[i]->getType()) &&
881 "Invoking a function with a bad signature!");
882#endif
883
884 // Set operands in order of their index to match use-list-order
885 // prediction.
886 llvm::copy(Args, op_begin());
887 setNormalDest(IfNormal);
888 setUnwindDest(IfException);
890
891 auto It = populateBundleOperandInfos(Bundles, Args.size());
892 (void)It;
893 assert(It + 3 == op_end() && "Should add up!");
894
895 setName(NameStr);
896}
897
898InvokeInst::InvokeInst(const InvokeInst &II, AllocInfo AllocInfo)
899 : CallBase(II.Attrs, II.FTy, II.getType(), Instruction::Invoke, AllocInfo) {
900 assert(getNumOperands() == II.getNumOperands() &&
901 "Wrong number of operands allocated");
902 setCallingConv(II.getCallingConv());
903 std::copy(II.op_begin(), II.op_end(), op_begin());
904 std::copy(II.bundle_op_info_begin(), II.bundle_op_info_end(),
906 SubclassOptionalData = II.SubclassOptionalData;
907}
908
910 InsertPosition InsertPt) {
911 std::vector<Value *> Args(II->arg_begin(), II->arg_end());
912
913 auto *NewII = InvokeInst::Create(
914 II->getFunctionType(), II->getCalledOperand(), II->getNormalDest(),
915 II->getUnwindDest(), Args, OpB, II->getName(), InsertPt);
916 NewII->setCallingConv(II->getCallingConv());
917 NewII->SubclassOptionalData = II->SubclassOptionalData;
918 NewII->setAttributes(II->getAttributes());
919 NewII->setDebugLoc(II->getDebugLoc());
920 return NewII;
921}
922
924 return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHIIt());
925}
926
927void InvokeInst::updateProfWeight(uint64_t S, uint64_t T) {
928 if (T == 0) {
929 LLVM_DEBUG(dbgs() << "Attempting to update profile weights will result in "
930 "div by 0. Ignoring. Likely the function "
931 << getParent()->getParent()->getName()
932 << " has 0 entry count, and contains call instructions "
933 "with non-zero prof info.");
934 return;
935 }
936 scaleProfData(*this, S, T);
937}
938
939//===----------------------------------------------------------------------===//
940// CallBrInst Implementation
941//===----------------------------------------------------------------------===//
942
943void CallBrInst::init(FunctionType *FTy, Value *Fn, BasicBlock *Fallthrough,
944 ArrayRef<BasicBlock *> IndirectDests,
947 const Twine &NameStr) {
948 this->FTy = FTy;
949
950 assert(getNumOperands() == ComputeNumOperands(Args.size(),
951 IndirectDests.size(),
952 CountBundleInputs(Bundles)) &&
953 "NumOperands not set up?");
954
955#ifndef NDEBUG
956 assert(((Args.size() == FTy->getNumParams()) ||
957 (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
958 "Calling a function with bad signature");
959
960 for (unsigned i = 0, e = Args.size(); i != e; i++)
961 assert((i >= FTy->getNumParams() ||
962 FTy->getParamType(i) == Args[i]->getType()) &&
963 "Calling a function with a bad signature!");
964#endif
965
966 // Set operands in order of their index to match use-list-order
967 // prediction.
968 llvm::copy(Args, op_begin());
969 NumIndirectDests = IndirectDests.size();
970 setDefaultDest(Fallthrough);
971 for (unsigned i = 0; i != NumIndirectDests; ++i)
972 setIndirectDest(i, IndirectDests[i]);
974
975 auto It = populateBundleOperandInfos(Bundles, Args.size());
976 (void)It;
977 assert(It + 2 + IndirectDests.size() == op_end() && "Should add up!");
978
979 setName(NameStr);
980}
981
982CallBrInst::CallBrInst(const CallBrInst &CBI, AllocInfo AllocInfo)
983 : CallBase(CBI.Attrs, CBI.FTy, CBI.getType(), Instruction::CallBr,
984 AllocInfo) {
986 "Wrong number of operands allocated");
988 std::copy(CBI.op_begin(), CBI.op_end(), op_begin());
989 std::copy(CBI.bundle_op_info_begin(), CBI.bundle_op_info_end(),
992 NumIndirectDests = CBI.NumIndirectDests;
993}
994
995CallBrInst *CallBrInst::Create(CallBrInst *CBI, ArrayRef<OperandBundleDef> OpB,
996 InsertPosition InsertPt) {
997 std::vector<Value *> Args(CBI->arg_begin(), CBI->arg_end());
998
999 auto *NewCBI = CallBrInst::Create(
1000 CBI->getFunctionType(), CBI->getCalledOperand(), CBI->getDefaultDest(),
1001 CBI->getIndirectDests(), Args, OpB, CBI->getName(), InsertPt);
1002 NewCBI->setCallingConv(CBI->getCallingConv());
1003 NewCBI->SubclassOptionalData = CBI->SubclassOptionalData;
1004 NewCBI->setAttributes(CBI->getAttributes());
1005 NewCBI->setDebugLoc(CBI->getDebugLoc());
1006 NewCBI->NumIndirectDests = CBI->NumIndirectDests;
1007 return NewCBI;
1008}
1009
1010//===----------------------------------------------------------------------===//
1011// ReturnInst Implementation
1012//===----------------------------------------------------------------------===//
1013
1014ReturnInst::ReturnInst(const ReturnInst &RI, AllocInfo AllocInfo)
1015 : Instruction(Type::getVoidTy(RI.getContext()), Instruction::Ret,
1016 AllocInfo) {
1018 "Wrong number of operands allocated");
1019 if (RI.getNumOperands())
1020 Op<0>() = RI.Op<0>();
1022}
1023
1024ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, AllocInfo AllocInfo,
1025 InsertPosition InsertBefore)
1026 : Instruction(Type::getVoidTy(C), Instruction::Ret, AllocInfo,
1027 InsertBefore) {
1028 if (retVal)
1029 Op<0>() = retVal;
1030}
1031
1032//===----------------------------------------------------------------------===//
1033// ResumeInst Implementation
1034//===----------------------------------------------------------------------===//
1035
1036ResumeInst::ResumeInst(const ResumeInst &RI)
1037 : Instruction(Type::getVoidTy(RI.getContext()), Instruction::Resume,
1038 AllocMarker) {
1039 Op<0>() = RI.Op<0>();
1040}
1041
1042ResumeInst::ResumeInst(Value *Exn, InsertPosition InsertBefore)
1043 : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
1044 AllocMarker, InsertBefore) {
1045 Op<0>() = Exn;
1046}
1047
1048//===----------------------------------------------------------------------===//
1049// CleanupReturnInst Implementation
1050//===----------------------------------------------------------------------===//
1051
1052CleanupReturnInst::CleanupReturnInst(const CleanupReturnInst &CRI,
1054 : Instruction(CRI.getType(), Instruction::CleanupRet, AllocInfo) {
1056 "Wrong number of operands allocated");
1057 setSubclassData<Instruction::OpaqueField>(
1059 Op<0>() = CRI.Op<0>();
1060 if (CRI.hasUnwindDest())
1061 Op<1>() = CRI.Op<1>();
1062}
1063
1064void CleanupReturnInst::init(Value *CleanupPad, BasicBlock *UnwindBB) {
1065 if (UnwindBB)
1066 setSubclassData<UnwindDestField>(true);
1067
1068 Op<0>() = CleanupPad;
1069 if (UnwindBB)
1070 Op<1>() = UnwindBB;
1071}
1072
1073CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
1075 InsertPosition InsertBefore)
1076 : Instruction(Type::getVoidTy(CleanupPad->getContext()),
1077 Instruction::CleanupRet, AllocInfo, InsertBefore) {
1078 init(CleanupPad, UnwindBB);
1079}
1080
1081//===----------------------------------------------------------------------===//
1082// CatchReturnInst Implementation
1083//===----------------------------------------------------------------------===//
1084void CatchReturnInst::init(Value *CatchPad, BasicBlock *BB) {
1085 Op<0>() = CatchPad;
1086 Op<1>() = BB;
1087}
1088
1089CatchReturnInst::CatchReturnInst(const CatchReturnInst &CRI)
1090 : Instruction(Type::getVoidTy(CRI.getContext()), Instruction::CatchRet,
1091 AllocMarker) {
1092 Op<0>() = CRI.Op<0>();
1093 Op<1>() = CRI.Op<1>();
1094}
1095
1096CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
1097 InsertPosition InsertBefore)
1098 : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
1099 AllocMarker, InsertBefore) {
1100 init(CatchPad, BB);
1101}
1102
1103//===----------------------------------------------------------------------===//
1104// CatchSwitchInst Implementation
1105//===----------------------------------------------------------------------===//
1106
1107CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
1108 unsigned NumReservedValues,
1109 const Twine &NameStr,
1110 InsertPosition InsertBefore)
1111 : Instruction(ParentPad->getType(), Instruction::CatchSwitch, AllocMarker,
1112 InsertBefore) {
1113 if (UnwindDest)
1114 ++NumReservedValues;
1115 init(ParentPad, UnwindDest, NumReservedValues + 1);
1116 setName(NameStr);
1117}
1118
1119CatchSwitchInst::CatchSwitchInst(const CatchSwitchInst &CSI)
1120 : Instruction(CSI.getType(), Instruction::CatchSwitch, AllocMarker) {
1122 init(CSI.getParentPad(), CSI.getUnwindDest(), CSI.getNumOperands());
1123 setNumHungOffUseOperands(ReservedSpace);
1124 Use *OL = getOperandList();
1125 const Use *InOL = CSI.getOperandList();
1126 for (unsigned I = 1, E = ReservedSpace; I != E; ++I)
1127 OL[I] = InOL[I];
1128}
1129
1130void CatchSwitchInst::init(Value *ParentPad, BasicBlock *UnwindDest,
1131 unsigned NumReservedValues) {
1132 assert(ParentPad && NumReservedValues);
1133
1134 ReservedSpace = NumReservedValues;
1135 allocHungoffUses(ReservedSpace);
1136 setNumHungOffUseOperands(UnwindDest ? 2 : 1);
1137
1138 Op<0>() = ParentPad;
1139 if (UnwindDest) {
1141 setUnwindDest(UnwindDest);
1142 }
1143}
1144
1145/// growOperands - grow operands - This grows the operand list in response to a
1146/// push_back style of operation. This grows the number of ops by 2 times.
1147void CatchSwitchInst::growOperands(unsigned Size) {
1148 unsigned NumOperands = getNumOperands();
1149 assert(NumOperands >= 1);
1150 if (ReservedSpace >= NumOperands + Size)
1151 return;
1152 ReservedSpace = (NumOperands + Size / 2) * 2;
1153 growHungoffUses(ReservedSpace);
1154}
1155
1157 unsigned OpNo = getNumOperands();
1158 growOperands(1);
1159 assert(OpNo < ReservedSpace && "Growing didn't work!");
1161 getOperandList()[OpNo] = Handler;
1162}
1163
1165 // Move all subsequent handlers up one.
1166 Use *EndDst = op_end() - 1;
1167 for (Use *CurDst = HI.getCurrent(); CurDst != EndDst; ++CurDst)
1168 *CurDst = *(CurDst + 1);
1169 // Null out the last handler use.
1170 *EndDst = nullptr;
1171
1173}
1174
1175//===----------------------------------------------------------------------===//
1176// FuncletPadInst Implementation
1177//===----------------------------------------------------------------------===//
1178void FuncletPadInst::init(Value *ParentPad, ArrayRef<Value *> Args,
1179 const Twine &NameStr) {
1180 assert(getNumOperands() == 1 + Args.size() && "NumOperands not set up?");
1181 llvm::copy(Args, op_begin());
1182 setParentPad(ParentPad);
1183 setName(NameStr);
1184}
1185
1186FuncletPadInst::FuncletPadInst(const FuncletPadInst &FPI, AllocInfo AllocInfo)
1187 : Instruction(FPI.getType(), FPI.getOpcode(), AllocInfo) {
1189 "Wrong number of operands allocated");
1190 std::copy(FPI.op_begin(), FPI.op_end(), op_begin());
1192}
1193
1194FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1196 const Twine &NameStr,
1197 InsertPosition InsertBefore)
1198 : Instruction(ParentPad->getType(), Op, AllocInfo, InsertBefore) {
1199 init(ParentPad, Args, NameStr);
1200}
1201
1202//===----------------------------------------------------------------------===//
1203// UnreachableInst Implementation
1204//===----------------------------------------------------------------------===//
1205
1207 InsertPosition InsertBefore)
1208 : Instruction(Type::getVoidTy(Context), Instruction::Unreachable,
1209 AllocMarker, InsertBefore) {}
1210
1211//===----------------------------------------------------------------------===//
1212// UncondBrInst Implementation
1213//===----------------------------------------------------------------------===//
1214
1215UncondBrInst::UncondBrInst(BasicBlock *Target, InsertPosition InsertBefore)
1216 : Instruction(Type::getVoidTy(Target->getContext()), Instruction::UncondBr,
1217 AllocMarker, InsertBefore) {
1218 Op<-1>() = Target;
1219}
1220
1221UncondBrInst::UncondBrInst(const UncondBrInst &BI)
1222 : Instruction(Type::getVoidTy(BI.getContext()), Instruction::UncondBr,
1223 AllocMarker) {
1224 Op<-1>() = BI.Op<-1>();
1226}
1227
1228//===----------------------------------------------------------------------===//
1229// CondBrInst Implementation
1230//===----------------------------------------------------------------------===//
1231
1232void CondBrInst::AssertOK() {
1233 assert(getCondition()->getType()->isIntegerTy(1) &&
1234 "May only branch on boolean predicates!");
1235}
1236
1237CondBrInst::CondBrInst(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse,
1238 InsertPosition InsertBefore)
1239 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::CondBr,
1240 AllocMarker, InsertBefore) {
1241 // Assign in order of operand index to make use-list order predictable.
1242 Op<-3>() = Cond;
1243 Op<-2>() = IfTrue;
1244 Op<-1>() = IfFalse;
1245#ifndef NDEBUG
1246 AssertOK();
1247#endif
1248}
1249
1250CondBrInst::CondBrInst(const CondBrInst &BI)
1251 : Instruction(Type::getVoidTy(BI.getContext()), Instruction::CondBr,
1252 AllocMarker) {
1253 // Assign in order of operand index to make use-list order predictable.
1254 Op<-3>() = BI.Op<-3>();
1255 Op<-2>() = BI.Op<-2>();
1256 Op<-1>() = BI.Op<-1>();
1258}
1259
1261 Op<-1>().swap(Op<-2>());
1262
1263 // Update profile metadata if present and it matches our structural
1264 // expectations.
1266}
1267
1268//===----------------------------------------------------------------------===//
1269// AllocaInst Implementation
1270//===----------------------------------------------------------------------===//
1271
1272static Value *getAISize(LLVMContext &Context, Value *Amt) {
1273 if (!Amt)
1274 Amt = ConstantInt::get(Type::getInt32Ty(Context), 1);
1275 else {
1276 assert(!isa<BasicBlock>(Amt) &&
1277 "Passed basic block into allocation size parameter! Use other ctor");
1278 assert(Amt->getType()->isIntegerTy() &&
1279 "Allocation array size is not an integer!");
1280 }
1281 return Amt;
1282}
1283
1285 assert(Pos.isValid() &&
1286 "Insertion position cannot be null when alignment not provided!");
1287 BasicBlock *BB = Pos.getBasicBlock();
1288 assert(BB->getParent() &&
1289 "BB must be in a Function when alignment not provided!");
1290 const DataLayout &DL = BB->getDataLayout();
1291 return DL.getPrefTypeAlign(Ty);
1292}
1293
1294AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
1295 InsertPosition InsertBefore)
1296 : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
1297
1298AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1299 const Twine &Name, InsertPosition InsertBefore)
1300 : AllocaInst(Ty, AddrSpace, ArraySize,
1301 computeAllocaDefaultAlign(Ty, InsertBefore), Name,
1302 InsertBefore) {}
1303
1304AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1305 Align Align, const Twine &Name,
1306 InsertPosition InsertBefore)
1307 : UnaryInstruction(PointerType::get(Ty->getContext(), AddrSpace), Alloca,
1308 getAISize(Ty->getContext(), ArraySize), InsertBefore),
1309 AllocatedType(Ty) {
1311 assert(!Ty->isVoidTy() && "Cannot allocate void!");
1312 setName(Name);
1313}
1314
1317 return !CI->isOne();
1318 return true;
1319}
1320
1321/// isStaticAlloca - Return true if this alloca is in the entry block of the
1322/// function and is a constant size. If so, the code generator will fold it
1323/// into the prolog/epilog code, so it is basically free.
1325 // Must be constant size.
1326 if (!isa<ConstantInt>(getArraySize())) return false;
1327
1328 // Must be in the entry block.
1329 const BasicBlock *Parent = getParent();
1330 return Parent->isEntryBlock() && !isUsedWithInAlloca();
1331}
1332
1333//===----------------------------------------------------------------------===//
1334// LoadInst Implementation
1335//===----------------------------------------------------------------------===//
1336
1337void LoadInst::AssertOK() {
1339 "Ptr must have pointer type.");
1340}
1341
1343 assert(Pos.isValid() &&
1344 "Insertion position cannot be null when alignment not provided!");
1345 BasicBlock *BB = Pos.getBasicBlock();
1346 assert(BB->getParent() &&
1347 "BB must be in a Function when alignment not provided!");
1348 const DataLayout &DL = BB->getDataLayout();
1349 return DL.getABITypeAlign(Ty);
1350}
1351
1352LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
1353 InsertPosition InsertBef)
1354 : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertBef) {}
1355
1356LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1357 InsertPosition InsertBef)
1358 : LoadInst(Ty, Ptr, Name, isVolatile,
1359 computeLoadStoreDefaultAlign(Ty, InsertBef), InsertBef) {}
1360
1361LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1362 Align Align, InsertPosition InsertBef)
1363 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
1364 SyncScope::System, InsertBef) {}
1365
1366LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
1367 const LoadStoreInstProperties &Props,
1368 InsertPosition InsertBef)
1369 : LoadInst(Ty, Ptr, Name, Props.IsVolatile, Props.Alignment, Props.Ordering,
1370 Props.SSID, InsertBef) {
1372}
1373
1374LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1376 InsertPosition InsertBef)
1377 : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
1380 setAtomic(Order, SSID);
1381 AssertOK();
1382 setName(Name);
1383}
1384
1385//===----------------------------------------------------------------------===//
1386// StoreInst Implementation
1387//===----------------------------------------------------------------------===//
1388
1389void StoreInst::AssertOK() {
1390 assert(getOperand(0) && getOperand(1) && "Both operands must be non-null!");
1392 "Ptr must have pointer type!");
1393}
1394
1396 : StoreInst(val, addr, /*isVolatile=*/false, InsertBefore) {}
1397
1399 InsertPosition InsertBefore)
1400 : StoreInst(val, addr, isVolatile,
1401 computeLoadStoreDefaultAlign(val->getType(), InsertBefore),
1402 InsertBefore) {}
1403
1405 InsertPosition InsertBefore)
1407 SyncScope::System, InsertBefore) {}
1408
1410 const LoadStoreInstProperties &Props,
1411 InsertPosition InsertBefore)
1412 : StoreInst(Val, Ptr, Props.IsVolatile, Props.Alignment, Props.Ordering,
1413 Props.SSID, InsertBefore) {
1415}
1416
1418 AtomicOrdering Order, SyncScope::ID SSID,
1419 InsertPosition InsertBefore)
1420 : Instruction(Type::getVoidTy(val->getContext()), Store, AllocMarker,
1421 InsertBefore) {
1422 Op<0>() = val;
1423 Op<1>() = addr;
1426 setAtomic(Order, SSID);
1427 AssertOK();
1428}
1429
1430//===----------------------------------------------------------------------===//
1431// AtomicCmpXchgInst Implementation
1432//===----------------------------------------------------------------------===//
1433
1434void AtomicCmpXchgInst::Init(Value *Ptr, Value *Cmp, Value *NewVal,
1435 Align Alignment, AtomicOrdering SuccessOrdering,
1436 AtomicOrdering FailureOrdering,
1437 SyncScope::ID SSID) {
1438 Op<0>() = Ptr;
1439 Op<1>() = Cmp;
1440 Op<2>() = NewVal;
1441 setSuccessOrdering(SuccessOrdering);
1442 setFailureOrdering(FailureOrdering);
1443 setSyncScopeID(SSID);
1444 setAlignment(Alignment);
1445
1446 assert(getOperand(0) && getOperand(1) && getOperand(2) &&
1447 "All operands must be non-null!");
1449 "Ptr must have pointer type!");
1450 assert(getOperand(1)->getType() == getOperand(2)->getType() &&
1451 "Cmp type and NewVal type must be same!");
1452}
1453
1455 Align Alignment,
1456 AtomicOrdering SuccessOrdering,
1457 AtomicOrdering FailureOrdering,
1458 SyncScope::ID SSID,
1459 InsertPosition InsertBefore)
1460 : Instruction(
1461 StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
1462 AtomicCmpXchg, AllocMarker, InsertBefore) {
1463 Init(Ptr, Cmp, NewVal, Alignment, SuccessOrdering, FailureOrdering, SSID);
1464}
1465
1466//===----------------------------------------------------------------------===//
1467// AtomicRMWInst Implementation
1468//===----------------------------------------------------------------------===//
1469
1470void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
1471 Align Alignment, AtomicOrdering Ordering,
1472 SyncScope::ID SSID, bool Elementwise) {
1473 assert(Ordering != AtomicOrdering::NotAtomic &&
1474 "atomicrmw instructions can only be atomic.");
1475 assert(Ordering != AtomicOrdering::Unordered &&
1476 "atomicrmw instructions cannot be unordered.");
1477 Op<0>() = Ptr;
1478 Op<1>() = Val;
1479 setOperation(Operation);
1480 setOrdering(Ordering);
1481 setSyncScopeID(SSID);
1482 setElementwise(Elementwise);
1483 setAlignment(Alignment);
1484
1485 assert(getOperand(0) && getOperand(1) && "All operands must be non-null!");
1487 "Ptr must have pointer type!");
1488 assert(Ordering != AtomicOrdering::NotAtomic &&
1489 "AtomicRMW instructions must be atomic!");
1490}
1491
1493 Align Alignment, AtomicOrdering Ordering,
1494 SyncScope::ID SSID, bool Elementwise,
1495 InsertPosition InsertBefore)
1496 : Instruction(Val->getType(), AtomicRMW, AllocMarker, InsertBefore) {
1497 Init(Operation, Ptr, Val, Alignment, Ordering, SSID, Elementwise);
1498}
1499
1501 switch (Op) {
1503 return "xchg";
1504 case AtomicRMWInst::Add:
1505 return "add";
1506 case AtomicRMWInst::Sub:
1507 return "sub";
1508 case AtomicRMWInst::And:
1509 return "and";
1511 return "nand";
1512 case AtomicRMWInst::Or:
1513 return "or";
1514 case AtomicRMWInst::Xor:
1515 return "xor";
1516 case AtomicRMWInst::Max:
1517 return "max";
1518 case AtomicRMWInst::Min:
1519 return "min";
1521 return "umax";
1523 return "umin";
1525 return "fadd";
1527 return "fsub";
1529 return "fmax";
1531 return "fmin";
1533 return "fmaximum";
1535 return "fminimum";
1537 return "fmaximumnum";
1539 return "fminimumnum";
1541 return "uinc_wrap";
1543 return "udec_wrap";
1545 return "usub_cond";
1547 return "usub_sat";
1549 return "<invalid operation>";
1550 }
1551
1552 llvm_unreachable("invalid atomicrmw operation");
1553}
1554
1555//===----------------------------------------------------------------------===//
1556// FenceInst Implementation
1557//===----------------------------------------------------------------------===//
1558
1560 SyncScope::ID SSID, InsertPosition InsertBefore)
1561 : Instruction(Type::getVoidTy(C), Fence, AllocMarker, InsertBefore) {
1562 setOrdering(Ordering);
1563 setSyncScopeID(SSID);
1564}
1565
1566//===----------------------------------------------------------------------===//
1567// GetElementPtrInst Implementation
1568//===----------------------------------------------------------------------===//
1569
1570void GetElementPtrInst::init(Value *Ptr, ArrayRef<Value *> IdxList,
1571 const Twine &Name) {
1572 assert(getNumOperands() == 1 + IdxList.size() &&
1573 "NumOperands not initialized?");
1574 Op<0>() = Ptr;
1575 llvm::copy(IdxList, op_begin() + 1);
1576 setName(Name);
1577}
1578
1579GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI,
1581 : Instruction(GEPI.getType(), GetElementPtr, AllocInfo),
1582 SourceElementType(GEPI.SourceElementType),
1583 ResultElementType(GEPI.ResultElementType) {
1584 assert(getNumOperands() == GEPI.getNumOperands() &&
1585 "Wrong number of operands allocated");
1586 std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
1588}
1589
1591 if (auto *Struct = dyn_cast<StructType>(Ty)) {
1592 if (!Struct->indexValid(Idx))
1593 return nullptr;
1594 return Struct->getTypeAtIndex(Idx);
1595 }
1596 if (!Idx->getType()->isIntOrIntVectorTy())
1597 return nullptr;
1598 if (auto *Array = dyn_cast<ArrayType>(Ty))
1599 return Array->getElementType();
1600 if (auto *Vector = dyn_cast<VectorType>(Ty))
1601 return Vector->getElementType();
1602 return nullptr;
1603}
1604
1606 if (auto *Struct = dyn_cast<StructType>(Ty)) {
1607 if (Idx >= Struct->getNumElements())
1608 return nullptr;
1609 return Struct->getElementType(Idx);
1610 }
1611 if (auto *Array = dyn_cast<ArrayType>(Ty))
1612 return Array->getElementType();
1613 if (auto *Vector = dyn_cast<VectorType>(Ty))
1614 return Vector->getElementType();
1615 return nullptr;
1616}
1617
1618template <typename IndexTy>
1620 if (IdxList.empty())
1621 return Ty;
1622 for (IndexTy V : IdxList.slice(1)) {
1624 if (!Ty)
1625 return Ty;
1626 }
1627 return Ty;
1628}
1629
1633
1635 ArrayRef<Constant *> IdxList) {
1636 return getIndexedTypeInternal(Ty, IdxList);
1637}
1638
1642
1643/// hasAllZeroIndices - Return true if all of the indices of this GEP are
1644/// zeros. If so, the result pointer and the first operand have the same
1645/// value, just potentially different types.
1647 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
1649 if (!CI->isZero()) return false;
1650 } else {
1651 return false;
1652 }
1653 }
1654 return true;
1655}
1656
1657/// hasAllConstantIndices - Return true if all of the indices of this GEP are
1658/// constant integers. If so, the result pointer and the first operand have
1659/// a constant offset between them.
1661 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
1663 return false;
1664 }
1665 return true;
1666}
1667
1671
1673 GEPNoWrapFlags NW = cast<GEPOperator>(this)->getNoWrapFlags();
1674 if (B)
1676 else
1677 NW = NW.withoutInBounds();
1678 setNoWrapFlags(NW);
1679}
1680
1682 return cast<GEPOperator>(this)->getNoWrapFlags();
1683}
1684
1686 return cast<GEPOperator>(this)->isInBounds();
1687}
1688
1690 return cast<GEPOperator>(this)->hasNoUnsignedSignedWrap();
1691}
1692
1694 return cast<GEPOperator>(this)->hasNoUnsignedWrap();
1695}
1696
1698 APInt &Offset) const {
1699 // Delegate to the generic GEPOperator implementation.
1700 return cast<GEPOperator>(this)->accumulateConstantOffset(DL, Offset);
1701}
1702
1704 const DataLayout &DL, unsigned BitWidth,
1705 SmallMapVector<Value *, APInt, 4> &VariableOffsets,
1706 APInt &ConstantOffset) const {
1707 // Delegate to the generic GEPOperator implementation.
1708 return cast<GEPOperator>(this)->collectOffset(DL, BitWidth, VariableOffsets,
1709 ConstantOffset);
1710}
1711
1712//===----------------------------------------------------------------------===//
1713// ExtractElementInst Implementation
1714//===----------------------------------------------------------------------===//
1715
1716ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
1717 const Twine &Name,
1718 InsertPosition InsertBef)
1719 : Instruction(cast<VectorType>(Val->getType())->getElementType(),
1720 ExtractElement, AllocMarker, InsertBef) {
1721 assert(isValidOperands(Val, Index) &&
1722 "Invalid extractelement instruction operands!");
1723 Op<0>() = Val;
1724 Op<1>() = Index;
1725 setName(Name);
1726}
1727
1728bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
1729 if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy())
1730 return false;
1731 return true;
1732}
1733
1734//===----------------------------------------------------------------------===//
1735// InsertElementInst Implementation
1736//===----------------------------------------------------------------------===//
1737
1738InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
1739 const Twine &Name,
1740 InsertPosition InsertBef)
1741 : Instruction(Vec->getType(), InsertElement, AllocMarker, InsertBef) {
1742 assert(isValidOperands(Vec, Elt, Index) &&
1743 "Invalid insertelement instruction operands!");
1744 Op<0>() = Vec;
1745 Op<1>() = Elt;
1746 Op<2>() = Index;
1747 setName(Name);
1748}
1749
1751 const Value *Index) {
1752 if (!Vec->getType()->isVectorTy())
1753 return false; // First operand of insertelement must be vector type.
1754
1755 if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
1756 return false;// Second operand of insertelement must be vector element type.
1757
1758 if (!Index->getType()->isIntegerTy())
1759 return false; // Third operand of insertelement must be an integer.
1760 return true;
1761}
1762
1763//===----------------------------------------------------------------------===//
1764// ShuffleVectorInst Implementation
1765//===----------------------------------------------------------------------===//
1766
1768 assert(V && "Cannot create placeholder of nullptr V");
1769 return PoisonValue::get(V->getType());
1770}
1771
1773 InsertPosition InsertBefore)
1775 InsertBefore) {}
1776
1778 const Twine &Name,
1779 InsertPosition InsertBefore)
1781 InsertBefore) {}
1782
1784 const Twine &Name,
1785 InsertPosition InsertBefore)
1786 : Instruction(
1787 VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1788 cast<VectorType>(Mask->getType())->getElementCount()),
1789 ShuffleVector, AllocMarker, InsertBefore) {
1790 assert(isValidOperands(V1, V2, Mask) &&
1791 "Invalid shuffle vector instruction operands!");
1792
1793 Op<0>() = V1;
1794 Op<1>() = V2;
1795 SmallVector<int, 16> MaskArr;
1796 getShuffleMask(cast<Constant>(Mask), MaskArr);
1797 setShuffleMask(MaskArr);
1798 setName(Name);
1799}
1800
1802 const Twine &Name,
1803 InsertPosition InsertBefore)
1804 : Instruction(
1805 VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1806 Mask.size(), isa<ScalableVectorType>(V1->getType())),
1807 ShuffleVector, AllocMarker, InsertBefore) {
1808 assert(isValidOperands(V1, V2, Mask) &&
1809 "Invalid shuffle vector instruction operands!");
1810 Op<0>() = V1;
1811 Op<1>() = V2;
1812 setShuffleMask(Mask);
1813 setName(Name);
1814}
1815
1817 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
1818 int NumMaskElts = ShuffleMask.size();
1819 SmallVector<int, 16> NewMask(NumMaskElts);
1820 for (int i = 0; i != NumMaskElts; ++i) {
1821 int MaskElt = getMaskValue(i);
1822 if (MaskElt == PoisonMaskElem) {
1823 NewMask[i] = PoisonMaskElem;
1824 continue;
1825 }
1826 assert(MaskElt >= 0 && MaskElt < 2 * NumOpElts && "Out-of-range mask");
1827 MaskElt = (MaskElt < NumOpElts) ? MaskElt + NumOpElts : MaskElt - NumOpElts;
1828 NewMask[i] = MaskElt;
1829 }
1830 setShuffleMask(NewMask);
1831 Op<0>().swap(Op<1>());
1832}
1833
1835 ArrayRef<int> Mask) {
1836 // V1 and V2 must be vectors of the same type.
1837 if (!isa<VectorType>(V1->getType()) || V1->getType() != V2->getType())
1838 return false;
1839
1840 if (isa<ScalableVectorType>(V1->getType()))
1841 return (Mask[0] == 0 || Mask[0] == PoisonMaskElem) && all_equal(Mask);
1842
1843 // Make sure the mask elements make sense.
1844 int64_t MaxMaskSz =
1845 cast<FixedVectorType>(V1->getType())->getNumElements() * 2LL;
1846 for (int Elem : Mask)
1847 if (Elem != PoisonMaskElem && Elem >= MaxMaskSz)
1848 return false;
1849 return true;
1850}
1851
1853 const Value *Mask) {
1854 // V1 and V2 must be vectors of the same type.
1855 if (!V1->getType()->isVectorTy() || V1->getType() != V2->getType())
1856 return false;
1857
1858 // Mask must be vector of i32, and must be the same kind of vector as the
1859 // input vectors
1860 auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
1861 if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32) ||
1862 isa<ScalableVectorType>(MaskTy) != isa<ScalableVectorType>(V1->getType()))
1863 return false;
1864
1865 // Check to see if Mask is valid.
1867 return true;
1868
1869 // NOTE: Through vector ConstantInt we have the potential to support more
1870 // than just zero splat masks but that requires a LangRef change.
1871 if (isa<ScalableVectorType>(MaskTy))
1872 return false;
1873
1874 unsigned V1Size = cast<FixedVectorType>(V1->getType())->getNumElements();
1875
1876 if (const auto *CI = dyn_cast<ConstantInt>(Mask))
1877 return !CI->uge(V1Size * 2);
1878
1879 if (const auto *MV = dyn_cast<ConstantVector>(Mask)) {
1880 for (Value *Op : MV->operands()) {
1881 if (auto *CI = dyn_cast<ConstantInt>(Op)) {
1882 if (CI->uge(V1Size*2))
1883 return false;
1884 } else if (!isa<UndefValue>(Op)) {
1885 return false;
1886 }
1887 }
1888 return true;
1889 }
1890
1891 if (const auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1892 for (unsigned i = 0, e = cast<FixedVectorType>(MaskTy)->getNumElements();
1893 i != e; ++i)
1894 if (CDS->getElementAsInteger(i) >= V1Size*2)
1895 return false;
1896 return true;
1897 }
1898
1899 return false;
1900}
1901
1903 SmallVectorImpl<int> &Result) {
1904 ElementCount EC = cast<VectorType>(Mask->getType())->getElementCount();
1905
1906 if (isa<ConstantAggregateZero>(Mask) || isa<UndefValue>(Mask)) {
1907 int MaskVal = isa<UndefValue>(Mask) ? -1 : 0;
1908 Result.append(EC.getKnownMinValue(), MaskVal);
1909 return;
1910 }
1911
1912 assert(!EC.isScalable() &&
1913 "Scalable vector shuffle mask must be undef or zeroinitializer");
1914
1915 unsigned NumElts = EC.getFixedValue();
1916
1917 Result.reserve(NumElts);
1918
1919 if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1920 for (unsigned i = 0; i != NumElts; ++i)
1921 Result.push_back(CDS->getElementAsInteger(i));
1922 return;
1923 }
1924 for (unsigned i = 0; i != NumElts; ++i) {
1925 Constant *C = Mask->getAggregateElement(i);
1926 Result.push_back(isa<UndefValue>(C) ? -1 :
1927 cast<ConstantInt>(C)->getZExtValue());
1928 }
1929}
1930
1932 ShuffleMask.assign(Mask.begin(), Mask.end());
1933 ShuffleMaskForBitcode = convertShuffleMaskForBitcode(Mask, getType());
1934}
1935
1937 Type *ResultTy) {
1938 Type *Int32Ty = Type::getInt32Ty(ResultTy->getContext());
1939 if (isa<ScalableVectorType>(ResultTy)) {
1940 assert(all_equal(Mask) && "Unexpected shuffle");
1941 Type *VecTy = VectorType::get(Int32Ty, Mask.size(), true);
1942 if (Mask[0] == 0)
1943 return Constant::getNullValue(VecTy);
1944 return PoisonValue::get(VecTy);
1945 }
1947 for (int Elem : Mask) {
1948 if (Elem == PoisonMaskElem)
1949 MaskConst.push_back(PoisonValue::get(Int32Ty));
1950 else
1951 MaskConst.push_back(ConstantInt::get(Int32Ty, Elem));
1952 }
1953 return ConstantVector::get(MaskConst);
1954}
1955
1956static bool isSingleSourceMaskImpl(ArrayRef<int> Mask, int64_t NumOpElts) {
1957 assert(!Mask.empty() && "Shuffle mask must contain elements");
1958 bool UsesLHS = false;
1959 bool UsesRHS = false;
1960 for (int I : Mask) {
1961 if (I == -1)
1962 continue;
1963 assert(I >= 0 && I < (NumOpElts * 2) &&
1964 "Out-of-bounds shuffle mask element");
1965 UsesLHS |= (I < NumOpElts);
1966 UsesRHS |= (I >= NumOpElts);
1967 if (UsesLHS && UsesRHS)
1968 return false;
1969 }
1970 // Allow for degenerate case: completely undef mask means neither source is used.
1971 return UsesLHS || UsesRHS;
1972}
1973
1975 // We don't have vector operand size information, so assume operands are the
1976 // same size as the mask.
1977 return isSingleSourceMaskImpl(Mask, NumSrcElts);
1978}
1979
1980static bool isIdentityMaskImpl(ArrayRef<int> Mask, int NumOpElts) {
1981 if (!isSingleSourceMaskImpl(Mask, NumOpElts))
1982 return false;
1983 for (int i = 0, NumMaskElts = Mask.size(); i < NumMaskElts; ++i) {
1984 if (Mask[i] == -1)
1985 continue;
1986 if (Mask[i] != i && Mask[i] != (NumOpElts + i))
1987 return false;
1988 }
1989 return true;
1990}
1991
1993 if (Mask.size() != static_cast<unsigned>(NumSrcElts))
1994 return false;
1995 // We don't have vector operand size information, so assume operands are the
1996 // same size as the mask.
1997 return isIdentityMaskImpl(Mask, NumSrcElts);
1998}
1999
2001 if (Mask.size() != static_cast<unsigned>(NumSrcElts))
2002 return false;
2003 if (!isSingleSourceMask(Mask, NumSrcElts))
2004 return false;
2005
2006 // The number of elements in the mask must be at least 2.
2007 if (NumSrcElts < 2)
2008 return false;
2009
2010 for (int I = 0, E = Mask.size(); I < E; ++I) {
2011 if (Mask[I] == -1)
2012 continue;
2013 if (Mask[I] != (NumSrcElts - 1 - I) &&
2014 Mask[I] != (NumSrcElts + NumSrcElts - 1 - I))
2015 return false;
2016 }
2017 return true;
2018}
2019
2021 if (Mask.size() != static_cast<unsigned>(NumSrcElts))
2022 return false;
2023 if (!isSingleSourceMask(Mask, NumSrcElts))
2024 return false;
2025 for (int I = 0, E = Mask.size(); I < E; ++I) {
2026 if (Mask[I] == -1)
2027 continue;
2028 if (Mask[I] != 0 && Mask[I] != NumSrcElts)
2029 return false;
2030 }
2031 return true;
2032}
2033
2035 if (Mask.size() != static_cast<unsigned>(NumSrcElts))
2036 return false;
2037 // Select is differentiated from identity. It requires using both sources.
2038 if (isSingleSourceMask(Mask, NumSrcElts))
2039 return false;
2040 for (int I = 0, E = Mask.size(); I < E; ++I) {
2041 if (Mask[I] == -1)
2042 continue;
2043 if (Mask[I] != I && Mask[I] != (NumSrcElts + I))
2044 return false;
2045 }
2046 return true;
2047}
2048
2050 // Example masks that will return true:
2051 // v1 = <a, b, c, d>
2052 // v2 = <e, f, g, h>
2053 // trn1 = shufflevector v1, v2 <0, 4, 2, 6> = <a, e, c, g>
2054 // trn2 = shufflevector v1, v2 <1, 5, 3, 7> = <b, f, d, h>
2055
2056 if (Mask.size() != static_cast<unsigned>(NumSrcElts))
2057 return false;
2058 // 1. The number of elements in the mask must be a power-of-2 and at least 2.
2059 int Sz = Mask.size();
2060 if (Sz < 2 || !isPowerOf2_32(Sz))
2061 return false;
2062
2063 // 2. The first element of the mask must be either a 0 or a 1.
2064 if (Mask[0] != 0 && Mask[0] != 1)
2065 return false;
2066
2067 // 3. The difference between the first 2 elements must be equal to the
2068 // number of elements in the mask.
2069 if ((Mask[1] - Mask[0]) != NumSrcElts)
2070 return false;
2071
2072 // 4. The difference between consecutive even-numbered and odd-numbered
2073 // elements must be equal to 2.
2074 for (int I = 2; I < Sz; ++I) {
2075 int MaskEltVal = Mask[I];
2076 if (MaskEltVal == -1)
2077 return false;
2078 int MaskEltPrevVal = Mask[I - 2];
2079 if (MaskEltVal - MaskEltPrevVal != 2)
2080 return false;
2081 }
2082 return true;
2083}
2084
2086 int &Index) {
2087 if (Mask.size() != static_cast<unsigned>(NumSrcElts))
2088 return false;
2089 // Example: shufflevector <4 x n> A, <4 x n> B, <1,2,3,4>
2090 int StartIndex = -1;
2091 for (int I = 0, E = Mask.size(); I != E; ++I) {
2092 int MaskEltVal = Mask[I];
2093 if (MaskEltVal == -1)
2094 continue;
2095
2096 if (StartIndex == -1) {
2097 // Don't support a StartIndex that begins in the second input, or if the
2098 // first non-undef index would access below the StartIndex.
2099 if (MaskEltVal < I || NumSrcElts <= (MaskEltVal - I))
2100 return false;
2101
2102 StartIndex = MaskEltVal - I;
2103 continue;
2104 }
2105
2106 // Splice is sequential starting from StartIndex.
2107 if (MaskEltVal != (StartIndex + I))
2108 return false;
2109 }
2110
2111 if (StartIndex == -1)
2112 return false;
2113
2114 // NOTE: This accepts StartIndex == 0 (COPY).
2115 Index = StartIndex;
2116 return true;
2117}
2118
2120 int NumSrcElts, int &Index) {
2121 // Must extract from a single source.
2122 if (!isSingleSourceMaskImpl(Mask, NumSrcElts))
2123 return false;
2124
2125 // Must be smaller (else this is an Identity shuffle).
2126 if (NumSrcElts <= (int)Mask.size())
2127 return false;
2128
2129 // Find start of extraction, accounting that we may start with an UNDEF.
2130 int SubIndex = -1;
2131 for (int i = 0, e = Mask.size(); i != e; ++i) {
2132 int M = Mask[i];
2133 if (M < 0)
2134 continue;
2135 int Offset = (M % NumSrcElts) - i;
2136 if (0 <= SubIndex && SubIndex != Offset)
2137 return false;
2138 SubIndex = Offset;
2139 }
2140
2141 if (0 <= SubIndex && SubIndex + (int)Mask.size() <= NumSrcElts) {
2142 Index = SubIndex;
2143 return true;
2144 }
2145 return false;
2146}
2147
2149 int NumSrcElts, int &NumSubElts,
2150 int &Index) {
2151 int NumMaskElts = Mask.size();
2152
2153 // Don't try to match if we're shuffling to a smaller size.
2154 if (NumMaskElts < NumSrcElts)
2155 return false;
2156
2157 // TODO: We don't recognize self-insertion/widening.
2158 if (isSingleSourceMaskImpl(Mask, NumSrcElts))
2159 return false;
2160
2161 // Determine which mask elements are attributed to which source.
2162 APInt UndefElts = APInt::getZero(NumMaskElts);
2163 APInt Src0Elts = APInt::getZero(NumMaskElts);
2164 APInt Src1Elts = APInt::getZero(NumMaskElts);
2165 bool Src0Identity = true;
2166 bool Src1Identity = true;
2167
2168 for (int i = 0; i != NumMaskElts; ++i) {
2169 int M = Mask[i];
2170 if (M < 0) {
2171 UndefElts.setBit(i);
2172 continue;
2173 }
2174 if (M < NumSrcElts) {
2175 Src0Elts.setBit(i);
2176 Src0Identity &= (M == i);
2177 continue;
2178 }
2179 Src1Elts.setBit(i);
2180 Src1Identity &= (M == (i + NumSrcElts));
2181 }
2182 assert((Src0Elts | Src1Elts | UndefElts).isAllOnes() &&
2183 "unknown shuffle elements");
2184 assert(!Src0Elts.isZero() && !Src1Elts.isZero() &&
2185 "2-source shuffle not found");
2186
2187 // Determine lo/hi span ranges.
2188 // TODO: How should we handle undefs at the start of subvector insertions?
2189 int Src0Lo = Src0Elts.countr_zero();
2190 int Src1Lo = Src1Elts.countr_zero();
2191 int Src0Hi = NumMaskElts - Src0Elts.countl_zero();
2192 int Src1Hi = NumMaskElts - Src1Elts.countl_zero();
2193
2194 // If src0 is in place, see if the src1 elements is inplace within its own
2195 // span.
2196 if (Src0Identity) {
2197 int NumSub1Elts = Src1Hi - Src1Lo;
2198 ArrayRef<int> Sub1Mask = Mask.slice(Src1Lo, NumSub1Elts);
2199 if (isIdentityMaskImpl(Sub1Mask, NumSrcElts)) {
2200 NumSubElts = NumSub1Elts;
2201 Index = Src1Lo;
2202 return true;
2203 }
2204 }
2205
2206 // If src1 is in place, see if the src0 elements is inplace within its own
2207 // span.
2208 if (Src1Identity) {
2209 int NumSub0Elts = Src0Hi - Src0Lo;
2210 ArrayRef<int> Sub0Mask = Mask.slice(Src0Lo, NumSub0Elts);
2211 if (isIdentityMaskImpl(Sub0Mask, NumSrcElts)) {
2212 NumSubElts = NumSub0Elts;
2213 Index = Src0Lo;
2214 return true;
2215 }
2216 }
2217
2218 return false;
2219}
2220
2222 // FIXME: Not currently possible to express a shuffle mask for a scalable
2223 // vector for this case.
2225 return false;
2226
2227 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2228 int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
2229 if (NumMaskElts <= NumOpElts)
2230 return false;
2231
2232 // The first part of the mask must choose elements from exactly 1 source op.
2234 if (!isIdentityMaskImpl(Mask, NumOpElts))
2235 return false;
2236
2237 // All extending must be with undef elements.
2238 for (int i = NumOpElts; i < NumMaskElts; ++i)
2239 if (Mask[i] != -1)
2240 return false;
2241
2242 return true;
2243}
2244
2246 // FIXME: Not currently possible to express a shuffle mask for a scalable
2247 // vector for this case.
2249 return false;
2250
2251 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2252 int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
2253 if (NumMaskElts >= NumOpElts)
2254 return false;
2255
2256 return isIdentityMaskImpl(getShuffleMask(), NumOpElts);
2257}
2258
2260 // Vector concatenation is differentiated from identity with padding.
2262 return false;
2263
2264 // FIXME: Not currently possible to express a shuffle mask for a scalable
2265 // vector for this case.
2267 return false;
2268
2269 int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2270 int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
2271 if (NumMaskElts != NumOpElts * 2)
2272 return false;
2273
2274 // Use the mask length rather than the operands' vector lengths here. We
2275 // already know that the shuffle returns a vector twice as long as the inputs,
2276 // and neither of the inputs are undef vectors. If the mask picks consecutive
2277 // elements from both inputs, then this is a concatenation of the inputs.
2278 return isIdentityMaskImpl(getShuffleMask(), NumMaskElts);
2279}
2280
2282 int ReplicationFactor, int VF) {
2283 assert(Mask.size() == (unsigned)ReplicationFactor * VF &&
2284 "Unexpected mask size.");
2285
2286 for (int CurrElt : seq(VF)) {
2287 ArrayRef<int> CurrSubMask = Mask.take_front(ReplicationFactor);
2288 assert(CurrSubMask.size() == (unsigned)ReplicationFactor &&
2289 "Run out of mask?");
2290 Mask = Mask.drop_front(ReplicationFactor);
2291 if (!all_of(CurrSubMask, [CurrElt](int MaskElt) {
2292 return MaskElt == PoisonMaskElem || MaskElt == CurrElt;
2293 }))
2294 return false;
2295 }
2296 assert(Mask.empty() && "Did not consume the whole mask?");
2297
2298 return true;
2299}
2300
2302 int &ReplicationFactor, int &VF) {
2303 // undef-less case is trivial.
2304 if (!llvm::is_contained(Mask, PoisonMaskElem)) {
2305 ReplicationFactor =
2306 Mask.take_while([](int MaskElt) { return MaskElt == 0; }).size();
2307 if (ReplicationFactor == 0 || Mask.size() % ReplicationFactor != 0)
2308 return false;
2309 VF = Mask.size() / ReplicationFactor;
2310 return isReplicationMaskWithParams(Mask, ReplicationFactor, VF);
2311 }
2312
2313 // However, if the mask contains undef's, we have to enumerate possible tuples
2314 // and pick one. There are bounds on replication factor: [1, mask size]
2315 // (where RF=1 is an identity shuffle, RF=mask size is a broadcast shuffle)
2316 // Additionally, mask size is a replication factor multiplied by vector size,
2317 // which further significantly reduces the search space.
2318
2319 // Before doing that, let's perform basic correctness checking first.
2320 int Largest = -1;
2321 for (int MaskElt : Mask) {
2322 if (MaskElt == PoisonMaskElem)
2323 continue;
2324 // Elements must be in non-decreasing order.
2325 if (MaskElt < Largest)
2326 return false;
2327 Largest = std::max(Largest, MaskElt);
2328 }
2329
2330 // Prefer larger replication factor if all else equal.
2331 for (int PossibleReplicationFactor :
2332 reverse(seq_inclusive<unsigned>(1, Mask.size()))) {
2333 if (Mask.size() % PossibleReplicationFactor != 0)
2334 continue;
2335 int PossibleVF = Mask.size() / PossibleReplicationFactor;
2336 if (!isReplicationMaskWithParams(Mask, PossibleReplicationFactor,
2337 PossibleVF))
2338 continue;
2339 ReplicationFactor = PossibleReplicationFactor;
2340 VF = PossibleVF;
2341 return true;
2342 }
2343
2344 return false;
2345}
2346
2347bool ShuffleVectorInst::isReplicationMask(int &ReplicationFactor,
2348 int &VF) const {
2349 // Not possible to express a shuffle mask for a scalable vector for this
2350 // case.
2352 return false;
2353
2354 VF = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
2355 if (ShuffleMask.size() % VF != 0)
2356 return false;
2357 ReplicationFactor = ShuffleMask.size() / VF;
2358
2359 return isReplicationMaskWithParams(ShuffleMask, ReplicationFactor, VF);
2360}
2361
2363 if (VF <= 0 || Mask.size() < static_cast<unsigned>(VF) ||
2364 Mask.size() % VF != 0)
2365 return false;
2366 for (unsigned K = 0, Sz = Mask.size(); K < Sz; K += VF) {
2367 ArrayRef<int> SubMask = Mask.slice(K, VF);
2368 if (all_of(SubMask, equal_to(PoisonMaskElem)))
2369 continue;
2370 SmallBitVector Used(VF, false);
2371 for (int Idx : SubMask) {
2372 if (Idx != PoisonMaskElem && Idx < VF)
2373 Used.set(Idx);
2374 }
2375 if (!Used.all())
2376 return false;
2377 }
2378 return true;
2379}
2380
2381/// Return true if this shuffle mask is a replication mask.
2383 // Not possible to express a shuffle mask for a scalable vector for this
2384 // case.
2386 return false;
2387 if (!isSingleSourceMask(ShuffleMask, VF))
2388 return false;
2389
2390 return isOneUseSingleSourceMask(ShuffleMask, VF);
2391}
2392
2393bool ShuffleVectorInst::isInterleave(unsigned Factor) {
2395 // shuffle_vector can only interleave fixed length vectors - for scalable
2396 // vectors, see the @llvm.vector.interleave2 intrinsic
2397 if (!OpTy)
2398 return false;
2399 unsigned OpNumElts = OpTy->getNumElements();
2400
2401 return isInterleaveMask(ShuffleMask, Factor, OpNumElts * 2);
2402}
2403
2405 ArrayRef<int> Mask, unsigned Factor, unsigned NumInputElts,
2406 SmallVectorImpl<unsigned> &StartIndexes) {
2407 unsigned NumElts = Mask.size();
2408 if (NumElts % Factor)
2409 return false;
2410
2411 unsigned LaneLen = NumElts / Factor;
2412 if (!isPowerOf2_32(LaneLen))
2413 return false;
2414
2415 StartIndexes.resize(Factor);
2416
2417 // Check whether each element matches the general interleaved rule.
2418 // Ignore undef elements, as long as the defined elements match the rule.
2419 // Outer loop processes all factors (x, y, z in the above example)
2420 unsigned I = 0, J;
2421 for (; I < Factor; I++) {
2422 unsigned SavedLaneValue;
2423 unsigned SavedNoUndefs = 0;
2424
2425 // Inner loop processes consecutive accesses (x, x+1... in the example)
2426 for (J = 0; J < LaneLen - 1; J++) {
2427 // Lane computes x's position in the Mask
2428 unsigned Lane = J * Factor + I;
2429 unsigned NextLane = Lane + Factor;
2430 int LaneValue = Mask[Lane];
2431 int NextLaneValue = Mask[NextLane];
2432
2433 // If both are defined, values must be sequential
2434 if (LaneValue >= 0 && NextLaneValue >= 0 &&
2435 LaneValue + 1 != NextLaneValue)
2436 break;
2437
2438 // If the next value is undef, save the current one as reference
2439 if (LaneValue >= 0 && NextLaneValue < 0) {
2440 SavedLaneValue = LaneValue;
2441 SavedNoUndefs = 1;
2442 }
2443
2444 // Undefs are allowed, but defined elements must still be consecutive:
2445 // i.e.: x,..., undef,..., x + 2,..., undef,..., undef,..., x + 5, ....
2446 // Verify this by storing the last non-undef followed by an undef
2447 // Check that following non-undef masks are incremented with the
2448 // corresponding distance.
2449 if (SavedNoUndefs > 0 && LaneValue < 0) {
2450 SavedNoUndefs++;
2451 if (NextLaneValue >= 0 &&
2452 SavedLaneValue + SavedNoUndefs != (unsigned)NextLaneValue)
2453 break;
2454 }
2455 }
2456
2457 if (J < LaneLen - 1)
2458 return false;
2459
2460 int StartMask = 0;
2461 if (Mask[I] >= 0) {
2462 // Check that the start of the I range (J=0) is greater than 0
2463 StartMask = Mask[I];
2464 } else if (Mask[(LaneLen - 1) * Factor + I] >= 0) {
2465 // StartMask defined by the last value in lane
2466 StartMask = Mask[(LaneLen - 1) * Factor + I] - J;
2467 } else if (SavedNoUndefs > 0) {
2468 // StartMask defined by some non-zero value in the j loop
2469 StartMask = SavedLaneValue - (LaneLen - 1 - SavedNoUndefs);
2470 }
2471 // else StartMask remains set to 0, i.e. all elements are undefs
2472
2473 if (StartMask < 0)
2474 return false;
2475 // We must stay within the vectors; This case can happen with undefs.
2476 if (StartMask + LaneLen > NumInputElts)
2477 return false;
2478
2479 StartIndexes[I] = StartMask;
2480 }
2481
2482 return true;
2483}
2484
2485/// Check if the mask is a DE-interleave mask of the given factor
2486/// \p Factor like:
2487/// <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
2489 unsigned Factor,
2490 unsigned &Index) {
2491 // Check all potential start indices from 0 to (Factor - 1).
2492 for (unsigned Idx = 0; Idx < Factor; Idx++) {
2493 unsigned I = 0;
2494
2495 // Check that elements are in ascending order by Factor. Ignore undef
2496 // elements.
2497 for (; I < Mask.size(); I++)
2498 if (Mask[I] >= 0 && static_cast<unsigned>(Mask[I]) != Idx + I * Factor)
2499 break;
2500
2501 if (I == Mask.size()) {
2502 Index = Idx;
2503 return true;
2504 }
2505 }
2506
2507 return false;
2508}
2509
2510/// Try to lower a vector shuffle as a bit rotation.
2511///
2512/// Look for a repeated rotation pattern in each sub group.
2513/// Returns an element-wise left bit rotation amount or -1 if failed.
2514static int matchShuffleAsBitRotate(ArrayRef<int> Mask, int NumSubElts) {
2515 int NumElts = Mask.size();
2516 assert((NumElts % NumSubElts) == 0 && "Illegal shuffle mask");
2517
2518 int RotateAmt = -1;
2519 for (int i = 0; i != NumElts; i += NumSubElts) {
2520 for (int j = 0; j != NumSubElts; ++j) {
2521 int M = Mask[i + j];
2522 if (M < 0)
2523 continue;
2524 if (M < i || M >= i + NumSubElts)
2525 return -1;
2526 int Offset = (NumSubElts - (M - (i + j))) % NumSubElts;
2527 if (0 <= RotateAmt && Offset != RotateAmt)
2528 return -1;
2529 RotateAmt = Offset;
2530 }
2531 }
2532 return RotateAmt;
2533}
2534
2536 ArrayRef<int> Mask, unsigned EltSizeInBits, unsigned MinSubElts,
2537 unsigned MaxSubElts, unsigned &NumSubElts, unsigned &RotateAmt) {
2538 for (NumSubElts = MinSubElts; NumSubElts <= MaxSubElts; NumSubElts *= 2) {
2539 int EltRotateAmt = matchShuffleAsBitRotate(Mask, NumSubElts);
2540 if (EltRotateAmt < 0)
2541 continue;
2542 RotateAmt = EltRotateAmt * EltSizeInBits;
2543 return true;
2544 }
2545
2546 return false;
2547}
2548
2549//===----------------------------------------------------------------------===//
2550// InsertValueInst Class
2551//===----------------------------------------------------------------------===//
2552
2553void InsertValueInst::init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2554 const Twine &Name) {
2555 assert(getNumOperands() == 2 && "NumOperands not initialized?");
2556
2557 // There's no fundamental reason why we require at least one index
2558 // (other than weirdness with &*IdxBegin being invalid; see
2559 // getelementptr's init routine for example). But there's no
2560 // present need to support it.
2561 assert(!Idxs.empty() && "InsertValueInst must have at least one index");
2562
2564 Val->getType() && "Inserted value must match indexed type!");
2565 Op<0>() = Agg;
2566 Op<1>() = Val;
2567
2568 Indices.append(Idxs.begin(), Idxs.end());
2569 setName(Name);
2570}
2571
2572InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
2573 : Instruction(IVI.getType(), InsertValue, AllocMarker),
2574 Indices(IVI.Indices) {
2575 Op<0>() = IVI.getOperand(0);
2576 Op<1>() = IVI.getOperand(1);
2578}
2579
2580//===----------------------------------------------------------------------===//
2581// ExtractValueInst Class
2582//===----------------------------------------------------------------------===//
2583
2584void ExtractValueInst::init(ArrayRef<unsigned> Idxs, const Twine &Name) {
2585 assert(getNumOperands() == 1 && "NumOperands not initialized?");
2586
2587 // There's no fundamental reason why we require at least one index.
2588 // But there's no present need to support it.
2589 assert(!Idxs.empty() && "ExtractValueInst must have at least one index");
2590
2591 Indices.append(Idxs.begin(), Idxs.end());
2592 setName(Name);
2593}
2594
2595ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
2596 : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0),
2597 (BasicBlock *)nullptr),
2598 Indices(EVI.Indices) {
2600}
2601
2602// getIndexedType - Returns the type of the element that would be extracted
2603// with an extractvalue instruction with the specified parameters.
2604//
2605// A null type is returned if the indices are invalid for the specified
2606// pointer type.
2607//
2609 ArrayRef<unsigned> Idxs) {
2610 for (unsigned Index : Idxs) {
2611 // We can't use CompositeType::indexValid(Index) here.
2612 // indexValid() always returns true for arrays because getelementptr allows
2613 // out-of-bounds indices. Since we don't allow those for extractvalue and
2614 // insertvalue we need to check array indexing manually.
2615 // Since the only other types we can index into are struct types it's just
2616 // as easy to check those manually as well.
2617 if (ArrayType *AT = dyn_cast<ArrayType>(Agg)) {
2618 if (Index >= AT->getNumElements())
2619 return nullptr;
2620 Agg = AT->getElementType();
2621 } else if (StructType *ST = dyn_cast<StructType>(Agg)) {
2622 if (Index >= ST->getNumElements())
2623 return nullptr;
2624 Agg = ST->getElementType(Index);
2625 } else {
2626 // Not a valid type to index into.
2627 return nullptr;
2628 }
2629 }
2630 return Agg;
2631}
2632
2633//===----------------------------------------------------------------------===//
2634// BitInsert Class
2635//===----------------------------------------------------------------------===//
2636BitInsertInst::BitInsertInst(Value *Base, Value *Val, Value *Offset,
2637 const Twine &Name, InsertPosition InsertBef)
2638 : Instruction(Base->getType(), BitInsert, AllocMarker, InsertBef) {
2639 assert(!areInvalidOperands(Base, Val, Offset) &&
2640 "Invalid bitinsert instruction operands!");
2641 Op<0>() = Base;
2642 Op<1>() = Val;
2643 Op<2>() = Offset;
2644 setName(Name);
2645}
2646
2648 Value *Offset) {
2649 if (!Base->getType()->isByteTy())
2650 return "bitinsert base must be a byte type";
2651 if (!(Val->getType()->isFloatingPointTy() || Val->getType()->isIntegerTy() ||
2652 Val->getType()->isPointerTy() || Val->getType()->isByteTy()))
2653 return "bitinsert value must be an integer, floating-point, pointer, or "
2654 "byte type";
2655 if (!Offset->getType()->isIntegerTy(32))
2656 return "bitinsert offset must be i32";
2657 return nullptr;
2658}
2659
2660//===----------------------------------------------------------------------===//
2661// BitExtract Class
2662//===----------------------------------------------------------------------===//
2663BitExtractInst::BitExtractInst(Type *Ty, Value *Src, Value *Offset,
2664 const Twine &Name, InsertPosition InsertBef)
2665 : Instruction(Ty, BitExtract, AllocMarker, InsertBef) {
2666 assert(!areInvalidOperands(Ty, Src, Offset) &&
2667 "Invalid bitextract instruction operands!");
2668 Op<0>() = Src;
2669 Op<1>() = Offset;
2670 setName(Name);
2671}
2672
2674 Value *Offset) {
2675 if (!(Ty->isFloatingPointTy() || Ty->isIntegerTy() || Ty->isPointerTy() ||
2676 Ty->isByteTy()))
2677 return "bitextract result must be an integer, floating-point, pointer, or "
2678 "byte type";
2679 if (!Src->getType()->isByteTy())
2680 return "bitextract source must be a byte type";
2681 if (!Offset->getType()->isIntegerTy(32))
2682 return "bitextract offset must be i32";
2683 return nullptr;
2684}
2685
2686//===----------------------------------------------------------------------===//
2687// UnaryOperator Class
2688//===----------------------------------------------------------------------===//
2689
2691 const Twine &Name, InsertPosition InsertBefore)
2692 : UnaryInstruction(Ty, iType, S, InsertBefore) {
2693 Op<0>() = S;
2694 setName(Name);
2695 AssertOK();
2696}
2697
2699 InsertPosition InsertBefore) {
2700 switch (Op) {
2701 case UnaryOps::FNeg:
2702 return new FPUnaryOperator(Op, S, S->getType(), Name, InsertBefore);
2703 default:
2704 return new UnaryOperator(Op, S, S->getType(), Name, InsertBefore);
2705 }
2706}
2707
2708void UnaryOperator::AssertOK() {
2709 Value *LHS = getOperand(0);
2710 (void)LHS; // Silence warnings.
2711#ifndef NDEBUG
2712 switch (getOpcode()) {
2713 case FNeg:
2714 assert(getType() == LHS->getType() &&
2715 "Unary operation should return same type as operand!");
2716 assert(getType()->isFPOrFPVectorTy() &&
2717 "Tried to create a floating-point operation on a "
2718 "non-floating-point type!");
2719 break;
2720 default: llvm_unreachable("Invalid opcode provided");
2721 }
2722#endif
2723}
2724
2725//===----------------------------------------------------------------------===//
2726// BinaryOperator Class
2727//===----------------------------------------------------------------------===//
2728
2730 const Twine &Name, InsertPosition InsertBefore)
2731 : Instruction(Ty, iType, AllocMarker, InsertBefore) {
2732 Op<0>() = S1;
2733 Op<1>() = S2;
2734 setName(Name);
2735 AssertOK();
2736}
2737
2738void BinaryOperator::AssertOK() {
2739 Value *LHS = getOperand(0), *RHS = getOperand(1);
2740 (void)LHS; (void)RHS; // Silence warnings.
2741 assert(LHS->getType() == RHS->getType() &&
2742 "Binary operator operand types must match!");
2743#ifndef NDEBUG
2744 switch (getOpcode()) {
2745 case Add: case Sub:
2746 case Mul:
2747 assert(getType() == LHS->getType() &&
2748 "Arithmetic operation should return same type as operands!");
2749 assert(getType()->isIntOrIntVectorTy() &&
2750 "Tried to create an integer operation on a non-integer type!");
2751 break;
2752 case FAdd: case FSub:
2753 case FMul:
2754 assert(getType() == LHS->getType() &&
2755 "Arithmetic operation should return same type as operands!");
2756 assert(getType()->isFPOrFPVectorTy() &&
2757 "Tried to create a floating-point operation on a "
2758 "non-floating-point type!");
2759 break;
2760 case UDiv:
2761 case SDiv:
2762 assert(getType() == LHS->getType() &&
2763 "Arithmetic operation should return same type as operands!");
2764 assert(getType()->isIntOrIntVectorTy() &&
2765 "Incorrect operand type (not integer) for S/UDIV");
2766 break;
2767 case FDiv:
2768 assert(getType() == LHS->getType() &&
2769 "Arithmetic operation should return same type as operands!");
2770 assert(getType()->isFPOrFPVectorTy() &&
2771 "Incorrect operand type (not floating point) for FDIV");
2772 break;
2773 case URem:
2774 case SRem:
2775 assert(getType() == LHS->getType() &&
2776 "Arithmetic operation should return same type as operands!");
2777 assert(getType()->isIntOrIntVectorTy() &&
2778 "Incorrect operand type (not integer) for S/UREM");
2779 break;
2780 case FRem:
2781 assert(getType() == LHS->getType() &&
2782 "Arithmetic operation should return same type as operands!");
2783 assert(getType()->isFPOrFPVectorTy() &&
2784 "Incorrect operand type (not floating point) for FREM");
2785 break;
2786 case Shl:
2787 case LShr:
2788 case AShr:
2789 assert(getType() == LHS->getType() &&
2790 "Shift operation should return same type as operands!");
2791 assert(getType()->isIntOrIntVectorTy() &&
2792 "Tried to create a shift operation on a non-integral type!");
2793 break;
2794 case And: case Or:
2795 case Xor:
2796 assert(getType() == LHS->getType() &&
2797 "Logical operation should return same type as operands!");
2798 assert(getType()->isIntOrIntVectorTy() &&
2799 "Tried to create a logical operation on a non-integral type!");
2800 break;
2801 default: llvm_unreachable("Invalid opcode provided");
2802 }
2803#endif
2804}
2805
2807 const Twine &Name,
2808 InsertPosition InsertBefore) {
2809 assert(S1->getType() == S2->getType() &&
2810 "Cannot create binary operator with two operands of differing type!");
2811 switch (Op) {
2812 case BinaryOps::FAdd:
2813 case BinaryOps::FSub:
2814 case BinaryOps::FMul:
2815 case BinaryOps::FDiv:
2816 case BinaryOps::FRem:
2817 return new FPBinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
2818 default:
2819 return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
2820 }
2821}
2822
2824 InsertPosition InsertBefore) {
2825 Value *Zero = ConstantInt::get(Op->getType(), 0);
2826 return new BinaryOperator(Instruction::Sub, Zero, Op, Op->getType(), Name,
2827 InsertBefore);
2828}
2829
2831 InsertPosition InsertBefore) {
2832 Value *Zero = ConstantInt::get(Op->getType(), 0);
2833 return BinaryOperator::CreateNSWSub(Zero, Op, Name, InsertBefore);
2834}
2835
2837 InsertPosition InsertBefore) {
2838 Constant *C = Constant::getAllOnesValue(Op->getType());
2839 return new BinaryOperator(Instruction::Xor, Op, C,
2840 Op->getType(), Name, InsertBefore);
2841}
2842
2843// Exchange the two operands to this instruction. This instruction is safe to
2844// use on any binary instruction and does not modify the semantics of the
2845// instruction.
2847 if (!isCommutative())
2848 return true; // Can't commute operands
2849 Op<0>().swap(Op<1>());
2850 return false;
2851}
2852
2853//===----------------------------------------------------------------------===//
2854// FPMathOperator Class
2855//===----------------------------------------------------------------------===//
2856
2858 const MDNode *MD =
2859 cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
2860 if (!MD)
2861 return 0.0;
2863 return Accuracy->getValueAPF().convertToFloat();
2864}
2865
2866//===----------------------------------------------------------------------===//
2867// CastInst Class
2868//===----------------------------------------------------------------------===//
2869
2870// Just determine if this cast only deals with integral->integral conversion.
2872 switch (getOpcode()) {
2873 default: return false;
2874 case Instruction::ZExt:
2875 case Instruction::SExt:
2876 case Instruction::Trunc:
2877 return true;
2878 case Instruction::BitCast:
2879 return getOperand(0)->getType()->isIntegerTy() &&
2880 getType()->isIntegerTy();
2881 }
2882}
2883
2884/// This function determines if the CastInst does not require any bits to be
2885/// changed in order to effect the cast. Essentially, it identifies cases where
2886/// no code gen is necessary for the cast, hence the name no-op cast. For
2887/// example, the following are all no-op casts:
2888/// # bitcast i32* %x to i8*
2889/// # bitcast <2 x i32> %x to <4 x i16>
2890/// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only
2891/// Determine if the described cast is a no-op.
2893 Type *SrcTy,
2894 Type *DestTy,
2895 const DataLayout &DL) {
2896 assert(castIsValid(Opcode, SrcTy, DestTy) && "method precondition");
2897 switch (Opcode) {
2898 default: llvm_unreachable("Invalid CastOp");
2899 case Instruction::Trunc:
2900 case Instruction::ZExt:
2901 case Instruction::SExt:
2902 case Instruction::FPTrunc:
2903 case Instruction::FPExt:
2904 case Instruction::UIToFP:
2905 case Instruction::SIToFP:
2906 case Instruction::FPToUI:
2907 case Instruction::FPToSI:
2908 case Instruction::AddrSpaceCast:
2909 // TODO: Target informations may give a more accurate answer here.
2910 return false;
2911 case Instruction::BitCast:
2912 return true; // BitCast never modifies bits.
2913 case Instruction::PtrToAddr:
2914 case Instruction::PtrToInt:
2915 return DL.getIntPtrType(SrcTy)->getScalarSizeInBits() ==
2916 DestTy->getScalarSizeInBits();
2917 case Instruction::IntToPtr:
2918 return DL.getIntPtrType(DestTy)->getScalarSizeInBits() ==
2919 SrcTy->getScalarSizeInBits();
2920 }
2921}
2922
2924 return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), DL);
2925}
2926
2927/// This function determines if a pair of casts can be eliminated and what
2928/// opcode should be used in the elimination. This assumes that there are two
2929/// instructions like this:
2930/// * %F = firstOpcode SrcTy %x to MidTy
2931/// * %S = secondOpcode MidTy %F to DstTy
2932/// The function returns a resultOpcode so these two casts can be replaced with:
2933/// * %Replacement = resultOpcode %SrcTy %x to DstTy
2934/// If no such cast is permitted, the function returns 0.
2936 Instruction::CastOps secondOp,
2937 Type *SrcTy, Type *MidTy, Type *DstTy,
2938 const DataLayout *DL) {
2939 // Define the 144 possibilities for these two cast instructions. The values
2940 // in this matrix determine what to do in a given situation and select the
2941 // case in the switch below. The rows correspond to firstOp, the columns
2942 // correspond to secondOp. In looking at the table below, keep in mind
2943 // the following cast properties:
2944 //
2945 // Size Compare Source Destination
2946 // Operator Src ? Size Type Sign Type Sign
2947 // -------- ------------ ------------------- ---------------------
2948 // TRUNC > Integer Any Integral Any
2949 // ZEXT < Integral Unsigned Integer Any
2950 // SEXT < Integral Signed Integer Any
2951 // FPTOUI n/a FloatPt n/a Integral Unsigned
2952 // FPTOSI n/a FloatPt n/a Integral Signed
2953 // UITOFP n/a Integral Unsigned FloatPt n/a
2954 // SITOFP n/a Integral Signed FloatPt n/a
2955 // FPTRUNC > FloatPt n/a FloatPt n/a
2956 // FPEXT < FloatPt n/a FloatPt n/a
2957 // PTRTOINT n/a Pointer n/a Integral Unsigned
2958 // PTRTOADDR n/a Pointer n/a Integral Unsigned
2959 // INTTOPTR n/a Integral Unsigned Pointer n/a
2960 // BITCAST = FirstClass n/a FirstClass n/a
2961 // ADDRSPCST n/a Pointer n/a Pointer n/a
2962 //
2963 // NOTE: some transforms are safe, but we consider them to be non-profitable.
2964 // For example, we could merge "fptoui double to i32" + "zext i32 to i64",
2965 // into "fptoui double to i64", but this loses information about the range
2966 // of the produced value (we no longer know the top-part is all zeros).
2967 // Further this conversion is often much more expensive for typical hardware,
2968 // and causes issues when building libgcc. We disallow fptosi+sext for the
2969 // same reason.
2970 const unsigned numCastOps =
2971 Instruction::CastOpsEnd - Instruction::CastOpsBegin;
2972 // clang-format off
2973 static const uint8_t CastResults[numCastOps][numCastOps] = {
2974 // T F F U S F F P P I B A -+
2975 // R Z S P P I I T P 2 2 N T S |
2976 // U E E 2 2 2 2 R E I A T C C +- secondOp
2977 // N X X U S F F N X N D 2 V V |
2978 // C T T I I P P C T T R P T T -+
2979 { 1, 0, 0,99,99, 0, 0,99,99,99,99, 0, 3, 0}, // Trunc -+
2980 { 8, 1, 9,99,99, 2,17,99,99,99,99, 2, 3, 0}, // ZExt |
2981 { 8, 0, 1,99,99, 0, 2,99,99,99,99, 0, 3, 0}, // SExt |
2982 { 0, 0, 0,99,99, 0, 0,99,99,99,99, 0, 3, 0}, // FPToUI |
2983 { 0, 0, 0,99,99, 0, 0,99,99,99,99, 0, 3, 0}, // FPToSI |
2984 { 99,99,99, 0, 0,99,99, 0, 0,99,99,99, 4, 0}, // UIToFP +- firstOp
2985 { 99,99,99, 0, 0,99,99, 0, 0,99,99,99, 4, 0}, // SIToFP |
2986 { 99,99,99, 0, 0,99,99, 0, 0,99,99,99, 4, 0}, // FPTrunc |
2987 { 99,99,99, 2, 2,99,99, 8, 2,99,99,99, 4, 0}, // FPExt |
2988 { 1, 0, 0,99,99, 0, 0,99,99,99,99, 7, 3, 0}, // PtrToInt |
2989 { 0, 0, 0,99,99, 0, 0,99,99,99,99, 0, 3, 0}, // PtrToAddr |
2990 { 99,99,99,99,99,99,99,99,99,11,11,99,15, 0}, // IntToPtr |
2991 { 5, 5, 5, 0, 0, 5, 5, 0, 0,16,16, 5, 1,14}, // BitCast |
2992 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12}, // AddrSpaceCast -+
2993 };
2994 // clang-format on
2995
2996 // TODO: This logic could be encoded into the table above and handled in the
2997 // switch below.
2998 // If either of the casts are a bitcast from scalar to vector, disallow the
2999 // merging. However, any pair of bitcasts are allowed.
3000 bool IsFirstBitcast = (firstOp == Instruction::BitCast);
3001 bool IsSecondBitcast = (secondOp == Instruction::BitCast);
3002 bool AreBothBitcasts = IsFirstBitcast && IsSecondBitcast;
3003
3004 // Check if any of the casts convert scalars <-> vectors.
3005 if ((IsFirstBitcast && isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
3006 (IsSecondBitcast && isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
3007 if (!AreBothBitcasts)
3008 return 0;
3009
3010 int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
3011 [secondOp-Instruction::CastOpsBegin];
3012 switch (ElimCase) {
3013 case 0:
3014 // Categorically disallowed.
3015 return 0;
3016 case 1:
3017 // Allowed, use first cast's opcode.
3018 return firstOp;
3019 case 2:
3020 // Allowed, use second cast's opcode.
3021 return secondOp;
3022 case 3:
3023 // No-op cast in second op implies firstOp as long as the DestTy
3024 // is integer and we are not converting between a vector and a
3025 // non-vector type.
3026 if (!SrcTy->isVectorTy() && DstTy->isIntegerTy())
3027 return firstOp;
3028 return 0;
3029 case 4:
3030 // No-op cast in second op implies firstOp as long as the DestTy
3031 // matches MidTy.
3032 if (DstTy == MidTy)
3033 return firstOp;
3034 return 0;
3035 case 5:
3036 // No-op cast in first op implies secondOp as long as the SrcTy
3037 // is an integer.
3038 if (SrcTy->isIntegerTy())
3039 return secondOp;
3040 return 0;
3041 case 7: {
3042 // Disable inttoptr/ptrtoint optimization if enabled.
3043 if (DisableI2pP2iOpt)
3044 return 0;
3045
3046 // Cannot simplify if address spaces are different!
3047 if (SrcTy != DstTy)
3048 return 0;
3049
3050 // Cannot simplify if the intermediate integer size is smaller than the
3051 // pointer size.
3052 unsigned MidSize = MidTy->getScalarSizeInBits();
3053 if (!DL || MidSize < DL->getPointerTypeSizeInBits(SrcTy))
3054 return 0;
3055
3056 return Instruction::BitCast;
3057 }
3058 case 8: {
3059 // ext, trunc -> bitcast, if the SrcTy and DstTy are the same
3060 // ext, trunc -> ext, if sizeof(SrcTy) < sizeof(DstTy)
3061 // ext, trunc -> trunc, if sizeof(SrcTy) > sizeof(DstTy)
3062 unsigned SrcSize = SrcTy->getScalarSizeInBits();
3063 unsigned DstSize = DstTy->getScalarSizeInBits();
3064 if (SrcTy == DstTy)
3065 return Instruction::BitCast;
3066 if (SrcSize < DstSize)
3067 return firstOp;
3068 if (SrcSize > DstSize)
3069 return secondOp;
3070 return 0;
3071 }
3072 case 9:
3073 // zext, sext -> zext, because sext can't sign extend after zext
3074 return Instruction::ZExt;
3075 case 11: {
3076 // inttoptr, ptrtoint/ptrtoaddr -> integer cast
3077 if (!DL)
3078 return 0;
3079 unsigned MidSize = secondOp == Instruction::PtrToAddr
3080 ? DL->getAddressSizeInBits(MidTy)
3081 : DL->getPointerTypeSizeInBits(MidTy);
3082 unsigned SrcSize = SrcTy->getScalarSizeInBits();
3083 unsigned DstSize = DstTy->getScalarSizeInBits();
3084 // If the middle size is smaller than both source and destination,
3085 // an additional masking operation would be required.
3086 if (MidSize < SrcSize && MidSize < DstSize)
3087 return 0;
3088 if (DstSize < SrcSize)
3089 return Instruction::Trunc;
3090 if (DstSize > SrcSize)
3091 return Instruction::ZExt;
3092 return Instruction::BitCast;
3093 }
3094 case 12:
3095 // addrspacecast, addrspacecast -> bitcast, if SrcAS == DstAS
3096 // addrspacecast, addrspacecast -> addrspacecast, if SrcAS != DstAS
3097 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
3098 return Instruction::AddrSpaceCast;
3099 return Instruction::BitCast;
3100 case 13:
3101 // FIXME: this state can be merged with (1), but the following assert
3102 // is useful to check the correcteness of the sequence due to semantic
3103 // change of bitcast.
3104 // addrspacecast can only fold through a bitcast if the result remains a
3105 // pointer. A pointer-to-byte bitcast must stay as a separate bitcast.
3106 if (!DstTy->isPtrOrPtrVectorTy())
3107 return 0;
3108 assert(
3109 SrcTy->isPtrOrPtrVectorTy() &&
3110 MidTy->isPtrOrPtrVectorTy() &&
3111 DstTy->isPtrOrPtrVectorTy() &&
3112 SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() &&
3113 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
3114 "Illegal addrspacecast, bitcast sequence!");
3115 // Allowed, use first cast's opcode
3116 return firstOp;
3117 case 14:
3118 // bitcast, addrspacecast -> addrspacecast
3119 // addrspacecast can only fold through a bitcast if the source was already
3120 // a pointer. A byte-to-pointer bitcast must stay as a separate bitcast.
3121 if (!SrcTy->isPtrOrPtrVectorTy())
3122 return 0;
3123 return Instruction::AddrSpaceCast;
3124 case 15:
3125 // FIXME: this state can be merged with (1), but the following assert
3126 // is useful to check the correcteness of the sequence due to semantic
3127 // change of bitcast.
3128 assert(
3129 SrcTy->isIntOrIntVectorTy() &&
3130 MidTy->isPtrOrPtrVectorTy() &&
3131 DstTy->isPtrOrPtrVectorTy() &&
3132 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
3133 "Illegal inttoptr, bitcast sequence!");
3134 // Allowed, use first cast's opcode
3135 return firstOp;
3136 case 16:
3137 // FIXME: this state can be merged with (2), but the following assert
3138 // is useful to check the correcteness of the sequence due to semantic
3139 // change of bitcast.
3140 assert(
3141 SrcTy->isPtrOrPtrVectorTy() &&
3142 MidTy->isPtrOrPtrVectorTy() &&
3143 DstTy->isIntOrIntVectorTy() &&
3144 SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&
3145 "Illegal bitcast, ptrtoint sequence!");
3146 // Allowed, use second cast's opcode
3147 return secondOp;
3148 case 17:
3149 // (sitofp (zext x)) -> (uitofp x)
3150 return Instruction::UIToFP;
3151 case 99:
3152 // Cast combination can't happen (error in input). This is for all cases
3153 // where the MidTy is not the same for the two cast instructions.
3154 llvm_unreachable("Invalid Cast Combination");
3155 default:
3156 llvm_unreachable("Error in CastResults table!!!");
3157 }
3158}
3159
3161 const Twine &Name, InsertPosition InsertBefore) {
3162 assert(castIsValid(op, S, Ty) && "Invalid cast!");
3163 // Construct and return the appropriate CastInst subclass
3164 switch (op) {
3165 case Trunc: return new TruncInst (S, Ty, Name, InsertBefore);
3166 case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore);
3167 case SExt: return new SExtInst (S, Ty, Name, InsertBefore);
3168 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore);
3169 case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore);
3170 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore);
3171 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore);
3172 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore);
3173 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
3174 case PtrToAddr: return new PtrToAddrInst (S, Ty, Name, InsertBefore);
3175 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
3176 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
3177 case BitCast:
3178 return new BitCastInst(S, Ty, Name, InsertBefore);
3179 case AddrSpaceCast:
3180 return new AddrSpaceCastInst(S, Ty, Name, InsertBefore);
3181 default:
3182 llvm_unreachable("Invalid opcode provided");
3183 }
3184}
3185
3187 InsertPosition InsertBefore) {
3188 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
3189 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
3190 return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
3191}
3192
3194 InsertPosition InsertBefore) {
3195 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
3196 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
3197 return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
3198}
3199
3201 InsertPosition InsertBefore) {
3202 if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
3203 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
3204 return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
3205}
3206
3207/// Create a BitCast or a PtrToInt cast instruction
3209 InsertPosition InsertBefore) {
3210 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
3211 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
3212 "Invalid cast");
3213 assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
3214 assert((!Ty->isVectorTy() ||
3215 cast<VectorType>(Ty)->getElementCount() ==
3216 cast<VectorType>(S->getType())->getElementCount()) &&
3217 "Invalid cast");
3218
3219 if (Ty->isIntOrIntVectorTy())
3220 return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
3221
3222 return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertBefore);
3223}
3224
3226 Value *S, Type *Ty, const Twine &Name, InsertPosition InsertBefore) {
3227 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
3228 assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
3229
3230 if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
3231 return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertBefore);
3232
3233 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
3234}
3235
3237 const Twine &Name,
3238 InsertPosition InsertBefore) {
3239 if (S->getType()->isPointerTy() && Ty->isIntegerTy())
3240 return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
3241 if (S->getType()->isIntegerTy() && Ty->isPointerTy())
3242 return Create(Instruction::IntToPtr, S, Ty, Name, InsertBefore);
3243
3244 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
3245}
3246
3248 const Twine &Name,
3249 InsertPosition InsertBefore) {
3250 assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
3251 "Invalid integer cast");
3252 unsigned SrcBits = C->getType()->getScalarSizeInBits();
3253 unsigned DstBits = Ty->getScalarSizeInBits();
3254 Instruction::CastOps opcode =
3255 (SrcBits == DstBits ? Instruction::BitCast :
3256 (SrcBits > DstBits ? Instruction::Trunc :
3257 (isSigned ? Instruction::SExt : Instruction::ZExt)));
3258 return Create(opcode, C, Ty, Name, InsertBefore);
3259}
3260
3262 InsertPosition InsertBefore) {
3263 assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
3264 "Invalid cast");
3265 unsigned SrcBits = C->getType()->getScalarSizeInBits();
3266 unsigned DstBits = Ty->getScalarSizeInBits();
3267 assert((C->getType() == Ty || SrcBits != DstBits) && "Invalid cast");
3268 Instruction::CastOps opcode =
3269 (SrcBits == DstBits ? Instruction::BitCast :
3270 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
3271 return Create(opcode, C, Ty, Name, InsertBefore);
3272}
3273
3274bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {
3275 if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
3276 return false;
3277
3278 if (SrcTy == DestTy)
3279 return true;
3280
3281 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
3282 if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) {
3283 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3284 // An element by element cast. Valid if casting the elements is valid.
3285 SrcTy = SrcVecTy->getElementType();
3286 DestTy = DestVecTy->getElementType();
3287 }
3288 }
3289 }
3290
3291 if (PointerType *DestPtrTy = dyn_cast<PointerType>(DestTy)) {
3292 if (PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy)) {
3293 return SrcPtrTy->getAddressSpace() == DestPtrTy->getAddressSpace();
3294 }
3295 }
3296
3297 TypeSize SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
3298 TypeSize DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
3299
3300 // Could still have vectors of pointers if the number of elements doesn't
3301 // match
3302 if (SrcBits.getKnownMinValue() == 0 || DestBits.getKnownMinValue() == 0)
3303 return false;
3304
3305 if (SrcBits != DestBits)
3306 return false;
3307
3308 return true;
3309}
3310
3312 const DataLayout &DL) {
3313 // ptrtoint and inttoptr are not allowed on non-integral pointers
3314 if (auto *PtrTy = dyn_cast<PointerType>(SrcTy))
3315 if (auto *IntTy = dyn_cast<IntegerType>(DestTy))
3316 return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
3317 !DL.isNonIntegralPointerType(PtrTy));
3318 if (auto *PtrTy = dyn_cast<PointerType>(DestTy))
3319 if (auto *IntTy = dyn_cast<IntegerType>(SrcTy))
3320 return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
3321 !DL.isNonIntegralPointerType(PtrTy));
3322
3323 return isBitCastable(SrcTy, DestTy);
3324}
3325
3326// Provide a way to get a "cast" where the cast opcode is inferred from the
3327// types and size of the operand. This, basically, is a parallel of the
3328// logic in the castIsValid function below. This axiom should hold:
3329// castIsValid( getCastOpcode(Val, Ty), Val, Ty)
3330// should not assert in castIsValid. In other words, this produces a "correct"
3331// casting opcode for the arguments passed to it.
3334 const Value *Src, bool SrcIsSigned, Type *DestTy, bool DestIsSigned) {
3335 Type *SrcTy = Src->getType();
3336
3337 assert(SrcTy->isFirstClassType() && DestTy->isFirstClassType() &&
3338 "Only first class types are castable!");
3339
3340 if (SrcTy == DestTy)
3341 return BitCast;
3342
3343 // FIXME: Check address space sizes here
3344 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
3345 if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
3346 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3347 // An element by element cast. Find the appropriate opcode based on the
3348 // element types.
3349 SrcTy = SrcVecTy->getElementType();
3350 DestTy = DestVecTy->getElementType();
3351 }
3352
3353 // Get the bit sizes, we'll need these
3354 // FIXME: This doesn't work for scalable vector types with different element
3355 // counts that don't call getElementType above.
3356 unsigned SrcBits =
3357 SrcTy->getPrimitiveSizeInBits().getFixedValue(); // 0 for ptr
3358 unsigned DestBits =
3359 DestTy->getPrimitiveSizeInBits().getFixedValue(); // 0 for ptr
3360
3361 // Run through the possibilities ...
3362 if (DestTy->isByteTy()) { // Casting to byte
3363 if (SrcTy->isIntegerTy()) { // Casting from integral
3364 assert(DestBits == SrcBits && "Illegal cast from integer to byte type");
3365 return BitCast;
3366 } else if (SrcTy->isPointerTy()) { // Casting from pointer
3367 assert(DestBits == SrcBits && "Illegal cast from pointer to byte type");
3368 return BitCast;
3369 }
3370 llvm_unreachable("Illegal cast to byte type");
3371 } else if (DestTy->isIntegerTy()) { // Casting to integral
3372 if (SrcTy->isIntegerTy()) { // Casting from integral
3373 if (DestBits < SrcBits)
3374 return Trunc; // int -> smaller int
3375 else if (DestBits > SrcBits) { // its an extension
3376 if (SrcIsSigned)
3377 return SExt; // signed -> SEXT
3378 else
3379 return ZExt; // unsigned -> ZEXT
3380 } else {
3381 return BitCast; // Same size, No-op cast
3382 }
3383 } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
3384 if (DestIsSigned)
3385 return FPToSI; // FP -> sint
3386 else
3387 return FPToUI; // FP -> uint
3388 } else if (SrcTy->isVectorTy()) {
3389 assert(DestBits == SrcBits &&
3390 "Casting vector to integer of different width");
3391 return BitCast; // Same size, no-op cast
3392 } else {
3393 assert(SrcTy->isPointerTy() &&
3394 "Casting from a value that is not first-class type");
3395 return PtrToInt; // ptr -> int
3396 }
3397 } else if (DestTy->isFloatingPointTy()) { // Casting to floating pt
3398 if (SrcTy->isIntegerTy()) { // Casting from integral
3399 if (SrcIsSigned)
3400 return SIToFP; // sint -> FP
3401 else
3402 return UIToFP; // uint -> FP
3403 } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
3404 if (DestBits < SrcBits) {
3405 return FPTrunc; // FP -> smaller FP
3406 } else if (DestBits > SrcBits) {
3407 return FPExt; // FP -> larger FP
3408 } else {
3409 return BitCast; // same size, no-op cast
3410 }
3411 } else if (SrcTy->isVectorTy()) {
3412 assert(DestBits == SrcBits &&
3413 "Casting vector to floating point of different width");
3414 return BitCast; // same size, no-op cast
3415 }
3416 llvm_unreachable("Casting pointer or non-first class to float");
3417 } else if (DestTy->isVectorTy()) {
3418 assert(DestBits == SrcBits &&
3419 "Illegal cast to vector (wrong type or size)");
3420 return BitCast;
3421 } else if (DestTy->isPointerTy()) {
3422 if (SrcTy->isPointerTy()) {
3423 if (DestTy->getPointerAddressSpace() != SrcTy->getPointerAddressSpace())
3424 return AddrSpaceCast;
3425 return BitCast; // ptr -> ptr
3426 } else if (SrcTy->isIntegerTy()) {
3427 return IntToPtr; // int -> ptr
3428 }
3429 llvm_unreachable("Casting pointer to other than pointer or int");
3430 }
3431 llvm_unreachable("Casting to type that is not first-class");
3432}
3433
3434//===----------------------------------------------------------------------===//
3435// CastInst SubClass Constructors
3436//===----------------------------------------------------------------------===//
3437
3438/// Check that the construction parameters for a CastInst are correct. This
3439/// could be broken out into the separate constructors but it is useful to have
3440/// it in one place and to eliminate the redundant code for getting the sizes
3441/// of the types involved.
3442bool
3444 if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType() ||
3445 SrcTy->isAggregateType() || DstTy->isAggregateType())
3446 return false;
3447
3448 // Get the size of the types in bits, and whether we are dealing
3449 // with vector types, we'll need this later.
3450 bool SrcIsVec = isa<VectorType>(SrcTy);
3451 bool DstIsVec = isa<VectorType>(DstTy);
3452 unsigned SrcScalarBitSize = SrcTy->getScalarSizeInBits();
3453 unsigned DstScalarBitSize = DstTy->getScalarSizeInBits();
3454
3455 // If these are vector types, get the lengths of the vectors (using zero for
3456 // scalar types means that checking that vector lengths match also checks that
3457 // scalars are not being converted to vectors or vectors to scalars).
3458 ElementCount SrcEC = SrcIsVec ? cast<VectorType>(SrcTy)->getElementCount()
3460 ElementCount DstEC = DstIsVec ? cast<VectorType>(DstTy)->getElementCount()
3462
3463 // Switch on the opcode provided
3464 switch (op) {
3465 default: return false; // This is an input error
3466 case Instruction::Trunc:
3467 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3468 SrcEC == DstEC && SrcScalarBitSize > DstScalarBitSize;
3469 case Instruction::ZExt:
3470 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3471 SrcEC == DstEC && SrcScalarBitSize < DstScalarBitSize;
3472 case Instruction::SExt:
3473 return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
3474 SrcEC == DstEC && SrcScalarBitSize < DstScalarBitSize;
3475 case Instruction::FPTrunc:
3476 return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
3477 SrcEC == DstEC && SrcScalarBitSize > DstScalarBitSize;
3478 case Instruction::FPExt:
3479 return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
3480 SrcEC == DstEC && SrcScalarBitSize < DstScalarBitSize;
3481 case Instruction::UIToFP:
3482 case Instruction::SIToFP:
3483 return SrcTy->isIntOrIntVectorTy() && DstTy->isFPOrFPVectorTy() &&
3484 SrcEC == DstEC;
3485 case Instruction::FPToUI:
3486 case Instruction::FPToSI:
3487 return SrcTy->isFPOrFPVectorTy() && DstTy->isIntOrIntVectorTy() &&
3488 SrcEC == DstEC;
3489 case Instruction::PtrToAddr:
3490 case Instruction::PtrToInt:
3491 if (SrcEC != DstEC)
3492 return false;
3493 return SrcTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy();
3494 case Instruction::IntToPtr:
3495 if (SrcEC != DstEC)
3496 return false;
3497 return SrcTy->isIntOrIntVectorTy() && DstTy->isPtrOrPtrVectorTy();
3498 case Instruction::BitCast: {
3499 Type *SrcScalarTy = SrcTy->getScalarType();
3500 if (SrcScalarTy->isTargetExtTy() || !SrcScalarTy->isSingleValueType())
3501 return false;
3502 Type *DstScalarTy = DstTy->getScalarType();
3503 if (DstScalarTy->isTargetExtTy() || !DstScalarTy->isSingleValueType())
3504 return false;
3505
3506 PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcScalarTy);
3507 PointerType *DstPtrTy = dyn_cast<PointerType>(DstScalarTy);
3508
3509 // BitCast implies a no-op cast of type only. No bits change.
3510 // However, you can't cast pointers to anything but pointers/bytes.
3511 if ((SrcPtrTy && DstTy->isByteOrByteVectorTy()) ||
3512 (SrcTy->isByteOrByteVectorTy() && DstPtrTy))
3513 return true;
3514 if (!SrcPtrTy != !DstPtrTy)
3515 return false;
3516
3517 // For non-pointer cases, the cast is okay if the source and destination bit
3518 // widths are identical.
3519 if (!SrcPtrTy)
3520 return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
3521
3522 // If both are pointers then the address spaces must match.
3523 if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
3524 return false;
3525
3526 // A vector of pointers must have the same number of elements.
3527 if (SrcIsVec && DstIsVec)
3528 return SrcEC == DstEC;
3529 if (SrcIsVec)
3530 return SrcEC == ElementCount::getFixed(1);
3531 if (DstIsVec)
3532 return DstEC == ElementCount::getFixed(1);
3533
3534 return true;
3535 }
3536 case Instruction::AddrSpaceCast: {
3537 PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
3538 if (!SrcPtrTy)
3539 return false;
3540
3541 PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
3542 if (!DstPtrTy)
3543 return false;
3544
3545 if (SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
3546 return false;
3547
3548 return SrcEC == DstEC;
3549 }
3550 }
3551}
3552
3554 InsertPosition InsertBefore)
3555 : CastInst(Ty, Trunc, S, Name, InsertBefore) {
3556 assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc");
3557}
3558
3559ZExtInst::ZExtInst(Value *S, Type *Ty, const Twine &Name,
3560 InsertPosition InsertBefore)
3561 : CastInst(Ty, ZExt, S, Name, InsertBefore) {
3562 assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt");
3563}
3564
3565SExtInst::SExtInst(Value *S, Type *Ty, const Twine &Name,
3566 InsertPosition InsertBefore)
3567 : CastInst(Ty, SExt, S, Name, InsertBefore) {
3568 assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt");
3569}
3570
3572 InsertPosition InsertBefore)
3573 : CastInst(Ty, FPTrunc, S, Name, InsertBefore) {
3574 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc");
3575}
3576
3578 InsertPosition InsertBefore)
3579 : CastInst(Ty, FPExt, S, Name, InsertBefore) {
3580 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt");
3581}
3582
3584 InsertPosition InsertBefore)
3585 : CastInst(Ty, UIToFP, S, Name, InsertBefore) {
3586 assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP");
3587}
3588
3590 InsertPosition InsertBefore)
3591 : CastInst(Ty, SIToFP, S, Name, InsertBefore) {
3592 assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP");
3593}
3594
3596 InsertPosition InsertBefore)
3597 : CastInst(Ty, FPToUI, S, Name, InsertBefore) {
3598 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI");
3599}
3600
3602 InsertPosition InsertBefore)
3603 : CastInst(Ty, FPToSI, S, Name, InsertBefore) {
3604 assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
3605}
3606
3608 InsertPosition InsertBefore)
3609 : CastInst(Ty, PtrToInt, S, Name, InsertBefore) {
3610 assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
3611}
3612
3614 InsertPosition InsertBefore)
3615 : CastInst(Ty, PtrToAddr, S, Name, InsertBefore) {
3616 assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToAddr");
3617}
3618
3620 InsertPosition InsertBefore)
3621 : CastInst(Ty, IntToPtr, S, Name, InsertBefore) {
3622 assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr");
3623}
3624
3626 InsertPosition InsertBefore)
3627 : CastInst(Ty, BitCast, S, Name, InsertBefore) {
3628 assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
3629}
3630
3632 InsertPosition InsertBefore)
3633 : CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
3634 assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
3635}
3636
3637//===----------------------------------------------------------------------===//
3638// CmpInst Classes
3639//===----------------------------------------------------------------------===//
3640
3642 Value *RHS, const Twine &Name, InsertPosition InsertBefore)
3643 : Instruction(ty, op, AllocMarker, InsertBefore) {
3644 Op<0>() = LHS;
3645 Op<1>() = RHS;
3646 setPredicate(predicate);
3647 setName(Name);
3648}
3649
3651 const Twine &Name, InsertPosition InsertBefore) {
3652 if (Op == Instruction::ICmp) {
3653 if (InsertBefore.isValid())
3654 return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
3655 S1, S2, Name);
3656 else
3657 return new ICmpInst(CmpInst::Predicate(predicate),
3658 S1, S2, Name);
3659 }
3660
3661 if (InsertBefore.isValid())
3662 return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
3663 S1, S2, Name);
3664 else
3665 return new FCmpInst(CmpInst::Predicate(predicate),
3666 S1, S2, Name);
3667}
3668
3670 Value *S2,
3671 const Instruction *FlagsSource,
3672 const Twine &Name,
3673 InsertPosition InsertBefore) {
3674 CmpInst *Inst = Create(Op, Pred, S1, S2, Name, InsertBefore);
3675 Inst->copyIRFlags(FlagsSource);
3676 return Inst;
3677}
3678
3680 if (ICmpInst *IC = dyn_cast<ICmpInst>(this))
3681 IC->swapOperands();
3682 else
3683 cast<FCmpInst>(this)->swapOperands();
3684}
3685
3687 if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
3688 return IC->isCommutative();
3689 return cast<FCmpInst>(this)->isCommutative();
3690}
3691
3694 return ICmpInst::isEquality(P);
3696 return FCmpInst::isEquality(P);
3697 llvm_unreachable("Unsupported predicate kind");
3698}
3699
3700// Returns true if either operand of CmpInst is a provably non-zero
3701// floating-point constant.
3702static bool hasNonZeroFPOperands(const CmpInst *Cmp) {
3703 auto *LHS = dyn_cast<Constant>(Cmp->getOperand(0));
3704 auto *RHS = dyn_cast<Constant>(Cmp->getOperand(1));
3705 if (auto *Const = LHS ? LHS : RHS) {
3706 using namespace llvm::PatternMatch;
3707 return match(Const, m_NonZeroNotDenormalFP());
3708 }
3709 return false;
3710}
3711
3712// Floating-point equality is not an equivalence when comparing +0.0 with
3713// -0.0, when comparing NaN with another value, or when flushing
3714// denormals-to-zero.
3715bool CmpInst::isEquivalence(bool Invert) const {
3716 switch (Invert ? getInversePredicate() : getPredicate()) {
3718 return true;
3720 if (!hasNoNaNs())
3721 return false;
3722 [[fallthrough]];
3724 return hasNonZeroFPOperands(this);
3725 default:
3726 return false;
3727 }
3728}
3729
3731 switch (pred) {
3732 default: llvm_unreachable("Unknown cmp predicate!");
3733 case ICMP_EQ: return ICMP_NE;
3734 case ICMP_NE: return ICMP_EQ;
3735 case ICMP_UGT: return ICMP_ULE;
3736 case ICMP_ULT: return ICMP_UGE;
3737 case ICMP_UGE: return ICMP_ULT;
3738 case ICMP_ULE: return ICMP_UGT;
3739 case ICMP_SGT: return ICMP_SLE;
3740 case ICMP_SLT: return ICMP_SGE;
3741 case ICMP_SGE: return ICMP_SLT;
3742 case ICMP_SLE: return ICMP_SGT;
3743
3744 case FCMP_OEQ: return FCMP_UNE;
3745 case FCMP_ONE: return FCMP_UEQ;
3746 case FCMP_OGT: return FCMP_ULE;
3747 case FCMP_OLT: return FCMP_UGE;
3748 case FCMP_OGE: return FCMP_ULT;
3749 case FCMP_OLE: return FCMP_UGT;
3750 case FCMP_UEQ: return FCMP_ONE;
3751 case FCMP_UNE: return FCMP_OEQ;
3752 case FCMP_UGT: return FCMP_OLE;
3753 case FCMP_ULT: return FCMP_OGE;
3754 case FCMP_UGE: return FCMP_OLT;
3755 case FCMP_ULE: return FCMP_OGT;
3756 case FCMP_ORD: return FCMP_UNO;
3757 case FCMP_UNO: return FCMP_ORD;
3758 case FCMP_TRUE: return FCMP_FALSE;
3759 case FCMP_FALSE: return FCMP_TRUE;
3760 }
3761}
3762
3764 switch (Pred) {
3765 default: return "unknown";
3766 case FCmpInst::FCMP_FALSE: return "false";
3767 case FCmpInst::FCMP_OEQ: return "oeq";
3768 case FCmpInst::FCMP_OGT: return "ogt";
3769 case FCmpInst::FCMP_OGE: return "oge";
3770 case FCmpInst::FCMP_OLT: return "olt";
3771 case FCmpInst::FCMP_OLE: return "ole";
3772 case FCmpInst::FCMP_ONE: return "one";
3773 case FCmpInst::FCMP_ORD: return "ord";
3774 case FCmpInst::FCMP_UNO: return "uno";
3775 case FCmpInst::FCMP_UEQ: return "ueq";
3776 case FCmpInst::FCMP_UGT: return "ugt";
3777 case FCmpInst::FCMP_UGE: return "uge";
3778 case FCmpInst::FCMP_ULT: return "ult";
3779 case FCmpInst::FCMP_ULE: return "ule";
3780 case FCmpInst::FCMP_UNE: return "une";
3781 case FCmpInst::FCMP_TRUE: return "true";
3782 case ICmpInst::ICMP_EQ: return "eq";
3783 case ICmpInst::ICMP_NE: return "ne";
3784 case ICmpInst::ICMP_SGT: return "sgt";
3785 case ICmpInst::ICMP_SGE: return "sge";
3786 case ICmpInst::ICMP_SLT: return "slt";
3787 case ICmpInst::ICMP_SLE: return "sle";
3788 case ICmpInst::ICMP_UGT: return "ugt";
3789 case ICmpInst::ICMP_UGE: return "uge";
3790 case ICmpInst::ICMP_ULT: return "ult";
3791 case ICmpInst::ICMP_ULE: return "ule";
3792 }
3793}
3794
3796 OS << CmpInst::getPredicateName(Pred);
3797 return OS;
3798}
3799
3801 switch (pred) {
3802 default: llvm_unreachable("Unknown icmp predicate!");
3803 case ICMP_EQ: case ICMP_NE:
3804 case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
3805 return pred;
3806 case ICMP_UGT: return ICMP_SGT;
3807 case ICMP_ULT: return ICMP_SLT;
3808 case ICMP_UGE: return ICMP_SGE;
3809 case ICMP_ULE: return ICMP_SLE;
3810 }
3811}
3812
3814 switch (pred) {
3815 default: llvm_unreachable("Unknown icmp predicate!");
3816 case ICMP_EQ: case ICMP_NE:
3817 case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE:
3818 return pred;
3819 case ICMP_SGT: return ICMP_UGT;
3820 case ICMP_SLT: return ICMP_ULT;
3821 case ICMP_SGE: return ICMP_UGE;
3822 case ICMP_SLE: return ICMP_ULE;
3823 }
3824}
3825
3827 switch (pred) {
3828 default: llvm_unreachable("Unknown cmp predicate!");
3829 case ICMP_EQ: case ICMP_NE:
3830 return pred;
3831 case ICMP_SGT: return ICMP_SLT;
3832 case ICMP_SLT: return ICMP_SGT;
3833 case ICMP_SGE: return ICMP_SLE;
3834 case ICMP_SLE: return ICMP_SGE;
3835 case ICMP_UGT: return ICMP_ULT;
3836 case ICMP_ULT: return ICMP_UGT;
3837 case ICMP_UGE: return ICMP_ULE;
3838 case ICMP_ULE: return ICMP_UGE;
3839
3840 case FCMP_FALSE: case FCMP_TRUE:
3841 case FCMP_OEQ: case FCMP_ONE:
3842 case FCMP_UEQ: case FCMP_UNE:
3843 case FCMP_ORD: case FCMP_UNO:
3844 return pred;
3845 case FCMP_OGT: return FCMP_OLT;
3846 case FCMP_OLT: return FCMP_OGT;
3847 case FCMP_OGE: return FCMP_OLE;
3848 case FCMP_OLE: return FCMP_OGE;
3849 case FCMP_UGT: return FCMP_ULT;
3850 case FCMP_ULT: return FCMP_UGT;
3851 case FCMP_UGE: return FCMP_ULE;
3852 case FCMP_ULE: return FCMP_UGE;
3853 }
3854}
3855
3857 switch (pred) {
3858 case ICMP_SGE:
3859 case ICMP_SLE:
3860 case ICMP_UGE:
3861 case ICMP_ULE:
3862 case FCMP_OGE:
3863 case FCMP_OLE:
3864 case FCMP_UGE:
3865 case FCMP_ULE:
3866 return true;
3867 default:
3868 return false;
3869 }
3870}
3871
3873 switch (pred) {
3874 case ICMP_SGT:
3875 case ICMP_SLT:
3876 case ICMP_UGT:
3877 case ICMP_ULT:
3878 case FCMP_OGT:
3879 case FCMP_OLT:
3880 case FCMP_UGT:
3881 case FCMP_ULT:
3882 return true;
3883 default:
3884 return false;
3885 }
3886}
3887
3889 switch (pred) {
3890 case ICMP_SGE:
3891 return ICMP_SGT;
3892 case ICMP_SLE:
3893 return ICMP_SLT;
3894 case ICMP_UGE:
3895 return ICMP_UGT;
3896 case ICMP_ULE:
3897 return ICMP_ULT;
3898 case FCMP_OGE:
3899 return FCMP_OGT;
3900 case FCMP_OLE:
3901 return FCMP_OLT;
3902 case FCMP_UGE:
3903 return FCMP_UGT;
3904 case FCMP_ULE:
3905 return FCMP_ULT;
3906 default:
3907 return pred;
3908 }
3909}
3910
3912 switch (pred) {
3913 case ICMP_SGT:
3914 return ICMP_SGE;
3915 case ICMP_SLT:
3916 return ICMP_SLE;
3917 case ICMP_UGT:
3918 return ICMP_UGE;
3919 case ICMP_ULT:
3920 return ICMP_ULE;
3921 case FCMP_OGT:
3922 return FCMP_OGE;
3923 case FCMP_OLT:
3924 return FCMP_OLE;
3925 case FCMP_UGT:
3926 return FCMP_UGE;
3927 case FCMP_ULT:
3928 return FCMP_ULE;
3929 default:
3930 return pred;
3931 }
3932}
3933
3935 assert(CmpInst::isRelational(pred) && "Call only with relational predicate!");
3936
3937 if (isStrictPredicate(pred))
3938 return getNonStrictPredicate(pred);
3939 if (isNonStrictPredicate(pred))
3940 return getStrictPredicate(pred);
3941
3942 llvm_unreachable("Unknown predicate!");
3943}
3944
3945bool ICmpInst::compare(const APInt &LHS, const APInt &RHS,
3946 ICmpInst::Predicate Pred) {
3947 assert(ICmpInst::isIntPredicate(Pred) && "Only for integer predicates!");
3948 switch (Pred) {
3950 return LHS.eq(RHS);
3952 return LHS.ne(RHS);
3954 return LHS.ugt(RHS);
3956 return LHS.uge(RHS);
3958 return LHS.ult(RHS);
3960 return LHS.ule(RHS);
3962 return LHS.sgt(RHS);
3964 return LHS.sge(RHS);
3966 return LHS.slt(RHS);
3968 return LHS.sle(RHS);
3969 default:
3970 llvm_unreachable("Unexpected non-integer predicate.");
3971 };
3972}
3973
3974bool FCmpInst::compare(const APFloat &LHS, const APFloat &RHS,
3975 FCmpInst::Predicate Pred) {
3976 APFloat::cmpResult R = LHS.compare(RHS);
3977 switch (Pred) {
3978 default:
3979 llvm_unreachable("Invalid FCmp Predicate");
3981 return false;
3983 return true;
3984 case FCmpInst::FCMP_UNO:
3985 return R == APFloat::cmpUnordered;
3986 case FCmpInst::FCMP_ORD:
3987 return R != APFloat::cmpUnordered;
3988 case FCmpInst::FCMP_UEQ:
3989 return R == APFloat::cmpUnordered || R == APFloat::cmpEqual;
3990 case FCmpInst::FCMP_OEQ:
3991 return R == APFloat::cmpEqual;
3992 case FCmpInst::FCMP_UNE:
3993 return R != APFloat::cmpEqual;
3994 case FCmpInst::FCMP_ONE:
3996 case FCmpInst::FCMP_ULT:
3997 return R == APFloat::cmpUnordered || R == APFloat::cmpLessThan;
3998 case FCmpInst::FCMP_OLT:
3999 return R == APFloat::cmpLessThan;
4000 case FCmpInst::FCMP_UGT:
4002 case FCmpInst::FCMP_OGT:
4003 return R == APFloat::cmpGreaterThan;
4004 case FCmpInst::FCMP_ULE:
4005 return R != APFloat::cmpGreaterThan;
4006 case FCmpInst::FCMP_OLE:
4007 return R == APFloat::cmpLessThan || R == APFloat::cmpEqual;
4008 case FCmpInst::FCMP_UGE:
4009 return R != APFloat::cmpLessThan;
4010 case FCmpInst::FCMP_OGE:
4011 return R == APFloat::cmpGreaterThan || R == APFloat::cmpEqual;
4012 }
4013}
4014
4015std::optional<bool> ICmpInst::compare(const KnownBits &LHS,
4016 const KnownBits &RHS,
4017 ICmpInst::Predicate Pred) {
4018 switch (Pred) {
4019 case ICmpInst::ICMP_EQ:
4020 return KnownBits::eq(LHS, RHS);
4021 case ICmpInst::ICMP_NE:
4022 return KnownBits::ne(LHS, RHS);
4023 case ICmpInst::ICMP_UGE:
4024 return KnownBits::uge(LHS, RHS);
4025 case ICmpInst::ICMP_UGT:
4026 return KnownBits::ugt(LHS, RHS);
4027 case ICmpInst::ICMP_ULE:
4028 return KnownBits::ule(LHS, RHS);
4029 case ICmpInst::ICMP_ULT:
4030 return KnownBits::ult(LHS, RHS);
4031 case ICmpInst::ICMP_SGE:
4032 return KnownBits::sge(LHS, RHS);
4033 case ICmpInst::ICMP_SGT:
4034 return KnownBits::sgt(LHS, RHS);
4035 case ICmpInst::ICMP_SLE:
4036 return KnownBits::sle(LHS, RHS);
4037 case ICmpInst::ICMP_SLT:
4038 return KnownBits::slt(LHS, RHS);
4039 default:
4040 llvm_unreachable("Unexpected non-integer predicate.");
4041 }
4042}
4043
4045 if (CmpInst::isEquality(pred))
4046 return pred;
4047 if (isSigned(pred))
4048 return getUnsignedPredicate(pred);
4049 if (isUnsigned(pred))
4050 return getSignedPredicate(pred);
4051
4052 llvm_unreachable("Unknown predicate!");
4053}
4054
4056 switch (predicate) {
4057 default: return false;
4060 case FCmpInst::FCMP_ORD: return true;
4061 }
4062}
4063
4065 switch (predicate) {
4066 default: return false;
4069 case FCmpInst::FCMP_UNO: return true;
4070 }
4071}
4072
4074 switch(predicate) {
4075 default: return false;
4076 case ICMP_EQ: case ICMP_UGE: case ICMP_ULE: case ICMP_SGE: case ICMP_SLE:
4077 case FCMP_TRUE: case FCMP_UEQ: case FCMP_UGE: case FCMP_ULE: return true;
4078 }
4079}
4080
4082 switch(predicate) {
4083 case ICMP_NE: case ICMP_UGT: case ICMP_ULT: case ICMP_SGT: case ICMP_SLT:
4084 case FCMP_FALSE: case FCMP_ONE: case FCMP_OGT: case FCMP_OLT: return true;
4085 default: return false;
4086 }
4087}
4088
4090 // If the predicates match, then we know the first condition implies the
4091 // second is true.
4092 if (CmpPredicate::getMatching(Pred1, Pred2))
4093 return true;
4094
4095 if (Pred1.hasSameSign() && CmpInst::isSigned(Pred2))
4097 else if (Pred2.hasSameSign() && CmpInst::isSigned(Pred1))
4099
4100 switch (Pred1) {
4101 default:
4102 break;
4103 case CmpInst::ICMP_EQ:
4104 // A == B implies A >=u B, A <=u B, A >=s B, and A <=s B are true.
4105 return Pred2 == CmpInst::ICMP_UGE || Pred2 == CmpInst::ICMP_ULE ||
4106 Pred2 == CmpInst::ICMP_SGE || Pred2 == CmpInst::ICMP_SLE;
4107 case CmpInst::ICMP_UGT: // A >u B implies A != B and A >=u B are true.
4108 return Pred2 == CmpInst::ICMP_NE || Pred2 == CmpInst::ICMP_UGE;
4109 case CmpInst::ICMP_ULT: // A <u B implies A != B and A <=u B are true.
4110 return Pred2 == CmpInst::ICMP_NE || Pred2 == CmpInst::ICMP_ULE;
4111 case CmpInst::ICMP_SGT: // A >s B implies A != B and A >=s B are true.
4112 return Pred2 == CmpInst::ICMP_NE || Pred2 == CmpInst::ICMP_SGE;
4113 case CmpInst::ICMP_SLT: // A <s B implies A != B and A <=s B are true.
4114 return Pred2 == CmpInst::ICMP_NE || Pred2 == CmpInst::ICMP_SLE;
4115 }
4116 return false;
4117}
4118
4120 CmpPredicate Pred2) {
4121 return isImpliedTrueByMatchingCmp(Pred1,
4123}
4124
4126 CmpPredicate Pred2) {
4127 if (isImpliedTrueByMatchingCmp(Pred1, Pred2))
4128 return true;
4129 if (isImpliedFalseByMatchingCmp(Pred1, Pred2))
4130 return false;
4131 return std::nullopt;
4132}
4133
4134//===----------------------------------------------------------------------===//
4135// CmpPredicate Implementation
4136//===----------------------------------------------------------------------===//
4137
4138std::optional<CmpPredicate> CmpPredicate::getMatching(CmpPredicate A,
4139 CmpPredicate B) {
4140 if (A.Pred == B.Pred)
4141 return A.HasSameSign == B.HasSameSign ? A : CmpPredicate(A.Pred);
4143 return {};
4144 if (A.HasSameSign &&
4146 return B.Pred;
4147 if (B.HasSameSign &&
4149 return A.Pred;
4150 return {};
4151}
4152
4156
4158 if (auto *ICI = dyn_cast<ICmpInst>(Cmp))
4159 return ICI->getCmpPredicate();
4160 return Cmp->getPredicate();
4161}
4162
4166
4170
4172 return getSwapped(get(Cmp));
4173}
4174
4175//===----------------------------------------------------------------------===//
4176// SwitchInst Implementation
4177//===----------------------------------------------------------------------===//
4178
4179void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumReserved) {
4180 assert(Value && Default && NumReserved);
4181 ReservedSpace = NumReserved;
4182 allocHungoffUses(ReservedSpace);
4184
4185 Op<0>() = Value;
4186 Op<1>() = Default;
4187}
4188
4189/// SwitchInst ctor - Create a new switch instruction, specifying a value to
4190/// switch on and a default destination. The number of additional cases can
4191/// be specified here to make memory allocation more efficient. This
4192/// constructor can also autoinsert before another instruction.
4193SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
4194 InsertPosition InsertBefore)
4195 : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
4196 AllocMarker, InsertBefore) {
4197 init(Value, Default, 2 + NumCases);
4198}
4199
4200SwitchInst::SwitchInst(const SwitchInst &SI)
4201 : Instruction(SI.getType(), Instruction::Switch, AllocMarker) {
4202 init(SI.getCondition(), SI.getDefaultDest(), SI.getNumOperands());
4203 setNumHungOffUseOperands(SI.getNumOperands());
4204 Use *OL = getOperandList();
4205 ConstantInt **VL = case_values();
4206 const Use *InOL = SI.getOperandList();
4207 ConstantInt *const *InVL = SI.case_values();
4208 for (unsigned i = 2, E = SI.getNumOperands(); i != E; ++i) {
4209 OL[i] = InOL[i];
4210 VL[i - 2] = InVL[i - 2];
4211 }
4212 SubclassOptionalData = SI.SubclassOptionalData;
4213}
4214
4215/// addCase - Add an entry to the switch instruction...
4216///
4218 unsigned NewCaseIdx = getNumCases();
4219 unsigned OpNo = getNumOperands();
4220 if (OpNo + 1 > ReservedSpace)
4221 growOperands(); // Get more space!
4222 // Initialize some new operands.
4223 assert(OpNo < ReservedSpace && "Growing didn't work!");
4224 setNumHungOffUseOperands(OpNo + 1);
4225 CaseHandle Case(this, NewCaseIdx);
4226 Case.setValue(OnVal);
4227 Case.setSuccessor(Dest);
4228}
4229
4230/// removeCase - This method removes the specified case and its successor
4231/// from the switch instruction.
4233 unsigned idx = I->getCaseIndex();
4234
4235 assert(2 + idx < getNumOperands() && "Case index out of range!!!");
4236
4237 unsigned NumOps = getNumOperands();
4238 Use *OL = getOperandList();
4239 ConstantInt **VL = case_values();
4240
4241 // Overwrite this case with the end of the list.
4242 if (2 + idx + 1 != NumOps) {
4243 OL[2 + idx] = OL[NumOps - 1];
4244 VL[idx] = VL[NumOps - 2 - 1];
4245 }
4246
4247 // Nuke the last value.
4248 OL[NumOps - 1].set(nullptr);
4249 VL[NumOps - 2 - 1] = nullptr;
4251
4252 return CaseIt(this, idx);
4253}
4254
4255/// growOperands - grow operands - This grows the operand list in response
4256/// to a push_back style of operation. This grows the number of ops by 3 times.
4257///
4258void SwitchInst::growOperands() {
4259 unsigned e = getNumOperands();
4260 unsigned NumOps = e*3;
4261
4262 ReservedSpace = NumOps;
4263 growHungoffUses(ReservedSpace, /*WithExtraValues=*/true);
4264}
4265
4267 MDNode *ProfileData = getBranchWeightMDNode(SI);
4268 if (!ProfileData)
4269 return;
4270
4271 if (getNumBranchWeights(*ProfileData) != SI.getNumSuccessors()) {
4272 llvm_unreachable("number of prof branch_weights metadata operands does "
4273 "not correspond to number of succesors");
4274 }
4275
4277 if (!extractBranchWeights(ProfileData, Weights))
4278 return;
4279 this->Weights = std::move(Weights);
4280}
4281
4284 if (Weights) {
4285 assert(SI.getNumSuccessors() == Weights->size() &&
4286 "num of prof branch_weights must accord with num of successors");
4287 Changed = true;
4288 // Copy the last case to the place of the removed one and shrink.
4289 // This is tightly coupled with the way SwitchInst::removeCase() removes
4290 // the cases in SwitchInst::removeCase(CaseIt).
4291 (*Weights)[I->getCaseIndex() + 1] = Weights->back();
4292 Weights->pop_back();
4293 }
4294 return SI.removeCase(I);
4295}
4296
4298 auto *DestBlock = I->getCaseSuccessor();
4299 if (Weights) {
4300 auto Weight = getSuccessorWeight(I->getCaseIndex() + 1);
4301 (*Weights)[0] = Weight.value();
4302 }
4303
4304 SI.setDefaultDest(DestBlock);
4305}
4306
4308 ConstantInt *OnVal, BasicBlock *Dest,
4310 SI.addCase(OnVal, Dest);
4311
4312 if (!Weights && W && *W) {
4313 Changed = true;
4314 Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
4315 (*Weights)[SI.getNumSuccessors() - 1] = *W;
4316 } else if (Weights) {
4317 Changed = true;
4318 Weights->push_back(W.value_or(0));
4319 }
4320 if (Weights)
4321 assert(SI.getNumSuccessors() == Weights->size() &&
4322 "num of prof branch_weights must accord with num of successors");
4323}
4324
4327 // Instruction is erased. Mark as unchanged to not touch it in the destructor.
4328 Changed = false;
4329 if (Weights)
4330 Weights->resize(0);
4331 return SI.eraseFromParent();
4332}
4333
4336 if (!Weights)
4337 return std::nullopt;
4338 return (*Weights)[idx];
4339}
4340
4343 if (!W)
4344 return;
4345
4346 if (!Weights && *W)
4347 Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
4348
4349 if (Weights) {
4350 auto &OldW = (*Weights)[idx];
4351 if (*W != OldW) {
4352 Changed = true;
4353 OldW = *W;
4354 }
4355 }
4356}
4357
4360 unsigned idx) {
4361 if (MDNode *ProfileData = getValidBranchWeightMDNode(SI)) {
4362 SmallVector<uint32_t> Weights;
4363 extractFromBranchWeightMD32(ProfileData, Weights);
4364 return Weights[idx];
4365 }
4366
4367 return std::nullopt;
4368}
4369
4370//===----------------------------------------------------------------------===//
4371// IndirectBrInst Implementation
4372//===----------------------------------------------------------------------===//
4373
4374void IndirectBrInst::init(Value *Address, unsigned NumDests) {
4375 assert(Address && Address->getType()->isPointerTy() &&
4376 "Address of indirectbr must be a pointer");
4377 ReservedSpace = 1 + NumDests;
4378 allocHungoffUses(ReservedSpace);
4380
4381 Op<0>() = Address;
4382}
4383
4384
4385/// growOperands - grow operands - This grows the operand list in response
4386/// to a push_back style of operation. This grows the number of ops by 2 times.
4387///
4388void IndirectBrInst::growOperands() {
4389 unsigned e = getNumOperands();
4390 unsigned NumOps = e*2;
4391
4392 ReservedSpace = NumOps;
4393 growHungoffUses(ReservedSpace);
4394}
4395
4396IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
4397 InsertPosition InsertBefore)
4398 : Instruction(Type::getVoidTy(Address->getContext()),
4399 Instruction::IndirectBr, AllocMarker, InsertBefore) {
4400 init(Address, NumCases);
4401}
4402
4403IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
4404 : Instruction(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
4405 AllocMarker) {
4406 allocHungoffUses(IBI.getNumOperands());
4407 setNumHungOffUseOperands(IBI.NumUserOperands);
4408 Use *OL = getOperandList();
4409 const Use *InOL = IBI.getOperandList();
4410 for (unsigned i = 0, E = IBI.getNumOperands(); i != E; ++i)
4411 OL[i] = InOL[i];
4412 SubclassOptionalData = IBI.SubclassOptionalData;
4413}
4414
4415/// addDestination - Add a destination.
4416///
4418 unsigned OpNo = getNumOperands();
4419 if (OpNo+1 > ReservedSpace)
4420 growOperands(); // Get more space!
4421 // Initialize some new operands.
4422 assert(OpNo < ReservedSpace && "Growing didn't work!");
4424 getOperandList()[OpNo] = DestBB;
4425}
4426
4427/// removeDestination - This method removes the specified successor from the
4428/// indirectbr instruction.
4430 assert(idx < getNumOperands()-1 && "Successor index out of range!");
4431
4432 unsigned NumOps = getNumOperands();
4433 Use *OL = getOperandList();
4434
4435 // Replace this value with the last one.
4436 OL[idx+1] = OL[NumOps-1];
4437
4438 // Nuke the last value.
4439 OL[NumOps-1].set(nullptr);
4441}
4442
4443//===----------------------------------------------------------------------===//
4444// FreezeInst Implementation
4445//===----------------------------------------------------------------------===//
4446
4447FreezeInst::FreezeInst(Value *S, const Twine &Name, InsertPosition InsertBefore)
4448 : UnaryInstruction(S->getType(), Freeze, S, InsertBefore) {
4449 setName(Name);
4450}
4451
4452//===----------------------------------------------------------------------===//
4453// cloneImpl() implementations
4454//===----------------------------------------------------------------------===//
4455
4456// Define these methods here so vtables don't get emitted into every translation
4457// unit that uses these classes.
4458
4459GetElementPtrInst *GetElementPtrInst::cloneImpl() const {
4461 return new (AllocMarker) GetElementPtrInst(*this, AllocMarker);
4462}
4463
4467
4469 auto *I = static_cast<FPUnaryOperator *>(Create(getOpcode(), Op<0>()));
4470 I->FMF = FMF;
4471 return I;
4472}
4473
4476 "Should call FPBinaryOperator::cloneImpl!");
4477 return Create(getOpcode(), Op<0>(), Op<1>());
4478}
4479
4481 auto *I =
4482 static_cast<FPBinaryOperator *>(Create(getOpcode(), Op<0>(), Op<1>()));
4483 I->FMF = FMF;
4484 return I;
4485}
4486
4488 auto *I = new FCmpInst(getPredicate(), Op<0>(), Op<1>());
4489 I->FMF = FMF;
4490 return I;
4491}
4492
4494 auto *Result = new ICmpInst(getPredicate(), Op<0>(), Op<1>());
4495 Result->setSameSign(hasSameSign());
4496 return Result;
4497}
4498
4499ExtractValueInst *ExtractValueInst::cloneImpl() const {
4500 return new ExtractValueInst(*this);
4501}
4502
4503InsertValueInst *InsertValueInst::cloneImpl() const {
4504 return new InsertValueInst(*this);
4505}
4506
4509 getOperand(0), getAlign());
4510 Result->setUsedWithInAlloca(isUsedWithInAlloca());
4511 Result->setSwiftError(isSwiftError());
4512 return Result;
4513}
4514
4516 return new LoadInst(getType(), getOperand(0), Twine(), getProperties(),
4517 /*InsertBefore=*/nullptr);
4518}
4519
4521 return new StoreInst(getOperand(0), getOperand(1), getProperties(),
4522 /*InsertBefore=*/nullptr);
4523}
4524
4529 Result->setVolatile(isVolatile());
4530 Result->setWeak(isWeak());
4531 return Result;
4532}
4533
4535 AtomicRMWInst *Result = new AtomicRMWInst(
4538 Result->setVolatile(isVolatile());
4539 return Result;
4540}
4541
4545
4547 return new TruncInst(getOperand(0), getType());
4548}
4549
4551 return new ZExtInst(getOperand(0), getType());
4552}
4553
4555 return new SExtInst(getOperand(0), getType());
4556}
4557
4559 auto *I = new FPTruncInst(getOperand(0), getType());
4560 I->FMF = FMF;
4561 return I;
4562}
4563
4565 auto *I = new FPExtInst(getOperand(0), getType());
4566 I->FMF = FMF;
4567 return I;
4568}
4569
4571 auto *Result = new UIToFPInst(getOperand(0), getType());
4572 Result->FMF = FMF;
4573 return Result;
4574}
4575
4577 auto *Result = new SIToFPInst(getOperand(0), getType());
4578 Result->FMF = FMF;
4579 return Result;
4580}
4581
4583 return new FPToUIInst(getOperand(0), getType());
4584}
4585
4587 return new FPToSIInst(getOperand(0), getType());
4588}
4589
4591 return new PtrToIntInst(getOperand(0), getType());
4592}
4593
4597
4599 return new IntToPtrInst(getOperand(0), getType());
4600}
4601
4603 return new BitCastInst(getOperand(0), getType());
4604}
4605
4609
4610CallInst *CallInst::cloneImpl() const {
4611 if (hasOperandBundles()) {
4615 return new (AllocMarker) CallInst(*this, AllocMarker);
4616 }
4618 return new (AllocMarker) CallInst(*this, AllocMarker);
4619}
4620
4621SelectInst *SelectInst::cloneImpl() const {
4623 I->FMF = FMF;
4624 return I;
4625}
4626
4628 return new VAArgInst(getOperand(0), getType());
4629}
4630
4631ExtractElementInst *ExtractElementInst::cloneImpl() const {
4633}
4634
4635InsertElementInst *InsertElementInst::cloneImpl() const {
4637}
4638
4639BitInsertInst *BitInsertInst::cloneImpl() const {
4641}
4642
4643BitExtractInst *BitExtractInst::cloneImpl() const {
4645}
4646
4650
4651PHINode *PHINode::cloneImpl() const { return new (AllocMarker) PHINode(*this); }
4652
4653LandingPadInst *LandingPadInst::cloneImpl() const {
4654 return new LandingPadInst(*this);
4655}
4656
4657ReturnInst *ReturnInst::cloneImpl() const {
4659 return new (AllocMarker) ReturnInst(*this, AllocMarker);
4660}
4661
4662UncondBrInst *UncondBrInst::cloneImpl() const {
4663 return new (AllocMarker) UncondBrInst(*this);
4664}
4665
4666CondBrInst *CondBrInst::cloneImpl() const {
4667 return new (AllocMarker) CondBrInst(*this);
4668}
4669
4670SwitchInst *SwitchInst::cloneImpl() const { return new SwitchInst(*this); }
4671
4672IndirectBrInst *IndirectBrInst::cloneImpl() const {
4673 return new IndirectBrInst(*this);
4674}
4675
4676InvokeInst *InvokeInst::cloneImpl() const {
4677 if (hasOperandBundles()) {
4681 return new (AllocMarker) InvokeInst(*this, AllocMarker);
4682 }
4684 return new (AllocMarker) InvokeInst(*this, AllocMarker);
4685}
4686
4687CallBrInst *CallBrInst::cloneImpl() const {
4688 if (hasOperandBundles()) {
4692 return new (AllocMarker) CallBrInst(*this, AllocMarker);
4693 }
4695 return new (AllocMarker) CallBrInst(*this, AllocMarker);
4696}
4697
4698ResumeInst *ResumeInst::cloneImpl() const {
4699 return new (AllocMarker) ResumeInst(*this);
4700}
4701
4702CleanupReturnInst *CleanupReturnInst::cloneImpl() const {
4704 return new (AllocMarker) CleanupReturnInst(*this, AllocMarker);
4705}
4706
4707CatchReturnInst *CatchReturnInst::cloneImpl() const {
4708 return new (AllocMarker) CatchReturnInst(*this);
4709}
4710
4711CatchSwitchInst *CatchSwitchInst::cloneImpl() const {
4712 return new CatchSwitchInst(*this);
4713}
4714
4715FuncletPadInst *FuncletPadInst::cloneImpl() const {
4717 return new (AllocMarker) FuncletPadInst(*this, AllocMarker);
4718}
4719
4721 LLVMContext &Context = getContext();
4722 return new UnreachableInst(Context);
4723}
4724
4725bool UnreachableInst::shouldLowerToTrap(bool TrapUnreachable,
4726 bool NoTrapAfterNoreturn) const {
4727 if (!TrapUnreachable)
4728 return false;
4729
4730 // We may be able to ignore unreachable behind a noreturn call.
4732 Call && Call->doesNotReturn()) {
4733 if (NoTrapAfterNoreturn)
4734 return false;
4735 // Do not emit an additional trap instruction.
4736 if (Call->isNonContinuableTrap())
4737 return false;
4738 }
4739
4740 if (getFunction()->hasFnAttribute(Attribute::Naked))
4741 return false;
4742
4743 return true;
4744}
4745
4747 return new FreezeInst(getOperand(0));
4748}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
constexpr LLT S1
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
@ FnAttr
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")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
This file contains the declarations for the subclasses of Constant, which represent the different fla...
@ Default
static bool isSigned(unsigned Opcode)
#define op(i)
Module.h This file contains the declarations for the Module class.
static Align computeLoadStoreDefaultAlign(Type *Ty, InsertPosition Pos)
static bool isImpliedFalseByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2)
static Value * createPlaceholderForShuffleVector(Value *V)
static Align computeAllocaDefaultAlign(Type *Ty, InsertPosition Pos)
static cl::opt< bool > DisableI2pP2iOpt("disable-i2p-p2i-opt", cl::init(false), cl::desc("Disables inttoptr/ptrtoint roundtrip optimization"))
static bool hasNonZeroFPOperands(const CmpInst *Cmp)
static int matchShuffleAsBitRotate(ArrayRef< int > Mask, int NumSubElts)
Try to lower a vector shuffle as a bit rotation.
static Type * getIndexedTypeInternal(Type *Ty, ArrayRef< IndexTy > IdxList)
static bool isReplicationMaskWithParams(ArrayRef< int > Mask, int ReplicationFactor, int VF)
static bool isIdentityMaskImpl(ArrayRef< int > Mask, int NumOpElts)
static Value * getAISize(LLVMContext &Context, Value *Amt)
static bool isImpliedTrueByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2)
static bool isSingleSourceMaskImpl(ArrayRef< int > Mask, int64_t NumOpElts)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
#define T
uint64_t IntrinsicInst * II
#define P(N)
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file implements the SmallBitVector class.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
Value * RHS
Value * LHS
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition APFloat.h:351
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:6121
Class for arbitrary precision integers.
Definition APInt.h:78
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition APInt.h:1350
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition APInt.h:376
unsigned countr_zero() const
Count the number of trailing zero bits.
Definition APInt.h:1659
unsigned countl_zero() const
The APInt version of std::countl_zero.
Definition APInt.h:1618
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:196
This class represents a conversion between pointers from one address space to another.
LLVM_ABI AddrSpaceCastInst * cloneImpl() const
Clone an identical AddrSpaceCastInst.
LLVM_ABI AddrSpaceCastInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI std::optional< TypeSize > getAllocationSizeInBits(const DataLayout &DL) const
Get allocation size in bits.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
LLVM_ABI bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
LLVM_ABI TypeSize getAllocationBaseSize(const DataLayout &DL) const
Get the size of the allocated type.
LLVM_ABI AllocaInst * cloneImpl() const
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
LLVM_ABI std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
void setAlignment(Align Align)
const Value * getArraySize() const
Get the number of elements allocated.
LLVM_ABI AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, const Twine &Name, InsertPosition InsertBefore)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition ArrayRef.h:185
Class to represent array types.
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this cmpxchg instruction.
bool isVolatile() const
Return true if this is a cmpxchg from a volatile memory location.
void setFailureOrdering(AtomicOrdering Ordering)
Sets the failure ordering constraint of this cmpxchg instruction.
AtomicOrdering getFailureOrdering() const
Returns the failure ordering constraint of this cmpxchg instruction.
void setSuccessOrdering(AtomicOrdering Ordering)
Sets the success ordering constraint of this cmpxchg instruction.
LLVM_ABI AtomicCmpXchgInst * cloneImpl() const
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
bool isWeak() const
Return true if this cmpxchg may spuriously fail.
void setAlignment(Align Align)
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this cmpxchg instruction.
LLVM_ABI AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID, InsertPosition InsertBefore=nullptr)
bool isElementwise() const
Return true if this RMW has elementwise vector semantics.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
LLVM_ABI AtomicRMWInst * cloneImpl() const
bool isVolatile() const
Return true if this is a RMW on a volatile memory location.
LLVM_ABI AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment, AtomicOrdering Ordering, SyncScope::ID SSID, bool Elementwise=false, InsertPosition InsertBefore=nullptr)
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Add
*p = old + v
@ FAdd
*p = old + v
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ Sub
*p = old - v
@ And
*p = old & v
@ Xor
*p = old ^ v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ FSub
*p = old - v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMaximumNum
*p = maximumnum(old, v) maximumnum matches the behavior of llvm.maximumnum.
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
@ FMinimumNum
*p = minimumnum(old, v) minimumnum matches the behavior of llvm.minimumnum.
@ Nand
*p = ~(old & v)
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this rmw instruction.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this rmw instruction.
void setOperation(BinOp Operation)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
BinOp getOperation() const
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this rmw instruction.
void setAlignment(Align Align)
void setElementwise(bool V)
Specify whether this RMW has elementwise vector semantics.
static LLVM_ABI StringRef getOperationName(BinOp Op)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
LLVM_ABI CaptureInfo getCaptureInfo() const
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
LLVM_ABI const ConstantRange & getRange() const
Returns the value of the range attribute.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:125
static LLVM_ABI Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:266
LLVM Basic Block Representation.
Definition BasicBlock.h:62
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
static LLVM_ABI BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
BinaryOps getOpcode() const
Definition InstrTypes.h:409
LLVM_ABI bool swapOperands()
Exchange the two operands to this instruction.
static LLVM_ABI BinaryOperator * CreateNot(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition InstrTypes.h:216
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
LLVM_ABI BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty, const Twine &Name, InsertPosition InsertBefore)
static LLVM_ABI BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
LLVM_ABI BinaryOperator * cloneImpl() const
This class represents a no-op cast from one type to another.
LLVM_ABI BitCastInst * cloneImpl() const
Clone an identical BitCastInst.
LLVM_ABI BitCastInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI BitExtractInst * cloneImpl() const
Clone an identical BitExtractInst.
static LLVM_ABI const char * areInvalidOperands(const Type *Ty, Value *Val, Value *Offset)
Return a string if the specified operands are invalid for a bitextract operation, otherwise return nu...
static BitExtractInst * Create(Type *Ty, Value *Src, Value *Offset, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI const char * areInvalidOperands(Value *Base, Value *Val, Value *Offset)
Return a string if the specified operands are invalid for a bitinsert operation, otherwise return nul...
static BitInsertInst * Create(Value *Base, Value *Val, Value *Offset, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI BitInsertInst * cloneImpl() const
Clone an identical BitInsertInst.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
LLVM_ABI FPClassTest getParamNoFPClass(unsigned i) const
Extract a test mask for disallowed floating-point value classes for the parameter.
bool isInlineAsm() const
Check if this call is an inline asm statement.
LLVM_ABI BundleOpInfo & getBundleOpInfoForOperand(unsigned OpIdx)
Return the BundleOpInfo for the operand at index OpIdx.
void setCallingConv(CallingConv::ID CC)
LLVM_ABI FPClassTest getRetNoFPClass() const
Extract a test mask for disallowed floating-point value classes for the return value.
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
LLVM_ABI bool paramHasNonNullAttr(unsigned ArgNo, bool AllowUndefOrPoison) const
Return true if this argument has the nonnull attribute on either the CallBase instruction or the call...
LLVM_ABI MemoryEffects getMemoryEffects() const
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
LLVM_ABI bool doesNotAccessMemory() const
Determine if the call does not access memory.
LLVM_ABI void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
LLVM_ABI void setOnlyAccessesArgMemory()
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
OperandBundleUse operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const
Simple helper function to map a BundleOpInfo to an OperandBundleUse.
LLVM_ABI void setOnlyAccessesInaccessibleMemOrArgMem()
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI void setDoesNotAccessMemory()
AttributeSet getParamAttributes(unsigned ArgNo) const
Return the param attributes for this call.
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
LLVM_ABI bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
LLVM_ABI unsigned getNumSubclassExtraOperandsDynamic() const
Get the number of extra operands for instructions that don't have a fixed number of extra operands.
BundleOpInfo * bundle_op_iterator
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
LLVM_ABI bool isIndirectCall() const
Return true if the callsite is an indirect call.
LLVM_ABI bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
iterator_range< bundle_op_iterator > bundle_op_infos()
Return the range [bundle_op_info_begin, bundle_op_info_end).
LLVM_ABI void setOnlyReadsMemory()
static LLVM_ABI CallBase * addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle OB added.
LLVM_ABI bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
static LLVM_ABI CallBase * removeOperandBundleAt(CallBase *CB, size_t Offset, InsertPosition InsertPtr=nullptr)
LLVM_ABI CaptureInfo getCaptureInfo(unsigned OpNo) const
Return which pointer components this operand may capture.
LLVM_ABI bool hasArgumentWithAdditionalReturnCaptureComponents() const
Returns whether the call has an argument that has an attribute like captures(ret: address,...
CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
Value * getCalledOperand() const
LLVM_ABI void setOnlyWritesMemory()
LLVM_ABI op_iterator populateBundleOperandInfos(ArrayRef< OperandBundleDef > Bundles, const unsigned BeginIndex)
Populate the BundleOpInfo instances and the Use& vector from Bundles.
AttributeList Attrs
parameter attributes for callable
bool hasOperandBundlesOtherThan(ArrayRef< uint32_t > IDs) const
Return true if this operand bundle user contains operand bundles with tags other than those specified...
LLVM_ABI std::optional< ConstantRange > getRange() const
If this return value has a range attribute, return the value range of the argument.
LLVM_ABI bool isReturnNonNull() const
Return true if the return value is known to be not null.
Value * getArgOperand(unsigned i) const
FunctionType * FTy
uint64_t getRetDereferenceableBytes() const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
FunctionType * getFunctionType() const
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
static unsigned CountBundleInputs(ArrayRef< OperandBundleDef > Bundles)
Return the total number of values used in Bundles.
LLVM_ABI Value * getArgOperandWithAttribute(Attribute::AttrKind Kind) const
If one of the arguments has the specified attribute, returns its operand value.
LLVM_ABI void setOnlyAccessesInaccessibleMemory()
static LLVM_ABI CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, InsertPosition InsertPt=nullptr)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
LLVM_ABI bool onlyWritesMemory() const
Determine if the call does not access or only writes memory.
LLVM_ABI bool hasClobberingOperandBundles() const
Return true if this operand bundle user has operand bundles that may write to the heap.
void setCalledOperand(Value *V)
static LLVM_ABI CallBase * removeOperandBundle(CallBase *CB, uint32_t ID, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle ID removed.
LLVM_ABI bool hasReadingOperandBundles() const
Return true if this operand bundle user has operand bundles that may read from the heap.
LLVM_ABI bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
LLVM_ABI void setMemoryEffects(MemoryEffects ME)
bool hasOperandBundles() const
Return true if this User has any operand bundles.
LLVM_ABI bool isTailCall() const
Tests if this call site is marked as a tail call.
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
SmallVector< BasicBlock *, 16 > getIndirectDests() const
void setDefaultDest(BasicBlock *B)
void setIndirectDest(unsigned i, BasicBlock *B)
BasicBlock * getDefaultDest() const
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
LLVM_ABI CallBrInst * cloneImpl() const
This class represents a function call, abstracting a target machine's calling convention.
LLVM_ABI void updateProfWeight(uint64_t S, uint64_t T)
Updates profile metadata by scaling it by S / T.
TailCallKind getTailCallKind() const
LLVM_ABI CallInst * cloneImpl() const
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Represents which components of the pointer may be captured in which location.
Definition ModRef.h:414
CaptureComponents getOtherComponents() const
Get components potentially captured through locations other than the return value.
Definition ModRef.h:446
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
Definition ModRef.h:427
static CaptureInfo all()
Create CaptureInfo that may capture all components of the pointer.
Definition ModRef.h:430
CaptureComponents getRetComponents() const
Get components potentially captured by the return value.
Definition ModRef.h:442
static LLVM_ABI Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static LLVM_ABI CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast or an AddrSpaceCast cast instruction.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition InstrTypes.h:674
static LLVM_ABI unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, const DataLayout *DL)
Determine how a pair of casts can be eliminated, if they can be at all.
static LLVM_ABI CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static LLVM_ABI CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics for subclasses.
Definition InstrTypes.h:515
static LLVM_ABI bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
static LLVM_ABI bool isBitCastable(Type *SrcTy, Type *DestTy)
Check whether a bitcast between these types is valid.
static LLVM_ABI CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
static LLVM_ABI CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static LLVM_ABI CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static LLVM_ABI bool isNoopCast(Instruction::CastOps Opcode, Type *SrcTy, Type *DstTy, const DataLayout &DL)
A no-op cast is one that can be effected without changing any bits.
static LLVM_ABI CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
LLVM_ABI bool isIntegerCast() const
There are several places where we need to know if a cast instruction only deals with integer source a...
static LLVM_ABI CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a SExt or BitCast cast instruction.
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
LLVM_ABI CatchReturnInst * cloneImpl() const
void setUnwindDest(BasicBlock *UnwindDest)
LLVM_ABI void addHandler(BasicBlock *Dest)
Add an entry to the switch instruction... Note: This action invalidates handler_end().
LLVM_ABI CatchSwitchInst * cloneImpl() const
mapped_iterator< op_iterator, DerefFnTy > handler_iterator
Value * getParentPad() const
void setParentPad(Value *ParentPad)
BasicBlock * getUnwindDest() const
LLVM_ABI void removeHandler(handler_iterator HI)
LLVM_ABI CleanupReturnInst * cloneImpl() const
This class is the base class for the comparison instructions.
Definition InstrTypes.h:728
Predicate getStrictPredicate() const
For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
Definition InstrTypes.h:921
bool isEquality() const
Determine if this is an equals/not equals predicate.
Definition InstrTypes.h:978
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition InstrTypes.h:831
bool isFalseWhenEqual() const
This is just a convenience.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:757
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:748
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:751
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:749
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:756
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:742
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:750
LLVM_ABI bool isEquivalence(bool Invert=false) const
Determine if one operand of this compare can always be replaced by the other operand,...
bool isSigned() const
Definition InstrTypes.h:993
static LLVM_ABI bool isEquality(Predicate pred)
Determine if this is an equals/not equals predicate.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:890
bool isTrueWhenEqual() const
This is just a convenience.
static LLVM_ABI CmpInst * Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
static bool isFPPredicate(Predicate P)
Definition InstrTypes.h:833
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition InstrTypes.h:934
static LLVM_ABI CmpInst * CreateWithCopiedFlags(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Instruction *FlagsSource, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate, the two operands and the instructio...
LLVM_ABI CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", InsertPosition InsertBefore=nullptr)
bool isNonStrictPredicate() const
Definition InstrTypes.h:915
LLVM_ABI void swapOperands()
This is just a convenience that dispatches to the subclasses.
static bool isRelational(Predicate P)
Return true if the predicate is relational (not EQ or NE).
Definition InstrTypes.h:986
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition InstrTypes.h:852
static LLVM_ABI StringRef getPredicateName(Predicate P)
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:828
bool isStrictPredicate() const
Definition InstrTypes.h:906
static LLVM_ABI bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition InstrTypes.h:956
static bool isIntPredicate(Predicate P)
Definition InstrTypes.h:839
static LLVM_ABI bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
bool isUnsigned() const
Definition InstrTypes.h:999
LLVM_ABI bool isCommutative() const
This is just a convenience that dispatches to the subclasses.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static LLVM_ABI CmpPredicate getInverse(CmpPredicate P)
Get the inverse predicate of a CmpPredicate.
CmpPredicate()
Default constructor.
static LLVM_ABI CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
LLVM_ABI CmpInst::Predicate getPreferredSignedPredicate() const
Attempts to return a signed CmpInst::Predicate from the CmpPredicate.
bool hasSameSign() const
Query samesign information, for optimizations.
static LLVM_ABI CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
Conditional Branch instruction.
LLVM_ABI void swapSuccessors()
Swap the successors of this branch instruction.
LLVM_ABI CondBrInst * cloneImpl() const
Value * getCondition() const
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
const APFloat & getValueAPF() const
Definition Constants.h:463
This is the shared class of boolean and integer constants.
Definition Constants.h:87
LLVM_ABI ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:305
LLVM_ABI ExtractElementInst * cloneImpl() const
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *Idx)
Return true if an extractelement instruction can be formed with the specified operands.
This instruction extracts a struct member or array element value from an aggregate value.
static LLVM_ABI Type * getIndexedType(Type *Agg, ArrayRef< unsigned > Idxs)
Returns the type of the element that would be extracted with an extractvalue instruction with the spe...
LLVM_ABI ExtractValueInst * cloneImpl() const
This instruction compares its operands according to the predicate given to the constructor.
bool isEquality() const
static LLVM_ABI bool compare(const APFloat &LHS, const APFloat &RHS, FCmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
LLVM_ABI FCmpInst * cloneImpl() const
Clone an identical FCmpInst.
FCmpInst(InsertPosition InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insertion semantics.
Binary operators support fast-math flags, users should not use this class directly,...
Definition InstrTypes.h:476
This class represents an extension of floating point types.
LLVM_ABI FPExtInst * cloneImpl() const
Clone an identical FPExtInst.
LLVM_ABI FPExtInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI float getFPAccuracy() const
Get the maximum error permitted by this operation in ULPs.
This class represents a cast from floating point to signed integer.
LLVM_ABI FPToSIInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI FPToSIInst * cloneImpl() const
Clone an identical FPToSIInst.
This class represents a cast from floating point to unsigned integer.
LLVM_ABI FPToUIInst * cloneImpl() const
Clone an identical FPToUIInst.
LLVM_ABI FPToUIInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
This class represents a truncation of floating point types.
LLVM_ABI FPTruncInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI FPTruncInst * cloneImpl() const
Clone an identical FPTruncInst.
Unary operators support fast-math flags, users should not use this class directly,...
Definition InstrTypes.h:179
LLVM_ABI FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, InsertPosition InsertBefore=nullptr)
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this fence instruction.
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this fence instruction.
LLVM_ABI FenceInst * cloneImpl() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this fence instruction.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Class to represent fixed width SIMD vectors.
LLVM_ABI FreezeInst(Value *S, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI FreezeInst * cloneImpl() const
Clone an identical FreezeInst.
void setParentPad(Value *ParentPad)
Value * getParentPad() const
Convenience accessors.
LLVM_ABI FuncletPadInst * cloneImpl() const
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Type * getParamType(unsigned i) const
Parameter type accessors.
bool isVarArg() const
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags inBounds()
GEPNoWrapFlags withoutInBounds() const
unsigned getRaw() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
LLVM_ABI bool isInBounds() const
Determine whether the GEP has the inbounds flag.
LLVM_ABI bool hasNoUnsignedSignedWrap() const
Determine whether the GEP has the nusw flag.
static LLVM_ABI Type * getTypeAtIndex(Type *Ty, Value *Idx)
Return the type of the element at the given index of an indexable type.
LLVM_ABI bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
LLVM_ABI bool hasNoUnsignedWrap() const
Determine whether the GEP has the nuw flag.
LLVM_ABI bool hasAllConstantIndices() const
Return true if all of the indices of this GEP are constant integers.
LLVM_ABI void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
LLVM_ABI bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
LLVM_ABI GetElementPtrInst * cloneImpl() const
LLVM_ABI bool collectOffset(const DataLayout &DL, unsigned BitWidth, SmallMapVector< Value *, APInt, 4 > &VariableOffsets, APInt &ConstantOffset) const
LLVM_ABI void setNoWrapFlags(GEPNoWrapFlags NW)
Set nowrap flags for GEP instruction.
LLVM_ABI GEPNoWrapFlags getNoWrapFlags() const
Get the nowrap flags for the GEP instruction.
Module * getParent()
Get the module that this global value is contained inside of...
This instruction compares its operands according to the predicate given to the constructor.
bool hasSameSign() const
An icmp instruction, which can be marked as "samesign", indicating that the two operands have the sam...
ICmpInst(InsertPosition InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr="")
Constructor with insertion semantics.
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
LLVM_ABI ICmpInst * cloneImpl() const
Clone an identical ICmpInst.
Predicate getFlippedSignednessPredicate() const
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
static CmpPredicate getInverseCmpPredicate(CmpPredicate Pred)
bool isEquality() const
Return true if this predicate is either EQ or NE.
static LLVM_ABI Predicate getFlippedSignednessPredicate(Predicate Pred)
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ.
static LLVM_ABI std::optional< bool > isImpliedByMatchingCmp(CmpPredicate Pred1, CmpPredicate Pred2)
Determine if Pred1 implies Pred2 is true, false, or if nothing can be inferred about the implication,...
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
Indirect Branch Instruction.
LLVM_ABI void addDestination(BasicBlock *Dest)
Add a destination.
LLVM_ABI void removeDestination(unsigned i)
This method removes the specified successor from the indirectbr instruction.
LLVM_ABI IndirectBrInst * cloneImpl() const
LLVM_ABI InsertElementInst * cloneImpl() const
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
bool isValid() const
Definition Instruction.h:59
BasicBlock * getBasicBlock()
Definition Instruction.h:60
This instruction inserts a struct field of array element value into an aggregate value.
LLVM_ABI InsertValueInst * cloneImpl() const
BitfieldElement::Type getSubclassData() const
LLVM_ABI bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
LLVM_ABI void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
LLVM_ABI bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Bitfield::Element< uint16_t, 0, 16 > OpaqueField
Instruction(const Instruction &)=delete
friend class Value
friend class BasicBlock
Various leaf nodes.
void setSubclassData(typename BitfieldElement::Type Value)
This class represents a cast from an integer to a pointer.
LLVM_ABI IntToPtrInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI IntToPtrInst * cloneImpl() const
Clone an identical IntToPtrInst.
Invoke instruction.
BasicBlock * getUnwindDest() const
void setNormalDest(BasicBlock *B)
LLVM_ABI InvokeInst * cloneImpl() const
LLVM_ABI LandingPadInst * getLandingPadInst() const
Get the landingpad instruction from the landing pad block (the unwind destination).
void setUnwindDest(BasicBlock *B)
LLVM_ABI void updateProfWeight(uint64_t S, uint64_t T)
Updates profile metadata by scaling it by S / T.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
LLVMContextImpl *const pImpl
Definition LLVMContext.h:70
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
LLVM_ABI LandingPadInst * cloneImpl() const
static LLVM_ABI LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
LLVM_ABI void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
void setElementwise(bool V)
Specify whether this is an elementwise atomic load or not.
void setAlignment(Align Align)
bool isVolatile() const
Return true if this is a load from a volatile memory location.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this load instruction.
LLVM_ABI LoadInst * cloneImpl() const
void setVolatile(bool V)
Specify whether this is a volatile load or not.
LoadStoreInstProperties getProperties() const
Returns the properties of this load instruction.
LLVM_ABI LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, InsertPosition InsertBefore)
Metadata node.
Definition Metadata.h:1081
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1437
static MemoryEffectsBase readOnly()
Definition ModRef.h:133
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
Definition ModRef.h:252
bool doesNotAccessMemory() const
Whether this function accesses no memory.
Definition ModRef.h:246
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:143
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:149
bool onlyAccessesInaccessibleMem() const
Whether this function only (at most) accesses inaccessible memory.
Definition ModRef.h:265
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
Definition ModRef.h:255
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition ModRef.h:249
static MemoryEffectsBase writeOnly()
Definition ModRef.h:138
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:166
static MemoryEffectsBase none()
Definition ModRef.h:128
bool onlyAccessesInaccessibleOrArgMem() const
Whether this function only (at most) accesses argument and inaccessible memory.
Definition ModRef.h:305
StringRef getTag() const
void allocHungoffUses(unsigned N)
const_block_iterator block_begin() const
LLVM_ABI void removeIncomingValueIf(function_ref< bool(unsigned)> Predicate, bool DeletePHIIfEmpty=true)
Remove all incoming values for which the predicate returns true.
void setIncomingBlock(unsigned i, BasicBlock *BB)
LLVM_ABI Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
LLVM_ABI bool hasConstantOrUndefValue() const
Whether the specified PHI node always merges together the same value, assuming undefs are equal to a ...
void setIncomingValue(unsigned i, Value *V)
const_block_iterator block_end() const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
LLVM_ABI Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value,...
LLVM_ABI PHINode * cloneImpl() const
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class represents a cast from a pointer to an address (non-capturing ptrtoint).
LLVM_ABI PtrToAddrInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI PtrToAddrInst * cloneImpl() const
Clone an identical PtrToAddrInst.
This class represents a cast from a pointer to an integer.
LLVM_ABI PtrToIntInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI PtrToIntInst * cloneImpl() const
Clone an identical PtrToIntInst.
Resume the propagation of an exception.
LLVM_ABI ResumeInst * cloneImpl() const
Return a value (possibly void), from a function.
LLVM_ABI ReturnInst * cloneImpl() const
This class represents a sign extension of integer types.
LLVM_ABI SExtInst * cloneImpl() const
Clone an identical SExtInst.
LLVM_ABI SExtInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
This class represents a cast from signed integer to floating point.
LLVM_ABI SIToFPInst * cloneImpl() const
Clone an identical SIToFPInst.
LLVM_ABI SIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
Class to represent scalable SIMD vectors.
LLVM_ABI SelectInst * cloneImpl() const
static LLVM_ABI const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
static LLVM_ABI bool isZeroEltSplatMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
ArrayRef< int > getShuffleMask() const
static LLVM_ABI bool isSpliceMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is a splice mask, concatenating the two inputs together and then ext...
int getMaskValue(unsigned Elt) const
Return the shuffle mask value of this instruction for the given element index.
LLVM_ABI ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
static LLVM_ABI bool isSelectMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from its source vectors without lane crossings.
static LLVM_ABI bool isBitRotateMask(ArrayRef< int > Mask, unsigned EltSizeInBits, unsigned MinSubElts, unsigned MaxSubElts, unsigned &NumSubElts, unsigned &RotateAmt)
Checks if the shuffle is a bit rotation of the first operand across multiple subelements,...
VectorType * getType() const
Overload to return most specific vector type.
LLVM_ABI bool isIdentityWithExtract() const
Return true if this shuffle extracts the first N elements of exactly one source vector.
static LLVM_ABI bool isOneUseSingleSourceMask(ArrayRef< int > Mask, int VF)
Return true if this shuffle mask represents "clustered" mask of size VF, i.e.
LLVM_ABI bool isIdentityWithPadding() const
Return true if this shuffle lengthens exactly one source vector with undefs in the high elements.
static LLVM_ABI bool isSingleSourceMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector.
LLVM_ABI bool isConcat() const
Return true if this shuffle concatenates its 2 source vectors.
static LLVM_ABI bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor, unsigned &Index)
Check if the mask is a DE-interleave mask of the given factor Factor like: <Index,...
LLVM_ABI ShuffleVectorInst * cloneImpl() const
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
static LLVM_ABI bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
LLVM_ABI void setShuffleMask(ArrayRef< int > Mask)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI bool isInterleave(unsigned Factor)
Return if this shuffle interleaves its two input vectors together.
static LLVM_ABI bool isReverseMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask swaps the order of elements from exactly one source vector.
static LLVM_ABI bool isTransposeMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask is a transpose mask.
LLVM_ABI void commute()
Swap the operands and adjust the mask to preserve the semantics of the instruction.
static LLVM_ABI bool isInsertSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &NumSubElts, int &Index)
Return true if this shuffle mask is an insert subvector mask.
static LLVM_ABI Constant * convertShuffleMaskForBitcode(ArrayRef< int > Mask, Type *ResultTy)
static LLVM_ABI bool isReplicationMask(ArrayRef< int > Mask, int &ReplicationFactor, int &VF)
Return true if this shuffle mask replicates each of the VF elements in a vector ReplicationFactor tim...
static LLVM_ABI bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts, SmallVectorImpl< unsigned > &StartIndexes)
Return true if the mask interleaves one or more input vectors together.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void setVolatile(bool V)
Specify whether this is a volatile store or not.
void setAlignment(Align Align)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LoadStoreInstProperties getProperties() const
Returns the properties of this store instruction.
LLVM_ABI StoreInst * cloneImpl() const
void setElementwise(bool V)
Specify whether this is an elementwise atomic store or not.
LLVM_ABI StoreInst(Value *Val, Value *Ptr, InsertPosition InsertBefore)
bool isVolatile() const
Return true if this is a store to a volatile memory location.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this store instruction.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
LLVM_ABI void setSuccessorWeight(unsigned idx, CaseWeightOpt W)
LLVM_ABI Instruction::InstListType::iterator eraseFromParent()
Delegate the call to the underlying SwitchInst::eraseFromParent() and mark this object to not touch t...
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest, CaseWeightOpt W)
Delegate the call to the underlying SwitchInst::addCase() and set the specified branch weight for the...
LLVM_ABI CaseWeightOpt getSuccessorWeight(unsigned idx)
LLVM_ABI void replaceDefaultDest(SwitchInst::CaseIt I)
Replace the default destination by given case.
std::optional< uint32_t > CaseWeightOpt
LLVM_ABI SwitchInst::CaseIt removeCase(SwitchInst::CaseIt I)
Delegate the call to the underlying SwitchInst::removeCase() and remove correspondent branch weight.
void setValue(ConstantInt *V) const
Sets the new value for current case.
void setSuccessor(BasicBlock *S) const
Sets the new successor for current case.
Multiway switch.
void allocHungoffUses(unsigned N)
LLVM_ABI SwitchInst * cloneImpl() const
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
CaseIteratorImpl< CaseHandle > CaseIt
ConstantInt *const * case_values() const
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
LLVM_ABI CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
Target - Wrapper for Target specific information.
This class represents a truncation of integer types.
LLVM_ABI TruncInst * cloneImpl() const
Clone an identical TruncInst.
LLVM_ABI TruncInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:339
static constexpr TypeSize get(ScalarTy Quantity, bool Scalable)
Definition TypeSize.h:336
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isByteTy() const
True if this is an instance of ByteType.
Definition Type.h:237
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSingleValueType() const
Return true if the type is a valid type for a register in codegen.
Definition Type.h:306
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
Definition Type.cpp:241
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:363
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:187
bool isByteOrByteVectorTy() const
Return true if this is a byte type or a vector of byte types.
Definition Type.h:243
bool isTargetExtTy() const
Return true if this is a target extension type.
Definition Type.h:205
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition Type.h:314
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:222
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:296
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:280
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
bool isTokenTy() const
Return true if this is 'token'.
Definition Type.h:231
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition Type.h:222
This class represents a cast unsigned integer to floating point.
LLVM_ABI UIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI UIToFPInst * cloneImpl() const
Clone an identical UIToFPInst.
UnaryInstruction(Type *Ty, unsigned iType, Value *V, InsertPosition InsertBefore=nullptr)
Definition InstrTypes.h:71
static LLVM_ABI UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
LLVM_ABI UnaryOperator(UnaryOps iType, Value *S, Type *Ty, const Twine &Name, InsertPosition InsertBefore)
LLVM_ABI UnaryOperator * cloneImpl() const
UnaryOps getOpcode() const
Definition InstrTypes.h:163
Unconditional Branch instruction.
LLVM_ABI UncondBrInst * cloneImpl() const
LLVM_ABI UnreachableInst(LLVMContext &C, InsertPosition InsertBefore=nullptr)
LLVM_ABI bool shouldLowerToTrap(bool TrapUnreachable, bool NoTrapAfterNoreturn) const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI UnreachableInst * cloneImpl() const
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM_ABI void set(Value *Val)
Definition Value.h:876
Use * op_iterator
Definition User.h:254
const Use * getOperandList() const
Definition User.h:200
op_iterator op_begin()
Definition User.h:259
LLVM_ABI void allocHungoffUses(unsigned N, bool WithExtraValues=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
Definition User.cpp:54
const Use & getOperandUse(unsigned i) const
Definition User.h:220
void setNumHungOffUseOperands(unsigned NumOps)
Subclasses with hung off uses need to manage the operand count themselves.
Definition User.h:240
Use & Op()
Definition User.h:171
LLVM_ABI void growHungoffUses(unsigned N, bool WithExtraValues=false)
Grow the number of hung off uses.
Definition User.cpp:71
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
op_iterator op_end()
Definition User.h:261
VAArgInst(Value *List, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI VAArgInst * cloneImpl() const
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
unsigned char SubclassOptionalData
Hold arbitary subclass data.
Definition Value.h:85
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:394
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
unsigned NumUserOperands
Definition Value.h:109
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:319
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
This class represents zero extension of integer types.
LLVM_ABI ZExtInst(Value *S, Type *Ty, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
LLVM_ABI ZExtInst * cloneImpl() const
Clone an identical ZExtInst.
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:165
An efficient, type-erasing, non-owning reference to a callable.
typename base_list_type::iterator iterator
Definition ilist.h:121
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool match(Val *V, const Pattern &P)
cstfp_pred_ty< is_non_zero_not_denormal_fp > m_NonZeroNotDenormalFP()
Match a floating-point non-zero that is not a denormal.
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
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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:1755
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
unsigned getPointerAddressSpace(const Type *T)
Definition SPIRVUtils.h:393
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr auto seq_inclusive(T Begin, T End)
Iterate over an integral type from Begin to End inclusive.
Definition Sequence.h:361
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
Definition STLExtras.h:2189
std::enable_if_t< std::is_unsigned_v< T >, std::optional< T > > checkedMulUnsigned(T LHS, T RHS)
Multiply two unsigned integers LHS and RHS.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool isPointerTy(const Type *T)
Definition SPIRVUtils.h:381
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
constexpr int PoisonMaskElem
LLVM_ABI unsigned getNumBranchWeights(const MDNode &ProfileData)
AtomicOrdering
Atomic ordering for LLVM's memory model.
LLVM_ABI void extractFromBranchWeightMD32(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Faster version of extractBranchWeights() that skips checks and must only be called with "branch_weigh...
OperandBundleDefT< Value * > OperandBundleDef
Definition AutoUpgrade.h:34
@ Mul
Product of integers.
@ FSub
Subtraction of floats.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1901
constexpr unsigned BitWidth
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
bool capturesAnything(CaptureComponents CC)
Definition ModRef.h:379
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2182
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:267
LLVM_ABI void scaleProfData(Instruction &I, uint64_t S, uint64_t T)
Scaling the profile data attached to 'I' using the ratio of S/T.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Summary of memprof metadata on allocations.
Used to keep track of an operand bundle.
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
static LLVM_ABI std::optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
static LLVM_ABI std::optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
static LLVM_ABI std::optional< bool > sge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGE result.
static LLVM_ABI std::optional< bool > ugt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGT result.
static LLVM_ABI std::optional< bool > slt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLT result.
static LLVM_ABI std::optional< bool > ult(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULT result.
static LLVM_ABI std::optional< bool > ule(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULE result.
static LLVM_ABI std::optional< bool > sle(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLE result.
static LLVM_ABI std::optional< bool > sgt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGT result.
static LLVM_ABI std::optional< bool > uge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGE result.
A structure representing the properties of a load or store instruction.
Matching combinators.
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:342
Indicates this User has operands co-allocated.
Definition User.h:60
Indicates this User has operands and a descriptor co-allocated .
Definition User.h:66