forked from OSchip/llvm-project
Add the "ForceSizeOpt" attribute.
Patch by Quentin Colombet <qcolombet@apple.com> Original description: """ The attached patch is the first step to have a better control on Oz related optimizations. The Oz optimization level focuses on code size, thus I propose to add an attribute called ForceSizeOpt. """ llvm-svn: 166422
This commit is contained in:
parent
632aea92a5
commit
dbf4783634
|
@ -84,7 +84,8 @@ public:
|
||||||
StackProtectReq = 24, ///< Stack protection required.
|
StackProtectReq = 24, ///< Stack protection required.
|
||||||
StructRet = 25, ///< Hidden pointer to structure to return
|
StructRet = 25, ///< Hidden pointer to structure to return
|
||||||
UWTable = 26, ///< Function must be in a unwind table
|
UWTable = 26, ///< Function must be in a unwind table
|
||||||
ZExt = 27 ///< Zero extended before/after call
|
ZExt = 27, ///< Zero extended before/after call
|
||||||
|
ForceSizeOpt = 28 ///< Function must be optimized for size first
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
AttributesImpl *Attrs;
|
AttributesImpl *Attrs;
|
||||||
|
@ -152,7 +153,8 @@ public:
|
||||||
hasAttribute(Attributes::UWTable) ||
|
hasAttribute(Attributes::UWTable) ||
|
||||||
hasAttribute(Attributes::NonLazyBind) ||
|
hasAttribute(Attributes::NonLazyBind) ||
|
||||||
hasAttribute(Attributes::ReturnsTwice) ||
|
hasAttribute(Attributes::ReturnsTwice) ||
|
||||||
hasAttribute(Attributes::AddressSafety);
|
hasAttribute(Attributes::AddressSafety) ||
|
||||||
|
hasAttribute(Attributes::ForceSizeOpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Attributes &A) const {
|
bool operator==(const Attributes &A) const {
|
||||||
|
@ -263,7 +265,8 @@ public:
|
||||||
.removeAttribute(Attributes::UWTable)
|
.removeAttribute(Attributes::UWTable)
|
||||||
.removeAttribute(Attributes::NonLazyBind)
|
.removeAttribute(Attributes::NonLazyBind)
|
||||||
.removeAttribute(Attributes::ReturnsTwice)
|
.removeAttribute(Attributes::ReturnsTwice)
|
||||||
.removeAttribute(Attributes::AddressSafety);
|
.removeAttribute(Attributes::AddressSafety)
|
||||||
|
.removeAttribute(Attributes::ForceSizeOpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Raw() const { return Bits; }
|
uint64_t Raw() const { return Bits; }
|
||||||
|
|
|
@ -557,6 +557,7 @@ lltok::Kind LLLexer::LexIdentifier() {
|
||||||
KEYWORD(naked);
|
KEYWORD(naked);
|
||||||
KEYWORD(nonlazybind);
|
KEYWORD(nonlazybind);
|
||||||
KEYWORD(address_safety);
|
KEYWORD(address_safety);
|
||||||
|
KEYWORD(forcesizeopt);
|
||||||
|
|
||||||
KEYWORD(type);
|
KEYWORD(type);
|
||||||
KEYWORD(opaque);
|
KEYWORD(opaque);
|
||||||
|
|
|
@ -953,6 +953,7 @@ bool LLParser::ParseOptionalAttrs(AttrBuilder &B, unsigned AttrKind) {
|
||||||
case lltok::kw_naked: B.addAttribute(Attributes::Naked); break;
|
case lltok::kw_naked: B.addAttribute(Attributes::Naked); break;
|
||||||
case lltok::kw_nonlazybind: B.addAttribute(Attributes::NonLazyBind); break;
|
case lltok::kw_nonlazybind: B.addAttribute(Attributes::NonLazyBind); break;
|
||||||
case lltok::kw_address_safety: B.addAttribute(Attributes::AddressSafety); break;
|
case lltok::kw_address_safety: B.addAttribute(Attributes::AddressSafety); break;
|
||||||
|
case lltok::kw_forcesizeopt: B.addAttribute(Attributes::ForceSizeOpt); break;
|
||||||
|
|
||||||
case lltok::kw_alignstack: {
|
case lltok::kw_alignstack: {
|
||||||
unsigned Alignment;
|
unsigned Alignment;
|
||||||
|
@ -1011,6 +1012,7 @@ bool LLParser::ParseOptionalAttrs(AttrBuilder &B, unsigned AttrKind) {
|
||||||
case lltok::kw_nonlazybind:
|
case lltok::kw_nonlazybind:
|
||||||
case lltok::kw_returns_twice:
|
case lltok::kw_returns_twice:
|
||||||
case lltok::kw_address_safety:
|
case lltok::kw_address_safety:
|
||||||
|
case lltok::kw_forcesizeopt:
|
||||||
if (AttrKind != 2)
|
if (AttrKind != 2)
|
||||||
HaveError |= Error(AttrLoc, "invalid use of function-only attribute");
|
HaveError |= Error(AttrLoc, "invalid use of function-only attribute");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -109,6 +109,7 @@ namespace lltok {
|
||||||
kw_naked,
|
kw_naked,
|
||||||
kw_nonlazybind,
|
kw_nonlazybind,
|
||||||
kw_address_safety,
|
kw_address_safety,
|
||||||
|
kw_forcesizeopt,
|
||||||
|
|
||||||
kw_type,
|
kw_type,
|
||||||
kw_opaque,
|
kw_opaque,
|
||||||
|
|
|
@ -127,7 +127,7 @@ uint64_t Attributes::encodeLLVMAttributesForBitcode(Attributes Attrs) {
|
||||||
uint64_t EncodedAttrs = Attrs.Raw() & 0xffff;
|
uint64_t EncodedAttrs = Attrs.Raw() & 0xffff;
|
||||||
if (Attrs.hasAttribute(Attributes::Alignment))
|
if (Attrs.hasAttribute(Attributes::Alignment))
|
||||||
EncodedAttrs |= Attrs.getAlignment() << 16;
|
EncodedAttrs |= Attrs.getAlignment() << 16;
|
||||||
EncodedAttrs |= (Attrs.Raw() & (0xfffULL << 21)) << 11;
|
EncodedAttrs |= (Attrs.Raw() & (0xffffULL << 21)) << 11;
|
||||||
return EncodedAttrs;
|
return EncodedAttrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ Attributes Attributes::decodeLLVMAttributesForBitcode(LLVMContext &C,
|
||||||
AttrBuilder B(EncodedAttrs & 0xffff);
|
AttrBuilder B(EncodedAttrs & 0xffff);
|
||||||
if (Alignment)
|
if (Alignment)
|
||||||
B.addAlignmentAttr(Alignment);
|
B.addAlignmentAttr(Alignment);
|
||||||
B.addRawValue((EncodedAttrs & (0xfffULL << 32)) >> 11);
|
B.addRawValue((EncodedAttrs & (0xffffULL << 32)) >> 11);
|
||||||
return Attributes::get(C, B);
|
return Attributes::get(C, B);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +201,8 @@ std::string Attributes::getAsString() const {
|
||||||
Result += "nonlazybind ";
|
Result += "nonlazybind ";
|
||||||
if (hasAttribute(Attributes::AddressSafety))
|
if (hasAttribute(Attributes::AddressSafety))
|
||||||
Result += "address_safety ";
|
Result += "address_safety ";
|
||||||
|
if (hasAttribute(Attributes::ForceSizeOpt))
|
||||||
|
Result += "forcesizeopt ";
|
||||||
if (hasAttribute(Attributes::StackAlignment)) {
|
if (hasAttribute(Attributes::StackAlignment)) {
|
||||||
Result += "alignstack(";
|
Result += "alignstack(";
|
||||||
Result += utostr(getStackAlignment());
|
Result += utostr(getStackAlignment());
|
||||||
|
@ -324,6 +326,7 @@ uint64_t AttributesImpl::getAttrMask(uint64_t Val) {
|
||||||
case Attributes::UWTable: return 1 << 30;
|
case Attributes::UWTable: return 1 << 30;
|
||||||
case Attributes::NonLazyBind: return 1U << 31;
|
case Attributes::NonLazyBind: return 1U << 31;
|
||||||
case Attributes::AddressSafety: return 1ULL << 32;
|
case Attributes::AddressSafety: return 1ULL << 32;
|
||||||
|
case Attributes::ForceSizeOpt: return 1ULL << 33;
|
||||||
}
|
}
|
||||||
llvm_unreachable("Unsupported attribute type");
|
llvm_unreachable("Unsupported attribute type");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue