LCOV - code coverage report
Current view: top level - lib/IR - Instructions.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 1329 1595 83.3 %
Date: 2018-10-20 13:21:21 Functions: 267 314 85.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13