Add a new shufflevector instruction
authorChris Lattner <sabre@nondot.org>
Sat, 8 Apr 2006 01:15:18 +0000 (01:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 8 Apr 2006 01:15:18 +0000 (01:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27507 91177308-0d34-0410-b5e6-96231b3b80d8

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

index eaa4cd9b3d872cffc0990de38fc58d2de34e486d..ef2c839adc22cd6eb264e8eb730e3f6c1b0e683d 100644 (file)
@@ -524,6 +524,8 @@ protected:
                                        Constant *Idx);
   static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
                                       Constant *Elt, Constant *Idx);
+  static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
+                                      Constant *V2, Constant *Mask);
 
 public:
   // Static methods to construct a ConstantExpr of different kinds.  Note that
@@ -591,15 +593,10 @@ public:
   static Constant *getGetElementPtr(Constant *C,
                                     const std::vector<Value*> &IdxList);
 
-  /// Extractelement form.
-  ///
-  static Constant *getExtractElement(Constant *Val, Constant *Idx);
-
-  /// Insertelement form.
-  ///
-  static Constant *getInsertElement(Constant *Val, Constant *Elt, 
-                                    Constant *Idx);
-
+  static Constant *getExtractElement(Constant *Vec, Constant *Idx);
+  static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
+  static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
+  
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const { return false; }
index ca20eb1d3cc4add894c3518429455e2ae4d40176..e298aa4fbb90c35c8cdedf8b499b3c142f57cec7 100644 (file)
@@ -135,9 +135,10 @@ 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
-HANDLE_OTHER_INST(38, ExtractElement, ExtractElementInst)  // extract packed element
-HANDLE_OTHER_INST(39, InsertElement, InsertElementInst)  // insert element into packed vector
-  LAST_OTHER_INST(39)
+HANDLE_OTHER_INST(38, ExtractElement, ExtractElementInst)// extract from vector.
+HANDLE_OTHER_INST(39, InsertElement, InsertElementInst)  // insert into vector
+HANDLE_OTHER_INST(40, ShuffleVector, ShuffleVectorInst)  // shuffle two vectors.
+  LAST_OTHER_INST(40)
 
 #undef  FIRST_TERM_INST
 #undef HANDLE_TERM_INST
index f94bffaa49f549ca142bd4233c53f217a7369488..3922cd3e9f5511b56293ff3399c949518bc26b95 100644 (file)
@@ -733,10 +733,10 @@ class ExtractElementInst : public Instruction {
   }
 
 public:
-  ExtractElementInst(Value *Val, Value *Index,
-                     const std::string &Name = "", Instruction *InsertBefore = 0);
-  ExtractElementInst(Value *Val, Value *Index,
-                     const std::string &Name, BasicBlock *InsertAtEnd);
+  ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
+                     Instruction *InsertBefore = 0);
+  ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
+                     BasicBlock *InsertAtEnd);
 
   virtual ExtractElementInst *clone() const;
 
@@ -780,9 +780,9 @@ class InsertElementInst : public Instruction {
   }
 
 public:
-  InsertElementInst(Value *Val, Value *Elt, Value *Index,
-                    const std::string &Name = "", Instruction *InsertBefore = 0);
-  InsertElementInst(Value *Val, Value *Elt,  Value *Index,
+  InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
+                    const std::string &Name = "",Instruction *InsertBefore = 0);
+  InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
                     const std::string &Name, BasicBlock *InsertAtEnd);
 
   virtual InsertElementInst *clone() const;
@@ -810,6 +810,59 @@ public:
   }
 };
 
+//===----------------------------------------------------------------------===//
+//                           ShuffleVectorInst Class
+//===----------------------------------------------------------------------===//
+
+/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
+/// input vectors.
+///
+class ShuffleVectorInst : public Instruction {
+  Use Ops[3];
+  ShuffleVectorInst(const ShuffleVectorInst &IE) : 
+    Instruction(IE.getType(), ShuffleVector, Ops, 3) {
+      Ops[0].init(IE.Ops[0], this);
+      Ops[1].init(IE.Ops[1], this);
+      Ops[2].init(IE.Ops[2], this);
+    }
+  
+public:
+  ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
+                    const std::string &Name = "", Instruction *InsertBefor = 0);
+  ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
+                    const std::string &Name, BasicBlock *InsertAtEnd);
+  
+  /// isValidOperands - Return true if a value shufflevector instruction can be
+  /// formed with the specified operands.
+  static bool isValidOperands(const Value *V1, const Value *V2,
+                              const Value *Mask);
+  
+  virtual ShuffleVectorInst *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 ShuffleVectorInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::ShuffleVector;
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
+};
+
+
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
 //===----------------------------------------------------------------------===//
index e48b3ffd7ebacdce34f058036dfa25b44fb88603..da9144a3a48dbc72738636309efaacf426d9d477 100644 (file)
@@ -177,6 +177,7 @@ public:
   RetTy visitVAArgInst(VAArgInst   &I)              { DELEGATE(Instruction); }
   RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction); }
   RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction); }
+  RetTy visitShuffleVectorInst(ShuffleVectorInst &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