implement reading of abbrevs, and writing of abbreviated global varrs.
llvm-svn: 36367
This commit is contained in:
parent
1c927957f0
commit
b5491378b1
|
@ -94,7 +94,8 @@ bool BitcodeReader::ParseTypeTable(BitstreamReader &Stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == bitc::DEFINE_ABBREV) {
|
if (Code == bitc::DEFINE_ABBREV) {
|
||||||
assert(0 && "Abbrevs not implemented yet!");
|
Stream.ReadAbbrevRecord();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a record.
|
// Read a record.
|
||||||
|
@ -231,7 +232,8 @@ bool BitcodeReader::ParseTypeSymbolTable(BitstreamReader &Stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == bitc::DEFINE_ABBREV) {
|
if (Code == bitc::DEFINE_ABBREV) {
|
||||||
assert(0 && "Abbrevs not implemented yet!");
|
Stream.ReadAbbrevRecord();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a record.
|
// Read a record.
|
||||||
|
@ -294,7 +296,8 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == bitc::DEFINE_ABBREV) {
|
if (Code == bitc::DEFINE_ABBREV) {
|
||||||
assert(0 && "Abbrevs not implemented yet!");
|
Stream.ReadAbbrevRecord();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a record.
|
// Read a record.
|
||||||
|
|
|
@ -204,9 +204,11 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
// compute the maximum alignment value.
|
// compute the maximum alignment value.
|
||||||
std::map<std::string, unsigned> SectionMap;
|
std::map<std::string, unsigned> SectionMap;
|
||||||
unsigned MaxAlignment = 0;
|
unsigned MaxAlignment = 0;
|
||||||
|
unsigned MaxGlobalType = 0;
|
||||||
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end();
|
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end();
|
||||||
GV != E; ++GV) {
|
GV != E; ++GV) {
|
||||||
MaxAlignment = std::max(MaxAlignment, GV->getAlignment());
|
MaxAlignment = std::max(MaxAlignment, GV->getAlignment());
|
||||||
|
MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV->getType()));
|
||||||
|
|
||||||
if (!GV->hasSection()) continue;
|
if (!GV->hasSection()) continue;
|
||||||
// Give section names unique ID's.
|
// Give section names unique ID's.
|
||||||
|
@ -229,10 +231,12 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
|
|
||||||
// Emit abbrev for globals, now that we know # sections and max alignment.
|
// Emit abbrev for globals, now that we know # sections and max alignment.
|
||||||
unsigned SimpleGVarAbbrev = 0;
|
unsigned SimpleGVarAbbrev = 0;
|
||||||
if (!M->global_empty() && 0) {
|
if (!M->global_empty()) {
|
||||||
// Add an abbrev for common globals with no visibility or thread localness.
|
// Add an abbrev for common globals with no visibility or thread localness.
|
||||||
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
|
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
|
||||||
Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
|
Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
|
||||||
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
|
||||||
|
Log2_32_Ceil(MaxGlobalType+1)));
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 1)); // Constant.
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 1)); // Constant.
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 3)); // Linkage.
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 3)); // Linkage.
|
||||||
|
@ -241,7 +245,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
else {
|
else {
|
||||||
unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1;
|
unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1;
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
|
||||||
Log2_32_Ceil(MaxEncAlignment)));
|
Log2_32_Ceil(MaxEncAlignment+1)));
|
||||||
}
|
}
|
||||||
if (SectionMap.empty()) // Section.
|
if (SectionMap.empty()) // Section.
|
||||||
Abbv->Add(BitCodeAbbrevOp(0));
|
Abbv->Add(BitCodeAbbrevOp(0));
|
||||||
|
@ -300,7 +304,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
|
|
||||||
/// WriteModule - Emit the specified module to the bitstream.
|
/// WriteModule - Emit the specified module to the bitstream.
|
||||||
static void WriteModule(const Module *M, BitstreamWriter &Stream) {
|
static void WriteModule(const Module *M, BitstreamWriter &Stream) {
|
||||||
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 2);
|
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
|
||||||
|
|
||||||
// Emit the version number if it is non-zero.
|
// Emit the version number if it is non-zero.
|
||||||
if (CurVersion) {
|
if (CurVersion) {
|
||||||
|
|
Loading…
Reference in New Issue