-
-//===----------------------------------------------------------------------===//
-// ShiftInst Class
-//===----------------------------------------------------------------------===//
-
-/// ShiftInst - This class represents left and right shift instructions.
-///
-class ShiftInst : public Instruction {
- Use Ops[2];
- ShiftInst(const ShiftInst &SI)
- : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
- Ops[0].init(SI.Ops[0], this);
- Ops[1].init(SI.Ops[1], this);
- }
- void init(OtherOps Opcode, Value *S, Value *SA) {
- assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) &&
- "ShiftInst Opcode invalid!");
- Ops[0].init(S, this);
- Ops[1].init(SA, this);
- }
-
-public:
- ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
- Instruction *InsertBefore = 0)
- : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
- init(Opcode, S, SA);
- }
- ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
- BasicBlock *InsertAtEnd)
- : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
- init(Opcode, S, SA);
- }
-
- OtherOps getOpcode() const {
- return static_cast<OtherOps>(Instruction::getOpcode());
- }
-
- /// Transparently provide more efficient getOperand methods.
- Value *getOperand(unsigned i) const {
- assert(i < 2 && "getOperand() out of range!");
- return Ops[i];
- }
- void setOperand(unsigned i, Value *Val) {
- assert(i < 2 && "setOperand() out of range!");
- Ops[i] = Val;
- }
- unsigned getNumOperands() const { return 2; }
-
- /// isLogicalShift - Return true if this is a logical shift left or a logical
- /// shift right.
- bool isLogicalShift() const {
- unsigned opcode = getOpcode();
- return opcode == Instruction::Shl || opcode == Instruction::LShr;
- }
-
-
- /// isArithmeticShift - Return true if this is a sign-extending shift right
- /// operation.
- bool isArithmeticShift() const {
- return !isLogicalShift();
- }
-
-
- virtual ShiftInst *clone() const;
-
- // Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const ShiftInst *) { return true; }
- static inline bool classof(const Instruction *I) {
- return (I->getOpcode() == Instruction::LShr) |
- (I->getOpcode() == Instruction::AShr) |
- (I->getOpcode() == Instruction::Shl);
- }
- static inline bool classof(const Value *V) {
- return isa<Instruction>(V) && classof(cast<Instruction>(V));
- }
-};
-