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

Generated by: LCOV version 1.13