summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2002-07-14 23:07:51 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2002-07-14 23:07:51 +0000
commitc1b6474a603a45c4a441c4bfdc9e554f54bcbb63 (patch)
tree276f95470a46fa07df7a8de262a2043083d94f25 /llvm/lib
parent827d91f257d1837bc5acf96f69764afbcb8a0c67 (diff)
downloadbcm5719-llvm-c1b6474a603a45c4a441c4bfdc9e554f54bcbb63.tar.gz
bcm5719-llvm-c1b6474a603a45c4a441c4bfdc9e554f54bcbb63.zip
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. llvm-svn: 2898
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bytecode/Writer/Writer.cpp92
1 files changed, 57 insertions, 35 deletions
diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp
index 75a25f2015c..334622dfa23 100644
--- a/llvm/lib/Bytecode/Writer/Writer.cpp
+++ b/llvm/lib/Bytecode/Writer/Writer.cpp
@@ -54,53 +54,75 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
outputSymbolTable(*M->getSymbolTable());
}
+// 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++)
+ /*empty*/;
+
+ unsigned NC = ValNo; // Number of constants
+ for (; NC < Plane.size() &&
+ (isa<Constant>(Plane[NC]) || isa<Type>(Plane[NC])); NC++)
+ /*empty*/;
+ NC -= ValNo; // Convert from index into count
+ if (NC == 0) return; // Skip empty type planes...
+
+ // Output type header: [num entries][type id number]
+ //
+ output_vbr(NC, Out);
+
+ // Output the Type ID Number...
+ int Slot = Table.getValSlot(Plane.front()->getType());
+ assert (Slot != -1 && "Type in constant pool but not in function!!");
+ output_vbr((unsigned)Slot, Out);
+
+ //cerr << "Emitting " << NC << " constants of type '"
+ // << Plane.front()->getType()->getName() << "' = Slot #" << Slot << "\n";
+
+ for (unsigned i = ValNo; i < ValNo+NC; ++i) {
+ const Value *V = Plane[i];
+ if (const Constant *CPV = dyn_cast<Constant>(V)) {
+ //cerr << "Serializing value: <" << V->getType() << ">: " << V << ":"
+ // << Out.size() << "\n";
+ outputConstant(CPV);
+ } else {
+ outputType(cast<const Type>(V));
+ }
+ }
+}
+
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)
- ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
+ continue; // Type plane was written out above
- // Scan through and ignore function arguments...
- for (; ValNo < Plane.size() && isa<Argument>(Plane[ValNo]); ValNo++)
- /*empty*/;
-
- unsigned NC = ValNo; // Number of constants
- for (; NC < Plane.size() &&
- (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...
-
- // Output type header: [num entries][type id number]
- //
- output_vbr(NC, Out);
-
- // Output the Type ID Number...
- int Slot = Table.getValSlot(Plane.front()->getType());
- assert (Slot != -1 && "Type in constant pool but not in function!!");
- output_vbr((unsigned)Slot, Out);
-
- //cerr << "Emitting " << NC << " constants of type '"
- // << Plane.front()->getType()->getName() << "' = Slot #" << Slot << "\n";
-
- for (unsigned i = ValNo; i < ValNo+NC; ++i) {
- const Value *V = Plane[i];
- if (const Constant *CPV = dyn_cast<Constant>(V)) {
- //cerr << "Serializing value: <" << V->getType() << ">: " << V << ":"
- // << Out.size() << "\n";
- outputConstant(CPV);
- } else {
- outputType(cast<const Type>(V));
- }
- }
+ outputConstantsInPlane(Plane, ValNo); // Write out constants in the plane
}
}
OpenPOWER on IntegriCloud