ReturnInst::ReturnInst(const ReturnInst &RI)
: TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandList, RI.getNumOperands()) {
+ &RetVal, RI.getNumOperands()) {
unsigned N = RI.getNumOperands();
- Use *OL = OperandList = new Use[N];
- for (unsigned i = 0; i < N; ++i)
- OL[i].init(RI.getOperand(i), this);
+ 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, OperandList, 0, InsertBefore) {
- init(retVal);
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertBefore) {
+ if (retVal)
+ init(&retVal, 1);
}
ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Ret, OperandList, 0, InsertAtEnd) {
- init(retVal);
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) {
+ if (retVal)
+ init(&retVal, 1);
}
ReturnInst::ReturnInst(BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Ret, OperandList, 0, InsertAtEnd) {
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, 0, InsertAtEnd) {
}
-ReturnInst::ReturnInst(const std::vector<Value *> &retVals, Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Ret, OperandList, retVals.size(), InsertBefore) {
- init(retVals);
-}
-ReturnInst::ReturnInst(const std::vector<Value *> &retVals, BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Ret, OperandList, retVals.size(), InsertAtEnd) {
- init(retVals);
+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(const std::vector<Value *> &retVals)
- : TerminatorInst(Type::VoidTy, Instruction::Ret, OperandList, retVals.size()) {
- init(retVals);
+ReturnInst::ReturnInst(Value * const* retVals, unsigned N,
+ BasicBlock *InsertAtEnd)
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, N, InsertAtEnd) {
+ if (N != 0)
+ init(retVals, N);
}
-
-void ReturnInst::init(Value *retVal) {
- if (retVal && retVal->getType() != Type::VoidTy) {
- assert(!isa<BasicBlock>(retVal) &&
- "Cannot return basic block. Probably using the incorrect ctor");
- NumOperands = 1;
- Use *OL = OperandList = new Use[1];
- OL[0].init(retVal, this);
- }
+ReturnInst::ReturnInst(Value * const* retVals, unsigned N)
+ : TerminatorInst(Type::VoidTy, Instruction::Ret, &RetVal, N) {
+ if (N != 0)
+ init(retVals, N);
}
-void ReturnInst::init(const std::vector<Value *> &retVals) {
- if (retVals.empty())
- return;
+void ReturnInst::init(Value * const* retVals, unsigned N) {
+ assert (N > 0 && "Invalid operands numbers in ReturnInst init");
- NumOperands = retVals.size();
+ NumOperands = N;
if (NumOperands == 1) {
- Value *V = retVals[0];
+ Value *V = *retVals;
if (V->getType() == Type::VoidTy)
return;
+ RetVal.init(V, this);
+ return;
}
Use *OL = OperandList = new Use[NumOperands];
for (unsigned i = 0; i < NumOperands; ++i) {
- Value *V = retVals[i];
+ Value *V = *retVals++;
assert(!isa<BasicBlock>(V) &&
"Cannot return basic block. Probably using the incorrect ctor");
OL[i].init(V, this);
}
}
-Value *ReturnInst::getReturnValue(unsigned n) const {
- if (NumOperands)
- return OperandList[n];
- else
- return 0;
-}
-
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!");
}
}
ReturnInst::~ReturnInst() {
- if (NumOperands)
+ if (NumOperands > 1)
delete [] OperandList;
}