LLVM  7.0.0svn
Instructions.cpp
Go to the documentation of this file.
1 //===- Instructions.cpp - Implement the LLVM instructions -----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements all of the non-inline methods for the LLVM instruction
11 // classes.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/IR/Instructions.h"
16 #include "LLVMContextImpl.h"
17 #include "llvm/ADT/None.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/IR/Attributes.h"
21 #include "llvm/IR/BasicBlock.h"
22 #include "llvm/IR/CallSite.h"
23 #include "llvm/IR/Constant.h"
24 #include "llvm/IR/Constants.h"
25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/DerivedTypes.h"
27 #include "llvm/IR/Function.h"
28 #include "llvm/IR/InstrTypes.h"
29 #include "llvm/IR/Instruction.h"
30 #include "llvm/IR/LLVMContext.h"
31 #include "llvm/IR/Metadata.h"
32 #include "llvm/IR/Module.h"
33 #include "llvm/IR/Operator.h"
34 #include "llvm/IR/Type.h"
35 #include "llvm/IR/Value.h"
37 #include "llvm/Support/Casting.h"
40 #include <algorithm>
41 #include <cassert>
42 #include <cstdint>
43 #include <vector>
44 
45 using namespace llvm;
46 
47 //===----------------------------------------------------------------------===//
48 // CallSite Class
49 //===----------------------------------------------------------------------===//
50 
51 User::op_iterator CallSite::getCallee() const {
53  return isCall()
54  ? cast<CallInst>(II)->op_end() - 1 // Skip Callee
55  : cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Callee
56 }
57 
58 //===----------------------------------------------------------------------===//
59 // TerminatorInst Class
60 //===----------------------------------------------------------------------===//
61 
63  switch (getOpcode()) {
64 #define HANDLE_TERM_INST(N, OPC, CLASS) \
65  case Instruction::OPC: \
66  return static_cast<const CLASS *>(this)->getNumSuccessors();
67 #include "llvm/IR/Instruction.def"
68  default:
69  break;
70  }
71  llvm_unreachable("not a terminator");
72 }
73 
75  switch (getOpcode()) {
76 #define HANDLE_TERM_INST(N, OPC, CLASS) \
77  case Instruction::OPC: \
78  return static_cast<const CLASS *>(this)->getSuccessor(idx);
79 #include "llvm/IR/Instruction.def"
80  default:
81  break;
82  }
83  llvm_unreachable("not a terminator");
84 }
85 
87  switch (getOpcode()) {
88 #define HANDLE_TERM_INST(N, OPC, CLASS) \
89  case Instruction::OPC: \
90  return static_cast<CLASS *>(this)->setSuccessor(idx, B);
91 #include "llvm/IR/Instruction.def"
92  default:
93  break;
94  }
95  llvm_unreachable("not a terminator");
96 }
97 
98 //===----------------------------------------------------------------------===//
99 // SelectInst Class
100 //===----------------------------------------------------------------------===//
101 
102 /// areInvalidOperands - Return a string if the specified operands are invalid
103 /// for a select operation, otherwise return null.
104 const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
105  if (Op1->getType() != Op2->getType())
106  return "both values to select must have same type";
107 
108  if (Op1->getType()->isTokenTy())
109  return "select values cannot have token type";
110 
111  if (VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
112  // Vector select.
113  if (VT->getElementType() != Type::getInt1Ty(Op0->getContext()))
114  return "vector select condition element type must be i1";
115  VectorType *ET = dyn_cast<VectorType>(Op1->getType());
116  if (!ET)
117  return "selected values for vector select must be vectors";
118  if (ET->getNumElements() != VT->getNumElements())
119  return "vector select requires selected vectors to have "
120  "the same vector length as select condition";
121  } else if (Op0->getType() != Type::getInt1Ty(Op0->getContext())) {
122  return "select condition must be i1 or <n x i1>";
123  }
124  return nullptr;
125 }
126 
127 //===----------------------------------------------------------------------===//
128 // PHINode Class
129 //===----------------------------------------------------------------------===//
130 
131 PHINode::PHINode(const PHINode &PN)
132  : Instruction(PN.getType(), Instruction::PHI, nullptr, PN.getNumOperands()),
133  ReservedSpace(PN.getNumOperands()) {
134  allocHungoffUses(PN.getNumOperands());
135  std::copy(PN.op_begin(), PN.op_end(), op_begin());
136  std::copy(PN.block_begin(), PN.block_end(), block_begin());
137  SubclassOptionalData = PN.SubclassOptionalData;
138 }
139 
140 // removeIncomingValue - Remove an incoming value. This is useful if a
141 // predecessor basic block is deleted.
142 Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
143  Value *Removed = getIncomingValue(Idx);
144 
145  // Move everything after this operand down.
146  //
147  // FIXME: we could just swap with the end of the list, then erase. However,
148  // clients might not expect this to happen. The code as it is thrashes the
149  // use/def lists, which is kinda lame.
150  std::copy(op_begin() + Idx + 1, op_end(), op_begin() + Idx);
151  std::copy(block_begin() + Idx + 1, block_end(), block_begin() + Idx);
152 
153  // Nuke the last value.
154  Op<-1>().set(nullptr);
155  setNumHungOffUseOperands(getNumOperands() - 1);
156 
157  // If the PHI node is dead, because it has zero entries, nuke it now.
158  if (getNumOperands() == 0 && DeletePHIIfEmpty) {
159  // If anyone is using this PHI, make them use a dummy value instead...
160  replaceAllUsesWith(UndefValue::get(getType()));
161  eraseFromParent();
162  }
163  return Removed;
164 }
165 
166 /// growOperands - grow operands - This grows the operand list in response
167 /// to a push_back style of operation. This grows the number of ops by 1.5
168 /// times.
169 ///
170 void PHINode::growOperands() {
171  unsigned e = getNumOperands();
172  unsigned NumOps = e + e / 2;
173  if (NumOps < 2) NumOps = 2; // 2 op PHI nodes are VERY common.
174 
175  ReservedSpace = NumOps;
176  growHungoffUses(ReservedSpace, /* IsPhi */ true);
177 }
178 
179 /// hasConstantValue - If the specified PHI node always merges together the same
180 /// value, return the value, otherwise return null.
182  // Exploit the fact that phi nodes always have at least one entry.
183  Value *ConstantValue = getIncomingValue(0);
184  for (unsigned i = 1, e = getNumIncomingValues(); i != e; ++i)
185  if (getIncomingValue(i) != ConstantValue && getIncomingValue(i) != this) {
186  if (ConstantValue != this)
187  return nullptr; // Incoming values not all the same.
188  // The case where the first value is this PHI.
189  ConstantValue = getIncomingValue(i);
190  }
191  if (ConstantValue == this)
192  return UndefValue::get(getType());
193  return ConstantValue;
194 }
195 
196 /// hasConstantOrUndefValue - Whether the specified PHI node always merges
197 /// together the same value, assuming that undefs result in the same value as
198 /// non-undefs.
199 /// Unlike \ref hasConstantValue, this does not return a value because the
200 /// unique non-undef incoming value need not dominate the PHI node.
202  Value *ConstantValue = nullptr;
203  for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) {
204  Value *Incoming = getIncomingValue(i);
205  if (Incoming != this && !isa<UndefValue>(Incoming)) {
206  if (ConstantValue && ConstantValue != Incoming)
207  return false;
208  ConstantValue = Incoming;
209  }
210  }
211  return true;
212 }
213 
214 //===----------------------------------------------------------------------===//
215 // LandingPadInst Implementation
216 //===----------------------------------------------------------------------===//
217 
218 LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
219  const Twine &NameStr, Instruction *InsertBefore)
220  : Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertBefore) {
221  init(NumReservedValues, NameStr);
222 }
223 
224 LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
225  const Twine &NameStr, BasicBlock *InsertAtEnd)
226  : Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertAtEnd) {
227  init(NumReservedValues, NameStr);
228 }
229 
230 LandingPadInst::LandingPadInst(const LandingPadInst &LP)
231  : Instruction(LP.getType(), Instruction::LandingPad, nullptr,
232  LP.getNumOperands()),
233  ReservedSpace(LP.getNumOperands()) {
234  allocHungoffUses(LP.getNumOperands());
235  Use *OL = getOperandList();
236  const Use *InOL = LP.getOperandList();
237  for (unsigned I = 0, E = ReservedSpace; I != E; ++I)
238  OL[I] = InOL[I];
239 
240  setCleanup(LP.isCleanup());
241 }
242 
243 LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
244  const Twine &NameStr,
245  Instruction *InsertBefore) {
246  return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertBefore);
247 }
248 
249 LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
250  const Twine &NameStr,
251  BasicBlock *InsertAtEnd) {
252  return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertAtEnd);
253 }
254 
255 void LandingPadInst::init(unsigned NumReservedValues, const Twine &NameStr) {
256  ReservedSpace = NumReservedValues;
257  setNumHungOffUseOperands(0);
258  allocHungoffUses(ReservedSpace);
259  setName(NameStr);
260  setCleanup(false);
261 }
262 
263 /// growOperands - grow operands - This grows the operand list in response to a
264 /// push_back style of operation. This grows the number of ops by 2 times.
265 void LandingPadInst::growOperands(unsigned Size) {
266  unsigned e = getNumOperands();
267  if (ReservedSpace >= e + Size) return;
268  ReservedSpace = (std::max(e, 1U) + Size / 2) * 2;
269  growHungoffUses(ReservedSpace);
270 }
271 
273  unsigned OpNo = getNumOperands();
274  growOperands(1);
275  assert(OpNo < ReservedSpace && "Growing didn't work!");
276  setNumHungOffUseOperands(getNumOperands() + 1);
277  getOperandList()[OpNo] = Val;
278 }
279 
280 //===----------------------------------------------------------------------===//
281 // CallInst Implementation
282 //===----------------------------------------------------------------------===//
283 
284 void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
285  ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
286  this->FTy = FTy;
287  assert(getNumOperands() == Args.size() + CountBundleInputs(Bundles) + 1 &&
288  "NumOperands not set up?");
289  Op<-1>() = Func;
290 
291 #ifndef NDEBUG
292  assert((Args.size() == FTy->getNumParams() ||
293  (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
294  "Calling a function with bad signature!");
295 
296  for (unsigned i = 0; i != Args.size(); ++i)
297  assert((i >= FTy->getNumParams() ||
298  FTy->getParamType(i) == Args[i]->getType()) &&
299  "Calling a function with a bad signature!");
300 #endif
301 
302  std::copy(Args.begin(), Args.end(), op_begin());
303 
304  auto It = populateBundleOperandInfos(Bundles, Args.size());
305  (void)It;
306  assert(It + 1 == op_end() && "Should add up!");
307 
308  setName(NameStr);
309 }
310 
311 void CallInst::init(Value *Func, const Twine &NameStr) {
312  FTy =
313  cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
314  assert(getNumOperands() == 1 && "NumOperands not set up?");
315  Op<-1>() = Func;
316 
317  assert(FTy->getNumParams() == 0 && "Calling a function with bad signature");
318 
319  setName(NameStr);
320 }
321 
322 CallInst::CallInst(Value *Func, const Twine &Name, Instruction *InsertBefore)
324  cast<FunctionType>(
325  cast<PointerType>(Func->getType())->getElementType())
326  ->getReturnType(),
328  OperandTraits<CallBase<CallInst>>::op_end(this) - 1, 1,
329  InsertBefore) {
330  init(Func, Name);
331 }
332 
333 CallInst::CallInst(Value *Func, const Twine &Name, BasicBlock *InsertAtEnd)
335  cast<FunctionType>(
336  cast<PointerType>(Func->getType())->getElementType())
337  ->getReturnType(),
339  OperandTraits<CallBase<CallInst>>::op_end(this) - 1, 1, InsertAtEnd) {
340  init(Func, Name);
341 }
342 
343 CallInst::CallInst(const CallInst &CI)
345  OperandTraits<CallBase<CallInst>>::op_end(this) -
346  CI.getNumOperands(),
347  CI.getNumOperands()) {
348  setTailCallKind(CI.getTailCallKind());
350 
351  std::copy(CI.op_begin(), CI.op_end(), op_begin());
353  bundle_op_info_begin());
354  SubclassOptionalData = CI.SubclassOptionalData;
355 }
356 
358  Instruction *InsertPt) {
359  std::vector<Value *> Args(CI->arg_begin(), CI->arg_end());
360 
361  auto *NewCI = CallInst::Create(CI->getCalledValue(), Args, OpB, CI->getName(),
362  InsertPt);
363  NewCI->setTailCallKind(CI->getTailCallKind());
364  NewCI->setCallingConv(CI->getCallingConv());
365  NewCI->SubclassOptionalData = CI->SubclassOptionalData;
366  NewCI->setAttributes(CI->getAttributes());
367  NewCI->setDebugLoc(CI->getDebugLoc());
368  return NewCI;
369 }
370 
371 
372 
373 
374 
375 
376 
377 
378 
379 
380 /// IsConstantOne - Return true only if val is constant int 1
381 static bool IsConstantOne(Value *val) {
382  assert(val && "IsConstantOne does not work with nullptr val");
383  const ConstantInt *CVal = dyn_cast<ConstantInt>(val);
384  return CVal && CVal->isOne();
385 }
386 
387 static Instruction *createMalloc(Instruction *InsertBefore,
388  BasicBlock *InsertAtEnd, Type *IntPtrTy,
389  Type *AllocTy, Value *AllocSize,
390  Value *ArraySize,
392  Function *MallocF, const Twine &Name) {
393  assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) &&
394  "createMalloc needs either InsertBefore or InsertAtEnd");
395 
396  // malloc(type) becomes:
397  // bitcast (i8* malloc(typeSize)) to type*
398  // malloc(type, arraySize) becomes:
399  // bitcast (i8* malloc(typeSize*arraySize)) to type*
400  if (!ArraySize)
401  ArraySize = ConstantInt::get(IntPtrTy, 1);
402  else if (ArraySize->getType() != IntPtrTy) {
403  if (InsertBefore)
404  ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy, false,
405  "", InsertBefore);
406  else
407  ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy, false,
408  "", InsertAtEnd);
409  }
410 
411  if (!IsConstantOne(ArraySize)) {
412  if (IsConstantOne(AllocSize)) {
413  AllocSize = ArraySize; // Operand * 1 = Operand
414  } else if (Constant *CO = dyn_cast<Constant>(ArraySize)) {
415  Constant *Scale = ConstantExpr::getIntegerCast(CO, IntPtrTy,
416  false /*ZExt*/);
417  // Malloc arg is constant product of type size and array size
418  AllocSize = ConstantExpr::getMul(Scale, cast<Constant>(AllocSize));
419  } else {
420  // Multiply type size by the array size...
421  if (InsertBefore)
422  AllocSize = BinaryOperator::CreateMul(ArraySize, AllocSize,
423  "mallocsize", InsertBefore);
424  else
425  AllocSize = BinaryOperator::CreateMul(ArraySize, AllocSize,
426  "mallocsize", InsertAtEnd);
427  }
428  }
429 
430  assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
431  // Create the call to Malloc.
432  BasicBlock *BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
433  Module *M = BB->getParent()->getParent();
434  Type *BPTy = Type::getInt8PtrTy(BB->getContext());
435  Value *MallocFunc = MallocF;
436  if (!MallocFunc)
437  // prototype malloc as "void *malloc(size_t)"
438  MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
439  PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
440  CallInst *MCall = nullptr;
441  Instruction *Result = nullptr;
442  if (InsertBefore) {
443  MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall",
444  InsertBefore);
445  Result = MCall;
446  if (Result->getType() != AllocPtrType)
447  // Create a cast instruction to convert to the right type...
448  Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
449  } else {
450  MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall");
451  Result = MCall;
452  if (Result->getType() != AllocPtrType) {
453  InsertAtEnd->getInstList().push_back(MCall);
454  // Create a cast instruction to convert to the right type...
455  Result = new BitCastInst(MCall, AllocPtrType, Name);
456  }
457  }
458  MCall->setTailCall();
459  if (Function *F = dyn_cast<Function>(MallocFunc)) {
460  MCall->setCallingConv(F->getCallingConv());
461  if (!F->returnDoesNotAlias())
462  F->setReturnDoesNotAlias();
463  }
464  assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
465 
466  return Result;
467 }
468 
469 /// CreateMalloc - Generate the IR for a call to malloc:
470 /// 1. Compute the malloc call's argument as the specified type's size,
471 /// possibly multiplied by the array size if the array size is not
472 /// constant 1.
473 /// 2. Call malloc with that argument.
474 /// 3. Bitcast the result of the malloc call to the specified type.
476  Type *IntPtrTy, Type *AllocTy,
477  Value *AllocSize, Value *ArraySize,
478  Function *MallocF,
479  const Twine &Name) {
480  return createMalloc(InsertBefore, nullptr, IntPtrTy, AllocTy, AllocSize,
481  ArraySize, None, MallocF, Name);
482 }
484  Type *IntPtrTy, Type *AllocTy,
485  Value *AllocSize, Value *ArraySize,
487  Function *MallocF,
488  const Twine &Name) {
489  return createMalloc(InsertBefore, nullptr, IntPtrTy, AllocTy, AllocSize,
490  ArraySize, OpB, MallocF, Name);
491 }
492 
493 /// CreateMalloc - Generate the IR for a call to malloc:
494 /// 1. Compute the malloc call's argument as the specified type's size,
495 /// possibly multiplied by the array size if the array size is not
496 /// constant 1.
497 /// 2. Call malloc with that argument.
498 /// 3. Bitcast the result of the malloc call to the specified type.
499 /// Note: This function does not add the bitcast to the basic block, that is the
500 /// responsibility of the caller.
502  Type *IntPtrTy, Type *AllocTy,
503  Value *AllocSize, Value *ArraySize,
504  Function *MallocF, const Twine &Name) {
505  return createMalloc(nullptr, InsertAtEnd, IntPtrTy, AllocTy, AllocSize,
506  ArraySize, None, MallocF, Name);
507 }
509  Type *IntPtrTy, Type *AllocTy,
510  Value *AllocSize, Value *ArraySize,
512  Function *MallocF, const Twine &Name) {
513  return createMalloc(nullptr, InsertAtEnd, IntPtrTy, AllocTy, AllocSize,
514  ArraySize, OpB, MallocF, Name);
515 }
516 
519  Instruction *InsertBefore,
520  BasicBlock *InsertAtEnd) {
521  assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) &&
522  "createFree needs either InsertBefore or InsertAtEnd");
523  assert(Source->getType()->isPointerTy() &&
524  "Can not free something of nonpointer type!");
525 
526  BasicBlock *BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
527  Module *M = BB->getParent()->getParent();
528 
529  Type *VoidTy = Type::getVoidTy(M->getContext());
530  Type *IntPtrTy = Type::getInt8PtrTy(M->getContext());
531  // prototype free as "void free(void*)"
532  Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy);
533  CallInst *Result = nullptr;
534  Value *PtrCast = Source;
535  if (InsertBefore) {
536  if (Source->getType() != IntPtrTy)
537  PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertBefore);
538  Result = CallInst::Create(FreeFunc, PtrCast, Bundles, "", InsertBefore);
539  } else {
540  if (Source->getType() != IntPtrTy)
541  PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertAtEnd);
542  Result = CallInst::Create(FreeFunc, PtrCast, Bundles, "");
543  }
544  Result->setTailCall();
545  if (Function *F = dyn_cast<Function>(FreeFunc))
546  Result->setCallingConv(F->getCallingConv());
547 
548  return Result;
549 }
550 
551 /// CreateFree - Generate the IR for a call to the builtin free function.
553  return createFree(Source, None, InsertBefore, nullptr);
554 }
557  Instruction *InsertBefore) {
558  return createFree(Source, Bundles, InsertBefore, nullptr);
559 }
560 
561 /// CreateFree - Generate the IR for a call to the builtin free function.
562 /// Note: This function does not add the call to the basic block, that is the
563 /// responsibility of the caller.
565  Instruction *FreeCall = createFree(Source, None, nullptr, InsertAtEnd);
566  assert(FreeCall && "CreateFree did not create a CallInst");
567  return FreeCall;
568 }
571  BasicBlock *InsertAtEnd) {
572  Instruction *FreeCall = createFree(Source, Bundles, nullptr, InsertAtEnd);
573  assert(FreeCall && "CreateFree did not create a CallInst");
574  return FreeCall;
575 }
576 
577 //===----------------------------------------------------------------------===//
578 // InvokeInst Implementation
579 //===----------------------------------------------------------------------===//
580 
581 void InvokeInst::init(FunctionType *FTy, Value *Fn, BasicBlock *IfNormal,
582  BasicBlock *IfException, ArrayRef<Value *> Args,
584  const Twine &NameStr) {
585  this->FTy = FTy;
586 
587  assert(getNumOperands() == 3 + Args.size() + CountBundleInputs(Bundles) &&
588  "NumOperands not set up?");
589  Op<-3>() = Fn;
590  Op<-2>() = IfNormal;
591  Op<-1>() = IfException;
592 
593 #ifndef NDEBUG
594  assert(((Args.size() == FTy->getNumParams()) ||
595  (FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
596  "Invoking a function with bad signature");
597 
598  for (unsigned i = 0, e = Args.size(); i != e; i++)
599  assert((i >= FTy->getNumParams() ||
600  FTy->getParamType(i) == Args[i]->getType()) &&
601  "Invoking a function with a bad signature!");
602 #endif
603 
604  std::copy(Args.begin(), Args.end(), op_begin());
605 
606  auto It = populateBundleOperandInfos(Bundles, Args.size());
607  (void)It;
608  assert(It + 3 == op_end() && "Should add up!");
609 
610  setName(NameStr);
611 }
612 
613 InvokeInst::InvokeInst(const InvokeInst &II)
614  : CallBase<InvokeInst>(II.Attrs, II.FTy, II.getType(), Instruction::Invoke,
615  OperandTraits<CallBase<InvokeInst>>::op_end(this) -
616  II.getNumOperands(),
617  II.getNumOperands()) {
619  std::copy(II.op_begin(), II.op_end(), op_begin());
621  bundle_op_info_begin());
622  SubclassOptionalData = II.SubclassOptionalData;
623 }
624 
626  Instruction *InsertPt) {
627  std::vector<Value *> Args(II->arg_begin(), II->arg_end());
628 
629  auto *NewII = InvokeInst::Create(II->getCalledValue(), II->getNormalDest(),
630  II->getUnwindDest(), Args, OpB,
631  II->getName(), InsertPt);
632  NewII->setCallingConv(II->getCallingConv());
633  NewII->SubclassOptionalData = II->SubclassOptionalData;
634  NewII->setAttributes(II->getAttributes());
635  NewII->setDebugLoc(II->getDebugLoc());
636  return NewII;
637 }
638 
639 
641  return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI());
642 }
643 
644 //===----------------------------------------------------------------------===//
645 // ReturnInst Implementation
646 //===----------------------------------------------------------------------===//
647 
648 ReturnInst::ReturnInst(const ReturnInst &RI)
651  RI.getNumOperands(),
652  RI.getNumOperands()) {
653  if (RI.getNumOperands())
654  Op<0>() = RI.Op<0>();
655  SubclassOptionalData = RI.SubclassOptionalData;
656 }
657 
658 ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore)
660  OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
661  InsertBefore) {
662  if (retVal)
663  Op<0>() = retVal;
664 }
665 
666 ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
668  OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
669  InsertAtEnd) {
670  if (retVal)
671  Op<0>() = retVal;
672 }
673 
674 ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
676  OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) {
677 }
678 
679 //===----------------------------------------------------------------------===//
680 // ResumeInst Implementation
681 //===----------------------------------------------------------------------===//
682 
683 ResumeInst::ResumeInst(const ResumeInst &RI)
684  : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Resume,
686  Op<0>() = RI.Op<0>();
687 }
688 
689 ResumeInst::ResumeInst(Value *Exn, Instruction *InsertBefore)
690  : TerminatorInst(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
691  OperandTraits<ResumeInst>::op_begin(this), 1, InsertBefore) {
692  Op<0>() = Exn;
693 }
694 
695 ResumeInst::ResumeInst(Value *Exn, BasicBlock *InsertAtEnd)
696  : TerminatorInst(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
697  OperandTraits<ResumeInst>::op_begin(this), 1, InsertAtEnd) {
698  Op<0>() = Exn;
699 }
700 
701 //===----------------------------------------------------------------------===//
702 // CleanupReturnInst Implementation
703 //===----------------------------------------------------------------------===//
704 
705 CleanupReturnInst::CleanupReturnInst(const CleanupReturnInst &CRI)
706  : TerminatorInst(CRI.getType(), Instruction::CleanupRet,
708  CRI.getNumOperands(),
709  CRI.getNumOperands()) {
710  setInstructionSubclassData(CRI.getSubclassDataFromInstruction());
711  Op<0>() = CRI.Op<0>();
712  if (CRI.hasUnwindDest())
713  Op<1>() = CRI.Op<1>();
714 }
715 
716 void CleanupReturnInst::init(Value *CleanupPad, BasicBlock *UnwindBB) {
717  if (UnwindBB)
718  setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
719 
720  Op<0>() = CleanupPad;
721  if (UnwindBB)
722  Op<1>() = UnwindBB;
723 }
724 
725 CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
726  unsigned Values, Instruction *InsertBefore)
727  : TerminatorInst(Type::getVoidTy(CleanupPad->getContext()),
728  Instruction::CleanupRet,
730  Values, InsertBefore) {
731  init(CleanupPad, UnwindBB);
732 }
733 
734 CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
735  unsigned Values, BasicBlock *InsertAtEnd)
736  : TerminatorInst(Type::getVoidTy(CleanupPad->getContext()),
737  Instruction::CleanupRet,
739  Values, InsertAtEnd) {
740  init(CleanupPad, UnwindBB);
741 }
742 
743 //===----------------------------------------------------------------------===//
744 // CatchReturnInst Implementation
745 //===----------------------------------------------------------------------===//
746 void CatchReturnInst::init(Value *CatchPad, BasicBlock *BB) {
747  Op<0>() = CatchPad;
748  Op<1>() = BB;
749 }
750 
751 CatchReturnInst::CatchReturnInst(const CatchReturnInst &CRI)
752  : TerminatorInst(Type::getVoidTy(CRI.getContext()), Instruction::CatchRet,
754  Op<0>() = CRI.Op<0>();
755  Op<1>() = CRI.Op<1>();
756 }
757 
758 CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
759  Instruction *InsertBefore)
760  : TerminatorInst(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
762  InsertBefore) {
763  init(CatchPad, BB);
764 }
765 
766 CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
767  BasicBlock *InsertAtEnd)
768  : TerminatorInst(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
770  InsertAtEnd) {
771  init(CatchPad, BB);
772 }
773 
774 //===----------------------------------------------------------------------===//
775 // CatchSwitchInst Implementation
776 //===----------------------------------------------------------------------===//
777 
778 CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
779  unsigned NumReservedValues,
780  const Twine &NameStr,
781  Instruction *InsertBefore)
782  : TerminatorInst(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
783  InsertBefore) {
784  if (UnwindDest)
785  ++NumReservedValues;
786  init(ParentPad, UnwindDest, NumReservedValues + 1);
787  setName(NameStr);
788 }
789 
790 CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
791  unsigned NumReservedValues,
792  const Twine &NameStr, BasicBlock *InsertAtEnd)
793  : TerminatorInst(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
794  InsertAtEnd) {
795  if (UnwindDest)
796  ++NumReservedValues;
797  init(ParentPad, UnwindDest, NumReservedValues + 1);
798  setName(NameStr);
799 }
800 
801 CatchSwitchInst::CatchSwitchInst(const CatchSwitchInst &CSI)
802  : TerminatorInst(CSI.getType(), Instruction::CatchSwitch, nullptr,
803  CSI.getNumOperands()) {
804  init(CSI.getParentPad(), CSI.getUnwindDest(), CSI.getNumOperands());
805  setNumHungOffUseOperands(ReservedSpace);
806  Use *OL = getOperandList();
807  const Use *InOL = CSI.getOperandList();
808  for (unsigned I = 1, E = ReservedSpace; I != E; ++I)
809  OL[I] = InOL[I];
810 }
811 
812 void CatchSwitchInst::init(Value *ParentPad, BasicBlock *UnwindDest,
813  unsigned NumReservedValues) {
814  assert(ParentPad && NumReservedValues);
815 
816  ReservedSpace = NumReservedValues;
817  setNumHungOffUseOperands(UnwindDest ? 2 : 1);
818  allocHungoffUses(ReservedSpace);
819 
820  Op<0>() = ParentPad;
821  if (UnwindDest) {
822  setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
823  setUnwindDest(UnwindDest);
824  }
825 }
826 
827 /// growOperands - grow operands - This grows the operand list in response to a
828 /// push_back style of operation. This grows the number of ops by 2 times.
829 void CatchSwitchInst::growOperands(unsigned Size) {
830  unsigned NumOperands = getNumOperands();
831  assert(NumOperands >= 1);
832  if (ReservedSpace >= NumOperands + Size)
833  return;
834  ReservedSpace = (NumOperands + Size / 2) * 2;
835  growHungoffUses(ReservedSpace);
836 }
837 
839  unsigned OpNo = getNumOperands();
840  growOperands(1);
841  assert(OpNo < ReservedSpace && "Growing didn't work!");
842  setNumHungOffUseOperands(getNumOperands() + 1);
843  getOperandList()[OpNo] = Handler;
844 }
845 
847  // Move all subsequent handlers up one.
848  Use *EndDst = op_end() - 1;
849  for (Use *CurDst = HI.getCurrent(); CurDst != EndDst; ++CurDst)
850  *CurDst = *(CurDst + 1);
851  // Null out the last handler use.
852  *EndDst = nullptr;
853 
854  setNumHungOffUseOperands(getNumOperands() - 1);
855 }
856 
857 //===----------------------------------------------------------------------===//
858 // FuncletPadInst Implementation
859 //===----------------------------------------------------------------------===//
860 void FuncletPadInst::init(Value *ParentPad, ArrayRef<Value *> Args,
861  const Twine &NameStr) {
862  assert(getNumOperands() == 1 + Args.size() && "NumOperands not set up?");
863  std::copy(Args.begin(), Args.end(), op_begin());
864  setParentPad(ParentPad);
865  setName(NameStr);
866 }
867 
868 FuncletPadInst::FuncletPadInst(const FuncletPadInst &FPI)
869  : Instruction(FPI.getType(), FPI.getOpcode(),
871  FPI.getNumOperands(),
872  FPI.getNumOperands()) {
873  std::copy(FPI.op_begin(), FPI.op_end(), op_begin());
874  setParentPad(FPI.getParentPad());
875 }
876 
877 FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
878  ArrayRef<Value *> Args, unsigned Values,
879  const Twine &NameStr, Instruction *InsertBefore)
880  : Instruction(ParentPad->getType(), Op,
881  OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
882  InsertBefore) {
883  init(ParentPad, Args, NameStr);
884 }
885 
886 FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
887  ArrayRef<Value *> Args, unsigned Values,
888  const Twine &NameStr, BasicBlock *InsertAtEnd)
889  : Instruction(ParentPad->getType(), Op,
890  OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
891  InsertAtEnd) {
892  init(ParentPad, Args, NameStr);
893 }
894 
895 //===----------------------------------------------------------------------===//
896 // UnreachableInst Implementation
897 //===----------------------------------------------------------------------===//
898 
900  Instruction *InsertBefore)
901  : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable,
902  nullptr, 0, InsertBefore) {
903 }
905  : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable,
906  nullptr, 0, InsertAtEnd) {
907 }
908 
909 //===----------------------------------------------------------------------===//
910 // BranchInst Implementation
911 //===----------------------------------------------------------------------===//
912 
913 void BranchInst::AssertOK() {
914  if (isConditional())
915  assert(getCondition()->getType()->isIntegerTy(1) &&
916  "May only branch on boolean predicates!");
917 }
918 
919 BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
920  : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
922  1, InsertBefore) {
923  assert(IfTrue && "Branch destination may not be null!");
924  Op<-1>() = IfTrue;
925 }
926 
927 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
928  Instruction *InsertBefore)
929  : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
931  3, InsertBefore) {
932  Op<-1>() = IfTrue;
933  Op<-2>() = IfFalse;
934  Op<-3>() = Cond;
935 #ifndef NDEBUG
936  AssertOK();
937 #endif
938 }
939 
940 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
941  : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
943  1, InsertAtEnd) {
944  assert(IfTrue && "Branch destination may not be null!");
945  Op<-1>() = IfTrue;
946 }
947 
948 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
949  BasicBlock *InsertAtEnd)
950  : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
952  3, InsertAtEnd) {
953  Op<-1>() = IfTrue;
954  Op<-2>() = IfFalse;
955  Op<-3>() = Cond;
956 #ifndef NDEBUG
957  AssertOK();
958 #endif
959 }
960 
961 BranchInst::BranchInst(const BranchInst &BI) :
962  TerminatorInst(Type::getVoidTy(BI.getContext()), Instruction::Br,
964  BI.getNumOperands()) {
965  Op<-1>() = BI.Op<-1>();
966  if (BI.getNumOperands() != 1) {
967  assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!");
968  Op<-3>() = BI.Op<-3>();
969  Op<-2>() = BI.Op<-2>();
970  }
972 }
973 
975  assert(isConditional() &&
976  "Cannot swap successors of an unconditional branch");
977  Op<-1>().swap(Op<-2>());
978 
979  // Update profile metadata if present and it matches our structural
980  // expectations.
982 }
983 
984 //===----------------------------------------------------------------------===//
985 // AllocaInst Implementation
986 //===----------------------------------------------------------------------===//
987 
988 static Value *getAISize(LLVMContext &Context, Value *Amt) {
989  if (!Amt)
990  Amt = ConstantInt::get(Type::getInt32Ty(Context), 1);
991  else {
992  assert(!isa<BasicBlock>(Amt) &&
993  "Passed basic block into allocation size parameter! Use other ctor");
994  assert(Amt->getType()->isIntegerTy() &&
995  "Allocation array size is not an integer!");
996  }
997  return Amt;
998 }
999 
1000 AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
1001  Instruction *InsertBefore)
1002  : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
1003 
1004 AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
1005  BasicBlock *InsertAtEnd)
1006  : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertAtEnd) {}
1007 
1008 AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1009  const Twine &Name, Instruction *InsertBefore)
1010  : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/0, Name, InsertBefore) {}
1011 
1012 AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1013  const Twine &Name, BasicBlock *InsertAtEnd)
1014  : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/0, Name, InsertAtEnd) {}
1015 
1016 AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1017  unsigned Align, const Twine &Name,
1018  Instruction *InsertBefore)
1019  : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
1020  getAISize(Ty->getContext(), ArraySize), InsertBefore),
1021  AllocatedType(Ty) {
1022  setAlignment(Align);
1023  assert(!Ty->isVoidTy() && "Cannot allocate void!");
1024  setName(Name);
1025 }
1026 
1027 AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1028  unsigned Align, const Twine &Name,
1029  BasicBlock *InsertAtEnd)
1030  : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
1031  getAISize(Ty->getContext(), ArraySize), InsertAtEnd),
1032  AllocatedType(Ty) {
1033  setAlignment(Align);
1034  assert(!Ty->isVoidTy() && "Cannot allocate void!");
1035  setName(Name);
1036 }
1037 
1039  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
1040  assert(Align <= MaximumAlignment &&
1041  "Alignment is greater than MaximumAlignment!");
1042  setInstructionSubclassData((getSubclassDataFromInstruction() & ~31) |
1043  (Log2_32(Align) + 1));
1044  assert(getAlignment() == Align && "Alignment representation error!");
1045 }
1046 
1048  if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
1049  return !CI->isOne();
1050  return true;
1051 }
1052 
1053 /// isStaticAlloca - Return true if this alloca is in the entry block of the
1054 /// function and is a constant size. If so, the code generator will fold it
1055 /// into the prolog/epilog code, so it is basically free.
1057  // Must be constant size.
1058  if (!isa<ConstantInt>(getArraySize())) return false;
1059 
1060  // Must be in the entry block.
1061  const BasicBlock *Parent = getParent();
1062  return Parent == &Parent->getParent()->front() && !isUsedWithInAlloca();
1063 }
1064 
1065 //===----------------------------------------------------------------------===//
1066 // LoadInst Implementation
1067 //===----------------------------------------------------------------------===//
1068 
1069 void LoadInst::AssertOK() {
1070  assert(getOperand(0)->getType()->isPointerTy() &&
1071  "Ptr must have pointer type.");
1072  assert(!(isAtomic() && getAlignment() == 0) &&
1073  "Alignment required for atomic load");
1074 }
1075 
1076 LoadInst::LoadInst(Value *Ptr, const Twine &Name, Instruction *InsertBef)
1077  : LoadInst(Ptr, Name, /*isVolatile=*/false, InsertBef) {}
1078 
1079 LoadInst::LoadInst(Value *Ptr, const Twine &Name, BasicBlock *InsertAE)
1080  : LoadInst(Ptr, Name, /*isVolatile=*/false, InsertAE) {}
1081 
1082 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1083  Instruction *InsertBef)
1084  : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertBef) {}
1085 
1086 LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile,
1087  BasicBlock *InsertAE)
1088  : LoadInst(Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {}
1089 
1090 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1091  unsigned Align, Instruction *InsertBef)
1092  : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
1093  SyncScope::System, InsertBef) {}
1094 
1095 LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile,
1096  unsigned Align, BasicBlock *InsertAE)
1097  : LoadInst(Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
1098  SyncScope::System, InsertAE) {}
1099 
1100 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1101  unsigned Align, AtomicOrdering Order,
1102  SyncScope::ID SSID, Instruction *InsertBef)
1103  : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
1104  assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());
1105  setVolatile(isVolatile);
1106  setAlignment(Align);
1107  setAtomic(Order, SSID);
1108  AssertOK();
1109  setName(Name);
1110 }
1111 
1112 LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile,
1113  unsigned Align, AtomicOrdering Order,
1114  SyncScope::ID SSID,
1115  BasicBlock *InsertAE)
1116  : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
1117  Load, Ptr, InsertAE) {
1118  setVolatile(isVolatile);
1119  setAlignment(Align);
1120  setAtomic(Order, SSID);
1121  AssertOK();
1122  setName(Name);
1123 }
1124 
1125 LoadInst::LoadInst(Value *Ptr, const char *Name, Instruction *InsertBef)
1126  : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
1127  Load, Ptr, InsertBef) {
1128  setVolatile(false);
1129  setAlignment(0);
1131  AssertOK();
1132  if (Name && Name[0]) setName(Name);
1133 }
1134 
1135 LoadInst::LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAE)
1136  : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
1137  Load, Ptr, InsertAE) {
1138  setVolatile(false);
1139  setAlignment(0);
1141  AssertOK();
1142  if (Name && Name[0]) setName(Name);
1143 }
1144 
1145 LoadInst::LoadInst(Type *Ty, Value *Ptr, const char *Name, bool isVolatile,
1146  Instruction *InsertBef)
1147  : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
1148  assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());
1149  setVolatile(isVolatile);
1150  setAlignment(0);
1152  AssertOK();
1153  if (Name && Name[0]) setName(Name);
1154 }
1155 
1156 LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile,
1157  BasicBlock *InsertAE)
1158  : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
1159  Load, Ptr, InsertAE) {
1160  setVolatile(isVolatile);
1161  setAlignment(0);
1163  AssertOK();
1164  if (Name && Name[0]) setName(Name);
1165 }
1166 
1168  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
1169  assert(Align <= MaximumAlignment &&
1170  "Alignment is greater than MaximumAlignment!");
1171  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
1172  ((Log2_32(Align)+1)<<1));
1173  assert(getAlignment() == Align && "Alignment representation error!");
1174 }
1175 
1176 //===----------------------------------------------------------------------===//
1177 // StoreInst Implementation
1178 //===----------------------------------------------------------------------===//
1179 
1180 void StoreInst::AssertOK() {
1181  assert(getOperand(0) && getOperand(1) && "Both operands must be non-null!");
1182  assert(getOperand(1)->getType()->isPointerTy() &&
1183  "Ptr must have pointer type!");
1184  assert(getOperand(0)->getType() ==
1185  cast<PointerType>(getOperand(1)->getType())->getElementType()
1186  && "Ptr must be a pointer to Val type!");
1187  assert(!(isAtomic() && getAlignment() == 0) &&
1188  "Alignment required for atomic store");
1189 }
1190 
1191 StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
1192  : StoreInst(val, addr, /*isVolatile=*/false, InsertBefore) {}
1193 
1194 StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
1195  : StoreInst(val, addr, /*isVolatile=*/false, InsertAtEnd) {}
1196 
1198  Instruction *InsertBefore)
1199  : StoreInst(val, addr, isVolatile, /*Align=*/0, InsertBefore) {}
1200 
1202  BasicBlock *InsertAtEnd)
1203  : StoreInst(val, addr, isVolatile, /*Align=*/0, InsertAtEnd) {}
1204 
1205 StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align,
1206  Instruction *InsertBefore)
1207  : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
1208  SyncScope::System, InsertBefore) {}
1209 
1210 StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align,
1211  BasicBlock *InsertAtEnd)
1212  : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
1213  SyncScope::System, InsertAtEnd) {}
1214 
1216  unsigned Align, AtomicOrdering Order,
1217  SyncScope::ID SSID,
1218  Instruction *InsertBefore)
1219  : Instruction(Type::getVoidTy(val->getContext()), Store,
1222  InsertBefore) {
1223  Op<0>() = val;
1224  Op<1>() = addr;
1225  setVolatile(isVolatile);
1226  setAlignment(Align);
1227  setAtomic(Order, SSID);
1228  AssertOK();
1229 }
1230 
1232  unsigned Align, AtomicOrdering Order,
1233  SyncScope::ID SSID,
1234  BasicBlock *InsertAtEnd)
1235  : Instruction(Type::getVoidTy(val->getContext()), Store,
1238  InsertAtEnd) {
1239  Op<0>() = val;
1240  Op<1>() = addr;
1241  setVolatile(isVolatile);
1242  setAlignment(Align);
1243  setAtomic(Order, SSID);
1244  AssertOK();
1245 }
1246 
1248  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
1249  assert(Align <= MaximumAlignment &&
1250  "Alignment is greater than MaximumAlignment!");
1251  setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
1252  ((Log2_32(Align)+1) << 1));
1253  assert(getAlignment() == Align && "Alignment representation error!");
1254 }
1255 
1256 //===----------------------------------------------------------------------===//
1257 // AtomicCmpXchgInst Implementation
1258 //===----------------------------------------------------------------------===//
1259 
1260 void AtomicCmpXchgInst::Init(Value *Ptr, Value *Cmp, Value *NewVal,
1261  AtomicOrdering SuccessOrdering,
1262  AtomicOrdering FailureOrdering,
1263  SyncScope::ID SSID) {
1264  Op<0>() = Ptr;
1265  Op<1>() = Cmp;
1266  Op<2>() = NewVal;
1267  setSuccessOrdering(SuccessOrdering);
1268  setFailureOrdering(FailureOrdering);
1269  setSyncScopeID(SSID);
1270 
1271  assert(getOperand(0) && getOperand(1) && getOperand(2) &&
1272  "All operands must be non-null!");
1273  assert(getOperand(0)->getType()->isPointerTy() &&
1274  "Ptr must have pointer type!");
1275  assert(getOperand(1)->getType() ==
1276  cast<PointerType>(getOperand(0)->getType())->getElementType()
1277  && "Ptr must be a pointer to Cmp type!");
1278  assert(getOperand(2)->getType() ==
1279  cast<PointerType>(getOperand(0)->getType())->getElementType()
1280  && "Ptr must be a pointer to NewVal type!");
1281  assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
1282  "AtomicCmpXchg instructions must be atomic!");
1283  assert(FailureOrdering != AtomicOrdering::NotAtomic &&
1284  "AtomicCmpXchg instructions must be atomic!");
1285  assert(!isStrongerThan(FailureOrdering, SuccessOrdering) &&
1286  "AtomicCmpXchg failure argument shall be no stronger than the success "
1287  "argument");
1288  assert(FailureOrdering != AtomicOrdering::Release &&
1289  FailureOrdering != AtomicOrdering::AcquireRelease &&
1290  "AtomicCmpXchg failure ordering cannot include release semantics");
1291 }
1292 
1294  AtomicOrdering SuccessOrdering,
1295  AtomicOrdering FailureOrdering,
1296  SyncScope::ID SSID,
1297  Instruction *InsertBefore)
1298  : Instruction(
1299  StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
1300  AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
1301  OperandTraits<AtomicCmpXchgInst>::operands(this), InsertBefore) {
1302  Init(Ptr, Cmp, NewVal, SuccessOrdering, FailureOrdering, SSID);
1303 }
1304 
1306  AtomicOrdering SuccessOrdering,
1307  AtomicOrdering FailureOrdering,
1308  SyncScope::ID SSID,
1309  BasicBlock *InsertAtEnd)
1310  : Instruction(
1311  StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
1312  AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
1313  OperandTraits<AtomicCmpXchgInst>::operands(this), InsertAtEnd) {
1314  Init(Ptr, Cmp, NewVal, SuccessOrdering, FailureOrdering, SSID);
1315 }
1316 
1317 //===----------------------------------------------------------------------===//
1318 // AtomicRMWInst Implementation
1319 //===----------------------------------------------------------------------===//
1320 
1321 void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
1322  AtomicOrdering Ordering,
1323  SyncScope::ID SSID) {
1324  Op<0>() = Ptr;
1325  Op<1>() = Val;
1326  setOperation(Operation);
1327  setOrdering(Ordering);
1328  setSyncScopeID(SSID);
1329 
1330  assert(getOperand(0) && getOperand(1) &&
1331  "All operands must be non-null!");
1332  assert(getOperand(0)->getType()->isPointerTy() &&
1333  "Ptr must have pointer type!");
1334  assert(getOperand(1)->getType() ==
1335  cast<PointerType>(getOperand(0)->getType())->getElementType()
1336  && "Ptr must be a pointer to Val type!");
1337  assert(Ordering != AtomicOrdering::NotAtomic &&
1338  "AtomicRMW instructions must be atomic!");
1339 }
1340 
1342  AtomicOrdering Ordering,
1343  SyncScope::ID SSID,
1344  Instruction *InsertBefore)
1345  : Instruction(Val->getType(), AtomicRMW,
1348  InsertBefore) {
1349  Init(Operation, Ptr, Val, Ordering, SSID);
1350 }
1351 
1353  AtomicOrdering Ordering,
1354  SyncScope::ID SSID,
1355  BasicBlock *InsertAtEnd)
1356  : Instruction(Val->getType(), AtomicRMW,
1359  InsertAtEnd) {
1360  Init(Operation, Ptr, Val, Ordering, SSID);
1361 }
1362 
1363 //===----------------------------------------------------------------------===//
1364 // FenceInst Implementation
1365 //===----------------------------------------------------------------------===//
1366 
1368  SyncScope::ID SSID,
1369  Instruction *InsertBefore)
1370  : Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertBefore) {
1371  setOrdering(Ordering);
1372  setSyncScopeID(SSID);
1373 }
1374 
1376  SyncScope::ID SSID,
1377  BasicBlock *InsertAtEnd)
1378  : Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertAtEnd) {
1379  setOrdering(Ordering);
1380  setSyncScopeID(SSID);
1381 }
1382 
1383 //===----------------------------------------------------------------------===//
1384 // GetElementPtrInst Implementation
1385 //===----------------------------------------------------------------------===//
1386 
1387 void GetElementPtrInst::init(Value *Ptr, ArrayRef<Value *> IdxList,
1388  const Twine &Name) {
1389  assert(getNumOperands() == 1 + IdxList.size() &&
1390  "NumOperands not initialized?");
1391  Op<0>() = Ptr;
1392  std::copy(IdxList.begin(), IdxList.end(), op_begin() + 1);
1393  setName(Name);
1394 }
1395 
1396 GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
1397  : Instruction(GEPI.getType(), GetElementPtr,
1399  GEPI.getNumOperands(),
1400  GEPI.getNumOperands()),
1401  SourceElementType(GEPI.SourceElementType),
1402  ResultElementType(GEPI.ResultElementType) {
1403  std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
1405 }
1406 
1407 /// getIndexedType - Returns the type of the element that would be accessed with
1408 /// a gep instruction with the specified parameters.
1409 ///
1410 /// The Idxs pointer should point to a continuous piece of memory containing the
1411 /// indices, either as Value* or uint64_t.
1412 ///
1413 /// A null type is returned if the indices are invalid for the specified
1414 /// pointer type.
1415 ///
1416 template <typename IndexTy>
1418  // Handle the special case of the empty set index set, which is always valid.
1419  if (IdxList.empty())
1420  return Agg;
1421 
1422  // If there is at least one index, the top level type must be sized, otherwise
1423  // it cannot be 'stepped over'.
1424  if (!Agg->isSized())
1425  return nullptr;
1426 
1427  unsigned CurIdx = 1;
1428  for (; CurIdx != IdxList.size(); ++CurIdx) {
1429  CompositeType *CT = dyn_cast<CompositeType>(Agg);
1430  if (!CT || CT->isPointerTy()) return nullptr;
1431  IndexTy Index = IdxList[CurIdx];
1432  if (!CT->indexValid(Index)) return nullptr;
1433  Agg = CT->getTypeAtIndex(Index);
1434  }
1435  return CurIdx == IdxList.size() ? Agg : nullptr;
1436 }
1437 
1439  return getIndexedTypeInternal(Ty, IdxList);
1440 }
1441 
1443  ArrayRef<Constant *> IdxList) {
1444  return getIndexedTypeInternal(Ty, IdxList);
1445 }
1446 
1448  return getIndexedTypeInternal(Ty, IdxList);
1449 }
1450 
1451 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
1452 /// zeros. If so, the result pointer and the first operand have the same
1453 /// value, just potentially different types.
1455  for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
1456  if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(i))) {
1457  if (!CI->isZero()) return false;
1458  } else {
1459  return false;
1460  }
1461  }
1462  return true;
1463 }
1464 
1465 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
1466 /// constant integers. If so, the result pointer and the first operand have
1467 /// a constant offset between them.
1469  for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
1470  if (!isa<ConstantInt>(getOperand(i)))
1471  return false;
1472  }
1473  return true;
1474 }
1475 
1477  cast<GEPOperator>(this)->setIsInBounds(B);
1478 }
1479 
1481  return cast<GEPOperator>(this)->isInBounds();
1482 }
1483 
1485  APInt &Offset) const {
1486  // Delegate to the generic GEPOperator implementation.
1487  return cast<GEPOperator>(this)->accumulateConstantOffset(DL, Offset);
1488 }
1489 
1490 //===----------------------------------------------------------------------===//
1491 // ExtractElementInst Implementation
1492 //===----------------------------------------------------------------------===//
1493 
1494 ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
1495  const Twine &Name,
1496  Instruction *InsertBef)
1497  : Instruction(cast<VectorType>(Val->getType())->getElementType(),
1498  ExtractElement,
1500  2, InsertBef) {
1501  assert(isValidOperands(Val, Index) &&
1502  "Invalid extractelement instruction operands!");
1503  Op<0>() = Val;
1504  Op<1>() = Index;
1505  setName(Name);
1506 }
1507 
1508 ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
1509  const Twine &Name,
1510  BasicBlock *InsertAE)
1511  : Instruction(cast<VectorType>(Val->getType())->getElementType(),
1512  ExtractElement,
1514  2, InsertAE) {
1515  assert(isValidOperands(Val, Index) &&
1516  "Invalid extractelement instruction operands!");
1517 
1518  Op<0>() = Val;
1519  Op<1>() = Index;
1520  setName(Name);
1521 }
1522 
1523 bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
1524  if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy())
1525  return false;
1526  return true;
1527 }
1528 
1529 //===----------------------------------------------------------------------===//
1530 // InsertElementInst Implementation
1531 //===----------------------------------------------------------------------===//
1532 
1533 InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
1534  const Twine &Name,
1535  Instruction *InsertBef)
1536  : Instruction(Vec->getType(), InsertElement,
1538  3, InsertBef) {
1539  assert(isValidOperands(Vec, Elt, Index) &&
1540  "Invalid insertelement instruction operands!");
1541  Op<0>() = Vec;
1542  Op<1>() = Elt;
1543  Op<2>() = Index;
1544  setName(Name);
1545 }
1546 
1547 InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
1548  const Twine &Name,
1549  BasicBlock *InsertAE)
1550  : Instruction(Vec->getType(), InsertElement,
1552  3, InsertAE) {
1553  assert(isValidOperands(Vec, Elt, Index) &&
1554  "Invalid insertelement instruction operands!");
1555 
1556  Op<0>() = Vec;
1557  Op<1>() = Elt;
1558  Op<2>() = Index;
1559  setName(Name);
1560 }
1561 
1562 bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
1563  const Value *Index) {
1564  if (!Vec->getType()->isVectorTy())
1565  return false; // First operand of insertelement must be vector type.
1566 
1567  if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
1568  return false;// Second operand of insertelement must be vector element type.
1569 
1570  if (!Index->getType()->isIntegerTy())
1571  return false; // Third operand of insertelement must be i32.
1572  return true;
1573 }
1574 
1575 //===----------------------------------------------------------------------===//
1576 // ShuffleVectorInst Implementation
1577 //===----------------------------------------------------------------------===//
1578 
1580  const Twine &Name,
1581  Instruction *InsertBefore)
1582 : Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1583  cast<VectorType>(Mask->getType())->getNumElements()),
1584  ShuffleVector,
1587  InsertBefore) {
1588  assert(isValidOperands(V1, V2, Mask) &&
1589  "Invalid shuffle vector instruction operands!");
1590  Op<0>() = V1;
1591  Op<1>() = V2;
1592  Op<2>() = Mask;
1593  setName(Name);
1594 }
1595 
1597  const Twine &Name,
1598  BasicBlock *InsertAtEnd)
1599 : Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1600  cast<VectorType>(Mask->getType())->getNumElements()),
1601  ShuffleVector,
1604  InsertAtEnd) {
1605  assert(isValidOperands(V1, V2, Mask) &&
1606  "Invalid shuffle vector instruction operands!");
1607 
1608  Op<0>() = V1;
1609  Op<1>() = V2;
1610  Op<2>() = Mask;
1611  setName(Name);
1612 }
1613 
1615  const Value *Mask) {
1616  // V1 and V2 must be vectors of the same type.
1617  if (!V1->getType()->isVectorTy() || V1->getType() != V2->getType())
1618  return false;
1619 
1620  // Mask must be vector of i32.
1621  auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
1622  if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32))
1623  return false;
1624 
1625  // Check to see if Mask is valid.
1626  if (isa<UndefValue>(Mask) || isa<ConstantAggregateZero>(Mask))
1627  return true;
1628 
1629  if (const auto *MV = dyn_cast<ConstantVector>(Mask)) {
1630  unsigned V1Size = cast<VectorType>(V1->getType())->getNumElements();
1631  for (Value *Op : MV->operands()) {
1632  if (auto *CI = dyn_cast<ConstantInt>(Op)) {
1633  if (CI->uge(V1Size*2))
1634  return false;
1635  } else if (!isa<UndefValue>(Op)) {
1636  return false;
1637  }
1638  }
1639  return true;
1640  }
1641 
1642  if (const auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1643  unsigned V1Size = cast<VectorType>(V1->getType())->getNumElements();
1644  for (unsigned i = 0, e = MaskTy->getNumElements(); i != e; ++i)
1645  if (CDS->getElementAsInteger(i) >= V1Size*2)
1646  return false;
1647  return true;
1648  }
1649 
1650  // The bitcode reader can create a place holder for a forward reference
1651  // used as the shuffle mask. When this occurs, the shuffle mask will
1652  // fall into this case and fail. To avoid this error, do this bit of
1653  // ugliness to allow such a mask pass.
1654  if (const auto *CE = dyn_cast<ConstantExpr>(Mask))
1655  if (CE->getOpcode() == Instruction::UserOp1)
1656  return true;
1657 
1658  return false;
1659 }
1660 
1662  assert(i < Mask->getType()->getVectorNumElements() && "Index out of range");
1663  if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask))
1664  return CDS->getElementAsInteger(i);
1665  Constant *C = Mask->getAggregateElement(i);
1666  if (isa<UndefValue>(C))
1667  return -1;
1668  return cast<ConstantInt>(C)->getZExtValue();
1669 }
1670 
1672  SmallVectorImpl<int> &Result) {
1673  unsigned NumElts = Mask->getType()->getVectorNumElements();
1674 
1675  if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1676  for (unsigned i = 0; i != NumElts; ++i)
1677  Result.push_back(CDS->getElementAsInteger(i));
1678  return;
1679  }
1680  for (unsigned i = 0; i != NumElts; ++i) {
1681  Constant *C = Mask->getAggregateElement(i);
1682  Result.push_back(isa<UndefValue>(C) ? -1 :
1683  cast<ConstantInt>(C)->getZExtValue());
1684  }
1685 }
1686 
1688  assert(!Mask.empty() && "Shuffle mask must contain elements");
1689  bool UsesLHS = false;
1690  bool UsesRHS = false;
1691  for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
1692  if (Mask[i] == -1)
1693  continue;
1694  assert(Mask[i] >= 0 && Mask[i] < (NumElts * 2) &&
1695  "Out-of-bounds shuffle mask element");
1696  UsesLHS |= (Mask[i] < NumElts);
1697  UsesRHS |= (Mask[i] >= NumElts);
1698  if (UsesLHS && UsesRHS)
1699  return false;
1700  }
1701  assert((UsesLHS ^ UsesRHS) && "Should have selected from exactly 1 source");
1702  return true;
1703 }
1704 
1706  if (!isSingleSourceMask(Mask))
1707  return false;
1708  for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
1709  if (Mask[i] == -1)
1710  continue;
1711  if (Mask[i] != i && Mask[i] != (NumElts + i))
1712  return false;
1713  }
1714  return true;
1715 }
1716 
1718  if (!isSingleSourceMask(Mask))
1719  return false;
1720  for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
1721  if (Mask[i] == -1)
1722  continue;
1723  if (Mask[i] != (NumElts - 1 - i) && Mask[i] != (NumElts + NumElts - 1 - i))
1724  return false;
1725  }
1726  return true;
1727 }
1728 
1730  if (!isSingleSourceMask(Mask))
1731  return false;
1732  for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
1733  if (Mask[i] == -1)
1734  continue;
1735  if (Mask[i] != 0 && Mask[i] != NumElts)
1736  return false;
1737  }
1738  return true;
1739 }
1740 
1742  // Select is differentiated from identity. It requires using both sources.
1743  if (isSingleSourceMask(Mask))
1744  return false;
1745  for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
1746  if (Mask[i] == -1)
1747  continue;
1748  if (Mask[i] != i && Mask[i] != (NumElts + i))
1749  return false;
1750  }
1751  return true;
1752 }
1753 
1755  // Example masks that will return true:
1756  // v1 = <a, b, c, d>
1757  // v2 = <e, f, g, h>
1758  // trn1 = shufflevector v1, v2 <0, 4, 2, 6> = <a, e, c, g>
1759  // trn2 = shufflevector v1, v2 <1, 5, 3, 7> = <b, f, d, h>
1760 
1761  // 1. The number of elements in the mask must be a power-of-2 and at least 2.
1762  int NumElts = Mask.size();
1763  if (NumElts < 2 || !isPowerOf2_32(NumElts))
1764  return false;
1765 
1766  // 2. The first element of the mask must be either a 0 or a 1.
1767  if (Mask[0] != 0 && Mask[0] != 1)
1768  return false;
1769 
1770  // 3. The difference between the first 2 elements must be equal to the
1771  // number of elements in the mask.
1772  if ((Mask[1] - Mask[0]) != NumElts)
1773  return false;
1774 
1775  // 4. The difference between consecutive even-numbered and odd-numbered
1776  // elements must be equal to 2.
1777  for (int i = 2; i < NumElts; ++i) {
1778  int MaskEltVal = Mask[i];
1779  if (MaskEltVal == -1)
1780  return false;
1781  int MaskEltPrevVal = Mask[i - 2];
1782  if (MaskEltVal - MaskEltPrevVal != 2)
1783  return false;
1784  }
1785  return true;
1786 }
1787 
1788 
1789 //===----------------------------------------------------------------------===//
1790 // InsertValueInst Class
1791 //===----------------------------------------------------------------------===//
1792 
1793 void InsertValueInst::init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1794  const Twine &Name) {
1795  assert(getNumOperands() == 2 && "NumOperands not initialized?");
1796 
1797  // There's no fundamental reason why we require at least one index
1798  // (other than weirdness with &*IdxBegin being invalid; see
1799  // getelementptr's init routine for example). But there's no
1800  // present need to support it.
1801  assert(!Idxs.empty() && "InsertValueInst must have at least one index");
1802 
1804  Val->getType() && "Inserted value must match indexed type!");
1805  Op<0>() = Agg;
1806  Op<1>() = Val;
1807 
1808  Indices.append(Idxs.begin(), Idxs.end());
1809  setName(Name);
1810 }
1811 
1812 InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
1813  : Instruction(IVI.getType(), InsertValue,
1815  Indices(IVI.Indices) {
1816  Op<0>() = IVI.getOperand(0);
1817  Op<1>() = IVI.getOperand(1);
1819 }
1820 
1821 //===----------------------------------------------------------------------===//
1822 // ExtractValueInst Class
1823 //===----------------------------------------------------------------------===//
1824 
1825 void ExtractValueInst::init(ArrayRef<unsigned> Idxs, const Twine &Name) {
1826  assert(getNumOperands() == 1 && "NumOperands not initialized?");
1827 
1828  // There's no fundamental reason why we require at least one index.
1829  // But there's no present need to support it.
1830  assert(!Idxs.empty() && "ExtractValueInst must have at least one index");
1831 
1832  Indices.append(Idxs.begin(), Idxs.end());
1833  setName(Name);
1834 }
1835 
1836 ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
1837  : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
1838  Indices(EVI.Indices) {
1840 }
1841 
1842 // getIndexedType - Returns the type of the element that would be extracted
1843 // with an extractvalue instruction with the specified parameters.
1844 //
1845 // A null type is returned if the indices are invalid for the specified
1846 // pointer type.
1847 //
1849  ArrayRef<unsigned> Idxs) {
1850  for (unsigned Index : Idxs) {
1851  // We can't use CompositeType::indexValid(Index) here.
1852  // indexValid() always returns true for arrays because getelementptr allows
1853  // out-of-bounds indices. Since we don't allow those for extractvalue and
1854  // insertvalue we need to check array indexing manually.
1855  // Since the only other types we can index into are struct types it's just
1856  // as easy to check those manually as well.
1857  if (ArrayType *AT = dyn_cast<ArrayType>(Agg)) {
1858  if (Index >= AT->getNumElements())
1859  return nullptr;
1860  } else if (StructType *ST = dyn_cast<StructType>(Agg)) {
1861  if (Index >= ST->getNumElements())
1862  return nullptr;
1863  } else {
1864  // Not a valid type to index into.
1865  return nullptr;
1866  }
1867 
1868  Agg = cast<CompositeType>(Agg)->getTypeAtIndex(Index);
1869  }
1870  return const_cast<Type*>(Agg);
1871 }
1872 
1873 //===----------------------------------------------------------------------===//
1874 // BinaryOperator Class
1875 //===----------------------------------------------------------------------===//
1876 
1878  Type *Ty, const Twine &Name,
1879  Instruction *InsertBefore)
1880  : Instruction(Ty, iType,
1883  InsertBefore) {
1884  Op<0>() = S1;
1885  Op<1>() = S2;
1886  setName(Name);
1887  AssertOK();
1888 }
1889 
1891  Type *Ty, const Twine &Name,
1892  BasicBlock *InsertAtEnd)
1893  : Instruction(Ty, iType,
1896  InsertAtEnd) {
1897  Op<0>() = S1;
1898  Op<1>() = S2;
1899  setName(Name);
1900  AssertOK();
1901 }
1902 
1903 void BinaryOperator::AssertOK() {
1904  Value *LHS = getOperand(0), *RHS = getOperand(1);
1905  (void)LHS; (void)RHS; // Silence warnings.
1906  assert(LHS->getType() == RHS->getType() &&
1907  "Binary operator operand types must match!");
1908 #ifndef NDEBUG
1909  switch (getOpcode()) {
1910  case Add: case Sub:
1911  case Mul:
1912  assert(getType() == LHS->getType() &&
1913  "Arithmetic operation should return same type as operands!");
1914  assert(getType()->isIntOrIntVectorTy() &&
1915  "Tried to create an integer operation on a non-integer type!");
1916  break;
1917  case FAdd: case FSub:
1918  case FMul:
1919  assert(getType() == LHS->getType() &&
1920  "Arithmetic operation should return same type as operands!");
1921  assert(getType()->isFPOrFPVectorTy() &&
1922  "Tried to create a floating-point operation on a "
1923  "non-floating-point type!");
1924  break;
1925  case UDiv:
1926  case SDiv:
1927  assert(getType() == LHS->getType() &&
1928  "Arithmetic operation should return same type as operands!");
1929  assert(getType()->isIntOrIntVectorTy() &&
1930  "Incorrect operand type (not integer) for S/UDIV");
1931  break;
1932  case FDiv:
1933  assert(getType() == LHS->getType() &&
1934  "Arithmetic operation should return same type as operands!");
1935  assert(getType()->isFPOrFPVectorTy() &&
1936  "Incorrect operand type (not floating point) for FDIV");
1937  break;
1938  case URem:
1939  case SRem:
1940  assert(getType() == LHS->getType() &&
1941  "Arithmetic operation should return same type as operands!");
1942  assert(getType()->isIntOrIntVectorTy() &&
1943  "Incorrect operand type (not integer) for S/UREM");
1944  break;
1945  case FRem:
1946  assert(getType() == LHS->getType() &&
1947  "Arithmetic operation should return same type as operands!");
1948  assert(getType()->isFPOrFPVectorTy() &&
1949  "Incorrect operand type (not floating point) for FREM");
1950  break;
1951  case Shl:
1952  case LShr:
1953  case AShr:
1954  assert(getType() == LHS->getType() &&
1955  "Shift operation should return same type as operands!");
1956  assert(getType()->isIntOrIntVectorTy() &&
1957  "Tried to create a shift operation on a non-integral type!");
1958  break;
1959  case And: case Or:
1960  case Xor:
1961  assert(getType() == LHS->getType() &&
1962  "Logical operation should return same type as operands!");
1963  assert(getType()->isIntOrIntVectorTy() &&
1964  "Tried to create a logical operation on a non-integral type!");
1965  break;
1966  default: llvm_unreachable("Invalid opcode provided");
1967  }
1968 #endif
1969 }
1970 
1972  const Twine &Name,
1973  Instruction *InsertBefore) {
1974  assert(S1->getType() == S2->getType() &&
1975  "Cannot create binary operator with two operands of differing type!");
1976  return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
1977 }
1978 
1980  const Twine &Name,
1981  BasicBlock *InsertAtEnd) {
1982  BinaryOperator *Res = Create(Op, S1, S2, Name);
1983  InsertAtEnd->getInstList().push_back(Res);
1984  return Res;
1985 }
1986 
1988  Instruction *InsertBefore) {
1990  return new BinaryOperator(Instruction::Sub,
1991  zero, Op,
1992  Op->getType(), Name, InsertBefore);
1993 }
1994 
1996  BasicBlock *InsertAtEnd) {
1998  return new BinaryOperator(Instruction::Sub,
1999  zero, Op,
2000  Op->getType(), Name, InsertAtEnd);
2001 }
2002 
2004  Instruction *InsertBefore) {
2006  return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertBefore);
2007 }
2008 
2010  BasicBlock *InsertAtEnd) {
2012  return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertAtEnd);
2013 }
2014 
2016  Instruction *InsertBefore) {
2018  return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertBefore);
2019 }
2020 
2022  BasicBlock *InsertAtEnd) {
2024  return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertAtEnd);
2025 }
2026 
2028  Instruction *InsertBefore) {
2030  return new BinaryOperator(Instruction::FSub, zero, Op,
2031  Op->getType(), Name, InsertBefore);
2032 }
2033 
2035  BasicBlock *InsertAtEnd) {
2037  return new BinaryOperator(Instruction::FSub, zero, Op,
2038  Op->getType(), Name, InsertAtEnd);
2039 }
2040 
2042  Instruction *InsertBefore) {
2044  return new BinaryOperator(Instruction::Xor, Op, C,
2045  Op->getType(), Name, InsertBefore);
2046 }
2047 
2049  BasicBlock *InsertAtEnd) {
2050  Constant *AllOnes = Constant::getAllOnesValue(Op->getType());
2051  return new BinaryOperator(Instruction::Xor, Op, AllOnes,
2052  Op->getType(), Name, InsertAtEnd);
2053 }
2054 
2055 // isConstantAllOnes - Helper function for several functions below
2056 static inline bool isConstantAllOnes(const Value *V) {
2057  if (const Constant *C = dyn_cast<Constant>(V))
2058  return C->isAllOnesValue();
2059  return false;
2060 }
2061 
2063  if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
2064  if (Bop->getOpcode() == Instruction::Sub)
2065  if (Constant *C = dyn_cast<Constant>(Bop->getOperand(0)))
2066  return C->isNegativeZeroValue();
2067  return false;
2068 }
2069 
2070 bool BinaryOperator::isFNeg(const Value *V, bool IgnoreZeroSign) {
2071  if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
2072  if (Bop->getOpcode() == Instruction::FSub)
2073  if (Constant *C = dyn_cast<Constant>(Bop->getOperand(0))) {
2074  if (!IgnoreZeroSign)
2075  IgnoreZeroSign = cast<Instruction>(V)->hasNoSignedZeros();
2076  return !IgnoreZeroSign ? C->isNegativeZeroValue() : C->isZeroValue();
2077  }
2078  return false;
2079 }
2080 
2082  if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
2083  return (Bop->getOpcode() == Instruction::Xor &&
2084  (isConstantAllOnes(Bop->getOperand(1)) ||
2085  isConstantAllOnes(Bop->getOperand(0))));
2086  return false;
2087 }
2088 
2090  return cast<BinaryOperator>(BinOp)->getOperand(1);
2091 }
2092 
2094  return getNegArgument(const_cast<Value*>(BinOp));
2095 }
2096 
2098  return cast<BinaryOperator>(BinOp)->getOperand(1);
2099 }
2100 
2102  return getFNegArgument(const_cast<Value*>(BinOp));
2103 }
2104 
2106  assert(isNot(BinOp) && "getNotArgument on non-'not' instruction!");
2107  BinaryOperator *BO = cast<BinaryOperator>(BinOp);
2108  Value *Op0 = BO->getOperand(0);
2109  Value *Op1 = BO->getOperand(1);
2110  if (isConstantAllOnes(Op0)) return Op1;
2111 
2112  assert(isConstantAllOnes(Op1));
2113  return Op0;
2114 }
2115 
2117  return getNotArgument(const_cast<Value*>(BinOp));
2118 }
2119 
2120 // Exchange the two operands to this instruction. This instruction is safe to
2121 // use on any binary instruction and does not modify the semantics of the
2122 // instruction. If the instruction is order-dependent (SetLT f.e.), the opcode
2123 // is changed.
2125  if (!isCommutative())
2126  return true; // Can't commute operands
2127  Op<0>().swap(Op<1>());
2128  return false;
2129 }
2130 
2131 //===----------------------------------------------------------------------===//
2132 // FPMathOperator Class
2133 //===----------------------------------------------------------------------===//
2134 
2136  const MDNode *MD =
2137  cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
2138  if (!MD)
2139  return 0.0;
2140  ConstantFP *Accuracy = mdconst::extract<ConstantFP>(MD->getOperand(0));
2141  return Accuracy->getValueAPF().convertToFloat();
2142 }
2143 
2144 //===----------------------------------------------------------------------===//
2145 // CastInst Class
2146 //===----------------------------------------------------------------------===//
2147 
2148 // Just determine if this cast only deals with integral->integral conversion.
2150  switch (getOpcode()) {
2151  default: return false;
2152  case Instruction::ZExt:
2153  case Instruction::SExt:
2154  case Instruction::Trunc:
2155  return true;
2156  case Instruction::BitCast:
2157  return getOperand(0)->getType()->isIntegerTy() &&
2158  getType()->isIntegerTy();
2159  }
2160 }
2161 
2163  // Only BitCast can be lossless, exit fast if we're not BitCast
2164  if (getOpcode() != Instruction::BitCast)
2165  return false;
2166 
2167  // Identity cast is always lossless
2168  Type *SrcTy = getOperand(0)->getType();
2169  Type *DstTy = getType();
2170  if (SrcTy == DstTy)
2171  return true;
2172 
2173  // Pointer to pointer is always lossless.
2174  if (SrcTy->isPointerTy())
2175  return DstTy->isPointerTy();
2176  return false; // Other types have no identity values
2177 }
2178 
2179 /// This function determines if the CastInst does not require any bits to be
2180 /// changed in order to effect the cast. Essentially, it identifies cases where
2181 /// no code gen is necessary for the cast, hence the name no-op cast. For
2182 /// example, the following are all no-op casts:
2183 /// # bitcast i32* %x to i8*
2184 /// # bitcast <2 x i32> %x to <4 x i16>
2185 /// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only
2186 /// Determine if the described cast is a no-op.
2188  Type *SrcTy,
2189  Type *DestTy,
2190  const DataLayout &DL) {
2191  switch (Opcode) {
2192  default: llvm_unreachable("Invalid CastOp");
2193  case Instruction::Trunc:
2194  case Instruction::ZExt:
2195  case Instruction::SExt:
2196  case Instruction::FPTrunc:
2197  case Instruction::FPExt:
2198  case Instruction::UIToFP:
2199  case Instruction::SIToFP:
2200  case Instruction::FPToUI:
2201  case Instruction::FPToSI:
2202  case Instruction::AddrSpaceCast:
2203  // TODO: Target informations may give a more accurate answer here.
2204  return false;
2205  case Instruction::BitCast:
2206  return true; // BitCast never modifies bits.
2207  case Instruction::PtrToInt:
2208  return DL.getIntPtrType(SrcTy)->getScalarSizeInBits() ==
2209  DestTy->getScalarSizeInBits();
2210  case Instruction::IntToPtr:
2211  return DL.getIntPtrType(DestTy)->getScalarSizeInBits() ==
2212  SrcTy->getScalarSizeInBits();
2213  }
2214 }
2215 
2216 bool CastInst::isNoopCast(const DataLayout &DL) const {
2217  return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), DL);
2218 }
2219 
2220 /// This function determines if a pair of casts can be eliminated and what
2221 /// opcode should be used in the elimination. This assumes that there are two
2222 /// instructions like this:
2223 /// * %F = firstOpcode SrcTy %x to MidTy
2224 /// * %S = secondOpcode MidTy %F to DstTy
2225 /// The function returns a resultOpcode so these two casts can be replaced with:
2226 /// * %Replacement = resultOpcode %SrcTy %x to DstTy
2227 /// If no such cast is permitted, the function returns 0.
2229  Instruction::CastOps firstOp, Instruction::CastOps secondOp,
2230  Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy,
2231  Type *DstIntPtrTy) {
2232  // Define the 144 possibilities for these two cast instructions. The values
2233  // in this matrix determine what to do in a given situation and select the
2234  // case in the switch below. The rows correspond to firstOp, the columns
2235  // correspond to secondOp. In looking at the table below, keep in mind
2236  // the following cast properties:
2237  //
2238  // Size Compare Source Destination
2239  // Operator Src ? Size Type Sign Type Sign
2240  // -------- ------------ ------------------- ---------------------
2241  // TRUNC > Integer Any Integral Any
2242  // ZEXT < Integral Unsigned Integer Any
2243  // SEXT < Integral Signed Integer Any
2244  // FPTOUI n/a FloatPt n/a Integral Unsigned
2245  // FPTOSI n/a FloatPt n/a Integral Signed
2246  // UITOFP n/a Integral Unsigned FloatPt n/a
2247  // SITOFP n/a Integral Signed FloatPt n/a
2248  // FPTRUNC > FloatPt n/a FloatPt n/a
2249  // FPEXT < FloatPt n/a FloatPt n/a
2250  // PTRTOINT n/a Pointer n/a Integral Unsigned
2251  // INTTOPTR n/a Integral Unsigned Pointer n/a
2252  // BITCAST = FirstClass n/a FirstClass n/a
2253  // ADDRSPCST n/a Pointer n/a Pointer n/a
2254  //
2255  // NOTE: some transforms are safe, but we consider them to be non-profitable.
2256  // For example, we could merge "fptoui double to i32" + "zext i32 to i64",
2257  // into "fptoui double to i64", but this loses information about the range
2258  // of the produced value (we no longer know the top-part is all zeros).
2259  // Further this conversion is often much more expensive for typical hardware,
2260  // and causes issues when building libgcc. We disallow fptosi+sext for the
2261  // same reason.
2262  const unsigned numCastOps =
2263  Instruction::CastOpsEnd - Instruction::CastOpsBegin;
2264  static const uint8_t CastResults[numCastOps][numCastOps] = {
2265  // T F F U S F F P I B A -+
2266  // R Z S P P I I T P 2 N T S |
2267  // U E E 2 2 2 2 R E I T C C +- secondOp
2268  // N X X U S F F N X N 2 V V |
2269  // C T T I I P P C T T P T T -+
2270  { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // Trunc -+
2271  { 8, 1, 9,99,99, 2,17,99,99,99, 2, 3, 0}, // ZExt |
2272  { 8, 0, 1,99,99, 0, 2,99,99,99, 0, 3, 0}, // SExt |
2273  { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // FPToUI |
2274  { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // FPToSI |
2275  { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // UIToFP +- firstOp
2276  { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // SIToFP |
2277  { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // FPTrunc |
2278  { 99,99,99, 2, 2,99,99, 8, 2,99,99, 4, 0}, // FPExt |
2279  { 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3, 0}, // PtrToInt |
2280  { 99,99,99,99,99,99,99,99,99,11,99,15, 0}, // IntToPtr |
2281  { 5, 5, 5, 6, 6, 5, 5, 6, 6,16, 5, 1,14}, // BitCast |
2282  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12}, // AddrSpaceCast -+
2283  };
2284 
2285  // TODO: This logic could be encoded into the table above and handled in the
2286  // switch below.
2287  // If either of the casts are a bitcast from scalar to vector, disallow the
2288  // merging. However, any pair of bitcasts are allowed.
2289  bool IsFirstBitcast = (firstOp == Instruction::BitCast);
2290  bool IsSecondBitcast = (secondOp == Instruction::BitCast);
2291  bool AreBothBitcasts = IsFirstBitcast && IsSecondBitcast;
2292 
2293  // Check if any of the casts convert scalars <-> vectors.
2294  if ((IsFirstBitcast && isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
2295  (IsSecondBitcast && isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
2296  if (!AreBothBitcasts)
2297  return 0;
2298 
2299  int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
2300  [secondOp-Instruction::CastOpsBegin];
2301  switch (ElimCase) {
2302  case 0:
2303  // Categorically disallowed.
2304  return 0;
2305  case 1:
2306  // Allowed, use first cast's opcode.
2307  return firstOp;
2308  case 2:
2309  // Allowed, use second cast's opcode.
2310  return secondOp;
2311  case 3:
2312  // No-op cast in second op implies firstOp as long as the DestTy
2313  // is integer and we are not converting between a vector and a
2314  // non-vector type.
2315  if (!SrcTy->isVectorTy() && DstTy->isIntegerTy())
2316  return firstOp;
2317  return 0;
2318  case 4:
2319  // No-op cast in second op implies firstOp as long as the DestTy
2320  // is floating point.
2321  if (DstTy->isFloatingPointTy())
2322  return firstOp;
2323  return 0;
2324  case 5:
2325  // No-op cast in first op implies secondOp as long as the SrcTy
2326  // is an integer.
2327  if (SrcTy->isIntegerTy())
2328  return secondOp;
2329  return 0;
2330  case 6:
2331  // No-op cast in first op implies secondOp as long as the SrcTy
2332  // is a floating point.
2333  if (SrcTy->isFloatingPointTy())
2334  return secondOp;
2335  return 0;
2336  case 7: {
2337  // Cannot simplify if address spaces are different!
2338  if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2339  return 0;
2340 
2341  unsigned MidSize = MidTy->getScalarSizeInBits();
2342  // We can still fold this without knowing the actual sizes as long we
2343  // know that the intermediate pointer is the largest possible
2344  // pointer size.
2345  // FIXME: Is this always true?
2346  if (MidSize == 64)
2347  return Instruction::BitCast;
2348 
2349  // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size.
2350  if (!SrcIntPtrTy || DstIntPtrTy != SrcIntPtrTy)
2351  return 0;
2352  unsigned PtrSize = SrcIntPtrTy->getScalarSizeInBits();
2353  if (MidSize >= PtrSize)
2354  return Instruction::BitCast;
2355  return 0;
2356  }
2357  case 8: {
2358  // ext, trunc -> bitcast, if the SrcTy and DstTy are same size
2359  // ext, trunc -> ext, if sizeof(SrcTy) < sizeof(DstTy)
2360  // ext, trunc -> trunc, if sizeof(SrcTy) > sizeof(DstTy)
2361  unsigned SrcSize = SrcTy->getScalarSizeInBits();
2362  unsigned DstSize = DstTy->getScalarSizeInBits();
2363  if (SrcSize == DstSize)
2364  return Instruction::BitCast;
2365  else if (SrcSize < DstSize)
2366  return firstOp;
2367  return secondOp;
2368  }
2369  case 9:
2370  // zext, sext -> zext, because sext can't sign extend after zext
2371  return Instruction::ZExt;
2372  case 11: {
2373  // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize
2374  if (!MidIntPtrTy)
2375  return 0;
2376  unsigned PtrSize = MidIntPtrTy->getScalarSizeInBits();
2377  unsigned SrcSize = SrcTy->getScalarSizeInBits();
2378  unsigned DstSize = DstTy->getScalarSizeInBits();
2379  if (SrcSize <= PtrSize && SrcSize == DstSize)
2380  return Instruction::BitCast;
2381  return 0;
2382  }
2383  case 12:
2384  // addrspacecast, addrspacecast -> bitcast, if SrcAS == DstAS
2385  // addrspacecast, addrspacecast -> addrspacecast, if SrcAS != DstAS
2386  if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2387  return Instruction::AddrSpaceCast;
2388  return Instruction::BitCast;
2389  case 13:
2390  // FIXME: this state can be merged with (1), but the following assert
2391  // is useful to check the correcteness of the sequence due to semantic
2392  // change of bitcast.
2393  assert(
2394  SrcTy->isPtrOrPtrVectorTy() &&
2395  MidTy->isPtrOrPtrVectorTy() &&
2396  DstTy->isPtrOrPtrVectorTy() &&
2397  SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() &&
2398  MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2399  "Illegal addrspacecast, bitcast sequence!");
2400  // Allowed, use first cast's opcode
2401  return firstOp;
2402  case 14:
2403  // bitcast, addrspacecast -> addrspacecast if the element type of
2404  // bitcast's source is the same as that of addrspacecast's destination.
2405  if (SrcTy->getScalarType()->getPointerElementType() ==
2407  return Instruction::AddrSpaceCast;
2408  return 0;
2409  case 15:
2410  // FIXME: this state can be merged with (1), but the following assert
2411  // is useful to check the correcteness of the sequence due to semantic
2412  // change of bitcast.
2413  assert(
2414  SrcTy->isIntOrIntVectorTy() &&
2415  MidTy->isPtrOrPtrVectorTy() &&
2416  DstTy->isPtrOrPtrVectorTy() &&
2417  MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2418  "Illegal inttoptr, bitcast sequence!");
2419  // Allowed, use first cast's opcode
2420  return firstOp;
2421  case 16:
2422  // FIXME: this state can be merged with (2), but the following assert
2423  // is useful to check the correcteness of the sequence due to semantic
2424  // change of bitcast.
2425  assert(
2426  SrcTy->isPtrOrPtrVectorTy() &&
2427  MidTy->isPtrOrPtrVectorTy() &&
2428  DstTy->isIntOrIntVectorTy() &&
2429  SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&
2430  "Illegal bitcast, ptrtoint sequence!");
2431  // Allowed, use second cast's opcode
2432  return secondOp;
2433  case 17:
2434  // (sitofp (zext x)) -> (uitofp x)
2435  return Instruction::UIToFP;
2436  case 99:
2437  // Cast combination can't happen (error in input). This is for all cases
2438  // where the MidTy is not the same for the two cast instructions.
2439  llvm_unreachable("Invalid Cast Combination");
2440  default:
2441  llvm_unreachable("Error in CastResults table!!!");
2442  }
2443 }
2444 
2446  const Twine &Name, Instruction *InsertBefore) {
2447  assert(castIsValid(op, S, Ty) && "Invalid cast!");
2448  // Construct and return the appropriate CastInst subclass
2449  switch (op) {
2450  case Trunc: return new TruncInst (S, Ty, Name, InsertBefore);
2451  case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore);
2452  case SExt: return new SExtInst (S, Ty, Name, InsertBefore);
2453  case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore);
2454  case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore);
2455  case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore);
2456  case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore);
2457  case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore);
2458  case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
2459  case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
2460  case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
2461  case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
2462  case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertBefore);
2463  default: llvm_unreachable("Invalid opcode provided");
2464  }
2465 }
2466 
2468  const Twine &Name, BasicBlock *InsertAtEnd) {
2469  assert(castIsValid(op, S, Ty) && "Invalid cast!");
2470  // Construct and return the appropriate CastInst subclass
2471  switch (op) {
2472  case Trunc: return new TruncInst (S, Ty, Name, InsertAtEnd);
2473  case ZExt: return new ZExtInst (S, Ty, Name, InsertAtEnd);
2474  case SExt: return new SExtInst (S, Ty, Name, InsertAtEnd);
2475  case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertAtEnd);
2476  case FPExt: return new FPExtInst (S, Ty, Name, InsertAtEnd);
2477  case UIToFP: return new UIToFPInst (S, Ty, Name, InsertAtEnd);
2478  case SIToFP: return new SIToFPInst (S, Ty, Name, InsertAtEnd);
2479  case FPToUI: return new FPToUIInst (S, Ty, Name, InsertAtEnd);
2480  case FPToSI: return new FPToSIInst (S, Ty, Name, InsertAtEnd);
2481  case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd);
2482  case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd);
2483  case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd);
2484  case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertAtEnd);
2485  default: llvm_unreachable("Invalid opcode provided");
2486  }
2487 }
2488 
2490  const Twine &Name,
2491  Instruction *InsertBefore) {
2492  if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2493  return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2494  return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
2495 }
2496 
2498  const Twine &Name,
2499  BasicBlock *InsertAtEnd) {
2500  if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2501  return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2502  return Create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
2503 }
2504 
2506  const Twine &Name,
2507  Instruction *InsertBefore) {
2508  if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2509  return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2510  return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
2511 }
2512 
2514  const Twine &Name,
2515  BasicBlock *InsertAtEnd) {
2516  if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2517  return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2518  return Create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
2519 }
2520 
2522  const Twine &Name,
2523  Instruction *InsertBefore) {
2524  if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2525  return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2526  return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
2527 }
2528 
2530  const Twine &Name,
2531  BasicBlock *InsertAtEnd) {
2532  if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
2533  return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2534  return Create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
2535 }
2536 
2538  const Twine &Name,
2539  BasicBlock *InsertAtEnd) {
2540  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2541  assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
2542  "Invalid cast");
2543  assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
2544  assert((!Ty->isVectorTy() ||
2546  "Invalid cast");
2547 
2548  if (Ty->isIntOrIntVectorTy())
2549  return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
2550 
2551  return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertAtEnd);
2552 }
2553 
2554 /// Create a BitCast or a PtrToInt cast instruction
2556  const Twine &Name,
2557  Instruction *InsertBefore) {
2558  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2559  assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
2560  "Invalid cast");
2561  assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
2562  assert((!Ty->isVectorTy() ||
2564  "Invalid cast");
2565 
2566  if (Ty->isIntOrIntVectorTy())
2567  return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
2568 
2569  return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertBefore);
2570 }
2571 
2573  Value *S, Type *Ty,
2574  const Twine &Name,
2575  BasicBlock *InsertAtEnd) {
2576  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2577  assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
2578 
2580  return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertAtEnd);
2581 
2582  return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
2583 }
2584 
2586  Value *S, Type *Ty,
2587  const Twine &Name,
2588  Instruction *InsertBefore) {
2589  assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
2590  assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
2591 
2593  return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertBefore);
2594 
2595  return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2596 }
2597 
2599  const Twine &Name,
2600  Instruction *InsertBefore) {
2601  if (S->getType()->isPointerTy() && Ty->isIntegerTy())
2602  return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
2603  if (S->getType()->isIntegerTy() && Ty->isPointerTy())
2604  return Create(Instruction::IntToPtr, S, Ty, Name, InsertBefore);
2605 
2606  return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
2607 }
2608 
2610  bool isSigned, const Twine &Name,
2611  Instruction *InsertBefore) {
2613  "Invalid integer cast");
2614  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2615  unsigned DstBits = Ty->getScalarSizeInBits();
2616  Instruction::CastOps opcode =
2617  (SrcBits == DstBits ? Instruction::BitCast :
2618  (SrcBits > DstBits ? Instruction::Trunc :
2619  (isSigned ? Instruction::SExt : Instruction::ZExt)));
2620  return Create(opcode, C, Ty, Name, InsertBefore);
2621 }
2622 
2624  bool isSigned, const Twine &Name,
2625  BasicBlock *InsertAtEnd) {
2627  "Invalid cast");
2628  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2629  unsigned DstBits = Ty->getScalarSizeInBits();
2630  Instruction::CastOps opcode =
2631  (SrcBits == DstBits ? Instruction::BitCast :
2632  (SrcBits > DstBits ? Instruction::Trunc :
2633  (isSigned ? Instruction::SExt : Instruction::ZExt)));
2634  return Create(opcode, C, Ty, Name, InsertAtEnd);
2635 }
2636 
2638  const Twine &Name,
2639  Instruction *InsertBefore) {
2640  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2641  "Invalid cast");
2642  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2643  unsigned DstBits = Ty->getScalarSizeInBits();
2644  Instruction::CastOps opcode =
2645  (SrcBits == DstBits ? Instruction::BitCast :
2646  (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
2647  return Create(opcode, C, Ty, Name, InsertBefore);
2648 }
2649 
2651  const Twine &Name,
2652  BasicBlock *InsertAtEnd) {
2653  assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
2654  "Invalid cast");
2655  unsigned SrcBits = C->getType()->getScalarSizeInBits();
2656  unsigned DstBits = Ty->getScalarSizeInBits();
2657  Instruction::CastOps opcode =
2658  (SrcBits == DstBits ? Instruction::BitCast :
2659  (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
2660  return Create(opcode, C, Ty, Name, InsertAtEnd);
2661 }
2662 
2663 // Check whether it is valid to call getCastOpcode for these types.
2664 // This routine must be kept in sync with getCastOpcode.
2665 bool CastInst::isCastable(Type *SrcTy, Type *DestTy) {
2666  if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
2667  return false;
2668 
2669  if (SrcTy == DestTy)
2670  return true;
2671 
2672  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
2673  if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
2674  if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
2675  // An element by element cast. Valid if casting the elements is valid.
2676  SrcTy = SrcVecTy->getElementType();
2677  DestTy = DestVecTy->getElementType();
2678  }
2679 
2680  // Get the bit sizes, we'll need these
2681  unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
2682  unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
2683 
2684  // Run through the possibilities ...
2685  if (DestTy->isIntegerTy()) { // Casting to integral
2686  if (SrcTy->isIntegerTy()) // Casting from integral
2687  return true;
2688  if (SrcTy->isFloatingPointTy()) // Casting from floating pt
2689  return true;
2690  if (SrcTy->isVectorTy()) // Casting from vector
2691  return DestBits == SrcBits;
2692  // Casting from something else
2693  return SrcTy->isPointerTy();
2694  }
2695  if (DestTy->isFloatingPointTy()) { // Casting to floating pt
2696  if (SrcTy->isIntegerTy()) // Casting from integral
2697  return true;
2698  if (SrcTy->isFloatingPointTy()) // Casting from floating pt
2699  return true;
2700  if (SrcTy->isVectorTy()) // Casting from vector
2701  return DestBits == SrcBits;
2702  // Casting from something else
2703  return false;
2704  }
2705  if (DestTy->isVectorTy()) // Casting to vector
2706  return DestBits == SrcBits;
2707  if (DestTy->isPointerTy()) { // Casting to pointer
2708  if (SrcTy->isPointerTy()) // Casting from pointer
2709  return true;
2710  return SrcTy->isIntegerTy(); // Casting from integral
2711  }
2712  if (DestTy->isX86_MMXTy()) {
2713  if (SrcTy->isVectorTy())
2714  return DestBits == SrcBits; // 64-bit vector to MMX
2715  return false;
2716  } // Casting to something else
2717  return false;
2718 }
2719 
2720 bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {
2721  if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
2722  return false;
2723 
2724  if (SrcTy == DestTy)
2725  return true;
2726 
2727  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
2728  if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) {
2729  if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
2730  // An element by element cast. Valid if casting the elements is valid.
2731  SrcTy = SrcVecTy->getElementType();
2732  DestTy = DestVecTy->getElementType();
2733  }
2734  }
2735  }
2736 
2737  if (PointerType *DestPtrTy = dyn_cast<PointerType>(DestTy)) {
2738  if (PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy)) {
2739  return SrcPtrTy->getAddressSpace() == DestPtrTy->getAddressSpace();
2740  }
2741  }
2742 
2743  unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
2744  unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
2745 
2746  // Could still have vectors of pointers if the number of elements doesn't
2747  // match
2748  if (SrcBits == 0 || DestBits == 0)
2749  return false;
2750 
2751  if (SrcBits != DestBits)
2752  return false;
2753 
2754  if (DestTy->isX86_MMXTy() || SrcTy->isX86_MMXTy())
2755  return false;
2756 
2757  return true;
2758 }
2759 
2761  const DataLayout &DL) {
2762  // ptrtoint and inttoptr are not allowed on non-integral pointers
2763  if (auto *PtrTy = dyn_cast<PointerType>(SrcTy))
2764  if (auto *IntTy = dyn_cast<IntegerType>(DestTy))
2765  return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
2766  !DL.isNonIntegralPointerType(PtrTy));
2767  if (auto *PtrTy = dyn_cast<PointerType>(DestTy))
2768  if (auto *IntTy = dyn_cast<IntegerType>(SrcTy))
2769  return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
2770  !DL.isNonIntegralPointerType(PtrTy));
2771 
2772  return isBitCastable(SrcTy, DestTy);
2773 }
2774 
2775 // Provide a way to get a "cast" where the cast opcode is inferred from the
2776 // types and size of the operand. This, basically, is a parallel of the
2777 // logic in the castIsValid function below. This axiom should hold:
2778 // castIsValid( getCastOpcode(Val, Ty), Val, Ty)
2779 // should not assert in castIsValid. In other words, this produces a "correct"
2780 // casting opcode for the arguments passed to it.
2781 // This routine must be kept in sync with isCastable.
2784  const Value *Src, bool SrcIsSigned, Type *DestTy, bool DestIsSigned) {
2785  Type *SrcTy = Src->getType();
2786 
2787  assert(SrcTy->isFirstClassType() && DestTy->isFirstClassType() &&
2788  "Only first class types are castable!");
2789 
2790  if (SrcTy == DestTy)
2791  return BitCast;
2792 
2793  // FIXME: Check address space sizes here
2794  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
2795  if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
2796  if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
2797  // An element by element cast. Find the appropriate opcode based on the
2798  // element types.
2799  SrcTy = SrcVecTy->getElementType();
2800  DestTy = DestVecTy->getElementType();
2801  }
2802 
2803  // Get the bit sizes, we'll need these
2804  unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr
2805  unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
2806 
2807  // Run through the possibilities ...
2808  if (DestTy->isIntegerTy()) { // Casting to integral
2809  if (SrcTy->isIntegerTy()) { // Casting from integral
2810  if (DestBits < SrcBits)
2811  return Trunc; // int -> smaller int
2812  else if (DestBits > SrcBits) { // its an extension
2813  if (SrcIsSigned)
2814  return SExt; // signed -> SEXT
2815  else
2816  return ZExt; // unsigned -> ZEXT
2817  } else {
2818  return BitCast; // Same size, No-op cast
2819  }
2820  } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
2821  if (DestIsSigned)
2822  return FPToSI; // FP -> sint
2823  else
2824  return FPToUI; // FP -> uint
2825  } else if (SrcTy->isVectorTy()) {
2826  assert(DestBits == SrcBits &&
2827  "Casting vector to integer of different width");
2828  return BitCast; // Same size, no-op cast
2829  } else {
2830  assert(SrcTy->isPointerTy() &&
2831  "Casting from a value that is not first-class type");
2832  return PtrToInt; // ptr -> int
2833  }
2834  } else if (DestTy->isFloatingPointTy()) { // Casting to floating pt
2835  if (SrcTy->isIntegerTy()) { // Casting from integral
2836  if (SrcIsSigned)
2837  return SIToFP; // sint -> FP
2838  else
2839  return UIToFP; // uint -> FP
2840  } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt
2841  if (DestBits < SrcBits) {
2842  return FPTrunc; // FP -> smaller FP
2843  } else if (DestBits > SrcBits) {
2844  return FPExt; // FP -> larger FP
2845  } else {
2846  return BitCast; // same size, no-op cast
2847  }
2848  } else if (SrcTy->isVectorTy()) {
2849  assert(DestBits == SrcBits &&
2850  "Casting vector to floating point of different width");
2851  return BitCast; // same size, no-op cast
2852  }
2853  llvm_unreachable("Casting pointer or non-first class to float");
2854  } else if (DestTy->isVectorTy()) {
2855  assert(DestBits == SrcBits &&
2856  "Illegal cast to vector (wrong type or size)");
2857  return BitCast;
2858  } else if (DestTy->isPointerTy()) {
2859  if (SrcTy->isPointerTy()) {
2860  if (DestTy->getPointerAddressSpace() != SrcTy->getPointerAddressSpace())
2861  return AddrSpaceCast;
2862  return BitCast; // ptr -> ptr
2863  } else if (SrcTy->isIntegerTy()) {
2864  return IntToPtr; // int -> ptr
2865  }
2866  llvm_unreachable("Casting pointer to other than pointer or int");
2867  } else if (DestTy->isX86_MMXTy()) {
2868  if (SrcTy->isVectorTy()) {
2869  assert(DestBits == SrcBits && "Casting vector of wrong width to X86_MMX");
2870  return BitCast; // 64-bit vector to MMX
2871  }
2872  llvm_unreachable("Illegal cast to X86_MMX");
2873  }
2874  llvm_unreachable("Casting to type that is not first-class");
2875 }
2876 
2877 //===----------------------------------------------------------------------===//
2878 // CastInst SubClass Constructors
2879 //===----------------------------------------------------------------------===//
2880 
2881 /// Check that the construction parameters for a CastInst are correct. This
2882 /// could be broken out into the separate constructors but it is useful to have
2883 /// it in one place and to eliminate the redundant code for getting the sizes
2884 /// of the types involved.
2885 bool
2887  // Check for type sanity on the arguments
2888  Type *SrcTy = S->getType();
2889 
2890  if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType() ||
2891  SrcTy->isAggregateType() || DstTy->isAggregateType())
2892  return false;
2893 
2894  // Get the size of the types in bits, we'll need this later
2895  unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
2896  unsigned DstBitSize = DstTy->getScalarSizeInBits();
2897 
2898  // If these are vector types, get the lengths of the vectors (using zero for
2899  // scalar types means that checking that vector lengths match also checks that
2900  // scalars are not being converted to vectors or vectors to scalars).
2901  unsigned SrcLength = SrcTy->isVectorTy() ?
2902  cast<VectorType>(SrcTy)->getNumElements() : 0;
2903  unsigned DstLength = DstTy->isVectorTy() ?
2904  cast<VectorType>(DstTy)->getNumElements() : 0;
2905 
2906  // Switch on the opcode provided
2907  switch (op) {
2908  default: return false; // This is an input error
2909  case Instruction::Trunc:
2910  return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
2911  SrcLength == DstLength && SrcBitSize > DstBitSize;
2912  case Instruction::ZExt:
2913  return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
2914  SrcLength == DstLength && SrcBitSize < DstBitSize;
2915  case Instruction::SExt:
2916  return SrcTy->isIntOrIntVectorTy() && DstTy->isIntOrIntVectorTy() &&
2917  SrcLength == DstLength && SrcBitSize < DstBitSize;
2918  case Instruction::FPTrunc:
2919  return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
2920  SrcLength == DstLength && SrcBitSize > DstBitSize;
2921  case Instruction::FPExt:
2922  return SrcTy->isFPOrFPVectorTy() && DstTy->isFPOrFPVectorTy() &&
2923  SrcLength == DstLength && SrcBitSize < DstBitSize;
2924  case Instruction::UIToFP:
2925  case Instruction::SIToFP:
2926  return SrcTy->isIntOrIntVectorTy() && DstTy->isFPOrFPVectorTy() &&
2927  SrcLength == DstLength;
2928  case Instruction::FPToUI:
2929  case Instruction::FPToSI:
2930  return SrcTy->isFPOrFPVectorTy() && DstTy->isIntOrIntVectorTy() &&
2931  SrcLength == DstLength;
2932  case Instruction::PtrToInt:
2933  if (isa<VectorType>(SrcTy) != isa<VectorType>(DstTy))
2934  return false;
2935  if (VectorType *VT = dyn_cast<VectorType>(SrcTy))
2936  if (VT->getNumElements() != cast<VectorType>(DstTy)->getNumElements())
2937  return false;
2938  return SrcTy->isPtrOrPtrVectorTy() && DstTy->isIntOrIntVectorTy();
2939  case Instruction::IntToPtr:
2940  if (isa<VectorType>(SrcTy) != isa<VectorType>(DstTy))
2941  return false;
2942  if (VectorType *VT = dyn_cast<VectorType>(SrcTy))
2943  if (VT->getNumElements() != cast<VectorType>(DstTy)->getNumElements())
2944  return false;
2945  return SrcTy->isIntOrIntVectorTy() && DstTy->isPtrOrPtrVectorTy();
2946  case Instruction::BitCast: {
2947  PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
2948  PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
2949 
2950  // BitCast implies a no-op cast of type only. No bits change.
2951  // However, you can't cast pointers to anything but pointers.
2952  if (!SrcPtrTy != !DstPtrTy)
2953  return false;
2954 
2955  // For non-pointer cases, the cast is okay if the source and destination bit
2956  // widths are identical.
2957  if (!SrcPtrTy)
2958  return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
2959 
2960  // If both are pointers then the address spaces must match.
2961  if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
2962  return false;
2963 
2964  // A vector of pointers must have the same number of elements.
2965  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
2966  if (VectorType *DstVecTy = dyn_cast<VectorType>(DstTy))
2967  return (SrcVecTy->getNumElements() == DstVecTy->getNumElements());
2968 
2969  return false;
2970  }
2971 
2972  return true;
2973  }
2974  case Instruction::AddrSpaceCast: {
2975  PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy->getScalarType());
2976  if (!SrcPtrTy)
2977  return false;
2978 
2979  PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy->getScalarType());
2980  if (!DstPtrTy)
2981  return false;
2982 
2983  if (SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
2984  return false;
2985 
2986  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
2987  if (VectorType *DstVecTy = dyn_cast<VectorType>(DstTy))
2988  return (SrcVecTy->getNumElements() == DstVecTy->getNumElements());
2989 
2990  return false;
2991  }
2992 
2993  return true;
2994  }
2995  }
2996 }
2997 
2999  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3000 ) : CastInst(Ty, Trunc, S, Name, InsertBefore) {
3001  assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc");
3002 }
3003 
3005  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3006 ) : CastInst(Ty, Trunc, S, Name, InsertAtEnd) {
3007  assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc");
3008 }
3009 
3011  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3012 ) : CastInst(Ty, ZExt, S, Name, InsertBefore) {
3013  assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt");
3014 }
3015 
3017  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3018 ) : CastInst(Ty, ZExt, S, Name, InsertAtEnd) {
3019  assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt");
3020 }
3022  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3023 ) : CastInst(Ty, SExt, S, Name, InsertBefore) {
3024  assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt");
3025 }
3026 
3028  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3029 ) : CastInst(Ty, SExt, S, Name, InsertAtEnd) {
3030  assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt");
3031 }
3032 
3034  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3035 ) : CastInst(Ty, FPTrunc, S, Name, InsertBefore) {
3036  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc");
3037 }
3038 
3040  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3041 ) : CastInst(Ty, FPTrunc, S, Name, InsertAtEnd) {
3042  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc");
3043 }
3044 
3046  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3047 ) : CastInst(Ty, FPExt, S, Name, InsertBefore) {
3048  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt");
3049 }
3050 
3052  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3053 ) : CastInst(Ty, FPExt, S, Name, InsertAtEnd) {
3054  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt");
3055 }
3056 
3058  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3059 ) : CastInst(Ty, UIToFP, S, Name, InsertBefore) {
3060  assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP");
3061 }
3062 
3064  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3065 ) : CastInst(Ty, UIToFP, S, Name, InsertAtEnd) {
3066  assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP");
3067 }
3068 
3070  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3071 ) : CastInst(Ty, SIToFP, S, Name, InsertBefore) {
3072  assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP");
3073 }
3074 
3076  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3077 ) : CastInst(Ty, SIToFP, S, Name, InsertAtEnd) {
3078  assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP");
3079 }
3080 
3082  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3083 ) : CastInst(Ty, FPToUI, S, Name, InsertBefore) {
3084  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI");
3085 }
3086 
3088  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3089 ) : CastInst(Ty, FPToUI, S, Name, InsertAtEnd) {
3090  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI");
3091 }
3092 
3094  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3095 ) : CastInst(Ty, FPToSI, S, Name, InsertBefore) {
3096  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
3097 }
3098 
3100  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3101 ) : CastInst(Ty, FPToSI, S, Name, InsertAtEnd) {
3102  assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
3103 }
3104 
3106  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3107 ) : CastInst(Ty, PtrToInt, S, Name, InsertBefore) {
3108  assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
3109 }
3110 
3112  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3113 ) : CastInst(Ty, PtrToInt, S, Name, InsertAtEnd) {
3114  assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
3115 }
3116 
3118  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3119 ) : CastInst(Ty, IntToPtr, S, Name, InsertBefore) {
3120  assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr");
3121 }
3122 
3124  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3125 ) : CastInst(Ty, IntToPtr, S, Name, InsertAtEnd) {
3126  assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr");
3127 }
3128 
3130  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3131 ) : CastInst(Ty, BitCast, S, Name, InsertBefore) {
3132  assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
3133 }
3134 
3136  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3137 ) : CastInst(Ty, BitCast, S, Name, InsertAtEnd) {
3138  assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
3139 }
3140 
3142  Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
3143 ) : CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
3144  assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
3145 }
3146 
3148  Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
3149 ) : CastInst(Ty, AddrSpaceCast, S, Name, InsertAtEnd) {
3150  assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
3151 }
3152 
3153 //===----------------------------------------------------------------------===//
3154 // CmpInst Classes
3155 //===----------------------------------------------------------------------===//
3156 
3158  Value *RHS, const Twine &Name, Instruction *InsertBefore)
3159  : Instruction(ty, op,
3160  OperandTraits<CmpInst>::op_begin(this),
3161  OperandTraits<CmpInst>::operands(this),
3162  InsertBefore) {
3163  Op<0>() = LHS;
3164  Op<1>() = RHS;
3165  setPredicate((Predicate)predicate);
3166  setName(Name);
3167 }
3168 
3170  Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd)
3171  : Instruction(ty, op,
3172  OperandTraits<CmpInst>::op_begin(this),
3173  OperandTraits<CmpInst>::operands(this),
3174  InsertAtEnd) {
3175  Op<0>() = LHS;
3176  Op<1>() = RHS;
3177  setPredicate((Predicate)predicate);
3178  setName(Name);
3179 }
3180 
3181 CmpInst *
3183  const Twine &Name, Instruction *InsertBefore) {
3184  if (Op == Instruction::ICmp) {
3185  if (InsertBefore)
3186  return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
3187  S1, S2, Name);
3188  else
3189  return new ICmpInst(CmpInst::Predicate(predicate),
3190  S1, S2, Name);
3191  }
3192 
3193  if (InsertBefore)
3194  return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
3195  S1, S2, Name);
3196  else
3197  return new FCmpInst(CmpInst::Predicate(predicate),
3198  S1, S2, Name);
3199 }
3200 
3201 CmpInst *
3203  const Twine &Name, BasicBlock *InsertAtEnd) {
3204  if (Op == Instruction::ICmp) {
3205  return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
3206  S1, S2, Name);
3207  }
3208  return new FCmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
3209  S1, S2, Name);
3210 }
3211 
3213  if (ICmpInst *IC = dyn_cast<ICmpInst>(this))
3214  IC->swapOperands();
3215  else
3216  cast<FCmpInst>(this)->swapOperands();
3217 }
3218 
3220  if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
3221  return IC->isCommutative();
3222  return cast<FCmpInst>(this)->isCommutative();
3223 }
3224 
3225 bool CmpInst::isEquality() const {
3226  if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
3227  return IC->isEquality();
3228  return cast<FCmpInst>(this)->isEquality();
3229 }
3230 
3232  switch (pred) {
3233  default: llvm_unreachable("Unknown cmp predicate!");
3234  case ICMP_EQ: return ICMP_NE;
3235  case ICMP_NE: return ICMP_EQ;
3236  case ICMP_UGT: return ICMP_ULE;
3237  case ICMP_ULT: return ICMP_UGE;
3238  case ICMP_UGE: return ICMP_ULT;
3239  case ICMP_ULE: return ICMP_UGT;
3240  case ICMP_SGT: return ICMP_SLE;
3241  case ICMP_SLT: return ICMP_SGE;
3242  case ICMP_SGE: return ICMP_SLT;
3243  case ICMP_SLE: return ICMP_SGT;
3244 
3245  case FCMP_OEQ: return FCMP_UNE;
3246  case FCMP_ONE: return FCMP_UEQ;
3247  case FCMP_OGT: return FCMP_ULE;
3248  case FCMP_OLT: return FCMP_UGE;
3249  case FCMP_OGE: return FCMP_ULT;
3250  case FCMP_OLE: return FCMP_UGT;
3251  case FCMP_UEQ: return FCMP_ONE;
3252  case FCMP_UNE: return FCMP_OEQ;
3253  case FCMP_UGT: return FCMP_OLE;
3254  case FCMP_ULT: return FCMP_OGE;
3255  case FCMP_UGE: return FCMP_OLT;
3256  case FCMP_ULE: return FCMP_OGT;
3257  case FCMP_ORD: return FCMP_UNO;
3258  case FCMP_UNO: return FCMP_ORD;
3259  case FCMP_TRUE: return FCMP_FALSE;
3260  case FCMP_FALSE: return FCMP_TRUE;
3261  }
3262 }
3263 
3265  switch (Pred) {
3266  default: return "unknown";
3267  case FCmpInst::FCMP_FALSE: return "false";
3268  case FCmpInst::FCMP_OEQ: return "oeq";
3269  case FCmpInst::FCMP_OGT: return "ogt";
3270  case FCmpInst::FCMP_OGE: return "oge";
3271  case FCmpInst::FCMP_OLT: return "olt";
3272  case FCmpInst::FCMP_OLE: return "ole";
3273  case FCmpInst::FCMP_ONE: return "one";
3274  case FCmpInst::FCMP_ORD: return "ord";
3275  case FCmpInst::FCMP_UNO: return "uno";
3276  case FCmpInst::FCMP_UEQ: return "ueq";
3277  case FCmpInst::FCMP_UGT: return "ugt";
3278  case FCmpInst::FCMP_UGE: return "uge";
3279  case FCmpInst::FCMP_ULT: return "ult";
3280  case FCmpInst::FCMP_ULE: return "ule";
3281  case FCmpInst::FCMP_UNE: return "une";
3282  case FCmpInst::FCMP_TRUE: return "true";
3283  case ICmpInst::ICMP_EQ: return "eq";
3284  case ICmpInst::ICMP_NE: return "ne";
3285  case ICmpInst::ICMP_SGT: return "sgt";
3286  case ICmpInst::ICMP_SGE: return "sge";
3287  case ICmpInst::ICMP_SLT: return "slt";
3288  case ICmpInst::ICMP_SLE: return "sle";
3289  case ICmpInst::ICMP_UGT: return "ugt";
3290  case ICmpInst::ICMP_UGE: return "uge";
3291  case ICmpInst::ICMP_ULT: return "ult";
3292  case ICmpInst::ICMP_ULE: return "ule";
3293  }
3294 }
3295 
3297  switch (pred) {
3298  default: llvm_unreachable("Unknown icmp predicate!");
3299  case ICMP_EQ: case ICMP_NE:
3300  case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
3301  return pred;
3302  case ICMP_UGT: return ICMP_SGT;
3303  case ICMP_ULT: return ICMP_SLT;
3304  case ICMP_UGE: return ICMP_SGE;
3305  case ICMP_ULE: return ICMP_SLE;
3306  }
3307 }
3308 
3310  switch (pred) {
3311  default: llvm_unreachable("Unknown icmp predicate!");
3312  case ICMP_EQ: case ICMP_NE:
3313  case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE:
3314  return pred;
3315  case ICMP_SGT: return ICMP_UGT;
3316  case ICMP_SLT: return ICMP_ULT;
3317  case ICMP_SGE: return ICMP_UGE;
3318  case ICMP_SLE: return ICMP_ULE;
3319  }
3320 }
3321 
3323  switch (pred) {
3324  default: llvm_unreachable("Unknown or unsupported cmp predicate!");
3325  case ICMP_SGT: return ICMP_SGE;
3326  case ICMP_SLT: return ICMP_SLE;
3327  case ICMP_SGE: return ICMP_SGT;
3328  case ICMP_SLE: return ICMP_SLT;
3329  case ICMP_UGT: return ICMP_UGE;
3330  case ICMP_ULT: return ICMP_ULE;
3331  case ICMP_UGE: return ICMP_UGT;
3332  case ICMP_ULE: return ICMP_ULT;
3333 
3334  case FCMP_OGT: return FCMP_OGE;
3335  case FCMP_OLT: return FCMP_OLE;
3336  case FCMP_OGE: return FCMP_OGT;
3337  case FCMP_OLE: return FCMP_OLT;
3338  case FCMP_UGT: return FCMP_UGE;
3339  case FCMP_ULT: return FCMP_ULE;
3340  case FCMP_UGE: return FCMP_UGT;
3341  case FCMP_ULE: return FCMP_ULT;
3342  }
3343 }
3344 
3346  switch (pred) {
3347  default: llvm_unreachable("Unknown cmp predicate!");
3348  case ICMP_EQ: case ICMP_NE:
3349  return pred;
3350  case ICMP_SGT: return ICMP_SLT;
3351  case ICMP_SLT: return ICMP_SGT;
3352  case ICMP_SGE: return ICMP_SLE;
3353  case ICMP_SLE: return ICMP_SGE;
3354  case ICMP_UGT: return ICMP_ULT;
3355  case ICMP_ULT: return ICMP_UGT;
3356  case ICMP_UGE: return ICMP_ULE;
3357  case ICMP_ULE: return ICMP_UGE;
3358 
3359  case FCMP_FALSE: case FCMP_TRUE:
3360  case FCMP_OEQ: case FCMP_ONE:
3361  case FCMP_UEQ: case FCMP_UNE:
3362  case FCMP_ORD: case FCMP_UNO:
3363  return pred;
3364  case FCMP_OGT: return FCMP_OLT;
3365  case FCMP_OLT: return FCMP_OGT;
3366  case FCMP_OGE: return FCMP_OLE;
3367  case FCMP_OLE: return FCMP_OGE;
3368  case FCMP_UGT: return FCMP_ULT;
3369  case FCMP_ULT: return FCMP_UGT;
3370  case FCMP_UGE: return FCMP_ULE;
3371  case FCMP_ULE: return FCMP_UGE;
3372  }
3373 }
3374 
3376  switch (pred) {
3377  case ICMP_SGT: return ICMP_SGE;
3378  case ICMP_SLT: return ICMP_SLE;
3379  case ICMP_UGT: return ICMP_UGE;
3380  case ICMP_ULT: return ICMP_ULE;
3381  case FCMP_OGT: return FCMP_OGE;
3382  case FCMP_OLT: return FCMP_OLE;
3383  case FCMP_UGT: return FCMP_UGE;
3384  case FCMP_ULT: return FCMP_ULE;
3385  default: return pred;
3386  }
3387 }
3388 
3390  assert(CmpInst::isUnsigned(pred) && "Call only with signed predicates!");
3391 
3392  switch (pred) {
3393  default:
3394  llvm_unreachable("Unknown predicate!");
3395  case CmpInst::ICMP_ULT:
3396  return CmpInst::ICMP_SLT;
3397  case CmpInst::ICMP_ULE:
3398  return CmpInst::ICMP_SLE;
3399  case CmpInst::ICMP_UGT:
3400  return CmpInst::ICMP_SGT;
3401  case CmpInst::ICMP_UGE:
3402  return CmpInst::ICMP_SGE;
3403  }
3404 }
3405 
3407  switch (predicate) {
3408  default: return false;
3410  case ICmpInst::ICMP_UGE: return true;
3411  }
3412 }
3413 
3414 bool CmpInst::isSigned(Predicate predicate) {
3415  switch (predicate) {
3416  default: return false;
3418  case ICmpInst::ICMP_SGE: return true;
3419  }
3420 }
3421 
3423  switch (predicate) {
3424  default: return false;
3427  case FCmpInst::FCMP_ORD: return true;
3428  }
3429 }
3430 
3432  switch (predicate) {
3433  default: return false;
3436  case FCmpInst::FCMP_UNO: return true;
3437  }
3438 }
3439 
3441  switch(predicate) {
3442  default: return false;
3443  case ICMP_EQ: case ICMP_UGE: case ICMP_ULE: case ICMP_SGE: case ICMP_SLE:
3444  case FCMP_TRUE: case FCMP_UEQ: case FCMP_UGE: case FCMP_ULE: return true;
3445  }
3446 }
3447 
3449  switch(predicate) {
3450  case ICMP_NE: case ICMP_UGT: case ICMP_ULT: case ICMP_SGT: case ICMP_SLT:
3451  case FCMP_FALSE: case FCMP_ONE: case FCMP_OGT: case FCMP_OLT: return true;
3452  default: return false;
3453  }
3454 }
3455 
3457  // If the predicates match, then we know the first condition implies the
3458  // second is true.
3459  if (Pred1 == Pred2)
3460  return true;
3461 
3462  switch (Pred1) {
3463  default:
3464  break;
3465  case ICMP_EQ:
3466  // A == B implies A >=u B, A <=u B, A >=s B, and A <=s B are true.
3467  return Pred2 == ICMP_UGE || Pred2 == ICMP_ULE || Pred2 == ICMP_SGE ||
3468  Pred2 == ICMP_SLE;
3469  case ICMP_UGT: // A >u B implies A != B and A >=u B are true.
3470  return Pred2 == ICMP_NE || Pred2 == ICMP_UGE;
3471  case ICMP_ULT: // A <u B implies A != B and A <=u B are true.
3472  return Pred2 == ICMP_NE || Pred2 == ICMP_ULE;
3473  case ICMP_SGT: // A >s B implies A != B and A >=s B are true.
3474  return Pred2 == ICMP_NE || Pred2 == ICMP_SGE;
3475  case ICMP_SLT: // A <s B implies A != B and A <=s B are true.
3476  return Pred2 == ICMP_NE || Pred2 == ICMP_SLE;
3477  }
3478  return false;
3479 }
3480 
3482  return isImpliedTrueByMatchingCmp(Pred1, getInversePredicate(Pred2));
3483 }
3484 
3485 //===----------------------------------------------------------------------===//
3486 // SwitchInst Implementation
3487 //===----------------------------------------------------------------------===//
3488 
3489 void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumReserved) {
3490  assert(Value && Default && NumReserved);
3491  ReservedSpace = NumReserved;
3493  allocHungoffUses(ReservedSpace);
3494 
3495  Op<0>() = Value;
3496  Op<1>() = Default;
3497 }
3498 
3499 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
3500 /// switch on and a default destination. The number of additional cases can
3501 /// be specified here to make memory allocation more efficient. This
3502 /// constructor can also autoinsert before another instruction.
3503 SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3504  Instruction *InsertBefore)
3505  : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3506  nullptr, 0, InsertBefore) {
3507  init(Value, Default, 2+NumCases*2);
3508 }
3509 
3510 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
3511 /// switch on and a default destination. The number of additional cases can
3512 /// be specified here to make memory allocation more efficient. This
3513 /// constructor also autoinserts at the end of the specified BasicBlock.
3514 SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3515  BasicBlock *InsertAtEnd)
3516  : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3517  nullptr, 0, InsertAtEnd) {
3518  init(Value, Default, 2+NumCases*2);
3519 }
3520 
3521 SwitchInst::SwitchInst(const SwitchInst &SI)
3522  : TerminatorInst(SI.getType(), Instruction::Switch, nullptr, 0) {
3523  init(SI.getCondition(), SI.getDefaultDest(), SI.getNumOperands());
3525  Use *OL = getOperandList();
3526  const Use *InOL = SI.getOperandList();
3527  for (unsigned i = 2, E = SI.getNumOperands(); i != E; i += 2) {
3528  OL[i] = InOL[i];
3529  OL[i+1] = InOL[i+1];
3530  }
3532 }
3533 
3534 
3535 /// addCase - Add an entry to the switch instruction...
3536 ///
3538  unsigned NewCaseIdx = getNumCases();
3539  unsigned OpNo = getNumOperands();
3540  if (OpNo+2 > ReservedSpace)
3541  growOperands(); // Get more space!
3542  // Initialize some new operands.
3543  assert(OpNo+1 < ReservedSpace && "Growing didn't work!");
3544  setNumHungOffUseOperands(OpNo+2);
3545  CaseHandle Case(this, NewCaseIdx);
3546  Case.setValue(OnVal);
3547  Case.setSuccessor(Dest);
3548 }
3549 
3550 /// removeCase - This method removes the specified case and its successor
3551 /// from the switch instruction.
3553  unsigned idx = I->getCaseIndex();
3554 
3555  assert(2 + idx*2 < getNumOperands() && "Case index out of range!!!");
3556 
3557  unsigned NumOps = getNumOperands();
3558  Use *OL = getOperandList();
3559 
3560  // Overwrite this case with the end of the list.
3561  if (2 + (idx + 1) * 2 != NumOps) {
3562  OL[2 + idx * 2] = OL[NumOps - 2];
3563  OL[2 + idx * 2 + 1] = OL[NumOps - 1];
3564  }
3565 
3566  // Nuke the last value.
3567  OL[NumOps-2].set(nullptr);
3568  OL[NumOps-2+1].set(nullptr);
3569  setNumHungOffUseOperands(NumOps-2);
3570 
3571  return CaseIt(this, idx);
3572 }
3573 
3574 /// growOperands - grow operands - This grows the operand list in response
3575 /// to a push_back style of operation. This grows the number of ops by 3 times.
3576 ///
3577 void SwitchInst::growOperands() {
3578  unsigned e = getNumOperands();
3579  unsigned NumOps = e*3;
3580 
3581  ReservedSpace = NumOps;
3582  growHungoffUses(ReservedSpace);
3583 }
3584 
3585 //===----------------------------------------------------------------------===//
3586 // IndirectBrInst Implementation
3587 //===----------------------------------------------------------------------===//
3588 
3589 void IndirectBrInst::init(Value *Address, unsigned NumDests) {
3590  assert(Address && Address->getType()->isPointerTy() &&
3591  "Address of indirectbr must be a pointer");
3592  ReservedSpace = 1+NumDests;
3594  allocHungoffUses(ReservedSpace);
3595 
3596  Op<0>() = Address;
3597 }
3598 
3599 
3600 /// growOperands - grow operands - This grows the operand list in response
3601 /// to a push_back style of operation. This grows the number of ops by 2 times.
3602 ///
3603 void IndirectBrInst::growOperands() {
3604  unsigned e = getNumOperands();
3605  unsigned NumOps = e*2;
3606 
3607  ReservedSpace = NumOps;
3608  growHungoffUses(ReservedSpace);
3609 }
3610 
3611 IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
3612  Instruction *InsertBefore)
3613 : TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr,
3614  nullptr, 0, InsertBefore) {
3615  init(Address, NumCases);
3616 }
3617 
3618 IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
3619  BasicBlock *InsertAtEnd)
3620 : TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr,
3621  nullptr, 0, InsertAtEnd) {
3622  init(Address, NumCases);
3623 }
3624 
3625 IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
3626  : TerminatorInst(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
3627  nullptr, IBI.getNumOperands()) {
3629  Use *OL = getOperandList();
3630  const Use *InOL = IBI.getOperandList();
3631  for (unsigned i = 0, E = IBI.getNumOperands(); i != E; ++i)
3632  OL[i] = InOL[i];
3634 }
3635 
3636 /// addDestination - Add a destination.
3637 ///
3639  unsigned OpNo = getNumOperands();
3640  if (OpNo+1 > ReservedSpace)
3641  growOperands(); // Get more space!
3642  // Initialize some new operands.
3643  assert(OpNo < ReservedSpace && "Growing didn't work!");
3644  setNumHungOffUseOperands(OpNo+1);
3645  getOperandList()[OpNo] = DestBB;
3646 }
3647 
3648 /// removeDestination - This method removes the specified successor from the
3649 /// indirectbr instruction.
3651  assert(idx < getNumOperands()-1 && "Successor index out of range!");
3652 
3653  unsigned NumOps = getNumOperands();
3654  Use *OL = getOperandList();
3655 
3656  // Replace this value with the last one.
3657  OL[idx+1] = OL[NumOps-1];
3658 
3659  // Nuke the last value.
3660  OL[NumOps-1].set(nullptr);
3661  setNumHungOffUseOperands(NumOps-1);
3662 }
3663 
3664 //===----------------------------------------------------------------------===//
3665 // cloneImpl() implementations
3666 //===----------------------------------------------------------------------===//
3667 
3668 // Define these methods here so vtables don't get emitted into every translation
3669 // unit that uses these classes.
3670 
3672  return new (getNumOperands()) GetElementPtrInst(*this);
3673 }
3674 
3676  return Create(getOpcode(), Op<0>(), Op<1>());
3677 }
3678 
3680  return new FCmpInst(getPredicate(), Op<0>(), Op<1>());
3681 }
3682 
3684  return new ICmpInst(getPredicate(), Op<0>(), Op<1>());
3685 }
3686 
3688  return new ExtractValueInst(*this);
3689 }
3690 
3692  return new InsertValueInst(*this);
3693 }
3694 
3696  AllocaInst *Result = new AllocaInst(getAllocatedType(),
3697  getType()->getAddressSpace(),
3698  (Value *)getOperand(0), getAlignment());
3699  Result->setUsedWithInAlloca(isUsedWithInAlloca());
3700  Result->setSwiftError(isSwiftError());
3701  return Result;
3702 }
3703 
3705  return new LoadInst(getOperand(0), Twine(), isVolatile(),
3706  getAlignment(), getOrdering(), getSyncScopeID());
3707 }
3708 
3710  return new StoreInst(getOperand(0), getOperand(1), isVolatile(),
3711  getAlignment(), getOrdering(), getSyncScopeID());
3712 
3713 }
3714 
3716  AtomicCmpXchgInst *Result =
3718  getSuccessOrdering(), getFailureOrdering(),
3719  getSyncScopeID());
3720  Result->setVolatile(isVolatile());
3721  Result->setWeak(isWeak());
3722  return Result;
3723 }
3724 
3726  AtomicRMWInst *Result =
3727  new AtomicRMWInst(getOperation(), getOperand(0), getOperand(1),
3728  getOrdering(), getSyncScopeID());
3729  Result->setVolatile(isVolatile());
3730  return Result;
3731 }
3732 
3734  return new FenceInst(getContext(), getOrdering(), getSyncScopeID());
3735 }
3736 
3738  return new TruncInst(getOperand(0), getType());
3739 }
3740 
3742  return new ZExtInst(getOperand(0), getType());
3743 }
3744 
3746  return new SExtInst(getOperand(0), getType());
3747 }
3748 
3750  return new FPTruncInst(getOperand(0), getType());
3751 }
3752 
3754  return new FPExtInst(getOperand(0), getType());
3755 }
3756 
3758  return new UIToFPInst(getOperand(0), getType());
3759 }
3760 
3762  return new SIToFPInst(getOperand(0), getType());
3763 }
3764 
3766  return new FPToUIInst(getOperand(0), getType());
3767 }
3768 
3770  return new FPToSIInst(getOperand(0), getType());
3771 }
3772 
3774  return new PtrToIntInst(getOperand(0), getType());
3775 }
3776 
3778  return new IntToPtrInst(getOperand(0), getType());
3779 }
3780 
3782  return new BitCastInst(getOperand(0), getType());
3783 }
3784 
3786  return new AddrSpaceCastInst(getOperand(0), getType());
3787 }
3788 
3790  if (hasOperandBundles()) {
3791  unsigned DescriptorBytes = getNumOperandBundles() * sizeof(BundleOpInfo);
3792  return new(getNumOperands(), DescriptorBytes) CallInst(*this);
3793  }
3794  return new(getNumOperands()) CallInst(*this);
3795 }
3796 
3799 }
3800 
3802  return new VAArgInst(getOperand(0), getType());
3803 }
3804 
3807 }
3808 
3811 }
3812 
3814  return new ShuffleVectorInst(getOperand(0), getOperand(1), getOperand(2));
3815 }
3816 
3817 PHINode *PHINode::cloneImpl() const { return new PHINode(*this); }
3818 
3820  return new LandingPadInst(*this);
3821 }
3822 
3824  return new(getNumOperands()) ReturnInst(*this);
3825 }
3826 
3828  return new(getNumOperands()) BranchInst(*this);
3829 }
3830 
3831 SwitchInst *SwitchInst::cloneImpl() const { return new SwitchInst(*this); }
3832 
3834  return new IndirectBrInst(*this);
3835 }
3836 
3838  if (hasOperandBundles()) {
3839  unsigned DescriptorBytes = getNumOperandBundles() * sizeof(BundleOpInfo);
3840  return new(getNumOperands(), DescriptorBytes) InvokeInst(*this);
3841  }
3842  return new(getNumOperands()) InvokeInst(*this);
3843 }
3844 
3845 ResumeInst *ResumeInst::cloneImpl() const { return new (1) ResumeInst(*this); }
3846 
3848  return new (getNumOperands()) CleanupReturnInst(*this);
3849 }
3850 
3852  return new (getNumOperands()) CatchReturnInst(*this);
3853 }
3854 
3856  return new CatchSwitchInst(*this);
3857 }
3858 
3860  return new (getNumOperands()) FuncletPadInst(*this);
3861 }
3862 
3864  LLVMContext &Context = getContext();
3865  return new UnreachableInst(Context);
3866 }
uint64_t CallInst * C
Return a value (possibly void), from a function.
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Definition: InstrTypes.h:1025
void push_back(const T &Elt)
Definition: SmallVector.h:213
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:875
FuncletPadInst * cloneImpl() const
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
StoreInst * cloneImpl() const
This instruction extracts a struct member or array element value from an aggregate value...
static bool IsConstantOne(Value *val)
IsConstantOne - Return true only if val is constant int 1.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVMContext & Context
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static const Value * getFNegArgument(const Value *BinOp)
Atomic ordering constants.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
BinaryOps getOpcode() const
Definition: InstrTypes.h:555
unsigned getSubclassDataFromInstruction() const
Definition: Instruction.h:695
void swapSuccessors()
Swap the successors of this branch instruction.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
IndirectBrInst * cloneImpl() const
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:142
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:262
iterator begin() const
Definition: ArrayRef.h:137
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
void setAlignment(unsigned Align)
An instruction for ordering other memory operations.
Definition: Instructions.h:440
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:514
bool isIntegerCast() const
There are several places where we need to know if a cast instruction only deals with integer source a...
BitCastInst * cloneImpl() const
Clone an identical BitCastInst.
This class represents zero extension of integer types.
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="", Instruction *InsertBefore=nullptr)
ShuffleVectorInst * cloneImpl() const
This class represents a function call, abstracting a target machine&#39;s calling convention.
This file contains the declarations for metadata subclasses.
Value * getCondition() const
unsigned less or equal
Definition: InstrTypes.h:911
unsigned less than
Definition: InstrTypes.h:910
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
float convertToFloat() const
Definition: APFloat.h:1098
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
Definition: Instructions.h:549
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:891
FenceInst * cloneImpl() const
void removeHandler(handler_iterator HI)
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:713
1 1 1 0 True if unordered or not equal
Definition: InstrTypes.h:901
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
SIToFPInst * cloneImpl() const
Clone an identical SIToFPInst.
Metadata node.
Definition: Metadata.h:862
F(f)
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
AttributeList Attrs
parameter attributes for callable
CatchSwitchInst * cloneImpl() const
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, Instruction *InsertBefore=nullptr)
This class represents a sign extension of integer types.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:503
An instruction for reading from memory.
Definition: Instructions.h:164
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:677
static bool isReverseMask(ArrayRef< int > Mask)
Return true if this shuffle mask swaps the order of elements from exactly one source vector...
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:227
InsertElementInst * cloneImpl() const
static Instruction * CreateFree(Value *Source, Instruction *InsertBefore)
Generate the IR for a call to the builtin free function.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
#define op(i)
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this store instruction.
Definition: Instructions.h:381
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:33
op_iterator op_begin()
Definition: User.h:230
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
ICmpInst * cloneImpl() const
Clone an identical ICmpInst.
void setVolatile(bool V)
Specify whether this is a volatile RMW or not.
Definition: Instructions.h:748
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op...
block_iterator block_end()
Predicate getSignedPredicate()
For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert.
Definition: InstrTypes.h:1073
bool indexValid(const Value *V) const
Definition: Type.cpp:537
bool swapOperands()
Exchange the two operands to this instruction.
AllocaInst * cloneImpl() const
SwitchInst * cloneImpl() const
1 0 0 1 True if unordered or equal
Definition: InstrTypes.h:896
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this load instruction.
Definition: Instructions.h:256
static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is false when two compares have matching operands.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition: InstrTypes.h:895
static const Value * getNegArgument(const Value *BinOp)
Helper functions to extract the unary argument of a NEG, FNEG or NOT operation implemented via Sub...
static uint32_t getAlignment(const MCSectionCOFF &Sec)
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Definition: Instructions.h:217
This class represents a conversion between pointers from one address space to another.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1580
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
bool isSigned() const
Definition: InstrTypes.h:1054
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
static Type * getIndexedType(Type *Agg, ArrayRef< unsigned > Idxs)
Returns the type of the element that would be extracted with an extractvalue instruction with the spe...
This class represents the LLVM &#39;select&#39; instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition: InstrTypes.h:983
Type * getPointerElementType() const
Definition: Type.h:373
IntToPtrInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instructions.h:109
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:592
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:638
PointerType * getType() const
Overload to return most specific pointer type.
Definition: Instructions.h:97
CatchReturnInst * cloneImpl() const
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:162
bool isStrongerThan(AtomicOrdering ao, AtomicOrdering other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice, which is based on C++&#39;s definition.
TailCallKind getTailCallKind() const
PtrToIntInst * cloneImpl() const
Clone an identical PtrToIntInst.
bool isCommutative() const
This is just a convenience that dispatches to the subclasses.
Class to represent struct types.
Definition: DerivedTypes.h:201
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:242
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
void growHungoffUses(unsigned N, bool IsPhi=false)
Grow the number of hung off uses.
Definition: User.cpp:59
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this fence instruction.
Definition: Instructions.h:470
void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
PtrToIntInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
bool isUnsigned() const
Definition: InstrTypes.h:1060
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is true when two compares have matching operands.
UIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:892
This file contains the simple types necessary to represent the attributes associated with functions a...
bundle_op_iterator bundle_op_info_begin()
Return the start of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1596
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:295
uint64_t getNumElements() const
Definition: DerivedTypes.h:359
static const unsigned MaximumAlignment
Definition: Value.h:595
block_iterator block_begin()
This class represents a cast from a pointer to an integer.
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
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.
void addHandler(BasicBlock *Dest)
Add an entry to the switch instruction...
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:201
OtherOps getOpcode() const
Get the opcode casted to the right type.
Definition: InstrTypes.h:954
Class to represent function types.
Definition: DerivedTypes.h:103
static bool isIdentityMask(ArrayRef< int > Mask)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:845
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
Definition: Type.h:241
LandingPadInst * getLandingPadInst() const
Get the landingpad instruction from the landing pad block (the unwind destination).
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:689
bool isSwiftError() const
Return true if this value is a swifterror value.
Definition: Value.cpp:734
Class to represent array types.
Definition: DerivedTypes.h:369
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: Instructions.h:121
This instruction compares its operands according to the predicate given to the constructor.
AddrSpaceCastInst * cloneImpl() const
Clone an identical AddrSpaceCastInst.
bool isVarArg() const
Definition: DerivedTypes.h:123
UnreachableInst * cloneImpl() const
LandingPadInst * cloneImpl() const
This class represents a no-op cast from one type to another.
static Instruction * createFree(Value *Source, ArrayRef< OperandBundleDef > Bundles, Instruction *InsertBefore, BasicBlock *InsertAtEnd)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:200
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
SIToFPInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:126
FPToSIInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
An instruction for storing to memory.
Definition: Instructions.h:306
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:203
This class represents a cast from floating point to signed integer.
ExtractElementInst * cloneImpl() const
Value * getParentPad() const
LoadInst * cloneImpl() const
AttributeList getAttributes() const
Return the parameter attributes for this call.
This class represents a truncation of integer types.
static const Value * getNotArgument(const Value *BinOp)
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
Definition: Casting.h:240
Value * getOperand(unsigned i) const
Definition: User.h:170
Class to represent pointers.
Definition: DerivedTypes.h:467
TruncInst * cloneImpl() const
Clone an identical TruncInst.
FPTruncInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Definition: Constants.cpp:328
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return &#39;this&#39;.
Definition: Type.h:301
User::op_iterator op_end()
Synchronized with respect to all concurrently executing threads.
Definition: LLVMContext.h:59
static Type * getIndexedTypeInternal(Type *Agg, ArrayRef< IndexTy > IdxList)
getIndexedType - Returns the type of the element that would be accessed with a gep instruction with t...
bool isVoidTy() const
Return true if this is &#39;void&#39;.
Definition: Type.h:141
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:837
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:742
ReturnInst * cloneImpl() const
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
unsigned getNumOperands() const
This instruction inserts a single (scalar) element into a VectorType value.
const Use * getOperandList() const
Definition: User.h:163
static BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:55
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
void set(Value *Val)
Definition: Value.h:670
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:421
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static bool isNoopCast(Instruction::CastOps Opcode, Type *SrcTy, Type *DstTy, const DataLayout &DL)
A no-op cast is one that can be effected without changing any bits.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
UnreachableInst(LLVMContext &C, Instruction *InsertBefore=nullptr)
Conditional or Unconditional Branch instruction.
PowerPC Reduce CR logical Operation
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this store instruction.
Definition: Instructions.h:375
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
Resume the propagation of an exception.
PHINode * cloneImpl() const
static StringRef getPredicateName(Predicate P)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
Definition: Instructions.h:126
SelectInst * cloneImpl() const
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
Indirect Branch Instruction.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:139
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:264
BasicBlock * getDefaultDest() const
User::op_iterator op_begin()
static bool isBitCastable(Type *SrcTy, Type *DestTy)
Check whether a bitcast between these types is valid.
op_iterator op_end()
Definition: User.h:232
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
UIToFPInst * cloneImpl() const
Clone an identical UIToFPInst.
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:885
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
BinaryOperator * cloneImpl() const
op_range operands()
Definition: User.h:238
0 1 1 1 True if ordered (no nans)
Definition: InstrTypes.h:894
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:495
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Definition: Type.h:182
static bool isNot(const Value *V)
static bool isZeroEltSplatMask(ArrayRef< int > Mask)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
FPExtInst * cloneImpl() const
Clone an identical FPExtInst.
AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, AtomicOrdering Ordering, SyncScope::ID SSID, Instruction *InsertBefore=nullptr)
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
void setTailCallKind(TailCallKind TCK)
CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
void setAlignment(unsigned Align)
VAArgInst * cloneImpl() const
bool hasConstantOrUndefValue() const
Whether the specified PHI node always merges together the same value, assuming undefs are equal to a ...
This class represents a cast from an integer to a pointer.
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:312
1 1 1 1 Always true (always folded)
Definition: InstrTypes.h:902
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, const Twine &NameStr="", Instruction *InsertBefor=nullptr)
void setTailCall(bool isTC=true)
BranchInst * cloneImpl() const
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1382
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
FPToUIInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
const Value * getArraySize() const
Get the number of elements allocated.
Definition: Instructions.h:93
ExtractValueInst * cloneImpl() const
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
static bool isSelectMask(ArrayRef< int > Mask)
Return true if this shuffle mask chooses elements from its source vectors without lane crossings...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
static bool isValidOperands(const Value *Vec, const Value *Idx)
Return true if an extractelement instruction can be formed with the specified operands.
static int getMaskValue(const Constant *Mask, unsigned Elt)
Return the shuffle mask value for the specified element of the mask.
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:900
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void swapOperands()
This is just a convenience that dispatches to the subclasses.
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
Definition: Value.h:91
signed greater than
Definition: InstrTypes.h:912
void setCallingConv(CallingConv::ID CC)
Value * getParentPad() const
Convenience accessors.
Definition: InstrTypes.h:1188
hexagon gen pred
static BinaryOperator * CreateNUWNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
TruncInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
const APFloat & getValueAPF() const
Definition: Constants.h:299
static Instruction * createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd, Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF, const Twine &Name)
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:889
BasicBlock * getNormalDest() const
InsertValueInst * cloneImpl() const
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value, otherwise return null.
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:224
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:329
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
unsigned getNumOperands() const
Definition: User.h:192
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
Definition: DerivedTypes.h:482
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
bool hasUnwindDest() const
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:130
AddrSpaceCastInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:899
Module.h This file contains the declarations for the Module class.
static bool isCastable(Type *SrcTy, Type *DestTy)
Check whether it is valid to call getCastOpcode for these types.
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore)
iterator end() const
Definition: ArrayRef.h:138
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition: Type.h:255
signed less than
Definition: InstrTypes.h:914
BasicBlock * getUnwindDest() const
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID, Instruction *InsertBefore=nullptr)
This class represents a cast from floating point to unsigned integer.
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
bundle_op_iterator bundle_op_info_end()
Return the end of the list of BundleOpInfo instances associated with this OperandBundleUser.
Definition: InstrTypes.h:1614
static bool isTransposeMask(ArrayRef< int > Mask)
Return true if this shuffle mask is a transpose mask.
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine how a pair of casts can be eliminated, if they can be at all.
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:611
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
SExtInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
IntToPtrInst * cloneImpl() const
Clone an identical IntToPtrInst.
bool isCommutative() const
Return true if the instruction is commutative:
Definition: Instruction.h:457
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Definition: InstrTypes.h:964
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
Definition: InstrTypes.h:1014
CleanupReturnInst * cloneImpl() const
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:531
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:924
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:462
bool isTrueWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:1079
signed less or equal
Definition: InstrTypes.h:915
Class to represent vector types.
Definition: DerivedTypes.h:393
void setVolatile(bool V)
Specify whether this is a volatile store or not.
Definition: Instructions.h:342
static bool isNeg(const Value *V)
Check if the given Value is a NEG, FNeg, or NOT instruction.
Class for arbitrary precision integers.
Definition: APInt.h:69
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty, const Twine &Name, Instruction *InsertBefore)
bool isFalseWhenEqual() const
This is just a convenience.
Definition: InstrTypes.h:1085
void push_back(pointer val)
Definition: ilist.h:313
static bool isWeak(const MCSymbolELF &Sym)
bool isCleanup() const
Return &#39;true&#39; if this landingpad instruction is a cleanup.
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.
void setWeak(bool IsWeak)
Definition: Instructions.h:559
FunctionType * FTy
ZExtInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, Value *RHS, const Twine &Name="", Instruction *InsertBefore=nullptr)
BitCastInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
AtomicCmpXchgInst * cloneImpl() const
static bool isConstantAllOnes(const Value *V)
Common super class of ArrayType, StructType and VectorType.
Definition: DerivedTypes.h:162
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:346
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
Definition: Instructions.h:137
static Instruction * CreateMalloc(Instruction *InsertBefore, Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize=nullptr, Function *MallocF=nullptr, const Twine &Name="")
Generate the IR for a call to malloc:
GetElementPtrInst * cloneImpl() const
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&#39;s ...
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:959
bool isVolatile() const
Return true if this is a store to a volatile memory location.
Definition: Instructions.h:339
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:290
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:226
static Type * getIndexedType(Type *Ty, ArrayRef< Value *> IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
ZExtInst * cloneImpl() const
Clone an identical ZExtInst.
unsigned greater or equal
Definition: InstrTypes.h:909
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
bool isTokenTy() const
Return true if this is &#39;token&#39;.
Definition: Type.h:194
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this fence instruction.
Definition: Instructions.h:481
float getFPAccuracy() const
Get the maximum error permitted by this operation in ULPs.
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
void setValue(ConstantInt *V)
Sets the new value for current case.
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
#define I(x, y, z)
Definition: MD5.cpp:58
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
Definition: Constants.cpp:738
This class represents a cast unsigned integer to floating point.
FCmpInst * cloneImpl() const
Clone an identical FCmpInst.
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:893
AtomicRMWInst * cloneImpl() const
FPToSIInst * cloneImpl() const
Clone an identical FPToSIInst.
Compile-time customization of User operands.
Definition: User.h:43
void setSyncScopeID(SyncScope::ID SSID)
Sets the synchronization scope ID of this cmpxchg instruction.
Definition: Instructions.h:599
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
This instruction extracts a single (scalar) element from a VectorType value.
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:897
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:351
Type * getType() const
Return the type of the instruction that generated this call site.
Definition: CallSite.h:264
void addDestination(BasicBlock *Dest)
Add a destination.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:185
Multiway switch.
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a SExt or BitCast cast instruction.
This class represents a cast from signed integer to floating point.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SExtInst * cloneImpl() const
Clone an identical SExtInst.
const BasicBlock & front() const
Definition: Function.h:649
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
SmallVector< int, 16 > getShuffleMask() const
This class represents a truncation of floating point types.
BasicBlock * getUnwindDest() const
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:888
LLVM Value Representation.
Definition: Value.h:73
void setAlignment(unsigned Align)
bool isEquality() const
This is just a convenience that dispatches to the subclasses.
FPExtInst(Value *S, Type *Ty, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructor with insert-before-instruction semantics.
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:898
static bool isSingleSourceMask(ArrayRef< int > Mask)
Return true if this shuffle mask chooses elements from exactly one source vector. ...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
void allocHungoffUses(unsigned N, bool IsPhi=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
Definition: User.cpp:40
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
static Value * getAISize(LLVMContext &Context, Value *Amt)
ResumeInst * cloneImpl() const
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore)
FPTruncInst * cloneImpl() const
Clone an identical FPTruncInst.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
Invoke instruction.
void setSuccessor(BasicBlock *S)
Sets the new successor for current case.
unsigned greater than
Definition: InstrTypes.h:908
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition: InstrTypes.h:999
Use & Op()
Definition: User.h:134
static bool isVolatile(Instruction *Inst)
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
void setNumHungOffUseOperands(unsigned NumOps)
Subclasses with hung off uses need to manage the operand count themselves.
Definition: User.h:216
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2199
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
This class represents an extension of floating point types.
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:960
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:890
void setVolatile(bool V)
Specify whether this is a volatile load or not.
Definition: Instructions.h:220
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
friend class Instruction
Definition: Instructions.h:445
VectorType * getType() const
Overload to return most specific vector type.
void removeDestination(unsigned i)
This method removes the specified successor from the indirectbr instruction.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
CallInst * cloneImpl() const