Contants generation

Hi,

I’d like to generate constants inside .text in order to use ip-relative loads, when the code model is “large”.
How can I do this?
(I’m on X86_64 linux)

Thank you.

  • Elena

Hi Elena,

I’d like to generate constants inside .text in order to use ip-relative
loads, when the code model is “large”.

I don't think this is a sequence the x86 backend supports at the
moment, but it is how ARM handles its constant-pools. The outline is
that you have a pass which looks through a functions constpool uses
and emits a pseudo-instruction for each, which is then handled in the
AsmPrinter.

ARM has the added complication that the instructions accessing these
constants are of limited range, which means lots of extra complexity
making sure they can be reached when needed. This is probably
unnecessary with x86's +/- 2GB limit. Any single function over 2GB in
size has bigger problems than where its constants are.

Actually, originally the AArch64 backend did the same thing but I
switched to the x86 model back in February. Which means thar r175258
is a nice potted (but reversed) description of all the steps needed.
Ignore the more baroque parts of AArch64ConstantIslandsPass.cpp, yours
will probably only have to add a bunch of CONSTPOOL_ENTRYs at the end
of the function (the doInitialPlacement method, though even that does
more than you need).

I'll watch with interest to see how you handle it, AArch64 will
probably have the same issues in the large code model.

Cheers.

Tim.

Hi again,

Actually, I've just been looking at the existing code and the ARM
solution may be over-complicated for this situation.

You should be able to override EmitConstantPool directly, or possibly
even just override getSectionForConstantKind in
X86LinuxTargetObjectFile (and perhaps others) to return .text.

Tim.

That what I actually did now, locally in the code.
But I still see the " movabsq"

  .text
  .align 8, 0x90
.LCPI0_0:
  .quad 4606281698874543309 # double 0.9
.LCPI0_1:
  .quad 4631147119616759172 # double 42.2794408
.LCPI0_2:
  .long 1065353216 # float 1
  .zero 4
...
  movabsq $.LCPI0_1, %rax # encoding: [0x48,0xb8,A,A,A,A,A,A,A,A]
                                        # fixup A - offset: 2, value: .LCPI0_1, kind: FK_Data_8
  vbroadcastsd (%rax), %ymm0 # encoding: [0xc4,0xe2,0x7d,0x19,0x00]

Actually, I'm looking for a flag that can say that the whole constants pool is in code section.

- Elena

But I still see the " movabsq"

Ah yes, I'd forgotten that the instruction sequence is still largely
decided in X86ISelLowering.cpp.

You should start by tweaking the LowerConstantPool function. But that
seems to cause an ISel failure that you'll have to investigate
(something isn't expecting to have to deal with RIP relative accesses
in Large code model).

Tim.