diff options
87 files changed, 7711 insertions, 6238 deletions
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index 6f775515fb..96aeb6340a 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -58,7 +58,7 @@ static Function *CreateFibFunction(Module *M) { BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); // Create the "if (arg < 2) goto exitbb" - Value *CondInst = BinaryOperator::createSetLE(ArgX, Two, "cond", BB); + Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); new BranchInst(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index dfda126378..7f2e1bfc10 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -83,7 +83,7 @@ static Function *CreateFibFunction(Module *M) BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); // Create the "if (arg < 2) goto exitbb" - Value *CondInst = BinaryOperator::createSetLE(ArgX, Two, "cond", BB); + Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); new BranchInst(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 diff --git a/include/llvm/Analysis/ScalarEvolutionExpressions.h b/include/llvm/Analysis/ScalarEvolutionExpressions.h index c261dfc8e5..b9bf93b8c7 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -426,8 +426,10 @@ namespace llvm { /// looking at this is that it returns the first iteration number where the /// value is not in the condition, thus computing the exit count. If the /// iteration count can't be computed, an instance of SCEVCouldNotCompute is - /// returned. - SCEVHandle getNumIterationsInRange(ConstantRange Range) const; + /// returned. The isSigned parameter indicates whether the ConstantRange + /// should be treated as signed or unsigned. + SCEVHandle getNumIterationsInRange(ConstantRange Range, + bool isSigned) const; SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, const SCEVHandle &Conc) const; diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 2a0c62423d..a6050f44a6 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -496,8 +496,8 @@ protected: // ConstantExprs in intermediate forms. static Constant *getTy(const Type *Ty, unsigned Opcode, Constant *C1, Constant *C2); - static Constant *getCompareTy(unsigned Opcode, unsigned short pred, - Constant *C1, Constant *C2); + static Constant *getCompareTy(unsigned short pred, Constant *C1, + Constant *C2); static Constant *getShiftTy(const Type *Ty, unsigned Opcode, Constant *C1, Constant *C2); static Constant *getSelectTy(const Type *Ty, @@ -604,8 +604,7 @@ public: static Constant *get(unsigned Opcode, Constant *C1, Constant *C2); /// @brief Return an ICmp or FCmp comparison operator constant expression. - static Constant *getCompare(unsigned Opcode, unsigned short pred, - Constant *C1, Constant *C2); + static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2); /// ConstantExpr::get* - Return some common constants without having to /// specify the full Instruction::OPCODE identifier. @@ -624,12 +623,6 @@ public: static Constant *getAnd(Constant *C1, Constant *C2); static Constant *getOr(Constant *C1, Constant *C2); static Constant *getXor(Constant *C1, Constant *C2); - static Constant *getSetEQ(Constant *C1, Constant *C2); - static Constant *getSetNE(Constant *C1, Constant *C2); - static Constant *getSetLT(Constant *C1, Constant *C2); - static Constant *getSetGT(Constant *C1, Constant *C2); - static Constant *getSetLE(Constant *C1, Constant *C2); - static Constant *getSetGE(Constant *C1, Constant *C2); static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS); static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS); static Constant *getShl(Constant *C1, Constant *C2); diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index b3ec55921f..152f4773eb 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -543,6 +543,20 @@ public: /// @brief Determine if this is an equals/not equals predicate. bool isEquality(); + /// @returns true if the predicate is unsigned, false otherwise. + /// @brief Determine if the predicate is an unsigned operation. + static bool isUnsigned(unsigned short predicate); + + /// @returns true if the predicate is signed, false otherwise. + /// @brief Determine if the predicate is an signed operation. + static bool isSigned(unsigned short predicate); + + /// @brief Determine if the predicate is an ordered operation. + static bool isOrdered(unsigned short predicate); + + /// @brief Determine if the predicate is an unordered operation. + static bool isUnordered(unsigned short predicate); + /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const CmpInst *) { return true; } static inline bool classof(const Instruction *I) { diff --git a/include/llvm/Instruction.def b/include/llvm/Instruction.def index db41734fa4..c33c4483be 100644 --- a/include/llvm/Instruction.def +++ b/include/llvm/Instruction.def @@ -118,61 +118,53 @@ HANDLE_BINARY_INST(15, FRem , BinaryOperator) HANDLE_BINARY_INST(16, And , BinaryOperator) HANDLE_BINARY_INST(17, Or , BinaryOperator) HANDLE_BINARY_INST(18, Xor , BinaryOperator) - -// Binary comparison operators... -HANDLE_BINARY_INST(19, SetEQ , SetCondInst) -HANDLE_BINARY_INST(20, SetNE , SetCondInst) -HANDLE_BINARY_INST(21, SetLE , SetCondInst) -HANDLE_BINARY_INST(22, SetGE , SetCondInst) -HANDLE_BINARY_INST(23, SetLT , SetCondInst) -HANDLE_BINARY_INST(24, SetGT , SetCondInst) - LAST_BINARY_INST(24) + LAST_BINARY_INST(18) // Memory operators... - FIRST_MEMORY_INST(25) -HANDLE_MEMORY_INST(25, Malloc, MallocInst) // Heap management instructions -HANDLE_MEMORY_INST(26, Free , FreeInst ) -HANDLE_MEMORY_INST(27, Alloca, AllocaInst) // Stack management -HANDLE_MEMORY_INST(28, Load , LoadInst ) // Memory manipulation instrs -HANDLE_MEMORY_INST(29, Store , StoreInst ) -HANDLE_MEMORY_INST(30, GetElementPtr, GetElementPtrInst) - LAST_MEMORY_INST(30) + FIRST_MEMORY_INST(19) +HANDLE_MEMORY_INST(19, Malloc, MallocInst) // Heap management instructions +HANDLE_MEMORY_INST(20, Free , FreeInst ) +HANDLE_MEMORY_INST(21, Alloca, AllocaInst) // Stack management +HANDLE_MEMORY_INST(22, Load , LoadInst ) // Memory manipulation instrs +HANDLE_MEMORY_INST(23, Store , StoreInst ) +HANDLE_MEMORY_INST(24, GetElementPtr, GetElementPtrInst) + LAST_MEMORY_INST(24) // Cast operators ... // NOTE: The order matters here because CastInst::isEliminableCastPair // NOTE: (see Instructions.cpp) encodes a table based on this ordering. - FIRST_CAST_INST(31) -HANDLE_CAST_INST(31, Trunc , TruncInst ) // Truncate integers -HANDLE_CAST_INST(32, ZExt , ZExtInst ) // Zero extend integers -HANDLE_CAST_INST(33, SExt , SExtInst ) // Sign extend integers -HANDLE_CAST_INST(34, FPToUI , FPToUIInst ) // floating point -> UInt -HANDLE_CAST_INST(35, FPToSI , FPToSIInst ) // floating point -> SInt -HANDLE_CAST_INST(36, UIToFP , UIToFPInst ) // UInt -> floating point -HANDLE_CAST_INST(37, SIToFP , SIToFPInst ) // SInt -> floating point -HANDLE_CAST_INST(38, FPTrunc , FPTruncInst ) // Truncate floating point -HANDLE_CAST_INST(39, FPExt , FPExtInst ) // Extend floating point -HANDLE_CAST_INST(40, PtrToInt, PtrToIntInst) // Pointer -> Integer -HANDLE_CAST_INST(41, IntToPtr, IntToPtrInst) // Integer -> Pointer -HANDLE_CAST_INST(42, BitCast , BitCastInst ) // Type cast - LAST_CAST_INST(42) + FIRST_CAST_INST(25) +HANDLE_CAST_INST(25, Trunc , TruncInst ) // Truncate integers +HANDLE_CAST_INST(26, ZExt , ZExtInst ) // Zero extend integers +HANDLE_CAST_INST(27, SExt , SExtInst ) // Sign extend integers +HANDLE_CAST_INST(28, FPToUI , FPToUIInst ) // floating point -> UInt +HANDLE_CAST_INST(29, FPToSI , FPToSIInst ) // floating point -> SInt +HANDLE_CAST_INST(30, UIToFP , UIToFPInst ) // UInt -> floating point +HANDLE_CAST_INST(31, SIToFP , SIToFPInst ) // SInt -> floating point +HANDLE_CAST_INST(32, FPTrunc , FPTruncInst ) // Truncate floating point +HANDLE_CAST_INST(33, FPExt , FPExtInst ) // Extend floating point +HANDLE_CAST_INST(34, PtrToInt, PtrToIntInst) // Pointer -> Integer +HANDLE_CAST_INST(35, IntToPtr, IntToPtrInst) // Integer -> Pointer +HANDLE_CAST_INST(36, BitCast , BitCastInst ) // Type cast + LAST_CAST_INST(36) // Other operators... - FIRST_OTHER_INST(43) -HANDLE_OTHER_INST(43, ICmp , ICmpInst ) // Integer comparison instruction -HANDLE_OTHER_INST(44, FCmp , FCmpInst ) // Floating point comparison instr. -HANDLE_OTHER_INST(45, PHI , PHINode ) // PHI node instruction -HANDLE_OTHER_INST(46, Call , CallInst ) // Call a function -HANDLE_OTHER_INST(47, Shl , ShiftInst ) // Shift Left operations (logical) -HANDLE_OTHER_INST(48, LShr , ShiftInst ) // Logical Shift right (unsigned) -HANDLE_OTHER_INST(49, AShr , ShiftInst ) // Arithmetic shift right (signed) -HANDLE_OTHER_INST(50, Select , SelectInst ) // select instruction -HANDLE_OTHER_INST(51, UserOp1, Instruction) // May be used internally in a pass -HANDLE_OTHER_INST(52, UserOp2, Instruction) // Internal to passes only -HANDLE_OTHER_INST(53, VAArg , VAArgInst ) // vaarg instruction -HANDLE_OTHER_INST(54, ExtractElement, ExtractElementInst)// extract from vector. -HANDLE_OTHER_INST(55, InsertElement, InsertElementInst) // insert into vector -HANDLE_OTHER_INST(56, ShuffleVector, ShuffleVectorInst) // shuffle two vectors. - LAST_OTHER_INST(56) + FIRST_OTHER_INST(37) +HANDLE_OTHER_INST(37, ICmp , ICmpInst ) // Integer comparison instruction +HANDLE_OTHER_INST(38, FCmp , FCmpInst ) // Floating point comparison instr. +HANDLE_OTHER_INST(39, PHI , PHINode ) // PHI node instruction +HANDLE_OTHER_INST(40, Call , CallInst ) // Call a function +HANDLE_OTHER_INST(41, Shl , ShiftInst ) // Shift Left operations (logical) +HANDLE_OTHER_INST(42, LShr , ShiftInst ) // Logical Shift right (unsigned) +HANDLE_OTHER_INST(43, AShr , ShiftInst ) // Arithmetic shift right (signed) +HANDLE_OTHER_INST(44, Select , SelectInst ) // select instruction +HANDLE_OTHER_INST(45, UserOp1, Instruction) // May be used internally in a pass +HANDLE_OTHER_INST(46, UserOp2, Instruction) // Internal to passes only +HANDLE_OTHER_INST(47, VAArg , VAArgInst ) // vaarg instruction +HANDLE_OTHER_INST(48, ExtractElement, ExtractElementInst)// extract from vector. +HANDLE_OTHER_INST(49, InsertElement, InsertElementInst) // insert into vector +HANDLE_OTHER_INST(50, ShuffleVector, ShuffleVectorInst) // shuffle two vectors. + LAST_OTHER_INST(50) #undef FIRST_TERM_INST #undef HANDLE_TERM_INST diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index ce75969902..a0376c785e 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -71,6 +71,16 @@ public: /// extra information (e.g. load is volatile) agree. bool isIdenticalTo(Instruction *I) const; + /// This function determines if the specified instruction executes the same + /// operation as the current one. This means that the opcodes, type, operand + /// types and any other factors affecting the operation must be the same. This + /// is similar to isIdenticalTo except the operands themselves don't have to + /// be identical. + /// @returns true if the specified instruction is the same operation as + /// the current one. + /// @brief Determine if one instruction is the same operation as another. + bool isSameOperationAs(Instruction *I) const; + /// use_back - Specialize the methods defined in Value, as we know that an /// instruction can only be used by other instructions. Instruction *use_back() { return cast<Instruction>(*use_begin());} @@ -155,12 +165,6 @@ public: bool isCommutative() const { return isCommutative(getOpcode()); } static bool isCommutative(unsigned op); - /// isComparison - Return true if the instruction is a Set* instruction: - /// - bool isComparison() const { return isComparison(getOpcode()); } - static bool isComparison(unsigned op); - - /// isTrappingInstruction - Return true if the instruction may trap. /// bool isTrapping() const { diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 5f7125678d..c786623526 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -440,7 +440,8 @@ public: ICMP_SLT = 40, ///< signed less than ICMP_SLE = 41, ///< signed less or equal FIRST_ICMP_PREDICATE = ICMP_EQ, - LAST_ICMP_PREDICATE = ICMP_SLE + LAST_ICMP_PREDICATE = ICMP_SLE, + BAD_ICMP_PREDICATE = ICMP_SLE + 1 }; /// @brief Constructor with insert-before-instruction semantics. @@ -490,16 +491,30 @@ public: /// This is a static version that you can use without an instruction /// available. /// @brief Return the predicate as if the operands were swapped. - static Predicate getSwappedPredicate(Predicate Opcode); + static Predicate getSwappedPredicate(Predicate pred); + + /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. + /// @returns the predicate that would be the result if the operand were + /// regarded as signed. + /// @brief Return the signed version of the predicate + Predicate getSignedPredicate() const { + return getSignedPred |