mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 04:24:00 +00:00
Make .bc en/decoding of AttrKind stable
The bitcode representation attribute kinds are encoded into / decoded from should be independent of the current set of LLVM attributes and their position in the AttrKind enum. This patch explicitly encodes attributes to fixed bitcode values. With this patch applied, LLVM does not silently misread attributes written by LLVM 3.3. We also enhance the decoding slightly such that an error message is printed if an unknown AttrKind encoding was dected. Bonus: Dropping bitcode attributes from AttrKind is now easy, as old AttrKinds do not need to be kept to support the Bitcode reader. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187186 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -161,6 +161,89 @@ static void WriteStringRecord(unsigned Code, StringRef Str,
|
||||
Stream.EmitRecord(Code, Vals, AbbrevToUse);
|
||||
}
|
||||
|
||||
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
|
||||
switch (Kind) {
|
||||
case Attribute::Alignment:
|
||||
return bitc::ATTR_KIND_ALIGNMENT;
|
||||
case Attribute::AlwaysInline:
|
||||
return bitc::ATTR_KIND_ALWAYS_INLINE;
|
||||
case Attribute::Builtin:
|
||||
return bitc::ATTR_KIND_BUILTIN;
|
||||
case Attribute::ByVal:
|
||||
return bitc::ATTR_KIND_BY_VAL;
|
||||
case Attribute::Cold:
|
||||
return bitc::ATTR_KIND_COLD;
|
||||
case Attribute::InlineHint:
|
||||
return bitc::ATTR_KIND_INLINE_HINT;
|
||||
case Attribute::InReg:
|
||||
return bitc::ATTR_KIND_IN_REG;
|
||||
case Attribute::MinSize:
|
||||
return bitc::ATTR_KIND_MIN_SIZE;
|
||||
case Attribute::Naked:
|
||||
return bitc::ATTR_KIND_NAKED;
|
||||
case Attribute::Nest:
|
||||
return bitc::ATTR_KIND_NEST;
|
||||
case Attribute::NoAlias:
|
||||
return bitc::ATTR_KIND_NO_ALIAS;
|
||||
case Attribute::NoBuiltin:
|
||||
return bitc::ATTR_KIND_NO_BUILTIN;
|
||||
case Attribute::NoCapture:
|
||||
return bitc::ATTR_KIND_NO_CAPTURE;
|
||||
case Attribute::NoDuplicate:
|
||||
return bitc::ATTR_KIND_NO_DUPLICATE;
|
||||
case Attribute::NoImplicitFloat:
|
||||
return bitc::ATTR_KIND_NO_IMPLICIT_FLOAT;
|
||||
case Attribute::NoInline:
|
||||
return bitc::ATTR_KIND_NO_INLINE;
|
||||
case Attribute::NonLazyBind:
|
||||
return bitc::ATTR_KIND_NON_LAZY_BIND;
|
||||
case Attribute::NoRedZone:
|
||||
return bitc::ATTR_KIND_NO_RED_ZONE;
|
||||
case Attribute::NoReturn:
|
||||
return bitc::ATTR_KIND_NO_RETURN;
|
||||
case Attribute::NoUnwind:
|
||||
return bitc::ATTR_KIND_NO_UNWIND;
|
||||
case Attribute::OptimizeForSize:
|
||||
return bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE;
|
||||
case Attribute::ReadNone:
|
||||
return bitc::ATTR_KIND_READ_NONE;
|
||||
case Attribute::ReadOnly:
|
||||
return bitc::ATTR_KIND_READ_ONLY;
|
||||
case Attribute::Returned:
|
||||
return bitc::ATTR_KIND_RETURNED;
|
||||
case Attribute::ReturnsTwice:
|
||||
return bitc::ATTR_KIND_RETURNS_TWICE;
|
||||
case Attribute::SExt:
|
||||
return bitc::ATTR_KIND_S_EXT;
|
||||
case Attribute::StackAlignment:
|
||||
return bitc::ATTR_KIND_STACK_ALIGNMENT;
|
||||
case Attribute::StackProtect:
|
||||
return bitc::ATTR_KIND_STACK_PROTECT;
|
||||
case Attribute::StackProtectReq:
|
||||
return bitc::ATTR_KIND_STACK_PROTECT_REQ;
|
||||
case Attribute::StackProtectStrong:
|
||||
return bitc::ATTR_KIND_STACK_PROTECT_STRONG;
|
||||
case Attribute::StructRet:
|
||||
return bitc::ATTR_KIND_STRUCT_RET;
|
||||
case Attribute::SanitizeAddress:
|
||||
return bitc::ATTR_KIND_SANITIZE_ADDRESS;
|
||||
case Attribute::SanitizeThread:
|
||||
return bitc::ATTR_KIND_SANITIZE_THREAD;
|
||||
case Attribute::SanitizeMemory:
|
||||
return bitc::ATTR_KIND_SANITIZE_MEMORY;
|
||||
case Attribute::UWTable:
|
||||
return bitc::ATTR_KIND_UW_TABLE;
|
||||
case Attribute::ZExt:
|
||||
return bitc::ATTR_KIND_Z_EXT;
|
||||
case Attribute::EndAttrKinds:
|
||||
llvm_unreachable("Can not encode end-attribute kinds marker.");
|
||||
case Attribute::None:
|
||||
llvm_unreachable("Can not encode none-attribute.");
|
||||
}
|
||||
|
||||
llvm_unreachable("Trying to encode unknown attribute");
|
||||
}
|
||||
|
||||
static void WriteAttributeGroupTable(const ValueEnumerator &VE,
|
||||
BitstreamWriter &Stream) {
|
||||
const std::vector<AttributeSet> &AttrGrps = VE.getAttributeGroups();
|
||||
@ -182,10 +265,10 @@ static void WriteAttributeGroupTable(const ValueEnumerator &VE,
|
||||
Attribute Attr = *I;
|
||||
if (Attr.isEnumAttribute()) {
|
||||
Record.push_back(0);
|
||||
Record.push_back(Attr.getKindAsEnum());
|
||||
Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
|
||||
} else if (Attr.isAlignAttribute()) {
|
||||
Record.push_back(1);
|
||||
Record.push_back(Attr.getKindAsEnum());
|
||||
Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
|
||||
Record.push_back(Attr.getValueAsInt());
|
||||
} else {
|
||||
StringRef Kind = Attr.getKindAsString();
|
||||
|
Reference in New Issue
Block a user