[RS4GC] Simplify attribute handling code NFC

Avoids use of AttributeList::getNumSlots, making it easier to change the
underlying implementation.

llvm-svn: 301671
This commit is contained in:
Reid Kleckner 2017-04-28 19:22:40 +00:00
parent f13722177b
commit 99351967c7
1 changed files with 22 additions and 44 deletions

View File

@ -1128,39 +1128,23 @@ normalizeForInvokeSafepoint(BasicBlock *BB, BasicBlock *InvokeParent,
// Create new attribute set containing only attributes which can be transferred
// from original call to the safepoint.
static AttributeList legalizeCallAttributes(AttributeList AS) {
AttributeList Ret;
static AttributeList legalizeCallAttributes(AttributeList AL) {
if (AL.isEmpty())
return AL;
for (unsigned Slot = 0; Slot < AS.getNumSlots(); Slot++) {
unsigned Index = AS.getSlotIndex(Slot);
if (Index == AttributeList::ReturnIndex ||
Index == AttributeList::FunctionIndex) {
for (Attribute Attr : make_range(AS.begin(Slot), AS.end(Slot))) {
// Do not allow certain attributes - just skip them
// Safepoint can not be read only or read none.
if (Attr.hasAttribute(Attribute::ReadNone) ||
Attr.hasAttribute(Attribute::ReadOnly))
continue;
// These attributes control the generation of the gc.statepoint call /
// invoke itself; and once the gc.statepoint is in place, they're of no
// use.
if (isStatepointDirectiveAttr(Attr))
continue;
Ret = Ret.addAttributes(
AS.getContext(), Index,
AttributeList::get(AS.getContext(), Index, AttrBuilder(Attr)));
}
}
// Just skip parameter attributes for now
// Remove the readonly, readnone, and statepoint function attributes.
AttrBuilder FnAttrs = AL.getFnAttributes();
FnAttrs.removeAttribute(Attribute::ReadNone);
FnAttrs.removeAttribute(Attribute::ReadOnly);
for (Attribute A : AL.getFnAttributes()) {
if (isStatepointDirectiveAttr(A))
FnAttrs.remove(A);
}
return Ret;
// Just skip parameter and return attributes for now
LLVMContext &Ctx = AL.getContext();
return AttributeList::get(Ctx, AttributeList::FunctionIndex,
AttributeSet::get(Ctx, FnAttrs));
}
/// Helper function to place all gc relocates necessary for the given
@ -1402,13 +1386,10 @@ makeStatepointExplicitImpl(const CallSite CS, /* to replace */
Call->setCallingConv(ToReplace->getCallingConv());
// Currently we will fail on parameter attributes and on certain
// function attributes.
AttributeList NewAttrs = legalizeCallAttributes(ToReplace->getAttributes());
// In case if we can handle this set of attributes - set up function attrs
// directly on statepoint and return attrs later for gc_result intrinsic.
Call->setAttributes(AttributeList::get(Call->getContext(),
AttributeList::FunctionIndex,
NewAttrs.getFnAttributes()));
// function attributes. In case if we can handle this set of attributes -
// set up function attrs directly on statepoint and return attrs later for
// gc_result intrinsic.
Call->setAttributes(legalizeCallAttributes(ToReplace->getAttributes()));
Token = Call;
@ -1431,13 +1412,10 @@ makeStatepointExplicitImpl(const CallSite CS, /* to replace */
Invoke->setCallingConv(ToReplace->getCallingConv());
// Currently we will fail on parameter attributes and on certain
// function attributes.
AttributeList NewAttrs = legalizeCallAttributes(ToReplace->getAttributes());
// In case if we can handle this set of attributes - set up function attrs
// directly on statepoint and return attrs later for gc_result intrinsic.
Invoke->setAttributes(AttributeList::get(Invoke->getContext(),
AttributeList::FunctionIndex,
NewAttrs.getFnAttributes()));
// function attributes. In case if we can handle this set of attributes -
// set up function attrs directly on statepoint and return attrs later for
// gc_result intrinsic.
Invoke->setAttributes(legalizeCallAttributes(ToReplace->getAttributes()));
Token = Invoke;