This is an archive of the discontinued LLVM Phabricator instance.

[mips] [IAS] Add support for the .insn directive.
ClosedPublic

Authored by tomatabacu on Mar 2 2015, 7:40 AM.

Details

Summary

This assembler directive marks the current label as an instruction label in microMIPS and MIPS16.

This initial implementation works only for microMIPS.

Diff Detail

Event Timeline

tomatabacu updated this revision to Diff 21008.Mar 2 2015, 7:40 AM
tomatabacu retitled this revision from to [mips] [IAS] Add support for the .insn directive..
tomatabacu updated this object.
tomatabacu edited the test plan for this revision. (Show Details)
tomatabacu added a reviewer: dsanders.
tomatabacu added a subscriber: Unknown Object (MLST).
dsanders accepted this revision.Apr 2 2015, 2:33 AM
dsanders edited edge metadata.

LGTM with a small change.

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
53–54

We should unconditionally clear Labels as the previous code did. We don't need to mark the same labels multiple times.

This revision is now accepted and ready to land.Apr 2 2015, 2:33 AM

Replied to review inline comment.

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
53–54

Labels actually is unconditionally cleared: in markLabelsAsMicroMips() for the if and directly for the else.

dsanders added inline comments.Apr 8 2015, 8:49 AM
lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
53–54

Good point. For consistency, could you pull it out of markLabelsAsMicroMips() into the two callers or sink the isMicroMipsEnabled() checks inside the markLabelsAsMicroMips() as an early-exit? Both options make the usage consistent and neither is better than the other. If you choose the latter though, you ought to change the name accordingly since it won't touch the labels if micromips is not enabled.

lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
649–652

I've just noticed that the Labels.clear() is missing here.

Replied to inline review comments.

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
53–54

"could you pull it out of markLabelsAsMicroMips() into the two callers"
No, because Labels can not be directly accessed from MipsTargetELFStreamer::emitDirectiveInsn(), because it's a private member of MipsELFStreamer.

"or sink the isMicroMipsEnabled() checks inside the markLabelsAsMicroMips() as an early-exit?"
I would personally prefer conditionally calling a function that will execute rather than unconditionally calling a function that may or may not execute.
Also, I can't think of a name for markLabelsAsMicroMips() with the microMIPS check inside which has a reasonable length.

lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
649–652

It's not missing, it's in markLabelsAsMicroMips(). We can't directly access Labels from here, because it's a private member of MipsELFStreamer.

dsanders added inline comments.Apr 15 2015, 3:54 AM
lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
53–54

"or sink the isMicroMipsEnabled() checks inside the markLabelsAsMicroMips() as an early-exit?"

I would personally prefer conditionally calling a function that will execute rather than unconditionally calling a function that may or may not execute.

There's nothing particularly wrong with a function doing nothing when it has nothing to do. In this case it wouldn't quite do nothing though. It would still empty the list of labels regardless of whether it annotated the labels or not.

Also, I can't think of a name for markLabelsAsMicroMips() with the microMIPS check inside which has a reasonable length.

The best name I can think of is createPendingLabelRelocs().

lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
649–652

It's not missing, it's in markLabelsAsMicroMips().

I mean it's missing from the else path. Sorry for being unclear.

The case I have in mind is something like:

.set nomicromips
foo:
  .insn
  .4byte 0
.set micromips
bar:
  addiu $1, $2, 3

I think the addiu will cause foo and bar to be marked microMIPS when it should only mark bar. This is because because the .insn didn't clear the list.

We can't directly access Labels from here, because it's a private member of MipsELFStreamer.

A public member for clearing the labels list would fix that but we won't need that if markLabelsAsMicroMips is called unconditionally and always clears the list regardless of whether it marks the labels or not.

tomatabacu updated this revision to Diff 23776.Apr 15 2015, 7:24 AM
tomatabacu edited edge metadata.

Renamed markLabelsAsMicroMips() to createPendingLabelRelocs().
Moved microMIPS check inside createPendingLabelRelocs().
Unconditionally clear Labels inside createPendingLabelRelocs().
Updated test to check that the labels get cleared after .insn.

LGTM with a couple tiny nits. Thanks.

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
4059

Nit: There's usually '()' when referencing functions.

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
69

Nit: ... if necessary for the subtarget.

tomatabacu updated this revision to Diff 23830.Apr 16 2015, 1:51 AM

Addressed nits.

tomatabacu closed this revision.Apr 16 2015, 2:56 AM