OSDN Git Service

Re-land r335297 "[X86] Implement more of x86-64 large and medium PIC code models"
authorReid Kleckner <rnk@google.com>
Mon, 25 Jun 2018 18:16:27 +0000 (18:16 +0000)
committerReid Kleckner <rnk@google.com>
Mon, 25 Jun 2018 18:16:27 +0000 (18:16 +0000)
commit2d21bce8d984402854fd9ebf54c60ddbbd90afa8
tree5745815677312594bc0c1d8b1232737c9a989343
parent88313d288dfd392acc5e3aac16885becf2093cce
Re-land r335297 "[X86] Implement more of x86-64 large and medium PIC code models"

The large code model allows code and data segments to exceed 2GB, which
means that some symbol references may require a displacement that cannot
be encoded as a displacement from RIP. The large PIC model even relaxes
the assumption that the GOT itself is within 2GB of all code. Therefore,
we need a special code sequence to materialize it:
  .LtmpN:
    leaq .LtmpN(%rip), %rbx
    movabsq $_GLOBAL_OFFSET_TABLE_-.LtmpN, %rax # Scratch
    addq %rax, %rbx # GOT base reg

From that, non-local references go through the GOT base register instead
of being PC-relative loads. Local references typically use GOTOFF
symbols, like this:
    movq extern_gv@GOT(%rbx), %rax
    movq local_gv@GOTOFF(%rbx), %rax

All calls end up being indirect:
    movabsq $local_fn@GOTOFF, %rax
    addq %rbx, %rax
    callq *%rax

The medium code model retains the assumption that the code segment is
less than 2GB, so calls are once again direct, and the RIP-relative
loads can be used to access the GOT. Materializing the GOT is easy:
    leaq _GLOBAL_OFFSET_TABLE_(%rip), %rbx # GOT base reg

DSO local data accesses will use it:
    movq local_gv@GOTOFF(%rbx), %rax

Non-local data accesses will use RIP-relative addressing, which means we
may not always need to materialize the GOT base:
    movq extern_gv@GOTPCREL(%rip), %rax

Direct calls are basically the same as they are in the small code model:
They use direct, PC-relative addressing, and the PLT is used for calls
to non-local functions.

This patch adds reasonably comprehensive testing of LEA, but there are
lots of interesting folding opportunities that are unimplemented.

I restricted the MCJIT/eh-lg-pic.ll test to Linux, since the large PIC
code model is not implemented for MachO yet.

Differential Revision: https://reviews.llvm.org/D47211

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335508 91177308-0d34-0410-b5e6-96231b3b80d8
14 files changed:
lib/Target/X86/X86ISelDAGToDAG.cpp
lib/Target/X86/X86InstrCompiler.td
lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86MCInstLower.cpp
lib/Target/X86/X86Subtarget.cpp
lib/Target/X86/X86TargetMachine.cpp
test/CodeGen/X86/cleanuppad-large-codemodel.ll
test/CodeGen/X86/code-model.ll [new file with mode: 0644]
test/CodeGen/X86/fast-isel-call-cleanup.ll
test/CodeGen/X86/fast-isel-constpool.ll
test/CodeGen/X86/hipe-cc64.ll
test/ExecutionEngine/MCJIT/eh-lg-pic.ll
utils/UpdateTestChecks/asm.py
utils/update_llc_test_checks.py