LLVM  15.0.0git
Constants.cpp
Go to the documentation of this file.
1 //===-- Constants.cpp - Implement Constant nodes --------------------------===//
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 the Constant* classes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/IR/Constants.h"
14 #include "LLVMContextImpl.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/IR/BasicBlock.h"
19 #include "llvm/IR/ConstantFold.h"
20 #include "llvm/IR/DerivedTypes.h"
21 #include "llvm/IR/Function.h"
23 #include "llvm/IR/GlobalAlias.h"
24 #include "llvm/IR/GlobalIFunc.h"
25 #include "llvm/IR/GlobalValue.h"
26 #include "llvm/IR/GlobalVariable.h"
27 #include "llvm/IR/Instructions.h"
28 #include "llvm/IR/Operator.h"
29 #include "llvm/IR/PatternMatch.h"
33 #include <algorithm>
34 
35 using namespace llvm;
36 using namespace PatternMatch;
37 
38 //===----------------------------------------------------------------------===//
39 // Constant Class
40 //===----------------------------------------------------------------------===//
41 
43  // Floating point values have an explicit -0.0 value.
44  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
45  return CFP->isZero() && CFP->isNegative();
46 
47  // Equivalent for a vector of -0.0's.
48  if (getType()->isVectorTy())
49  if (const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(getSplatValue()))
50  return SplatCFP->isNegativeZeroValue();
51 
52  // We've already handled true FP case; any other FP vectors can't represent -0.0.
53  if (getType()->isFPOrFPVectorTy())
54  return false;
55 
56  // Otherwise, just use +0.0.
57  return isNullValue();
58 }
59 
60 // Return true iff this constant is positive zero (floating point), negative
61 // zero (floating point), or a null value.
62 bool Constant::isZeroValue() const {
63  // Floating point values have an explicit -0.0 value.
64  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
65  return CFP->isZero();
66 
67  // Check for constant splat vectors of 1 values.
68  if (getType()->isVectorTy())
69  if (const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(getSplatValue()))
70  return SplatCFP->isZero();
71 
72  // Otherwise, just use +0.0.
73  return isNullValue();
74 }
75 
76 bool Constant::isNullValue() const {
77  // 0 is null.
78  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
79  return CI->isZero();
80 
81  // +0.0 is null.
82  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
83  // ppc_fp128 determine isZero using high order double only
84  // Should check the bitwise value to make sure all bits are zero.
85  return CFP->isExactlyValue(+0.0);
86 
87  // constant zero is zero for aggregates, cpnull is null for pointers, none for
88  // tokens.
89  return isa<ConstantAggregateZero>(this) || isa<ConstantPointerNull>(this) ||
90  isa<ConstantTokenNone>(this);
91 }
92 
94  // Check for -1 integers
95  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
96  return CI->isMinusOne();
97 
98  // Check for FP which are bitcasted from -1 integers
99  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
100  return CFP->getValueAPF().bitcastToAPInt().isAllOnes();
101 
102  // Check for constant splat vectors of 1 values.
103  if (getType()->isVectorTy())
104  if (const auto *SplatVal = getSplatValue())
105  return SplatVal->isAllOnesValue();
106 
107  return false;
108 }
109 
110 bool Constant::isOneValue() const {
111  // Check for 1 integers
112  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
113  return CI->isOne();
114 
115  // Check for FP which are bitcasted from 1 integers
116  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
117  return CFP->getValueAPF().bitcastToAPInt().isOne();
118 
119  // Check for constant splat vectors of 1 values.
120  if (getType()->isVectorTy())
121  if (const auto *SplatVal = getSplatValue())
122  return SplatVal->isOneValue();
123 
124  return false;
125 }
126 
128  // Check for 1 integers
129  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
130  return !CI->isOneValue();
131 
132  // Check for FP which are bitcasted from 1 integers
133  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
134  return !CFP->getValueAPF().bitcastToAPInt().isOne();
135 
136  // Check that vectors don't contain 1
137  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
138  for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
139  Constant *Elt = getAggregateElement(I);
140  if (!Elt || !Elt->isNotOneValue())
141  return false;
142  }
143  return true;
144  }
145 
146  // Check for splats that don't contain 1
147  if (getType()->isVectorTy())
148  if (const auto *SplatVal = getSplatValue())
149  return SplatVal->isNotOneValue();
150 
151  // It *may* contain 1, we can't tell.
152  return false;
153 }
154 
156  // Check for INT_MIN integers
157  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
158  return CI->isMinValue(/*isSigned=*/true);
159 
160  // Check for FP which are bitcasted from INT_MIN integers
161  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
162  return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
163 
164  // Check for splats of INT_MIN values.
165  if (getType()->isVectorTy())
166  if (const auto *SplatVal = getSplatValue())
167  return SplatVal->isMinSignedValue();
168 
169  return false;
170 }
171 
173  // Check for INT_MIN integers
174  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
175  return !CI->isMinValue(/*isSigned=*/true);
176 
177  // Check for FP which are bitcasted from INT_MIN integers
178  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
179  return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
180 
181  // Check that vectors don't contain INT_MIN
182  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
183  for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
184  Constant *Elt = getAggregateElement(I);
185  if (!Elt || !Elt->isNotMinSignedValue())
186  return false;
187  }
188  return true;
189  }
190 
191  // Check for splats that aren't INT_MIN
192  if (getType()->isVectorTy())
193  if (const auto *SplatVal = getSplatValue())
194  return SplatVal->isNotMinSignedValue();
195 
196  // It *may* contain INT_MIN, we can't tell.
197  return false;
198 }
199 
201  if (auto *CFP = dyn_cast<ConstantFP>(this))
202  return CFP->getValueAPF().isFiniteNonZero();
203 
204  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
205  for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
206  auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(I));
207  if (!CFP || !CFP->getValueAPF().isFiniteNonZero())
208  return false;
209  }
210  return true;
211  }
212 
213  if (getType()->isVectorTy())
214  if (const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(getSplatValue()))
215  return SplatCFP->isFiniteNonZeroFP();
216 
217  // It *may* contain finite non-zero, we can't tell.
218  return false;
219 }
220 
221 bool Constant::isNormalFP() const {
222  if (auto *CFP = dyn_cast<ConstantFP>(this))
223  return CFP->getValueAPF().isNormal();
224 
225  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
226  for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
227  auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(I));
228  if (!CFP || !CFP->getValueAPF().isNormal())
229  return false;
230  }
231  return true;
232  }
233 
234  if (getType()->isVectorTy())
235  if (const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(getSplatValue()))
236  return SplatCFP->isNormalFP();
237 
238  // It *may* contain a normal fp value, we can't tell.
239  return false;
240 }
241 
243  if (auto *CFP = dyn_cast<ConstantFP>(this))
244  return CFP->getValueAPF().getExactInverse(nullptr);
245 
246  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
247  for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
248  auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(I));
249  if (!CFP || !CFP->getValueAPF().getExactInverse(nullptr))
250  return false;
251  }
252  return true;
253  }
254 
255  if (getType()->isVectorTy())
256  if (const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(getSplatValue()))
257  return SplatCFP->hasExactInverseFP();
258 
259  // It *may* have an exact inverse fp value, we can't tell.
260  return false;
261 }
262 
263 bool Constant::isNaN() const {
264  if (auto *CFP = dyn_cast<ConstantFP>(this))
265  return CFP->isNaN();
266 
267  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
268  for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
269  auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(I));
270  if (!CFP || !CFP->isNaN())
271  return false;
272  }
273  return true;
274  }
275 
276  if (getType()->isVectorTy())
277  if (const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(getSplatValue()))
278  return SplatCFP->isNaN();
279 
280  // It *may* be NaN, we can't tell.
281  return false;
282 }
283 
285  // Are they fully identical?
286  if (this == Y)
287  return true;
288 
289  // The input value must be a vector constant with the same type.
290  auto *VTy = dyn_cast<VectorType>(getType());
291  if (!isa<Constant>(Y) || !VTy || VTy != Y->getType())
292  return false;
293 
294  // TODO: Compare pointer constants?
295  if (!(VTy->getElementType()->isIntegerTy() ||
296  VTy->getElementType()->isFloatingPointTy()))
297  return false;
298 
299  // They may still be identical element-wise (if they have `undef`s).
300  // Bitcast to integer to allow exact bitwise comparison for all types.
301  Type *IntTy = VectorType::getInteger(VTy);
302  Constant *C0 = ConstantExpr::getBitCast(const_cast<Constant *>(this), IntTy);
303  Constant *C1 = ConstantExpr::getBitCast(cast<Constant>(Y), IntTy);
305  return isa<UndefValue>(CmpEq) || match(CmpEq, m_One());
306 }
307 
308 static bool
310  function_ref<bool(const Constant *)> HasFn) {
311  if (auto *VTy = dyn_cast<VectorType>(C->getType())) {
312  if (HasFn(C))
313  return true;
314  if (isa<ConstantAggregateZero>(C))
315  return false;
316  if (isa<ScalableVectorType>(C->getType()))
317  return false;
318 
319  for (unsigned i = 0, e = cast<FixedVectorType>(VTy)->getNumElements();
320  i != e; ++i) {
321  if (Constant *Elem = C->getAggregateElement(i))
322  if (HasFn(Elem))
323  return true;
324  }
325  }
326 
327  return false;
328 }
329 
332  this, [&](const auto *C) { return isa<UndefValue>(C); });
333 }
334 
337  this, [&](const auto *C) { return isa<PoisonValue>(C); });
338 }
339 
341  if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
342  for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
343  if (isa<ConstantExpr>(getAggregateElement(i)))
344  return true;
345  }
346  return false;
347 }
348 
349 /// Constructor to create a '0' constant of arbitrary type.
351  switch (Ty->getTypeID()) {
352  case Type::IntegerTyID:
353  return ConstantInt::get(Ty, 0);
354  case Type::HalfTyID:
355  case Type::BFloatTyID:
356  case Type::FloatTyID:
357  case Type::DoubleTyID:
358  case Type::X86_FP80TyID:
359  case Type::FP128TyID:
360  case Type::PPC_FP128TyID:
361  return ConstantFP::get(Ty->getContext(),
363  case Type::PointerTyID:
364  return ConstantPointerNull::get(cast<PointerType>(Ty));
365  case Type::StructTyID:
366  case Type::ArrayTyID:
369  return ConstantAggregateZero::get(Ty);
370  case Type::TokenTyID:
371  return ConstantTokenNone::get(Ty->getContext());
372  default:
373  // Function, Label, or Opaque type?
374  llvm_unreachable("Cannot create a null constant of that type!");
375  }
376 }
377 
379  Type *ScalarTy = Ty->getScalarType();
380 
381  // Create the base integer constant.
382  Constant *C = ConstantInt::get(Ty->getContext(), V);
383 
384  // Convert an integer to a pointer, if necessary.
385  if (PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
386  C = ConstantExpr::getIntToPtr(C, PTy);
387 
388  // Broadcast a scalar to a vector, if necessary.
389  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
390  C = ConstantVector::getSplat(VTy->getElementCount(), C);
391 
392  return C;
393 }
394 
396  if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
397  return ConstantInt::get(Ty->getContext(),
398  APInt::getAllOnes(ITy->getBitWidth()));
399 
400  if (Ty->isFloatingPointTy()) {
402  return ConstantFP::get(Ty->getContext(), FL);
403  }
404 
405  VectorType *VTy = cast<VectorType>(Ty);
407  getAllOnesValue(VTy->getElementType()));
408 }
409 
411  assert((getType()->isAggregateType() || getType()->isVectorTy()) &&
412  "Must be an aggregate/vector constant");
413 
414  if (const auto *CC = dyn_cast<ConstantAggregate>(this))
415  return Elt < CC->getNumOperands() ? CC->getOperand(Elt) : nullptr;
416 
417  if (const auto *CAZ = dyn_cast<ConstantAggregateZero>(this))
418  return Elt < CAZ->getElementCount().getKnownMinValue()
419  ? CAZ->getElementValue(Elt)
420  : nullptr;
421 
422  // FIXME: getNumElements() will fail for non-fixed vector types.
423  if (isa<ScalableVectorType>(getType()))
424  return nullptr;
425 
426  if (const auto *PV = dyn_cast<PoisonValue>(this))
427  return Elt < PV->getNumElements() ? PV->getElementValue(Elt) : nullptr;
428 
429  if (const auto *UV = dyn_cast<UndefValue>(this))
430  return Elt < UV->getNumElements() ? UV->getElementValue(Elt) : nullptr;
431 
432  if (const auto *CDS = dyn_cast<ConstantDataSequential>(this))
433  return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
434  : nullptr;
435 
436  return nullptr;
437 }
438 
440  assert(isa<IntegerType>(Elt->getType()) && "Index must be an integer");
441  if (ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) {
442  // Check if the constant fits into an uint64_t.
443  if (CI->getValue().getActiveBits() > 64)
444  return nullptr;
445  return getAggregateElement(CI->getZExtValue());
446  }
447  return nullptr;
448 }
449 
451  /// First call destroyConstantImpl on the subclass. This gives the subclass
452  /// a chance to remove the constant from any maps/pools it's contained in.
453  switch (getValueID()) {
454  default:
455  llvm_unreachable("Not a constant!");
456 #define HANDLE_CONSTANT(Name) \
457  case Value::Name##Val: \
458  cast<Name>(this)->destroyConstantImpl(); \
459  break;
460 #include "llvm/IR/Value.def"
461  }
462 
463  // When a Constant is destroyed, there may be lingering
464  // references to the constant by other constants in the constant pool. These
465  // constants are implicitly dependent on the module that is being deleted,
466  // but they don't know that. Because we only find out when the CPV is
467  // deleted, we must now notify all of our users (that should only be
468  // Constants) that they are, in fact, invalid now and should be deleted.
469  //
470  while (!use_empty()) {
471  Value *V = user_back();
472 #ifndef NDEBUG // Only in -g mode...
473  if (!isa<Constant>(V)) {
474  dbgs() << "While deleting: " << *this
475  << "\n\nUse still stuck around after Def is destroyed: " << *V
476  << "\n\n";
477  }
478 #endif
479  assert(isa<Constant>(V) && "References remain to Constant being destroyed");
480  cast<Constant>(V)->destroyConstant();
481 
482  // The constant should remove itself from our use list...
483  assert((use_empty() || user_back() != V) && "Constant not removed!");
484  }
485 
486  // Value has no outstanding references it is safe to delete it now...
487  deleteConstant(this);
488 }
489 
491  switch (C->getValueID()) {
492  case Constant::ConstantIntVal:
493  delete static_cast<ConstantInt *>(C);
494  break;
495  case Constant::ConstantFPVal:
496  delete static_cast<ConstantFP *>(C);
497  break;
498  case Constant::ConstantAggregateZeroVal:
499  delete static_cast<ConstantAggregateZero *>(C);
500  break;
501  case Constant::ConstantArrayVal:
502  delete static_cast<ConstantArray *>(C);
503  break;
504  case Constant::ConstantStructVal:
505  delete static_cast<ConstantStruct *>(C);
506  break;
507  case Constant::ConstantVectorVal:
508  delete static_cast<ConstantVector *>(C);
509  break;
510  case Constant::ConstantPointerNullVal:
511  delete static_cast<ConstantPointerNull *>(C);
512  break;
513  case Constant::ConstantDataArrayVal:
514  delete static_cast<ConstantDataArray *>(C);
515  break;
516  case Constant::ConstantDataVectorVal:
517  delete static_cast<ConstantDataVector *>(C);
518  break;
519  case Constant::ConstantTokenNoneVal:
520  delete static_cast<ConstantTokenNone *>(C);
521  break;
522  case Constant::BlockAddressVal:
523  delete static_cast<BlockAddress *>(C);
524  break;
525  case Constant::DSOLocalEquivalentVal:
526  delete static_cast<DSOLocalEquivalent *>(C);
527  break;
528  case Constant::NoCFIValueVal:
529  delete static_cast<NoCFIValue *>(C);
530  break;
531  case Constant::UndefValueVal:
532  delete static_cast<UndefValue *>(C);
533  break;
534  case Constant::PoisonValueVal:
535  delete static_cast<PoisonValue *>(C);
536  break;
537  case Constant::ConstantExprVal:
538  if (isa<UnaryConstantExpr>(C))
539  delete static_cast<UnaryConstantExpr *>(C);
540  else if (isa<BinaryConstantExpr>(C))
541  delete static_cast<BinaryConstantExpr *>(C);
542  else if (isa<SelectConstantExpr>(C))
543  delete static_cast<SelectConstantExpr *>(C);
544  else if (isa<ExtractElementConstantExpr>(C))
545  delete static_cast<ExtractElementConstantExpr *>(C);
546  else if (isa<InsertElementConstantExpr>(C))
547  delete static_cast<InsertElementConstantExpr *>(C);
548  else if (isa<ShuffleVectorConstantExpr>(C))
549  delete static_cast<ShuffleVectorConstantExpr *>(C);
550  else if (isa<InsertValueConstantExpr>(C))
551  delete static_cast<InsertValueConstantExpr *>(C);
552  else if (isa<GetElementPtrConstantExpr>(C))
553  delete static_cast<GetElementPtrConstantExpr *>(C);
554  else if (isa<CompareConstantExpr>(C))
555  delete static_cast<CompareConstantExpr *>(C);
556  else
557  llvm_unreachable("Unexpected constant expr");
558  break;
559  default:
560  llvm_unreachable("Unexpected constant");
561  }
562 }
563 
564 static bool canTrapImpl(const Constant *C,
565  SmallPtrSetImpl<const Constant *> &NonTrappingOps) {
566  assert(C->getType()->isFirstClassType() &&
567  "Cannot evaluate non-first-class types!");
568  // ConstantExpr or ConstantAggregate trap if any operands can trap.
569  if (isa<ConstantExpr>(C) || isa<ConstantAggregate>(C)) {
570  for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
571  const Constant *Op = cast<Constant>(C->getOperand(i));
572  if (isa<ConstantExpr>(Op) || isa<ConstantAggregate>(Op)) {
573  if (NonTrappingOps.insert(Op).second && canTrapImpl(Op, NonTrappingOps))
574  return true;
575  }
576  }
577  }
578 
579  // The only leafs that can trap are constant expressions.
580  const ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
581  if (!CE)
582  return false;
583 
584  // Otherwise, only specific operations can trap.
585  switch (CE->getOpcode()) {
586  default:
587  return false;
588  case Instruction::SDiv:
589  case Instruction::SRem:
590  // Signed div/rem can trap for SignedMin / -1.
591  if (!CE->getOperand(0)->isNotMinSignedValue() &&
592  (!isa<ConstantInt>(CE->getOperand(1)) ||
593  CE->getOperand(1)->isAllOnesValue()))
594  return true;
596  case Instruction::UDiv:
597  case Instruction::URem:
598  // Div and rem can trap if the RHS is not known to be non-zero.
599  return !isa<ConstantInt>(CE->getOperand(1)) ||
600  CE->getOperand(1)->isNullValue();
601  }
602 }
603 
604 bool Constant::canTrap() const {
605  SmallPtrSet<const Constant *, 4> NonTrappingOps;
606  return canTrapImpl(this, NonTrappingOps);
607 }
608 
609 /// Check if C contains a GlobalValue for which Predicate is true.
610 static bool
612  bool (*Predicate)(const GlobalValue *)) {
615  WorkList.push_back(C);
616  Visited.insert(C);
617 
618  while (!WorkList.empty()) {
619  const Constant *WorkItem = WorkList.pop_back_val();
620  if (const auto *GV = dyn_cast<GlobalValue>(WorkItem))
621  if (Predicate(GV))
622  return true;
623  for (const Value *Op : WorkItem->operands()) {
624  const Constant *ConstOp = dyn_cast<Constant>(Op);
625  if (!ConstOp)
626  continue;
627  if (Visited.insert(ConstOp).second)
628  WorkList.push_back(ConstOp);
629  }
630  }
631  return false;
632 }
633 
635  auto DLLImportPredicate = [](const GlobalValue *GV) {
636  return GV->isThreadLocal();
637  };
638  return ConstHasGlobalValuePredicate(this, DLLImportPredicate);
639 }
640 
642  auto DLLImportPredicate = [](const GlobalValue *GV) {
643  return GV->hasDLLImportStorageClass();
644  };
645  return ConstHasGlobalValuePredicate(this, DLLImportPredicate);
646 }
647 
649  for (const User *U : users()) {
650  const Constant *UC = dyn_cast<Constant>(U);
651  if (!UC || isa<GlobalValue>(UC))
652  return true;
653 
654  if (UC->isConstantUsed())
655  return true;
656  }
657  return false;
658 }
659 
661  return getRelocationInfo() == GlobalRelocation;
662 }
663 
665  return getRelocationInfo() != NoRelocation;
666 }
667 
668 Constant::PossibleRelocationsTy Constant::getRelocationInfo() const {
669  if (isa<GlobalValue>(this))
670  return GlobalRelocation; // Global reference.
671 
672  if (const BlockAddress *BA = dyn_cast<BlockAddress>(this))
673  return BA->getFunction()->getRelocationInfo();
674 
675  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) {
676  if (CE->getOpcode() == Instruction::Sub) {
677  ConstantExpr *LHS = dyn_cast<ConstantExpr>(CE->getOperand(0));
678  ConstantExpr *RHS = dyn_cast<ConstantExpr>(CE->getOperand(1));
679  if (LHS && RHS && LHS->getOpcode() == Instruction::PtrToInt &&
680  RHS->getOpcode() == Instruction::PtrToInt) {
681  Constant *LHSOp0 = LHS->getOperand(0);
682  Constant *RHSOp0 = RHS->getOperand(0);
683 
684  // While raw uses of blockaddress need to be relocated, differences
685  // between two of them don't when they are for labels in the same
686  // function. This is a common idiom when creating a table for the
687  // indirect goto extension, so we handle it efficiently here.
688  if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
689  cast<BlockAddress>(LHSOp0)->getFunction() ==
690  cast<BlockAddress>(RHSOp0)->getFunction())
691  return NoRelocation;
692 
693  // Relative pointers do not need to be dynamically relocated.
694  if (auto *RHSGV =
695  dyn_cast<GlobalValue>(RHSOp0->stripInBoundsConstantOffsets())) {
696  auto *LHS = LHSOp0->stripInBoundsConstantOffsets();
697  if (auto *LHSGV = dyn_cast<GlobalValue>(LHS)) {
698  if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
699  return LocalRelocation;
700  } else if (isa<DSOLocalEquivalent>(LHS)) {
701  if (RHSGV->isDSOLocal())
702  return LocalRelocation;
703  }
704  }
705  }
706  }
707  }
708 
709  PossibleRelocationsTy Result = NoRelocation;
710  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
711  Result =
712  std::max(cast<Constant>(getOperand(i))->getRelocationInfo(), Result);
713 
714  return Result;
715 }
716 
717 /// Return true if the specified constantexpr is dead. This involves
718 /// recursively traversing users of the constantexpr.
719 /// If RemoveDeadUsers is true, also remove dead users at the same time.
720 static bool constantIsDead(const Constant *C, bool RemoveDeadUsers) {
721  if (isa<GlobalValue>(C)) return false; // Cannot remove this
722 
723  Value::const_user_iterator I = C->user_begin(), E = C->user_end();
724  while (I != E) {
725  const Constant *User = dyn_cast<Constant>(*I);
726  if (!User) return false; // Non-constant usage;
727  if (!constantIsDead(User, RemoveDeadUsers))
728  return false; // Constant wasn't dead
729 
730  // Just removed User, so the iterator was invalidated.
731  // Since we return immediately upon finding a live user, we can always
732  // restart from user_begin().
733  if (RemoveDeadUsers)
734  I = C->user_begin();
735  else
736  ++I;
737  }
738 
739  if (RemoveDeadUsers) {
740  // If C is only used by metadata, it should not be preserved but should
741  // have its uses replaced.
743  const_cast<Constant *>(C)->destroyConstant();
744  }
745 
746  return true;
747 }
748 
750  Value::const_user_iterator I = user_begin(), E = user_end();
751  Value::const_user_iterator LastNonDeadUser = E;
752  while (I != E) {
753  const Constant *User = dyn_cast<Constant>(*I);
754  if (!User) {
755  LastNonDeadUser = I;
756  ++I;
757  continue;
758  }
759 
760  if (!constantIsDead(User, /* RemoveDeadUsers= */ true)) {
761  // If the constant wasn't dead, remember that this was the last live use
762  // and move on to the next constant.
763  LastNonDeadUser = I;
764  ++I;
765  continue;
766  }
767 
768  // If the constant was dead, then the iterator is invalidated.
769  if (LastNonDeadUser == E)
770  I = user_begin();
771  else
772  I = std::next(LastNonDeadUser);
773  }
774 }
775 
776 bool Constant::hasOneLiveUse() const { return hasNLiveUses(1); }
777 
778 bool Constant::hasZeroLiveUses() const { return hasNLiveUses(0); }
779 
780 bool Constant::hasNLiveUses(unsigned N) const {
781  unsigned NumUses = 0;
782  for (const Use &U : uses()) {
783  const Constant *User = dyn_cast<Constant>(U.getUser());
784  if (!User || !constantIsDead(User, /* RemoveDeadUsers= */ false)) {
785  ++NumUses;
786 
787  if (NumUses > N)
788  return false;
789  }
790  }
791  return NumUses == N;
792 }
793 
795  assert(C && Replacement && "Expected non-nullptr constant arguments");
796  Type *Ty = C->getType();
797  if (match(C, m_Undef())) {
798  assert(Ty == Replacement->getType() && "Expected matching types");
799  return Replacement;
800  }
801 
802  // Don't know how to deal with this constant.
803  auto *VTy = dyn_cast<FixedVectorType>(Ty);
804  if (!VTy)
805  return C;
806 
807  unsigned NumElts = VTy->getNumElements();
808  SmallVector<Constant *, 32> NewC(NumElts);
809  for (unsigned i = 0; i != NumElts; ++i) {
810  Constant *EltC = C->getAggregateElement(i);
811  assert((!EltC || EltC->getType() == Replacement->getType()) &&
812  "Expected matching types");
813  NewC[i] = EltC && match(EltC, m_Undef()) ? Replacement : EltC;
814  }
815  return ConstantVector::get(NewC);
816 }
817 
819  assert(C && Other && "Expected non-nullptr constant arguments");
820  if (match(C, m_Undef()))
821  return C;
822 
823  Type *Ty = C->getType();
824  if (match(Other, m_Undef()))
825  return UndefValue::get(Ty);
826 
827  auto *VTy = dyn_cast<FixedVectorType>(Ty);
828  if (!VTy)
829  return C;
830 
831  Type *EltTy = VTy->getElementType();
832  unsigned NumElts = VTy->getNumElements();
833  assert(isa<FixedVectorType>(Other->getType()) &&
834  cast<FixedVectorType>(Other->getType())->getNumElements() == NumElts &&
835  "Type mismatch");
836 
837  bool FoundExtraUndef = false;
838  SmallVector<Constant *, 32> NewC(NumElts);
839  for (unsigned I = 0; I != NumElts; ++I) {
840  NewC[I] = C->getAggregateElement(I);
841  Constant *OtherEltC = Other->getAggregateElement(I);
842  assert(NewC[I] && OtherEltC && "Unknown vector element");
843  if (!match(NewC[I], m_Undef()) && match(OtherEltC, m_Undef())) {
844  NewC[I] = UndefValue::get(EltTy);
845  FoundExtraUndef = true;
846  }
847  }
848  if (FoundExtraUndef)
849  return ConstantVector::get(NewC);
850  return C;
851 }
852 
854  if (isa<ConstantData>(this))
855  return true;
856  if (isa<ConstantAggregate>(this) || isa<ConstantExpr>(this)) {
857  for (const Value *Op : operand_values())
858  if (!cast<Constant>(Op)->isManifestConstant())
859  return false;
860  return true;
861  }
862  return false;
863 }
864 
865 //===----------------------------------------------------------------------===//
866 // ConstantInt
867 //===----------------------------------------------------------------------===//
868 
869 ConstantInt::ConstantInt(IntegerType *Ty, const APInt &V)
870  : ConstantData(Ty, ConstantIntVal), Val(V) {
871  assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
872 }
873 
875  LLVMContextImpl *pImpl = Context.pImpl;
876  if (!pImpl->TheTrueVal)
878  return pImpl->TheTrueVal;
879 }
880 
882  LLVMContextImpl *pImpl = Context.pImpl;
883  if (!pImpl->TheFalseVal)
885  return pImpl->TheFalseVal;
886 }
887 
889  return V ? getTrue(Context) : getFalse(Context);
890 }
891 
893  assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
895  if (auto *VTy = dyn_cast<VectorType>(Ty))
896  return ConstantVector::getSplat(VTy->getElementCount(), TrueC);
897  return TrueC;
898 }
899 
901  assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
903  if (auto *VTy = dyn_cast<VectorType>(Ty))
904  return ConstantVector::getSplat(VTy->getElementCount(), FalseC);
905  return FalseC;
906 }
907 
909  return V ? getTrue(Ty) : getFalse(Ty);
910 }
911 
912 // Get a ConstantInt from an APInt.
914  // get an existing value or the insertion position
915  LLVMContextImpl *pImpl = Context.pImpl;
916  std::unique_ptr<ConstantInt> &Slot = pImpl->IntConstants[V];
917  if (!Slot) {
918  // Get the corresponding integer type for the bit width of the value.
920  Slot.reset(new ConstantInt(ITy, V));
921  }
922  assert(Slot->getType() == IntegerType::get(Context, V.getBitWidth()));
923  return Slot.get();
924 }
925 
926 Constant *ConstantInt::get(Type *Ty, uint64_t V, bool isSigned) {
927  Constant *C = get(cast<IntegerType>(Ty->getScalarType()), V, isSigned);
928 
929  // For vectors, broadcast the value.
930  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
931  return ConstantVector::getSplat(VTy->getElementCount(), C);
932 
933  return C;
934 }
935 
937  return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned));
938 }
939 
941  return get(Ty, V, true);
942 }
943 
945  return get(Ty, V, true);
946 }
947 
949  ConstantInt *C = get(Ty->getContext(), V);
950  assert(C->getType() == Ty->getScalarType() &&
951  "ConstantInt type doesn't match the type implied by its value!");
952 
953  // For vectors, broadcast the value.
954  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
955  return ConstantVector::getSplat(VTy->getElementCount(), C);
956 
957  return C;
958 }
959 
961  return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
962 }
963 
964 /// Remove the constant from the constant table.
965 void ConstantInt::destroyConstantImpl() {
966  llvm_unreachable("You can't ConstantInt->destroyConstantImpl()!");
967 }
968 
969 //===----------------------------------------------------------------------===//
970 // ConstantFP
971 //===----------------------------------------------------------------------===//
972 
973 Constant *ConstantFP::get(Type *Ty, double V) {
974  LLVMContext &Context = Ty->getContext();
975 
976  APFloat FV(V);
977  bool ignored;
979  APFloat::rmNearestTiesToEven, &ignored);
980  Constant *C = get(Context, FV);
981 
982  // For vectors, broadcast the value.
983  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
984  return ConstantVector::getSplat(VTy->getElementCount(), C);
985 
986  return C;
987 }
988 
990  ConstantFP *C = get(Ty->getContext(), V);
991  assert(C->getType() == Ty->getScalarType() &&
992  "ConstantFP type doesn't match the type implied by its value!");
993 
994  // For vectors, broadcast the value.
995  if (auto *VTy = dyn_cast<VectorType>(Ty))
996  return ConstantVector::getSplat(VTy->getElementCount(), C);
997 
998  return C;
999 }
1000 
1002  LLVMContext &Context = Ty->getContext();
1003 
1004  APFloat FV(Ty->getScalarType()->getFltSemantics(), Str);
1005  Constant *C = get(Context, FV);
1006 
1007  // For vectors, broadcast the value.
1008  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1009  return ConstantVector::getSplat(VTy->getElementCount(), C);
1010 
1011  return C;
1012 }
1013 
1014 Constant *ConstantFP::getNaN(Type *Ty, bool Negative, uint64_t Payload) {
1015  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1016  APFloat NaN = APFloat::getNaN(Semantics, Negative, Payload);
1017  Constant *C = get(Ty->getContext(), NaN);
1018 
1019  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1020  return ConstantVector::getSplat(VTy->getElementCount(), C);
1021 
1022  return C;
1023 }
1024 
1025 Constant *ConstantFP::getQNaN(Type *Ty, bool Negative, APInt *Payload) {
1026  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1027  APFloat NaN = APFloat::getQNaN(Semantics, Negative, Payload);
1028  Constant *C = get(Ty->getContext(), NaN);
1029 
1030  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1031  return ConstantVector::getSplat(VTy->getElementCount(), C);
1032 
1033  return C;
1034 }
1035 
1036 Constant *ConstantFP::getSNaN(Type *Ty, bool Negative, APInt *Payload) {
1037  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1038  APFloat NaN = APFloat::getSNaN(Semantics, Negative, Payload);
1039  Constant *C = get(Ty->getContext(), NaN);
1040 
1041  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1042  return ConstantVector::getSplat(VTy->getElementCount(), C);
1043 
1044  return C;
1045 }
1046 
1047 Constant *ConstantFP::getZero(Type *Ty, bool Negative) {
1048  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1049  APFloat NegZero = APFloat::getZero(Semantics, Negative);
1050  Constant *C = get(Ty->getContext(), NegZero);
1051 
1052  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1053  return ConstantVector::getSplat(VTy->getElementCount(), C);
1054 
1055  return C;
1056 }
1057 
1059  if (Ty->isFPOrFPVectorTy())
1060  return getNegativeZero(Ty);
1061 
1062  return Constant::getNullValue(Ty);
1063 }
1064 
1065 
1066 // ConstantFP accessors.
1068  LLVMContextImpl* pImpl = Context.pImpl;
1069 
1070  std::unique_ptr<ConstantFP> &Slot = pImpl->FPConstants[V];
1071 
1072  if (!Slot) {
1074  Slot.reset(new ConstantFP(Ty, V));
1075  }
1076 
1077  return Slot.get();
1078 }
1079 
1080 Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) {
1081  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1082  Constant *C = get(Ty->getContext(), APFloat::getInf(Semantics, Negative));
1083 
1084  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1085  return ConstantVector::getSplat(VTy->getElementCount(), C);
1086 
1087  return C;
1088 }
1089 
1090 ConstantFP::ConstantFP(Type *Ty, const APFloat &V)
1091  : ConstantData(Ty, ConstantFPVal), Val(V) {
1092  assert(&V.getSemantics() == &Ty->getFltSemantics() &&
1093  "FP type Mismatch");
1094 }
1095 
1096 bool ConstantFP::isExactlyValue(const APFloat &V) const {
1097  return Val.bitwiseIsEqual(V);
1098 }
1099 
1100 /// Remove the constant from the constant table.
1101 void ConstantFP::destroyConstantImpl() {
1102  llvm_unreachable("You can't ConstantFP->destroyConstantImpl()!");
1103 }
1104 
1105 //===----------------------------------------------------------------------===//
1106 // ConstantAggregateZero Implementation
1107 //===----------------------------------------------------------------------===//
1108 
1110  if (auto *AT = dyn_cast<ArrayType>(getType()))
1111  return Constant::getNullValue(AT->getElementType());
1112  return Constant::getNullValue(cast<VectorType>(getType())->getElementType());
1113 }
1114 
1116  return Constant::getNullValue(getType()->getStructElementType(Elt));
1117 }
1118 
1120  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1121  return getSequentialElement();
1122  return getStructElement(cast<ConstantInt>(C)->getZExtValue());
1123 }
1124 
1126  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1127  return getSequentialElement();
1128  return getStructElement(Idx);
1129 }
1130 
1132  Type *Ty = getType();
1133  if (auto *AT = dyn_cast<ArrayType>(Ty))
1134  return ElementCount::getFixed(AT->getNumElements());
1135  if (auto *VT = dyn_cast<VectorType>(Ty))
1136  return VT->getElementCount();
1138 }
1139 
1140 //===----------------------------------------------------------------------===//
1141 // UndefValue Implementation
1142 //===----------------------------------------------------------------------===//
1143 
1145  if (ArrayType *ATy = dyn_cast<ArrayType>(getType()))
1146  return UndefValue::get(ATy->getElementType());
1147  return UndefValue::get(cast<VectorType>(getType())->getElementType());
1148 }
1149 
1151  return UndefValue::get(getType()->getStructElementType(Elt));
1152 }
1153 
1155  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1156  return getSequentialElement();
1157  return getStructElement(cast<ConstantInt>(C)->getZExtValue());
1158 }
1159 
1161  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1162  return getSequentialElement();
1163  return getStructElement(Idx);
1164 }
1165 
1166 unsigned UndefValue::getNumElements() const {
1167  Type *Ty = getType();
1168  if (auto *AT = dyn_cast<ArrayType>(Ty))
1169  return AT->getNumElements();
1170  if (auto *VT = dyn_cast<VectorType>(Ty))
1171  return cast<FixedVectorType>(VT)->getNumElements();
1172  return Ty->getStructNumElements();
1173 }
1174 
1175 //===----------------------------------------------------------------------===//
1176 // PoisonValue Implementation
1177 //===----------------------------------------------------------------------===//
1178 
1180  if (ArrayType *ATy = dyn_cast<ArrayType>(getType()))
1181  return PoisonValue::get(ATy->getElementType());
1182  return PoisonValue::get(cast<VectorType>(getType())->getElementType());
1183 }
1184 
1186  return PoisonValue::get(getType()->getStructElementType(Elt));
1187 }
1188 
1190  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1191  return getSequentialElement();
1192  return getStructElement(cast<ConstantInt>(C)->getZExtValue());
1193 }
1194 
1196  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1197  return getSequentialElement();
1198  return getStructElement(Idx);
1199 }
1200 
1201 //===----------------------------------------------------------------------===//
1202 // ConstantXXX Classes
1203 //===----------------------------------------------------------------------===//
1204 
1205 template <typename ItTy, typename EltTy>
1206 static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt) {
1207  for (; Start != End; ++Start)
1208  if (*Start != Elt)
1209  return false;
1210  return true;
1211 }
1212 
1213 template <typename SequentialTy, typename ElementTy>
1215  assert(!V.empty() && "Cannot get empty int sequence.");
1216 
1218  for (Constant *C : V)
1219  if (auto *CI = dyn_cast<ConstantInt>(C))
1220  Elts.push_back(CI->getZExtValue());
1221  else
1222  return nullptr;
1223  return SequentialTy::get(V[0]->getContext(), Elts);
1224 }
1225 
1226 template <typename SequentialTy, typename ElementTy>
1228  assert(!V.empty() && "Cannot get empty FP sequence.");
1229 
1231  for (Constant *C : V)
1232  if (auto *CFP = dyn_cast<ConstantFP>(C))
1233  Elts.push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1234  else
1235  return nullptr;
1236  return SequentialTy::getFP(V[0]->getType(), Elts);
1237 }
1238 
1239 template <typename SequenceTy>
1242  // We speculatively build the elements here even if it turns out that there is
1243  // a constantexpr or something else weird, since it is so uncommon for that to
1244  // happen.
1245  if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
1246  if (CI->getType()->isIntegerTy(8))
1247  return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1248  else if (CI->getType()->isIntegerTy(16))
1249  return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1250  else if (CI->getType()->isIntegerTy(32))
1251  return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1252  else if (CI->getType()->isIntegerTy(64))
1253  return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1254  } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
1255  if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1256  return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1257  else if (CFP->getType()->isFloatTy())
1258  return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1259  else if (CFP->getType()->isDoubleTy())
1260  return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1261  }
1262 
1263  return nullptr;
1264 }
1265 
1268  : Constant(T, VT, OperandTraits<ConstantAggregate>::op_end(this) - V.size(),
1269  V.size()) {
1270  llvm::copy(V, op_begin());
1271 
1272  // Check that types match, unless this is an opaque struct.
1273  if (auto *ST = dyn_cast<StructType>(T)) {
1274  if (ST->isOpaque())
1275  return;
1276  for (unsigned I = 0, E = V.size(); I != E; ++I)
1277  assert(V[I]->getType() == ST->getTypeAtIndex(I) &&
1278  "Initializer for struct element doesn't match!");
1279  }
1280 }
1281 
1282 ConstantArray::ConstantArray(ArrayType *T, ArrayRef<Constant *> V)
1283  : ConstantAggregate(T, ConstantArrayVal, V) {
1284  assert(V.size() == T->getNumElements() &&
1285  "Invalid initializer for constant array");
1286 }
1287 
1289  if (Constant *C = getImpl(Ty, V))
1290  return C;
1291  return Ty->getContext().pImpl->ArrayConstants.getOrCreate(Ty, V);
1292 }
1293 
1294 Constant *ConstantArray::getImpl(ArrayType *Ty, ArrayRef<Constant*> V) {
1295  // Empty arrays are canonicalized to ConstantAggregateZero.
1296  if (V.empty())
1297  return ConstantAggregateZero::get(Ty);
1298 
1299  for (Constant *C : V) {
1300  assert(C->getType() == Ty->getElementType() &&
1301  "Wrong type in array element initializer");
1302  (void)C;
1303  }
1304 
1305  // If this is an all-zero array, return a ConstantAggregateZero object. If
1306  // all undef, return an UndefValue, if "all simple", then return a
1307  // ConstantDataArray.
1308  Constant *C = V[0];
1309  if (isa<PoisonValue>(C) && rangeOnlyContains(V.begin(), V.end(), C))
1310  return PoisonValue::get(Ty);
1311 
1312  if (isa<UndefValue>(C) && rangeOnlyContains(V.begin(), V.end(), C))
1313  return UndefValue::get(Ty);
1314 
1315  if (C->isNullValue() && rangeOnlyContains(V.begin(), V.end(), C))
1316  return ConstantAggregateZero::get(Ty);
1317 
1318  // Check to see if all of the elements are ConstantFP or ConstantInt and if
1319  // the element type is compatible with ConstantDataVector. If so, use it.
1321  return getSequenceIfElementsMatch<ConstantDataArray>(C, V);
1322 
1323  // Otherwise, we really do want to create a ConstantArray.
1324  return nullptr;
1325 }
1326 
1329  bool Packed) {
1330  unsigned VecSize = V.size();
1331  SmallVector<Type*, 16> EltTypes(VecSize);
1332  for (unsigned i = 0; i != VecSize; ++i)
1333  EltTypes[i] = V[i]->getType();
1334 
1335  return StructType::get(Context, EltTypes, Packed);
1336 }
1337 
1338 
1340  bool Packed) {
1341  assert(!V.empty() &&
1342  "ConstantStruct::getTypeForElements cannot be called on empty list");
1343  return getTypeForElements(V[0]->getContext(), V, Packed);
1344 }
1345 
1346 ConstantStruct::ConstantStruct(StructType *T, ArrayRef<Constant *> V)
1347  : ConstantAggregate(T, ConstantStructVal, V) {
1348  assert((T->isOpaque() || V.size() == T->getNumElements()) &&
1349  "Invalid initializer for constant struct");
1350 }
1351 
1352 // ConstantStruct accessors.
1354  assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1355  "Incorrect # elements specified to ConstantStruct::get");
1356 
1357  // Create a ConstantAggregateZero value if all elements are zeros.
1358  bool isZero = true;
1359  bool isUndef = false;
1360  bool isPoison = false;
1361 
1362  if (!V.empty()) {
1363  isUndef = isa<UndefValue>(V[0]);
1364  isPoison = isa<PoisonValue>(V[0]);
1365  isZero = V[0]->isNullValue();
1366  // PoisonValue inherits UndefValue, so its check is not necessary.
1367  if (isUndef || isZero) {
1368  for (Constant *C : V) {
1369  if (!C->isNullValue())
1370  isZero = false;
1371  if (!isa<PoisonValue>(C))
1372  isPoison = false;
1373  if (isa<PoisonValue>(C) || !isa<UndefValue>(C))
1374  isUndef = false;
1375  }
1376  }
1377  }
1378  if (isZero)
1380  if (isPoison)
1381  return PoisonValue::get(ST);
1382  if (isUndef)
1383  return UndefValue::get(ST);
1384 
1385  return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1386 }
1387 
1388 ConstantVector::ConstantVector(VectorType *T, ArrayRef<Constant *> V)
1389  : ConstantAggregate(T, ConstantVectorVal, V) {
1390  assert(V.size() == cast<FixedVectorType>(T)->getNumElements() &&
1391  "Invalid initializer for constant vector");
1392 }
1393 
1394 // ConstantVector accessors.
1396  if (Constant *C = getImpl(V))
1397  return C;
1398  auto *Ty = FixedVectorType::get(V.front()->getType(), V.size());
1399  return Ty->getContext().pImpl->VectorConstants.getOrCreate(Ty, V);
1400 }
1401 
1402 Constant *ConstantVector::getImpl(ArrayRef<Constant*> V) {
1403  assert(!V.empty() && "Vectors can't be empty");
1404  auto *T = FixedVectorType::get(V.front()->getType(), V.size());
1405 
1406  // If this is an all-undef or all-zero vector, return a
1407  // ConstantAggregateZero or UndefValue.
1408  Constant *C = V[0];
1409  bool isZero = C->isNullValue();
1410  bool isUndef = isa<UndefValue>(C);
1411  bool isPoison = isa<PoisonValue>(C);
1412 
1413  if (isZero || isUndef) {
1414  for (unsigned i = 1, e = V.size(); i != e; ++i)
1415  if (V[i] != C) {
1416  isZero = isUndef = isPoison = false;
1417  break;
1418  }
1419  }
1420 
1421  if (isZero)
1422  return ConstantAggregateZero::get(T);
1423  if (isPoison)
1424  return PoisonValue::get(T);
1425  if (isUndef)
1426  return UndefValue::get(T);
1427 
1428  // Check to see if all of the elements are ConstantFP or ConstantInt and if
1429  // the element type is compatible with ConstantDataVector. If so, use it.
1431  return getSequenceIfElementsMatch<ConstantDataVector>(C, V);
1432 
1433  // Otherwise, the element type isn't compatible with ConstantDataVector, or
1434  // the operand list contains a ConstantExpr or something else strange.
1435  return nullptr;
1436 }
1437 
1439  if (!EC.isScalable()) {
1440  // If this splat is compatible with ConstantDataVector, use it instead of
1441  // ConstantVector.
1442  if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1444  return ConstantDataVector::getSplat(EC.getKnownMinValue(), V);
1445 
1446  SmallVector<Constant *, 32> Elts(EC.getKnownMinValue(), V);
1447  return get(Elts);
1448  }
1449 
1450  Type *VTy = VectorType::get(V->getType(), EC);
1451 
1452  if (V->isNullValue())
1453  return ConstantAggregateZero::get(VTy);
1454  else if (isa<UndefValue>(V))
1455  return UndefValue::get(VTy);
1456 
1457  Type *I32Ty = Type::getInt32Ty(VTy->getContext());
1458 
1459  // Move scalar into vector.
1460  Constant *PoisonV = PoisonValue::get(VTy);
1461  V = ConstantExpr::getInsertElement(PoisonV, V, ConstantInt::get(I32Ty, 0));
1462  // Build shuffle mask to perform the splat.
1463  SmallVector<int, 8> Zeros(EC.getKnownMinValue(), 0);
1464  // Splat.
1465  return ConstantExpr::getShuffleVector(V, PoisonV, Zeros);
1466 }
1467 
1469  LLVMContextImpl *pImpl = Context.pImpl;
1470  if (!pImpl->TheNoneToken)
1471  pImpl->TheNoneToken.reset(new ConstantTokenNone(Context));
1472  return pImpl->TheNoneToken.get();
1473 }
1474 
1475 /// Remove the constant from the constant table.
1476 void ConstantTokenNone::destroyConstantImpl() {
1477  llvm_unreachable("You can't ConstantTokenNone->destroyConstantImpl()!");
1478 }
1479 
1480 // Utility function for determining if a ConstantExpr is a CastOp or not. This
1481 // can't be inline because we don't want to #include Instruction.h into
1482 // Constant.h
1483 bool ConstantExpr::isCast() const {
1484  return Instruction::isCast(getOpcode());
1485 }
1486 
1488  return getOpcode() == Instruction::ICmp || getOpcode() == Instruction::FCmp;
1489 }
1490 
1492  return getOpcode() == Instruction::InsertValue;
1493 }
1494 
1496  return cast<InsertValueConstantExpr>(this)->Indices;
1497 }
1498 
1499 unsigned ConstantExpr::getPredicate() const {
1500  return cast<CompareConstantExpr>(this)->predicate;
1501 }
1502 
1504  return cast<ShuffleVectorConstantExpr>(this)->ShuffleMask;
1505 }
1506 
1508  return cast<ShuffleVectorConstantExpr>(this)->ShuffleMaskForBitcode;
1509 }
1510 
1512  bool OnlyIfReduced, Type *SrcTy) const {
1513  assert(Ops.size() == getNumOperands() && "Operand count mismatch!");
1514 
1515  // If no operands changed return self.
1516  if (Ty == getType() && std::equal(Ops.begin(), Ops.end(), op_begin()))
1517  return const_cast<ConstantExpr*>(this);
1518 
1519  Type *OnlyIfReducedTy = OnlyIfReduced ? Ty : nullptr;
1520  switch (getOpcode()) {
1521  case Instruction::Trunc:
1522  case Instruction::ZExt:
1523  case Instruction::SExt:
1524  case Instruction::FPTrunc:
1525  case Instruction::FPExt:
1526  case Instruction::UIToFP:
1527  case Instruction::SIToFP:
1528  case Instruction::FPToUI:
1529  case Instruction::FPToSI:
1530  case Instruction::PtrToInt:
1531  case Instruction::IntToPtr:
1532  case Instruction::BitCast:
1533  case Instruction::AddrSpaceCast:
1534  return ConstantExpr::getCast(getOpcode(), Ops[0], Ty, OnlyIfReduced);
1535  case Instruction::Select:
1536  return ConstantExpr::getSelect(Ops[0], Ops[1], Ops[2], OnlyIfReducedTy);
1537  case Instruction::InsertElement:
1538  return ConstantExpr::getInsertElement(Ops[0], Ops[1], Ops[2],
1539  OnlyIfReducedTy);
1540  case Instruction::ExtractElement:
1541  return ConstantExpr::getExtractElement(Ops[0], Ops[1], OnlyIfReducedTy);
1542  case Instruction::InsertValue:
1543  return ConstantExpr::getInsertValue(Ops[0], Ops[1], getIndices(),
1544  OnlyIfReducedTy);
1545  case Instruction::FNeg:
1546  return ConstantExpr::getFNeg(Ops[0]);
1547  case Instruction::ShuffleVector:
1548  return ConstantExpr::getShuffleVector(Ops[0], Ops[1], getShuffleMask(),
1549  OnlyIfReducedTy);
1550  case Instruction::GetElementPtr: {
1551  auto *GEPO = cast<GEPOperator>(this);
1552  assert(SrcTy || (Ops[0]->getType() == getOperand(0)->getType()));
1554  SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.slice(1),
1555  GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1556  }
1557  case Instruction::ICmp:
1558  case Instruction::FCmp:
1559  return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1],
1560  OnlyIfReducedTy);
1561  default:
1562  assert(getNumOperands() == 2 && "Must be binary operator?");
1563  return ConstantExpr::get(getOpcode(), Ops[0], Ops[1], SubclassOptionalData,
1564  OnlyIfReducedTy);
1565  }
1566 }
1567 
1568 
1569 //===----------------------------------------------------------------------===//
1570 // isValueValidForType implementations
1571 
1573  unsigned NumBits = Ty->getIntegerBitWidth(); // assert okay
1574  if (Ty->isIntegerTy(1))
1575  return Val == 0 || Val == 1;
1576  return isUIntN(NumBits, Val);
1577 }
1578 
1579 bool ConstantInt::isValueValidForType(Type *Ty, int64_t Val) {
1580  unsigned NumBits = Ty->getIntegerBitWidth();
1581  if (Ty->isIntegerTy(1))
1582  return Val == 0 || Val == 1 || Val == -1;
1583  return isIntN(NumBits, Val);
1584 }
1585 
1587  // convert modifies in place, so make a copy.
1588  APFloat Val2 = APFloat(Val);
1589  bool losesInfo;
1590  switch (Ty->getTypeID()) {
1591  default:
1592  return false; // These can't be represented as floating point!
1593 
1594  // FIXME rounding mode needs to be more flexible
1595  case Type::HalfTyID: {
1596  if (&Val2.getSemantics() == &APFloat::IEEEhalf())
1597  return true;
1599  return !losesInfo;
1600  }
1601  case Type::BFloatTyID: {
1602  if (&Val2.getSemantics() == &APFloat::BFloat())
1603  return true;
1605  return !losesInfo;
1606  }
1607  case Type::FloatTyID: {
1608  if (&Val2.getSemantics() == &APFloat::IEEEsingle())
1609  return true;
1611  return !losesInfo;
1612  }
1613  case Type::DoubleTyID: {
1614  if (&Val2.getSemantics() == &APFloat::IEEEhalf() ||
1615  &Val2.getSemantics() == &APFloat::BFloat() ||
1616  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1617  &Val2.getSemantics() == &APFloat::IEEEdouble())
1618  return true;
1620  return !losesInfo;
1621  }
1622  case Type::X86_FP80TyID:
1623  return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1624  &Val2.getSemantics() == &APFloat::BFloat() ||
1625  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1626  &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1628  case Type::FP128TyID:
1629  return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1630  &Val2.getSemantics() == &APFloat::BFloat() ||
1631  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1632  &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1633  &Val2.getSemantics() == &APFloat::IEEEquad();
1634  case Type::PPC_FP128TyID:
1635  return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1636  &Val2.getSemantics() == &APFloat::BFloat() ||
1637  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1638  &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1639  &Val2.getSemantics() == &APFloat::PPCDoubleDouble();
1640  }
1641 }
1642 
1643 
1644 //===----------------------------------------------------------------------===//
1645 // Factory Function Implementation
1646 
1648  assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
1649  "Cannot create an aggregate zero of non-aggregate type!");
1650 
1651  std::unique_ptr<ConstantAggregateZero> &Entry =
1652  Ty->getContext().pImpl->CAZConstants[Ty];
1653  if (!Entry)
1654  Entry.reset(new ConstantAggregateZero(Ty));
1655 
1656  return Entry.get();
1657 }
1658 
1659 /// Remove the constant from the constant table.
1660 void ConstantAggregateZero::destroyConstantImpl() {
1661  getContext().pImpl->CAZConstants.erase(getType());
1662 }
1663 
1664 /// Remove the constant from the constant table.
1665 void ConstantArray::destroyConstantImpl() {
1667 }
1668 
1669 
1670 //---- ConstantStruct::get() implementation...
1671 //
1672 
1673 /// Remove the constant from the constant table.
1674 void ConstantStruct::destroyConstantImpl() {
1676 }
1677 
1678 /// Remove the constant from the constant table.
1679 void ConstantVector::destroyConstantImpl() {
1681 }
1682 
1683 Constant *Constant::getSplatValue(bool AllowUndefs) const {
1684  assert(this->getType()->isVectorTy() && "Only valid for vectors!");
1685  if (isa<ConstantAggregateZero>(this))
1686  return getNullValue(cast<VectorType>(getType())->getElementType());
1687  if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(this))
1688  return CV->getSplatValue();
1689  if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
1690  return CV->getSplatValue(AllowUndefs);
1691 
1692  // Check if this is a constant expression splat of the form returned by
1693  // ConstantVector::getSplat()
1694  const auto *Shuf = dyn_cast<ConstantExpr>(this);
1695  if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1696  isa<UndefValue>(Shuf->getOperand(1))) {
1697 
1698  const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1699  if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1700  isa<UndefValue>(IElt->getOperand(0))) {
1701 
1702  ArrayRef<int> Mask = Shuf->getShuffleMask();
1703  Constant *SplatVal = IElt->getOperand(1);
1704  ConstantInt *Index = dyn_cast<ConstantInt>(IElt->getOperand(2));
1705 
1706  if (Index && Index->getValue() == 0 &&
1707  llvm::all_of(Mask, [](int I) { return I == 0; }))
1708  return SplatVal;
1709  }
1710  }
1711 
1712  return nullptr;
1713 }
1714 
1715 Constant *ConstantVector::getSplatValue(bool AllowUndefs) const {
1716  // Check out first element.
1717  Constant *Elt = getOperand(0);
1718  // Then make sure all remaining elements point to the same value.
1719  for (unsigned I = 1, E = getNumOperands(); I < E; ++I) {
1720  Constant *OpC = getOperand(I);
1721  if (OpC == Elt)
1722  continue;
1723 
1724  // Strict mode: any mismatch is not a splat.
1725  if (!AllowUndefs)
1726  return nullptr;
1727 
1728  // Allow undefs mode: ignore undefined elements.
1729  if (isa<UndefValue>(OpC))
1730  continue;
1731 
1732  // If we do not have a defined element yet, use the current operand.
1733  if (isa<UndefValue>(Elt))
1734  Elt = OpC;
1735 
1736  if (OpC != Elt)
1737  return nullptr;
1738  }
1739  return Elt;
1740 }
1741 
1743  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
1744  return CI->getValue();
1745  assert(this->getSplatValue() && "Doesn't contain a unique integer!");
1746  const Constant *C = this->getAggregateElement(0U);
1747  assert(C && isa<ConstantInt>(C) && "Not a vector of numbers!");
1748  return cast<ConstantInt>(C)->getValue();
1749 }
1750 
1751 //---- ConstantPointerNull::get() implementation.
1752 //
1753 
1755  std::unique_ptr<ConstantPointerNull> &Entry =
1756  Ty->getContext().pImpl->CPNConstants[Ty];
1757  if (!Entry)
1758  Entry.reset(new ConstantPointerNull(Ty));
1759 
1760  return Entry.get();
1761 }
1762 
1763 /// Remove the constant from the constant table.
1764 void ConstantPointerNull::destroyConstantImpl() {
1765  getContext().pImpl->CPNConstants.erase(getType());
1766 }
1767 
1769  std::unique_ptr<UndefValue> &Entry = Ty->getContext().pImpl->UVConstants[Ty];
1770  if (!Entry)
1771  Entry.reset(new UndefValue(Ty));
1772 
1773  return Entry.get();
1774 }
1775 
1776 /// Remove the constant from the constant table.
1777 void UndefValue::destroyConstantImpl() {
1778  // Free the constant and any dangling references to it.
1779  if (getValueID() == UndefValueVal) {
1780  getContext().pImpl->UVConstants.erase(getType());
1781  } else if (getValueID() == PoisonValueVal) {
1782  getContext().pImpl->PVConstants.erase(getType());
1783  }
1784  llvm_unreachable("Not a undef or a poison!");
1785 }
1786 
1788  std::unique_ptr<PoisonValue> &Entry = Ty->getContext().pImpl->PVConstants[Ty];
1789  if (!Entry)
1790  Entry.reset(new PoisonValue(Ty));
1791 
1792  return Entry.get();
1793 }
1794 
1795 /// Remove the constant from the constant table.
1796 void PoisonValue::destroyConstantImpl() {
1797  // Free the constant and any dangling references to it.
1798  getContext().pImpl->PVConstants.erase(getType());
1799 }
1800 
1802  assert(BB->getParent() && "Block must have a parent");
1803  return get(BB->getParent(), BB);
1804 }
1805 
1807  BlockAddress *&BA =
1808  F->getContext().pImpl->BlockAddresses[std::make_pair(F, BB)];
1809  if (!BA)
1810  BA = new BlockAddress(F, BB);
1811 
1812  assert(BA->getFunction() == F && "Basic block moved between functions");
1813  return BA;
1814 }
1815 
1816 BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
1817  : Constant(Type::getInt8PtrTy(F->getContext(), F->getAddressSpace()),
1818  Value::BlockAddressVal, &Op<0>(), 2) {
1819  setOperand(0, F);
1820  setOperand(1, BB);
1821  BB->AdjustBlockAddressRefCount(1);
1822 }
1823 
1825  if (!BB->hasAddressTaken())
1826  return nullptr;
1827 
1828  const Function *F = BB->getParent();
1829  assert(F && "Block must have a parent");
1830  BlockAddress *BA =
1831  F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(F, BB));
1832  assert(BA && "Refcount and block address map disagree!");
1833  return BA;
1834 }
1835 
1836 /// Remove the constant from the constant table.
1837 void BlockAddress::destroyConstantImpl() {
1839  ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
1840  getBasicBlock()->AdjustBlockAddressRefCount(-1);
1841 }
1842 
1843 Value *BlockAddress::handleOperandChangeImpl(Value *From, Value *To) {
1844  // This could be replacing either the Basic Block or the Function. In either
1845  // case, we have to remove the map entry.
1846  Function *NewF = getFunction();
1847  BasicBlock *NewBB = getBasicBlock();
1848 
1849  if (From == NewF)
1850  NewF = cast<Function>(To->stripPointerCasts());
1851  else {
1852  assert(From == NewBB && "From does not match any operand");
1853  NewBB = cast<BasicBlock>(To);
1854  }
1855 
1856  // See if the 'new' entry already exists, if not, just update this in place
1857  // and return early.
1858  BlockAddress *&NewBA =
1859  getContext().pImpl->BlockAddresses[std::make_pair(NewF, NewBB)];
1860  if (NewBA)
1861  return NewBA;
1862 
1863  getBasicBlock()->AdjustBlockAddressRefCount(-1);
1864 
1865  // Remove the old entry, this can't cause the map to rehash (just a
1866  // tombstone will get added).
1867  getContext().pImpl->BlockAddresses.erase(std::make_pair(getFunction(),
1868  getBasicBlock()));
1869  NewBA = this;
1870  setOperand(0, NewF);
1871  setOperand(1, NewBB);
1872  getBasicBlock()->AdjustBlockAddressRefCount(1);
1873 
1874  // If we just want to keep the existing value, then return null.
1875  // Callers know that this means we shouldn't delete this value.
1876  return nullptr;
1877 }
1878 
1881  if (!Equiv)
1882  Equiv = new DSOLocalEquivalent(GV);
1883 
1884  assert(Equiv->getGlobalValue() == GV &&
1885  "DSOLocalFunction does not match the expected global value");
1886  return Equiv;
1887 }
1888 
1889 DSOLocalEquivalent::DSOLocalEquivalent(GlobalValue *GV)
1890  : Constant(GV->getType(), Value::DSOLocalEquivalentVal, &Op<0>(), 1) {
1891  setOperand(0, GV);
1892 }
1893 
1894 /// Remove the constant from the constant table.
1895 void DSOLocalEquivalent::destroyConstantImpl() {
1896  const GlobalValue *GV = getGlobalValue();
1897  GV->getContext().pImpl->DSOLocalEquivalents.erase(GV);
1898 }
1899 
1900 Value *DSOLocalEquivalent::handleOperandChangeImpl(Value *From, Value *To) {
1901  assert(From == getGlobalValue() && "Changing value does not match operand.");
1902  assert(isa<Constant>(To) && "Can only replace the operands with a constant");
1903 
1904  // The replacement is with another global value.
1905  if (const auto *ToObj = dyn_cast<GlobalValue>(To)) {
1906  DSOLocalEquivalent *&NewEquiv =
1908  if (NewEquiv)
1909  return llvm::ConstantExpr::getBitCast(NewEquiv, getType());
1910  }
1911 
1912  // If the argument is replaced with a null value, just replace this constant
1913  // with a null value.
1914  if (cast<Constant>(To)->isNullValue())
1915  return To;
1916 
1917  // The replacement could be a bitcast or an alias to another function. We can
1918  // replace it with a bitcast to the dso_local_equivalent of that function.
1919  auto *Func = cast<Function>(To->stripPointerCastsAndAliases());
1921  if (NewEquiv)
1922  return llvm::ConstantExpr::getBitCast(NewEquiv, getType());
1923 
1924  // Replace this with the new one.
1926  NewEquiv = this;
1927  setOperand(0, Func);
1928 
1929  if (Func->getType() != getType()) {
1930  // It is ok to mutate the type here because this constant should always
1931  // reflect the type of the function it's holding.
1932  mutateType(Func->getType());
1933  }
1934  return nullptr;
1935 }
1936 
1938  NoCFIValue *&NC = GV->getContext().pImpl->NoCFIValues[GV];
1939  if (!NC)
1940  NC = new NoCFIValue(GV);
1941 
1942  assert(NC->getGlobalValue() == GV &&
1943  "NoCFIValue does not match the expected global value");
1944  return NC;
1945 }
1946 
1947 NoCFIValue::NoCFIValue(GlobalValue *GV)
1948  : Constant(GV->getType(), Value::NoCFIValueVal, &Op<0>(), 1) {
1949  setOperand(0, GV);
1950 }
1951 
1952 /// Remove the constant from the constant table.
1953 void NoCFIValue::destroyConstantImpl() {
1954  const GlobalValue *GV = getGlobalValue();
1955  GV->getContext().pImpl->NoCFIValues.erase(GV);
1956 }
1957 
1958 Value *NoCFIValue::handleOperandChangeImpl(Value *From, Value *To) {
1959  assert(From == getGlobalValue() && "Changing value does not match operand.");
1960 
1961  GlobalValue *GV = dyn_cast<GlobalValue>(To->stripPointerCasts());
1962  assert(GV && "Can only replace the operands with a global value");
1963 
1964  NoCFIValue *&NewNC = getContext().pImpl->NoCFIValues[GV];
1965  if (NewNC)
1966  return llvm::ConstantExpr::getBitCast(NewNC, getType());
1967 
1969  NewNC = this;
1970  setOperand(0, GV);
1971 
1972  if (GV->getType() != getType())
1973  mutateType(GV->getType());
1974 
1975  return nullptr;
1976 }
1977 
1978 //---- ConstantExpr::get() implementations.
1979 //
1980 
1981 /// This is a utility function to handle folding of casts and lookup of the
1982 /// cast in the ExprConstants map. It is used by the various get* methods below.
1984  bool OnlyIfReduced = false) {
1985  assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
1986  // Fold a few common cases
1987  if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty))
1988  return FC;
1989 
1990  if (OnlyIfReduced)
1991  return nullptr;
1992 
1993  LLVMContextImpl *pImpl = Ty->getContext().pImpl;
1994 
1995  // Look up the constant in the table first to ensure uniqueness.
1996  ConstantExprKeyType Key(opc, C);
1997 
1998  return pImpl->ExprConstants.getOrCreate(Ty, Key);
1999 }
2000 
2002  bool OnlyIfReduced) {
2004  assert(Instruction::isCast(opc) && "opcode out of range");
2005  assert(C && Ty && "Null arguments to getCast");
2006  assert(CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!");
2007 
2008  switch (opc) {
2009  default:
2010  llvm_unreachable("Invalid cast opcode");
2011  case Instruction::Trunc:
2012  return getTrunc(C, Ty, OnlyIfReduced);
2013  case Instruction::ZExt:
2014  return getZExt(C, Ty, OnlyIfReduced);
2015  case Instruction::SExt:
2016  return getSExt(C, Ty, OnlyIfReduced);
2017  case Instruction::FPTrunc:
2018  return getFPTrunc(C, Ty, OnlyIfReduced);
2019  case Instruction::FPExt:
2020  return getFPExtend(C, Ty, OnlyIfReduced);
2021  case Instruction::UIToFP:
2022  return getUIToFP(C, Ty, OnlyIfReduced);
2023  case Instruction::SIToFP:
2024  return getSIToFP(C, Ty, OnlyIfReduced);
2025  case Instruction::FPToUI:
2026  return getFPToUI(C, Ty, OnlyIfReduced);
2027  case Instruction::FPToSI:
2028  return getFPToSI(C, Ty, OnlyIfReduced);
2029  case Instruction::PtrToInt:
2030  return getPtrToInt(C, Ty, OnlyIfReduced);
2031  case Instruction::IntToPtr:
2032  return getIntToPtr(C, Ty, OnlyIfReduced);
2033  case Instruction::BitCast:
2034  return getBitCast(C, Ty, OnlyIfReduced);
2035  case Instruction::AddrSpaceCast:
2036  return getAddrSpaceCast(C, Ty, OnlyIfReduced);
2037  }
2038 }
2039 
2041  if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2042  return getBitCast(C, Ty);
2043  return getZExt(C, Ty);
2044 }
2045 
2047  if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2048  return getBitCast(C, Ty);
2049  return getSExt(C, Ty);
2050 }
2051 
2053  if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2054  return getBitCast(C, Ty);
2055  return getTrunc(C, Ty);
2056 }
2057 
2059  assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
2060  "Can only sign extend/truncate integers!");
2061  Type *CTy = C->getType();
2062  if (CTy->getScalarSizeInBits() < Ty->getScalarSizeInBits())
2063  return getSExt(C, Ty);
2064  if (CTy->getScalarSizeInBits() > Ty->getScalarSizeInBits())
2065  return getTrunc(C, Ty);
2066  return C;
2067 }
2068 
2070  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2071  assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
2072  "Invalid cast");
2073 
2074  if (Ty->isIntOrIntVectorTy())
2075  return getPtrToInt(S, Ty);
2076 
2077  unsigned SrcAS = S->getType()->getPointerAddressSpace();
2078  if (Ty->isPtrOrPtrVectorTy() && SrcAS != Ty->getPointerAddressSpace())
2079  return getAddrSpaceCast(S, Ty);
2080 
2081  return getBitCast(S, Ty);
2082 }
2083 
2085  Type *Ty) {
2086  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2087  assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
2088 
2089  if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
2090  return getAddrSpaceCast(S, Ty);
2091 
2092  return getBitCast(S, Ty);
2093 }
2094 
2096  assert(C->getType()->isIntOrIntVectorTy() &&
2097  Ty->isIntOrIntVectorTy() && "Invalid cast");
2098  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2099  unsigned DstBits = Ty->getScalarSizeInBits();
2100  Instruction::CastOps opcode =
2101  (SrcBits == DstBits ? Instruction::BitCast :
2102  (SrcBits > DstBits ? Instruction::Trunc :
2103  (isSigned ? Instruction::SExt : Instruction::ZExt)));
2104  return getCast(opcode, C, Ty);
2105 }
2106 
2108  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2109  "Invalid cast");
2110  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2111  unsigned DstBits = Ty->getScalarSizeInBits();
2112  if (SrcBits == DstBits)
2113  return C; // Avoid a useless cast
2114  Instruction::CastOps opcode =
2115  (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
2116  return getCast(opcode, C, Ty);
2117 }
2118 
2119 Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
2120 #ifndef NDEBUG
2121  bool fromVec = isa<VectorType>(C->getType());
2122  bool toVec = isa<VectorType>(Ty);
2123 #endif
2124  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2125  assert(C->getType()->isIntOrIntVectorTy() && "Trunc operand must be integer");
2126  assert(Ty->isIntOrIntVectorTy() && "Trunc produces only integral");
2127  assert(C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
2128  "SrcTy must be larger than DestTy for Trunc!");
2129 
2130  return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
2131 }
2132 
2133 Constant *ConstantExpr::getSExt(Constant *C, Type *Ty, bool OnlyIfReduced) {
2134 #ifndef NDEBUG
2135  bool fromVec = isa<VectorType>(C->getType());
2136  bool toVec = isa<VectorType>(Ty);
2137 #endif
2138  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2139  assert(C->getType()->isIntOrIntVectorTy() && "SExt operand must be integral");
2140  assert(Ty->isIntOrIntVectorTy() && "SExt produces only integer");
2141  assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
2142  "SrcTy must be smaller than DestTy for SExt!");
2143 
2144  return getFoldedCast(Instruction::SExt, C, Ty, OnlyIfReduced);
2145 }
2146 
2147 Constant *ConstantExpr::getZExt(Constant *C, Type *Ty, bool OnlyIfReduced) {
2148 #ifndef NDEBUG
2149  bool fromVec = isa<VectorType>(C->getType());
2150  bool toVec = isa<VectorType>(Ty);
2151 #endif
2152  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2153  assert(C->getType()->isIntOrIntVectorTy() && "ZEXt operand must be integral");
2154  assert(Ty->isIntOrIntVectorTy() && "ZExt produces only integer");
2155  assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
2156  "SrcTy must be smaller than DestTy for ZExt!");
2157 
2158  return getFoldedCast(Instruction::ZExt, C, Ty, OnlyIfReduced);
2159 }
2160 
2161 Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
2162 #ifndef NDEBUG
2163  bool fromVec = isa<VectorType>(C->getType());
2164  bool toVec = isa<VectorType>(Ty);
2165 #endif
2166  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2167  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2168  C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
2169  "This is an illegal floating point truncation!");
2170  return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced);
2171 }
2172 
2173 Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced) {
2174 #ifndef NDEBUG
2175  bool fromVec = isa<VectorType>(C->getType());
2176  bool toVec = isa<VectorType>(Ty);
2177 #endif
2178  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2179  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2180  C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
2181  "This is an illegal floating point extension!");
2182  return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced);
2183 }
2184 
2185 Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
2186 #ifndef NDEBUG
2187  bool fromVec = isa<VectorType>(C->getType());
2188  bool toVec = isa<VectorType>(Ty);
2189 #endif
2190  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2191  assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
2192  "This is an illegal uint to floating point cast!");
2193  return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced);
2194 }
2195 
2196 Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
2197 #ifndef NDEBUG
2198  bool fromVec = isa<VectorType>(C->getType());
2199  bool toVec = isa<VectorType>(Ty);
2200 #endif
2201  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2202  assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
2203  "This is an illegal sint to floating point cast!");
2204  return getFoldedCast(Instruction::SIToFP, C, Ty, OnlyIfReduced);
2205 }
2206 
2207 Constant *ConstantExpr::getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced) {
2208 #ifndef NDEBUG
2209  bool fromVec = isa<VectorType>(C->getType());
2210  bool toVec = isa<VectorType>(Ty);
2211 #endif
2212  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2213  assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
2214  "This is an illegal floating point to uint cast!");
2215  return getFoldedCast(Instruction::FPToUI, C, Ty, OnlyIfReduced);
2216 }
2217 
2218 Constant *ConstantExpr::getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced) {
2219 #ifndef NDEBUG
2220  bool fromVec = isa<VectorType>(C->getType());
2221  bool toVec = isa<VectorType>(Ty);
2222 #endif
2223  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2224  assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
2225  "This is an illegal floating point to sint cast!");
2226  return getFoldedCast(Instruction::FPToSI, C, Ty, OnlyIfReduced);
2227 }
2228 
2230  bool OnlyIfReduced) {
2231  assert(C->getType()->isPtrOrPtrVectorTy() &&
2232  "PtrToInt source must be pointer or pointer vector");
2233  assert(DstTy->isIntOrIntVectorTy() &&
2234  "PtrToInt destination must be integer or integer vector");
2235  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
2236  if (isa<VectorType>(C->getType()))
2237  assert(cast<VectorType>(C->getType())->getElementCount() ==
2238  cast<VectorType>(DstTy)->getElementCount() &&
2239  "Invalid cast between a different number of vector elements");
2240  return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
2241 }
2242 
2244  bool OnlyIfReduced) {
2245  assert(C->getType()->isIntOrIntVectorTy() &&
2246  "IntToPtr source must be integer or integer vector");
2247  assert(DstTy->isPtrOrPtrVectorTy() &&
2248  "IntToPtr destination must be a pointer or pointer vector");
2249  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
2250  if (isa<VectorType>(C->getType()))
2251  assert(cast<VectorType>(C->getType())->getElementCount() ==
2252  cast<VectorType>(DstTy)->getElementCount() &&
2253  "Invalid cast between a different number of vector elements");
2254  return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced);
2255 }
2256 
2258  bool OnlyIfReduced) {
2259  assert(CastInst::castIsValid(Instruction::BitCast, C, DstTy) &&
2260  "Invalid constantexpr bitcast!");
2261 
2262  // It is common to ask for a bitcast of a value to its own type, handle this
2263  // speedily.
2264  if (C->getType() == DstTy) return C;
2265 
2266  return getFoldedCast(Instruction::BitCast, C, DstTy, OnlyIfReduced);
2267 }
2268 
2270  bool OnlyIfReduced) {
2271  assert(CastInst::castIsValid(Instruction::AddrSpaceCast, C, DstTy) &&
2272  "Invalid constantexpr addrspacecast!");
2273 
2274  // Canonicalize addrspacecasts between different pointer types by first
2275  // bitcasting the pointer type and then converting the address space.
2276  PointerType *SrcScalarTy = cast<PointerType>(C->getType()->getScalarType());
2277  PointerType *DstScalarTy = cast<PointerType>(DstTy->getScalarType());
2278  if (!SrcScalarTy->hasSameElementTypeAs(DstScalarTy)) {
2280  DstScalarTy, SrcScalarTy->getAddressSpace());
2281  if (VectorType *VT = dyn_cast<VectorType>(DstTy)) {
2282  // Handle vectors of pointers.
2283  MidTy = FixedVectorType::get(MidTy,
2284  cast<FixedVectorType>(VT)->getNumElements());
2285  }
2286  C = getBitCast(C, MidTy);
2287  }
2288  return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced);
2289 }
2290 
2291 Constant *ConstantExpr::get(unsigned Opcode, Constant *C, unsigned Flags,
2292  Type *OnlyIfReducedTy) {
2293  // Check the operands for consistency first.
2294  assert(Instruction::isUnaryOp(Opcode) &&
2295  "Invalid opcode in unary constant expression");
2296 
2297 #ifndef NDEBUG
2298  switch (Opcode) {
2299  case Instruction::FNeg:
2300  assert(C->getType()->isFPOrFPVectorTy() &&
2301  "Tried to create a floating-point operation on a "
2302  "non-floating-point type!");
2303  break;
2304  default:
2305  break;
2306  }
2307 #endif
2308 
2309  if (Constant *FC = ConstantFoldUnaryInstruction(Opcode, C))
2310  return FC;
2311 
2312  if (OnlyIfReducedTy == C->getType())
2313  return nullptr;
2314 
2315  Constant *ArgVec[] = { C };
2316  ConstantExprKeyType Key(Opcode, ArgVec, 0, Flags);
2317 
2318  LLVMContextImpl *pImpl = C->getContext().pImpl;
2319  return pImpl->ExprConstants.getOrCreate(C->getType(), Key);
2320 }
2321 
2323  unsigned Flags, Type *OnlyIfReducedTy) {
2324  // Check the operands for consistency first.
2325  assert(Instruction::isBinaryOp(Opcode) &&
2326  "Invalid opcode in binary constant expression");
2327  assert(C1->getType() == C2->getType() &&
2328  "Operand types in binary constant expression should match");
2329 
2330 #ifndef NDEBUG
2331  switch (Opcode) {
2332  case Instruction::Add:
2333  case Instruction::Sub:
2334  case Instruction::Mul:
2335  case Instruction::UDiv:
2336  case Instruction::SDiv:
2337  case Instruction::URem:
2338  case Instruction::SRem:
2339  assert(C1->getType()->isIntOrIntVectorTy() &&
2340  "Tried to create an integer operation on a non-integer type!");
2341  break;
2342  case Instruction::FAdd:
2343  case Instruction::FSub:
2344  case Instruction::FMul:
2345  case Instruction::FDiv:
2346  case Instruction::FRem:
2347  assert(C1->getType()->isFPOrFPVectorTy() &&
2348  "Tried to create a floating-point operation on a "
2349  "non-floating-point type!");
2350  break;
2351  case Instruction::And:
2352  case Instruction::Or:
2353  case Instruction::Xor:
2354  assert(C1->getType()->isIntOrIntVectorTy() &&
2355  "Tried to create a logical operation on a non-integral type!");
2356  break;
2357  case Instruction::Shl:
2358  case Instruction::LShr:
2359  case Instruction::AShr:
2360  assert(C1->getType()->isIntOrIntVectorTy() &&
2361  "Tried to create a shift operation on a non-integer type!");
2362  break;
2363  default:
2364  break;
2365  }
2366 #endif
2367 
2368  if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
2369  return FC;
2370 
2371  if (OnlyIfReducedTy == C1->getType())
2372  return nullptr;
2373 
2374  Constant *ArgVec[] = { C1, C2 };
2375  ConstantExprKeyType Key(Opcode, ArgVec, 0, Flags);
2376 
2377  LLVMContextImpl *pImpl = C1->getContext().pImpl;
2378  return pImpl->ExprConstants.getOrCreate(C1->getType(), Key);
2379 }
2380 
2382  // sizeof is implemented as: (i64) gep (Ty*)null, 1
2383  // Note that a non-inbounds gep is used, as null isn't within any object.
2387  return getPtrToInt(GEP,
2388  Type::getInt64Ty(Ty->getContext()));
2389 }
2390 
2392  // alignof is implemented as: (i64) gep ({i1,Ty}*)null, 0, 1
2393  // Note that a non-inbounds gep is used, as null isn't within any object.
2394  Type *AligningTy = StructType::get(Type::getInt1Ty(Ty->getContext()), Ty);
2395  Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo(0));
2398  Constant *Indices[2] = { Zero, One };
2399  Constant *GEP = getGetElementPtr(AligningTy, NullPtr, Indices);
2400  return getPtrToInt(GEP,
2401  Type::getInt64Ty(Ty->getContext()));
2402 }
2403 
2406  FieldNo));
2407 }
2408 
2410  // offsetof is implemented as: (i64) gep (Ty*)null, 0, FieldNo
2411  // Note that a non-inbounds gep is used, as null isn't within any object.
2412  Constant *GEPIdx[] = {
2414  FieldNo
2415  };
2418  return getPtrToInt(GEP,
2419  Type::getInt64Ty(Ty->getContext()));
2420 }
2421 
2423  Constant *C2, bool OnlyIfReduced) {
2424  assert(C1->getType() == C2->getType() && "Op types should be identical!");
2425 
2426  switch (Predicate) {
2427  default: llvm_unreachable("Invalid CmpInst predicate");
2433  case CmpInst::FCMP_TRUE:
2434  return getFCmp(Predicate, C1, C2, OnlyIfReduced);
2435 
2439  case CmpInst::ICMP_SLE:
2440  return getICmp(Predicate, C1, C2, OnlyIfReduced);
2441  }
2442 }
2443 
2445  Type *OnlyIfReducedTy) {
2446  assert(!SelectInst::areInvalidOperands(C, V1, V2)&&"Invalid select operands");
2447 
2449  return SC; // Fold common cases
2450 
2451  if (OnlyIfReducedTy == V1->getType())
2452  return nullptr;
2453 
2454  Constant *ArgVec[] = { C, V1, V2 };
2456 
2457  LLVMContextImpl *pImpl = C->getContext().pImpl;
2458  return pImpl->ExprConstants.getOrCreate(V1->getType(), Key);
2459 }
2460 
2462  ArrayRef<Value *> Idxs, bool InBounds,
2463  Optional<unsigned> InRangeIndex,
2464  Type *OnlyIfReducedTy) {
2465  PointerType *OrigPtrTy = cast<PointerType>(C->getType()->getScalarType());
2466  assert(Ty && "Must specify element type");
2467  assert(OrigPtrTy->isOpaqueOrPointeeTypeMatches(Ty));
2468 
2469  if (Constant *FC =
2470  ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs))
2471  return FC; // Fold a few common cases.
2472 
2473  // Get the result type of the getelementptr!
2474  Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs);
2475  assert(DestTy && "GEP indices invalid!");
2476  unsigned AS = OrigPtrTy->getAddressSpace();
2477  Type *ReqTy = OrigPtrTy->isOpaque()
2478  ? PointerType::get(OrigPtrTy->getContext(), AS)
2479  : DestTy->getPointerTo(AS);
2480 
2481  auto EltCount = ElementCount::getFixed(0);
2482  if (VectorType *VecTy = dyn_cast<VectorType>(C->getType()))
2483  EltCount = VecTy->getElementCount();
2484  else
2485  for (auto Idx : Idxs)
2486  if (VectorType *VecTy = dyn_cast<VectorType>(Idx->getType()))
2487  EltCount = VecTy->getElementCount();
2488 
2489  if (EltCount.isNonZero())
2490  ReqTy = VectorType::get(ReqTy, EltCount);
2491 
2492  if (OnlyIfReducedTy == ReqTy)
2493  return nullptr;
2494 
2495  // Look up the constant in the table first to ensure uniqueness
2496  std::vector<Constant*> ArgVec;
2497  ArgVec.reserve(1 + Idxs.size());
2498  ArgVec.push_back(C);
2499  auto GTI = gep_type_begin(Ty, Idxs), GTE = gep_type_end(Ty, Idxs);
2500  for (; GTI != GTE; ++GTI) {
2501  auto *Idx = cast<Constant>(GTI.getOperand());
2502  assert(
2503  (!isa<VectorType>(Idx->getType()) ||
2504  cast<VectorType>(Idx->getType())->getElementCount() == EltCount) &&
2505  "getelementptr index type missmatch");
2506 
2507  if (GTI.isStruct() && Idx->getType()->isVectorTy()) {
2508  Idx = Idx->getSplatValue();
2509  } else if (GTI.isSequential() && EltCount.isNonZero() &&
2510  !Idx->getType()->isVectorTy()) {
2511  Idx = ConstantVector::getSplat(EltCount, Idx);
2512  }
2513  ArgVec.push_back(Idx);
2514  }
2515 
2516  unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
2517  if (InRangeIndex && *InRangeIndex < 63)
2518  SubClassOptionalData |= (*InRangeIndex + 1) << 1;
2519  const ConstantExprKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
2520  SubClassOptionalData, None, None, Ty);
2521 
2522  LLVMContextImpl *pImpl = C->getContext().pImpl;
2523  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2524 }
2525 
2527  Constant *RHS, bool OnlyIfReduced) {
2528  auto Predicate = static_cast<CmpInst::Predicate>(pred);
2529  assert(LHS->getType() == RHS->getType());
2530  assert(CmpInst::isIntPredicate(Predicate) && "Invalid ICmp Predicate");
2531 
2533  return FC; // Fold a few common cases...
2534 
2535  if (OnlyIfReduced)
2536  return nullptr;
2537 
2538  // Look up the constant in the table first to ensure uniqueness
2539  Constant *ArgVec[] = { LHS, RHS };
2540  // Get the key type with both the opcode and predicate
2541  const ConstantExprKeyType Key(Instruction::ICmp, ArgVec, Predicate);
2542 
2543  Type *ResultTy = Type::getInt1Ty(LHS->getContext());
2544  if (VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
2545  ResultTy = VectorType::get(ResultTy, VT->getElementCount());
2546 
2547  LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
2548  return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
2549 }
2550 
2552  Constant *RHS, bool OnlyIfReduced) {
2553  auto Predicate = static_cast<CmpInst::Predicate>(pred);
2554  assert(LHS->getType() == RHS->getType());
2555  assert(CmpInst::isFPPredicate(Predicate) && "Invalid FCmp Predicate");
2556 
2558  return FC; // Fold a few common cases...
2559 
2560  if (OnlyIfReduced)
2561  return nullptr;
2562 
2563  // Look up the constant in the table first to ensure uniqueness
2564  Constant *ArgVec[] = { LHS, RHS };
2565  // Get the key type with both the opcode and predicate
2566  const ConstantExprKeyType Key(Instruction::FCmp, ArgVec, Predicate);
2567 
2568  Type *ResultTy = Type::getInt1Ty(LHS->getContext());
2569  if (VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
2570  ResultTy = VectorType::get(ResultTy, VT->getElementCount());
2571 
2572  LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
2573  return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
2574 }
2575 
2577  Type *OnlyIfReducedTy) {
2578  assert(Val->getType()->isVectorTy() &&
2579  "Tried to create extractelement operation on non-vector type!");
2580  assert(Idx->getType()->isIntegerTy() &&
2581  "Extractelement index must be an integer type!");
2582 
2584  return FC; // Fold a few common cases.
2585 
2586  Type *ReqTy = cast<VectorType>(Val->getType())->getElementType();
2587  if (OnlyIfReducedTy == ReqTy)
2588  return nullptr;
2589 
2590  // Look up the constant in the table first to ensure uniqueness
2591  Constant *ArgVec[] = { Val, Idx };
2592  const ConstantExprKeyType Key(Instruction::ExtractElement, ArgVec);
2593 
2594  LLVMContextImpl *pImpl = Val->getContext().pImpl;
2595  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2596 }
2597 
2599  Constant *Idx, Type *OnlyIfReducedTy) {
2600  assert(Val->getType()->isVectorTy() &&
2601  "Tried to create insertelement operation on non-vector type!");
2602  assert(Elt->getType() == cast<VectorType>(Val->getType())->getElementType() &&
2603  "Insertelement types must match!");
2604  assert(Idx->getType()->isIntegerTy() &&
2605  "Insertelement index must be i32 type!");
2606 
2607  if (Constant *FC = ConstantFoldInsertElementInstruction(Val, Elt, Idx))
2608  return FC; // Fold a few common cases.
2609 
2610  if (OnlyIfReducedTy == Val->getType())
2611  return nullptr;
2612 
2613  // Look up the constant in the table first to ensure uniqueness
2614  Constant *ArgVec[] = { Val, Elt, Idx };
2615  const ConstantExprKeyType Key(Instruction::InsertElement, ArgVec);
2616 
2617  LLVMContextImpl *pImpl = Val->getContext().pImpl;
2618  return pImpl->ExprConstants.getOrCreate(Val->getType(), Key);
2619 }
2620 
2623  Type *OnlyIfReducedTy) {
2625  "Invalid shuffle vector constant expr operands!");
2626 
2628  return FC; // Fold a few common cases.
2629 
2630  unsigned NElts = Mask.size();
2631  auto V1VTy = cast<VectorType>(V1->getType());
2632  Type *EltTy = V1VTy->getElementType();
2633  bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2634  Type *ShufTy = VectorType::get(EltTy, NElts, TypeIsScalable);
2635 
2636  if (OnlyIfReducedTy == ShufTy)
2637  return nullptr;
2638 
2639  // Look up the constant in the table first to ensure uniqueness
2640  Constant *ArgVec[] = {V1, V2};
2641  ConstantExprKeyType Key(Instruction::ShuffleVector, ArgVec, 0, 0, None, Mask);
2642 
2643  LLVMContextImpl *pImpl = ShufTy->getContext().pImpl;
2644  return pImpl->ExprConstants.getOrCreate(ShufTy, Key);
2645 }
2646 
2648  ArrayRef<unsigned> Idxs,
2649  Type *OnlyIfReducedTy) {
2650  assert(Agg->getType()->isFirstClassType() &&
2651  "Non-first-class type for constant insertvalue expression");
2652 
2654  Idxs) == Val->getType() &&
2655  "insertvalue indices invalid!");
2656  Type *ReqTy = Val->getType();
2657 
2658  if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs))
2659  return FC;
2660 
2661  if (OnlyIfReducedTy == ReqTy)
2662  return nullptr;
2663 
2664  Constant *ArgVec[] = { Agg, Val };
2665  const ConstantExprKeyType Key(Instruction::InsertValue, ArgVec, 0, 0, Idxs);
2666 
2667  LLVMContextImpl *pImpl = Agg->getContext().pImpl;
2668  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2669 }
2670 
2671 Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) {
2672  assert(C->getType()->isIntOrIntVectorTy() &&
2673  "Cannot NEG a nonintegral value!");
2674  return getSub(ConstantFP::getZeroValueForNegation(C->getType()),
2675  C, HasNUW, HasNSW);
2676 }
2677 
2679  assert(C->getType()->isFPOrFPVectorTy() &&
2680  "Cannot FNEG a non-floating-point value!");
2681  return get(Instruction::FNeg, C);
2682 }
2683 
2685  assert(C->getType()->isIntOrIntVectorTy() &&
2686  "Cannot NOT a nonintegral value!");
2687  return get(Instruction::Xor, C, Constant::getAllOnesValue(C->getType()));
2688 }
2689 
2691  bool HasNUW, bool HasNSW) {
2692  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2694  return get(Instruction::Add, C1, C2, Flags);
2695 }
2696 
2698  return get(Instruction::FAdd, C1, C2);
2699 }
2700 
2702  bool HasNUW, bool HasNSW) {
2703  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2705  return get(Instruction::Sub, C1, C2, Flags);
2706 }
2707 
2709  return get(Instruction::FSub, C1, C2);
2710 }
2711 
2713  bool HasNUW, bool HasNSW) {
2714  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2716  return get(Instruction::Mul, C1, C2, Flags);
2717 }
2718 
2720  return get(Instruction::FMul, C1, C2);
2721 }
2722 
2724  return get(Instruction::UDiv, C1, C2,
2725  isExact ? PossiblyExactOperator::IsExact : 0);
2726 }
2727 
2729  return get(Instruction::SDiv, C1, C2,
2730  isExact ? PossiblyExactOperator::IsExact : 0);
2731 }
2732 
2734  return get(Instruction::FDiv, C1, C2);
2735 }
2736 
2738  return get(Instruction::URem, C1, C2);
2739 }
2740 
2742  return get(Instruction::SRem, C1, C2);
2743 }
2744 
2746  return get(Instruction::FRem, C1, C2);
2747 }
2748 
2750  return get(Instruction::And, C1, C2);
2751 }
2752 
2754  return get(Instruction::Or, C1, C2);
2755 }
2756 
2758  return get(Instruction::Xor, C1, C2);
2759 }
2760 
2763  return getSelect(Cmp, C1, C2);
2764 }
2765 
2767  bool HasNUW, bool HasNSW) {
2768  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2770  return get(Instruction::Shl, C1, C2, Flags);
2771 }
2772 
2774  return get(Instruction::LShr, C1, C2,
2775  isExact ? PossiblyExactOperator::IsExact : 0);
2776 }
2777 
2779  return get(Instruction::AShr, C1, C2,
2780  isExact ? PossiblyExactOperator::IsExact : 0);
2781 }
2782 
2784  Type *Ty = C->getType();
2785  const APInt *IVal;
2786  if (match(C, m_APInt(IVal)) && IVal->isPowerOf2())
2787  return ConstantInt::get(Ty, IVal->logBase2());
2788 
2789  // FIXME: We can extract pow of 2 of splat constant for scalable vectors.
2790  auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2791  if (!VecTy)
2792  return nullptr;
2793 
2795  for (unsigned I = 0, E = VecTy->getNumElements(); I != E; ++I) {
2796  Constant *Elt = C->getAggregateElement(I);
2797  if (!Elt)
2798  return nullptr;
2799  // Note that log2(iN undef) is *NOT* iN undef, because log2(iN undef) u< N.
2800  if (isa<UndefValue>(Elt)) {
2801  Elts.push_back(Constant::getNullValue(Ty->getScalarType()));
2802  continue;
2803  }
2804  if (!match(Elt, m_APInt(IVal)) || !IVal->isPowerOf2())
2805  return nullptr;
2806  Elts.push_back(ConstantInt::get(Ty->getScalarType(), IVal->logBase2()));
2807  }
2808 
2809  return ConstantVector::get(Elts);
2810 }
2811 
2813  bool AllowRHSConstant, bool NSZ) {
2814  assert(Instruction::isBinaryOp(Opcode) && "Only binops allowed");
2815 
2816  // Commutative opcodes: it does not matter if AllowRHSConstant is set.
2817  if (Instruction::isCommutative(Opcode)) {
2818  switch (Opcode) {
2819  case Instruction::Add: // X + 0 = X
2820  case Instruction::Or: // X | 0 = X
2821  case Instruction::Xor: // X ^ 0 = X
2822  return Constant::getNullValue(Ty);
2823  case Instruction::Mul: // X * 1 = X
2824  return ConstantInt::get(Ty, 1);
2825  case Instruction::And: // X & -1 = X
2826  return Constant::getAllOnesValue(Ty);
2827  case Instruction::FAdd: // X + -0.0 = X
2828  return ConstantFP::getZero(Ty, !NSZ);
2829  case Instruction::FMul: // X * 1.0 = X
2830  return ConstantFP::get(Ty, 1.0);
2831  default:
2832  llvm_unreachable("Every commutative binop has an identity constant");
2833  }
2834  }
2835 
2836  // Non-commutative opcodes: AllowRHSConstant must be set.
2837  if (!AllowRHSConstant)
2838  return nullptr;
2839 
2840  switch (Opcode) {
2841  case Instruction::Sub: // X - 0 = X
2842  case Instruction::Shl: // X << 0 = X
2843  case Instruction::LShr: // X >>u 0 = X
2844  case Instruction::AShr: // X >> 0 = X
2845  case Instruction::FSub: // X - 0.0 = X
2846  return Constant::getNullValue(Ty);
2847  case Instruction::SDiv: // X / 1 = X
2848  case Instruction::UDiv: // X /u 1 = X
2849  return ConstantInt::get(Ty, 1);
2850  case Instruction::FDiv: // X / 1.0 = X
2851  return ConstantFP::get(Ty, 1.0);
2852  default:
2853  return nullptr;
2854  }
2855 }
2856 
2858  switch (Opcode) {
2859  default:
2860  // Doesn't have an absorber.
2861  return nullptr;
2862 
2863  case Instruction::Or:
2864  return Constant::getAllOnesValue(Ty);
2865 
2866  case Instruction::And:
2867  case Instruction::Mul:
2868  return Constant::getNullValue(Ty);
2869  }
2870 }
2871 
2872 /// Remove the constant from the constant table.
2873 void ConstantExpr::destroyConstantImpl() {
2874  getType()->getContext().pImpl->ExprConstants.remove(this);
2875 }
2876 
2877 const char *ConstantExpr::getOpcodeName() const {
2879 }
2880 
2881 GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2882  Type *SrcElementTy, Constant *C, ArrayRef<Constant *> IdxList, Type *DestTy)
2883  : ConstantExpr(DestTy, Instruction::GetElementPtr,
2885  (IdxList.size() + 1),
2886  IdxList.size() + 1),
2887  SrcElementTy(SrcElementTy),
2888  ResElementTy(GetElementPtrInst::getIndexedType(SrcElementTy, IdxList)) {
2889  Op<0>() = C;
2890  Use *OperandList = getOperandList();
2891  for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
2892  OperandList[i+1] = IdxList[i];
2893 }
2894 
2896  return SrcElementTy;
2897 }
2898 
2900  return ResElementTy;
2901 }
2902 
2903 //===----------------------------------------------------------------------===//
2904 // ConstantData* implementations
2905 
2907  if (ArrayType *ATy = dyn_cast<ArrayType>(getType()))
2908  return ATy->getElementType();
2909  return cast<VectorType>(getType())->getElementType();
2910 }
2911 
2913  return StringRef(DataElements, getNumElements()*getElementByteSize());
2914 }
2915 
2917  if (Ty->isHalfTy() || Ty->isBFloatTy() || Ty->isFloatTy() || Ty->isDoubleTy())
2918  return true;
2919  if (auto *IT = dyn_cast<IntegerType>(Ty)) {
2920  switch (IT->getBitWidth()) {
2921  case 8:
2922  case 16:
2923  case 32:
2924  case 64:
2925  return true;
2926  default: break;
2927  }
2928  }
2929  return false;
2930 }
2931 
2933  if (ArrayType *AT = dyn_cast<ArrayType>(getType()))
2934  return AT->getNumElements();
2935  return cast<FixedVectorType>(getType())->getNumElements();
2936 }
2937 
2938 
2940  return getElementType()->getPrimitiveSizeInBits()/8;
2941 }
2942 
2943 /// Return the start of the specified element.
2944 const char *ConstantDataSequential::getElementPointer(unsigned Elt) const {
2945  assert(Elt < getNumElements() && "Invalid Elt");
2946  return DataElements+Elt*getElementByteSize();
2947 }
2948 
2949 
2950 /// Return true if the array is empty or all zeros.
2951 static bool isAllZeros(StringRef Arr) {
2952  for (char I : Arr)
2953  if (I != 0)
2954  return false;
2955  return true;
2956 }
2957 
2958 /// This is the underlying implementation of all of the
2959 /// ConstantDataSequential::get methods. They all thunk down to here, providing
2960 /// the correct element type. We take the bytes in as a StringRef because
2961 /// we *want* an underlying "char*" to avoid TBAA type punning violations.
2963 #ifndef NDEBUG
2964  if (ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2965  assert(isElementTypeCompatible(ATy->getElementType()));
2966  else
2967  assert(isElementTypeCompatible(cast<VectorType>(Ty)->getElementType()));
2968 #endif
2969  // If the elements are all zero or there are no elements, return a CAZ, which
2970  // is more dense and canonical.
2971  if (isAllZeros(Elements))
2972  return ConstantAggregateZero::get(Ty);
2973 
2974  // Do a lookup to see if we have already formed one of these.
2975  auto &Slot =
2976  *Ty->getContext()
2977  .pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr))
2978  .first;
2979 
2980  // The bucket can point to a linked list of different CDS's that have the same
2981  // body but different types. For example, 0,0,0,1 could be a 4 element array
2982  // of i8, or a 1-element array of i32. They'll both end up in the same
2983  /// StringMap bucket, linked up by their Next pointers. Walk the list.
2984  std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2985  for (; *Entry; Entry = &(*Entry)->Next)
2986  if ((*Entry)->getType() == Ty)
2987  return Entry->get();
2988 
2989  // Okay, we didn't get a hit. Create a node of the right class, link it in,
2990  // and return it.
2991  if (isa<ArrayType>(Ty)) {
2992  // Use reset because std::make_unique can't access the constructor.
2993  Entry->reset(new ConstantDataArray(Ty, Slot.first().data()));
2994  return Entry->get();
2995  }
2996 
2997  assert(isa<VectorType>(Ty));
2998  // Use reset because std::make_unique can't access the constructor.
2999  Entry->reset(new ConstantDataVector(Ty, Slot.first().data()));
3000  return Entry->get();
3001 }
3002 
3003 void ConstantDataSequential::destroyConstantImpl() {
3004  // Remove the constant from the StringMap.
3007 
3008  auto Slot = CDSConstants.find(getRawDataValues());
3009 
3010  assert(Slot != CDSConstants.end() && "CDS not found in uniquing table");
3011 
3012  std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
3013 
3014  // Remove the entry from the hash table.
3015  if (!(*Entry)->Next) {
3016  // If there is only one value in the bucket (common case) it must be this
3017  // entry, and removing the entry should remove the bucket completely.
3018  assert(Entry->get() == this && "Hash mismatch in ConstantDataSequential");
3019  getContext().pImpl->CDSConstants.erase(Slot);
3020  return;
3021  }
3022 
3023  // Otherwise, there are multiple entries linked off the bucket, unlink the
3024  // node we care about but keep the bucket around.
3025  while (true) {
3026  std::unique_ptr<ConstantDataSequential> &Node = *Entry;
3027  assert(Node && "Didn't find entry in its uniquing hash table!");
3028  // If we found our entry, unlink it from the list and we're done.
3029  if (Node.get() == this) {
3030  Node = std::move(Node->Next);
3031  return;
3032  }
3033 
3034  Entry = &Node->Next;
3035  }
3036 }
3037 
3038 /// getFP() constructors - Return a constant of array type with a float
3039 /// element type taken from argument `ElementType', and count taken from
3040 /// argument `Elts'. The amount of bits of the contained type must match the
3041 /// number of bits of the type contained in the passed in ArrayRef.
3042 /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
3043 /// that this can return a ConstantAggregateZero object.
3045  assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
3046  "Element type is not a 16-bit float type");
3047  Type *Ty = ArrayType::get(ElementType, Elts.size());
3048  const char *Data = reinterpret_cast<const char *>(Elts.data());
3049  return getImpl(StringRef(Data, Elts.size() * 2), Ty);
3050 }
3052  assert(ElementType->isFloatTy() && "Element type is not a 32-bit float type");
3053  Type *Ty = ArrayType::get(ElementType, Elts.size());
3054  const char *Data = reinterpret_cast<const char *>(Elts.data());
3055  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
3056 }
3058  assert(ElementType->isDoubleTy() &&
3059  "Element type is not a 64-bit float type");
3060  Type *Ty = ArrayType::get(ElementType, Elts.size());
3061  const char *Data = reinterpret_cast<const char *>(Elts.data());
3062  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
3063 }
3064 
3066  StringRef Str, bool AddNull) {
3067  if (!AddNull) {
3068  const uint8_t *Data = Str.bytes_begin();
3069  return get(Context, makeArrayRef(Data, Str.size()));
3070  }
3071 
3072  SmallVector<uint8_t, 64> ElementVals;
3073  ElementVals.append(Str.begin(), Str.end());
3074  ElementVals.push_back(0);
3075  return get(Context, ElementVals);
3076 }
3077 
3078 /// get() constructors - Return a constant with vector type with an element
3079 /// count and element type matching the ArrayRef passed in. Note that this
3080 /// can return a ConstantAggregateZero object.
3082  auto *Ty = FixedVectorType::get(Type::getInt8Ty(Context), Elts.size());
3083  const char *Data = reinterpret_cast<const char *>(Elts.data());
3084  return getImpl(StringRef(Data, Elts.size() * 1), Ty);
3085 }
3087  auto *Ty = FixedVectorType::get(Type::getInt16Ty(Context), Elts.size());
3088  const char *Data = reinterpret_cast<const char *>(Elts.data());
3089  return getImpl(StringRef(Data, Elts.size() * 2), Ty);
3090 }
3092  auto *Ty = FixedVectorType::get(Type::getInt32Ty(Context), Elts.size());
3093  const char *Data = reinterpret_cast<const char *>(Elts.data());
3094  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
3095 }
3097  auto *Ty = FixedVectorType::get(Type::getInt64Ty(Context), Elts.size());
3098  const char *Data = reinterpret_cast<const char *>(Elts.data());
3099  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
3100 }
3102  auto *Ty = FixedVectorType::get(Type::getFloatTy(Context), Elts.size());
3103  const char *Data = reinterpret_cast<const char *>(Elts.data());
3104  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
3105 }
3107  auto *Ty = FixedVectorType::get(Type::getDoubleTy(Context), Elts.size());
3108  const char *Data = reinterpret_cast<const char *>(Elts.data());
3109  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
3110 }
3111 
3112 /// getFP() constructors - Return a constant of vector type with a float
3113 /// element type taken from argument `ElementType', and count taken from
3114 /// argument `Elts'. The amount of bits of the contained type must match the
3115 /// number of bits of the type contained in the passed in ArrayRef.
3116 /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
3117 /// that this can return a ConstantAggregateZero object.
3119  ArrayRef<uint16_t> Elts) {
3120  assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
3121  "Element type is not a 16-bit float type");
3122  auto *Ty = FixedVectorType::get(ElementType, Elts.size());
3123  const char *Data = reinterpret_cast<const char *>(Elts.data());
3124  return getImpl(StringRef(Data, Elts.size() * 2), Ty);
3125 }
3127  ArrayRef<uint32_t> Elts) {
3128  assert(ElementType->isFloatTy() && "Element type is not a 32-bit float type");
3129  auto *Ty = FixedVectorType::get(ElementType, Elts.size());
3130  const char *Data = reinterpret_cast<const char *>(Elts.data());
3131  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
3132 }
3134  ArrayRef<uint64_t> Elts) {
3135  assert(ElementType->isDoubleTy() &&
3136  "Element type is not a 64-bit float type");
3137  auto *Ty = FixedVectorType::get(ElementType, Elts.size());
3138  const char *Data = reinterpret_cast<const char *>(Elts.data());
3139  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
3140 }
3141 
3144  "Element type not compatible with ConstantData");
3145  if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
3146  if (CI->getType()->isIntegerTy(8)) {
3147  SmallVector<uint8_t, 16> Elts(NumElts, CI->getZExtValue());
3148  return get(V->getContext(), Elts);
3149  }
3150  if (CI->getType()->isIntegerTy(16)) {
3151  SmallVector<uint16_t, 16> Elts(NumElts, CI->getZExtValue());
3152  return get(V->getContext(), Elts);
3153  }
3154  if (CI->getType()->isIntegerTy(32)) {
3155  SmallVector<uint32_t, 16> Elts(NumElts, CI->getZExtValue());
3156  return get(V->getContext(), Elts);
3157  }
3158  assert(CI->getType()->isIntegerTy(64) && "Unsupported ConstantData type");
3159  SmallVector<uint64_t, 16> Elts(NumElts, CI->getZExtValue());
3160  return get(V->getContext(), Elts);
3161  }
3162 
3163  if (ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3164  if (CFP->getType()->isHalfTy()) {
3166  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3167  return getFP(V->getType(), Elts);
3168  }
3169  if (CFP->getType()->isBFloatTy()) {
3171  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3172  return getFP(V->getType(), Elts);
3173  }
3174  if (CFP->getType()->isFloatTy()) {
3176  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3177  return getFP(V->getType(), Elts);
3178  }
3179  if (CFP->getType()->isDoubleTy()) {
3181  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3182  return getFP(V->getType(), Elts);
3183  }
3184  }
3186 }
3187 
3188 
3190  assert(isa<IntegerType>(getElementType()) &&
3191  "Accessor can only be used when element is an integer");
3192  const char *EltPtr = getElementPointer(Elt);
3193 
3194  // The data is stored in host byte order, make sure to cast back to the right
3195  // type to load with the right endianness.
3196  switch (getElementType()->getIntegerBitWidth()) {
3197  default: llvm_unreachable("Invalid bitwidth for CDS");
3198  case 8:
3199  return *reinterpret_cast<const uint8_t *>(EltPtr);
3200  case 16:
3201  return *reinterpret_cast<const uint16_t *>(EltPtr);
3202  case 32:
3203  return *reinterpret_cast<const uint32_t *>(EltPtr);
3204  case 64:
3205  return *reinterpret_cast<const uint64_t *>(EltPtr);
3206  }
3207 }
3208 
3210  assert(isa<IntegerType>(getElementType()) &&
3211  "Accessor can only be used when element is an integer");
3212  const char *EltPtr = getElementPointer(Elt);
3213 
3214  // The data is stored in host byte order, make sure to cast back to the right
3215  // type to load with the right endianness.
3216  switch (getElementType()->getIntegerBitWidth()) {
3217  default: llvm_unreachable("Invalid bitwidth for CDS");
3218  case 8: {
3219  auto EltVal = *reinterpret_cast<const uint8_t *>(EltPtr);
3220  return APInt(8, EltVal);
3221  }
3222  case 16: {
3223  auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3224  return APInt(16, EltVal);
3225  }
3226  case 32: {
3227  auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
3228  return APInt(32, EltVal);
3229  }
3230  case 64: {
3231  auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
3232  return APInt(64, EltVal);
3233  }
3234  }
3235 }
3236 
3238  const char *EltPtr = getElementPointer(Elt);
3239 
3240  switch (getElementType()->getTypeID()) {
3241  default:
3242  llvm_unreachable("Accessor can only be used when element is float/double!");
3243  case Type::HalfTyID: {
3244  auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3245  return APFloat(APFloat::IEEEhalf(), APInt(16, EltVal));
3246  }
3247  case Type::BFloatTyID: {
3248  auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3249  return APFloat(APFloat::BFloat(), APInt(16, EltVal));
3250  }
3251  case Type::FloatTyID: {
3252  auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
3253  return APFloat(APFloat::IEEEsingle(), APInt(32, EltVal));
3254  }
3255  case Type::DoubleTyID: {
3256  auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
3257  return APFloat(APFloat::IEEEdouble(), APInt(64, EltVal));
3258  }
3259  }
3260 }
3261 
3263  assert(getElementType()->isFloatTy() &&
3264  "Accessor can only be used when element is a 'float'");
3265  return *reinterpret_cast<const float *>(getElementPointer(Elt));
3266 }
3267 
3269  assert(getElementType()->isDoubleTy() &&
3270  "Accessor can only be used when element is a 'float'");
3271  return *reinterpret_cast<const double *>(getElementPointer(Elt));
3272 }
3273 
3275  if (getElementType()->isHalfTy() || getElementType()->isBFloatTy() ||
3276  getElementType()->isFloatTy() || getElementType()->isDoubleTy())
3278 
3280 }
3281 
3282 bool ConstantDataSequential::isString(unsigned CharSize) const {
3283  return isa<ArrayType>(getType()) && getElementType()->isIntegerTy(CharSize);
3284 }
3285 
3287  if (!isString())
3288  return false;
3289 
3290  StringRef Str = getAsString();
3291 
3292  // The last value must be nul.
3293  if (Str.back() != 0) return false;
3294 
3295  // Other elements must be non-nul.
3296  return !Str.drop_back().contains(0);
3297 }
3298 
3299 bool ConstantDataVector::isSplatData() const {
3300  const char *Base = getRawDataValues().data();
3301 
3302  // Compare elements 1+ to the 0'th element.
3303  unsigned EltSize = getElementByteSize();
3304  for (unsigned i = 1, e = getNumElements(); i != e; ++i)
3305  if (memcmp(Base, Base+i*EltSize, EltSize))
3306  return false;
3307 
3308  return true;
3309 }
3310 
3312  if (!IsSplatSet) {
3313  IsSplatSet = true;
3314  IsSplat = isSplatData();
3315  }
3316  return IsSplat;
3317 }
3318 
3320  // If they're all the same, return the 0th one as a representative.
3321  return isSplat() ? getElementAsConstant(0) : nullptr;
3322 }
3323 
3324 //===----------------------------------------------------------------------===//
3325 // handleOperandChange implementations
3326 
3327 /// Update this constant array to change uses of
3328 /// 'From' to be uses of 'To'. This must update the uniquing data structures
3329 /// etc.
3330 ///
3331 /// Note that we intentionally replace all uses of From with To here. Consider
3332 /// a large array that uses 'From' 1000 times. By handling this case all here,
3333 /// ConstantArray::handleOperandChange is only invoked once, and that
3334 /// single invocation handles all 1000 uses. Handling them one at a time would
3335 /// work, but would be really slow because it would have to unique each updated
3336 /// array instance.
3337 ///
3339  Value *Replacement = nullptr;
3340  switch (getValueID()) {
3341  default:
3342  llvm_unreachable("Not a constant!");
3343 #define HANDLE_CONSTANT(Name) \
3344  case Value::Name##Val: \
3345  Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3346  break;
3347 #include "llvm/IR/Value.def"
3348  }
3349 
3350  // If handleOperandChangeImpl returned nullptr, then it handled
3351  // replacing itself and we don't want to delete or replace anything else here.
3352  if (!Replacement)
3353  return;
3354 
3355  // I do need to replace this with an existing value.
3356  assert(Replacement != this && "I didn't contain From!");
3357 
3358  // Everyone using this now uses the replacement.
3359  replaceAllUsesWith(Replacement);
3360 
3361  // Delete the old constant!
3362  destroyConstant();
3363 }
3364 
3365 Value *ConstantArray::handleOperandChangeImpl(Value *From, Value *To) {
3366  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
3367  Constant *ToC = cast<Constant>(To);
3368 
3370  Values.reserve(getNumOperands()); // Build replacement array.
3371 
3372  // Fill values with the modified operands of the constant array. Also,
3373  // compute whether this turns into an all-zeros array.
3374  unsigned NumUpdated = 0;
3375 
3376  // Keep track of whether all the values in the array are "ToC".
3377  bool AllSame = true;
3378  Use *OperandList = getOperandList();
3379  unsigned OperandNo = 0;
3380  for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
3381  Constant *Val = cast<Constant>(O->get());
3382  if (Val == From) {
3383  OperandNo = (O - OperandList);
3384  Val = ToC;
3385  ++NumUpdated;
3386  }
3387  Values.push_back(Val);
3388  AllSame &= Val == ToC;
3389  }
3390 
3391  if (AllSame && ToC->isNullValue())
3393 
3394  if (AllSame && isa<UndefValue>(ToC))
3395  return UndefValue::get(getType());
3396 
3397  // Check for any other type of constant-folding.
3398  if (Constant *C = getImpl(getType(), Values))
3399  return C;
3400 
3401  // Update to the new value.
3403  Values, this, From, ToC, NumUpdated, OperandNo);
3404 }
3405 
3406 Value *ConstantStruct::handleOperandChangeImpl(Value *From, Value *To) {
3407  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
3408  Constant *ToC = cast<Constant>(To);
3409 
3410  Use *OperandList = getOperandList();
3411 
3413  Values.reserve(getNumOperands()); // Build replacement struct.
3414 
3415  // Fill values with the modified operands of the constant struct. Also,
3416  // compute whether this turns into an all-zeros struct.
3417  unsigned NumUpdated = 0;
3418  bool AllSame = true;
3419  unsigned OperandNo = 0;
3420  for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O) {
3421  Constant *Val = cast<Constant>(O->get());
3422  if (Val == From) {
3423  OperandNo = (O - OperandList);
3424  Val = ToC;
3425  ++NumUpdated;
3426  }
3427  Values.push_back(Val);
3428  AllSame &= Val == ToC;
3429  }
3430 
3431  if (AllSame && ToC->isNullValue())
3433 
3434  if (AllSame && isa<UndefValue>(ToC))
3435  return UndefValue::get(getType());
3436 
3437  // Update to the new value.
3439  Values, this, From, ToC, NumUpdated, OperandNo);
3440 }
3441 
3442 Value *ConstantVector::handleOperandChangeImpl(Value *From, Value *To) {
3443  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
3444  Constant *ToC = cast<Constant>(To);
3445 
3447  Values.reserve(getNumOperands()); // Build replacement array...
3448  unsigned NumUpdated = 0;
3449  unsigned OperandNo = 0;
3450  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
3451  Constant *Val = getOperand(i);
3452  if (Val == From) {
3453  OperandNo = i;
3454  ++NumUpdated;
3455  Val = ToC;
3456  }
3457  Values.push_back(Val);
3458  }
3459 
3460  if (Constant *C = getImpl(Values))
3461  return C;
3462 
3463  // Update to the new value.
3465  Values, this, From, ToC, NumUpdated, OperandNo);
3466 }
3467 
3468 Value *ConstantExpr::handleOperandChangeImpl(Value *From, Value *ToV) {
3469  assert(isa<Constant>(ToV) && "Cannot make Constant refer to non-constant!");
3470  Constant *To = cast<Constant>(ToV);
3471 
3473  unsigned NumUpdated = 0;
3474  unsigned OperandNo = 0;
3475  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
3476  Constant *Op = getOperand(i);
3477  if (Op == From) {
3478  OperandNo = i;
3479  ++NumUpdated;
3480  Op = To;
3481  }
3482  NewOps.push_back(Op);
3483  }
3484  assert(NumUpdated && "I didn't contain From!");
3485 
3486  if (Constant *C = getWithOperands(NewOps, getType(), true))
3487  return C;
3488 
3489  // Update to the new value.
3490  return getContext().pImpl->ExprConstants.replaceOperandsInPlace(
3491  NewOps, this, From, To, NumUpdated, OperandNo);
3492 }
3493 
3495  SmallVector<Value *, 4> ValueOperands(operands());
3496  ArrayRef<Value*> Ops(ValueOperands);
3497 
3498  switch (getOpcode()) {
3499  case Instruction::Trunc:
3500  case Instruction::ZExt:
3501  case Instruction::SExt:
3502  case Instruction::FPTrunc:
3503  case Instruction::FPExt:
3504  case Instruction::UIToFP:
3505  case Instruction::SIToFP:
3506  case Instruction::FPToUI:
3507  case Instruction::FPToSI:
3508  case Instruction::PtrToInt:
3509  case Instruction::IntToPtr:
3510  case Instruction::BitCast:
3511  case Instruction::AddrSpaceCast:
3513  getType(), "", InsertBefore);
3514  case Instruction::Select:
3515  return SelectInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore);
3516  case Instruction::InsertElement:
3517  return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore);
3518  case Instruction::ExtractElement:
3519  return ExtractElementInst::Create(Ops[0], Ops[1], "", InsertBefore);
3520  case Instruction::InsertValue:
3521  return InsertValueInst::Create(Ops[0], Ops[1], getIndices(), "",
3522  InsertBefore);
3523  case Instruction::ShuffleVector:
3524  return new ShuffleVectorInst(Ops[0], Ops[1], getShuffleMask(), "",
3525  InsertBefore);
3526 
3527  case Instruction::GetElementPtr: {
3528  const auto *GO = cast<GEPOperator>(this);
3529  if (GO->isInBounds())
3531  GO->getSourceElementType(), Ops[0], Ops.slice(1), "", InsertBefore);
3532  return GetElementPtrInst::Create(GO->getSourceElementType(), Ops[0],
3533  Ops.slice(1), "", InsertBefore);
3534  }
3535  case Instruction::ICmp:
3536  case Instruction::FCmp:
3538  (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1],
3539  "", InsertBefore);
3540  case Instruction::FNeg:
3542  InsertBefore);
3543  default:
3544  assert(getNumOperands() == 2 && "Must be binary operator?");
3546  (Instruction::BinaryOps)getOpcode(), Ops[0], Ops[1], "", InsertBefore);
3547  if (isa<OverflowingBinaryOperator>(BO)) {
3552  }
3553  if (isa<PossiblyExactOperator>(BO))
3555  return BO;
3556  }
3557 }
i
i
Definition: README.txt:29
llvm::lltok::APFloat
@ APFloat
Definition: LLToken.h:437
llvm::CmpInst::FCMP_ULE
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:734
llvm::Type::ArrayTyID
@ ArrayTyID
Arrays.
Definition: Type.h:75
llvm::LLVMContext::pImpl
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:70
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
llvm::Constant::isAllOnesValue
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
Definition: Constants.cpp:93
llvm::Value::const_user_iterator
user_iterator_impl< const User > const_user_iterator
Definition: Value.h:391
llvm::Value::stripPointerCastsAndAliases
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:686
MathExtras.h
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
llvm::Constant::isFiniteNonZeroFP
bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector c...
Definition: Constants.cpp:200
GlobalIFunc.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::ConstantDataSequential::getElementByteSize
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
Definition: Constants.cpp:2939
llvm::Constant::isNormalFP
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
Definition: Constants.cpp:221
llvm::Constant::isNaN
bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
Definition: Constants.cpp:263
llvm::ConstantExpr::getFDiv
static Constant * getFDiv(Constant *C1, Constant *C2)
Definition: Constants.cpp:2733
llvm::Type::getInt1Ty
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:236
llvm::ConstantExpr::getExtractElement
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2576
llvm::deleteConstant
void deleteConstant(Constant *C)
Definition: Constants.cpp:490
llvm::CmpInst::ICMP_EQ
@ ICMP_EQ
equal
Definition: InstrTypes.h:740
llvm::LLVMContextImpl::BlockAddresses
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
Definition: LLVMContextImpl.h:1450
llvm::ConstantExpr::getNot
static Constant * getNot(Constant *C)
Definition: Constants.cpp:2684
llvm::StructType::get
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:406
llvm::ConstantFP::isValueValidForType
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
Definition: Constants.cpp:1586
llvm::ARMII::VecSize
@ VecSize
Definition: ARMBaseInfo.h:421
llvm::ConstantExpr::getZExtOrBitCast
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:2040
llvm::Instruction::UnaryOps
UnaryOps
Definition: Instruction.h:779
llvm::ConstantExpr::getSIToFP
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2196
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:719
llvm::User::operands
op_range operands()
Definition: User.h:242
llvm::Value::SubclassOptionalData
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:90
llvm::Constant::containsPoisonElement
bool containsPoisonElement() const
Return true if this is a vector constant that includes any poison elements.
Definition: Constants.cpp:335
llvm::ConstantExpr::getOpcodeName
const char * getOpcodeName() const
Return a string representation for an opcode.
Definition: Constants.cpp:2877
llvm::ConstantAggregateZero::getSequentialElement
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
Definition: Constants.cpp:1109
isAllZeros
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
Definition: Constants.cpp:2951
llvm::ElementCount
Definition: TypeSize.h:404
llvm::APFloatBase::IEEEsingle
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:170
llvm::ConstantUniqueMap::replaceOperandsInPlace
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
Definition: ConstantsContext.h:708
llvm::LLVMContextImpl::FPConstants
FPMapTy FPConstants
Definition: LLVMContextImpl.h:1407
llvm::ConstantExpr::getZExt
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2147
T
llvm::Function
Definition: Function.h:60
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:236
llvm::Instruction::isCast
bool isCast() const
Definition: Instruction.h:165
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1353
llvm::LLVMContextImpl::UVConstants
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
Definition: LLVMContextImpl.h:1443
llvm::ConstantExpr::getAsInstruction
Instruction * getAsInstruction(Instruction *InsertBefore=nullptr) const
Returns an Instruction which implements the same operation as this ConstantExpr.
Definition: Constants.cpp:3494
rangeOnlyContains
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
Definition: Constants.cpp:1206
llvm::ConstantExpr::getFRem
static Constant * getFRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2745
llvm::APInt::isPowerOf2
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Definition: APInt.h:425
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition: Type.cpp:727
llvm::ConstantExpr::getFPCast
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
Definition: Constants.cpp:2107
C1
instcombine should handle this C2 when C1
Definition: README.txt:263
llvm::ConstantFoldSelectInstruction
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
Definition: ConstantFold.cpp:521
GetElementPtrTypeIterator.h
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:309
llvm::ConstantExpr::getOpcode
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Definition: Constants.h:1302
llvm::PoisonValue::getSequentialElement
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
Definition: Constants.cpp:1179
llvm::ConstantExpr::getSExt
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2133
uses
This might compile to this xmm1 xorps xmm0 movss xmm0 ret Now consider if the code caused xmm1 to get spilled This might produce this xmm1 movaps xmm0 movaps xmm1 movss xmm0 ret since the reload is only used by these we could fold it into the uses
Definition: README-SSE.txt:258
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::ConstantExpr::getICmp
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
Definition: Constants.cpp:2526
llvm::PoisonValue::getElementValue
PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
Definition: Constants.cpp:1189
llvm::CmpInst::FCMP_ONE
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:727
llvm::Type::getFltSemantics
const fltSemantics & getFltSemantics() const
Definition: Type.cpp:67
llvm::ConstantDataSequential::getElementAsInteger
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Definition: Constants.cpp:3189
llvm::getSplatValue
Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
Definition: VectorUtils.cpp:371
ErrorHandling.h
llvm::ConstantExpr::getPredicate
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
Definition: Constants.cpp:1499
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:729
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:3567
llvm::InsertValueInst::Create
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:2548
llvm::CastInst::Create
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Definition: Instructions.cpp:3182
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:682
llvm::ConstantAggregate
Base class for aggregate constants (with operands).
Definition: Constants.h:386
llvm::CmpInst::ICMP_NE
@ ICMP_NE
not equal
Definition: InstrTypes.h:741
llvm::ConstantExpr::getBitCast
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2257
R600_InstFlag::FC
@ FC
Definition: R600Defines.h:32
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:2602
llvm::LLVMContextImpl::ExprConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
Definition: LLVMContextImpl.h:1456
llvm::BlockAddress::getBasicBlock
BasicBlock * getBasicBlock() const
Definition: Constants.h:878
memcmp
Merge contiguous icmps into a memcmp
Definition: MergeICmps.cpp:899
llvm::ConstantFP::getInfinity
static Constant * getInfinity(Type *Ty, bool Negative=false)
Definition: Constants.cpp:1080
llvm::ConstantExpr::getSelect
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
Definition: Constants.cpp:2444
llvm::Type::getTypeID
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
llvm::ConstantExpr::getInsertValue
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2647
llvm::ConstantExpr::getSExtOrTrunc
static Constant * getSExtOrTrunc(Constant *C, Type *Ty)
Create either an sext, trunc or nothing, depending on whether Ty is wider, narrower or the same as C-...
Definition: Constants.cpp:2058
llvm::APFloatBase::x87DoubleExtended
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
Definition: APFloat.cpp:179
llvm::Type::isFPOrFPVectorTy
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:179
IT
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
llvm::ConstantDataVector::get
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
Definition: Constants.cpp:3081
llvm::ConstantDataSequential::getElementAsFloat
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
Definition: Constants.cpp:3262
llvm::InsertElementInst::Create
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1937
llvm::ConstantAggregateZero::getElementCount
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Definition: Constants.cpp:1131
llvm::ConstantExpr::getOffsetOf
static Constant * getOffsetOf(StructType *STy, unsigned FieldNo)
getOffsetOf constant expr - computes the offset of a struct field in a target independent way (Note: ...
Definition: Constants.cpp:2404
llvm::CmpInst::ICMP_SGT
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:746
llvm::StringMap::end
iterator end()
Definition: StringMap.h:205
llvm::ExtractElementInst::Create
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1872
llvm::GetElementPtrConstantExpr
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Definition: ConstantsContext.h:245
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::NoCFIValue
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
Definition: Constants.h:932
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1411
llvm::APFloatBase::BFloat
static const fltSemantics & BFloat() LLVM_READNONE
Definition: APFloat.cpp:167
llvm::Constant::isNotOneValue
bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
Definition: Constants.cpp:127
llvm::ConstantExpr::hasIndices
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
Definition: Constants.cpp:1491
llvm::ConstantDataSequential::isElementTypeCompatible
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
Definition: Constants.cpp:2916
llvm::ConstantExpr::getFPToSI
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2218
llvm::ConstantAggregateZero
All zero aggregate value.
Definition: Constants.h:337
llvm::Constant::needsDynamicRelocation
bool needsDynamicRelocation() const
Definition: Constants.cpp:660
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1668
llvm::Constant::needsRelocation
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry (eith...
Definition: Constants.cpp:664
llvm::Instruction::setHasNoUnsignedWrap
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
Definition: Instruction.cpp:123
llvm::Optional< unsigned >
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
Operator.h
llvm::VectorType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:422
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:2073
llvm::CmpInst::ICMP_SLE
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:749
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::ConstantExpr::getExactLogBase2
static Constant * getExactLogBase2(Constant *C)
If C is a scalar/fixed width vector of known powers of 2, then this function returns a new scalar/fix...
Definition: Constants.cpp:2783
llvm::APFloat::getSNaN
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
Definition: APFloat.h:924
STLExtras.h
llvm::SmallVectorImpl::pop_back_val
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:654
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:357
llvm::StringMap::find
iterator find(StringRef Key)
Definition: StringMap.h:218
llvm::gep_type_begin
gep_type_iterator gep_type_begin(const User *GEP)
Definition: GetElementPtrTypeIterator.h:123
llvm::ConstantFP::getNegativeZero
static Constant * getNegativeZero(Type *Ty)
Definition: Constants.h:293
llvm::Type::isFloatingPointTy
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:163
llvm::Constant::isOneValue
bool isOneValue() const
Returns true if the value is one.
Definition: Constants.cpp:110
llvm::Instruction::setIsExact
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Definition: Instruction.cpp:131
llvm::CmpInst::FCMP_OGT
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:723
llvm::ConstantDataSequential::isString
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
Definition: Constants.cpp:3282
llvm::APFloat::getSemantics
const fltSemantics & getSemantics() const
Definition: APFloat.h:1223
llvm::LLVMContextImpl::DSOLocalEquivalents
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
Definition: LLVMContextImpl.h:1452
llvm::Type::getInt8Ty
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:237
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:239
llvm::Constant::isThreadDependent
bool isThreadDependent() const
Return true if the value can vary between threads.
Definition: Constants.cpp:634
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:161
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:75
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::ConstantExpr::getWithOperands
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
Definition: Constants.h:1328
getFPSequenceIfElementsMatch
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
Definition: Constants.cpp:1227
llvm::ConstantExpr::getPointerCast
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:2069
llvm::LLVMContextImpl::TheNoneToken
std::unique_ptr< ConstantTokenNone > TheNoneToken
Definition: LLVMContextImpl.h:1469
llvm::APFloatBase::IEEEquad
static const fltSemantics & IEEEquad() LLVM_READNONE
Definition: APFloat.cpp:176
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::lltok::equal
@ equal
Definition: LLToken.h:25
llvm::LLVMContextImpl::ArrayConstants
ArrayConstantsTy ArrayConstants
Definition: LLVMContextImpl.h:1433
llvm::gep_type_end
gep_type_iterator gep_type_end(const User *GEP)
Definition: GetElementPtrTypeIterator.h:130
isUndef
static bool isUndef(ArrayRef< int > Mask)
Definition: HexagonISelDAGToDAGHVX.cpp:909
llvm::CmpInst::FCMP_ULT
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:733
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::ConstantExpr::getSub
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2701
llvm::ConstantDataSequential::getElementAsAPFloat
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
Definition: Constants.cpp:3237
llvm::ConstantData
Base class for constants with no operands.
Definition: Constants.h:51
llvm::AVR::getAddressSpace
AddressSpace getAddressSpace(T *V)
Definition: AVR.h:64
llvm::ConstantPointerNull
A constant pointer value that points to null.
Definition: Constants.h:535
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::PatternMatch::m_APInt
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
Definition: PatternMatch.h:272
llvm::ConstantExpr::getBinOpIdentity
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
Definition: Constants.cpp:2812
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::APFloat::getZero
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:885
llvm::PointerType::isOpaqueOrPointeeTypeMatches
bool isOpaqueOrPointeeTypeMatches(Type *Ty)
Return true if either this is an opaque pointer type or if this pointee type matches Ty.
Definition: DerivedTypes.h:688
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::Type::isArrayTy
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition: Type.h:215
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1375
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:1617
llvm::SelectInst::Create
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Definition: Instructions.h:1755
llvm::ConstantExpr::getShuffleMask
ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
Definition: Constants.cpp:1503
GlobalValue.h
llvm::OperandTraits
Compile-time customization of User operands.
Definition: User.h:42
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:418
llvm::Constant::containsConstantExpression
bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
Definition: Constants.cpp:340
llvm::CmpInst::isFPPredicate
bool isFPPredicate() const
Definition: InstrTypes.h:826
Constants.h
llvm::PatternMatch::match
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
isZero
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition: Lint.cpp:524
llvm::Constant::isNullValue
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:76
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:667
llvm::APFloatBase::IEEEhalf
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:164
llvm::Instruction::setHasNoSignedWrap
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
Definition: Instruction.cpp:127
llvm::User
Definition: User.h:44
llvm::UndefValue::getElementValue
UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
Definition: Constants.cpp:1154
llvm::Type::getDoubleTy
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:227
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
ItTy
llvm::CmpInst::ICMP_ULE
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:745
llvm::LLVMContextImpl
Definition: LLVMContextImpl.h:1354
llvm::ConstantExpr::getIntToPtr
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2243
llvm::LLVMContextImpl::CAZConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
Definition: LLVMContextImpl.h:1430
llvm::UnaryConstantExpr
UnaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implemen...
Definition: ConstantsContext.h:46
llvm::VectorType::getInteger
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
Definition: DerivedTypes.h:440
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
llvm::ConstantExpr::getUDiv
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2723
llvm::CmpInst::FCMP_UGE
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:732
llvm::ConstantExpr::getPtrToInt
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2229
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::Instruction::OtherOps
OtherOps
Definition: Instruction.h:814
llvm::APInt::getAllOnes
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition: APInt.h:214
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::Type::isVectorTy
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:227
llvm::VectorType::getElementCount
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:627
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::ConstantExpr::getBinOpAbsorber
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty)
Return the absorbing element for the given binary operation, i.e.
Definition: Constants.cpp:2857
llvm::Value::getValueID
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
llvm::isUIntN
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:455
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::Instruction::getOpcodeName
const char * getOpcodeName() const
Definition: Instruction.h:159
llvm::Instruction::CastOps
CastOps
Definition: Instruction.h:800
llvm::ConstantArray
ConstantArray - Constant Array Declarations.
Definition: Constants.h:410
llvm::Constant::getAllOnesValue
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:395
llvm::CmpInst::FCMP_UNO
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:729
llvm::Instruction
Definition: Instruction.h:42
containsUndefinedElement
static bool containsUndefinedElement(const Constant *C, function_ref< bool(const Constant *)> HasFn)
Definition: Constants.cpp:309
llvm::ConstantDataVector::getSplatValue
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
Definition: Constants.cpp:3319
llvm::Type::getScalarSizeInBits
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition: Type.cpp:189
LLVMContextImpl.h
llvm::APFloat::bitwiseIsEqual
bool bitwiseIsEqual(const APFloat &RHS) const
Definition: APFloat.h:1180
llvm::InsertValueConstantExpr
InsertValueConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to im...
Definition: ConstantsContext.h:215
llvm::ConstantFoldGetElementPtr
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
Definition: ConstantFold.cpp:2022
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
llvm::ConstantVector::getSplat
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Definition: Constants.cpp:1438
llvm::ConstantFP::isExactlyValue
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition: Constants.cpp:1096
llvm::ShuffleVectorConstantExpr
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Definition: ConstantsContext.h:179
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1768
llvm::ConstantExpr::getXor
static Constant * getXor(Constant *C1, Constant *C2)
Definition: Constants.cpp:2757
llvm::ConstantExpr::getURem
static Constant * getURem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2737
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:926
llvm::OverflowingBinaryOperator::NoSignedWrap
@ NoSignedWrap
Definition: Operator.h:77
llvm::CmpInst::FCMP_OEQ
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:722
llvm::OverflowingBinaryOperator::NoUnsignedWrap
@ NoUnsignedWrap
Definition: Operator.h:76
llvm::ConstantDataSequential::getImpl
static Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
Definition: Constants.cpp:2962
llvm::CmpInst::FCMP_OLT
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:725
llvm::PoisonValue::getStructElement
PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
Definition: Constants.cpp:1185
StringMap.h
llvm::Type::PointerTyID
@ PointerTyID
Pointers.
Definition: Type.h:73
PatternMatch.h
llvm::ConstantStruct::getType
StructType * getType() const
Specialization - reduce amount of casting.
Definition: Constants.h:481
llvm::ConstantAggregate::ConstantAggregate
ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V)
Definition: Constants.cpp:1266
llvm::FixedVectorType::get
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:684
getSequenceIfElementsMatch
static Constant * getSequenceIfElementsMatch(Constant *C, ArrayRef< Constant * > V)
Definition: Constants.cpp:1240
llvm::PointerType::isOpaque
bool isOpaque() const
Definition: DerivedTypes.h:673
llvm::Type::BFloatTyID
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
llvm::Constant::isMinSignedValue
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
Definition: Constants.cpp:155
llvm::LLVMContextImpl::CDSConstants
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
Definition: LLVMContextImpl.h:1447
llvm::isIntN
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:460
llvm::SelectConstantExpr
SelectConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
Definition: ConstantsContext.h:97
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:194
llvm::UndefValue::getNumElements
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
Definition: Constants.cpp:1166
llvm::ConstantFP::getSNaN
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constants.cpp:1036
llvm::None
const NoneType None
Definition: None.h:24
llvm::LinearPolySize< ElementCount >::getFixed
static ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:283
llvm::Type::getIntegerBitWidth
unsigned getIntegerBitWidth() const
Definition: DerivedTypes.h:97
llvm::ConstantExpr::getFNeg
static Constant * getFNeg(Constant *C)
Definition: Constants.cpp:2678
llvm::ConstantExpr::isCompare
bool isCompare() const
Return true if this is a compare constant expression.
Definition: Constants.cpp:1487
llvm::ConstantExpr::getShuffleMaskForBitcode
Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
Definition: Constants.cpp:1507
llvm::ConstantFoldBinaryInstruction
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
Definition: ConstantFold.cpp:872
llvm::ConstantFoldExtractElementInstruction
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
Definition: ConstantFold.cpp:610
llvm::PatternMatch::m_One
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
Definition: PatternMatch.h:511
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::Instruction::isCommutative
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
Definition: Instruction.cpp:770
llvm::CmpInst::FCMP_FALSE
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition: InstrTypes.h:721
llvm::ConstantExpr::getAShr
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2778
llvm::Type::getStructNumElements
unsigned getStructNumElements() const
Definition: DerivedTypes.h:348
llvm::ConstantDataSequential::isCString
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
Definition: Constants.cpp:3286
llvm::ConstantFoldCastInstruction
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Definition: ConstantFold.cpp:350
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:191
llvm::APFloat::getQNaN
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition: APFloat.h:916
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::ConstantExpr::isCast
bool isCast() const
Return true if this is a convert constant expression.
Definition: Constants.cpp:1483
llvm::ConstantExpr::getShuffleVector
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2621
llvm::ConstantArray::getType
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Definition: Constants.h:429
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:389
llvm::ConstantExpr::getTrunc
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2119
BasicBlock.h
llvm::ConstantDataSequential::getRawDataValues
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
Definition: Constants.cpp:2912
llvm::APFloat
Definition: APFloat.h:701
llvm::ConstantVector::getType
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Definition: Constants.h:517
llvm::Constant::isDLLImportDependent
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
Definition: Constants.cpp:641
llvm::ConstantExpr::getCompare
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
Definition: Constants.cpp:2422
llvm::Constant::hasZeroLiveUses
bool hasZeroLiveUses() const
Return true if the constant has no live uses.
Definition: Constants.cpp:778
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:240
llvm::ConstantFP::getQNaN
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constants.cpp:1025
llvm::PPC::Predicate
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:26
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::ConstantFoldCompareInstruction
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
Definition: ConstantFold.cpp:1572
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::Value::mutateType
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
Definition: Value.h:801
llvm::PointerType::getUnqual
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:651
llvm::LLVMContextImpl::CPNConstants
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
Definition: LLVMContextImpl.h:1441
llvm::Constant::isElementWiseEqual
bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
Definition: Constants.cpp:284
getFoldedCast
static Constant * getFoldedCast(Instruction::CastOps opc, Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is a utility function to handle folding of casts and lookup of the cast in the ExprConstants map...
Definition: Constants.cpp:1983
llvm::Constant::replaceUndefsWith
static Constant * replaceUndefsWith(Constant *C, Constant *Replacement)
Try to replace undefined constant C or undefined elements in C with Replacement.
Definition: Constants.cpp:794
llvm::ConstantDataVector::getFP
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
Definition: Constants.cpp:3118
uint64_t
llvm::ConstantFoldInsertValueInstruction
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
Definition: ConstantFold.cpp:787
llvm::ConstantFP::getZero
static Constant * getZero(Type *Ty, bool Negative=false)
Definition: Constants.cpp:1047
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::ConstantExpr::getIndices
ArrayRef< unsigned > getIndices() const
Assert that this is an insertvalue or exactvalue expression and return the list of indices.
Definition: Constants.cpp:1495
llvm::LLVMContextImpl::TheFalseVal
ConstantInt * TheFalseVal
Definition: LLVMContextImpl.h:1461
llvm::ConstantExpr::getAddrSpaceCast
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2269
llvm::APInt::logBase2
unsigned logBase2() const
Definition: APInt.h:1652
llvm::ConstantPointerNull::get
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1754
llvm::ConstantDataArray
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Definition: Constants.h:679
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DSOLocalEquivalent::getGlobalValue
GlobalValue * getGlobalValue() const
Definition: Constants.h:914
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::ConstantDataVector::isSplat
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
Definition: Constants.cpp:3311
llvm::GetElementPtrConstantExpr::getSourceElementType
Type * getSourceElementType() const
Definition: Constants.cpp:2895
llvm::ConstantExpr::get
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.
Definition: Constants.cpp:2291
llvm::ConstantExpr::getAlignOf
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
Definition: Constants.cpp:2391
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::ConstantDataVector
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Definition: Constants.h:753
llvm::UndefValue
'undef' values are things that do not have specified contents.
Definition: Constants.h:1384
llvm::GetElementPtrInst
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:916
llvm::ConstantExpr::getShl
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2766
llvm::ConstantExpr::getFSub
static Constant * getFSub(Constant *C1, Constant *C2)
Definition: Constants.cpp:2708
llvm::ConstantExpr::getOr
static Constant * getOr(Constant *C1, Constant *C2)
Definition: Constants.cpp:2753
getIntSequenceIfElementsMatch
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
Definition: Constants.cpp:1214
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:632
llvm::ConstantDataSequential::getElementType
Type * getElementType() const
Return the element type of the array/vector.
Definition: Constants.cpp:2906
llvm::ConstantUniqueMap::getOrCreate
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
Definition: ConstantsContext.h:683
llvm::Type::isHalfTy
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:142
llvm::GetElementPtrInst::CreateInBounds
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Definition: Instructions.h:969
llvm::Constant::hasOneLiveUse
bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
Definition: Constants.cpp:776
llvm::CompareConstantExpr
Definition: ConstantsContext.h:279
llvm::ConstantVector
Constant Vector Declarations.
Definition: Constants.h:494
llvm::APFloatBase::PPCDoubleDouble
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Definition: APFloat.cpp:185
llvm::ConstantFoldInsertElementInstruction
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
Definition: ConstantFold.cpp:674
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ConstantDataSequential::getElementAsConstant
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
Definition: Constants.cpp:3274
llvm::Constant::isNegativeZeroValue
bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
Definition: Constants.cpp:42
llvm::Constant::isManifestConstant
bool isManifestConstant() const
Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only Co...
Definition: Constants.cpp:853
llvm::CmpInst::FCMP_OGE
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:724
llvm::ConstantExpr::getCast
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Definition: Constants.cpp:2001
llvm::LLVMContextImpl::TheTrueVal
ConstantInt * TheTrueVal
Definition: LLVMContextImpl.h:1460
llvm::CmpInst::ICMP_UGE
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:743
llvm::ConstantFP::getZeroValueForNegation
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
Definition: Constants.cpp:1058
llvm::ConstantAggregateZero::getElementValue
Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e....
Definition: Constants.cpp:1119
llvm::Instruction::isBinaryOp
bool isBinaryOp() const
Definition: Instruction.h:162
llvm::ConstantVector::getSplatValue
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
Definition: Constants.cpp:1715
llvm::ArrayType::get
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:638
llvm::ConstantFP::getNaN
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
Definition: Constants.cpp:1014
llvm::Constant::handleOperandChange
void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
Definition: Constants.cpp:3338
llvm::ConstantExpr::getTruncOrBitCast
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:2052
llvm::ConstantStruct
Definition: Constants.h:442
llvm::ConstantExpr::getSizeOf
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
Definition: Constants.cpp:2381
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::User::setOperand
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
llvm::CmpInst::ICMP_SLT
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:748
llvm::CmpInst::isIntPredicate
bool isIntPredicate() const
Definition: InstrTypes.h:827
llvm::Type::FP128TyID
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
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:1598
llvm::LLVMContextImpl::IntConstants
IntMapTy IntConstants
Definition: LLVMContextImpl.h:1403
llvm::GetElementPtrInst::Create
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:942
llvm::Value::ValueTy
ValueTy
Concrete subclass of this.
Definition: Value.h:513
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:849
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::Constant::removeDeadConstantUsers
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:749
llvm::BinaryOperator
Definition: InstrTypes.h:188
Mul
BinaryOperator * Mul
Definition: X86PartialReduction.cpp:70
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:213
llvm::APFloatBase::IEEEdouble
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:173
llvm::Type::PPC_FP128TyID
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm::User::getOperandList
const Use * getOperandList() const
Definition: User.h:162
llvm::PatternMatch::m_Undef
auto m_Undef()
Match an arbitrary undef constant.
Definition: PatternMatch.h:136
llvm::ConstantExpr::getSExtOrBitCast
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:2046
llvm::ConstantExpr::getUMin
static Constant * getUMin(Constant *C1, Constant *C2)
Definition: Constants.cpp:2761
llvm::CmpInst::ICMP_ULT
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:744
llvm::ConstantDataSequential::getElementAsAPInt
APInt getElementAsAPInt(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
Definition: Constants.cpp:3209
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Constant::getAggregateElement
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Definition: Constants.cpp:410
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition: Constants.h:692
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:529
uint32_t
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:991
llvm::LLVMContextImpl::StructConstants
StructConstantsTy StructConstants
Definition: LLVMContextImpl.h:1436
llvm::ConstantExpr::getInsertElement
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2598
llvm::ConstantDataArray::getString
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:3065
llvm::ReplaceableMetadataImpl::SalvageDebugInfo
static void SalvageDebugInfo(const Constant &C)
Replace all uses of the constant with Undef in debug info metadata.
Definition: Metadata.cpp:248
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::LLVMContextImpl::PVConstants
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
Definition: LLVMContextImpl.h:1445
llvm::ConstantExpr::getIntegerCast
static Constant * getIntegerCast(Constant *C, Type *Ty, bool IsSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:2095
llvm::ConstantExprKeyType
Definition: ConstantsContext.h:469
llvm::ConstantVector::get
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1395
llvm::Type::isPtrOrPtrVectorTy
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:224
llvm::ConstantExpr::getFMul
static Constant * getFMul(Constant *C1, Constant *C2)
Definition: Constants.cpp:2719
llvm::ifs::IFSSymbolType::Func
@ Func
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:280
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::ArrayRef::front
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:167
users
iv users
Definition: IVUsers.cpp:48
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:682
llvm::ConstantInt::getFalse
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:881
llvm::ConstantExpr::getFCmp
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
Definition: Constants.cpp:2551
ConstantFold.h
llvm::Type::IntegerTyID
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
llvm::ConstantDataArray::getFP
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
Definition: Constants.cpp:3044
llvm::ConstantAggregateZero::getStructElement
Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
Definition: Constants.cpp:1115
llvm::MCID::Select
@ Select
Definition: MCInstrDesc.h:164
llvm::NoCFIValue::get
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
Definition: Constants.cpp:1937
llvm::CmpInst::FCMP_UGT
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:731
llvm::BlockAddress::getFunction
Function * getFunction() const
Definition: Constants.h:877
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::UndefValue::getSequentialElement
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
Definition: Constants.cpp:1144
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:972
constantIsDead
static bool constantIsDead(const Constant *C, bool RemoveDeadUsers)
Return true if the specified constantexpr is dead.
Definition: Constants.cpp:720
llvm::ConstantExpr::getSDiv
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2728
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:874
llvm::Constant::getNullValue
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:350
llvm::PointerType::hasSameElementTypeAs
bool hasSameElementTypeAs(PointerType *Other)
Return true if both pointer types have the same element type.
Definition: DerivedTypes.h:696
llvm::Type::isFloatTy
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:148
uint16_t
llvm::ConstantExpr::getNeg
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2671
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
NC
#define NC
Definition: regutils.h:42
llvm::ConstantDataSequential::getElementAsDouble
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
Definition: Constants.cpp:3268
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::ConstantInt::getBool
static ConstantInt * getBool(LLVMContext &Context, bool V)
Definition: Constants.cpp:888
llvm::Type::FixedVectorTyID
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
llvm::Constant::isZeroValue
bool isZeroValue() const
Return true if the value is negative zero or null value.
Definition: Constants.cpp:62
llvm::ConstantExpr::getAdd
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2690
llvm::Type::isIntOrIntVectorTy
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:197
GlobalVariable.h
llvm::ConstantFP::get
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:973
llvm::ConstantTokenNone::get
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
Definition: Constants.cpp:1468
llvm::ConstantInt::getSigned
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.cpp:940
llvm::fltSemantics
Definition: APFloat.cpp:54
Function.h
getTypeID
static char getTypeID(Type *Ty)
Definition: ExternalFunctions.cpp:73
llvm::ConstantExpr::getAnd
static Constant * getAnd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2749
llvm::ConstantFoldShuffleVectorInstruction
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
Definition: ConstantFold.cpp:716
llvm::UndefValue::getStructElement
UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
Definition: Constants.cpp:1150
llvm::Type::getPointerTo
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Definition: Type.cpp:774
llvm::Type::TokenTyID
@ TokenTyID
Tokens.
Definition: Type.h:68
llvm::Type::isDoubleTy
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:151
ConstHasGlobalValuePredicate
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
Definition: Constants.cpp:611
llvm::ConstantArray::get
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1288
llvm::ConstantExpr::getGetElementPtr
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Definition: Constants.h:1247
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:1790
llvm::ConstantExpr::getLShr
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2773
llvm::ConstantUniqueMap::remove
void remove(ConstantClass *CP)
Remove this constant from the map.
Definition: ConstantsContext.h:701
llvm::ConstantExpr::getFPTrunc
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2161
llvm::CmpInst::ICMP_SGE
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:747
llvm::ConstantExpr::getFPToUI
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2207
llvm::MCID::Add
@ Add
Definition: MCInstrDesc.h:185
GlobalAlias.h
llvm::CmpInst::Create
static CmpInst * Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
Definition: Instructions.cpp:3853
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::Constant::mergeUndefsWith
static Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
Definition: Constants.cpp:818
llvm::APFloat::getAllOnesValue
static APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
Definition: APFloat.cpp:4868
llvm::Instruction::BinaryOps
BinaryOps
Definition: Instruction.h:786
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition: Type.h:74
llvm::GetElementPtrConstantExpr::getResultElementType
Type * getResultElementType() const
Definition: Constants.cpp:2899
llvm::ShuffleVectorInst
This instruction constructs a fixed permutation of two input vectors.
Definition: Instructions.h:1995
llvm::APFloatBase::rmNearestTiesToEven
static constexpr roundingMode rmNearestTiesToEven
Definition: APFloat.h:190
llvm::UnaryOperator::Create
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
Definition: Instructions.cpp:2649
Instructions.h
llvm::APFloat::convert
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4843
llvm::Constant::getIntegerValue
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
Definition: Constants.cpp:378
llvm::Constant::hasExactInverseFP
bool hasExactInverseFP() const
Return true if this scalar has an exact multiplicative inverse or this vector has an exact multiplica...
Definition: Constants.cpp:242
llvm::User::getNumOperands
unsigned getNumOperands() const
Definition: User.h:191
llvm::Type::isStructTy
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:212
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Definition: Constants.cpp:2084
llvm::ConstantExpr::getSRem
static Constant * getSRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2741
llvm::InsertElementConstantExpr
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Definition: ConstantsContext.h:151
canTrapImpl
static bool canTrapImpl(const Constant *C, SmallPtrSetImpl< const Constant * > &NonTrappingOps)
Definition: Constants.cpp:564
SmallVector.h
llvm::Type::isBFloatTy
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
Definition: Type.h:145
llvm::Constant::getUniqueInteger
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
Definition: Constants.cpp:1742
llvm::ConstantExpr::getFPExtend
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2173
llvm::Value::stripInBoundsConstantOffsets
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Definition: Value.cpp:694
llvm::CmpInst::ICMP_UGT
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:742
llvm::User::op_begin
op_iterator op_begin()
Definition: User.h:234
llvm::PointerType::getWithSamePointeeType
static PointerType * getWithSamePointeeType(PointerType *PT, unsigned AddressSpace)
This constructs a pointer type with the same pointee type as input PointerType (or opaque pointer if ...
Definition: DerivedTypes.h:666
llvm::CmpInst::FCMP_UNE
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:735
llvm::Constant::containsUndefOrPoisonElement
bool containsUndefOrPoisonElement() const
Return true if this is a vector constant that includes any undef or poison elements.
Definition: Constants.cpp:330
llvm::ConstantDataVector::getSplat
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Definition: Constants.cpp:3142
N
#define N
llvm::BinaryConstantExpr
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
Definition: ConstantsContext.h:70
llvm::Constant::canTrap
bool canTrap() const
Return true if evaluation of this constant could trap.
Definition: Constants.cpp:604
llvm::BlockAddress::get
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1806
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::IntegerType::getBitWidth
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:72
llvm::ConstantInt::isValueValidForType
static bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
Definition: Constants.cpp:1572
llvm::ConstantExpr::getMul
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2712
llvm::Instruction::isUnaryOp
bool isUnaryOp() const
Definition: Instruction.h:161
llvm::APFloat::getNaN
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition: APFloat.h:905
llvm::Constant::getSplatValue
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
Definition: Constants.cpp:1683
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::CmpInst::FCMP_OLE
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:726
llvm::LLVMContextImpl::VectorConstants
VectorConstantsTy VectorConstants
Definition: LLVMContextImpl.h:1439
llvm::ConstantStruct::getTypeForElements
static StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct type to use for a constant with the specified set of elements.
Definition: Constants.cpp:1339
llvm::NoCFIValue::getGlobalValue
GlobalValue * getGlobalValue() const
Definition: Constants.h:949
llvm::Type::getInt16Ty
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:238
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:276
DerivedTypes.h
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
pred
hexagon gen pred
Definition: HexagonGenPredicate.cpp:134
llvm::Constant::isNotMinSignedValue
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
Definition: Constants.cpp:172
llvm::IntegerType::get
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
llvm::APFloat::getInf
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition: APFloat.h:894
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
GEP
Hexagon Common GEP
Definition: HexagonCommonGEP.cpp:171
llvm::User::Op
Use & Op()
Definition: User.h:133
llvm::BlockAddress::lookup
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Definition: Constants.cpp:1824
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::ConstantPointerNull::getType
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
Definition: Constants.h:551
llvm::Constant::isConstantUsed
bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things.
Definition: Constants.cpp:648
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::ConstantDataSequential::getAsString
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
Definition: Constants.h:645
raw_ostream.h
llvm::ConstantFoldUnaryInstruction
Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
Definition: ConstantFold.cpp:816
llvm::ConstantExpr::getFAdd
static Constant * getFAdd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2697
llvm::LLVMContextImpl::NoCFIValues
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
Definition: LLVMContextImpl.h:1454
llvm::ConstantAggregateZero::get
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1647
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:644
llvm::BinaryOperator::Create
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
Definition: Instructions.cpp:2778
llvm::CmpInst::FCMP_TRUE
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition: InstrTypes.h:736
llvm::ConstantTokenNone
A constant token which is empty.
Definition: Constants.h:827
llvm::PossiblyExactOperator::IsExact
@ IsExact
Definition: Operator.h:129
llvm::DSOLocalEquivalent::get
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
Definition: Constants.cpp:1879
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::DSOLocalEquivalent
Wrapper for a function that represents a value that functionally represents the original function.
Definition: Constants.h:895
llvm::VectorType::get
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:668
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
llvm::Type::X86_FP80TyID
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
llvm::Type::getFloatTy
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:226
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:153
llvm::Type::getFloatingPointTy
static Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
Definition: Type.cpp:84
llvm::ArrayType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:370
llvm::Constant::destroyConstant
void destroyConstant()
Called if some element of this constant is no longer valid.
Definition: Constants.cpp:450
llvm::CmpInst::FCMP_ORD
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:728