Use covariant return types for Instruction::clone, and eliminate
authorDan Gohman <gohman@apple.com>
Tue, 25 Aug 2009 22:29:08 +0000 (22:29 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 25 Aug 2009 22:29:08 +0000 (22:29 +0000)
the forms of ExtractElementInst and InsertElementInst that are
equivalent to clone.

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

include/llvm/InstrTypes.h
include/llvm/Instructions.h
lib/VMCore/Instructions.cpp

index 9b59c80326e17d02bf073177d7190a85135ae1e9..c9a6ac3aa964f5b41b9c9e1b5a89ecae7090f6c5 100644 (file)
@@ -53,7 +53,7 @@ protected:
   virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
 public:
 
-  virtual Instruction *clone(LLVMContext &Context) const = 0;
+  virtual TerminatorInst *clone(LLVMContext &Context) const = 0;
 
   /// getNumSuccessors - Return the number of successors that this terminator
   /// has.
index 5163342f3325b272d788802756d0656a6f026888..4da87d1b06b57b8d880b1e44f0073960f70d2571 100644 (file)
@@ -78,7 +78,7 @@ public:
   unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
   void setAlignment(unsigned Align);
 
-  virtual Instruction *clone(LLVMContext &Context) const = 0;
+  virtual AllocationInst *clone(LLVMContext &Context) const = 0;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const AllocationInst *) { return true; }
@@ -1276,10 +1276,6 @@ class ExtractElementInst : public Instruction {
   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
                      BasicBlock *InsertAtEnd);
 public:
-  static ExtractElementInst *Create(const ExtractElementInst &EE) {
-    return Create(EE.getOperand(0), EE.getOperand(1));
-  }
-
   static ExtractElementInst *Create(Value *Vec, Value *Idx,
                                    const Twine &NameStr = "",
                                    Instruction *InsertBefore = 0) {
@@ -1330,9 +1326,6 @@ class InsertElementInst : public Instruction {
   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
                     const Twine &NameStr, BasicBlock *InsertAtEnd);
 public:
-  static InsertElementInst *Create(const InsertElementInst &IE) {
-    return Create(IE.getOperand(0), IE.getOperand(1), IE.getOperand(2));
-  }
   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
                                    const Twine &NameStr = "",
                                    Instruction *InsertBefore = 0) {
@@ -2638,7 +2631,7 @@ public:
   );
 
   /// @brief Clone an identical TruncInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual TruncInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const TruncInst *) { return true; }
@@ -2674,7 +2667,7 @@ public:
   );
 
   /// @brief Clone an identical ZExtInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual ZExtInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ZExtInst *) { return true; }
@@ -2710,7 +2703,7 @@ public:
   );
 
   /// @brief Clone an identical SExtInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual SExtInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const SExtInst *) { return true; }
@@ -2746,7 +2739,7 @@ public:
   );
 
   /// @brief Clone an identical FPTruncInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual FPTruncInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FPTruncInst *) { return true; }
@@ -2782,7 +2775,7 @@ public:
   );
 
   /// @brief Clone an identical FPExtInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual FPExtInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FPExtInst *) { return true; }
@@ -2818,7 +2811,7 @@ public:
   );
 
   /// @brief Clone an identical UIToFPInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual UIToFPInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const UIToFPInst *) { return true; }
@@ -2854,7 +2847,7 @@ public:
   );
 
   /// @brief Clone an identical SIToFPInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual SIToFPInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const SIToFPInst *) { return true; }
@@ -2890,7 +2883,7 @@ public:
   );
 
   /// @brief Clone an identical FPToUIInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual FPToUIInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FPToUIInst *) { return true; }
@@ -2926,7 +2919,7 @@ public:
   );
 
   /// @brief Clone an identical FPToSIInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual FPToSIInst *clone(LLVMContext &Context) const;
 
   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const FPToSIInst *) { return true; }
@@ -2962,7 +2955,7 @@ public:
   );
 
   /// @brief Clone an identical IntToPtrInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual IntToPtrInst *clone(LLVMContext &Context) const;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const IntToPtrInst *) { return true; }
@@ -2998,7 +2991,7 @@ public:
   );
 
   /// @brief Clone an identical PtrToIntInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual PtrToIntInst *clone(LLVMContext &Context) const;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const PtrToIntInst *) { return true; }
@@ -3034,7 +3027,7 @@ public:
   );
 
   /// @brief Clone an identical BitCastInst
-  virtual CastInst *clone(LLVMContext &Context) const;
+  virtual BitCastInst *clone(LLVMContext &Context) const;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const BitCastInst *) { return true; }
index 12a4045a14eeb896d54053e52d063191adc4574f..122569ddaed96ae05e30c97377ca1475a4816d3e 100644 (file)
@@ -2933,73 +2933,73 @@ StoreInst *StoreInst::clone(LLVMContext&) const {
   return New;
 }
 
-CastInst *TruncInst::clone(LLVMContext&) const {
+TruncInst *TruncInst::clone(LLVMContext&) const {
   TruncInst *New = new TruncInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *ZExtInst::clone(LLVMContext&) const {
+ZExtInst *ZExtInst::clone(LLVMContext&) const {
   ZExtInst *New = new ZExtInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *SExtInst::clone(LLVMContext&) const {
+SExtInst *SExtInst::clone(LLVMContext&) const {
   SExtInst *New = new SExtInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *FPTruncInst::clone(LLVMContext&) const {
+FPTruncInst *FPTruncInst::clone(LLVMContext&) const {
   FPTruncInst *New = new FPTruncInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *FPExtInst::clone(LLVMContext&) const {
+FPExtInst *FPExtInst::clone(LLVMContext&) const {
   FPExtInst *New = new FPExtInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *UIToFPInst::clone(LLVMContext&) const {
+UIToFPInst *UIToFPInst::clone(LLVMContext&) const {
   UIToFPInst *New = new UIToFPInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *SIToFPInst::clone(LLVMContext&) const {
+SIToFPInst *SIToFPInst::clone(LLVMContext&) const {
   SIToFPInst *New = new SIToFPInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *FPToUIInst::clone(LLVMContext&) const {
+FPToUIInst *FPToUIInst::clone(LLVMContext&) const {
   FPToUIInst *New = new FPToUIInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *FPToSIInst::clone(LLVMContext&) const {
+FPToSIInst *FPToSIInst::clone(LLVMContext&) const {
   FPToSIInst *New = new FPToSIInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *PtrToIntInst::clone(LLVMContext&) const {
+PtrToIntInst *PtrToIntInst::clone(LLVMContext&) const {
   PtrToIntInst *New = new PtrToIntInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *IntToPtrInst::clone(LLVMContext&) const {
+IntToPtrInst *IntToPtrInst::clone(LLVMContext&) const {
   IntToPtrInst *New = new IntToPtrInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;
 }
 
-CastInst *BitCastInst::clone(LLVMContext&) const {
+BitCastInst *BitCastInst::clone(LLVMContext&) const {
   BitCastInst *New = new BitCastInst(getOperand(0), getType());
   New->SubclassOptionalData = SubclassOptionalData;
   return New;