LLVM v3.9.0 and '.p2align'

While investigating a new bug in some code using our LLVM v3.9.0 derived compiler, it turns out that it now emits ‘.p2align’ unconditionally if the alignment value is a power of 2. Previously this was dependent on ‘MAI->getAlignmentIsInBytes()’.

We don’t support non-power-of 2 alignment anyway, but our assembler does not support ‘.p2align’ and there appears to be no way of changing this in a target configurable way.

There have been emails about the fact that the ‘MCAsmStreamer’ implementation is hidden, and the argument is that if the target needs something different it can implement its own specialisation of ‘MCStreamer’. While this is technically true, but ‘MCAsmStreamer’ already does more than 90% of what I need, and to implement my own specialisation really means cloning ‘MCAsmStreamer’, and editing those few places where my assembly requirements are different to it. And then the target that does this clone is required to carefully track future revisions of ‘MCAsmStreamer’ to ensure that their clone is still a clone.

Generally it is good practice to reuse existing code, and specialise only for the differences, so it really make a lot more sense to publish it in a header, and allow the target to sub-class it with overrides for each of the methods it wants to handle differently.

As it is, I have had to add yet another tweak to this code, all of which are relatively trivial:

· ‘MCAsmStreamer::EmitAssignment’ changed to implement aliases as ‘.alias symA symB’ instead of ‘symA - symB’

· ‘MCAsmStreamer::EmitBytes’ to break long ‘.byte’ sequences into multiple ‘.byte’ sequences on multiple lines (actually, I could retire this change as our assembler now handles the long sequences)

· ‘MCAsmStreamer::EmitFill’ because we need an additional argument in the directive

· ‘MCAsmStreamer::EmitValueToAlignment’ to use ‘.align’ instead of ‘.p2align’

These are such small changes that it really does not warrant me cloning 1,600 lines of code so that I can tweak 8 of them, and being able to sub-class the otherwise very useful ‘MCAsmStreamer’ class would greatly simplify adapting LLVM for non-gas compliant assemblers. It seems to me that splitting this file into a source and a header is not going to create maintenance problems for LLVM, while at the same time it would greatly simplify the implementation of compilers for non-mainstream assemblers.

Thanks,

MartinO