Movatterモバイル変換


[0]ホーム

URL:


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

Generated on Thu Jul 17 2025 12:30:07 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp