This is an archive of the discontinued LLVM Phabricator instance.

Copy Elementtype Attribute to IR at Link step
ClosedPublic

Authored by chenyang.liu on Aug 26 2021, 5:58 PM.

Details

Summary

Copying IR during linking causes a type mismatch due to the field being missing in IRMover/Valuemapper. Adds the full range of typed attributes including elementtype attribute in the copy functions.

Diff Detail

Event Timeline

chenyang.liu created this revision.Aug 26 2021, 5:58 PM
chenyang.liu requested review of this revision.Aug 26 2021, 5:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2021, 5:58 PM
nikic added a subscriber: nikic.Aug 27 2021, 12:52 AM
nikic added inline comments.
llvm/lib/Linker/IRMover.cpp
652–654

You can use FirstTypeAttr and LastTypeAttr to generalize this.

chenyang.liu added inline comments.Aug 27 2021, 10:51 AM
llvm/lib/Linker/IRMover.cpp
652–654

I can do it like this if you think it's ok:

for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
  auto Attr = Attrs.getAttribute(i);
  if (Attr.isTypeAttribute()) {
    auto TypedAttr = Attr.getKindAsEnum();
    if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
      Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, TypeMap.get(Ty));
      break;
chenyang.liu added inline comments.Aug 27 2021, 1:12 PM
llvm/lib/Linker/IRMover.cpp
652–654

Nvm, the existing Attributes API doesn't allow get/set without specifying the specific attribute itself. I wouldn't be able to generalize the attributes with only the firsttype/lasttype as there isn't a way to get the set of attributes of specific type. It's also out of the scope of this change that I want to make.

nikic added inline comments.Aug 27 2021, 1:31 PM
llvm/lib/Linker/IRMover.cpp
652–654

To be clear, what I'm suggesting is that you replace the hardcoded list of type attributes with something like for (Attribute::AttrKind TypedAttr = Attribute::FirstTypeAttr; TypedAttr <= Attribute::LastTypeAttr; TypedAttr++).

Updated the loop to use FirstTypeAttr and LastTypeAttr.

chenyang.liu edited the summary of this revision. (Show Details)

Rebased to fix conflicts

chenyang.liu marked an inline comment as done.Sep 1 2021, 12:12 PM

Generate new diff.

nikic accepted this revision.Sep 3 2021, 12:58 AM

LGTM

This revision is now accepted and ready to land.Sep 3 2021, 12:58 AM

I don't see any issues locally. Is there something else required to get the automated build passing?

nikic added a comment.Sep 3 2021, 1:15 AM

@chenyang.liu You can ignore test failures that don't look related to your change.

This revision was landed with ongoing or failed builds.Sep 7 2021, 11:46 AM
This revision was automatically updated to reflect the committed changes.