Skip to content

Commit

Permalink
Add code for emitting the attribute groups.
Browse files Browse the repository at this point in the history
This is some initial code for emitting the attribute groups into the bitcode.

NOTE: This format *may* change! Do not rely upon the attribute groups' bitcode
not changing.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174845 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
isanbard committed Feb 10, 2013
1 parent 8c2e77f commit 0f715c2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
16 changes: 8 additions & 8 deletions include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ namespace bitc {

// Module sub-block id's.
PARAMATTR_BLOCK_ID,

UNUSED_ID1,
PARAMATTR_GROUP_BLOCK_ID,

CONSTANTS_BLOCK_ID,
FUNCTION_BLOCK_ID,

UNUSED_ID2,
UNUSED_ID1,

VALUE_SYMTAB_BLOCK_ID,
METADATA_BLOCK_ID,
Expand Down Expand Up @@ -69,7 +68,7 @@ namespace bitc {
// ALIAS: [alias type, aliasee val#, linkage, visibility]
MODULE_CODE_ALIAS = 9,

/// MODULE_CODE_PURGEVALS: [numvals]
// MODULE_CODE_PURGEVALS: [numvals]
MODULE_CODE_PURGEVALS = 10,

MODULE_CODE_GCNAME = 11 // GCNAME: [strchr x N]
Expand All @@ -78,10 +77,11 @@ namespace bitc {
/// PARAMATTR blocks have code for defining a parameter attribute set.
enum AttributeCodes {
// FIXME: Remove `PARAMATTR_CODE_ENTRY_OLD' in 4.0
PARAMATTR_CODE_ENTRY_OLD = 1, // ENTRY: [paramidx0, attr0,
// paramidx1, attr1...]
PARAMATTR_CODE_ENTRY = 2 // ENTRY: [paramidx0, attrgrp0,
// paramidx1, attrgrp1...]
PARAMATTR_CODE_ENTRY_OLD = 1, // ENTRY: [paramidx0, attr0,
// paramidx1, attr1...]
PARAMATTR_CODE_ENTRY = 2, // ENTRY: [paramidx0, attrgrp0,
// paramidx1, attrgrp1, ...]
PARAMATTR_GRP_CODE_ENTRY = 3 // ENTRY: [id, attr0, att1, ...]
};

/// TYPE blocks have codes for each type primitive they use.
Expand Down
53 changes: 53 additions & 0 deletions lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,63 @@ static uint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs,
return EncodedAttrs;
}

static void WriteAttributeGroupTable(const ValueEnumerator &VE,
BitstreamWriter &Stream) {
const std::vector<AttributeSet> &Attrs = VE.getAttributeSets();
if (Attrs.empty()) return;

Stream.EnterSubblock(bitc::PARAMATTR_GROUP_BLOCK_ID, 3);

SmallVector<uint64_t, 64> Record;
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
AttributeSet AS = Attrs[i];
for (unsigned i = 0, e = AS.getNumSlots(); i != e; ++i) {
AttributeSet A = AS.getSlotAttributes(i);

Record.push_back(VE.getAttributeSetID(A));
Record.push_back(AS.getSlotIndex(i));

for (AttributeSet::iterator I = AS.begin(0), E = AS.end(0);
I != E; ++I) {
Attribute Attr = *I;
if (Attr.isEnumAttribute()) {
Record.push_back(0);
Record.push_back(Attr.getKindAsEnum());
} else if (Attr.isAlignAttribute()) {
Record.push_back(1);
Record.push_back(Attr.getKindAsEnum());
Record.push_back(Attr.getValueAsInt());
} else {
StringRef Kind = Attr.getKindAsString();
StringRef Val = Attr.getValueAsString();

Record.push_back(Val.empty() ? 3 : 4);
Record.append(Kind.begin(), Kind.end());
Record.push_back(0);
if (!Val.empty()) {
Record.append(Val.begin(), Val.end());
Record.push_back(0);
}
}
}

Stream.EmitRecord(bitc::PARAMATTR_GRP_CODE_ENTRY, Record);
Record.clear();
}
}

Stream.ExitBlock();
}

static void WriteAttributeTable(const ValueEnumerator &VE,
BitstreamWriter &Stream) {
const std::vector<AttributeSet> &Attrs = VE.getAttributes();
if (Attrs.empty()) return;

Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);

// FIXME: Remove this! It no longer works with the current attributes classes.

SmallVector<uint64_t, 64> Record;
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
const AttributeSet &A = Attrs[i];
Expand Down Expand Up @@ -1854,6 +1904,9 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
// Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream);

// Emit information about attribute groups.
WriteAttributeGroupTable(VE, Stream);

// Emit information about parameter attributes.
WriteAttributeTable(VE, Stream);

Expand Down

0 comments on commit 0f715c2

Please sign in to comment.