aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-02-26 01:29:32 +0000
committerDevang Patel <dpatel@apple.com>2008-02-26 01:29:32 +0000
commitd9d99ff8e8fe2897a3d45609763aeb8088b63afa (patch)
treec9a3f4f0dcc9385286a1dff457568ea18e5328ae /lib/Bitcode
parentaaeb60ae4028c841bf009173529d91a45f370756 (diff)
downloadexternal_llvm-d9d99ff8e8fe2897a3d45609763aeb8088b63afa.zip
external_llvm-d9d99ff8e8fe2897a3d45609763aeb8088b63afa.tar.gz
external_llvm-d9d99ff8e8fe2897a3d45609763aeb8088b63afa.tar.bz2
Update bitcode reader and writer to handle multiple return values.
Take 2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47583 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp29
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp23
2 files changed, 34 insertions, 18 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index ebfca09..487a135 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1337,17 +1337,24 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
case bitc::FUNC_CODE_INST_RET: // RET: [opty,opval<optional>]
- 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<Value *> 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/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 9b2b93c..6a54514 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/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<GetResultInst>(I).getIndex())+1);
+ Vals.push_back(cast<GetResultInst>(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;