This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Support the .isnt directive for MachO and COFF targets
ClosedPublic

Authored by mstorsjo on Jul 27 2018, 2:09 PM.

Details

Summary

Contrary to ELF, we don't add any markers that distinguish data generated with .short/.long from normal instructions, so the .inst directive only adds compatibility with assembly that uses it.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Jul 27 2018, 2:09 PM

I can't comment too much on the use of .inst in machO and Windows. I have a small suggestion that might make it possible to share more of the implementation, but it is only a personal preference.

lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
52 ↗(On Diff #157764)

This looks almost identical to ARMELFStreamer::emitInst() with just the EmitARMMappingSymbol() and EmitThumbMappingSymbol().

Would it be possible to add a hook for adding the mapping symbol that the ELF backend can override and then make it use the implementation in ARMTargetStreamer?

mstorsjo added inline comments.Jul 30 2018, 4:22 AM
lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
52 ↗(On Diff #157764)

Yes, it's identical except for that, and minus some asserts about IsThumb which isn't available here.

Sharing in one way or another is doable, but it requires a little more than that. The ARMELFTargetStreamer::emitInst() method calls ARMELFStreamer::emitInst(), which contains the body of the method implementation, that we'd like to share. But ARMELFStreamer::EmitBytes() also overrides MCELFStreamer::EmitBytes to force adding a data symbol in front of it. So we can't have ARMTargetStreamer just call getStreamer().EmitBytes(StringRef(Buffer, Size)); since that will get the extra data prefix prepended.

So we can:

  • Add an emitBytesCode to ARMTargetStreamer which ARMELFTargetStreamer can override, which takes care of adding the arm/thumb mapping symbol and takes care of not adding a data symbol
  • Add getInstBytes to ARMTargetStreamer which both ARMTargetStreamer and ARMELFTargetStreamer can use to get the formatted bytes to print
  • Something else?
peter.smith added inline comments.Jul 30 2018, 5:55 AM
lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
52 ↗(On Diff #157764)

Thanks for pointing that out; it is more complicated than I first thought. One possible alternative could be to add an overaload of emitInst with a MCObjectStreamer parameter to ARMTargetStreamer which we could call emitBytes() and potentially add the mapping symbol hooks to. The backend overrides of emitInst could add the appropriate streamer.

This is getting to the point where the extra code to factor out the duplication may not be worth it. I suggest seeing if anyone else has any preferences.

@peter.smith, yeah, I think that sharing this might make it more complex. This looks fine to me, any other concerns?

peter.smith accepted this revision.Jul 31 2018, 1:43 AM

@peter.smith, yeah, I think that sharing this might make it more complex. This looks fine to me, any other concerns?

No further concerns. Looks good to me.

This revision is now accepted and ready to land.Jul 31 2018, 1:43 AM
This revision was automatically updated to reflect the committed changes.