forked from OSchip/llvm-project
[AttrBuilder] Add string attribute getter (NFC)
This avoids the need to scan through td_attrs() in AutoUpgrade, decoupling it from AttrBuilder implementation details.
This commit is contained in:
parent
1b09d0c42b
commit
541322540e
|
@ -1074,6 +1074,10 @@ public:
|
|||
/// Return true if the builder has an alignment attribute.
|
||||
bool hasAlignmentAttr() const;
|
||||
|
||||
/// Return Attribute with the given Kind. The returned attribute will be
|
||||
/// invalid if the Kind is not present in the builder.
|
||||
Attribute getAttribute(StringRef Kind) const;
|
||||
|
||||
/// Return raw (possibly packed/encoded) value of integer attribute or 0 if
|
||||
/// not set.
|
||||
uint64_t getRawIntAttr(Attribute::AttrKind Kind) const;
|
||||
|
|
|
@ -1791,9 +1791,15 @@ bool AttrBuilder::overlaps(const AttributeMask &AM) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool AttrBuilder::contains(StringRef A) const {
|
||||
Attribute AttrBuilder::getAttribute(StringRef A) const {
|
||||
auto It = lower_bound(TargetDepAttrs, A, StringAttributeComparator());
|
||||
return It != TargetDepAttrs.end() && It->hasAttribute(A);
|
||||
if (It != TargetDepAttrs.end() && It->hasAttribute(A))
|
||||
return *It;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool AttrBuilder::contains(StringRef A) const {
|
||||
return getAttribute(A).isValid();
|
||||
}
|
||||
|
||||
bool AttrBuilder::hasAttributes() const {
|
||||
|
|
|
@ -4585,11 +4585,10 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) {
|
|||
|
||||
void llvm::UpgradeAttributes(AttrBuilder &B) {
|
||||
StringRef FramePointer;
|
||||
if (B.contains("no-frame-pointer-elim")) {
|
||||
Attribute A = B.getAttribute("no-frame-pointer-elim");
|
||||
if (A.isValid()) {
|
||||
// The value can be "true" or "false".
|
||||
for (const auto &A : B.td_attrs())
|
||||
if (A.getKindAsString() == "no-frame-pointer-elim")
|
||||
FramePointer = A.getValueAsString() == "true" ? "all" : "none";
|
||||
FramePointer = A.getValueAsString() == "true" ? "all" : "none";
|
||||
B.removeAttribute("no-frame-pointer-elim");
|
||||
}
|
||||
if (B.contains("no-frame-pointer-elim-non-leaf")) {
|
||||
|
@ -4601,12 +4600,10 @@ void llvm::UpgradeAttributes(AttrBuilder &B) {
|
|||
if (!FramePointer.empty())
|
||||
B.addAttribute("frame-pointer", FramePointer);
|
||||
|
||||
if (B.contains("null-pointer-is-valid")) {
|
||||
A = B.getAttribute("null-pointer-is-valid");
|
||||
if (A.isValid()) {
|
||||
// The value can be "true" or "false".
|
||||
bool NullPointerIsValid = false;
|
||||
for (const auto &A : B.td_attrs())
|
||||
if (A.getKindAsString() == "null-pointer-is-valid")
|
||||
NullPointerIsValid = A.getValueAsString() == "true";
|
||||
bool NullPointerIsValid = A.getValueAsString() == "true";
|
||||
B.removeAttribute("null-pointer-is-valid");
|
||||
if (NullPointerIsValid)
|
||||
B.addAttribute(Attribute::NullPointerIsValid);
|
||||
|
|
Loading…
Reference in New Issue