diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -174,6 +174,13 @@ return static_cast(Instruction::getOpcode()); } + // Returns true if the UnaryOperator I has same special properties as the + // current instruction. Any addition of operands in UnaryOperator class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because UnaryOperator has no + // special properties to compare. + bool hasSamePropertiesAs(const UnaryOperator *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->isUnaryOp(); @@ -403,6 +410,13 @@ /// bool swapOperands(); + // Returns true if the BinaryOperator I has same special properties as the + // current instruction. Any addition of operands in BinaryOperator class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because BinaryOperator has no + // special properties to compare. + bool hasSamePropertiesAs(const BinaryOperator *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->isBinaryOp(); diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -142,6 +142,16 @@ (V ? 64 : 0)); } + // Returns true if the AllocaInst AI has same special properties as the + // current instruction. Any addition of operands in AllocaInst class need to + // be reflected here so that the IR comparators stay in sync with the changes + // to IR. + bool hasSamePropertiesAs(const AllocaInst *AI, + bool IgnoreAlignment = false) const { + return getAllocatedType() == AI->getAllocatedType() && + (getAlignment() == AI->getAlignment() || IgnoreAlignment); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::Alloca); @@ -262,6 +272,18 @@ return getPointerOperandType()->getPointerAddressSpace(); } + // Returns true if the LoadInst LI has same special properties as the current + // instruction. Any addition of operands in LoadInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const LoadInst *LI, + bool IgnoreAlignment = false) const { + return isVolatile() == LI->isVolatile() && + (getAlignment() == LI->getAlignment() || IgnoreAlignment) && + getOrdering() == LI->getOrdering() && + getSyncScopeID() == LI->getSyncScopeID(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Load; @@ -391,6 +413,18 @@ return getPointerOperandType()->getPointerAddressSpace(); } + // Returns true if the StoreInst SI has same special properties as the current + // instruction. Any addition of operands in StoreInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const StoreInst *SI, + bool IgnoreAlignment = false) const { + return isVolatile() == SI->isVolatile() && + (getAlignment() == SI->getAlignment() || IgnoreAlignment) && + getOrdering() == SI->getOrdering() && + getSyncScopeID() == SI->getSyncScopeID(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Store; @@ -468,6 +502,15 @@ this->SSID = SSID; } + // Returns true if the FenceInst FI has same special properties as the current + // instruction. Any addition of operands in FenceInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const FenceInst *FI) const { + return getOrdering() == FI->getOrdering() && + getSyncScopeID() == FI->getSyncScopeID(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Fence; @@ -626,6 +669,17 @@ } } + // Returns true if the AtomicCmpXchgInst I has same special properties as the + // current instruction. Any addition of operands in AtomicCmpXchgInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const AtomicCmpXchgInst *I) const { + return isVolatile() == I->isVolatile() && isWeak() == I->isWeak() && + getSuccessOrdering() == I->getSuccessOrdering() && + getFailureOrdering() == I->getFailureOrdering() && + getSyncScopeID() == I->getSyncScopeID(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::AtomicCmpXchg; @@ -798,6 +852,17 @@ return isFPOperation(getOperation()); } + // Returns true if the AtomicRMWInst I has same special properties as the + // current instruction. Any addition of operands in AtomicRMWInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const AtomicRMWInst *I) const { + return getOperation() == I->getOperation() && + isVolatile() == I->isVolatile() && + getOrdering() == I->getOrdering() && + getSyncScopeID() == I->getSyncScopeID(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::AtomicRMW; @@ -1065,6 +1130,13 @@ /// the base GEP pointer. bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const; + // Returns true if the GetElementPtrInst I has same special properties as the + // current instruction. Any addition of operands in GetElementPtrInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because GetElementPtr has no + // special properties to compare. + bool hasSamePropertiesAs(const GetElementPtrInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::GetElementPtr); @@ -1242,6 +1314,15 @@ Op<0>().swap(Op<1>()); } + // Returns true if the ICmpInst I has same special properties as the current + // instruction. Any addition of operands in ICmpInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const ICmpInst *I) const { + return getPredicate() == I->getPredicate(); + ; + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::ICmp; @@ -1350,6 +1431,14 @@ Op<0>().swap(Op<1>()); } + // Returns true if the FCmpInst I has same special properties as the current + // instruction. Any addition of operands in FCmpInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const FCmpInst *I) const { + return getPredicate() == I->getPredicate(); + } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::FCmp; @@ -1581,6 +1670,17 @@ addAttribute(AttributeList::FunctionIndex, Attribute::ReturnsTwice); } + // Returns true if the CallInst I has same special properties as the current + // instruction. Any addition of operands in CallInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const CallInst *I) const { + return isTailCall() == I->isTailCall() && + getCallingConv() == I->getCallingConv() && + getAttributes() == I->getAttributes() && + hasIdenticalOperandBundleSchema(*I); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Call; @@ -1701,6 +1801,13 @@ return static_cast(Instruction::getOpcode()); } + // Returns true if the SelectInst I has same special properties as the current + // instruction. Any addition of operands in SelectInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because SelectInst has no special properties + // to compare. + bool hasSamePropertiesAs(const SelectInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Select; @@ -1747,6 +1854,13 @@ const Value *getPointerOperand() const { return getOperand(0); } static unsigned getPointerOperandIndex() { return 0U; } + // Returns true if the VAArgInst I has same special properties as the current + // instruction. Any addition of operands in VAArgInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because VAArgInst has no special properties to + // compare. + bool hasSamePropertiesAs(const VAArgInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == VAArg; @@ -1801,6 +1915,13 @@ return cast(getVectorOperand()->getType()); } + // Returns true if the ExtractElementInst I has same special properties as the + // current instruction. Any addition of operands in ExtractElementInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because ExtractElementInst has no + // special properties to compare. + bool hasSamePropertiesAs(const ExtractElementInst *I) const { return true; } + /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -1864,6 +1985,13 @@ return cast(Instruction::getType()); } + // Returns true if the InsertElementInst I has same special properties as the + // current instruction. Any addition of operands in InsertElementInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because InsertElementInst has no + // special properties to compare. + bool hasSamePropertiesAs(const InsertElementInst *I) const { return true; } + /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -2197,6 +2325,14 @@ } } + // Returns true if the ShuffleVectorInst I has same special properties as the + // current instruction. Any addition of operands in ShuffleVectorInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const ShuffleVectorInst *I) const { + return getShuffleMask() == I->getShuffleMask(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::ShuffleVector; @@ -2296,6 +2432,14 @@ return true; } + // Returns true if the ExtractValueInst I has same special properties as the + // current instruction. Any addition of operands in ExtractValueInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const ExtractValueInst *I) const { + return getIndices() == I->getIndices(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::ExtractValue; @@ -2427,6 +2571,14 @@ return true; } + // Returns true if the InsertValueInst I has same special properties as the + // current instruction. Any addition of operands in InsertValueInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const InsertValueInst *I) const { + return getIndices() == I->getIndices(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::InsertValue; @@ -2684,6 +2836,13 @@ /// non-undef value. bool hasConstantOrUndefValue() const; + // Returns true if the PHINode I has same special properties as the current + // instruction. Any addition of operands in PHINode class need to be reflected + // here so that the IR comparators stay in sync with the changes to IR. + // Currently returning true because PHINode has no special properties to + // compare. + bool hasSamePropertiesAs(const PHINode *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::PHI; @@ -2793,6 +2952,15 @@ /// number of clauses. void reserveClauses(unsigned Size) { growOperands(Size); } + // Returns true if the LandingPadInst I has same special properties as the + // current instruction. Any addition of operands in LandingPadInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const LandingPadInst *I) const { + return isCleanup() == I->isCleanup(); + ; + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::LandingPad; @@ -2867,6 +3035,13 @@ unsigned getNumSuccessors() const { return 0; } + // Returns true if the ReturnInst I has same special properties as the current + // instruction. Any addition of operands in ReturnInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because ReturnInst has no special properties + // to compare. + bool hasSamePropertiesAs(const ReturnInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::Ret); @@ -3020,6 +3195,13 @@ const_succ_op_iterator(value_op_end())); } + // Returns true if the BranchInst I has same special properties as the current + // instruction. Any addition of operands in BranchInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because BranchInst has no special properties + // to compare. + bool hasSamePropertiesAs(const BranchInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::Br); @@ -3377,6 +3559,13 @@ setOperand(idx * 2 + 1, NewSucc); } + // Returns true if the SwitchInst I has same special properties as the current + // instruction. Any addition of operands in SwitchInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because SwitchInst has no special properties + // to compare. + bool hasSamePropertiesAs(const SwitchInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Switch; @@ -3557,6 +3746,13 @@ const_succ_op_iterator(value_op_end())); } + // Returns true if the IndirectBrInst I has same special properties as the + // current instruction. Any addition of operands in IndirectBrInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because IndirectBrInst has no + // special properties to compare. + bool hasSamePropertiesAs(const IndirectBrInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::IndirectBr; @@ -3743,6 +3939,16 @@ unsigned getNumSuccessors() const { return 2; } + // Returns true if the InvokeInst I has same special properties as the current + // instruction. Any addition of operands in InvokeInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const InvokeInst *I) const { + return getCallingConv() == I->getCallingConv() && + getAttributes() == I->getAttributes() && + hasIdenticalOperandBundleSchema(*I); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::Invoke); @@ -3983,6 +4189,16 @@ unsigned getNumSuccessors() const { return getNumIndirectDests() + 1; } + // Returns true if the CallBrInst I has same special properties as the current + // instruction. Any addition of operands in CallBrInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. + bool hasSamePropertiesAs(const CallBrInst *I) const { + return getCallingConv() == I->getCallingConv() && + getAttributes() == I->getAttributes() && + hasIdenticalOperandBundleSchema(*I); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::CallBr); @@ -4058,6 +4274,13 @@ unsigned getNumSuccessors() const { return 0; } + // Returns true if the ResumeInst I has same special properties as the current + // instruction. Any addition of operands in ResumeInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because ResumeInst has no special properties + // to compare. + bool hasSamePropertiesAs(const ResumeInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Resume; @@ -4243,6 +4466,14 @@ setOperand(Idx + 1, NewSucc); } + // Returns true if the CatchSwitchInst I has same special properties as the + // current instruction. Any addition of operands in CatchSwitchInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const CatchSwitchInst *I) const { + return unwindsToCaller() == I->unwindsToCaller(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::CatchSwitch; @@ -4289,6 +4520,13 @@ CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd); } + // Returns true if the CleanupPadInst I has same special properties as the + // current instruction. Any addition of operands in CleanupPadInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because CleanupPadInst has no + // special properties to compare. + bool hasSamePropertiesAs(const CleanupPadInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::CleanupPad; @@ -4339,6 +4577,15 @@ Op<-1>() = CatchSwitch; } + // Returns true if the CatchPadInst I has same special properties as the + // current instruction. Any addition of operands in CatchPadInst class need to + // be reflected here so that the IR comparators stay in sync with the changes + // to IR. + bool hasSamePropertiesAs(const CatchPadInst *I) const { + const CatchSwitchInst *CSI = getCatchSwitch(); + return CSI->hasSamePropertiesAs(I->getCatchSwitch()); + } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::CatchPad; @@ -4403,6 +4650,13 @@ return getCatchPad()->getCatchSwitch()->getParentPad(); } + // Returns true if the CatchReturnInst I has same special properties as the + // current instruction. Any addition of operands in CatchReturnInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because CatchReturnInst has no + // special properties to compare. + bool hasSamePropertiesAs(const CatchReturnInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::CatchRet); @@ -4497,6 +4751,14 @@ Op<1>() = NewDest; } + // Returns true if the CleanupReturnInst I has same special properties as the + // current instruction. Any addition of operands in CleanupReturnInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. + bool hasSamePropertiesAs(const CleanupReturnInst *I) const { + return unwindsToCaller() == I->unwindsToCaller(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return (I->getOpcode() == Instruction::CleanupRet); @@ -4556,6 +4818,13 @@ unsigned getNumSuccessors() const { return 0; } + // Returns true if the UnreachableInst I has same special properties as the + // current instruction. Any addition of operands in UnreachableInst class need + // to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because UnreachableInst has no + // special properties to compare. + bool hasSamePropertiesAs(const UnreachableInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Instruction::Unreachable; @@ -4604,6 +4873,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the TruncInst I has same special properties as the current + // instruction. Any addition of operands in TruncInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because TruncInst has no special properties to + // compare. + bool hasSamePropertiesAs(const TruncInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == Trunc; @@ -4643,6 +4919,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the ZExtInst I has same special properties as the current + // instruction. Any addition of operands in ZExtInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because ZExtInst has no special properties to + // compare. + bool hasSamePropertiesAs(const ZExtInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == ZExt; @@ -4682,6 +4965,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the SExtInst I has same special properties as the current + // instruction. Any addition of operands in SExtInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because SExtInst has no special properties to + // compare. + bool hasSamePropertiesAs(const SExtInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == SExt; @@ -4721,6 +5011,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the FPTruncInst I has same special properties as the + // current instruction. Any addition of operands in FPTruncInst class need to + // be reflected here so that the IR comparators stay in sync with the changes + // to IR. Currently returning true because FPTruncInst has no special + // properties to compare. + bool hasSamePropertiesAs(const FPTruncInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == FPTrunc; @@ -4760,6 +5057,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the FPExtInst I has same special properties as the current + // instruction. Any addition of operands in FPExtInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because FPExtInst has no special properties to + // compare. + bool hasSamePropertiesAs(const FPExtInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == FPExt; @@ -4799,6 +5103,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the UIToFPInst I has same special properties as the current + // instruction. Any addition of operands in UIToFPInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because UIToFPInst has no special properties + // to compare. + bool hasSamePropertiesAs(const UIToFPInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == UIToFP; @@ -4838,6 +5149,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the SIToFPInst I has same special properties as the current + // instruction. Any addition of operands in SIToFPInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because SIToFPInst has no special properties + // to compare. + bool hasSamePropertiesAs(const SIToFPInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == SIToFP; @@ -4877,6 +5195,13 @@ BasicBlock *InsertAtEnd ///< Where to insert the new instruction ); + // Returns true if the FPToUIInst I has same special properties as the current + // instruction. Any addition of operands in FPToUIInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because FPToUIInst has no special properties + // to compare. + bool hasSamePropertiesAs(const FPToUIInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == FPToUI; @@ -4916,6 +5241,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the FPToSIInst I has same special properties as the current + // instruction. Any addition of operands in FPToSIInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because FPToSIInst has no special properties + // to compare. + bool hasSamePropertiesAs(const FPToSIInst *I) const { return true; } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == FPToSI; @@ -4959,6 +5291,13 @@ return getType()->getPointerAddressSpace(); } + // Returns true if the IntToPtrInst I has same special properties as the + // current instruction. Any addition of operands in IntToPtrInst class need to + // be reflected here so that the IR comparators stay in sync with the changes + // to IR. Currently returning true because IntToPtrInst has no special + // properties to compare. + bool hasSamePropertiesAs(const IntToPtrInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == IntToPtr; @@ -5010,6 +5349,13 @@ return getPointerOperand()->getType()->getPointerAddressSpace(); } + // Returns true if the PtrToIntInst I has same special properties as the + // current instruction. Any addition of operands in PtrToIntInst class need to + // be reflected here so that the IR comparators stay in sync with the changes + // to IR. Currently returning true because PtrToIntInst has no special + // properties to compare. + bool hasSamePropertiesAs(const PtrToIntInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == PtrToInt; @@ -5049,6 +5395,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the BitCastInst I has same special properties as the + // current instruction. Any addition of operands in BitCastInst class need to + // be reflected here so that the IR comparators stay in sync with the changes + // to IR. Currently returning true because BitCastInst has no special + // properties to compare. + bool hasSamePropertiesAs(const BitCastInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == BitCast; @@ -5089,6 +5442,13 @@ BasicBlock *InsertAtEnd ///< The block to insert the instruction into ); + // Returns true if the AddrSpaceCastInst I has same special properties as the + // current instruction. Any addition of operands in AddrSpaceCastInst class + // need to be reflected here so that the IR comparators stay in sync with the + // changes to IR. Currently returning true because AddrSpaceCastInst has no + // special properties to compare. + bool hasSamePropertiesAs(const AddrSpaceCastInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Instruction *I) { return I->getOpcode() == AddrSpaceCast; @@ -5189,6 +5549,13 @@ Instruction *InsertBefore = nullptr); FreezeInst(Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd); + // Returns true if the FreezeInst I has same special properties as the current + // instruction. Any addition of operands in FreezeInst class need to be + // reflected here so that the IR comparators stay in sync with the changes to + // IR. Currently returning true because FreezeInst has no special properties + // to compare. + bool hasSamePropertiesAs(const FreezeInst *I) const { return true; } + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Instruction *I) { return I->getOpcode() == Freeze; diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -408,64 +408,223 @@ bool IgnoreAlignment = false) { assert(I1->getOpcode() == I2->getOpcode() && "Can not compare special state of different instructions"); + assert(I1->getNumOperands() == I2->getNumOperands() && + "Can not compare special state of instructions with different number " + "of operands"); - if (const AllocaInst *AI = dyn_cast(I1)) - return AI->getAllocatedType() == cast(I2)->getAllocatedType() && - (AI->getAlignment() == cast(I2)->getAlignment() || - IgnoreAlignment); - if (const LoadInst *LI = dyn_cast(I1)) - return LI->isVolatile() == cast(I2)->isVolatile() && - (LI->getAlignment() == cast(I2)->getAlignment() || - IgnoreAlignment) && - LI->getOrdering() == cast(I2)->getOrdering() && - LI->getSyncScopeID() == cast(I2)->getSyncScopeID(); - if (const StoreInst *SI = dyn_cast(I1)) - return SI->isVolatile() == cast(I2)->isVolatile() && - (SI->getAlignment() == cast(I2)->getAlignment() || - IgnoreAlignment) && - SI->getOrdering() == cast(I2)->getOrdering() && - SI->getSyncScopeID() == cast(I2)->getSyncScopeID(); - if (const CmpInst *CI = dyn_cast(I1)) - return CI->getPredicate() == cast(I2)->getPredicate(); - if (const CallInst *CI = dyn_cast(I1)) - return CI->isTailCall() == cast(I2)->isTailCall() && - CI->getCallingConv() == cast(I2)->getCallingConv() && - CI->getAttributes() == cast(I2)->getAttributes() && - CI->hasIdenticalOperandBundleSchema(*cast(I2)); - if (const InvokeInst *CI = dyn_cast(I1)) - return CI->getCallingConv() == cast(I2)->getCallingConv() && - CI->getAttributes() == cast(I2)->getAttributes() && - CI->hasIdenticalOperandBundleSchema(*cast(I2)); - if (const CallBrInst *CI = dyn_cast(I1)) - return CI->getCallingConv() == cast(I2)->getCallingConv() && - CI->getAttributes() == cast(I2)->getAttributes() && - CI->hasIdenticalOperandBundleSchema(*cast(I2)); - if (const InsertValueInst *IVI = dyn_cast(I1)) - return IVI->getIndices() == cast(I2)->getIndices(); - if (const ExtractValueInst *EVI = dyn_cast(I1)) - return EVI->getIndices() == cast(I2)->getIndices(); - if (const FenceInst *FI = dyn_cast(I1)) - return FI->getOrdering() == cast(I2)->getOrdering() && - FI->getSyncScopeID() == cast(I2)->getSyncScopeID(); - if (const AtomicCmpXchgInst *CXI = dyn_cast(I1)) - return CXI->isVolatile() == cast(I2)->isVolatile() && - CXI->isWeak() == cast(I2)->isWeak() && - CXI->getSuccessOrdering() == - cast(I2)->getSuccessOrdering() && - CXI->getFailureOrdering() == - cast(I2)->getFailureOrdering() && - CXI->getSyncScopeID() == - cast(I2)->getSyncScopeID(); - if (const AtomicRMWInst *RMWI = dyn_cast(I1)) - return RMWI->getOperation() == cast(I2)->getOperation() && - RMWI->isVolatile() == cast(I2)->isVolatile() && - RMWI->getOrdering() == cast(I2)->getOrdering() && - RMWI->getSyncScopeID() == cast(I2)->getSyncScopeID(); - if (const ShuffleVectorInst *SVI = dyn_cast(I1)) - return SVI->getShuffleMask() == - cast(I2)->getShuffleMask(); - - return true; + switch (I1->getOpcode()) { + default: + llvm_unreachable("Instructions to compare are unknown"); + case Instruction::Alloca: { + const AllocaInst *AI = cast(I1); + return AI->hasSamePropertiesAs(cast(I2), IgnoreAlignment); + } + case Instruction::Load: { + const LoadInst *LI = cast(I1); + return LI->hasSamePropertiesAs(cast(I2), IgnoreAlignment); + } + case Instruction::Store: { + const StoreInst *SI = cast(I1); + return SI->hasSamePropertiesAs(cast(I2), IgnoreAlignment); + } + case Instruction::ICmp: { + const ICmpInst *IC = cast(I1); + return IC->hasSamePropertiesAs(cast(I2)); + } + case Instruction::FCmp: { + const FCmpInst *FC = cast(I1); + return FC->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Call: { + const CallInst *CI = cast(I1); + return CI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Invoke: { + const InvokeInst *II = cast(I1); + return II->hasSamePropertiesAs(cast(I2)); + } + case Instruction::CallBr: { + const CallBrInst *CBI = cast(I1); + return CBI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::InsertValue: { + const InsertValueInst *IVI = cast(I1); + return IVI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::ExtractValue: { + const ExtractValueInst *EVI = cast(I1); + return EVI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Fence: { + const FenceInst *FI = cast(I1); + return FI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::AtomicCmpXchg: { + const AtomicCmpXchgInst *CXI = cast(I1); + return CXI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::AtomicRMW: { + const AtomicRMWInst *RMWI = cast(I1); + return RMWI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::ShuffleVector: { + const ShuffleVectorInst *SVI = cast(I1); + return SVI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Ret: { + const ReturnInst *RI = cast(I1); + return RI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Br: { + const BranchInst *BI = cast(I1); + return BI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Switch: { + const SwitchInst *SI = cast(I1); + return SI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::IndirectBr: { + const IndirectBrInst *IBI = cast(I1); + return IBI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Resume: { + const ResumeInst *RI = cast(I1); + return RI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::CatchSwitch: { + const CatchSwitchInst *CSI = cast(I1); + return CSI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::CatchRet: { + const CatchReturnInst *CRI = cast(I1); + return CRI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::CleanupRet: { + const CleanupReturnInst *CRI = cast(I1); + return CRI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Unreachable: { + const UnreachableInst *UI = cast(I1); + return UI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::FNeg: { + const UnaryOperator *UOP = cast(I1); + return UOP->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Add: + case Instruction::FAdd: + case Instruction::Sub: + case Instruction::FSub: + case Instruction::Mul: + case Instruction::FMul: + case Instruction::UDiv: + case Instruction::SDiv: + case Instruction::FDiv: + case Instruction::URem: + case Instruction::SRem: + case Instruction::FRem: + case Instruction::Shl: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::And: + case Instruction::Or: + case Instruction::Xor: { + const BinaryOperator *BOP = cast(I1); + return BOP->hasSamePropertiesAs(cast(I2)); + } + case Instruction::GetElementPtr: { + const GetElementPtrInst *GEP = cast(I1); + return GEP->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Trunc: { + const TruncInst *TI = cast(I1); + return TI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::ZExt: { + const ZExtInst *ZEI = cast(I1); + return ZEI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::SExt: { + const SExtInst *SEI = cast(I1); + return SEI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::FPToUI: { + const FPToUIInst *FUI = cast(I1); + return FUI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::FPToSI: { + const FPToSIInst *FSI = cast(I1); + return FSI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::UIToFP: { + const UIToFPInst *UFI = cast(I1); + return UFI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::SIToFP: { + const SIToFPInst *SFI = cast(I1); + return SFI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::FPTrunc: { + const FPTruncInst *FTI = cast(I1); + return FTI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::FPExt: { + const FPExtInst *FEI = cast(I1); + return FEI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::PtrToInt: { + const PtrToIntInst *PII = cast(I1); + return PII->hasSamePropertiesAs(cast(I2)); + } + case Instruction::IntToPtr: { + const IntToPtrInst *IPI = cast(I1); + return IPI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::BitCast: { + const BitCastInst *BI = cast(I1); + return BI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::AddrSpaceCast: { + const AddrSpaceCastInst *ACI = cast(I1); + return ACI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::CleanupPad: { + const CleanupPadInst *CPI = cast(I1); + return CPI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::CatchPad: { + const CatchPadInst *CPI = cast(I1); + return CPI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::PHI: { + const PHINode *PI = cast(I1); + return PI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Select: { + const SelectInst *SI = cast(I1); + return SI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::VAArg: { + const VAArgInst *VAI = cast(I1); + return VAI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::ExtractElement: { + const ExtractElementInst *EEI = cast(I1); + return EEI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::InsertElement: { + const InsertElementInst *IEI = cast(I1); + return IEI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::LandingPad: { + const LandingPadInst *LPI = cast(I1); + return LPI->hasSamePropertiesAs(cast(I2)); + } + case Instruction::Freeze: { + const FreezeInst *FI = cast(I1); + return FI->hasSamePropertiesAs(cast(I2)); + } + } } bool Instruction::isIdenticalTo(const Instruction *I) const {