aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-31 00:58:22 +0000
committerDan Gohman <gohman@apple.com>2008-05-31 00:58:22 +0000
commit81a0c0b44e582baca8b68754a7fcabfc3aef2e7a (patch)
tree0b0d24cd0d230447b1d8419bb0360c74955fdda1 /lib/Bitcode
parent652f7ea955bb433d6b7a4d33685dca9485fd7b8b (diff)
downloadexternal_llvm-81a0c0b44e582baca8b68754a7fcabfc3aef2e7a.zip
external_llvm-81a0c0b44e582baca8b68754a7fcabfc3aef2e7a.tar.gz
external_llvm-81a0c0b44e582baca8b68754a7fcabfc3aef2e7a.tar.bz2
IR, bitcode reader, bitcode writer, and asmparser changes to
insertvalue and extractvalue to use constant indices instead of Value* indices. And begin updating LangRef.html. There's definately more to come here, but I'm checking this basic support in now to make it available to people who are interested. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51806 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp88
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp26
2 files changed, 71 insertions, 43 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 818b47c..60767bd 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -770,27 +770,45 @@ bool BitcodeReader::ParseConstants() {
V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
break;
}
- case bitc::CST_CODE_CE_EXTRACTVAL: { // CE_EXTRACTVAL: [n x operands]
- if (Record.size() & 1) return Error("Invalid CE_EXTRACTVAL record");
- SmallVector<Constant*, 16> Elts;
- for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
- const Type *ElTy = getTypeByID(Record[i]);
- if (!ElTy) return Error("Invalid CE_EXTRACTVAL record");
- Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
+ case bitc::CST_CODE_CE_EXTRACTVAL: {
+ // CE_EXTRACTVAL: [opty, opval, n x indices]
+ const Type *AggTy = getTypeByID(Record[0]);
+ if (!AggTy || !AggTy->isAggregateType())
+ return Error("Invalid CE_INSERTVAL record");
+ Constant *Agg = ValueList.getConstantFwdRef(Record[1], AggTy);
+ SmallVector<unsigned, 4> Indices;
+ for (unsigned i = 2, e = Record.size(); i != e; ++i) {
+ uint64_t Index = Record[i];
+ if ((unsigned)Index != Index)
+ return Error("Invalid CE_EXTRACTVAL record");
+ Indices.push_back((unsigned)Index);
}
- V = ConstantExpr::getExtractValue(Elts[0], &Elts[1], Elts.size()-1);
- break;
- }
- case bitc::CST_CODE_CE_INSERTVAL: { // CE_INSERTVAL: [n x operands]
- if (Record.size() & 1) return Error("Invalid CE_INSERTVAL record");
- SmallVector<Constant*, 16> Elts;
- for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
- const Type *ElTy = getTypeByID(Record[i]);
- if (!ElTy) return Error("Invalid CE_INSERTVAL record");
- Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
+ if (!ExtractValueInst::getIndexedType(AggTy,
+ Indices.begin(), Indices.end()))
+ return Error("Invalid CE_EXTRACTVAL record");
+ V = ConstantExpr::getExtractValue(Agg, &Indices[0], Indices.size());
+ break;
+ }
+ case bitc::CST_CODE_CE_INSERTVAL: {
+ // CE_INSERTVAL: [opty, opval, opty, opval, n x indices]
+ const Type *AggTy = getTypeByID(Record[0]);
+ if (!AggTy || !AggTy->isAggregateType())
+ return Error("Invalid CE_INSERTVAL record");
+ Constant *Agg = ValueList.getConstantFwdRef(Record[1], AggTy);
+ const Type *ValTy = getTypeByID(Record[2]);
+ Constant *Val = ValueList.getConstantFwdRef(Record[2], ValTy);
+ SmallVector<unsigned, 4> Indices;
+ for (unsigned i = 4, e = Record.size(); i != e; ++i) {
+ uint64_t Index = Record[i];
+ if ((unsigned)Index != Index)
+ return Error("Invalid CE_INSERTVAL record");
+ Indices.push_back((unsigned)Index);
}
- V = ConstantExpr::getInsertValue(Elts[0], Elts[1],
- &Elts[2], Elts.size()-1);
+ if (ExtractValueInst::getIndexedType(AggTy,
+ Indices.begin(),
+ Indices.end()) != ValTy)
+ return Error("Invalid CE_INSERTVAL record");
+ V = ConstantExpr::getInsertValue(Agg, Val, &Indices[0], Indices.size());
break;
}
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
@@ -1324,18 +1342,20 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
break;
}
- case bitc::FUNC_CODE_INST_EXTRACTVAL: { // EXTRACTVAL: [n x operands]
+ case bitc::FUNC_CODE_INST_EXTRACTVAL: {
+ // EXTRACTVAL: [opty, opval, n x indices]
unsigned OpNum = 0;
Value *Agg;
if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
return Error("Invalid EXTRACTVAL record");
- SmallVector<Value*, 16> EXTRACTVALIdx;
- while (OpNum != Record.size()) {
- Value *Op;
- if (getValueTypePair(Record, OpNum, NextValueNo, Op))
- return Error("Invalid EXTRACTVAL record");
- EXTRACTVALIdx.push_back(Op);
+ SmallVector<unsigned, 4> EXTRACTVALIdx;
+ for (unsigned RecSize = Record.size();
+ OpNum != RecSize; ++OpNum) {
+ uint64_t Index = Record[OpNum];
+ if ((unsigned)Index != Index)
+ return Error("Invalid EXTRACTVAL index");
+ EXTRACTVALIdx.push_back((unsigned)Index);
}
I = ExtractValueInst::Create(Agg,
@@ -1343,7 +1363,8 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
break;
}
- case bitc::FUNC_CODE_INST_INSERTVAL: { // INSERTVAL: [n x operands]
+ case bitc::FUNC_CODE_INST_INSERTVAL: {
+ // INSERTVAL: [opty, opval, opty, opval, n x indices]
unsigned OpNum = 0;
Value *Agg;
if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
@@ -1352,12 +1373,13 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
if (getValueTypePair(Record, OpNum, NextValueNo, Val))
return Error("Invalid INSERTVAL record");
- SmallVector<Value*, 16> INSERTVALIdx;
- while (OpNum != Record.size()) {
- Value *Op;
- if (getValueTypePair(Record, OpNum, NextValueNo, Op))
- return Error("Invalid INSERTVAL record");
- INSERTVALIdx.push_back(Op);
+ SmallVector<unsigned, 4> INSERTVALIdx;
+ for (unsigned RecSize = Record.size();
+ OpNum != RecSize; ++OpNum) {
+ uint64_t Index = Record[OpNum];
+ if ((unsigned)Index != Index)
+ return Error("Invalid INSERTVAL index");
+ INSERTVALIdx.push_back((unsigned)Index);
}
I = InsertValueInst::Create(Agg, Val,
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index cb5963c..376cc05 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -610,20 +610,26 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
Record.push_back(VE.getValueID(C->getOperand(i)));
}
break;
- case Instruction::ExtractValue:
+ case Instruction::ExtractValue: {
Code = bitc::CST_CODE_CE_EXTRACTVAL;
- for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
- Record.push_back(VE.getTypeID(C->getOperand(i)->getType()));
- Record.push_back(VE.getValueID(C->getOperand(i)));
- }
+ Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
+ Record.push_back(VE.getValueID(C->getOperand(0)));
+ const SmallVector<unsigned, 4> &Indices = CE->getIndices();
+ for (unsigned i = 0, e = Indices.size(); i != e; ++i)
+ Record.push_back(Indices[i]);
break;
- case Instruction::InsertValue:
+ }
+ case Instruction::InsertValue: {
Code = bitc::CST_CODE_CE_INSERTVAL;
- for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
- Record.push_back(VE.getTypeID(C->getOperand(i)->getType()));
- Record.push_back(VE.getValueID(C->getOperand(i)));
- }
+ Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
+ Record.push_back(VE.getValueID(C->getOperand(0)));
+ Record.push_back(VE.getTypeID(C->getOperand(1)->getType()));
+ Record.push_back(VE.getValueID(C->getOperand(1)));
+ const SmallVector<unsigned, 4> &Indices = CE->getIndices();
+ for (unsigned i = 0, e = Indices.size(); i != e; ++i)
+ Record.push_back(Indices[i]);
break;
+ }
case Instruction::Select:
Code = bitc::CST_CODE_CE_SELECT;
Record.push_back(VE.getValueID(C->getOperand(0)));