Write out the plane for types first, since values of primitive types

may be constructed by expressions of other types (and so the
contents of the primitive type planes must come after all types).
Use a helper function outputConstantsInPlane in outputConstants to
do this.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2898 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve
2002-07-14 23:07:51 +00:00
parent 054bd689db
commit a7dac3db79

View File

@ -54,19 +54,12 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
outputSymbolTable(*M->getSymbolTable());
}
void BytecodeWriter::outputConstants(bool isFunction) {
BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out);
unsigned NumPlanes = Table.getNumPlanes();
for (unsigned pno = 0; pno < NumPlanes; pno++) {
const std::vector<const Value*> &Plane = Table.getPlane(pno);
if (Plane.empty()) continue; // Skip empty type planes...
unsigned ValNo = 0;
if (isFunction) // Don't reemit module constants
ValNo = Table.getModuleLevel(pno);
else if (pno == Type::TypeTyID)
ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
// Helper function for outputConstants().
// Writes out all the constants in the plane Plane starting at entry StartNo.
//
void BytecodeWriter::outputConstantsInPlane(const std::vector<const Value*>
&Plane, unsigned StartNo) {
unsigned ValNo = StartNo;
// Scan through and ignore function arguments...
for (; ValNo < Plane.size() && isa<Argument>(Plane[ValNo]); ValNo++)
@ -77,7 +70,7 @@ void BytecodeWriter::outputConstants(bool isFunction) {
(isa<Constant>(Plane[NC]) || isa<Type>(Plane[NC])); NC++)
/*empty*/;
NC -= ValNo; // Convert from index into count
if (NC == 0) continue; // Skip empty type planes...
if (NC == 0) return; // Skip empty type planes...
// Output type header: [num entries][type id number]
//
@ -102,6 +95,35 @@ void BytecodeWriter::outputConstants(bool isFunction) {
}
}
}
void BytecodeWriter::outputConstants(bool isFunction) {
BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out);
unsigned NumPlanes = Table.getNumPlanes();
// Write the type plane for types first because earlier planes
// (e.g. for a primitive type like float) may have constants constructed
// using types coming later (e.g., via getelementptr from a pointer type).
// The type plane is needed before types can be fwd or bkwd referenced.
if (!isFunction) {
const std::vector<const Value*> &Plane = Table.getPlane(Type::TypeTyID);
assert(!Plane.empty() && "No types at all?");
unsigned ValNo = Type::FirstDerivedTyID; // Start at the derived types...
outputConstantsInPlane(Plane, ValNo); // Write out the types
}
for (unsigned pno = 0; pno < NumPlanes; pno++) {
const std::vector<const Value*> &Plane = Table.getPlane(pno);
if (Plane.empty()) continue; // Skip empty type planes...
unsigned ValNo = 0;
if (isFunction) // Don't reemit module constants
ValNo = Table.getModuleLevel(pno);
else if (pno == Type::TypeTyID)
continue; // Type plane was written out above
outputConstantsInPlane(Plane, ValNo); // Write out constants in the plane
}
}
void BytecodeWriter::outputModuleInfoBlock(const Module *M) {