[llvm-commits] [llvm] r70165 - in /llvm/trunk: docs/BitCodeFormat.html include/llvm/Bitcode/BitCodes.h include/llvm/Bitcode/BitstreamReader.h tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
Chris Lattner
sabre at nondot.org
Sun Apr 26 15:21:58 PDT 2009
Author: lattner
Date: Sun Apr 26 17:21:57 2009
New Revision: 70165
URL: http://llvm.org/viewvc/llvm-project?rev=70165&view=rev
Log:
Add two new record types to the blockinfo block:
BLOCKNAME and SETRECORDNAME. This allows a bitcode
file to be self describing with pretty names for
records and blocks in addition to numbers. This
enhances llvm-bcanalyzer to use this to print prettily.
Modified:
llvm/trunk/docs/BitCodeFormat.html
llvm/trunk/include/llvm/Bitcode/BitCodes.h
llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
Modified: llvm/trunk/docs/BitCodeFormat.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/BitCodeFormat.html?rev=70165&r1=70164&r2=70165&view=diff
==============================================================================
--- llvm/trunk/docs/BitCodeFormat.html (original)
+++ llvm/trunk/docs/BitCodeFormat.html Sun Apr 26 17:21:57 2009
@@ -563,6 +563,8 @@
<pre>
[SETBID (#1), blockid]
[DEFINE_ABBREV, ...]
+[BLOCKNAME, ...name...]
+[SETRECORDNAME, RecordID, ...name...]
</pre>
</div>
@@ -582,6 +584,15 @@
in <tt><a href="#DEFINE_ABBREV">DEFINE_ABBREV</a></tt>.
</p>
+<p>The <tt>BLOCKNAME</tt> can optionally occur in this block. The elements of
+the record are the bytes for the string name of the block. llvm-bcanalyzer uses
+this to dump out bitcode files symbolically.</p>
+
+<p>The <tt>SETRECORDNAME</tt> record can optionally occur in this block. The
+first entry is a record ID number and the rest of the elements of the record are
+the bytes for the string name of the record. llvm-bcanalyzer uses
+this to dump out bitcode files symbolically.</p>
+
<p>
Note that although the data in <tt>BLOCKINFO</tt> blocks is described as
"metadata," the abbreviations they contain are essential for parsing records
Modified: llvm/trunk/include/llvm/Bitcode/BitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitCodes.h?rev=70165&r1=70164&r2=70165&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitCodes.h Sun Apr 26 17:21:57 2009
@@ -66,10 +66,12 @@
/// BlockInfoCodes - The blockinfo block contains metadata about user-defined
/// blocks.
enum BlockInfoCodes {
- BLOCKINFO_CODE_SETBID = 1 // SETBID: [blockid#]
// DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
// block, instead of the BlockInfo block.
- // BLOCKNAME: give string name to block, if desired.
+
+ BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#]
+ BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name]
+ BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME: [id, name]
};
} // End bitc namespace
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=70165&r1=70164&r2=70165&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Sun Apr 26 17:21:57 2009
@@ -30,6 +30,9 @@
struct BlockInfo {
unsigned BlockID;
std::vector<BitCodeAbbrev*> Abbrevs;
+ std::string Name;
+
+ std::vector<std::pair<unsigned, std::string> > RecordNames;
};
private:
/// FirstChar/LastChar - This remembers the first and last bytes of the
@@ -78,7 +81,7 @@
/// getBlockInfo - If there is block info for the specified ID, return it,
/// otherwise return null.
- BlockInfo *getBlockInfo(unsigned BlockID) {
+ const BlockInfo *getBlockInfo(unsigned BlockID) const {
// Common case, the most recent entry matches BlockID.
if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
return &BlockInfoRecords.back();
@@ -91,8 +94,8 @@
}
BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
- if (BlockInfo *BI = getBlockInfo(BlockID))
- return *BI;
+ if (const BlockInfo *BI = getBlockInfo(BlockID))
+ return *const_cast<BlockInfo*>(BI);
// Otherwise, add a new record.
BlockInfoRecords.push_back(BlockInfo());
@@ -216,6 +219,13 @@
return (NextChar-BitStream->getFirstChar())*CHAR_BIT - BitsInCurWord;
}
+ BitstreamReader *getBitStreamReader() {
+ return BitStream;
+ }
+ const BitstreamReader *getBitStreamReader() const {
+ return BitStream;
+ }
+
/// JumpToBit - Reset the stream to the specified bit number.
void JumpToBit(uint64_t BitNo) {
@@ -363,7 +373,8 @@
BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
// Add the abbrevs specific to this block to the CurAbbrevs list.
- if (BitstreamReader::BlockInfo *Info = BitStream->getBlockInfo(BlockID)) {
+ if (const BitstreamReader::BlockInfo *Info =
+ BitStream->getBlockInfo(BlockID)) {
for (unsigned i = 0, e = static_cast<unsigned>(Info->Abbrevs.size());
i != e; ++i) {
CurAbbrevs.push_back(Info->Abbrevs[i]);
@@ -585,6 +596,23 @@
if (Record.size() < 1) return true;
CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
break;
+ case bitc::BLOCKINFO_CODE_BLOCKNAME: {
+ if (!CurBlockInfo) return true;
+ std::string Name;
+ for (unsigned i = 0, e = Record.size(); i != e; ++i)
+ Name += (char)Record[i];
+ CurBlockInfo->Name = Name;
+ break;
+ }
+ case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
+ if (!CurBlockInfo) return true;
+ std::string Name;
+ for (unsigned i = 1, e = Record.size(); i != e; ++i)
+ Name += (char)Record[i];
+ CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
+ Name));
+ break;
+ }
}
}
}
Modified: llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp?rev=70165&r1=70164&r2=70165&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp (original)
+++ llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp Sun Apr 26 17:21:57 2009
@@ -72,7 +72,8 @@
/// GetBlockName - Return a symbolic block name if known, otherwise return
/// null.
-static const char *GetBlockName(unsigned BlockID) {
+static const char *GetBlockName(unsigned BlockID,
+ const BitstreamReader &StreamFile) {
// Standard blocks for all bitcode files.
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID)
@@ -80,6 +81,14 @@
return 0;
}
+ // Check to see if we have a blockinfo record for this block, with a name.
+ if (const BitstreamReader::BlockInfo *Info =
+ StreamFile.getBlockInfo(BlockID)) {
+ if (!Info->Name.empty())
+ return Info->Name.c_str();
+ }
+
+
if (CurStreamType != LLVMIRBitstream) return 0;
switch (BlockID) {
@@ -96,18 +105,30 @@
/// GetCodeName - Return a symbolic code name if known, otherwise return
/// null.
-static const char *GetCodeName(unsigned CodeID, unsigned BlockID) {
+static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
+ const BitstreamReader &StreamFile) {
// Standard blocks for all bitcode files.
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
switch (CodeID) {
default: return 0;
- case bitc::MODULE_CODE_VERSION: return "VERSION";
+ case bitc::BLOCKINFO_CODE_SETBID: return "SETBID";
+ case bitc::BLOCKINFO_CODE_BLOCKNAME: return "BLOCKNAME";
+ case bitc::BLOCKINFO_CODE_SETRECORDNAME: return "SETRECORDNAME";
}
}
return 0;
}
+ // Check to see if we have a blockinfo record for this record, with a name.
+ if (const BitstreamReader::BlockInfo *Info =
+ StreamFile.getBlockInfo(BlockID)) {
+ for (unsigned i = 0, e = Info->RecordNames.size(); i != e; ++i)
+ if (Info->RecordNames[i].first == CodeID)
+ return Info->RecordNames[i].second.c_str();
+ }
+
+
if (CurStreamType != LLVMIRBitstream) return 0;
switch (BlockID) {
@@ -289,7 +310,7 @@
const char *BlockName = 0;
if (Dump) {
std::cerr << Indent << "<";
- if ((BlockName = GetBlockName(BlockID)))
+ if ((BlockName = GetBlockName(BlockID, *Stream.getBitStreamReader())))
std::cerr << BlockName;
else
std::cerr << "UnknownBlock" << BlockID;
@@ -358,11 +379,13 @@
if (Dump) {
std::cerr << Indent << " <";
- if (const char *CodeName = GetCodeName(Code, BlockID))
+ if (const char *CodeName =
+ GetCodeName(Code, BlockID, *Stream.getBitStreamReader()))
std::cerr << CodeName;
else
std::cerr << "UnknownCode" << Code;
- if (NonSymbolic && GetCodeName(Code, BlockID))
+ if (NonSymbolic &&
+ GetCodeName(Code, BlockID, *Stream.getBitStreamReader()))
std::cerr << " codeid=" << Code;
if (AbbrevID != bitc::UNABBREV_RECORD)
std::cerr << " abbrevid=" << AbbrevID;
@@ -474,7 +497,7 @@
for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(),
E = BlockIDStats.end(); I != E; ++I) {
std::cerr << " Block ID #" << I->first;
- if (const char *BlockName = GetBlockName(I->first))
+ if (const char *BlockName = GetBlockName(I->first, StreamFile))
std::cerr << " (" << BlockName << ")";
std::cerr << ":\n";
@@ -517,7 +540,8 @@
std::cerr << "\tCode Histogram:\n";
for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) {
std::cerr << "\t\t" << FreqPairs[i].first << "\t";
- if (const char *CodeName = GetCodeName(FreqPairs[i].second, I->first))
+ if (const char *CodeName =
+ GetCodeName(FreqPairs[i].second, I->first, StreamFile))
std::cerr << CodeName << "\n";
else
std::cerr << "UnknownCode" << FreqPairs[i].second << "\n";
More information about the llvm-commits
mailing list