summaryrefslogtreecommitdiff
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-23 16:04:05 +0000
committerChris Lattner <sabre@nondot.org>2007-04-23 16:04:05 +0000
commit36d5e7d31be61f631ace0488f0d6cd71b8f31a16 (patch)
treeab799d8bdf8f375e4d530cc9babfd8f7314a6a6d /lib/Bitcode
parenta18b9657528916b9bd5edcc1d3b6db571327d40c (diff)
downloadllvm-36d5e7d31be61f631ace0488f0d6cd71b8f31a16.tar.gz
llvm-36d5e7d31be61f631ace0488f0d6cd71b8f31a16.tar.bz2
llvm-36d5e7d31be61f631ace0488f0d6cd71b8f31a16.tar.xz
first part of implementation of abbrevs. The writer isn't fully there yet and the
reader doesn't handle them at all yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36363 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp14
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp45
2 files changed, 47 insertions, 12 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index be05f45619..f464e33f6a 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -93,7 +93,7 @@ bool BitcodeReader::ParseTypeTable(BitstreamReader &Stream) {
continue;
}
- if (Code == bitc::DEFINE_ABBREVS) {
+ if (Code == bitc::DEFINE_ABBREV) {
assert(0 && "Abbrevs not implemented yet!");
}
@@ -230,7 +230,7 @@ bool BitcodeReader::ParseTypeSymbolTable(BitstreamReader &Stream) {
continue;
}
- if (Code == bitc::DEFINE_ABBREVS) {
+ if (Code == bitc::DEFINE_ABBREV) {
assert(0 && "Abbrevs not implemented yet!");
}
@@ -293,7 +293,7 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
continue;
}
- if (Code == bitc::DEFINE_ABBREVS) {
+ if (Code == bitc::DEFINE_ABBREV) {
assert(0 && "Abbrevs not implemented yet!");
}
@@ -345,7 +345,7 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
// GLOBALVAR: [type, isconst, initid,
// linkage, alignment, section, visibility, threadlocal]
case bitc::MODULE_CODE_GLOBALVAR: {
- if (Record.size() < 8)
+ if (Record.size() < 6)
return Error("Invalid MODULE_CODE_GLOBALVAR record");
const Type *Ty = getTypeByID(Record[0]);
if (!isa<PointerType>(Ty))
@@ -361,8 +361,10 @@ bool BitcodeReader::ParseModule(BitstreamReader &Stream,
return Error("Invalid section ID");
Section = SectionTable[Record[5]-1];
}
- GlobalValue::VisibilityTypes Visibility = GetDecodedVisibility(Record[6]);
- bool isThreadLocal = Record[7];
+ GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
+ if (Record.size() >= 6) Visibility = GetDecodedVisibility(Record[6]);
+ bool isThreadLocal = false;
+ if (Record.size() >= 7) isThreadLocal = Record[7];
GlobalVariable *NewGV =
new GlobalVariable(Ty, isConstant, Linkage, 0, "", TheModule);
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index b22d00c6ac..d78ea29b56 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -200,10 +200,14 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
WriteStringRecord(bitc::MODULE_CODE_ASM, M->getModuleInlineAsm(),
0/*TODO*/, Stream);
- // Emit information about sections.
+ // Emit information about sections, computing how many there are. Also
+ // compute the maximum alignment value.
std::map<std::string, unsigned> SectionMap;
+ unsigned MaxAlignment = 0;
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end();
GV != E; ++GV) {
+ MaxAlignment = std::max(MaxAlignment, GV->getAlignment());
+
if (!GV->hasSection()) continue;
// Give section names unique ID's.
unsigned &Entry = SectionMap[GV->getSection()];
@@ -213,6 +217,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Entry = SectionMap.size();
}
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
+ MaxAlignment = std::max(MaxAlignment, F->getAlignment());
if (!F->hasSection()) continue;
// Give section names unique ID's.
unsigned &Entry = SectionMap[F->getSection()];
@@ -222,13 +227,37 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Entry = SectionMap.size();
}
- // TODO: Emit abbrev, now that we know # sections.
+ // Emit abbrev for globals, now that we know # sections and max alignment.
+ unsigned SimpleGVarAbbrev = 0;
+ if (!M->global_empty() && 0) {
+ // Add an abbrev for common globals with no visibility or thread localness.
+ BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 1)); // Constant.
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 3)); // Linkage.
+ if (MaxAlignment == 0) // Alignment.
+ Abbv->Add(BitCodeAbbrevOp(0));
+ else {
+ unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1;
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
+ Log2_32_Ceil(MaxEncAlignment)));
+ }
+ if (SectionMap.empty()) // Section.
+ Abbv->Add(BitCodeAbbrevOp(0));
+ else
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth,
+ Log2_32_Ceil(SectionMap.size())));
+ // Don't bother emitting vis + thread local.
+ SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv);
+ }
// Emit the global variable information.
SmallVector<unsigned, 64> Vals;
for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end();
GV != E; ++GV) {
-
+ unsigned AbbrevToUse = 0;
+
// GLOBALVAR: [type, isconst, initid,
// linkage, alignment, section, visibility, threadlocal]
Vals.push_back(VE.getTypeID(GV->getType()));
@@ -238,10 +267,14 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Vals.push_back(getEncodedLinkage(GV));
Vals.push_back(Log2_32(GV->getAlignment())+1);
Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0);
- Vals.push_back(getEncodedVisibility(GV));
- Vals.push_back(GV->isThreadLocal());
+ if (GV->isThreadLocal() ||
+ GV->getVisibility() != GlobalValue::DefaultVisibility) {
+ Vals.push_back(getEncodedVisibility(GV));
+ Vals.push_back(GV->isThreadLocal());
+ } else {
+ AbbrevToUse = SimpleGVarAbbrev;
+ }
- unsigned AbbrevToUse = 0;
Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse);
Vals.clear();
}