This is an archive of the discontinued LLVM Phabricator instance.

ARM IAS: support .inst directive
ClosedPublic

Authored by compnerd on Dec 14 2013, 10:06 PM.

Details

Summary

This adds support for the .inst directive. This is an ARM specific directive to
indicate an instruction encoded as a constant expression. The major difference
between .word, .short, or .byte and .inst is that the latter will be
disassembled as an instruction since it does not get flagged as data.

Diff Detail

Event Timeline

Hi Saleem,

Thanks for working on this, please update bug http://llvm.org/PR18199 after this has gone in to show that .inst is implemented (and give the commit number).

Also, please use "diff -U999" so that we can see the context before and after each change, as this way I have to go back and forth to an editor to understand which functions and classes were changed.

Hi Saleem,

This looks pretty good, despite the comments I've added. One thing I'd say that didn't attach to any particular line is that a test for llvm-mc's text printing would be a good idea (i.e. ARMTargetAsmStreamer::emitInst).

Cheers.

Tim.

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
8303

I agree with Joerg that we probably shouldn't have redundant arguments like Width and Suffix.

8330–8337

It seems a little odd that "size == 2" always produces an error but "size == 4" a warning.

lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
196

Size is unused in this function.

390

I think I'd prefer "Size == 2 || Size == 4".

393–394

I believe instructions are always stored in little-endian format on ARM (well, approximately, it seems to be configurable in R-class processors to avoid annoying people with brain-dead legacy code: see A3.3.1).

If so, this logic is probably unnecessary.

399

I'm reasonably sure there are more even numbers than 4.

compnerd added inline comments.Dec 15 2013, 2:24 PM
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
8330–8337

I modelled the behaviour against GAS. I would argue that relying on the truncation to be a warning is bad form, and have made this an error as well. While at it, introduced an additional negative test.

lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
196

Inlined the size selection.

393–394

Unfortunately, for compatibility with GAS, we need to do this stupid swapping :-(.

399

Bad message; fixed :-).

compnerd updated this revision to Unknown Object (????).Dec 15 2013, 2:26 PM

Address Tim's comments; add additional context for Renato.

I believe instructions are always stored in little-endian format on ARM (well, approximately, it seems to be configurable in R-class processors to avoid annoying people with brain-dead legacy code: see A3.3.1).

If so, this logic is probably unnecessary.

Unfortunately, for compatibility with GAS, we need to do this stupid swapping :-(.

I've just been scarred for life by digging into what goes on.
Apparently the linker gets the job of swapping the byte order on all
instructions back to little-endian, so the swapping *is* needed.

Other than that, I've just got one more small point (the rest looks
fine to me). The error message ""inst.w operand is too big" seems to
be printed in ARM mode, where it's a bit misleading.

Cheers.

Tim.

Hi Saleem,

Thanks for the context, it's a lot easier to understand the diffs that way. ;)

The patch looks good to me, too (apart from a few comments below), and the tests are really good, thanks!

cheers,
--renato

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
8362

Nit pick on style, this should be before the block to avoid extra indentation:

const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
if (!Value)
  return Error(Loc, "expected constant expression");

switch (Width) {
...
lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
386

Is it possible to put an assert here to make sure we're in the right mode instead of assuming the parser did a good job?

Good point on the diagnostics, Tim. I've made the diagnostics more appropriate and added an additional test.

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
8362

Done

lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
386

I like more strictness, added an assert(!IsThumb) and assert(IsThumb) before the mapping symbol emission appropriately.

compnerd accepted this revision.Dec 22 2013, 12:53 PM
compnerd closed this revision.