From 910c80a07503591052a77cefb26cebea95a8d743 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 24 Feb 2007 00:55:48 +0000 Subject: Refactor the setName stuff, moving it down the inheritance hierarchy, to solve a crash in -instcombine -debug that was hit while investigating PR1217 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34544 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InstrTypes.h | 44 ++++++------------- include/llvm/Instruction.h | 8 +--- include/llvm/Instructions.h | 104 +++++++++++--------------------------------- 3 files changed, 41 insertions(+), 115 deletions(-) (limited to 'include') diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index ce5885f..5439337 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -29,19 +29,14 @@ namespace llvm { /// class TerminatorInst : public Instruction { protected: - TerminatorInst(Instruction::TermOps iType, Use *Ops, unsigned NumOps, - Instruction *InsertBefore = 0); TerminatorInst(const Type *Ty, Instruction::TermOps iType, - Use *Ops, unsigned NumOps, - const std::string &Name = "", Instruction *InsertBefore = 0) - : Instruction(Ty, iType, Ops, NumOps, Name, InsertBefore) {} + Use *Ops, unsigned NumOps, + Instruction *InsertBefore = 0) + : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {} - TerminatorInst(Instruction::TermOps iType, Use *Ops, unsigned NumOps, - BasicBlock *InsertAtEnd); TerminatorInst(const Type *Ty, Instruction::TermOps iType, - Use *Ops, unsigned NumOps, - const std::string &Name, BasicBlock *InsertAtEnd) - : Instruction(Ty, iType, Ops, NumOps, Name, InsertAtEnd) {} + Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd) + : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {} // Out of line virtual method, so the vtable, etc has a home. ~TerminatorInst(); @@ -90,13 +85,11 @@ public: class UnaryInstruction : public Instruction { Use Op; protected: - UnaryInstruction(const Type *Ty, unsigned iType, Value *V, - const char *Name = 0, Instruction *IB = 0) - : Instruction(Ty, iType, &Op, 1, Name, IB), Op(V, this) { + UnaryInstruction(const Type *Ty, unsigned iType, Value *V, Instruction *IB =0) + : Instruction(Ty, iType, &Op, 1, IB), Op(V, this) { } - UnaryInstruction(const Type *Ty, unsigned iType, Value *V, - const char *Name, BasicBlock *IAE) - : Instruction(Ty, iType, &Op, 1, Name, IAE), Op(V, this) { + UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE) + : Instruction(Ty, iType, &Op, 1, IAE), Op(V, this) { } public: // Out of line virtual method, so the vtable, etc has a home. @@ -123,20 +116,9 @@ class BinaryOperator : public Instruction { protected: void init(BinaryOps iType); BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty, - const std::string &Name, Instruction *InsertBefore) - : Instruction(Ty, iType, Ops, 2, Name, InsertBefore) { - Ops[0].init(S1, this); - Ops[1].init(S2, this); - init(iType); - } + const std::string &Name, Instruction *InsertBefore); BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty, - const std::string &Name, BasicBlock *InsertAtEnd) - : Instruction(Ty, iType, Ops, 2, Name, InsertAtEnd) { - Ops[0].init(S1, this); - Ops[1].init(S2, this); - init(iType); - } - + const std::string &Name, BasicBlock *InsertAtEnd); public: /// Transparently provide more efficient getOperand methods. @@ -264,13 +246,13 @@ protected: /// @brief Constructor with insert-before-instruction semantics for subclasses CastInst(const Type *Ty, unsigned iType, Value *S, const std::string &Name = "", Instruction *InsertBefore = 0) - : UnaryInstruction(Ty, iType, S, 0, InsertBefore) { + : UnaryInstruction(Ty, iType, S, InsertBefore) { setName(Name); } /// @brief Constructor with insert-at-end-of-block semantics for subclasses CastInst(const Type *Ty, unsigned iType, Value *S, const std::string &Name, BasicBlock *InsertAtEnd) - : UnaryInstruction(Ty, iType, S, 0, InsertAtEnd) { + : UnaryInstruction(Ty, iType, S, InsertAtEnd) { setName(Name); } public: diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 239e878..bda59e9 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -41,13 +41,9 @@ class Instruction : public User { void setParent(BasicBlock *P); protected: Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, - const std::string &Name, Instruction *InsertBefore = 0); + Instruction *InsertBefore = 0); Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, - const std::string &Name, BasicBlock *InsertAtEnd); - Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, - const char *Name = 0, Instruction *InsertBefore = 0); - Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, - const char *Name, BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd); public: // Out of line virtual method, so the vtable, etc has a home. ~Instruction(); diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 259b5aa..c78426a 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -773,15 +773,15 @@ class SelectInst : public Instruction { public: SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "", Instruction *InsertBefore = 0) - : Instruction(S1->getType(), Instruction::Select, Ops, 3, - Name, InsertBefore) { + : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) { init(C, S1, S2); + setName(Name); } SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, BasicBlock *InsertAtEnd) - : Instruction(S1->getType(), Instruction::Select, Ops, 3, - Name, InsertAtEnd) { + : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) { init(C, S1, S2); + setName(Name); } Value *getCondition() const { return Ops[0]; } @@ -828,12 +828,12 @@ class VAArgInst : public UnaryInstruction { public: VAArgInst(Value *List, const Type *Ty, const std::string &Name = "", Instruction *InsertBefore = 0) - : UnaryInstruction(Ty, VAArg, List, 0, InsertBefore) { + : UnaryInstruction(Ty, VAArg, List, InsertBefore) { setName(Name); } VAArgInst(Value *List, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) - : UnaryInstruction(Ty, VAArg, List, 0, InsertAtEnd) { + : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { setName(Name); } @@ -1022,13 +1022,15 @@ class PHINode : public Instruction { public: explicit PHINode(const Type *Ty, const std::string &Name = "", Instruction *InsertBefore = 0) - : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore), + : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), ReservedSpace(0) { + setName(Name); } PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) - : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd), + : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), ReservedSpace(0) { + setName(Name); } ~PHINode(); @@ -1143,13 +1145,8 @@ public: /// does not continue in this function any longer. /// class ReturnInst : public TerminatorInst { - Use RetVal; // Possibly null retval. - ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal, - RI.getNumOperands()) { - if (RI.getNumOperands()) - RetVal.init(RI.RetVal, this); - } - + Use RetVal; // Return Value: null if 'void'. + ReturnInst(const ReturnInst &RI); void init(Value *RetVal); public: @@ -1164,17 +1161,9 @@ public: // // NOTE: If the Value* passed is of type void then the constructor behaves as // if it was passed NULL. - explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0) - : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) { - init(retVal); - } - ReturnInst(Value *retVal, BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) { - init(retVal); - } - explicit ReturnInst(BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) { - } + explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0); + ReturnInst(Value *retVal, BasicBlock *InsertAtEnd); + explicit ReturnInst(BasicBlock *InsertAtEnd); virtual ReturnInst *clone() const; @@ -1228,39 +1217,12 @@ public: // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I // BranchInst(BB* B, BB *I) - 'br B' insert at end // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end - explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0) - : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) { - assert(IfTrue != 0 && "Branch destination may not be null!"); - Ops[0].init(reinterpret_cast(IfTrue), this); - } + explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, - Instruction *InsertBefore = 0) - : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) { - Ops[0].init(reinterpret_cast(IfTrue), this); - Ops[1].init(reinterpret_cast(IfFalse), this); - Ops[2].init(Cond, this); -#ifndef NDEBUG - AssertOK(); -#endif - } - - BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) { - assert(IfTrue != 0 && "Branch destination may not be null!"); - Ops[0].init(reinterpret_cast(IfTrue), this); - } - + Instruction *InsertBefore = 0); + BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, - BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) { - Ops[0].init(reinterpret_cast(IfTrue), this); - Ops[1].init(reinterpret_cast(IfFalse), this); - Ops[2].init(Cond, this); -#ifndef NDEBUG - AssertOK(); -#endif - } - + BasicBlock *InsertAtEnd); /// Transparently provide more efficient getOperand methods. Value *getOperand(unsigned i) const { @@ -1348,20 +1310,14 @@ public: /// be specified here to make memory allocation more efficient. This /// constructor can also autoinsert before another instruction. SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, - Instruction *InsertBefore = 0) - : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) { - init(Value, Default, NumCases); - } - + Instruction *InsertBefore = 0); + /// SwitchInst ctor - Create a new switch instruction, specifying a value to /// switch on and a default destination. The number of additional cases can /// be specified here to make memory allocation more efficient. This /// constructor also autoinserts at the end of the specified BasicBlock. SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, - BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) { - init(Value, Default, NumCases); - } + BasicBlock *InsertAtEnd); ~SwitchInst(); @@ -1554,12 +1510,8 @@ private: /// class UnwindInst : public TerminatorInst { public: - explicit UnwindInst(Instruction *InsertBefore = 0) - : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) { - } - explicit UnwindInst(BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) { - } + explicit UnwindInst(Instruction *InsertBefore = 0); + explicit UnwindInst(BasicBlock *InsertAtEnd); virtual UnwindInst *clone() const; @@ -1590,12 +1542,8 @@ private: /// class UnreachableInst : public TerminatorInst { public: - explicit UnreachableInst(Instruction *InsertBefore = 0) - : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) { - } - explicit UnreachableInst(BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) { - } + explicit UnreachableInst(Instruction *InsertBefore = 0); + explicit UnreachableInst(BasicBlock *InsertAtEnd); virtual UnreachableInst *clone() const; -- cgit v1.1