Instruction and constant expression definitions for the insertelement
authorRobert Bocchino <bocchino@illinois.edu>
Tue, 17 Jan 2006 20:05:59 +0000 (20:05 +0000)
committerRobert Bocchino <bocchino@illinois.edu>
Tue, 17 Jan 2006 20:05:59 +0000 (20:05 +0000)
operation.

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

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

index f5fcd4e9ec6fa7e6243ff69936afcdc63148a6bb..1f8a5ecca66ac657fcf44f074b23a96c2be74d27 100644 (file)
@@ -523,6 +523,8 @@ protected:
                                       const std::vector<Value*> &IdxList);
   static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
                                        Constant *Idx);
+  static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
+                                      Constant *Elt, Constant *Idx);
 
 public:
   // Static methods to construct a ConstantExpr of different kinds.  Note that
@@ -594,6 +596,11 @@ public:
   ///
   static Constant *getExtractElement(Constant *Val, Constant *Idx);
 
+  /// Insertelement form.
+  ///
+  static Constant *getInsertElement(Constant *Val, Constant *Elt, 
+                                    Constant *Idx);
+
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const { return false; }
index 3c22a9b7a9a0f32afeb783d69aceec48811db074..ca20eb1d3cc4add894c3518429455e2ae4d40176 100644 (file)
@@ -136,7 +136,8 @@ 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
 HANDLE_OTHER_INST(38, ExtractElement, ExtractElementInst)  // extract packed element
-  LAST_OTHER_INST(38)
+HANDLE_OTHER_INST(39, InsertElement, InsertElementInst)  // insert element into packed vector
+  LAST_OTHER_INST(39)
 
 #undef  FIRST_TERM_INST
 #undef HANDLE_TERM_INST
index 703c41d67996870c98f85e625dcb5cb0ee7f3866..f94bffaa49f549ca142bd4233c53f217a7369488 100644 (file)
@@ -726,17 +726,17 @@ public:
 ///
 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);
+  ExtractElementInst(const ExtractElementInst &EE) : 
+    Instruction(EE.getType(), ExtractElement, Ops, 2) {
+    Ops[0].init(EE.Ops[0], this);
+    Ops[1].init(EE.Ops[1], this);
   }
 
 public:
   ExtractElementInst(Value *Val, Value *Index,
-               const std::string &Name = "", Instruction *InsertBefore = 0);
+                     const std::string &Name = "", Instruction *InsertBefore = 0);
   ExtractElementInst(Value *Val, Value *Index,
-               const std::string &Name, BasicBlock *InsertAtEnd);
+                     const std::string &Name, BasicBlock *InsertAtEnd);
 
   virtual ExtractElementInst *clone() const;
 
@@ -763,6 +763,53 @@ public:
   }
 };
 
+//===----------------------------------------------------------------------===//
+//                                InsertElementInst Class
+//===----------------------------------------------------------------------===//
+
+/// InsertElementInst - This instruction inserts a single (scalar)
+/// element into a PackedType value
+///
+class InsertElementInst : public Instruction {
+  Use Ops[3];
+  InsertElementInst(const InsertElementInst &IE) : 
+    Instruction(IE.getType(), InsertElement, Ops, 3) {
+    Ops[0].init(IE.Ops[0], this);
+    Ops[1].init(IE.Ops[1], this);
+    Ops[2].init(IE.Ops[2], this);
+  }
+
+public:
+  InsertElementInst(Value *Val, Value *Elt, Value *Index,
+                    const std::string &Name = "", Instruction *InsertBefore = 0);
+  InsertElementInst(Value *Val, Value *Elt,  Value *Index,
+                    const std::string &Name, BasicBlock *InsertAtEnd);
+
+  virtual InsertElementInst *clone() const;
+
+  virtual bool mayWriteToMemory() const { return false; }
+
+  /// Transparently provide more efficient getOperand methods.
+  Value *getOperand(unsigned i) const {
+    assert(i < 3 && "getOperand() out of range!");
+    return Ops[i];
+  }
+  void setOperand(unsigned i, Value *Val) {
+    assert(i < 3 && "setOperand() out of range!");
+    Ops[i] = Val;
+  }
+  unsigned getNumOperands() const { return 3; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const InsertElementInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::InsertElement;
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
+};
+
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
 //===----------------------------------------------------------------------===//