From bbfd874cb4269afe358d2375a8974aa75a71074a Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 26 Feb 2008 01:29:32 +0000 Subject: [PATCH] Update bitcode reader and writer to handle multiple return values. Take 2. llvm-svn: 47583 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 29 ++++++++++++------- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 23 ++++++++++----- .../2008-02-20-MultipleReturnValue.ll | 2 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index ebfca09c4912..487a135509c4 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1337,17 +1337,24 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { } case bitc::FUNC_CODE_INST_RET: // RET: [opty,opval] - if (Record.empty()) { - I = new ReturnInst(); - break; - } else { - unsigned OpNum = 0; - Value *Op; - if (getValueTypePair(Record, OpNum, NextValueNo, Op) || - OpNum != Record.size()) - return Error("Invalid RET record"); - I = new ReturnInst(Op); - break; + { + unsigned Size = Record.size(); + if (Size == 0) { + I = new ReturnInst(); + break; + } else { + unsigned OpNum = 0; + std::vector Vs; + do { + Value *Op = NULL; + if (getValueTypePair(Record, OpNum, NextValueNo, Op)) + return Error("Invalid RET record"); + Vs.push_back(Op); + } while(OpNum != Record.size()); + + I = new ReturnInst(Vs); + break; + } } case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#] if (Record.size() != 1 && Record.size() != 3) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 9b2b93cfceaa..6a54514db6d1 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -747,15 +747,24 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, case Instruction::GetResult: Code = bitc::FUNC_CODE_INST_GETRESULT; PushValueAndType(I.getOperand(0), InstID, Vals, VE); - Vals.push_back(Log2_32(cast(I).getIndex())+1); + Vals.push_back(cast(I).getIndex()); break; - case Instruction::Ret: - Code = bitc::FUNC_CODE_INST_RET; - if (!I.getNumOperands()) - AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV; - else if (!PushValueAndType(I.getOperand(0), InstID, Vals, VE)) - AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV; + case Instruction::Ret: + { + Code = bitc::FUNC_CODE_INST_RET; + unsigned NumOperands = I.getNumOperands(); + // printf ("dpatel write %d\n", NumOperands); + if (NumOperands == 0) + AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV; + else if (NumOperands == 1) { + if (!PushValueAndType(I.getOperand(0), InstID, Vals, VE)) + AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV; + } else { + for (unsigned i = 0, e = NumOperands; i != e; ++i) + PushValueAndType(I.getOperand(i), InstID, Vals, VE); + } + } break; case Instruction::Br: Code = bitc::FUNC_CODE_INST_BR; diff --git a/llvm/test/Assembler/2008-02-20-MultipleReturnValue.ll b/llvm/test/Assembler/2008-02-20-MultipleReturnValue.ll index f84ceef293bd..5b2ed7e8f480 100644 --- a/llvm/test/Assembler/2008-02-20-MultipleReturnValue.ll +++ b/llvm/test/Assembler/2008-02-20-MultipleReturnValue.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s -disable-output +; RUN: llvm-as < %s | opt -verify | llvm-dis | llvm-as -disable-output define {i32, i8} @foo(i32 %p) { ret i32 1, i8 2