llvm.org GIT mirror llvm / ed455c8
Devirtualizing Value destructor (PR889). Patch by Pawel Kunio! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44747 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 12 years ago
22 changed file(s) with 760 addition(s) and 236 deletion(s). Raw diff Collapse all Expand all
3434 friend class SymbolTableListTraits;
3535 void setParent(Function *parent);
3636
37 protected:
38 static void destroyThis(Argument*v) {
39 Value::destroyThis(v);
40 }
41 friend class Value;
3742 public:
3843 /// Argument ctor - If Function argument is specified, this argument is
3944 /// inserted at the end of the argument list for the function.
6464 BasicBlock(const BasicBlock &); // Do not implement
6565 void operator=(const BasicBlock &); // Do not implement
6666
67 protected:
68 static void destroyThis(BasicBlock*);
69 friend class Value;
6770 public:
6871 /// Instruction iterators...
6972 typedef InstListType::iterator iterator;
7578 ///
7679 explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
7780 BasicBlock *InsertBefore = 0);
78 ~BasicBlock();
7981
8082 /// getParent - Return the enclosing method, or null if none
8183 ///
205207 const BasicBlock *getPrev() const { return Prev; }
206208 };
207209
210 /// DummyInst - An instance of this class is used to mark the end of the
211 /// instruction list. This is not a real instruction.
212 class DummyInst : public Instruction {
213 protected:
214 static void destroyThis(DummyInst* v) {
215 Instruction::destroyThis(v);
216 }
217 friend class Value;
218 public:
219 DummyInst();
220
221 Instruction *clone() const {
222 assert(0 && "Cannot clone EOL");abort();
223 return 0;
224 }
225 const char *getOpcodeName() const { return "*end-of-list-inst*"; }
226
227 // Methods for support type inquiry through isa, cast, and dyn_cast...
228 static inline bool classof(const DummyInst *) { return true; }
229 static inline bool classof(const Instruction *I) {
230 return I->getOpcode() == OtherOpsEnd;
231 }
232 static inline bool classof(const Value *V) {
233 return isa(V) && classof(cast(V));
234 }
235 };
236
208237 inline int
209238 ilist_traits::getListOffset() {
210239 return BasicBlock::getInstListOffset();
4242 : User(Ty, vty, Ops, NumOps) {}
4343
4444 void destroyConstantImpl();
45 static void destroyThis(Constant*v) {
46 User::destroyThis(v);
47 }
48 friend class Value;
4549 public:
4650 /// Static constructor to get a '0' constant of arbitrary type...
4751 ///
4545 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
4646 ConstantInt(const IntegerType *Ty, const APInt& V);
4747 APInt Val;
48 protected:
49 static void destroyThis(ConstantInt*v) {
50 Constant::destroyThis(v);
51 }
52 friend class Value;
4853 public:
4954 /// Return the constant as an APInt value reference. This allows clients to
5055 /// obtain a copy of the value, with all its precision in tact.
217222 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
218223 protected:
219224 ConstantFP(const Type *Ty, const APFloat& V);
225 static void destroyThis(ConstantFP*v) {
226 Constant::destroyThis(v);
227 }
228 friend class Value;
220229 public:
221230 /// get() - Static factory methods - Return objects of the specified value
222231 static ConstantFP *get(const Type *Ty, const APFloat& V);
265274 protected:
266275 explicit ConstantAggregateZero(const Type *Ty)
267276 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
277
278 static void destroyThis(ConstantAggregateZero*v) {
279 Constant::destroyThis(v);
280 }
281 friend class Value;
268282 public:
269283 /// get() - static factory method for creating a null aggregate. It is
270284 /// illegal to call this method with a non-aggregate type.
294308 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
295309 protected:
296310 ConstantArray(const ArrayType *T, const std::vector &Val);
297 ~ConstantArray();
311 static void destroyThis(ConstantArray*);
312 friend class Value;
298313 public:
299314 /// get() - Static factory methods - Return objects of the specified value
300315 static Constant *get(const ArrayType *T, const std::vector &);
360375 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
361376 protected:
362377 ConstantStruct(const StructType *T, const std::vector &Val);
363 ~ConstantStruct();
378 static void destroyThis(ConstantStruct*);
379 friend class Value;
364380 public:
365381 /// get() - Static factory methods - Return objects of the specified value
366382 ///
404420 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
405421 protected:
406422 ConstantVector(const VectorType *T, const std::vector &Val);
407 ~ConstantVector();
423 static void destroyThis(ConstantVector*v);
424 friend class Value;
408425 public:
409426 /// get() - Static factory methods - Return objects of the specified value
410427 static Constant *get(const VectorType *T, const std::vector &);
461478 explicit ConstantPointerNull(const PointerType *T)
462479 : Constant(reinterpret_cast(T),
463480 Value::ConstantPointerNullVal, 0, 0) {}
464
481 static void destroyThis(ConstantPointerNull*v) {
482 Constant::destroyThis(v);
483 }
484 friend class Value;
465485 public:
466486
467487 /// get() - Static factory methods - Return objects of the specified value
523543 static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
524544 Constant *V2, Constant *Mask);
525545
546 static void destroyThis(ConstantExpr* v) {
547 Constant::destroyThis(v);
548 }
549 friend class Value;
526550 public:
527551 // Static methods to construct a ConstantExpr of different kinds. Note that
528552 // these methods may return a object that is not an instance of the
708732 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
709733 protected:
710734 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
735 static void destroyThis(UndefValue*v) {
736 Constant::destroyThis(v);
737 }
738 friend class Value;
711739 public:
712740 /// get() - Static factory methods - Return an 'undef' object of the specified
713741 /// type.
727755 }
728756 };
729757
758 /// GetElementPtrConstantExpr - Helper class for Constants.cpp,
759 /// used behind the scenes to implement getelementpr constant exprs.
760 class GetElementPtrConstantExpr : public ConstantExpr {
761 protected:
762 static void destroyThis(GetElementPtrConstantExpr*v) {
763 delete [] v->OperandList;
764 ConstantExpr::destroyThis(v);
765 }
766 friend class Value;
767 public:
768 GetElementPtrConstantExpr(Constant *C, const std::vector &IdxList,
769 const Type *DestTy);
770 };
771
772 /// UnaryConstantExpr - Helper class for Constants.cpp, used
773 /// behind the scenes to implement unary constant exprs.
774 class UnaryConstantExpr : public ConstantExpr {
775 Use Op;
776 protected:
777 static void destroyThis(UnaryConstantExpr*v) {
778 ConstantExpr::destroyThis(v);
779 }
780 friend class Value;
781 public:
782 UnaryConstantExpr(unsigned Opcode, Constant *C, const Type *Ty);
783 };
784
785 /// BinaryConstantExpr - Helper class for Constants.cpp, used
786 /// behind the scenes to implement binary constant exprs.
787 class BinaryConstantExpr : public ConstantExpr {
788 Use Ops[2];
789 protected:
790 static void destroyThis(BinaryConstantExpr*v) {
791 ConstantExpr::destroyThis(v);
792 }
793 friend class Value;
794 public:
795 BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
796 : ConstantExpr(C1->getType(), Opcode, Ops, 2) {
797 Ops[0].init(C1, this);
798 Ops[1].init(C2, this);
799 }
800 };
801
802 /// SelectConstantExpr - Helper class for Constants.cpp, used
803 /// behind the scenes to implement select constant exprs.
804 class SelectConstantExpr : public ConstantExpr {
805 Use Ops[3];
806 protected:
807 static void destroyThis(SelectConstantExpr*v) {
808 ConstantExpr::destroyThis(v);
809 }
810 friend class Value;
811 public:
812 SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3);
813 };
814
815 /// ExtractElementConstantExpr - Helper class for Constants.cpp, used
816 /// behind the scenes to implement extractelement constant exprs.
817 class ExtractElementConstantExpr : public ConstantExpr {
818 Use Ops[2];
819 protected:
820 static void destroyThis(ExtractElementConstantExpr*v) {
821 ConstantExpr::destroyThis(v);
822 }
823 friend class Value;
824 public:
825 ExtractElementConstantExpr(Constant *C1, Constant *C2);
826 };
827
828 /// InsertElementConstantExpr - Helper class for Constants.cpp, used
829 /// behind the scenes to implement insertelement constant exprs.
830 class InsertElementConstantExpr : public ConstantExpr {
831 Use Ops[3];
832 protected:
833 static void destroyThis(InsertElementConstantExpr*v) {
834 ConstantExpr::destroyThis(v);
835 }
836 friend class Value;
837 public:
838 InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3);
839 };
840
841 /// ShuffleVectorConstantExpr - Helper class for Constants.cpp, used
842 /// behind the scenes to implement shufflevector constant exprs.
843 class ShuffleVectorConstantExpr : public ConstantExpr {
844 Use Ops[3];
845 protected:
846 static void destroyThis(ShuffleVectorConstantExpr*v) {
847 ConstantExpr::destroyThis(v);
848 }
849 friend class Value;
850 public:
851 ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3);
852 };
853
854
855
856 // CompareConstantExpr - Helper class for Constants.cpp, used
857 // behind the scenes to implement ICmp and FCmp constant expressions. This is
858 // needed in order to store the predicate value for these instructions.
859 class CompareConstantExpr : public ConstantExpr {
860 protected:
861 static void destroyThis(CompareConstantExpr*v) {
862 ConstantExpr::destroyThis(v);
863 }
864 friend class Value;
865 public:
866 unsigned short predicate;
867 Use Ops[2];
868 CompareConstantExpr(unsigned opc, unsigned short pred,
869 Constant* LHS, Constant* RHS);
870 };
871
730872 } // End llvm namespace
731873
732874 #endif
5252 };
5353
5454 class Function : public GlobalValue, public Annotable {
55 protected:
56 static void destroyThis(Function*v);
57 friend class Value;
5558 public:
5659 typedef iplist ArgumentListType;
5760 typedef iplist BasicBlockListType;
108111 ///
109112 Function(const FunctionType *Ty, LinkageTypes Linkage,
110113 const std::string &N = "", Module *M = 0);
111 ~Function();
112114
113115 const Type *getReturnType() const; // Return the type of the ret val
114116 const FunctionType *getFunctionType() const; // Return the FunctionType for me
4242 const GlobalAlias *getPrev() const { return Prev; }
4343
4444 Use Aliasee;
45 protected:
46 static void destroyThis(GlobalAlias*v) {
47 GlobalValue::destroyThis(v);
48 }
49 friend class Value;
4550 public:
4651 /// GlobalAlias ctor - If a parent module is specified, the alias is
4752 /// automatically inserted into the end of the specified module's alias list.
6262 unsigned Visibility : 2; // The visibility style of this global
6363 unsigned Alignment : 16; // Alignment of this symbol, must be power of two
6464 std::string Section; // Section to emit this into, empty mean default
65
66 static void destroyThis(GlobalValue*v) {
67 v->removeDeadConstantUsers(); // remove any dead constants using this.
68 Constant::destroyThis(v);
69 }
6570 public:
66 ~GlobalValue() {
67 removeDeadConstantUsers(); // remove any dead constants using this.
68 }
69
7071 unsigned getAlignment() const { return Alignment; }
7172 void setAlignment(unsigned Align) {
7273 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
4444 bool isThreadLocalSymbol : 1; // Is this symbol "Thread Local"?
4545 Use Initializer;
4646
47 protected:
48 static void destroyThis(GlobalVariable*v) {
49 GlobalValue::destroyThis(v);
50 }
51 friend class Value;
4752 public:
4853 /// GlobalVariable ctor - If a parent module is specified, the global is
4954 /// automatically inserted into the end of the specified modules global list.
3535
3636 InlineAsm(const FunctionType *Ty, const std::string &AsmString,
3737 const std::string &Constraints, bool hasSideEffects);
38 virtual ~InlineAsm();
38 protected:
39 static void destroyThis(InlineAsm*v) {
40 Value::destroyThis(v);
41 }
42 friend class Value;
3943 public:
40
4144 /// InlineAsm::get - Return the the specified uniqued inline asm string.
4245 ///
4346 static InlineAsm *get(const FunctionType *Ty, const std::string &AsmString,
3737 Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
3838 : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
3939
40 // Out of line virtual method, so the vtable, etc has a home.
41 ~TerminatorInst();
42
4340 /// Virtual methods - Terminators should overload these and provide inline
4441 /// overrides of non-V methods.
4542 virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
4643 virtual unsigned getNumSuccessorsV() const = 0;
4744 virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
45
46 static void destroyThis(TerminatorInst* v) {
47 Instruction::destroyThis(v);
48 }
49 friend class Value;
4850 public:
4951
5052 virtual Instruction *clone() const = 0;
9395 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
9496 : Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) {
9597 }
98
99 static void destroyThis(UnaryInstruction* v) {
100 Instruction::destroyThis(v);
101 }
102 friend class Value;
96103 public:
97 // Out of line virtual method, so the vtable, etc has a home.
98 ~UnaryInstruction();
99
100104 // Transparently provide more efficient getOperand methods.
101105 Value *getOperand(unsigned i) const {
102106 assert(i == 0 && "getOperand() out of range!");
135139 const std::string &Name, Instruction *InsertBefore);
136140 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
137141 const std::string &Name, BasicBlock *InsertAtEnd);
142
143 static void destroyThis(BinaryOperator* v) {
144 Instruction::destroyThis(v);
145 }
146 friend class Value;
138147 public:
139148
140149 /// Transparently provide more efficient getOperand methods.
271280 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
272281 setName(Name);
273282 }
283
284 protected:
285 static void destroyThis(CastInst* v) {
286 UnaryInstruction::destroyThis(v);
287 }
288 friend class Value;
274289 public:
275290 /// Provides a way to construct any of the CastInst subclasses using an
276291 /// opcode instead of the subclass's constructor. The opcode must be in the
492507
493508 Use Ops[2]; // CmpInst instructions always have 2 operands, optimize
494509
510 static void destroyThis(CmpInst* v) {
511 Instruction::destroyThis(v);
512 }
513 friend class Value;
495514 public:
496515 /// Construct a compare instruction, given the opcode, the predicate and
497516 /// the two operands. Optionally (if InstBefore is specified) insert the
4141 Instruction *InsertBefore = 0);
4242 Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
4343 BasicBlock *InsertAtEnd);
44
45 static void destroyThis(Instruction*v);
46 friend class Value;
4447 public:
45 // Out of line virtual method, so the vtable, etc has a home.
46 ~Instruction();
47
4848 /// mayWriteToMemory - Return true if this instruction may modify memory.
4949 ///
5050 bool mayWriteToMemory() const;
4646 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
4747 const std::string &Name, BasicBlock *InsertAtEnd);
4848 public:
49 // Out of line virtual method, so the vtable, etc has a home.
50 virtual ~AllocationInst();
51
5249 /// isArrayAllocation - Return true if there is an allocation size parameter
5350 /// to the allocation instruction that is not 1.
5451 ///
189186 ///
190187 class FreeInst : public UnaryInstruction {
191188 void AssertOK();
189 protected:
190 static void destroyThis(FreeInst* v) {
191 UnaryInstruction::destroyThis(v);
192 }
193 friend class Value;
192194 public:
193195 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
194196 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
229231 #endif
230232 }
231233 void AssertOK();
234 protected:
235 static void destroyThis(LoadInst* v) {
236 UnaryInstruction::destroyThis(v);
237 }
238 friend class Value;
232239 public:
233240 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
234241 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
304311 #endif
305312 }
306313 void AssertOK();
314 protected:
315 static void destroyThis(StoreInst* v) {
316 Instruction::destroyThis(v);
317 }
318 friend class Value;
307319 public:
308320 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
309321 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
442454 }
443455 }
444456
457 protected:
458 static void destroyThis(GetElementPtrInst*v);
459 friend class Value;
445460 public:
446461 /// Constructors - Create a getelementptr instruction with a base pointer an
447462 /// list of indices. The first ctor can optionally insert before an existing
476491 const std::string &Name = "", Instruction *InsertBefore =0);
477492 GetElementPtrInst(Value *Ptr, Value *Idx,
478493 const std::string &Name, BasicBlock *InsertAtEnd);
479 ~GetElementPtrInst();
480494
481495 virtual GetElementPtrInst *clone() const;
482496
555569 /// vectors of integrals. The two operands must be the same type.
556570 /// @brief Represent an integer comparison operator.
557571 class ICmpInst: public CmpInst {
572 protected:
573 static void destroyThis(ICmpInst* v) {
574 CmpInst::destroyThis(v);
575 }
576 friend class Value;
558577 public:
559578 /// This enumeration lists the possible predicates for the ICmpInst. The
560579 /// values in the range 0-31 are reserved for FCmpInst while values in the
711730 /// vectors of floating point values. The operands must be identical types.
712731 /// @brief Represents a floating point comparison operator.
713732 class FCmpInst: public CmpInst {
733 protected:
734 static void destroyThis(FCmpInst* v) {
735 CmpInst::destroyThis(v);
736 }
737 friend class Value;
714738 public:
715739 /// This enumeration lists the possible predicates for the FCmpInst. Values
716740 /// in the range 0-31 are reserved for FCmpInst.
856880 setName(Name);
857881 }
858882
883 protected:
884 static void destroyThis(CallInst*v);
885 friend class Value;
859886 public:
860887 /// Construct a CallInst given a range of arguments. InputIterator
861888 /// must be a random-access iterator pointing to contiguous storage
896923 explicit CallInst(Value *F, const std::string &Name = "",
897924 Instruction *InsertBefore = 0);
898925 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
899 ~CallInst();
900926
901927 virtual CallInst *clone() const;
902928
9881014 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
9891015 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
9901016 }
1017 protected:
1018 static void destroyThis(SelectInst* v) {
1019 Instruction::destroyThis(v);
1020 }
1021 friend class Value;
9911022 public:
9921023 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
9931024 Instruction *InsertBefore = 0)
10431074 class VAArgInst : public UnaryInstruction {
10441075 VAArgInst(const VAArgInst &VAA)
10451076 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
1077 protected:
1078 static void destroyThis(VAArgInst* v) {
1079 UnaryInstruction::destroyThis(v);
1080 }
1081 friend class Value;
10461082 public:
10471083 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
10481084 Instruction *InsertBefore = 0)
10821118 Ops[1].init(EE.Ops[1], this);
10831119 }
10841120
1121 protected:
1122 static void destroyThis(ExtractElementInst* v) {
1123 Instruction::destroyThis(v);
1124 }
1125 friend class Value;
10851126 public:
10861127 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
10871128 Instruction *InsertBefore = 0);
11291170 class InsertElementInst : public Instruction {
11301171 Use Ops[3];
11311172 InsertElementInst(const InsertElementInst &IE);
1173 protected:
1174 static void destroyThis(InsertElementInst* v) {
1175 Instruction::destroyThis(v);
1176 }
1177 friend class Value;
11321178 public:
11331179 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
11341180 const std::string &Name = "",Instruction *InsertBefore = 0);
11831229 class ShuffleVectorInst : public Instruction {
11841230 Use Ops[3];
11851231 ShuffleVectorInst(const ShuffleVectorInst &IE);
1232 protected:
1233 static void destroyThis(ShuffleVectorInst* v) {
1234 Instruction::destroyThis(v);
1235 }
1236 friend class Value;
11861237 public:
11871238 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
11881239 const std::string &Name = "", Instruction *InsertBefor = 0);
12371288 /// the number actually in use.
12381289 unsigned ReservedSpace;
12391290 PHINode(const PHINode &PN);
1291 protected:
1292 static void destroyThis(PHINode*);
1293 friend class Value;
12401294 public:
12411295 explicit PHINode(const Type *Ty, const std::string &Name = "",
12421296 Instruction *InsertBefore = 0)
12501304 ReservedSpace(0) {
12511305 setName(Name);
12521306 }
1253
1254 ~PHINode();
12551307
12561308 /// reserveOperandSpace - This method can be used to avoid repeated
12571309 /// reallocation of PHI operand lists by reserving space for the correct
15211573 SwitchInst(const SwitchInst &RI);
15221574 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
15231575 void resizeOperands(unsigned No);
1576 protected:
1577 static void destroyThis(SwitchInst*v);
1578 friend class Value;
15241579 public:
15251580 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
15261581 /// switch on and a default destination. The number of additional cases can
15351590 /// constructor also autoinserts at the end of the specified BasicBlock.
15361591 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
15371592 BasicBlock *InsertAtEnd);
1538 ~SwitchInst();
15391593
15401594
15411595 // Accessor Methods for Switch stmt
16631717 setName(Name);
16641718 }
16651719
1720 protected:
1721 static void destroyThis(InvokeInst*v);
1722 friend class Value;
16661723 public:
16671724 /// Construct an InvokeInst given a range of arguments.
16681725 /// InputIterator must be a random-access iterator pointing to
17001757 typename std::iterator_traits::iterator_category());
17011758 }
17021759
1703 ~InvokeInst();
1704
17051760 virtual InvokeInst *clone() const;
17061761
17071762 /// getCallingConv/setCallingConv - Get or set the calling convention of this
18711926 TruncInst(const TruncInst &CI)
18721927 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
18731928 }
1929 protected:
1930 static void destroyThis(TruncInst* v) {
1931 CastInst::destroyThis(v);
1932 }
1933 friend class Value;
18741934 public:
18751935 /// @brief Constructor with insert-before-instruction semantics
18761936 TruncInst(
19111971 ZExtInst(const ZExtInst &CI)
19121972 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
19131973 }
1974 protected:
1975 static void destroyThis(ZExtInst* v) {
1976 CastInst::destroyThis(v);
1977 }
1978 friend class Value;
19141979 public:
19151980 /// @brief Constructor with insert-before-instruction semantics
19161981 ZExtInst(
19512016 SExtInst(const SExtInst &CI)
19522017 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
19532018 }
2019 protected:
2020 static void destroyThis(SExtInst* v) {
2021 CastInst::destroyThis(v);
2022 }
2023 friend class Value;
19542024 public:
19552025 /// @brief Constructor with insert-before-instruction semantics
19562026 SExtInst(
19902060 FPTruncInst(const FPTruncInst &CI)
19912061 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
19922062 }
2063 protected:
2064 static void destroyThis(FPTruncInst* v) {
2065 CastInst::destroyThis(v);
2066 }
2067 friend class Value;
19932068 public:
19942069 /// @brief Constructor with insert-before-instruction semantics
19952070 FPTruncInst(
20292104 FPExtInst(const FPExtInst &CI)
20302105 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
20312106 }
2107 protected:
2108 static void destroyThis(FPExtInst* v) {
2109 CastInst::destroyThis(v);
2110 }
2111 friend class Value;
20322112 public:
20332113 /// @brief Constructor with insert-before-instruction semantics
20342114 FPExtInst(
20682148 UIToFPInst(const UIToFPInst &CI)
20692149 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
20702150 }
2151 protected:
2152 static void destroyThis(UIToFPInst* v) {
2153 CastInst::destroyThis(v);
2154 }
2155 friend class Value;
20712156 public:
20722157 /// @brief Constructor with insert-before-instruction semantics
20732158 UIToFPInst(
21072192 SIToFPInst(const SIToFPInst &CI)
21082193 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
21092194 }
2195 protected:
2196 static void destroyThis(SIToFPInst* v) {
2197 CastInst::destroyThis(v);
2198 }
2199 friend class Value;
21102200 public:
21112201 /// @brief Constructor with insert-before-instruction semantics
21122202 SIToFPInst(
21462236 FPToUIInst(const FPToUIInst &CI)
21472237 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
21482238 }
2239 protected:
2240 static void destroyThis(FPToUIInst* v) {
2241 CastInst::destroyThis(v);
2242 }
2243 friend class Value;
21492244 public:
21502245 /// @brief Constructor with insert-before-instruction semantics
21512246 FPToUIInst(
21852280 FPToSIInst(const FPToSIInst &CI)
21862281 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
21872282 }
2283 protected:
2284 static void destroyThis(FPToSIInst* v) {
2285 CastInst::destroyThis(v);
2286 }
2287 friend class Value;
21882288 public:
21892289 /// @brief Constructor with insert-before-instruction semantics
21902290 FPToSIInst(
22242324 IntToPtrInst(const IntToPtrInst &CI)
22252325 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
22262326 }
2327 protected:
2328 static void destroyThis(IntToPtrInst* v) {
2329 CastInst::destroyThis(v);
2330 }
2331 friend class Value;
22272332 public:
22282333 /// @brief Constructor with insert-before-instruction semantics
22292334 IntToPtrInst(
22632368 PtrToIntInst(const PtrToIntInst &CI)
22642369 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
22652370 }
2371 protected:
2372 static void destroyThis(PtrToIntInst* v) {
2373 CastInst::destroyThis(v);
2374 }
2375 friend class Value;
22662376 public:
22672377 /// @brief Constructor with insert-before-instruction semantics
22682378 PtrToIntInst(
23022412 BitCastInst(const BitCastInst &CI)
23032413 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
23042414 }
2415 protected:
2416 static void destroyThis(BitCastInst* v) {
2417 CastInst::destroyThis(v);
2418 }
2419 friend class Value;
23052420 public:
23062421 /// @brief Constructor with insert-before-instruction semantics
23072422 BitCastInst(
3737 IntrinsicInst(); // DO NOT IMPLEMENT
3838 IntrinsicInst(const IntrinsicInst&); // DO NOT IMPLEMENT
3939 void operator=(const IntrinsicInst&); // DO NOT IMPLEMENT
40 protected:
41 static void destroyThis(IntrinsicInst* v) {
42 CallInst::destroyThis(v);
43 }
44 friend class Value;
4045 public:
4146
4247 /// StripPointerCasts - This static method strips off any unneeded pointer
8489 }
8590
8691 static Value *StripCast(Value *C);
92 protected:
93 static void destroyThis(DbgInfoIntrinsic* v) {
94 IntrinsicInst::destroyThis(v);
95 }
96 friend class Value;
8797 };
8898
8999 /// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction.
113123 static inline bool classof(const Value *V) {
114124 return isa(V) && classof(cast(V));
115125 }
126 protected:
127 static void destroyThis(DbgStopPointInst* v) {
128 DbgInfoIntrinsic::destroyThis(v);
129 }
130 friend class Value;
116131 };
117132
118133 /// DbgFuncStartInst - This represents the llvm.dbg.func.start instruction.
128143 static inline bool classof(const Value *V) {
129144 return isa(V) && classof(cast(V));
130145 }
146 protected:
147 static void destroyThis(DbgFuncStartInst* v) {
148 DbgInfoIntrinsic::destroyThis(v);
149 }
150 friend class Value;
131151 };
132152
133153 /// DbgRegionStartInst - This represents the llvm.dbg.region.start
143163 static inline bool classof(const Value *V) {
144164 return isa(V) && classof(cast(V));
145165 }
166 protected:
167 static void destroyThis(DbgRegionStartInst* v) {
168 DbgInfoIntrinsic::destroyThis(v);
169 }
170 friend class Value;
146171 };
147172
148173 /// DbgRegionEndInst - This represents the llvm.dbg.region.end instruction.
174199 static inline bool classof(const Value *V) {
175200 return isa(V) && classof(cast(V));
176201 }
202 protected:
203 static void destroyThis(DbgDeclareInst* v) {
204 DbgInfoIntrinsic::destroyThis(v);
205 }
206 friend class Value;
177207 };
178208
179209 /// MemIntrinsic - This is the common base class for memset/memcpy/memmove.
227257 static inline bool classof(const Value *V) {
228258 return isa(V) && classof(cast(V));
229259 }
260 protected:
261 static void destroyThis(MemIntrinsic* v) {
262 IntrinsicInst::destroyThis(v);
263 }
264 friend class Value;
230265 };
231266
232267
258293 static inline bool classof(const Value *V) {
259294 return isa(V) && classof(cast(V));
260295 }
296 protected:
297 static void destroyThis(MemCpyInst* v) {
298 MemIntrinsic::destroyThis(v);
299 }
300 friend class Value;
261301 };
262302
263303 /// MemMoveInst - This class wraps the llvm.memmove intrinsic.
287327 static inline bool classof(const Value *V) {
288328 return isa(V) && classof(cast(V));
289329 }
330 protected:
331 static void destroyThis(MemMoveInst* v) {
332 MemIntrinsic::destroyThis(v);
333 }
334 friend class Value;
290335 };
291336
292337 /// MemSetInst - This class wraps the llvm.memset intrinsic.
311356 static inline bool classof(const Value *V) {
312357 return isa(V) && classof(cast(V));
313358 }
359 protected:
360 static void destroyThis(MemSetInst* v) {
361 MemIntrinsic::destroyThis(v);
362 }
363 friend class Value;
314364 };
315365
316366 }
3636 ///
3737 unsigned NumOperands;
3838
39 static void destroyThis(User*v) {
40 Value::destroyThis(v);
41 }
42 friend class Value;
3943 public:
4044 User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
4145 : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
6565 friend class SymbolTable; // Allow SymbolTable to directly poke Name.
6666 ValueName *Name;
6767
68 private:
6869 void operator=(const Value &); // Do not implement
6970 Value(const Value &); // Do not implement
71 protected:
72 static void destroyThis(Value*);
7073
7174 public:
7275 Value(const Type *Ty, unsigned scid);
2929 return 0;
3030 }
3131
32
33 namespace {
34 /// DummyInst - An instance of this class is used to mark the end of the
35 /// instruction list. This is not a real instruction.
36 struct VISIBILITY_HIDDEN DummyInst : public Instruction {
37 DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
38 // This should not be garbage monitored.
39 LeakDetector::removeGarbageObject(this);
40 }
41
42 Instruction *clone() const {
43 assert(0 && "Cannot clone EOL");abort();
44 return 0;
45 }
46 const char *getOpcodeName() const { return "*end-of-list-inst*"; }
47
48 // Methods for support type inquiry through isa, cast, and dyn_cast...
49 static inline bool classof(const DummyInst *) { return true; }
50 static inline bool classof(const Instruction *I) {
51 return I->getOpcode() == OtherOpsEnd;
52 }
53 static inline bool classof(const Value *V) {
54 return isa(V) && classof(cast(V));
55 }
56 };
32 DummyInst::DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
33 // This should not be garbage monitored.
34 LeakDetector::removeGarbageObject(this);
5735 }
5836
5937 Instruction *ilist_traits::createSentinel() {
8765 }
8866
8967
90 BasicBlock::~BasicBlock() {
91 assert(getParent() == 0 && "BasicBlock still linked into the program!");
92 dropAllReferences();
93 InstList.clear();
68 void BasicBlock::destroyThis(BasicBlock*v)
69 {
70 assert(v->getParent() == 0 && "BasicBlock still linked into the program!");
71 v->dropAllReferences();
72 v->InstList.clear();
73 Value::destroyThis(v);
9474 }
9575
9676 void BasicBlock::setParent(Function *parent) {
355355 }
356356 }
357357
358 ConstantArray::~ConstantArray() {
359 delete [] OperandList;
358 void ConstantArray::destroyThis(ConstantArray*v) {
359 delete [] v->OperandList;
360 Constant::destroyThis(v);
360361 }
361362
362363 ConstantStruct::ConstantStruct(const StructType *T,
378379 }
379380 }
380381
381 ConstantStruct::~ConstantStruct() {
382 delete [] OperandList;
382 void ConstantStruct::destroyThis(ConstantStruct*v) {
383 delete [] v->OperandList;
384 Constant::destroyThis(v);
383385 }
384386
385387
398400 }
399401 }
400402
401 ConstantVector::~ConstantVector() {
402 delete [] OperandList;
403 }
404
405 // We declare several classes private to this file, so use an anonymous
406 // namespace
407 namespace {
408
409 /// UnaryConstantExpr - This class is private to Constants.cpp, and is used
410 /// behind the scenes to implement unary constant exprs.
411 class VISIBILITY_HIDDEN UnaryConstantExpr : public ConstantExpr {
412 Use Op;
413 public:
414 UnaryConstantExpr(unsigned Opcode, Constant *C, const Type *Ty)
415 : ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {}
416 };
417
418 /// BinaryConstantExpr - This class is private to Constants.cpp, and is used
419 /// behind the scenes to implement binary constant exprs.
420 class VISIBILITY_HIDDEN BinaryConstantExpr : public ConstantExpr {
421 Use Ops[2];
422 public:
423 BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
424 : ConstantExpr(C1->getType(), Opcode, Ops, 2) {
425 Ops[0].init(C1, this);
426 Ops[1].init(C2, this);
427 }
428 };
429
430 /// SelectConstantExpr - This class is private to Constants.cpp, and is used
431 /// behind the scenes to implement select constant exprs.
432 class VISIBILITY_HIDDEN SelectConstantExpr : public ConstantExpr {
433 Use Ops[3];
434 public:
435 SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
436 : ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) {
437 Ops[0].init(C1, this);
438 Ops[1].init(C2, this);
439 Ops[2].init(C3, this);
440 }
441 };
442
443 /// ExtractElementConstantExpr - This class is private to
444 /// Constants.cpp, and is used behind the scenes to implement
445 /// extractelement constant exprs.
446 class VISIBILITY_HIDDEN ExtractElementConstantExpr : public ConstantExpr {
447 Use Ops[2];
448 public:
449 ExtractElementConstantExpr(Constant *C1, Constant *C2)
450 : ConstantExpr(cast(C1->getType())->getElementType(),
451 Instruction::ExtractElement, Ops, 2) {
452 Ops[0].init(C1, this);
453 Ops[1].init(C2, this);
454 }
455 };
456
457 /// InsertElementConstantExpr - This class is private to
458 /// Constants.cpp, and is used behind the scenes to implement
459 /// insertelement constant exprs.
460 class VISIBILITY_HIDDEN InsertElementConstantExpr : public ConstantExpr {
461 Use Ops[3];
462 public:
463 InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
464 : ConstantExpr(C1->getType(), Instruction::InsertElement,
465 Ops, 3) {
466 Ops[0].init(C1, this);
467 Ops[1].init(C2, this);
468 Ops[2].init(C3, this);
469 }
470 };
471
472 /// ShuffleVectorConstantExpr - This class is private to
473 /// Constants.cpp, and is used behind the scenes to implement
474 /// shufflevector constant exprs.
475 class VISIBILITY_HIDDEN ShuffleVectorConstantExpr : public ConstantExpr {
476 Use Ops[3];
477 public:
478 ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
479 : ConstantExpr(C1->getType(), Instruction::ShuffleVector,
480 Ops, 3) {
481 Ops[0].init(C1, this);
482 Ops[1].init(C2, this);
483 Ops[2].init(C3, this);
484 }
485 };
486
487 /// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
488 /// used behind the scenes to implement getelementpr constant exprs.
489 struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
490 GetElementPtrConstantExpr(Constant *C, const std::vector &IdxList,
491 const Type *DestTy)
492 : ConstantExpr(DestTy, Instruction::GetElementPtr,
493 new Use[IdxList.size()+1], IdxList.size()+1) {
494 OperandList[0].init(C, this);
495 for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
496 OperandList[i+1].init(IdxList[i], this);
497 }
498 ~GetElementPtrConstantExpr() {
499 delete [] OperandList;
500 }
501 };
502
503 // CompareConstantExpr - This class is private to Constants.cpp, and is used
504 // behind the scenes to implement ICmp and FCmp constant expressions. This is
505 // needed in order to store the predicate value for these instructions.
506 struct VISIBILITY_HIDDEN CompareConstantExpr : public ConstantExpr {
507 unsigned short predicate;
508 Use Ops[2];
509 CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred,
510 Constant* LHS, Constant* RHS)
511 : ConstantExpr(Type::Int1Ty, opc, Ops, 2), predicate(pred) {
512 OperandList[0].init(LHS, this);
513 OperandList[1].init(RHS, this);
514 }
515 };
516
517 } // end anonymous namespace
518
403 void ConstantVector::destroyThis(ConstantVector*v) {
404 delete [] v->OperandList;
405 Constant::destroyThis(v);
406 }
407
408 UnaryConstantExpr::UnaryConstantExpr(unsigned Opcode,
409 Constant *C, const Type *Ty)
410 : ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {
411 }
412
413 SelectConstantExpr::SelectConstantExpr(Constant *C1,
414 Constant *C2, Constant *C3)
415 : ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) {
416 Ops[0].init(C1, this);
417 Ops[1].init(C2, this);
418 Ops[2].init(C3, this);
419 }
420
421 ExtractElementConstantExpr::ExtractElementConstantExpr(Constant *C1,
422 Constant *C2)
423 : ConstantExpr(cast(C1->getType())->getElementType(),
424 Instruction::ExtractElement, Ops, 2) {
425 Ops[0].init(C1, this);
426 Ops[1].init(C2, this);
427 }
428
429 InsertElementConstantExpr::InsertElementConstantExpr(Constant *C1,
430 Constant *C2,
431 Constant *C3)
432 : ConstantExpr(C1->getType(), Instruction::InsertElement, Ops, 3) {
433 Ops[0].init(C1, this);
434 Ops[1].init(C2, this);
435 Ops[2].init(C3, this);
436 }
437
438 ShuffleVectorConstantExpr::ShuffleVectorConstantExpr(Constant *C1,
439 Constant *C2,
440 Constant *C3)
441 : ConstantExpr(C1->getType(), Instruction::ShuffleVector, Ops, 3) {
442 Ops[0].init(C1, this);
443 Ops[1].init(C2, this);
444 Ops[2].init(C3, this);
445 }
446
447 CompareConstantExpr::CompareConstantExpr(unsigned opc, unsigned short pred,
448 Constant* LHS, Constant* RHS)
449 : ConstantExpr(Type::Int1Ty, opc, Ops, 2), predicate(pred) {
450 OperandList[0].init(LHS, this);
451 OperandList[1].init(RHS, this);
452 }
453
454 GetElementPtrConstantExpr::GetElementPtrConstantExpr(Constant *C,
455 const std::vector
456 &IdxList, const Type *DestTy)
457 : ConstantExpr(DestTy, Instruction::GetElementPtr,
458 new Use[IdxList.size()+1], IdxList.size()+1)
459 {
460 OperandList[0].init(C, this);
461 for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
462 OperandList[i+1].init(IdxList[i], this);
463 }
519464
520465 // Utility function for determining if a ConstantExpr is a CastOp or not. This
521466 // can't be inline because we don't want to #include Instruction.h into
286286 ParentModule->getFunctionList().push_back(this);
287287 }
288288
289 Function::~Function() {
290 dropAllReferences(); // After this it is safe to delete instructions.
289 void Function::destroyThis(Function*v) {
290 v->dropAllReferences(); // After this it is safe to delete instructions.
291291
292292 // Delete all of the method arguments and unlink from symbol table...
293 ArgumentList.clear();
294 delete SymTab;
293 v->ArgumentList.clear();
294 delete v->SymTab;
295295
296296 // Drop our reference to the parameter attributes, if any.
297 if (ParamAttrs)
298 ParamAttrs->dropRef();
297 if (v->ParamAttrs)
298 v->ParamAttrs->dropRef();
299 GlobalValue::destroyThis(v);
299300 }
300301
301302 void Function::BuildLazyArguments() const {
1515 #include
1616 #include
1717 using namespace llvm;
18
19 // Implement the first virtual method in this class in this file so the
20 // InlineAsm vtable is emitted here.
21 InlineAsm::~InlineAsm() {
22 }
23
2418
2519 // NOTE: when memoizing the function type, we have to be careful to handle the
2620 // case when the type gets refined.
4545
4646
4747 // Out of line virtual method, so the vtable, etc has a home.
48 Instruction::~Instruction() {
49 assert(Parent == 0 && "Instruction still linked in the program!");
48 void Instruction::destroyThis(Instruction*v) {
49 assert(v->Parent == 0 && "Instruction still linked in the program!");
5050 }
5151
5252
6666 }
6767
6868
69
70 //===----------------------------------------------------------------------===//
71 // TerminatorInst Class
72 //===----------------------------------------------------------------------===//
73
74 // Out of line virtual method, so the vtable, etc has a home.
75 TerminatorInst::~TerminatorInst() {
76 }
77
78 // Out of line virtual method, so the vtable, etc has a home.
79 UnaryInstruction::~UnaryInstruction() {
80 }
81
82
8369 //===----------------------------------------------------------------------===//
8470 // PHINode Class
8571 //===----------------------------------------------------------------------===//
9581 }
9682 }
9783
98 PHINode::~PHINode() {
99 delete [] OperandList;
84 void PHINode::destroyThis(PHINode*v) {
85 delete [] v->OperandList;
86 Instruction::destroyThis(v);
10087 }
10188
10289 // removeIncomingValue - Remove an incoming value. This is useful if a
213200 // CallInst Implementation
214201 //===----------------------------------------------------------------------===//
215202
216 CallInst::~CallInst() {
217 delete [] OperandList;
218 if (ParamAttrs)
219 ParamAttrs->dropRef();
203 void CallInst::destroyThis(CallInst*v) {
204 delete [] v->OperandList;
205 if (v->ParamAttrs)
206 v->ParamAttrs->dropRef();
207 Instruction::destroyThis(v);
220208 }
221209
222210 void CallInst::init(Value *Func, Value* const *Params, unsigned NumParams) {
405393 // InvokeInst Implementation
406394 //===----------------------------------------------------------------------===//
407395
408 InvokeInst::~InvokeInst() {
409 delete [] OperandList;
410 if (ParamAttrs)
411 ParamAttrs->dropRef();
396 void InvokeInst::destroyThis(InvokeInst*v) {
397 delete [] v->OperandList;
398 if (v->ParamAttrs)
399 v->ParamAttrs->dropRef();
400 TerminatorInst::destroyThis(v);
412401 }
413402
414403 void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
682671 setName(Name);
683672 }
684673
685 // Out of line virtual method, so the vtable, etc has a home.
686 AllocationInst::~AllocationInst() {
687 }
688
689674 bool AllocationInst::isArrayAllocation() const {
690675 if (ConstantInt *CI = dyn_cast(getOperand(0)))
691676 return CI->getZExtValue() != 1;
950935 setName(Name);
951936 }
952937
953 GetElementPtrInst::~GetElementPtrInst() {
954 delete[] OperandList;
938 void GetElementPtrInst::destroyThis(GetElementPtrInst*v) {
939 delete[] v->OperandList;
955940 }
956941
957942 // getIndexedType - Returns the type of the element that would be loaded with
24682453 }
24692454 }
24702455
2471 SwitchInst::~SwitchInst() {
2472 delete [] OperandList;
2456 void SwitchInst::destroyThis(SwitchInst*v) {
2457 delete [] v->OperandList;
2458 TerminatorInst::destroyThis(v);
24732459 }
24742460
24752461
1717 #include "llvm/ValueSymbolTable.h"
1818 #include "llvm/Support/Debug.h"
1919 #include "llvm/Support/LeakDetector.h"
20 #include "llvm/Constants.h"
21 #include "llvm/InlineAsm.h"
22 #include "llvm/Instructions.h"
23 #include "llvm/IntrinsicInst.h"
24 #include "llvm/InstrTypes.h"
2025 #include
2126 using namespace llvm;
2227
3843 "Cannot create non-first-class values except for constants!");
3944 }
4045
41 Value::~Value() {
46 Value::~Value()
47 {
48 switch(SubclassID)
49 {
50 case ArgumentVal:
51 Argument::destroyThis(cast(this));
52 break;
53 case BasicBlockVal:
54 BasicBlock::destroyThis(cast(this));
55 break;
56 case FunctionVal:
57 Function::destroyThis(cast(this));
58 break;
59 case GlobalAliasVal:
60 GlobalAlias::destroyThis(cast(this));
61 break;
62 case GlobalVariableVal:
63 GlobalVariable::destroyThis(cast(this));
64 break;
65 case UndefValueVal:
66 UndefValue::destroyThis(cast(this));
67 break;
68 case ConstantExprVal:
69 {
70 ConstantExpr* CE = dyn_cast(this);
71 if(CE->getOpcode() == Instruction::GetElementPtr)
72 {
73 GetElementPtrConstantExpr* GECE =
74 dyn_cast(CE);
75 GetElementPtrConstantExpr::destroyThis(GECE);
76 }
77 else if(CE->getOpcode() == Instruction::ExtractElement)
78 {
79 ExtractElementConstantExpr* EECE =
80 dyn_cast(CE);
81 ExtractElementConstantExpr::destroyThis(EECE);
82 }
83 else if(CE->getOpcode() == Instruction::InsertElement)
84 {
85 InsertElementConstantExpr* IECE =
86 dyn_cast(CE);
87 InsertElementConstantExpr::destroyThis(IECE);
88 }
89 else if(CE->getOpcode() == Instruction::Select)
90 {
91 SelectConstantExpr* SCE = dyn_cast(CE);
92 SelectConstantExpr::destroyThis(SCE);
93 }
94 else if(CE->getOpcode() == Instruction::ShuffleVector)
95 {
96 ShuffleVectorConstantExpr* SVCE =
97 dyn_cast(CE);
98 ShuffleVectorConstantExpr::destroyThis(SVCE);
99 }
100 else if(BinaryConstantExpr* BCE = dyn_cast(this))
101 BinaryConstantExpr::destroyThis(BCE);
102 else if(UnaryConstantExpr* UCE = dyn_cast(this))
103 UnaryConstantExpr::destroyThis(UCE);
104 else if(CompareConstantExpr* CCE = dyn_cast(this))
105 CompareConstantExpr::destroyThis(CCE);
106 else
107 assert(0 && "Unknown ConstantExpr-inherited class in ~Value.");
108 }
109 break;
110 case ConstantAggregateZeroVal:
111 ConstantAggregateZero::destroyThis(cast(this));
112 break;
113 case ConstantIntVal:
114 ConstantInt::destroyThis(cast(this));
115 break;
116 case ConstantFPVal:
117 ConstantFP::destroyThis(cast(this));
118 break;
119 case ConstantArrayVal:
120 ConstantArray::destroyThis(cast(this));
121 break;
122 case ConstantStructVal:
123 ConstantStruct::destroyThis(cast(this));
124 break;
125 case ConstantVectorVal:
126 ConstantVector::destroyThis(cast(this));
127 break;
128 case ConstantPointerNullVal:
129 ConstantPointerNull::destroyThis(cast(this));
130 break;
131 case InlineAsmVal:
132 InlineAsm::destroyThis(cast(this));
133 break;
134
135 default:
136 if (BinaryOperator *BO = dyn_cast(this))
137 BinaryOperator::destroyThis(BO);
138 else if (CallInst *CI = dyn_cast(this))
139 {
140 if(IntrinsicInst* II = dyn_cast(this))
141 {
142 if(DbgInfoIntrinsic* DII = dyn_cast(this))
143 {
144 if(DbgDeclareInst* DDI = dyn_cast(this))
145 DbgDeclareInst::destroyThis(DDI);
146 else if(DbgFuncStartInst* DFSI = dyn_cast(this))
147 DbgFuncStartInst::destroyThis(DFSI);
148 else if(DbgRegionEndInst* DREI = dyn_cast(this))
149 DbgRegionEndInst::destroyThis(DREI);
150 else if(DbgRegionStartInst* DRSI = dyn_cast(this))
151 DbgRegionStartInst::destroyThis(DRSI);
152 else if(DbgStopPointInst* DSPI = dyn_cast(this))
153 DbgStopPointInst::destroyThis(DSPI);
154 else
155 assert(0 && "Unknown DbgInfo-inherited class in ~Value.");
156 }
157 else if(MemIntrinsic* MI = dyn_cast(this))
158 {
159 if(MemCpyInst* MCI = dyn_cast(this))
160 MemCpyInst::destroyThis(MCI);
161 else if(MemMoveInst* MMI = dyn_cast(this))
162 MemMoveInst::destroyThis(MMI);
163 else if(MemSetInst* MSI = dyn_cast(this))
164 MemSetInst::destroyThis(MSI);
165 else
166 assert(0 && "Unknown MemIntrinsic-inherited class in ~Value.");
167 }
168 else
169 assert(0 && "Unknown IntrinsicInst-inherited class in ~Value.");
170 }
171 else
172 assert(0 && "Unknown CallInst-inherited class in ~Value.");
173 }
174 else if (CmpInst *CI = dyn_cast(this))
175 {
176 if (FCmpInst *FCI = dyn_cast(this))
177 FCmpInst::destroyThis(FCI);
178 else if (ICmpInst *ICI = dyn_cast(this))
179 ICmpInst::destroyThis(ICI);
180 else
181 assert(0 && "Unknown CmpInst-inherited class in ~Value.");
182 }
183 else if (ExtractElementInst *EEI = dyn_cast(this))
184 ExtractElementInst::destroyThis(EEI);
185 else if (GetElementPtrInst *GEP = dyn_cast(this))
186 GetElementPtrInst::destroyThis(GEP);
187 else if (InsertElementInst* IE = dyn_cast(this))
188 InsertElementInst::destroyThis(IE);
189 else if (PHINode *PN = dyn_cast(this))
190 PHINode::destroyThis(PN);
191 else if (SelectInst *SI = dyn_cast(this))
192 SelectInst::destroyThis(SI);
193 else if (ShuffleVectorInst *SVI = dyn_cast(this))
194 ShuffleVectorInst::destroyThis(SVI);
195 else if (StoreInst *SI = dyn_cast(this))
196 StoreInst::destroyThis(SI);
197 else if (TerminatorInst *TI = dyn_cast(this))
198 {
199 if (BranchInst* BI = dyn_cast(this))
200 BranchInst::destroyThis(BI);
201 else if (InvokeInst* II = dyn_cast(this))
202 InvokeInst::destroyThis(II);
203 else if (ReturnInst* RI = dyn_cast(this))
204 ReturnInst::destroyThis(RI);
205 else if (SwitchInst *SI = dyn_cast(this))
206 SwitchInst::destroyThis(SI);
207 else if (UnreachableInst *UI = dyn_cast(this))
208 UnreachableInst::destroyThis(UI);
209 else if (UnwindInst *UI = dyn_cast(this))
210 UnwindInst::destroyThis(UI);
211 else
212 assert(0 && "Unknown TerminatorInst-inherited class in ~Value.");
213 }
214 else if(UnaryInstruction* UI = dyn_cast(this))
215 {
216 if(AllocationInst* AI = dyn_cast(this))
217 {
218 if(AllocaInst* AI = dyn_cast(this))
219 AllocaInst::destroyThis(AI);
220 else if(MallocInst* MI = dyn_cast(this))
221 MallocInst::destroyThis(MI);
222 else
223 assert(0 && "Unknown AllocationInst-inherited class in ~Value.");
224 }
225 else if(CastInst* CI = dyn_cast(this))
226 {
227 if(BitCastInst* BCI = dyn_cast(this))
228 BitCastInst::destroyThis(BCI);
229 else if(FPExtInst* FPEI = dyn_cast(this))
230 FPExtInst::destroyThis(FPEI);
231 else if(FPToSIInst* FPSII = dyn_cast(this))
232 FPToSIInst::destroyThis(FPSII);
233 else if(FPToUIInst* FPUII = dyn_cast(this))
234 FPToUIInst::destroyThis(FPUII);
235 else if(FPTruncInst* FPTI = dyn_cast(this))
236 FPTruncInst::destroyThis(FPTI);
237 else if(IntToPtrInst* I2PI = dyn_cast(this))
238 IntToPtrInst::destroyThis(I2PI);
239 else if(PtrToIntInst* P2II = dyn_cast(this))
240 PtrToIntInst::destroyThis(P2II);
241 else if(SExtInst* SEI = dyn_cast(this))
242 SExtInst::destroyThis(SEI);
243 else if(SIToFPInst* SIFPI = dyn_cast(this))
244 SIToFPInst::destroyThis(SIFPI);
245 else if(TruncInst* TI = dyn_cast(this))
246 TruncInst::destroyThis(TI);
247 else if(UIToFPInst* UIFPI = dyn_cast(this))
248 UIToFPInst::destroyThis(UIFPI);
249 else if(ZExtInst* ZEI = dyn_cast(this))
250 ZExtInst::destroyThis(ZEI);
251 else
252 assert(0 && "Unknown CastInst-inherited class in ~Value.");
253 }
254 else if(FreeInst* FI = dyn_cast(this))
255 FreeInst::destroyThis(FI);
256 else if(LoadInst* LI = dyn_cast(this))
257 LoadInst::destroyThis(LI);
258 else if(VAArgInst* VAI = dyn_cast(this))
259 VAArgInst::destroyThis(VAI);
260 else
261 assert(0 && "Unknown UnaryInstruction-inherited class in ~Value.");
262 }
263 else if (DummyInst *DI = dyn_cast(this))
264 DummyInst::destroyThis(DI);
265 else
266 assert(0 && "Unknown Instruction-inherited class in ~Value.");
267 break;
268 }
269 }
270
271 void Value::destroyThis(Value*v)
272 {
42273 #ifndef NDEBUG // Only in -g mode...
43274 // Check to make sure that there are no uses of this value that are still
44275 // around when the value is destroyed. If there are, then we have a dangling
46277 // still being referenced. The value in question should be printed as
47278 // a
48279 //
49 if (!use_empty()) {
50 DOUT << "While deleting: " << *Ty << " %" << Name << "\n";
51 for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)
280 if (!v->use_empty()) {
281 DOUT << "While deleting: " << *v->Ty << " %" << v->Name << "\n";
282 for (use_iterator I = v->use_begin(), E = v->use_end(); I != E; ++I)
52283 DOUT << "Use still stuck around after Def is destroyed:"
53284 << **I << "\n";
54285 }
55286 #endif
56 assert(use_empty() && "Uses remain when a value is destroyed!");
287 assert(v->use_empty() && "Uses remain when a value is destroyed!");
57288
58289 // If this value is named, destroy the name. This should not be in a symtab
59290 // at this point.
60 if (Name)
61 Name->Destroy();
291 if (v->Name)
292 v->Name->Destroy();
62293
63294 // There should be no uses of this object anymore, remove it.
64 LeakDetector::removeGarbageObject(this);
295 LeakDetector::removeGarbageObject(v);
65296 }
66297
67298 /// hasNUses - Return true if this Value has exactly N users.