From 814ebd77b015c9e95afa6be74cb7e7a636baa7f4 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 26 Feb 2008 18:49:29 +0000 Subject: [PATCH] Unify to ReturnInst::init() member functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47611 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Instructions.h | 3 +-- lib/VMCore/Instructions.cpp | 39 ++++++++++++++++--------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 70a98d78bed..75ae5c1ae42 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -1381,8 +1381,7 @@ public: class ReturnInst : public TerminatorInst { Use RetVal; ReturnInst(const ReturnInst &RI); - void init(Value *RetVal); - void init(const std::vector &RetVals); + void init(const Value * const* retVals, unsigned N); public: // ReturnInst constructors: diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 163601a6c13..e0c14b83286 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -586,11 +586,13 @@ ReturnInst::ReturnInst(const ReturnInst &RI) ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertBefore) { - init(retVal); + if (retVal) + init(&retVal, 1); } ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) { - init(retVal); + if (retVal) + init(&retVal, 1); } ReturnInst::ReturnInst(BasicBlock *InsertAtEnd) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) { @@ -600,48 +602,41 @@ ReturnInst::ReturnInst(const std::vector &retVals, Instruction *InsertBefore) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, retVals.size(), InsertBefore) { - init(retVals); + if (!retVals.empty()) + init(&retVals[0], retVals.size()); } ReturnInst::ReturnInst(const std::vector &retVals, BasicBlock *InsertAtEnd) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, retVals.size(), InsertAtEnd) { - init(retVals); + if (!retVals.empty()) + init(&retVals[0], retVals.size()); } ReturnInst::ReturnInst(const std::vector &retVals) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, retVals.size()) { - init(retVals); + if (!retVals.empty()) + init(&retVals[0], retVals.size()); } -void ReturnInst::init(Value *retVal) { - if (retVal && retVal->getType() != Type::VoidTy) { - assert(!isa(retVal) && - "Cannot return basic block. Probably using the incorrect ctor"); - NumOperands = 1; - RetVal.init(retVal, this); - } -} +void ReturnInst::init(const Value * const* retVals, unsigned N) { -void ReturnInst::init(const std::vector &retVals) { - if (retVals.empty()) - return; + assert (N > 0 && "Invalid operands numbers in ReturnInst init"); - NumOperands = retVals.size(); + NumOperands = N; if (NumOperands == 1) { - Value *V = retVals[0]; + const Value *V = *retVals; if (V->getType() == Type::VoidTy) return; - RetVal.init(V, this); + RetVal.init(const_cast(V), this); return; } Use *OL = OperandList = new Use[NumOperands]; - RetVal.init(retVals[0], this); for (unsigned i = 0; i < NumOperands; ++i) { - Value *V = retVals[i]; + const Value *V = *retVals++; assert(!isa(V) && "Cannot return basic block. Probably using the incorrect ctor"); - OL[i].init(V, this); + OL[i].init(const_cast(V), this); } } -- 2.34.1