aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-01-20 00:54:06 +0000
committerChris Lattner <sabre@nondot.org>2004-01-20 00:54:06 +0000
commit52f86d624722a0ecedf0556a58460111bc1cccf2 (patch)
treeacd4993787e23e1e845a28e1585386eb25de8f42 /lib/Bytecode
parent54111c49bf0552a5c598b60dda0835ef4a73646b (diff)
Bugfixes for dealing with partially compactified functions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp25
-rw-r--r--lib/Bytecode/Writer/Writer.cpp18
2 files changed, 29 insertions, 14 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index f4b620ed19..dca8890205 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -120,17 +120,29 @@ Value *BytecodeParser::getValue(unsigned type, unsigned oNum, bool Create) {
return CompactionTable[type][Num];
Num -= CompactionTable[type].size();
} else {
+ // If the type plane was compactified, figure out the global type ID.
+ unsigned GlobalTyID = type;
+ if (CompactionTable.size() > Type::TypeTyID &&
+ !CompactionTable[Type::TypeTyID].empty() &&
+ type >= Type::FirstDerivedTyID) {
+ std::vector<Value*> &TypePlane = CompactionTable[Type::TypeTyID];
+ const Type *Ty = cast<Type>(TypePlane[type-Type::FirstDerivedTyID]);
+ TypeValuesListTy::iterator I =
+ find(ModuleTypeValues.begin(), ModuleTypeValues.end(), Ty);
+ assert(I != ModuleTypeValues.end());
+ GlobalTyID = Type::FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
+ }
- if (hasImplicitNull(type, hasExplicitPrimitiveZeros)) {
+ if (hasImplicitNull(GlobalTyID, hasExplicitPrimitiveZeros)) {
if (Num == 0)
return Constant::getNullValue(getType(type));
--Num;
}
- if (type < ModuleValues.size() && ModuleValues[type]) {
- if (Num < ModuleValues[type]->size())
- return ModuleValues[type]->getOperand(Num);
- Num -= ModuleValues[type]->size();
+ if (GlobalTyID < ModuleValues.size() && ModuleValues[GlobalTyID]) {
+ if (Num < ModuleValues[GlobalTyID]->size())
+ return ModuleValues[GlobalTyID]->getOperand(Num);
+ Num -= ModuleValues[GlobalTyID]->size();
}
}
@@ -290,7 +302,8 @@ void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf,
} else {
V = getValue(Typ, slot, false); // Find mapping...
}
- if (V == 0) throw std::string("Failed value look-up.");
+ if (V == 0)
+ throw std::string("Failed value look-up.");
BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << *V;
if (!isa<Instruction>(V)) std::cerr << "\n");
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index a55508e6e0..7cdae16395 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -43,7 +43,7 @@ ConstantTotalBytes("bytecodewriter", "Bytes of constants total");
static Statistic<>
ConstantPlaneHeaderBytes("bytecodewriter", "Constant plane header bytes");
static Statistic<>
-InstructionBytes("bytecodewriter", "Bytes of bytes of instructions");
+InstructionBytes("bytecodewriter", "Bytes of instructions");
static Statistic<>
SymTabBytes("bytecodewriter", "Bytes of symbol table");
static Statistic<>
@@ -160,7 +160,7 @@ static inline bool hasNullValue(unsigned TyID) {
}
void BytecodeWriter::outputConstants(bool isFunction) {
- ConstantTotalBytes -= Out.size();
+ ConstantTotalBytes -= Out.size(); {
BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out,
true /* Elide block if empty */);
@@ -197,7 +197,7 @@ void BytecodeWriter::outputConstants(bool isFunction) {
outputConstantsInPlane(Plane, ValNo);
}
}
- ConstantTotalBytes += Out.size();
+ }ConstantTotalBytes += Out.size();
}
static unsigned getEncodedLinkage(const GlobalValue *GV) {
@@ -289,7 +289,7 @@ void BytecodeWriter::outputCompactionTablePlane(unsigned PlaneNo,
const std::vector<const Value*> &Plane,
unsigned StartNo) {
unsigned End = Table.getModuleLevel(PlaneNo);
- if (StartNo == End || End == 0) return; // Nothing to emit
+ if (Plane.empty() || StartNo == End || End == 0) return; // Nothing to emit
assert(StartNo < End && "Cannot emit negative range!");
assert(StartNo < Plane.size() && End <= Plane.size());
@@ -316,7 +316,7 @@ void BytecodeWriter::outputCompactionTablePlane(unsigned PlaneNo,
}
void BytecodeWriter::outputCompactionTable() {
- CompactionTableBytes -= Out.size();
+ CompactionTableBytes -= Out.size(); {
BytecodeBlock CTB(BytecodeFormat::CompactionTable, Out, true/*ElideIfEmpty*/);
const std::vector<std::vector<const Value*> > &CT =Table.getCompactionTable();
@@ -328,7 +328,7 @@ void BytecodeWriter::outputCompactionTable() {
for (unsigned i = 0, e = CT.size(); i != e; ++i)
if (i != Type::TypeTyID)
outputCompactionTablePlane(i, CT[i], 0);
- CompactionTableBytes += Out.size();
+ } CompactionTableBytes += Out.size();
}
void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
@@ -336,7 +336,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
// space!
if (MST.begin() == MST.end()) return;
- SymTabBytes -= Out.size();
+ SymTabBytes -= Out.size(); {
BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTable, Out,
true/* ElideIfEmpty*/);
@@ -357,6 +357,8 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
for (; I != End; ++I) {
// Symtab entry: [def slot #][name]
+ const Value *V = I->second;
+
Slot = Table.getSlot(I->second);
assert(Slot != -1 && "Value in symtab but has no slot number!!");
output_vbr((unsigned)Slot, Out);
@@ -364,7 +366,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
}
}
- SymTabBytes += Out.size();
+ }SymTabBytes += Out.size();
}
void llvm::WriteBytecodeToFile(const Module *C, std::ostream &Out) {