X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FInstructions.cpp;h=c0b3413da33782870832f11d011181ba3ab69485;hb=e6be34a53ecbe8c2ff9f0793b13d847e94c0de91;hp=457987a176a0f727bb96eab231fd21edc8d69fca;hpb=22c3979fcaa7ff19c44253eb9b0b0160dfef0aa4;p=oota-llvm.git diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 457987a176a..c0b3413da33 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -574,30 +574,66 @@ bool InvokeInst::isStructReturn() const { ReturnInst::ReturnInst(const ReturnInst &RI) : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, RI.getNumOperands()) { - if (RI.getNumOperands()) + unsigned N = RI.getNumOperands(); + if (N == 1) RetVal.init(RI.RetVal, this); + else if (N) { + Use *OL = OperandList = new Use[N]; + for (unsigned i = 0; i < N; ++i) + OL[i].init(RI.getOperand(i), this); + } } 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) { } +ReturnInst::ReturnInst(Value * const* retVals, unsigned N, + Instruction *InsertBefore) + : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, N, InsertBefore) { + if (N != 0) + init(retVals, N); +} +ReturnInst::ReturnInst(Value * const* retVals, unsigned N, + BasicBlock *InsertAtEnd) + : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, N, InsertAtEnd) { + if (N != 0) + init(retVals, N); +} +ReturnInst::ReturnInst(Value * const* retVals, unsigned N) + : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, N) { + if (N != 0) + init(retVals, N); +} + +void ReturnInst::init(Value * const* retVals, unsigned N) { + assert (N > 0 && "Invalid operands numbers in ReturnInst init"); + NumOperands = N; + if (NumOperands == 1) { + Value *V = *retVals; + if (V->getType() == Type::VoidTy) + return; + RetVal.init(V, this); + return; + } -void ReturnInst::init(Value *retVal) { - if (retVal && retVal->getType() != Type::VoidTy) { - assert(!isa(retVal) && + Use *OL = OperandList = new Use[NumOperands]; + for (unsigned i = 0; i < NumOperands; ++i) { + Value *V = *retVals++; + assert(!isa(V) && "Cannot return basic block. Probably using the incorrect ctor"); - NumOperands = 1; - RetVal.init(retVal, this); + OL[i].init(V, this); } } @@ -605,8 +641,8 @@ unsigned ReturnInst::getNumSuccessorsV() const { return getNumSuccessors(); } -// Out-of-line ReturnInst method, put here so the C++ compiler can choose to -// emit the vtable for the class in this translation unit. +/// Out-of-line ReturnInst method, put here so the C++ compiler can choose to +/// emit the vtable for the class in this translation unit. void ReturnInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) { assert(0 && "ReturnInst has no successors!"); } @@ -617,6 +653,10 @@ BasicBlock *ReturnInst::getSuccessorV(unsigned idx) const { return 0; } +ReturnInst::~ReturnInst() { + if (NumOperands > 1) + delete [] OperandList; +} //===----------------------------------------------------------------------===// // UnwindInst Implementation @@ -2759,7 +2799,6 @@ bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) { return false; } - // Define these methods here so vtables don't get emitted into every translation // unit that uses these classes.