[llvm-commits] CVS: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp ValueEnumerator.h Writer.cpp
Chris Lattner
sabre at nondot.org
Wed Apr 25 20:28:21 PDT 2007
Changes in directory llvm/lib/Bitcode/Writer:
ValueEnumerator.cpp updated: 1.3 -> 1.4
ValueEnumerator.h updated: 1.3 -> 1.4
Writer.cpp updated: 1.9 -> 1.10
---
Log message:
move some code around, fix a bug in the reader reading globalinits (which
I just introduced), stub out function reading, purge aggregate values from
the value table before reading functions.
---
Diffs of the changes: (+107 -66)
ValueEnumerator.cpp | 16 +++++
ValueEnumerator.h | 5 +
Writer.cpp | 152 +++++++++++++++++++++++++++++-----------------------
3 files changed, 107 insertions(+), 66 deletions(-)
Index: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
diff -u llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:1.3 llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:1.4
--- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:1.3 Wed Apr 25 21:46:40 2007
+++ llvm/lib/Bitcode/Writer/ValueEnumerator.cpp Wed Apr 25 22:27:58 2007
@@ -140,6 +140,22 @@
EnumerateType(*I);
}
+/// PurgeAggregateValues - If there are any aggregate values at the end of the
+/// value list, remove them and return the count of the remaining values. If
+/// there are none, return -1.
+int ValueEnumerator::PurgeAggregateValues() {
+ // If there are no aggregate values at the end of the list, return -1.
+ if (Values.empty() || Values.back().first->getType()->isFirstClassType())
+ return -1;
+
+ // Otherwise, remove aggregate values...
+ while (!Values.empty() && !Values.back().first->getType()->isFirstClassType())
+ Values.pop_back();
+
+ // ... and return the new size.
+ return Values.size();
+}
+
#if 0
Index: llvm/lib/Bitcode/Writer/ValueEnumerator.h
diff -u llvm/lib/Bitcode/Writer/ValueEnumerator.h:1.3 llvm/lib/Bitcode/Writer/ValueEnumerator.h:1.4
--- llvm/lib/Bitcode/Writer/ValueEnumerator.h:1.3 Mon Apr 23 19:16:04 2007
+++ llvm/lib/Bitcode/Writer/ValueEnumerator.h Wed Apr 25 22:27:58 2007
@@ -64,6 +64,11 @@
const ValueList &getValues() const { return Values; }
const TypeList &getTypes() const { return Types; }
+ /// PurgeAggregateValues - If there are any aggregate values at the end of the
+ /// value list, remove them and return the count of the remaining values. If
+ /// there are none, return -1.
+ int PurgeAggregateValues();
+
/// incorporateFunction/purgeFunction - If you'd like to deal with a function,
/// use these two methods to get its data into the ValueEnumerator!
///
Index: llvm/lib/Bitcode/Writer/Writer.cpp
diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.9 llvm/lib/Bitcode/Writer/Writer.cpp:1.10
--- llvm/lib/Bitcode/Writer/Writer.cpp:1.9 Wed Apr 25 21:46:40 2007
+++ llvm/lib/Bitcode/Writer/Writer.cpp Wed Apr 25 22:27:58 2007
@@ -324,69 +324,6 @@
}
-/// WriteTypeSymbolTable - Emit a block for the specified type symtab.
-static void WriteTypeSymbolTable(const TypeSymbolTable &TST,
- const ValueEnumerator &VE,
- BitstreamWriter &Stream) {
- if (TST.empty()) return;
-
- Stream.EnterSubblock(bitc::TYPE_SYMTAB_BLOCK_ID, 3);
-
- // FIXME: Set up the abbrev, we know how many types there are!
- // FIXME: We know if the type names can use 7-bit ascii.
-
- SmallVector<unsigned, 64> NameVals;
-
- for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
- TI != TE; ++TI) {
- unsigned AbbrevToUse = 0;
-
- // TST_ENTRY: [typeid, namelen, namechar x N]
- NameVals.push_back(VE.getTypeID(TI->second));
-
- const std::string &Str = TI->first;
- NameVals.push_back(Str.size());
- for (unsigned i = 0, e = Str.size(); i != e; ++i)
- NameVals.push_back(Str[i]);
-
- // Emit the finished record.
- Stream.EmitRecord(bitc::VST_CODE_ENTRY, NameVals, AbbrevToUse);
- NameVals.clear();
- }
-
- Stream.ExitBlock();
-}
-
-// Emit names for globals/functions etc.
-static void WriteValueSymbolTable(const ValueSymbolTable &VST,
- const ValueEnumerator &VE,
- BitstreamWriter &Stream) {
- if (VST.empty()) return;
- Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 3);
-
- // FIXME: Set up the abbrev, we know how many values there are!
- // FIXME: We know if the type names can use 7-bit ascii.
- SmallVector<unsigned, 64> NameVals;
-
- for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end();
- SI != SE; ++SI) {
- unsigned AbbrevToUse = 0;
-
- // VST_ENTRY: [valueid, namelen, namechar x N]
- NameVals.push_back(VE.getValueID(SI->getValue()));
-
- NameVals.push_back(SI->getKeyLength());
- for (const char *P = SI->getKeyData(),
- *E = SI->getKeyData()+SI->getKeyLength(); P != E; ++P)
- NameVals.push_back((unsigned char)*P);
-
- // Emit the finished record.
- Stream.EmitRecord(bitc::VST_CODE_ENTRY, NameVals, AbbrevToUse);
- NameVals.clear();
- }
- Stream.ExitBlock();
-}
-
static void WriteConstants(unsigned FirstVal, unsigned LastVal,
const ValueEnumerator &VE,
BitstreamWriter &Stream) {
@@ -541,15 +478,85 @@
}
}
+
+static void WriteFunction(const Function &F, ValueEnumerator &VE,
+ BitstreamWriter &Stream) {
+
+}
+
+/// WriteTypeSymbolTable - Emit a block for the specified type symtab.
+static void WriteTypeSymbolTable(const TypeSymbolTable &TST,
+ const ValueEnumerator &VE,
+ BitstreamWriter &Stream) {
+ if (TST.empty()) return;
+
+ Stream.EnterSubblock(bitc::TYPE_SYMTAB_BLOCK_ID, 3);
+
+ // FIXME: Set up the abbrev, we know how many types there are!
+ // FIXME: We know if the type names can use 7-bit ascii.
+
+ SmallVector<unsigned, 64> NameVals;
+
+ for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
+ TI != TE; ++TI) {
+ unsigned AbbrevToUse = 0;
+
+ // TST_ENTRY: [typeid, namelen, namechar x N]
+ NameVals.push_back(VE.getTypeID(TI->second));
+
+ const std::string &Str = TI->first;
+ NameVals.push_back(Str.size());
+ for (unsigned i = 0, e = Str.size(); i != e; ++i)
+ NameVals.push_back(Str[i]);
+
+ // Emit the finished record.
+ Stream.EmitRecord(bitc::VST_CODE_ENTRY, NameVals, AbbrevToUse);
+ NameVals.clear();
+ }
+
+ Stream.ExitBlock();
+}
+
+// Emit names for globals/functions etc.
+static void WriteValueSymbolTable(const ValueSymbolTable &VST,
+ const ValueEnumerator &VE,
+ BitstreamWriter &Stream) {
+ if (VST.empty()) return;
+ Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 3);
+
+ // FIXME: Set up the abbrev, we know how many values there are!
+ // FIXME: We know if the type names can use 7-bit ascii.
+ SmallVector<unsigned, 64> NameVals;
+
+ for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end();
+ SI != SE; ++SI) {
+ unsigned AbbrevToUse = 0;
+
+ // VST_ENTRY: [valueid, namelen, namechar x N]
+ NameVals.push_back(VE.getValueID(SI->getValue()));
+
+ NameVals.push_back(SI->getKeyLength());
+ for (const char *P = SI->getKeyData(),
+ *E = SI->getKeyData()+SI->getKeyLength(); P != E; ++P)
+ NameVals.push_back((unsigned char)*P);
+
+ // Emit the finished record.
+ Stream.EmitRecord(bitc::VST_CODE_ENTRY, NameVals, AbbrevToUse);
+ NameVals.clear();
+ }
+ Stream.ExitBlock();
+}
+
+
/// WriteModule - Emit the specified module to the bitstream.
static void WriteModule(const Module *M, BitstreamWriter &Stream) {
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
// Emit the version number if it is non-zero.
if (CurVersion) {
- SmallVector<unsigned, 1> VersionVals;
- VersionVals.push_back(CurVersion);
- Stream.EmitRecord(bitc::MODULE_CODE_VERSION, VersionVals);
+ SmallVector<unsigned, 1> Vals;
+ Vals.push_back(CurVersion);
+ Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
}
// Analyze the module, enumerating globals, functions, etc.
@@ -565,6 +572,19 @@
// Emit constants.
WriteModuleConstants(VE, Stream);
+ // FIXME: Purge aggregate values from the VE, emit a record that indicates how
+ // many to purge.
+ int NumNonAggregates = VE.PurgeAggregateValues();
+ if (NumNonAggregates != -1) {
+ SmallVector<unsigned, 1> Vals;
+ Vals.push_back(NumNonAggregates);
+ Stream.EmitRecord(bitc::MODULE_CODE_PURGEVALS, Vals);
+ }
+
+ // Emit function bodies.
+ for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
+ WriteFunction(*I, VE, Stream);
+
// Emit the type symbol table information.
WriteTypeSymbolTable(M->getTypeSymbolTable(), VE, Stream);
More information about the llvm-commits
mailing list