LLVM  16.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<CastConstantExpr>(C))
539  delete static_cast<CastConstantExpr *>(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<GetElementPtrConstantExpr>(C))
551  delete static_cast<GetElementPtrConstantExpr *>(C);
552  else if (isa<CompareConstantExpr>(C))
553  delete static_cast<CompareConstantExpr *>(C);
554  else
555  llvm_unreachable("Unexpected constant expr");
556  break;
557  default:
558  llvm_unreachable("Unexpected constant");
559  }
560 }
561 
562 /// Check if C contains a GlobalValue for which Predicate is true.
563 static bool
565  bool (*Predicate)(const GlobalValue *)) {
568  WorkList.push_back(C);
569  Visited.insert(C);
570 
571  while (!WorkList.empty()) {
572  const Constant *WorkItem = WorkList.pop_back_val();
573  if (const auto *GV = dyn_cast<GlobalValue>(WorkItem))
574  if (Predicate(GV))
575  return true;
576  for (const Value *Op : WorkItem->operands()) {
577  const Constant *ConstOp = dyn_cast<Constant>(Op);
578  if (!ConstOp)
579  continue;
580  if (Visited.insert(ConstOp).second)
581  WorkList.push_back(ConstOp);
582  }
583  }
584  return false;
585 }
586 
588  auto DLLImportPredicate = [](const GlobalValue *GV) {
589  return GV->isThreadLocal();
590  };
591  return ConstHasGlobalValuePredicate(this, DLLImportPredicate);
592 }
593 
595  auto DLLImportPredicate = [](const GlobalValue *GV) {
596  return GV->hasDLLImportStorageClass();
597  };
598  return ConstHasGlobalValuePredicate(this, DLLImportPredicate);
599 }
600 
602  for (const User *U : users()) {
603  const Constant *UC = dyn_cast<Constant>(U);
604  if (!UC || isa<GlobalValue>(UC))
605  return true;
606 
607  if (UC->isConstantUsed())
608  return true;
609  }
610  return false;
611 }
612 
614  return getRelocationInfo() == GlobalRelocation;
615 }
616 
618  return getRelocationInfo() != NoRelocation;
619 }
620 
621 Constant::PossibleRelocationsTy Constant::getRelocationInfo() const {
622  if (isa<GlobalValue>(this))
623  return GlobalRelocation; // Global reference.
624 
625  if (const BlockAddress *BA = dyn_cast<BlockAddress>(this))
626  return BA->getFunction()->getRelocationInfo();
627 
628  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) {
629  if (CE->getOpcode() == Instruction::Sub) {
630  ConstantExpr *LHS = dyn_cast<ConstantExpr>(CE->getOperand(0));
631  ConstantExpr *RHS = dyn_cast<ConstantExpr>(CE->getOperand(1));
632  if (LHS && RHS && LHS->getOpcode() == Instruction::PtrToInt &&
633  RHS->getOpcode() == Instruction::PtrToInt) {
634  Constant *LHSOp0 = LHS->getOperand(0);
635  Constant *RHSOp0 = RHS->getOperand(0);
636 
637  // While raw uses of blockaddress need to be relocated, differences
638  // between two of them don't when they are for labels in the same
639  // function. This is a common idiom when creating a table for the
640  // indirect goto extension, so we handle it efficiently here.
641  if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
642  cast<BlockAddress>(LHSOp0)->getFunction() ==
643  cast<BlockAddress>(RHSOp0)->getFunction())
644  return NoRelocation;
645 
646  // Relative pointers do not need to be dynamically relocated.
647  if (auto *RHSGV =
648  dyn_cast<GlobalValue>(RHSOp0->stripInBoundsConstantOffsets())) {
649  auto *LHS = LHSOp0->stripInBoundsConstantOffsets();
650  if (auto *LHSGV = dyn_cast<GlobalValue>(LHS)) {
651  if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
652  return LocalRelocation;
653  } else if (isa<DSOLocalEquivalent>(LHS)) {
654  if (RHSGV->isDSOLocal())
655  return LocalRelocation;
656  }
657  }
658  }
659  }
660  }
661 
662  PossibleRelocationsTy Result = NoRelocation;
663  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
664  Result =
665  std::max(cast<Constant>(getOperand(i))->getRelocationInfo(), Result);
666 
667  return Result;
668 }
669 
670 /// Return true if the specified constantexpr is dead. This involves
671 /// recursively traversing users of the constantexpr.
672 /// If RemoveDeadUsers is true, also remove dead users at the same time.
673 static bool constantIsDead(const Constant *C, bool RemoveDeadUsers) {
674  if (isa<GlobalValue>(C)) return false; // Cannot remove this
675 
676  Value::const_user_iterator I = C->user_begin(), E = C->user_end();
677  while (I != E) {
678  const Constant *User = dyn_cast<Constant>(*I);
679  if (!User) return false; // Non-constant usage;
680  if (!constantIsDead(User, RemoveDeadUsers))
681  return false; // Constant wasn't dead
682 
683  // Just removed User, so the iterator was invalidated.
684  // Since we return immediately upon finding a live user, we can always
685  // restart from user_begin().
686  if (RemoveDeadUsers)
687  I = C->user_begin();
688  else
689  ++I;
690  }
691 
692  if (RemoveDeadUsers) {
693  // If C is only used by metadata, it should not be preserved but should
694  // have its uses replaced.
696  const_cast<Constant *>(C)->destroyConstant();
697  }
698 
699  return true;
700 }
701 
703  Value::const_user_iterator I = user_begin(), E = user_end();
704  Value::const_user_iterator LastNonDeadUser = E;
705  while (I != E) {
706  const Constant *User = dyn_cast<Constant>(*I);
707  if (!User) {
708  LastNonDeadUser = I;
709  ++I;
710  continue;
711  }
712 
713  if (!constantIsDead(User, /* RemoveDeadUsers= */ true)) {
714  // If the constant wasn't dead, remember that this was the last live use
715  // and move on to the next constant.
716  LastNonDeadUser = I;
717  ++I;
718  continue;
719  }
720 
721  // If the constant was dead, then the iterator is invalidated.
722  if (LastNonDeadUser == E)
723  I = user_begin();
724  else
725  I = std::next(LastNonDeadUser);
726  }
727 }
728 
729 bool Constant::hasOneLiveUse() const { return hasNLiveUses(1); }
730 
731 bool Constant::hasZeroLiveUses() const { return hasNLiveUses(0); }
732 
733 bool Constant::hasNLiveUses(unsigned N) const {
734  unsigned NumUses = 0;
735  for (const Use &U : uses()) {
736  const Constant *User = dyn_cast<Constant>(U.getUser());
737  if (!User || !constantIsDead(User, /* RemoveDeadUsers= */ false)) {
738  ++NumUses;
739 
740  if (NumUses > N)
741  return false;
742  }
743  }
744  return NumUses == N;
745 }
746 
748  assert(C && Replacement && "Expected non-nullptr constant arguments");
749  Type *Ty = C->getType();
750  if (match(C, m_Undef())) {
751  assert(Ty == Replacement->getType() && "Expected matching types");
752  return Replacement;
753  }
754 
755  // Don't know how to deal with this constant.
756  auto *VTy = dyn_cast<FixedVectorType>(Ty);
757  if (!VTy)
758  return C;
759 
760  unsigned NumElts = VTy->getNumElements();
761  SmallVector<Constant *, 32> NewC(NumElts);
762  for (unsigned i = 0; i != NumElts; ++i) {
763  Constant *EltC = C->getAggregateElement(i);
764  assert((!EltC || EltC->getType() == Replacement->getType()) &&
765  "Expected matching types");
766  NewC[i] = EltC && match(EltC, m_Undef()) ? Replacement : EltC;
767  }
768  return ConstantVector::get(NewC);
769 }
770 
772  assert(C && Other && "Expected non-nullptr constant arguments");
773  if (match(C, m_Undef()))
774  return C;
775 
776  Type *Ty = C->getType();
777  if (match(Other, m_Undef()))
778  return UndefValue::get(Ty);
779 
780  auto *VTy = dyn_cast<FixedVectorType>(Ty);
781  if (!VTy)
782  return C;
783 
784  Type *EltTy = VTy->getElementType();
785  unsigned NumElts = VTy->getNumElements();
786  assert(isa<FixedVectorType>(Other->getType()) &&
787  cast<FixedVectorType>(Other->getType())->getNumElements() == NumElts &&
788  "Type mismatch");
789 
790  bool FoundExtraUndef = false;
791  SmallVector<Constant *, 32> NewC(NumElts);
792  for (unsigned I = 0; I != NumElts; ++I) {
793  NewC[I] = C->getAggregateElement(I);
794  Constant *OtherEltC = Other->getAggregateElement(I);
795  assert(NewC[I] && OtherEltC && "Unknown vector element");
796  if (!match(NewC[I], m_Undef()) && match(OtherEltC, m_Undef())) {
797  NewC[I] = UndefValue::get(EltTy);
798  FoundExtraUndef = true;
799  }
800  }
801  if (FoundExtraUndef)
802  return ConstantVector::get(NewC);
803  return C;
804 }
805 
807  if (isa<ConstantData>(this))
808  return true;
809  if (isa<ConstantAggregate>(this) || isa<ConstantExpr>(this)) {
810  for (const Value *Op : operand_values())
811  if (!cast<Constant>(Op)->isManifestConstant())
812  return false;
813  return true;
814  }
815  return false;
816 }
817 
818 //===----------------------------------------------------------------------===//
819 // ConstantInt
820 //===----------------------------------------------------------------------===//
821 
822 ConstantInt::ConstantInt(IntegerType *Ty, const APInt &V)
823  : ConstantData(Ty, ConstantIntVal), Val(V) {
824  assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
825 }
826 
828  LLVMContextImpl *pImpl = Context.pImpl;
829  if (!pImpl->TheTrueVal)
831  return pImpl->TheTrueVal;
832 }
833 
835  LLVMContextImpl *pImpl = Context.pImpl;
836  if (!pImpl->TheFalseVal)
838  return pImpl->TheFalseVal;
839 }
840 
842  return V ? getTrue(Context) : getFalse(Context);
843 }
844 
846  assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
848  if (auto *VTy = dyn_cast<VectorType>(Ty))
849  return ConstantVector::getSplat(VTy->getElementCount(), TrueC);
850  return TrueC;
851 }
852 
854  assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
856  if (auto *VTy = dyn_cast<VectorType>(Ty))
857  return ConstantVector::getSplat(VTy->getElementCount(), FalseC);
858  return FalseC;
859 }
860 
862  return V ? getTrue(Ty) : getFalse(Ty);
863 }
864 
865 // Get a ConstantInt from an APInt.
867  // get an existing value or the insertion position
868  LLVMContextImpl *pImpl = Context.pImpl;
869  std::unique_ptr<ConstantInt> &Slot = pImpl->IntConstants[V];
870  if (!Slot) {
871  // Get the corresponding integer type for the bit width of the value.
873  Slot.reset(new ConstantInt(ITy, V));
874  }
875  assert(Slot->getType() == IntegerType::get(Context, V.getBitWidth()));
876  return Slot.get();
877 }
878 
880  Constant *C = get(cast<IntegerType>(Ty->getScalarType()), V, isSigned);
881 
882  // For vectors, broadcast the value.
883  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
884  return ConstantVector::getSplat(VTy->getElementCount(), C);
885 
886  return C;
887 }
888 
890  return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned));
891 }
892 
894  return get(Ty, V, true);
895 }
896 
898  return get(Ty, V, true);
899 }
900 
902  ConstantInt *C = get(Ty->getContext(), V);
903  assert(C->getType() == Ty->getScalarType() &&
904  "ConstantInt type doesn't match the type implied by its value!");
905 
906  // For vectors, broadcast the value.
907  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
908  return ConstantVector::getSplat(VTy->getElementCount(), C);
909 
910  return C;
911 }
912 
914  return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
915 }
916 
917 /// Remove the constant from the constant table.
918 void ConstantInt::destroyConstantImpl() {
919  llvm_unreachable("You can't ConstantInt->destroyConstantImpl()!");
920 }
921 
922 //===----------------------------------------------------------------------===//
923 // ConstantFP
924 //===----------------------------------------------------------------------===//
925 
926 Constant *ConstantFP::get(Type *Ty, double V) {
927  LLVMContext &Context = Ty->getContext();
928 
929  APFloat FV(V);
930  bool ignored;
932  APFloat::rmNearestTiesToEven, &ignored);
933  Constant *C = get(Context, FV);
934 
935  // For vectors, broadcast the value.
936  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
937  return ConstantVector::getSplat(VTy->getElementCount(), C);
938 
939  return C;
940 }
941 
943  ConstantFP *C = get(Ty->getContext(), V);
944  assert(C->getType() == Ty->getScalarType() &&
945  "ConstantFP type doesn't match the type implied by its value!");
946 
947  // For vectors, broadcast the value.
948  if (auto *VTy = dyn_cast<VectorType>(Ty))
949  return ConstantVector::getSplat(VTy->getElementCount(), C);
950 
951  return C;
952 }
953 
955  LLVMContext &Context = Ty->getContext();
956 
957  APFloat FV(Ty->getScalarType()->getFltSemantics(), Str);
958  Constant *C = get(Context, FV);
959 
960  // For vectors, broadcast the value.
961  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
962  return ConstantVector::getSplat(VTy->getElementCount(), C);
963 
964  return C;
965 }
966 
967 Constant *ConstantFP::getNaN(Type *Ty, bool Negative, uint64_t Payload) {
968  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
969  APFloat NaN = APFloat::getNaN(Semantics, Negative, Payload);
970  Constant *C = get(Ty->getContext(), NaN);
971 
972  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
973  return ConstantVector::getSplat(VTy->getElementCount(), C);
974 
975  return C;
976 }
977 
978 Constant *ConstantFP::getQNaN(Type *Ty, bool Negative, APInt *Payload) {
979  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
980  APFloat NaN = APFloat::getQNaN(Semantics, Negative, Payload);
981  Constant *C = get(Ty->getContext(), NaN);
982 
983  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
984  return ConstantVector::getSplat(VTy->getElementCount(), C);
985 
986  return C;
987 }
988 
989 Constant *ConstantFP::getSNaN(Type *Ty, bool Negative, APInt *Payload) {
990  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
991  APFloat NaN = APFloat::getSNaN(Semantics, Negative, Payload);
992  Constant *C = get(Ty->getContext(), NaN);
993 
994  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
995  return ConstantVector::getSplat(VTy->getElementCount(), C);
996 
997  return C;
998 }
999 
1000 Constant *ConstantFP::getZero(Type *Ty, bool Negative) {
1001  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1002  APFloat NegZero = APFloat::getZero(Semantics, Negative);
1003  Constant *C = get(Ty->getContext(), NegZero);
1004 
1005  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1006  return ConstantVector::getSplat(VTy->getElementCount(), C);
1007 
1008  return C;
1009 }
1010 
1012  if (Ty->isFPOrFPVectorTy())
1013  return getNegativeZero(Ty);
1014 
1015  return Constant::getNullValue(Ty);
1016 }
1017 
1018 
1019 // ConstantFP accessors.
1021  LLVMContextImpl* pImpl = Context.pImpl;
1022 
1023  std::unique_ptr<ConstantFP> &Slot = pImpl->FPConstants[V];
1024 
1025  if (!Slot) {
1027  Slot.reset(new ConstantFP(Ty, V));
1028  }
1029 
1030  return Slot.get();
1031 }
1032 
1033 Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) {
1034  const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics();
1035  Constant *C = get(Ty->getContext(), APFloat::getInf(Semantics, Negative));
1036 
1037  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
1038  return ConstantVector::getSplat(VTy->getElementCount(), C);
1039 
1040  return C;
1041 }
1042 
1043 ConstantFP::ConstantFP(Type *Ty, const APFloat &V)
1044  : ConstantData(Ty, ConstantFPVal), Val(V) {
1045  assert(&V.getSemantics() == &Ty->getFltSemantics() &&
1046  "FP type Mismatch");
1047 }
1048 
1049 bool ConstantFP::isExactlyValue(const APFloat &V) const {
1050  return Val.bitwiseIsEqual(V);
1051 }
1052 
1053 /// Remove the constant from the constant table.
1054 void ConstantFP::destroyConstantImpl() {
1055  llvm_unreachable("You can't ConstantFP->destroyConstantImpl()!");
1056 }
1057 
1058 //===----------------------------------------------------------------------===//
1059 // ConstantAggregateZero Implementation
1060 //===----------------------------------------------------------------------===//
1061 
1063  if (auto *AT = dyn_cast<ArrayType>(getType()))
1064  return Constant::getNullValue(AT->getElementType());
1065  return Constant::getNullValue(cast<VectorType>(getType())->getElementType());
1066 }
1067 
1069  return Constant::getNullValue(getType()->getStructElementType(Elt));
1070 }
1071 
1073  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1074  return getSequentialElement();
1075  return getStructElement(cast<ConstantInt>(C)->getZExtValue());
1076 }
1077 
1079  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1080  return getSequentialElement();
1081  return getStructElement(Idx);
1082 }
1083 
1085  Type *Ty = getType();
1086  if (auto *AT = dyn_cast<ArrayType>(Ty))
1087  return ElementCount::getFixed(AT->getNumElements());
1088  if (auto *VT = dyn_cast<VectorType>(Ty))
1089  return VT->getElementCount();
1091 }
1092 
1093 //===----------------------------------------------------------------------===//
1094 // UndefValue Implementation
1095 //===----------------------------------------------------------------------===//
1096 
1098  if (ArrayType *ATy = dyn_cast<ArrayType>(getType()))
1099  return UndefValue::get(ATy->getElementType());
1100  return UndefValue::get(cast<VectorType>(getType())->getElementType());
1101 }
1102 
1104  return UndefValue::get(getType()->getStructElementType(Elt));
1105 }
1106 
1108  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1109  return getSequentialElement();
1110  return getStructElement(cast<ConstantInt>(C)->getZExtValue());
1111 }
1112 
1114  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1115  return getSequentialElement();
1116  return getStructElement(Idx);
1117 }
1118 
1119 unsigned UndefValue::getNumElements() const {
1120  Type *Ty = getType();
1121  if (auto *AT = dyn_cast<ArrayType>(Ty))
1122  return AT->getNumElements();
1123  if (auto *VT = dyn_cast<VectorType>(Ty))
1124  return cast<FixedVectorType>(VT)->getNumElements();
1125  return Ty->getStructNumElements();
1126 }
1127 
1128 //===----------------------------------------------------------------------===//
1129 // PoisonValue Implementation
1130 //===----------------------------------------------------------------------===//
1131 
1133  if (ArrayType *ATy = dyn_cast<ArrayType>(getType()))
1134  return PoisonValue::get(ATy->getElementType());
1135  return PoisonValue::get(cast<VectorType>(getType())->getElementType());
1136 }
1137 
1139  return PoisonValue::get(getType()->getStructElementType(Elt));
1140 }
1141 
1143  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1144  return getSequentialElement();
1145  return getStructElement(cast<ConstantInt>(C)->getZExtValue());
1146 }
1147 
1149  if (isa<ArrayType>(getType()) || isa<VectorType>(getType()))
1150  return getSequentialElement();
1151  return getStructElement(Idx);
1152 }
1153 
1154 //===----------------------------------------------------------------------===//
1155 // ConstantXXX Classes
1156 //===----------------------------------------------------------------------===//
1157 
1158 template <typename ItTy, typename EltTy>
1159 static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt) {
1160  for (; Start != End; ++Start)
1161  if (*Start != Elt)
1162  return false;
1163  return true;
1164 }
1165 
1166 template <typename SequentialTy, typename ElementTy>
1168  assert(!V.empty() && "Cannot get empty int sequence.");
1169 
1171  for (Constant *C : V)
1172  if (auto *CI = dyn_cast<ConstantInt>(C))
1173  Elts.push_back(CI->getZExtValue());
1174  else
1175  return nullptr;
1176  return SequentialTy::get(V[0]->getContext(), Elts);
1177 }
1178 
1179 template <typename SequentialTy, typename ElementTy>
1181  assert(!V.empty() && "Cannot get empty FP sequence.");
1182 
1184  for (Constant *C : V)
1185  if (auto *CFP = dyn_cast<ConstantFP>(C))
1186  Elts.push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1187  else
1188  return nullptr;
1189  return SequentialTy::getFP(V[0]->getType(), Elts);
1190 }
1191 
1192 template <typename SequenceTy>
1195  // We speculatively build the elements here even if it turns out that there is
1196  // a constantexpr or something else weird, since it is so uncommon for that to
1197  // happen.
1198  if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
1199  if (CI->getType()->isIntegerTy(8))
1200  return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1201  else if (CI->getType()->isIntegerTy(16))
1202  return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1203  else if (CI->getType()->isIntegerTy(32))
1204  return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1205  else if (CI->getType()->isIntegerTy(64))
1206  return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1207  } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
1208  if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1209  return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1210  else if (CFP->getType()->isFloatTy())
1211  return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1212  else if (CFP->getType()->isDoubleTy())
1213  return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1214  }
1215 
1216  return nullptr;
1217 }
1218 
1221  : Constant(T, VT, OperandTraits<ConstantAggregate>::op_end(this) - V.size(),
1222  V.size()) {
1223  llvm::copy(V, op_begin());
1224 
1225  // Check that types match, unless this is an opaque struct.
1226  if (auto *ST = dyn_cast<StructType>(T)) {
1227  if (ST->isOpaque())
1228  return;
1229  for (unsigned I = 0, E = V.size(); I != E; ++I)
1230  assert(V[I]->getType() == ST->getTypeAtIndex(I) &&
1231  "Initializer for struct element doesn't match!");
1232  }
1233 }
1234 
1235 ConstantArray::ConstantArray(ArrayType *T, ArrayRef<Constant *> V)
1236  : ConstantAggregate(T, ConstantArrayVal, V) {
1237  assert(V.size() == T->getNumElements() &&
1238  "Invalid initializer for constant array");
1239 }
1240 
1242  if (Constant *C = getImpl(Ty, V))
1243  return C;
1244  return Ty->getContext().pImpl->ArrayConstants.getOrCreate(Ty, V);
1245 }
1246 
1247 Constant *ConstantArray::getImpl(ArrayType *Ty, ArrayRef<Constant*> V) {
1248  // Empty arrays are canonicalized to ConstantAggregateZero.
1249  if (V.empty())
1250  return ConstantAggregateZero::get(Ty);
1251 
1252  for (Constant *C : V) {
1253  assert(C->getType() == Ty->getElementType() &&
1254  "Wrong type in array element initializer");
1255  (void)C;
1256  }
1257 
1258  // If this is an all-zero array, return a ConstantAggregateZero object. If
1259  // all undef, return an UndefValue, if "all simple", then return a
1260  // ConstantDataArray.
1261  Constant *C = V[0];
1262  if (isa<PoisonValue>(C) && rangeOnlyContains(V.begin(), V.end(), C))
1263  return PoisonValue::get(Ty);
1264 
1265  if (isa<UndefValue>(C) && rangeOnlyContains(V.begin(), V.end(), C))
1266  return UndefValue::get(Ty);
1267 
1268  if (C->isNullValue() && rangeOnlyContains(V.begin(), V.end(), C))
1269  return ConstantAggregateZero::get(Ty);
1270 
1271  // Check to see if all of the elements are ConstantFP or ConstantInt and if
1272  // the element type is compatible with ConstantDataVector. If so, use it.
1274  return getSequenceIfElementsMatch<ConstantDataArray>(C, V);
1275 
1276  // Otherwise, we really do want to create a ConstantArray.
1277  return nullptr;
1278 }
1279 
1282  bool Packed) {
1283  unsigned VecSize = V.size();
1284  SmallVector<Type*, 16> EltTypes(VecSize);
1285  for (unsigned i = 0; i != VecSize; ++i)
1286  EltTypes[i] = V[i]->getType();
1287 
1288  return StructType::get(Context, EltTypes, Packed);
1289 }
1290 
1291 
1293  bool Packed) {
1294  assert(!V.empty() &&
1295  "ConstantStruct::getTypeForElements cannot be called on empty list");
1296  return getTypeForElements(V[0]->getContext(), V, Packed);
1297 }
1298 
1299 ConstantStruct::ConstantStruct(StructType *T, ArrayRef<Constant *> V)
1300  : ConstantAggregate(T, ConstantStructVal, V) {
1301  assert((T->isOpaque() || V.size() == T->getNumElements()) &&
1302  "Invalid initializer for constant struct");
1303 }
1304 
1305 // ConstantStruct accessors.
1307  assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1308  "Incorrect # elements specified to ConstantStruct::get");
1309 
1310  // Create a ConstantAggregateZero value if all elements are zeros.
1311  bool isZero = true;
1312  bool isUndef = false;
1313  bool isPoison = false;
1314 
1315  if (!V.empty()) {
1316  isUndef = isa<UndefValue>(V[0]);
1317  isPoison = isa<PoisonValue>(V[0]);
1318  isZero = V[0]->isNullValue();
1319  // PoisonValue inherits UndefValue, so its check is not necessary.
1320  if (isUndef || isZero) {
1321  for (Constant *C : V) {
1322  if (!C->isNullValue())
1323  isZero = false;
1324  if (!isa<PoisonValue>(C))
1325  isPoison = false;
1326  if (isa<PoisonValue>(C) || !isa<UndefValue>(C))
1327  isUndef = false;
1328  }
1329  }
1330  }
1331  if (isZero)
1333  if (isPoison)
1334  return PoisonValue::get(ST);
1335  if (isUndef)
1336  return UndefValue::get(ST);
1337 
1338  return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1339 }
1340 
1341 ConstantVector::ConstantVector(VectorType *T, ArrayRef<Constant *> V)
1342  : ConstantAggregate(T, ConstantVectorVal, V) {
1343  assert(V.size() == cast<FixedVectorType>(T)->getNumElements() &&
1344  "Invalid initializer for constant vector");
1345 }
1346 
1347 // ConstantVector accessors.
1349  if (Constant *C = getImpl(V))
1350  return C;
1351  auto *Ty = FixedVectorType::get(V.front()->getType(), V.size());
1352  return Ty->getContext().pImpl->VectorConstants.getOrCreate(Ty, V);
1353 }
1354 
1355 Constant *ConstantVector::getImpl(ArrayRef<Constant*> V) {
1356  assert(!V.empty() && "Vectors can't be empty");
1357  auto *T = FixedVectorType::get(V.front()->getType(), V.size());
1358 
1359  // If this is an all-undef or all-zero vector, return a
1360  // ConstantAggregateZero or UndefValue.
1361  Constant *C = V[0];
1362  bool isZero = C->isNullValue();
1363  bool isUndef = isa<UndefValue>(C);
1364  bool isPoison = isa<PoisonValue>(C);
1365 
1366  if (isZero || isUndef) {
1367  for (unsigned i = 1, e = V.size(); i != e; ++i)
1368  if (V[i] != C) {
1369  isZero = isUndef = isPoison = false;
1370  break;
1371  }
1372  }
1373 
1374  if (isZero)
1375  return ConstantAggregateZero::get(T);
1376  if (isPoison)
1377  return PoisonValue::get(T);
1378  if (isUndef)
1379  return UndefValue::get(T);
1380 
1381  // Check to see if all of the elements are ConstantFP or ConstantInt and if
1382  // the element type is compatible with ConstantDataVector. If so, use it.
1384  return getSequenceIfElementsMatch<ConstantDataVector>(C, V);
1385 
1386  // Otherwise, the element type isn't compatible with ConstantDataVector, or
1387  // the operand list contains a ConstantExpr or something else strange.
1388  return nullptr;
1389 }
1390 
1392  if (!EC.isScalable()) {
1393  // If this splat is compatible with ConstantDataVector, use it instead of
1394  // ConstantVector.
1395  if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1397  return ConstantDataVector::getSplat(EC.getKnownMinValue(), V);
1398 
1399  SmallVector<Constant *, 32> Elts(EC.getKnownMinValue(), V);
1400  return get(Elts);
1401  }
1402 
1403  Type *VTy = VectorType::get(V->getType(), EC);
1404 
1405  if (V->isNullValue())
1406  return ConstantAggregateZero::get(VTy);
1407  else if (isa<UndefValue>(V))
1408  return UndefValue::get(VTy);
1409 
1410  Type *I32Ty = Type::getInt32Ty(VTy->getContext());
1411 
1412  // Move scalar into vector.
1413  Constant *PoisonV = PoisonValue::get(VTy);
1414  V = ConstantExpr::getInsertElement(PoisonV, V, ConstantInt::get(I32Ty, 0));
1415  // Build shuffle mask to perform the splat.
1416  SmallVector<int, 8> Zeros(EC.getKnownMinValue(), 0);
1417  // Splat.
1418  return ConstantExpr::getShuffleVector(V, PoisonV, Zeros);
1419 }
1420 
1422  LLVMContextImpl *pImpl = Context.pImpl;
1423  if (!pImpl->TheNoneToken)
1424  pImpl->TheNoneToken.reset(new ConstantTokenNone(Context));
1425  return pImpl->TheNoneToken.get();
1426 }
1427 
1428 /// Remove the constant from the constant table.
1429 void ConstantTokenNone::destroyConstantImpl() {
1430  llvm_unreachable("You can't ConstantTokenNone->destroyConstantImpl()!");
1431 }
1432 
1433 // Utility function for determining if a ConstantExpr is a CastOp or not. This
1434 // can't be inline because we don't want to #include Instruction.h into
1435 // Constant.h
1436 bool ConstantExpr::isCast() const {
1437  return Instruction::isCast(getOpcode());
1438 }
1439 
1441  return getOpcode() == Instruction::ICmp || getOpcode() == Instruction::FCmp;
1442 }
1443 
1444 unsigned ConstantExpr::getPredicate() const {
1445  return cast<CompareConstantExpr>(this)->predicate;
1446 }
1447 
1449  return cast<ShuffleVectorConstantExpr>(this)->ShuffleMask;
1450 }
1451 
1453  return cast<ShuffleVectorConstantExpr>(this)->ShuffleMaskForBitcode;
1454 }
1455 
1457  bool OnlyIfReduced, Type *SrcTy) const {
1458  assert(Ops.size() == getNumOperands() && "Operand count mismatch!");
1459 
1460  // If no operands changed return self.
1461  if (Ty == getType() && std::equal(Ops.begin(), Ops.end(), op_begin()))
1462  return const_cast<ConstantExpr*>(this);
1463 
1464  Type *OnlyIfReducedTy = OnlyIfReduced ? Ty : nullptr;
1465  switch (getOpcode()) {
1466  case Instruction::Trunc:
1467  case Instruction::ZExt:
1468  case Instruction::SExt:
1469  case Instruction::FPTrunc:
1470  case Instruction::FPExt:
1471  case Instruction::UIToFP:
1472  case Instruction::SIToFP:
1473  case Instruction::FPToUI:
1474  case Instruction::FPToSI:
1475  case Instruction::PtrToInt:
1476  case Instruction::IntToPtr:
1477  case Instruction::BitCast:
1478  case Instruction::AddrSpaceCast:
1479  return ConstantExpr::getCast(getOpcode(), Ops[0], Ty, OnlyIfReduced);
1480  case Instruction::Select:
1481  return ConstantExpr::getSelect(Ops[0], Ops[1], Ops[2], OnlyIfReducedTy);
1482  case Instruction::InsertElement:
1483  return ConstantExpr::getInsertElement(Ops[0], Ops[1], Ops[2],
1484  OnlyIfReducedTy);
1485  case Instruction::ExtractElement:
1486  return ConstantExpr::getExtractElement(Ops[0], Ops[1], OnlyIfReducedTy);
1487  case Instruction::ShuffleVector:
1488  return ConstantExpr::getShuffleVector(Ops[0], Ops[1], getShuffleMask(),
1489  OnlyIfReducedTy);
1490  case Instruction::GetElementPtr: {
1491  auto *GEPO = cast<GEPOperator>(this);
1492  assert(SrcTy || (Ops[0]->getType() == getOperand(0)->getType()));
1494  SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.slice(1),
1495  GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1496  }
1497  case Instruction::ICmp:
1498  case Instruction::FCmp:
1499  return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1],
1500  OnlyIfReducedTy);
1501  default:
1502  assert(getNumOperands() == 2 && "Must be binary operator?");
1503  return ConstantExpr::get(getOpcode(), Ops[0], Ops[1], SubclassOptionalData,
1504  OnlyIfReducedTy);
1505  }
1506 }
1507 
1508 
1509 //===----------------------------------------------------------------------===//
1510 // isValueValidForType implementations
1511 
1513  unsigned NumBits = Ty->getIntegerBitWidth(); // assert okay
1514  if (Ty->isIntegerTy(1))
1515  return Val == 0 || Val == 1;
1516  return isUIntN(NumBits, Val);
1517 }
1518 
1519 bool ConstantInt::isValueValidForType(Type *Ty, int64_t Val) {
1520  unsigned NumBits = Ty->getIntegerBitWidth();
1521  if (Ty->isIntegerTy(1))
1522  return Val == 0 || Val == 1 || Val == -1;
1523  return isIntN(NumBits, Val);
1524 }
1525 
1527  // convert modifies in place, so make a copy.
1528  APFloat Val2 = APFloat(Val);
1529  bool losesInfo;
1530  switch (Ty->getTypeID()) {
1531  default:
1532  return false; // These can't be represented as floating point!
1533 
1534  // FIXME rounding mode needs to be more flexible
1535  case Type::HalfTyID: {
1536  if (&Val2.getSemantics() == &APFloat::IEEEhalf())
1537  return true;
1539  return !losesInfo;
1540  }
1541  case Type::BFloatTyID: {
1542  if (&Val2.getSemantics() == &APFloat::BFloat())
1543  return true;
1545  return !losesInfo;
1546  }
1547  case Type::FloatTyID: {
1548  if (&Val2.getSemantics() == &APFloat::IEEEsingle())
1549  return true;
1551  return !losesInfo;
1552  }
1553  case Type::DoubleTyID: {
1554  if (&Val2.getSemantics() == &APFloat::IEEEhalf() ||
1555  &Val2.getSemantics() == &APFloat::BFloat() ||
1556  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1557  &Val2.getSemantics() == &APFloat::IEEEdouble())
1558  return true;
1560  return !losesInfo;
1561  }
1562  case Type::X86_FP80TyID:
1563  return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1564  &Val2.getSemantics() == &APFloat::BFloat() ||
1565  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1566  &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1568  case Type::FP128TyID:
1569  return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1570  &Val2.getSemantics() == &APFloat::BFloat() ||
1571  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1572  &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1573  &Val2.getSemantics() == &APFloat::IEEEquad();
1574  case Type::PPC_FP128TyID:
1575  return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1576  &Val2.getSemantics() == &APFloat::BFloat() ||
1577  &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1578  &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1579  &Val2.getSemantics() == &APFloat::PPCDoubleDouble();
1580  }
1581 }
1582 
1583 
1584 //===----------------------------------------------------------------------===//
1585 // Factory Function Implementation
1586 
1588  assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
1589  "Cannot create an aggregate zero of non-aggregate type!");
1590 
1591  std::unique_ptr<ConstantAggregateZero> &Entry =
1592  Ty->getContext().pImpl->CAZConstants[Ty];
1593  if (!Entry)
1594  Entry.reset(new ConstantAggregateZero(Ty));
1595 
1596  return Entry.get();
1597 }
1598 
1599 /// Remove the constant from the constant table.
1600 void ConstantAggregateZero::destroyConstantImpl() {
1601  getContext().pImpl->CAZConstants.erase(getType());
1602 }
1603 
1604 /// Remove the constant from the constant table.
1605 void ConstantArray::destroyConstantImpl() {
1607 }
1608 
1609 
1610 //---- ConstantStruct::get() implementation...
1611 //
1612 
1613 /// Remove the constant from the constant table.
1614 void ConstantStruct::destroyConstantImpl() {
1616 }
1617 
1618 /// Remove the constant from the constant table.
1619 void ConstantVector::destroyConstantImpl() {
1621 }
1622 
1623 Constant *Constant::getSplatValue(bool AllowUndefs) const {
1624  assert(this->getType()->isVectorTy() && "Only valid for vectors!");
1625  if (isa<ConstantAggregateZero>(this))
1626  return getNullValue(cast<VectorType>(getType())->getElementType());
1627  if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(this))
1628  return CV->getSplatValue();
1629  if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
1630  return CV->getSplatValue(AllowUndefs);
1631 
1632  // Check if this is a constant expression splat of the form returned by
1633  // ConstantVector::getSplat()
1634  const auto *Shuf = dyn_cast<ConstantExpr>(this);
1635  if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1636  isa<UndefValue>(Shuf->getOperand(1))) {
1637 
1638  const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1639  if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1640  isa<UndefValue>(IElt->getOperand(0))) {
1641 
1642  ArrayRef<int> Mask = Shuf->getShuffleMask();
1643  Constant *SplatVal = IElt->getOperand(1);
1644  ConstantInt *Index = dyn_cast<ConstantInt>(IElt->getOperand(2));
1645 
1646  if (Index && Index->getValue() == 0 &&
1647  llvm::all_of(Mask, [](int I) { return I == 0; }))
1648  return SplatVal;
1649  }
1650  }
1651 
1652  return nullptr;
1653 }
1654 
1655 Constant *ConstantVector::getSplatValue(bool AllowUndefs) const {
1656  // Check out first element.
1657  Constant *Elt = getOperand(0);
1658  // Then make sure all remaining elements point to the same value.
1659  for (unsigned I = 1, E = getNumOperands(); I < E; ++I) {
1660  Constant *OpC = getOperand(I);
1661  if (OpC == Elt)
1662  continue;
1663 
1664  // Strict mode: any mismatch is not a splat.
1665  if (!AllowUndefs)
1666  return nullptr;
1667 
1668  // Allow undefs mode: ignore undefined elements.
1669  if (isa<UndefValue>(OpC))
1670  continue;
1671 
1672  // If we do not have a defined element yet, use the current operand.
1673  if (isa<UndefValue>(Elt))
1674  Elt = OpC;
1675 
1676  if (OpC != Elt)
1677  return nullptr;
1678  }
1679  return Elt;
1680 }
1681 
1683  if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
1684  return CI->getValue();
1685  assert(this->getSplatValue() && "Doesn't contain a unique integer!");
1686  const Constant *C = this->getAggregateElement(0U);
1687  assert(C && isa<ConstantInt>(C) && "Not a vector of numbers!");
1688  return cast<ConstantInt>(C)->getValue();
1689 }
1690 
1691 //---- ConstantPointerNull::get() implementation.
1692 //
1693 
1695  std::unique_ptr<ConstantPointerNull> &Entry =
1696  Ty->getContext().pImpl->CPNConstants[Ty];
1697  if (!Entry)
1698  Entry.reset(new ConstantPointerNull(Ty));
1699 
1700  return Entry.get();
1701 }
1702 
1703 /// Remove the constant from the constant table.
1704 void ConstantPointerNull::destroyConstantImpl() {
1705  getContext().pImpl->CPNConstants.erase(getType());
1706 }
1707 
1709  std::unique_ptr<UndefValue> &Entry = Ty->getContext().pImpl->UVConstants[Ty];
1710  if (!Entry)
1711  Entry.reset(new UndefValue(Ty));
1712 
1713  return Entry.get();
1714 }
1715 
1716 /// Remove the constant from the constant table.
1717 void UndefValue::destroyConstantImpl() {
1718  // Free the constant and any dangling references to it.
1719  if (getValueID() == UndefValueVal) {
1720  getContext().pImpl->UVConstants.erase(getType());
1721  } else if (getValueID() == PoisonValueVal) {
1722  getContext().pImpl->PVConstants.erase(getType());
1723  }
1724  llvm_unreachable("Not a undef or a poison!");
1725 }
1726 
1728  std::unique_ptr<PoisonValue> &Entry = Ty->getContext().pImpl->PVConstants[Ty];
1729  if (!Entry)
1730  Entry.reset(new PoisonValue(Ty));
1731 
1732  return Entry.get();
1733 }
1734 
1735 /// Remove the constant from the constant table.
1736 void PoisonValue::destroyConstantImpl() {
1737  // Free the constant and any dangling references to it.
1738  getContext().pImpl->PVConstants.erase(getType());
1739 }
1740 
1742  assert(BB->getParent() && "Block must have a parent");
1743  return get(BB->getParent(), BB);
1744 }
1745 
1747  BlockAddress *&BA =
1748  F->getContext().pImpl->BlockAddresses[std::make_pair(F, BB)];
1749  if (!BA)
1750  BA = new BlockAddress(F, BB);
1751 
1752  assert(BA->getFunction() == F && "Basic block moved between functions");
1753  return BA;
1754 }
1755 
1756 BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
1757  : Constant(Type::getInt8PtrTy(F->getContext(), F->getAddressSpace()),
1758  Value::BlockAddressVal, &Op<0>(), 2) {
1759  setOperand(0, F);
1760  setOperand(1, BB);
1761  BB->AdjustBlockAddressRefCount(1);
1762 }
1763 
1765  if (!BB->hasAddressTaken())
1766  return nullptr;
1767 
1768  const Function *F = BB->getParent();
1769  assert(F && "Block must have a parent");
1770  BlockAddress *BA =
1771  F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(F, BB));
1772  assert(BA && "Refcount and block address map disagree!");
1773  return BA;
1774 }
1775 
1776 /// Remove the constant from the constant table.
1777 void BlockAddress::destroyConstantImpl() {
1779  ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
1780  getBasicBlock()->AdjustBlockAddressRefCount(-1);
1781 }
1782 
1783 Value *BlockAddress::handleOperandChangeImpl(Value *From, Value *To) {
1784  // This could be replacing either the Basic Block or the Function. In either
1785  // case, we have to remove the map entry.
1786  Function *NewF = getFunction();
1787  BasicBlock *NewBB = getBasicBlock();
1788 
1789  if (From == NewF)
1790  NewF = cast<Function>(To->stripPointerCasts());
1791  else {
1792  assert(From == NewBB && "From does not match any operand");
1793  NewBB = cast<BasicBlock>(To);
1794  }
1795 
1796  // See if the 'new' entry already exists, if not, just update this in place
1797  // and return early.
1798  BlockAddress *&NewBA =
1799  getContext().pImpl->BlockAddresses[std::make_pair(NewF, NewBB)];
1800  if (NewBA)
1801  return NewBA;
1802 
1803  getBasicBlock()->AdjustBlockAddressRefCount(-1);
1804 
1805  // Remove the old entry, this can't cause the map to rehash (just a
1806  // tombstone will get added).
1807  getContext().pImpl->BlockAddresses.erase(std::make_pair(getFunction(),
1808  getBasicBlock()));
1809  NewBA = this;
1810  setOperand(0, NewF);
1811  setOperand(1, NewBB);
1812  getBasicBlock()->AdjustBlockAddressRefCount(1);
1813 
1814  // If we just want to keep the existing value, then return null.
1815  // Callers know that this means we shouldn't delete this value.
1816  return nullptr;
1817 }
1818 
1821  if (!Equiv)
1822  Equiv = new DSOLocalEquivalent(GV);
1823 
1824  assert(Equiv->getGlobalValue() == GV &&
1825  "DSOLocalFunction does not match the expected global value");
1826  return Equiv;
1827 }
1828 
1829 DSOLocalEquivalent::DSOLocalEquivalent(GlobalValue *GV)
1830  : Constant(GV->getType(), Value::DSOLocalEquivalentVal, &Op<0>(), 1) {
1831  setOperand(0, GV);
1832 }
1833 
1834 /// Remove the constant from the constant table.
1835 void DSOLocalEquivalent::destroyConstantImpl() {
1836  const GlobalValue *GV = getGlobalValue();
1837  GV->getContext().pImpl->DSOLocalEquivalents.erase(GV);
1838 }
1839 
1840 Value *DSOLocalEquivalent::handleOperandChangeImpl(Value *From, Value *To) {
1841  assert(From == getGlobalValue() && "Changing value does not match operand.");
1842  assert(isa<Constant>(To) && "Can only replace the operands with a constant");
1843 
1844  // The replacement is with another global value.
1845  if (const auto *ToObj = dyn_cast<GlobalValue>(To)) {
1846  DSOLocalEquivalent *&NewEquiv =
1848  if (NewEquiv)
1849  return llvm::ConstantExpr::getBitCast(NewEquiv, getType());
1850  }
1851 
1852  // If the argument is replaced with a null value, just replace this constant
1853  // with a null value.
1854  if (cast<Constant>(To)->isNullValue())
1855  return To;
1856 
1857  // The replacement could be a bitcast or an alias to another function. We can
1858  // replace it with a bitcast to the dso_local_equivalent of that function.
1859  auto *Func = cast<Function>(To->stripPointerCastsAndAliases());
1861  if (NewEquiv)
1862  return llvm::ConstantExpr::getBitCast(NewEquiv, getType());
1863 
1864  // Replace this with the new one.
1866  NewEquiv = this;
1867  setOperand(0, Func);
1868 
1869  if (Func->getType() != getType()) {
1870  // It is ok to mutate the type here because this constant should always
1871  // reflect the type of the function it's holding.
1872  mutateType(Func->getType());
1873  }
1874  return nullptr;
1875 }
1876 
1878  NoCFIValue *&NC = GV->getContext().pImpl->NoCFIValues[GV];
1879  if (!NC)
1880  NC = new NoCFIValue(GV);
1881 
1882  assert(NC->getGlobalValue() == GV &&
1883  "NoCFIValue does not match the expected global value");
1884  return NC;
1885 }
1886 
1887 NoCFIValue::NoCFIValue(GlobalValue *GV)
1888  : Constant(GV->getType(), Value::NoCFIValueVal, &Op<0>(), 1) {
1889  setOperand(0, GV);
1890 }
1891 
1892 /// Remove the constant from the constant table.
1893 void NoCFIValue::destroyConstantImpl() {
1894  const GlobalValue *GV = getGlobalValue();
1895  GV->getContext().pImpl->NoCFIValues.erase(GV);
1896 }
1897 
1898 Value *NoCFIValue::handleOperandChangeImpl(Value *From, Value *To) {
1899  assert(From == getGlobalValue() && "Changing value does not match operand.");
1900 
1901  GlobalValue *GV = dyn_cast<GlobalValue>(To->stripPointerCasts());
1902  assert(GV && "Can only replace the operands with a global value");
1903 
1904  NoCFIValue *&NewNC = getContext().pImpl->NoCFIValues[GV];
1905  if (NewNC)
1906  return llvm::ConstantExpr::getBitCast(NewNC, getType());
1907 
1909  NewNC = this;
1910  setOperand(0, GV);
1911 
1912  if (GV->getType() != getType())
1913  mutateType(GV->getType());
1914 
1915  return nullptr;
1916 }
1917 
1918 //---- ConstantExpr::get() implementations.
1919 //
1920 
1921 /// This is a utility function to handle folding of casts and lookup of the
1922 /// cast in the ExprConstants map. It is used by the various get* methods below.
1924  bool OnlyIfReduced = false) {
1925  assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
1926  // Fold a few common cases
1927  if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty))
1928  return FC;
1929 
1930  if (OnlyIfReduced)
1931  return nullptr;
1932 
1933  LLVMContextImpl *pImpl = Ty->getContext().pImpl;
1934 
1935  // Look up the constant in the table first to ensure uniqueness.
1936  ConstantExprKeyType Key(opc, C);
1937 
1938  return pImpl->ExprConstants.getOrCreate(Ty, Key);
1939 }
1940 
1942  bool OnlyIfReduced) {
1944  assert(Instruction::isCast(opc) && "opcode out of range");
1945  assert(C && Ty && "Null arguments to getCast");
1946  assert(CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!");
1947 
1948  switch (opc) {
1949  default:
1950  llvm_unreachable("Invalid cast opcode");
1951  case Instruction::Trunc:
1952  return getTrunc(C, Ty, OnlyIfReduced);
1953  case Instruction::ZExt:
1954  return getZExt(C, Ty, OnlyIfReduced);
1955  case Instruction::SExt:
1956  return getSExt(C, Ty, OnlyIfReduced);
1957  case Instruction::FPTrunc:
1958  return getFPTrunc(C, Ty, OnlyIfReduced);
1959  case Instruction::FPExt:
1960  return getFPExtend(C, Ty, OnlyIfReduced);
1961  case Instruction::UIToFP:
1962  return getUIToFP(C, Ty, OnlyIfReduced);
1963  case Instruction::SIToFP:
1964  return getSIToFP(C, Ty, OnlyIfReduced);
1965  case Instruction::FPToUI:
1966  return getFPToUI(C, Ty, OnlyIfReduced);
1967  case Instruction::FPToSI:
1968  return getFPToSI(C, Ty, OnlyIfReduced);
1969  case Instruction::PtrToInt:
1970  return getPtrToInt(C, Ty, OnlyIfReduced);
1971  case Instruction::IntToPtr:
1972  return getIntToPtr(C, Ty, OnlyIfReduced);
1973  case Instruction::BitCast:
1974  return getBitCast(C, Ty, OnlyIfReduced);
1975  case Instruction::AddrSpaceCast:
1976  return getAddrSpaceCast(C, Ty, OnlyIfReduced);
1977  }
1978 }
1979 
1981  if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1982  return getBitCast(C, Ty);
1983  return getZExt(C, Ty);
1984 }
1985 
1987  if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1988  return getBitCast(C, Ty);
1989  return getSExt(C, Ty);
1990 }
1991 
1993  if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
1994  return getBitCast(C, Ty);
1995  return getTrunc(C, Ty);
1996 }
1997 
1999  assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
2000  "Can only sign extend/truncate integers!");
2001  Type *CTy = C->getType();
2002  if (CTy->getScalarSizeInBits() < Ty->getScalarSizeInBits())
2003  return getSExt(C, Ty);
2004  if (CTy->getScalarSizeInBits() > Ty->getScalarSizeInBits())
2005  return getTrunc(C, Ty);
2006  return C;
2007 }
2008 
2010  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2011  assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
2012  "Invalid cast");
2013 
2014  if (Ty->isIntOrIntVectorTy())
2015  return getPtrToInt(S, Ty);
2016 
2017  unsigned SrcAS = S->getType()->getPointerAddressSpace();
2018  if (Ty->isPtrOrPtrVectorTy() && SrcAS != Ty->getPointerAddressSpace())
2019  return getAddrSpaceCast(S, Ty);
2020 
2021  return getBitCast(S, Ty);
2022 }
2023 
2025  Type *Ty) {
2026  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2027  assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
2028 
2029  if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
2030  return getAddrSpaceCast(S, Ty);
2031 
2032  return getBitCast(S, Ty);
2033 }
2034 
2036  assert(C->getType()->isIntOrIntVectorTy() &&
2037  Ty->isIntOrIntVectorTy() && "Invalid cast");
2038  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2039  unsigned DstBits = Ty->getScalarSizeInBits();
2040  Instruction::CastOps opcode =
2041  (SrcBits == DstBits ? Instruction::BitCast :
2042  (SrcBits > DstBits ? Instruction::Trunc :
2043  (isSigned ? Instruction::SExt : Instruction::ZExt)));
2044  return getCast(opcode, C, Ty);
2045 }
2046 
2048  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2049  "Invalid cast");
2050  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2051  unsigned DstBits = Ty->getScalarSizeInBits();
2052  if (SrcBits == DstBits)
2053  return C; // Avoid a useless cast
2054  Instruction::CastOps opcode =
2055  (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
2056  return getCast(opcode, C, Ty);
2057 }
2058 
2059 Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
2060 #ifndef NDEBUG
2061  bool fromVec = isa<VectorType>(C->getType());
2062  bool toVec = isa<VectorType>(Ty);
2063 #endif
2064  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2065  assert(C->getType()->isIntOrIntVectorTy() && "Trunc operand must be integer");
2066  assert(Ty->isIntOrIntVectorTy() && "Trunc produces only integral");
2067  assert(C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
2068  "SrcTy must be larger than DestTy for Trunc!");
2069 
2070  return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
2071 }
2072 
2073 Constant *ConstantExpr::getSExt(Constant *C, Type *Ty, bool OnlyIfReduced) {
2074 #ifndef NDEBUG
2075  bool fromVec = isa<VectorType>(C->getType());
2076  bool toVec = isa<VectorType>(Ty);
2077 #endif
2078  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2079  assert(C->getType()->isIntOrIntVectorTy() && "SExt operand must be integral");
2080  assert(Ty->isIntOrIntVectorTy() && "SExt produces only integer");
2081  assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
2082  "SrcTy must be smaller than DestTy for SExt!");
2083 
2084  return getFoldedCast(Instruction::SExt, C, Ty, OnlyIfReduced);
2085 }
2086 
2087 Constant *ConstantExpr::getZExt(Constant *C, Type *Ty, bool OnlyIfReduced) {
2088 #ifndef NDEBUG
2089  bool fromVec = isa<VectorType>(C->getType());
2090  bool toVec = isa<VectorType>(Ty);
2091 #endif
2092  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2093  assert(C->getType()->isIntOrIntVectorTy() && "ZEXt operand must be integral");
2094  assert(Ty->isIntOrIntVectorTy() && "ZExt produces only integer");
2095  assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
2096  "SrcTy must be smaller than DestTy for ZExt!");
2097 
2098  return getFoldedCast(Instruction::ZExt, C, Ty, OnlyIfReduced);
2099 }
2100 
2101 Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
2102 #ifndef NDEBUG
2103  bool fromVec = isa<VectorType>(C->getType());
2104  bool toVec = isa<VectorType>(Ty);
2105 #endif
2106  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2107  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2108  C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
2109  "This is an illegal floating point truncation!");
2110  return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced);
2111 }
2112 
2113 Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced) {
2114 #ifndef NDEBUG
2115  bool fromVec = isa<VectorType>(C->getType());
2116  bool toVec = isa<VectorType>(Ty);
2117 #endif
2118  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2119  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2120  C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
2121  "This is an illegal floating point extension!");
2122  return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced);
2123 }
2124 
2125 Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
2126 #ifndef NDEBUG
2127  bool fromVec = isa<VectorType>(C->getType());
2128  bool toVec = isa<VectorType>(Ty);
2129 #endif
2130  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2131  assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
2132  "This is an illegal uint to floating point cast!");
2133  return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced);
2134 }
2135 
2136 Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
2137 #ifndef NDEBUG
2138  bool fromVec = isa<VectorType>(C->getType());
2139  bool toVec = isa<VectorType>(Ty);
2140 #endif
2141  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2142  assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
2143  "This is an illegal sint to floating point cast!");
2144  return getFoldedCast(Instruction::SIToFP, C, Ty, OnlyIfReduced);
2145 }
2146 
2147 Constant *ConstantExpr::getFPToUI(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()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
2154  "This is an illegal floating point to uint cast!");
2155  return getFoldedCast(Instruction::FPToUI, C, Ty, OnlyIfReduced);
2156 }
2157 
2158 Constant *ConstantExpr::getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced) {
2159 #ifndef NDEBUG
2160  bool fromVec = isa<VectorType>(C->getType());
2161  bool toVec = isa<VectorType>(Ty);
2162 #endif
2163  assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
2164  assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() &&
2165  "This is an illegal floating point to sint cast!");
2166  return getFoldedCast(Instruction::FPToSI, C, Ty, OnlyIfReduced);
2167 }
2168 
2170  bool OnlyIfReduced) {
2171  assert(C->getType()->isPtrOrPtrVectorTy() &&
2172  "PtrToInt source must be pointer or pointer vector");
2173  assert(DstTy->isIntOrIntVectorTy() &&
2174  "PtrToInt destination must be integer or integer vector");
2175  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
2176  if (isa<VectorType>(C->getType()))
2177  assert(cast<VectorType>(C->getType())->getElementCount() ==
2178  cast<VectorType>(DstTy)->getElementCount() &&
2179  "Invalid cast between a different number of vector elements");
2180  return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
2181 }
2182 
2184  bool OnlyIfReduced) {
2185  assert(C->getType()->isIntOrIntVectorTy() &&
2186  "IntToPtr source must be integer or integer vector");
2187  assert(DstTy->isPtrOrPtrVectorTy() &&
2188  "IntToPtr destination must be a pointer or pointer vector");
2189  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
2190  if (isa<VectorType>(C->getType()))
2191  assert(cast<VectorType>(C->getType())->getElementCount() ==
2192  cast<VectorType>(DstTy)->getElementCount() &&
2193  "Invalid cast between a different number of vector elements");
2194  return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced);
2195 }
2196 
2198  bool OnlyIfReduced) {
2199  assert(CastInst::castIsValid(Instruction::BitCast, C, DstTy) &&
2200  "Invalid constantexpr bitcast!");
2201 
2202  // It is common to ask for a bitcast of a value to its own type, handle this
2203  // speedily.
2204  if (C->getType() == DstTy) return C;
2205 
2206  return getFoldedCast(Instruction::BitCast, C, DstTy, OnlyIfReduced);
2207 }
2208 
2210  bool OnlyIfReduced) {
2211  assert(CastInst::castIsValid(Instruction::AddrSpaceCast, C, DstTy) &&
2212  "Invalid constantexpr addrspacecast!");
2213 
2214  // Canonicalize addrspacecasts between different pointer types by first
2215  // bitcasting the pointer type and then converting the address space.
2216  PointerType *SrcScalarTy = cast<PointerType>(C->getType()->getScalarType());
2217  PointerType *DstScalarTy = cast<PointerType>(DstTy->getScalarType());
2218  if (!SrcScalarTy->hasSameElementTypeAs(DstScalarTy)) {
2220  DstScalarTy, SrcScalarTy->getAddressSpace());
2221  if (VectorType *VT = dyn_cast<VectorType>(DstTy)) {
2222  // Handle vectors of pointers.
2223  MidTy = FixedVectorType::get(MidTy,
2224  cast<FixedVectorType>(VT)->getNumElements());
2225  }
2226  C = getBitCast(C, MidTy);
2227  }
2228  return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced);
2229 }
2230 
2232  unsigned Flags, Type *OnlyIfReducedTy) {
2233  // Check the operands for consistency first.
2234  assert(Instruction::isBinaryOp(Opcode) &&
2235  "Invalid opcode in binary constant expression");
2236  assert(isSupportedBinOp(Opcode) &&
2237  "Binop not supported as constant expression");
2238  assert(C1->getType() == C2->getType() &&
2239  "Operand types in binary constant expression should match");
2240 
2241 #ifndef NDEBUG
2242  switch (Opcode) {
2243  case Instruction::Add:
2244  case Instruction::Sub:
2245  case Instruction::Mul:
2246  case Instruction::UDiv:
2247  case Instruction::SDiv:
2248  case Instruction::URem:
2249  case Instruction::SRem:
2250  assert(C1->getType()->isIntOrIntVectorTy() &&
2251  "Tried to create an integer operation on a non-integer type!");
2252  break;
2253  case Instruction::FAdd:
2254  case Instruction::FSub:
2255  case Instruction::FMul:
2256  case Instruction::FDiv:
2257  case Instruction::FRem:
2258  assert(C1->getType()->isFPOrFPVectorTy() &&
2259  "Tried to create a floating-point operation on a "
2260  "non-floating-point type!");
2261  break;
2262  case Instruction::And:
2263  case Instruction::Or:
2264  case Instruction::Xor:
2265  assert(C1->getType()->isIntOrIntVectorTy() &&
2266  "Tried to create a logical operation on a non-integral type!");
2267  break;
2268  case Instruction::Shl:
2269  case Instruction::LShr:
2270  case Instruction::AShr:
2271  assert(C1->getType()->isIntOrIntVectorTy() &&
2272  "Tried to create a shift operation on a non-integer type!");
2273  break;
2274  default:
2275  break;
2276  }
2277 #endif
2278 
2279  if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
2280  return FC;
2281 
2282  if (OnlyIfReducedTy == C1->getType())
2283  return nullptr;
2284 
2285  Constant *ArgVec[] = { C1, C2 };
2286  ConstantExprKeyType Key(Opcode, ArgVec, 0, Flags);
2287 
2288  LLVMContextImpl *pImpl = C1->getContext().pImpl;
2289  return pImpl->ExprConstants.getOrCreate(C1->getType(), Key);
2290 }
2291 
2292 bool ConstantExpr::isDesirableBinOp(unsigned Opcode) {
2293  switch (Opcode) {
2294  case Instruction::UDiv:
2295  case Instruction::SDiv:
2296  case Instruction::URem:
2297  case Instruction::SRem:
2298  case Instruction::FAdd:
2299  case Instruction::FSub:
2300  case Instruction::FMul:
2301  case Instruction::FDiv:
2302  case Instruction::FRem:
2303  return false;
2304  case Instruction::Add:
2305  case Instruction::Sub:
2306  case Instruction::Mul:
2307  case Instruction::Shl:
2308  case Instruction::LShr:
2309  case Instruction::AShr:
2310  case Instruction::And:
2311  case Instruction::Or:
2312  case Instruction::Xor:
2313  return true;
2314  default:
2315  llvm_unreachable("Argument must be binop opcode");
2316  }
2317 }
2318 
2319 bool ConstantExpr::isSupportedBinOp(unsigned Opcode) {
2320  switch (Opcode) {
2321  case Instruction::UDiv:
2322  case Instruction::SDiv:
2323  case Instruction::URem:
2324  case Instruction::SRem:
2325  case Instruction::FAdd:
2326  case Instruction::FSub:
2327  case Instruction::FMul:
2328  case Instruction::FDiv:
2329  case Instruction::FRem:
2330  return false;
2331  case Instruction::Add:
2332  case Instruction::Sub:
2333  case Instruction::Mul:
2334  case Instruction::Shl:
2335  case Instruction::LShr:
2336  case Instruction::AShr:
2337  case Instruction::And:
2338  case Instruction::Or:
2339  case Instruction::Xor:
2340  return true;
2341  default:
2342  llvm_unreachable("Argument must be binop opcode");
2343  }
2344 }
2345 
2347  // sizeof is implemented as: (i64) gep (Ty*)null, 1
2348  // Note that a non-inbounds gep is used, as null isn't within any object.
2352  return getPtrToInt(GEP,
2353  Type::getInt64Ty(Ty->getContext()));
2354 }
2355 
2357  // alignof is implemented as: (i64) gep ({i1,Ty}*)null, 0, 1
2358  // Note that a non-inbounds gep is used, as null isn't within any object.
2359  Type *AligningTy = StructType::get(Type::getInt1Ty(Ty->getContext()), Ty);
2360  Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo(0));
2363  Constant *Indices[2] = { Zero, One };
2364  Constant *GEP = getGetElementPtr(AligningTy, NullPtr, Indices);
2365  return getPtrToInt(GEP,
2366  Type::getInt64Ty(Ty->getContext()));
2367 }
2368 
2371  FieldNo));
2372 }
2373 
2375  // offsetof is implemented as: (i64) gep (Ty*)null, 0, FieldNo
2376  // Note that a non-inbounds gep is used, as null isn't within any object.
2377  Constant *GEPIdx[] = {
2379  FieldNo
2380  };
2383  return getPtrToInt(GEP,
2384  Type::getInt64Ty(Ty->getContext()));
2385 }
2386 
2388  Constant *C2, bool OnlyIfReduced) {
2389  assert(C1->getType() == C2->getType() && "Op types should be identical!");
2390 
2391  switch (Predicate) {
2392  default: llvm_unreachable("Invalid CmpInst predicate");
2398  case CmpInst::FCMP_TRUE:
2399  return getFCmp(Predicate, C1, C2, OnlyIfReduced);
2400 
2404  case CmpInst::ICMP_SLE:
2405  return getICmp(Predicate, C1, C2, OnlyIfReduced);
2406  }
2407 }
2408 
2410  Type *OnlyIfReducedTy) {
2411  assert(!SelectInst::areInvalidOperands(C, V1, V2)&&"Invalid select operands");
2412 
2414  return SC; // Fold common cases
2415 
2416  if (OnlyIfReducedTy == V1->getType())
2417  return nullptr;
2418 
2419  Constant *ArgVec[] = { C, V1, V2 };
2421 
2422  LLVMContextImpl *pImpl = C->getContext().pImpl;
2423  return pImpl->ExprConstants.getOrCreate(V1->getType(), Key);
2424 }
2425 
2427  ArrayRef<Value *> Idxs, bool InBounds,
2428  Optional<unsigned> InRangeIndex,
2429  Type *OnlyIfReducedTy) {
2430  PointerType *OrigPtrTy = cast<PointerType>(C->getType()->getScalarType());
2431  assert(Ty && "Must specify element type");
2432  assert(OrigPtrTy->isOpaqueOrPointeeTypeMatches(Ty));
2433 
2434  if (Constant *FC =
2435  ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs))
2436  return FC; // Fold a few common cases.
2437 
2438  // Get the result type of the getelementptr!
2439  Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs);
2440  assert(DestTy && "GEP indices invalid!");
2441  unsigned AS = OrigPtrTy->getAddressSpace();
2442  Type *ReqTy = OrigPtrTy->isOpaque()
2443  ? PointerType::get(OrigPtrTy->getContext(), AS)
2444  : DestTy->getPointerTo(AS);
2445 
2446  auto EltCount = ElementCount::getFixed(0);
2447  if (VectorType *VecTy = dyn_cast<VectorType>(C->getType()))
2448  EltCount = VecTy->getElementCount();
2449  else
2450  for (auto *Idx : Idxs)
2451  if (VectorType *VecTy = dyn_cast<VectorType>(Idx->getType()))
2452  EltCount = VecTy->getElementCount();
2453 
2454  if (EltCount.isNonZero())
2455  ReqTy = VectorType::get(ReqTy, EltCount);
2456 
2457  if (OnlyIfReducedTy == ReqTy)
2458  return nullptr;
2459 
2460  // Look up the constant in the table first to ensure uniqueness
2461  std::vector<Constant*> ArgVec;
2462  ArgVec.reserve(1 + Idxs.size());
2463  ArgVec.push_back(C);
2464  auto GTI = gep_type_begin(Ty, Idxs), GTE = gep_type_end(Ty, Idxs);
2465  for (; GTI != GTE; ++GTI) {
2466  auto *Idx = cast<Constant>(GTI.getOperand());
2467  assert(
2468  (!isa<VectorType>(Idx->getType()) ||
2469  cast<VectorType>(Idx->getType())->getElementCount() == EltCount) &&
2470  "getelementptr index type missmatch");
2471 
2472  if (GTI.isStruct() && Idx->getType()->isVectorTy()) {
2473  Idx = Idx->getSplatValue();
2474  } else if (GTI.isSequential() && EltCount.isNonZero() &&
2475  !Idx->getType()->isVectorTy()) {
2476  Idx = ConstantVector::getSplat(EltCount, Idx);
2477  }
2478  ArgVec.push_back(Idx);
2479  }
2480 
2481  unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
2482  if (InRangeIndex && *InRangeIndex < 63)
2483  SubClassOptionalData |= (*InRangeIndex + 1) << 1;
2484  const ConstantExprKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
2485  SubClassOptionalData, None, Ty);
2486 
2487  LLVMContextImpl *pImpl = C->getContext().pImpl;
2488  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2489 }
2490 
2492  Constant *RHS, bool OnlyIfReduced) {
2493  auto Predicate = static_cast<CmpInst::Predicate>(pred);
2494  assert(LHS->getType() == RHS->getType());
2495  assert(CmpInst::isIntPredicate(Predicate) && "Invalid ICmp Predicate");
2496 
2498  return FC; // Fold a few common cases...
2499 
2500  if (OnlyIfReduced)
2501  return nullptr;
2502 
2503  // Look up the constant in the table first to ensure uniqueness
2504  Constant *ArgVec[] = { LHS, RHS };
2505  // Get the key type with both the opcode and predicate
2506  const ConstantExprKeyType Key(Instruction::ICmp, ArgVec, Predicate);
2507 
2508  Type *ResultTy = Type::getInt1Ty(LHS->getContext());
2509  if (VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
2510  ResultTy = VectorType::get(ResultTy, VT->getElementCount());
2511 
2512  LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
2513  return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
2514 }
2515 
2517  Constant *RHS, bool OnlyIfReduced) {
2518  auto Predicate = static_cast<CmpInst::Predicate>(pred);
2519  assert(LHS->getType() == RHS->getType());
2520  assert(CmpInst::isFPPredicate(Predicate) && "Invalid FCmp Predicate");
2521 
2523  return FC; // Fold a few common cases...
2524 
2525  if (OnlyIfReduced)
2526  return nullptr;
2527 
2528  // Look up the constant in the table first to ensure uniqueness
2529  Constant *ArgVec[] = { LHS, RHS };
2530  // Get the key type with both the opcode and predicate
2531  const ConstantExprKeyType Key(Instruction::FCmp, ArgVec, Predicate);
2532 
2533  Type *ResultTy = Type::getInt1Ty(LHS->getContext());
2534  if (VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
2535  ResultTy = VectorType::get(ResultTy, VT->getElementCount());
2536 
2537  LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
2538  return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
2539 }
2540 
2542  Type *OnlyIfReducedTy) {
2543  assert(Val->getType()->isVectorTy() &&
2544  "Tried to create extractelement operation on non-vector type!");
2545  assert(Idx->getType()->isIntegerTy() &&
2546  "Extractelement index must be an integer type!");
2547 
2549  return FC; // Fold a few common cases.
2550 
2551  Type *ReqTy = cast<VectorType>(Val->getType())->getElementType();
2552  if (OnlyIfReducedTy == ReqTy)
2553  return nullptr;
2554 
2555  // Look up the constant in the table first to ensure uniqueness
2556  Constant *ArgVec[] = { Val, Idx };
2557  const ConstantExprKeyType Key(Instruction::ExtractElement, ArgVec);
2558 
2559  LLVMContextImpl *pImpl = Val->getContext().pImpl;
2560  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
2561 }
2562 
2564  Constant *Idx, Type *OnlyIfReducedTy) {
2565  assert(Val->getType()->isVectorTy() &&
2566  "Tried to create insertelement operation on non-vector type!");
2567  assert(Elt->getType() == cast<VectorType>(Val->getType())->getElementType() &&
2568  "Insertelement types must match!");
2569  assert(Idx->getType()->isIntegerTy() &&
2570  "Insertelement index must be i32 type!");
2571 
2572  if (Constant *FC = ConstantFoldInsertElementInstruction(Val, Elt, Idx))
2573  return FC; // Fold a few common cases.
2574 
2575  if (OnlyIfReducedTy == Val->getType())
2576  return nullptr;
2577 
2578  // Look up the constant in the table first to ensure uniqueness
2579  Constant *ArgVec[] = { Val, Elt, Idx };
2580  const ConstantExprKeyType Key(Instruction::InsertElement, ArgVec);
2581 
2582  LLVMContextImpl *pImpl = Val->getContext().pImpl;
2583  return pImpl->ExprConstants.getOrCreate(Val->getType(), Key);
2584 }
2585 
2588  Type *OnlyIfReducedTy) {
2590  "Invalid shuffle vector constant expr operands!");
2591 
2593  return FC; // Fold a few common cases.
2594 
2595  unsigned NElts = Mask.size();
2596  auto V1VTy = cast<VectorType>(V1->getType());
2597  Type *EltTy = V1VTy->getElementType();
2598  bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2599  Type *ShufTy = VectorType::get(EltTy, NElts, TypeIsScalable);
2600 
2601  if (OnlyIfReducedTy == ShufTy)
2602  return nullptr;
2603 
2604  // Look up the constant in the table first to ensure uniqueness
2605  Constant *ArgVec[] = {V1, V2};
2606  ConstantExprKeyType Key(Instruction::ShuffleVector, ArgVec, 0, 0, Mask);
2607 
2608  LLVMContextImpl *pImpl = ShufTy->getContext().pImpl;
2609  return pImpl->ExprConstants.getOrCreate(ShufTy, Key);
2610 }
2611 
2612 Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) {
2613  assert(C->getType()->isIntOrIntVectorTy() &&
2614  "Cannot NEG a nonintegral value!");
2615  return getSub(ConstantFP::getZeroValueForNegation(C->getType()),
2616  C, HasNUW, HasNSW);
2617 }
2618 
2620  assert(C->getType()->isIntOrIntVectorTy() &&
2621  "Cannot NOT a nonintegral value!");
2622  return get(Instruction::Xor, C, Constant::getAllOnesValue(C->getType()));
2623 }
2624 
2626  bool HasNUW, bool HasNSW) {
2627  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2629  return get(Instruction::Add, C1, C2, Flags);
2630 }
2631 
2633  bool HasNUW, bool HasNSW) {
2634  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2636  return get(Instruction::Sub, C1, C2, Flags);
2637 }
2638 
2640  bool HasNUW, bool HasNSW) {
2641  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2643  return get(Instruction::Mul, C1, C2, Flags);
2644 }
2645 
2647  return get(Instruction::And, C1, C2);
2648 }
2649 
2651  return get(Instruction::Or, C1, C2);
2652 }
2653 
2655  return get(Instruction::Xor, C1, C2);
2656 }
2657 
2660  return getSelect(Cmp, C1, C2);
2661 }
2662 
2664  bool HasNUW, bool HasNSW) {
2665  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2667  return get(Instruction::Shl, C1, C2, Flags);
2668 }
2669 
2671  return get(Instruction::LShr, C1, C2,
2672  isExact ? PossiblyExactOperator::IsExact : 0);
2673 }
2674 
2676  return get(Instruction::AShr, C1, C2,
2677  isExact ? PossiblyExactOperator::IsExact : 0);
2678 }
2679 
2681  Type *Ty = C->getType();
2682  const APInt *IVal;
2683  if (match(C, m_APInt(IVal)) && IVal->isPowerOf2())
2684  return ConstantInt::get(Ty, IVal->logBase2());
2685 
2686  // FIXME: We can extract pow of 2 of splat constant for scalable vectors.
2687  auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2688  if (!VecTy)
2689  return nullptr;
2690 
2692  for (unsigned I = 0, E = VecTy->getNumElements(); I != E; ++I) {
2693  Constant *Elt = C->getAggregateElement(I);
2694  if (!Elt)
2695  return nullptr;
2696  // Note that log2(iN undef) is *NOT* iN undef, because log2(iN undef) u< N.
2697  if (isa<UndefValue>(Elt)) {
2698  Elts.push_back(Constant::getNullValue(Ty->getScalarType()));
2699  continue;
2700  }
2701  if (!match(Elt, m_APInt(IVal)) || !IVal->isPowerOf2())
2702  return nullptr;
2703  Elts.push_back(ConstantInt::get(Ty->getScalarType(), IVal->logBase2()));
2704  }
2705 
2706  return ConstantVector::get(Elts);
2707 }
2708 
2710  bool AllowRHSConstant, bool NSZ) {
2711  assert(Instruction::isBinaryOp(Opcode) && "Only binops allowed");
2712 
2713  // Commutative opcodes: it does not matter if AllowRHSConstant is set.
2714  if (Instruction::isCommutative(Opcode)) {
2715  switch (Opcode) {
2716  case Instruction::Add: // X + 0 = X
2717  case Instruction::Or: // X | 0 = X
2718  case Instruction::Xor: // X ^ 0 = X
2719  return Constant::getNullValue(Ty);
2720  case Instruction::Mul: // X * 1 = X
2721  return ConstantInt::get(Ty, 1);
2722  case Instruction::And: // X & -1 = X
2723  return Constant::getAllOnesValue(Ty);
2724  case Instruction::FAdd: // X + -0.0 = X
2725  return ConstantFP::getZero(Ty, !NSZ);
2726  case Instruction::FMul: // X * 1.0 = X
2727  return ConstantFP::get(Ty, 1.0);
2728  default:
2729  llvm_unreachable("Every commutative binop has an identity constant");
2730  }
2731  }
2732 
2733  // Non-commutative opcodes: AllowRHSConstant must be set.
2734  if (!AllowRHSConstant)
2735  return nullptr;
2736 
2737  switch (Opcode) {
2738  case Instruction::Sub: // X - 0 = X
2739  case Instruction::Shl: // X << 0 = X
2740  case Instruction::LShr: // X >>u 0 = X
2741  case Instruction::AShr: // X >> 0 = X
2742  case Instruction::FSub: // X - 0.0 = X
2743  return Constant::getNullValue(Ty);
2744  case Instruction::SDiv: // X / 1 = X
2745  case Instruction::UDiv: // X /u 1 = X
2746  return ConstantInt::get(Ty, 1);
2747  case Instruction::FDiv: // X / 1.0 = X
2748  return ConstantFP::get(Ty, 1.0);
2749  default:
2750  return nullptr;
2751  }
2752 }
2753 
2755  switch (Opcode) {
2756  default:
2757  // Doesn't have an absorber.
2758  return nullptr;
2759 
2760  case Instruction::Or:
2761  return Constant::getAllOnesValue(Ty);
2762 
2763  case Instruction::And:
2764  case Instruction::Mul:
2765  return Constant::getNullValue(Ty);
2766  }
2767 }
2768 
2769 /// Remove the constant from the constant table.
2770 void ConstantExpr::destroyConstantImpl() {
2771  getType()->getContext().pImpl->ExprConstants.remove(this);
2772 }
2773 
2774 const char *ConstantExpr::getOpcodeName() const {
2776 }
2777 
2778 GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2779  Type *SrcElementTy, Constant *C, ArrayRef<Constant *> IdxList, Type *DestTy)
2780  : ConstantExpr(DestTy, Instruction::GetElementPtr,
2782  (IdxList.size() + 1),
2783  IdxList.size() + 1),
2784  SrcElementTy(SrcElementTy),
2785  ResElementTy(GetElementPtrInst::getIndexedType(SrcElementTy, IdxList)) {
2786  Op<0>() = C;
2787  Use *OperandList = getOperandList();
2788  for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
2789  OperandList[i+1] = IdxList[i];
2790 }
2791 
2793  return SrcElementTy;
2794 }
2795 
2797  return ResElementTy;
2798 }
2799 
2800 //===----------------------------------------------------------------------===//
2801 // ConstantData* implementations
2802 
2804  if (ArrayType *ATy = dyn_cast<ArrayType>(getType()))
2805  return ATy->getElementType();
2806  return cast<VectorType>(getType())->getElementType();
2807 }
2808 
2810  return StringRef(DataElements, getNumElements()*getElementByteSize());
2811 }
2812 
2814  if (Ty->isHalfTy() || Ty->isBFloatTy() || Ty->isFloatTy() || Ty->isDoubleTy())
2815  return true;
2816  if (auto *IT = dyn_cast<IntegerType>(Ty)) {
2817  switch (IT->getBitWidth()) {
2818  case 8:
2819  case 16:
2820  case 32:
2821  case 64:
2822  return true;
2823  default: break;
2824  }
2825  }
2826  return false;
2827 }
2828 
2830  if (ArrayType *AT = dyn_cast<ArrayType>(getType()))
2831  return AT->getNumElements();
2832  return cast<FixedVectorType>(getType())->getNumElements();
2833 }
2834 
2835 
2837  return getElementType()->getPrimitiveSizeInBits()/8;
2838 }
2839 
2840 /// Return the start of the specified element.
2841 const char *ConstantDataSequential::getElementPointer(unsigned Elt) const {
2842  assert(Elt < getNumElements() && "Invalid Elt");
2843  return DataElements+Elt*getElementByteSize();
2844 }
2845 
2846 
2847 /// Return true if the array is empty or all zeros.
2848 static bool isAllZeros(StringRef Arr) {
2849  for (char I : Arr)
2850  if (I != 0)
2851  return false;
2852  return true;
2853 }
2854 
2855 /// This is the underlying implementation of all of the
2856 /// ConstantDataSequential::get methods. They all thunk down to here, providing
2857 /// the correct element type. We take the bytes in as a StringRef because
2858 /// we *want* an underlying "char*" to avoid TBAA type punning violations.
2860 #ifndef NDEBUG
2861  if (ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2862  assert(isElementTypeCompatible(ATy->getElementType()));
2863  else
2864  assert(isElementTypeCompatible(cast<VectorType>(Ty)->getElementType()));
2865 #endif
2866  // If the elements are all zero or there are no elements, return a CAZ, which
2867  // is more dense and canonical.
2868  if (isAllZeros(Elements))
2869  return ConstantAggregateZero::get(Ty);
2870 
2871  // Do a lookup to see if we have already formed one of these.
2872  auto &Slot =
2873  *Ty->getContext()
2874  .pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr))
2875  .first;
2876 
2877  // The bucket can point to a linked list of different CDS's that have the same
2878  // body but different types. For example, 0,0,0,1 could be a 4 element array
2879  // of i8, or a 1-element array of i32. They'll both end up in the same
2880  /// StringMap bucket, linked up by their Next pointers. Walk the list.
2881  std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2882  for (; *Entry; Entry = &(*Entry)->Next)
2883  if ((*Entry)->getType() == Ty)
2884  return Entry->get();
2885 
2886  // Okay, we didn't get a hit. Create a node of the right class, link it in,
2887  // and return it.
2888  if (isa<ArrayType>(Ty)) {
2889  // Use reset because std::make_unique can't access the constructor.
2890  Entry->reset(new ConstantDataArray(Ty, Slot.first().data()));
2891  return Entry->get();
2892  }
2893 
2894  assert(isa<VectorType>(Ty));
2895  // Use reset because std::make_unique can't access the constructor.
2896  Entry->reset(new ConstantDataVector(Ty, Slot.first().data()));
2897  return Entry->get();
2898 }
2899 
2900 void ConstantDataSequential::destroyConstantImpl() {
2901  // Remove the constant from the StringMap.
2904 
2905  auto Slot = CDSConstants.find(getRawDataValues());
2906 
2907  assert(Slot != CDSConstants.end() && "CDS not found in uniquing table");
2908 
2909  std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
2910 
2911  // Remove the entry from the hash table.
2912  if (!(*Entry)->Next) {
2913  // If there is only one value in the bucket (common case) it must be this
2914  // entry, and removing the entry should remove the bucket completely.
2915  assert(Entry->get() == this && "Hash mismatch in ConstantDataSequential");
2916  getContext().pImpl->CDSConstants.erase(Slot);
2917  return;
2918  }
2919 
2920  // Otherwise, there are multiple entries linked off the bucket, unlink the
2921  // node we care about but keep the bucket around.
2922  while (true) {
2923  std::unique_ptr<ConstantDataSequential> &Node = *Entry;
2924  assert(Node && "Didn't find entry in its uniquing hash table!");
2925  // If we found our entry, unlink it from the list and we're done.
2926  if (Node.get() == this) {
2927  Node = std::move(Node->Next);
2928  return;
2929  }
2930 
2931  Entry = &Node->Next;
2932  }
2933 }
2934 
2935 /// getFP() constructors - Return a constant of array type with a float
2936 /// element type taken from argument `ElementType', and count taken from
2937 /// argument `Elts'. The amount of bits of the contained type must match the
2938 /// number of bits of the type contained in the passed in ArrayRef.
2939 /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
2940 /// that this can return a ConstantAggregateZero object.
2942  assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
2943  "Element type is not a 16-bit float type");
2944  Type *Ty = ArrayType::get(ElementType, Elts.size());
2945  const char *Data = reinterpret_cast<const char *>(Elts.data());
2946  return getImpl(StringRef(Data, Elts.size() * 2), Ty);
2947 }
2949  assert(ElementType->isFloatTy() && "Element type is not a 32-bit float type");
2950  Type *Ty = ArrayType::get(ElementType, Elts.size());
2951  const char *Data = reinterpret_cast<const char *>(Elts.data());
2952  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
2953 }
2955  assert(ElementType->isDoubleTy() &&
2956  "Element type is not a 64-bit float type");
2957  Type *Ty = ArrayType::get(ElementType, Elts.size());
2958  const char *Data = reinterpret_cast<const char *>(Elts.data());
2959  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
2960 }
2961 
2963  StringRef Str, bool AddNull) {
2964  if (!AddNull) {
2965  const uint8_t *Data = Str.bytes_begin();
2966  return get(Context, makeArrayRef(Data, Str.size()));
2967  }
2968 
2969  SmallVector<uint8_t, 64> ElementVals;
2970  ElementVals.append(Str.begin(), Str.end());
2971  ElementVals.push_back(0);
2972  return get(Context, ElementVals);
2973 }
2974 
2975 /// get() constructors - Return a constant with vector type with an element
2976 /// count and element type matching the ArrayRef passed in. Note that this
2977 /// can return a ConstantAggregateZero object.
2979  auto *Ty = FixedVectorType::get(Type::getInt8Ty(Context), Elts.size());
2980  const char *Data = reinterpret_cast<const char *>(Elts.data());
2981  return getImpl(StringRef(Data, Elts.size() * 1), Ty);
2982 }
2984  auto *Ty = FixedVectorType::get(Type::getInt16Ty(Context), Elts.size());
2985  const char *Data = reinterpret_cast<const char *>(Elts.data());
2986  return getImpl(StringRef(Data, Elts.size() * 2), Ty);
2987 }
2989  auto *Ty = FixedVectorType::get(Type::getInt32Ty(Context), Elts.size());
2990  const char *Data = reinterpret_cast<const char *>(Elts.data());
2991  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
2992 }
2994  auto *Ty = FixedVectorType::get(Type::getInt64Ty(Context), Elts.size());
2995  const char *Data = reinterpret_cast<const char *>(Elts.data());
2996  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
2997 }
2999  auto *Ty = FixedVectorType::get(Type::getFloatTy(Context), Elts.size());
3000  const char *Data = reinterpret_cast<const char *>(Elts.data());
3001  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
3002 }
3004  auto *Ty = FixedVectorType::get(Type::getDoubleTy(Context), Elts.size());
3005  const char *Data = reinterpret_cast<const char *>(Elts.data());
3006  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
3007 }
3008 
3009 /// getFP() constructors - Return a constant of vector type with a float
3010 /// element type taken from argument `ElementType', and count taken from
3011 /// argument `Elts'. The amount of bits of the contained type must match the
3012 /// number of bits of the type contained in the passed in ArrayRef.
3013 /// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note
3014 /// that this can return a ConstantAggregateZero object.
3016  ArrayRef<uint16_t> Elts) {
3017  assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
3018  "Element type is not a 16-bit float type");
3019  auto *Ty = FixedVectorType::get(ElementType, Elts.size());
3020  const char *Data = reinterpret_cast<const char *>(Elts.data());
3021  return getImpl(StringRef(Data, Elts.size() * 2), Ty);
3022 }
3024  ArrayRef<uint32_t> Elts) {
3025  assert(ElementType->isFloatTy() && "Element type is not a 32-bit float type");
3026  auto *Ty = FixedVectorType::get(ElementType, Elts.size());
3027  const char *Data = reinterpret_cast<const char *>(Elts.data());
3028  return getImpl(StringRef(Data, Elts.size() * 4), Ty);
3029 }
3031  ArrayRef<uint64_t> Elts) {
3032  assert(ElementType->isDoubleTy() &&
3033  "Element type is not a 64-bit float type");
3034  auto *Ty = FixedVectorType::get(ElementType, Elts.size());
3035  const char *Data = reinterpret_cast<const char *>(Elts.data());
3036  return getImpl(StringRef(Data, Elts.size() * 8), Ty);
3037 }
3038 
3041  "Element type not compatible with ConstantData");
3042  if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
3043  if (CI->getType()->isIntegerTy(8)) {
3044  SmallVector<uint8_t, 16> Elts(NumElts, CI->getZExtValue());
3045  return get(V->getContext(), Elts);
3046  }
3047  if (CI->getType()->isIntegerTy(16)) {
3048  SmallVector<uint16_t, 16> Elts(NumElts, CI->getZExtValue());
3049  return get(V->getContext(), Elts);
3050  }
3051  if (CI->getType()->isIntegerTy(32)) {
3052  SmallVector<uint32_t, 16> Elts(NumElts, CI->getZExtValue());
3053  return get(V->getContext(), Elts);
3054  }
3055  assert(CI->getType()->isIntegerTy(64) && "Unsupported ConstantData type");
3056  SmallVector<uint64_t, 16> Elts(NumElts, CI->getZExtValue());
3057  return get(V->getContext(), Elts);
3058  }
3059 
3060  if (ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3061  if (CFP->getType()->isHalfTy()) {
3063  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3064  return getFP(V->getType(), Elts);
3065  }
3066  if (CFP->getType()->isBFloatTy()) {
3068  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3069  return getFP(V->getType(), Elts);
3070  }
3071  if (CFP->getType()->isFloatTy()) {
3073  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3074  return getFP(V->getType(), Elts);
3075  }
3076  if (CFP->getType()->isDoubleTy()) {
3078  NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3079  return getFP(V->getType(), Elts);
3080  }
3081  }
3083 }
3084 
3085 
3087  assert(isa<IntegerType>(getElementType()) &&
3088  "Accessor can only be used when element is an integer");
3089  const char *EltPtr = getElementPointer(Elt);
3090 
3091  // The data is stored in host byte order, make sure to cast back to the right
3092  // type to load with the right endianness.
3093  switch (getElementType()->getIntegerBitWidth()) {
3094  default: llvm_unreachable("Invalid bitwidth for CDS");
3095  case 8:
3096  return *reinterpret_cast<const uint8_t *>(EltPtr);
3097  case 16:
3098  return *reinterpret_cast<const uint16_t *>(EltPtr);
3099  case 32:
3100  return *reinterpret_cast<const uint32_t *>(EltPtr);
3101  case 64:
3102  return *reinterpret_cast<const uint64_t *>(EltPtr);
3103  }
3104 }
3105 
3107  assert(isa<IntegerType>(getElementType()) &&
3108  "Accessor can only be used when element is an integer");
3109  const char *EltPtr = getElementPointer(Elt);
3110 
3111  // The data is stored in host byte order, make sure to cast back to the right
3112  // type to load with the right endianness.
3113  switch (getElementType()->getIntegerBitWidth()) {
3114  default: llvm_unreachable("Invalid bitwidth for CDS");
3115  case 8: {
3116  auto EltVal = *reinterpret_cast<const uint8_t *>(EltPtr);
3117  return APInt(8, EltVal);
3118  }
3119  case 16: {
3120  auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3121  return APInt(16, EltVal);
3122  }
3123  case 32: {
3124  auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
3125  return APInt(32, EltVal);
3126  }
3127  case 64: {
3128  auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
3129  return APInt(64, EltVal);
3130  }
3131  }
3132 }
3133 
3135  const char *EltPtr = getElementPointer(Elt);
3136 
3137  switch (getElementType()->getTypeID()) {
3138  default:
3139  llvm_unreachable("Accessor can only be used when element is float/double!");
3140  case Type::HalfTyID: {
3141  auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3142  return APFloat(APFloat::IEEEhalf(), APInt(16, EltVal));
3143  }
3144  case Type::BFloatTyID: {
3145  auto EltVal = *reinterpret_cast<const uint16_t *>(EltPtr);
3146  return APFloat(APFloat::BFloat(), APInt(16, EltVal));
3147  }
3148  case Type::FloatTyID: {
3149  auto EltVal = *reinterpret_cast<const uint32_t *>(EltPtr);
3150  return APFloat(APFloat::IEEEsingle(), APInt(32, EltVal));
3151  }
3152  case Type::DoubleTyID: {
3153  auto EltVal = *reinterpret_cast<const uint64_t *>(EltPtr);
3154  return APFloat(APFloat::IEEEdouble(), APInt(64, EltVal));
3155  }
3156  }
3157 }
3158 
3160  assert(getElementType()->isFloatTy() &&
3161  "Accessor can only be used when element is a 'float'");
3162  return *reinterpret_cast<const float *>(getElementPointer(Elt));
3163 }
3164 
3166  assert(getElementType()->isDoubleTy() &&
3167  "Accessor can only be used when element is a 'float'");
3168  return *reinterpret_cast<const double *>(getElementPointer(Elt));
3169 }
3170 
3172  if (getElementType()->isHalfTy() || getElementType()->isBFloatTy() ||
3173  getElementType()->isFloatTy() || getElementType()->isDoubleTy())
3175 
3177 }
3178 
3179 bool ConstantDataSequential::isString(unsigned CharSize) const {
3180  return isa<ArrayType>(getType()) && getElementType()->isIntegerTy(CharSize);
3181 }
3182 
3184  if (!isString())
3185  return false;
3186 
3187  StringRef Str = getAsString();
3188 
3189  // The last value must be nul.
3190  if (Str.back() != 0) return false;
3191 
3192  // Other elements must be non-nul.
3193  return !Str.drop_back().contains(0);
3194 }
3195 
3196 bool ConstantDataVector::isSplatData() const {
3197  const char *Base = getRawDataValues().data();
3198 
3199  // Compare elements 1+ to the 0'th element.
3200  unsigned EltSize = getElementByteSize();
3201  for (unsigned i = 1, e = getNumElements(); i != e; ++i)
3202  if (memcmp(Base, Base+i*EltSize, EltSize))
3203  return false;
3204 
3205  return true;
3206 }
3207 
3209  if (!IsSplatSet) {
3210  IsSplatSet = true;
3211  IsSplat = isSplatData();
3212  }
3213  return IsSplat;
3214 }
3215 
3217  // If they're all the same, return the 0th one as a representative.
3218  return isSplat() ? getElementAsConstant(0) : nullptr;
3219 }
3220 
3221 //===----------------------------------------------------------------------===//
3222 // handleOperandChange implementations
3223 
3224 /// Update this constant array to change uses of
3225 /// 'From' to be uses of 'To'. This must update the uniquing data structures
3226 /// etc.
3227 ///
3228 /// Note that we intentionally replace all uses of From with To here. Consider
3229 /// a large array that uses 'From' 1000 times. By handling this case all here,
3230 /// ConstantArray::handleOperandChange is only invoked once, and that
3231 /// single invocation handles all 1000 uses. Handling them one at a time would
3232 /// work, but would be really slow because it would have to unique each updated
3233 /// array instance.
3234 ///
3236  Value *Replacement = nullptr;
3237  switch (getValueID()) {
3238  default:
3239  llvm_unreachable("Not a constant!");
3240 #define HANDLE_CONSTANT(Name) \
3241  case Value::Name##Val: \
3242  Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3243  break;
3244 #include "llvm/IR/Value.def"
3245  }
3246 
3247  // If handleOperandChangeImpl returned nullptr, then it handled
3248  // replacing itself and we don't want to delete or replace anything else here.
3249  if (!Replacement)
3250  return;
3251 
3252  // I do need to replace this with an existing value.
3253  assert(Replacement != this && "I didn't contain From!");
3254 
3255  // Everyone using this now uses the replacement.
3256  replaceAllUsesWith(Replacement);
3257 
3258  // Delete the old constant!
3259  destroyConstant();
3260 }
3261 
3262 Value *ConstantArray::handleOperandChangeImpl(Value *From, Value *To) {
3263  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
3264  Constant *ToC = cast<Constant>(To);
3265 
3267  Values.reserve(getNumOperands()); // Build replacement array.
3268 
3269  // Fill values with the modified operands of the constant array. Also,
3270  // compute whether this turns into an all-zeros array.
3271  unsigned NumUpdated = 0;
3272 
3273  // Keep track of whether all the values in the array are "ToC".
3274  bool AllSame = true;
3275  Use *OperandList = getOperandList();
3276  unsigned OperandNo = 0;
3277  for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
3278  Constant *Val = cast<Constant>(O->get());
3279  if (Val == From) {
3280  OperandNo = (O - OperandList);
3281  Val = ToC;
3282  ++NumUpdated;
3283  }
3284  Values.push_back(Val);
3285  AllSame &= Val == ToC;
3286  }
3287 
3288  if (AllSame && ToC->isNullValue())
3290 
3291  if (AllSame && isa<UndefValue>(ToC))
3292  return UndefValue::get(getType());
3293 
3294  // Check for any other type of constant-folding.
3295  if (Constant *C = getImpl(getType(), Values))
3296  return C;
3297 
3298  // Update to the new value.
3300  Values, this, From, ToC, NumUpdated, OperandNo);
3301 }
3302 
3303 Value *ConstantStruct::handleOperandChangeImpl(Value *From, Value *To) {
3304  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
3305  Constant *ToC = cast<Constant>(To);
3306 
3307  Use *OperandList = getOperandList();
3308 
3310  Values.reserve(getNumOperands()); // Build replacement struct.
3311 
3312  // Fill values with the modified operands of the constant struct. Also,
3313  // compute whether this turns into an all-zeros struct.
3314  unsigned NumUpdated = 0;
3315  bool AllSame = true;
3316  unsigned OperandNo = 0;
3317  for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O) {
3318  Constant *Val = cast<Constant>(O->get());
3319  if (Val == From) {
3320  OperandNo = (O - OperandList);
3321  Val = ToC;
3322  ++NumUpdated;
3323  }
3324  Values.push_back(Val);
3325  AllSame &= Val == ToC;
3326  }
3327 
3328  if (AllSame && ToC->isNullValue())
3330 
3331  if (AllSame && isa<UndefValue>(ToC))
3332  return UndefValue::get(getType());
3333 
3334  // Update to the new value.
3336  Values, this, From, ToC, NumUpdated, OperandNo);
3337 }
3338 
3339 Value *ConstantVector::handleOperandChangeImpl(Value *From, Value *To) {
3340  assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
3341  Constant *ToC = cast<Constant>(To);
3342 
3344  Values.reserve(getNumOperands()); // Build replacement array...
3345  unsigned NumUpdated = 0;
3346  unsigned OperandNo = 0;
3347  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
3348  Constant *Val = getOperand(i);
3349  if (Val == From) {
3350  OperandNo = i;
3351  ++NumUpdated;
3352  Val = ToC;
3353  }
3354  Values.push_back(Val);
3355  }
3356 
3357  if (Constant *C = getImpl(Values))
3358  return C;
3359 
3360  // Update to the new value.
3362  Values, this, From, ToC, NumUpdated, OperandNo);
3363 }
3364 
3365 Value *ConstantExpr::handleOperandChangeImpl(Value *From, Value *ToV) {
3366  assert(isa<Constant>(ToV) && "Cannot make Constant refer to non-constant!");
3367  Constant *To = cast<Constant>(ToV);
3368 
3370  unsigned NumUpdated = 0;
3371  unsigned OperandNo = 0;
3372  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
3373  Constant *Op = getOperand(i);
3374  if (Op == From) {
3375  OperandNo = i;
3376  ++NumUpdated;
3377  Op = To;
3378  }
3379  NewOps.push_back(Op);
3380  }
3381  assert(NumUpdated && "I didn't contain From!");
3382 
3383  if (Constant *C = getWithOperands(NewOps, getType(), true))
3384  return C;
3385 
3386  // Update to the new value.
3387  return getContext().pImpl->ExprConstants.replaceOperandsInPlace(
3388  NewOps, this, From, To, NumUpdated, OperandNo);
3389 }
3390 
3392  SmallVector<Value *, 4> ValueOperands(operands());
3393  ArrayRef<Value*> Ops(ValueOperands);
3394 
3395  switch (getOpcode()) {
3396  case Instruction::Trunc:
3397  case Instruction::ZExt:
3398  case Instruction::SExt:
3399  case Instruction::FPTrunc:
3400  case Instruction::FPExt:
3401  case Instruction::UIToFP:
3402  case Instruction::SIToFP:
3403  case Instruction::FPToUI:
3404  case Instruction::FPToSI:
3405  case Instruction::PtrToInt:
3406  case Instruction::IntToPtr:
3407  case Instruction::BitCast:
3408  case Instruction::AddrSpaceCast:
3410  getType(), "", InsertBefore);
3411  case Instruction::Select:
3412  return SelectInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore);
3413  case Instruction::InsertElement:
3414  return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore);
3415  case Instruction::ExtractElement:
3416  return ExtractElementInst::Create(Ops[0], Ops[1], "", InsertBefore);
3417  case Instruction::ShuffleVector:
3418  return new ShuffleVectorInst(Ops[0], Ops[1], getShuffleMask(), "",
3419  InsertBefore);
3420 
3421  case Instruction::GetElementPtr: {
3422  const auto *GO = cast<GEPOperator>(this);
3423  if (GO->isInBounds())
3425  GO->getSourceElementType(), Ops[0], Ops.slice(1), "", InsertBefore);
3426  return GetElementPtrInst::Create(GO->getSourceElementType(), Ops[0],
3427  Ops.slice(1), "", InsertBefore);
3428  }
3429  case Instruction::ICmp:
3430  case Instruction::FCmp:
3432  (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1],
3433  "", InsertBefore);
3434  default:
3435  assert(getNumOperands() == 2 && "Must be binary operator?");
3437  (Instruction::BinaryOps)getOpcode(), Ops[0], Ops[1], "", InsertBefore);
3438  if (isa<OverflowingBinaryOperator>(BO)) {
3443  }
3444  if (isa<PossiblyExactOperator>(BO))
3446  return BO;
3447  }
3448 }
i
i
Definition: README.txt:29
llvm::lltok::APFloat
@ APFloat
Definition: LLToken.h:438
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:69
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:689
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:18
llvm::ConstantDataSequential::getElementByteSize
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
Definition: Constants.cpp:2836
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::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:2541
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:1451
llvm::ConstantExpr::getNot
static Constant * getNot(Constant *C)
Definition: Constants.cpp:2619
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:1526
llvm::ConstantExpr::getZExtOrBitCast
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1980
llvm::ConstantExpr::getSIToFP
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2136
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:2774
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:1062
isAllZeros
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
Definition: Constants.cpp:2848
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:655
llvm::LLVMContextImpl::FPConstants
FPMapTy FPConstants
Definition: LLVMContextImpl.h:1408
llvm::ConstantExpr::getZExt
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2087
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:172
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1306
llvm::LLVMContextImpl::UVConstants
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
Definition: LLVMContextImpl.h:1444
llvm::ConstantExpr::getAsInstruction
Instruction * getAsInstruction(Instruction *InsertBefore=nullptr) const
Returns an Instruction which implements the same operation as this ConstantExpr.
Definition: Constants.cpp:3391
rangeOnlyContains
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
Definition: Constants.cpp:1159
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:2047
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:314
llvm::ConstantExpr::getOpcode
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Definition: Constants.h:1270
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:1132
llvm::ConstantExpr::getSExt
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2073
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:1182
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:2491
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:1142
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:3086
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:1444
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:3628
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:3243
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:2197
R600_InstFlag::FC
@ FC
Definition: R600Defines.h:32
llvm::LLVMContextImpl::ExprConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
Definition: LLVMContextImpl.h:1457
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:1033
llvm::ConstantExpr::getSelect
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
Definition: Constants.cpp:2409
llvm::Type::getTypeID
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
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:1998
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:184
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:2978
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:3159
llvm::InsertElementInst::Create
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1950
llvm::ConstantAggregateZero::getElementCount
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Definition: Constants.cpp:1084
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:2369
llvm::CmpInst::ICMP_SGT
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:746
llvm::StringMap::end
iterator end()
Definition: StringMap.h:204
llvm::ExtractElementInst::Create
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1885
llvm::GetElementPtrConstantExpr
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Definition: ConstantsContext.h:213
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::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:2813
llvm::ConstantExpr::getFPToSI
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2158
llvm::ConstantAggregateZero
All zero aggregate value.
Definition: Constants.h:337
llvm::Constant::needsDynamicRelocation
bool needsDynamicRelocation() const
Definition: Constants.cpp:613
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1641
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:617
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:149
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:2072
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:2680
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
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:217
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:168
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:157
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:3179
llvm::APFloat::getSemantics
const fltSemantics & getSemantics() const
Definition: APFloat.h:1223
llvm::LLVMContextImpl::DSOLocalEquivalents
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
Definition: LLVMContextImpl.h:1453
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:587
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:76
llvm::ConstantExpr::isSupportedBinOp
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
Definition: Constants.cpp:2319
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:1292
getFPSequenceIfElementsMatch
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
Definition: Constants.cpp:1180
llvm::ConstantExpr::getPointerCast
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:2009
llvm::LLVMContextImpl::TheNoneToken
std::unique_ptr< ConstantTokenNone > TheNoneToken
Definition: LLVMContextImpl.h:1470
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:1434
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:2632
llvm::ConstantExpr::get
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
Definition: Constants.cpp:2231
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:3134
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:278
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:2709
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:220
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:1590
llvm::SelectInst::Create
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Definition: Instructions.h:1768
llvm::ConstantExpr::getShuffleMask
ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
Definition: Constants.cpp:1448
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::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:153
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:1107
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:1355
llvm::ConstantExpr::getIntToPtr
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2183
llvm::LLVMContextImpl::CAZConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
Definition: LLVMContextImpl.h:1431
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::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:2169
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::Instruction::OtherOps
OtherOps
Definition: Instruction.h:801
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:232
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:2754
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:423
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::Instruction::getOpcodeName
const char * getOpcodeName() const
Definition: Instruction.h:166
llvm::Instruction::CastOps
CastOps
Definition: Instruction.h:787
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:3216
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::ConstantFoldGetElementPtr
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
Definition: ConstantFold.cpp:2032
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:1391
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:1049
llvm::ShuffleVectorConstantExpr
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Definition: ConstantsContext.h:178
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1708
llvm::ConstantExpr::getXor
static Constant * getXor(Constant *C1, Constant *C2)
Definition: Constants.cpp:2654
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:879
llvm::StringRef::data
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
llvm::CmpInst::FCMP_OEQ
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:722
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:2859
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:1138
llvm::SmallVectorImpl::append
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:670
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:1219
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:1193
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:1448
llvm::isIntN
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:428
llvm::SelectConstantExpr
SelectConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
Definition: ConstantsContext.h:96
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:1119
llvm::ConstantFP::getSNaN
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constants.cpp:989
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::isCompare
bool isCompare() const
Return true if this is a compare constant expression.
Definition: Constants.cpp:1440
llvm::ConstantExpr::getShuffleMaskForBitcode
Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
Definition: Constants.cpp:1452
llvm::ConstantFoldBinaryInstruction
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
Definition: ConstantFold.cpp:873
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:517
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:796
llvm::PossiblyExactOperator::IsExact
@ IsExact
Definition: Operator.h:129
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:2675
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:3183
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:196
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:1436
llvm::ConstantExpr::getShuffleVector
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2586
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:2059
BasicBlock.h
llvm::ConstantDataSequential::getRawDataValues
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
Definition: Constants.cpp:2809
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:594
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:2387
llvm::Constant::hasZeroLiveUses
bool hasZeroLiveUses() const
Return true if the constant has no live uses.
Definition: Constants.cpp:731
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::ConstantFP::getQNaN
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Definition: Constants.cpp:978
llvm::PPC::Predicate
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:26
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::OverflowingBinaryOperator::NoUnsignedWrap
@ NoUnsignedWrap
Definition: Operator.h:76
llvm::ConstantFoldCompareInstruction
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
Definition: ConstantFold.cpp:1582
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:1442
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:1923
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:747
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:3015
uint64_t
llvm::ConstantFP::getZero
static Constant * getZero(Type *Ty, bool Negative=false)
Definition: Constants.cpp:1000
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::LLVMContextImpl::TheFalseVal
ConstantInt * TheFalseVal
Definition: LLVMContextImpl.h:1462
llvm::ConstantExpr::getAddrSpaceCast
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2209
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:1694
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:67
llvm::DSOLocalEquivalent::getGlobalValue
GlobalValue * getGlobalValue() const
Definition: Constants.h:914
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:54
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:3208
llvm::GetElementPtrConstantExpr::getSourceElementType
Type * getSourceElementType() const
Definition: Constants.cpp:2792
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:2356
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:1356
llvm::GetElementPtrInst
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:929
llvm::ConstantExpr::getShl
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2663
llvm::ConstantExpr::getOr
static Constant * getOr(Constant *C1, Constant *C2)
Definition: Constants.cpp:2650
getIntSequenceIfElementsMatch
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
Definition: Constants.cpp:1167
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:2803
llvm::ConstantUniqueMap::getOrCreate
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
Definition: ConstantsContext.h:630
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:982
llvm::Constant::hasOneLiveUse
bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
Definition: Constants.cpp:729
llvm::CompareConstantExpr
Definition: ConstantsContext.h:247
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:3171
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:806
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:1941
llvm::LLVMContextImpl::TheTrueVal
ConstantInt * TheTrueVal
Definition: LLVMContextImpl.h:1461
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:1011
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:1072
llvm::CastConstantExpr
CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...
Definition: ConstantsContext.h:46
llvm::Instruction::isBinaryOp
bool isBinaryOp() const
Definition: Instruction.h:169
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:1655
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:967
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:3235
llvm::ConstantExpr::getTruncOrBitCast
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1992
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:2346
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::User::setOperand
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
getType
static M68kRelType getType(unsigned Kind, MCSymbolRefExpr::VariantKind &Modifier, bool &IsPCRel)
Definition: M68kELFObjectWriter.cpp:48
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:1571
llvm::LLVMContextImpl::IntConstants
IntMapTy IntConstants
Definition: LLVMContextImpl.h:1404
llvm::GetElementPtrInst::Create
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:955
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:702
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:50
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:1986
llvm::ConstantExpr::getUMin
static Constant * getUMin(Constant *C1, Constant *C2)
Definition: Constants.cpp:2658
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:3106
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:532
uint32_t
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
llvm::LLVMContextImpl::StructConstants
StructConstantsTy StructConstants
Definition: LLVMContextImpl.h:1437
llvm::ConstantExpr::getInsertElement
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2563
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:2962
llvm::ReplaceableMetadataImpl::SalvageDebugInfo
static void SalvageDebugInfo(const Constant &C)
Replace all uses of the constant with Undef in debug info metadata.
Definition: Metadata.cpp:249
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:1446
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:2035
CC
auto CC
Definition: RISCVRedundantCopyElimination.cpp:79
llvm::ConstantExprKeyType
Definition: ConstantsContext.h:432
llvm::ConstantVector::get
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1348
llvm::Type::isPtrOrPtrVectorTy
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:229
llvm::ifs::IFSSymbolType::Func
@ Func
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:685
llvm::ConstantInt::getFalse
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:834
llvm::ConstantExpr::getFCmp
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
Definition: Constants.cpp:2516
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:2941
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:1068
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:1877
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:1097
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:673
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:827
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:153
uint16_t
llvm::ConstantExpr::getNeg
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2612
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:3165
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:841
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:2625
llvm::Type::isIntOrIntVectorTy
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:202
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:926
llvm::ConstantTokenNone::get
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
Definition: Constants.cpp:1421
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:893
llvm::fltSemantics
Definition: APFloat.cpp:54
Function.h
getTypeID
static char getTypeID(Type *Ty)
Definition: ExternalFunctions.cpp:82
llvm::ConstantExpr::getAnd
static Constant * getAnd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2646
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:1103
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:156
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:564
llvm::ConstantArray::get
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1241
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:1218
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:1789
llvm::ConstantExpr::getLShr
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2670
llvm::ConstantUniqueMap::remove
void remove(ConstantClass *CP)
Remove this constant from the map.
Definition: ConstantsContext.h:648
llvm::ConstantExpr::getFPTrunc
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2101
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:2147
llvm::MCID::Add
@ Add
Definition: MCInstrDesc.h:185
llvm::ARMII::VecSize
@ VecSize
Definition: ARMBaseInfo.h:421
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:3914
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:771
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::OverflowingBinaryOperator::NoSignedWrap
@ NoSignedWrap
Definition: Operator.h:77
llvm::ConstantExpr::isDesirableBinOp
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
Definition: Constants.cpp:2292
Predicate
llvm::Instruction::BinaryOps
BinaryOps
Definition: Instruction.h:773
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition: Type.h:74
llvm::GetElementPtrConstantExpr::getResultElementType
Type * getResultElementType() const
Definition: Constants.cpp:2796
llvm::ShuffleVectorInst
This instruction constructs a fixed permutation of two input vectors.
Definition: Instructions.h:2008
isSigned
static bool isSigned(unsigned int Opcode)
Definition: ExpandLargeDivRem.cpp:52
llvm::APFloatBase::rmNearestTiesToEven
static constexpr roundingMode rmNearestTiesToEven
Definition: APFloat.h:190
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:217
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:2024
llvm::InsertElementConstantExpr
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Definition: ConstantsContext.h:150
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:1682
llvm::ConstantExpr::getFPExtend
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2113
llvm::Value::stripInBoundsConstantOffsets
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Definition: Value.cpp:697
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:3039
N
#define N
llvm::SmallVectorImpl::pop_back_val
T pop_back_val()
Definition: SmallVector.h:660
llvm::BinaryConstantExpr
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
Definition: ConstantsContext.h:69
llvm::BlockAddress::get
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1746
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:1512
llvm::ConstantExpr::getMul
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2639
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:1623
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:1440
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:1292
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:284
DerivedTypes.h
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:1764
StringMap.h
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:601
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::LLVMContextImpl::NoCFIValues
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
Definition: LLVMContextImpl.h:1455
llvm::ConstantAggregateZero::get
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1587
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:650
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:2839
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::DSOLocalEquivalent::get
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
Definition: Constants.cpp:1819
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
llvm::ExtractElementConstantExpr
ExtractElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to...
Definition: ConstantsContext.h:123
llvm::Type::isFirstClassType
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
Definition: Type.h:248
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1247
llvm::CmpInst::FCMP_UEQ
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:730
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:164
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
llvm::ConstantExpr::getUIToFP
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2125
llvm::PoisonValue
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
Definition: Constants.h:1404
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1727
llvm::ConstantDataSequential::getNumElements
unsigned getNumElements() const
Return the number of elements in the array or vector.
Definition: Constants.cpp:2829