Added an instruction and constant expression for the extractelement
authorRobert Bocchino <bocchino@illinois.edu>
Tue, 10 Jan 2006 19:04:13 +0000 (19:04 +0000)
committerRobert Bocchino <bocchino@illinois.edu>
Tue, 10 Jan 2006 19:04:13 +0000 (19:04 +0000)
operation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25176 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h
include/llvm/Instruction.def
include/llvm/Instructions.h
include/llvm/Support/InstVisitor.h

index 4a749abe4788b273b071d10ba244a1805098177f..f5fcd4e9ec6fa7e6243ff69936afcdc63148a6bb 100644 (file)
@@ -521,6 +521,8 @@ protected:
                                Constant *C1, Constant *C2, Constant *C3);
   static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
                                       const std::vector<Value*> &IdxList);
+  static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
+                                       Constant *Idx);
 
 public:
   // Static methods to construct a ConstantExpr of different kinds.  Note that
@@ -588,6 +590,10 @@ public:
   static Constant *getGetElementPtr(Constant *C,
                                     const std::vector<Value*> &IdxList);
 
+  /// Extractelement form.
+  ///
+  static Constant *getExtractElement(Constant *Val, Constant *Idx);
+
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const { return false; }
index 48a458ceb88d29d26113880576431e1e69825b48..3c22a9b7a9a0f32afeb783d69aceec48811db074 100644 (file)
@@ -135,7 +135,8 @@ HANDLE_OTHER_INST(34, Select , SelectInst )  // select instruction
 HANDLE_OTHER_INST(35, UserOp1, Instruction)  // May be used internally in a pass
 HANDLE_OTHER_INST(36, UserOp2, Instruction)
 HANDLE_OTHER_INST(37, VAArg  , VAArgInst  )  // vaarg instruction
-  LAST_OTHER_INST(37)
+HANDLE_OTHER_INST(38, ExtractElement, ExtractElementInst)  // extract packed element
+  LAST_OTHER_INST(38)
 
 #undef  FIRST_TERM_INST
 #undef HANDLE_TERM_INST
index 8c62d3de3b446d47680bf9423058252ced20a4f0..703c41d67996870c98f85e625dcb5cb0ee7f3866 100644 (file)
@@ -717,6 +717,52 @@ public:
   }
 };
 
+//===----------------------------------------------------------------------===//
+//                                ExtractElementInst Class
+//===----------------------------------------------------------------------===//
+
+/// ExtractElementInst - This instruction extracts a single (scalar)
+/// element from a PackedType value
+///
+class ExtractElementInst : public Instruction {
+  Use Ops[2];
+  ExtractElementInst(const ExtractElementInst &EI) : 
+    Instruction(EI.getType(), ExtractElement, Ops, 2) {
+    Ops[0].init(EI.Ops[0], this);
+    Ops[1].init(EI.Ops[1], this);
+  }
+
+public:
+  ExtractElementInst(Value *Val, Value *Index,
+               const std::string &Name = "", Instruction *InsertBefore = 0);
+  ExtractElementInst(Value *Val, Value *Index,
+               const std::string &Name, BasicBlock *InsertAtEnd);
+
+  virtual ExtractElementInst *clone() const;
+
+  virtual bool mayWriteToMemory() const { return false; }
+
+  /// 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; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const ExtractElementInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::ExtractElement;
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
+};
+
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
 //===----------------------------------------------------------------------===//
index a4b1f8b5ee76b6e5445a4a3ae1af13b50b4b8bf3..9f888cbb59017f34b61ca265ec6d7790971d4a68 100644 (file)
@@ -175,6 +175,7 @@ public:
   RetTy visitCallInst(CallInst     &I)              { DELEGATE(Instruction); }
   RetTy visitShiftInst(ShiftInst   &I)              { DELEGATE(Instruction); }
   RetTy visitVAArgInst(VAArgInst   &I)              { DELEGATE(Instruction); }
+  RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction); }
 
   // Next level propagators... if the user does not overload a specific
   // instruction type, they can overload one of these to get the whole class