[PATCH] D47211: [X86] Implement more of x86-64 large and medium PIC code models

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 11:29:05 PDT 2018


rnk created this revision.
rnk added reviewers: chandlerc, echristo.
Herald added a subscriber: hiraditya.

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 at GOT(%rbx), %rax
  movq local_gv at GOTOFF(%rbx), %rax

All calls end up being indirect:

  movabsq $local_fn at 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 at 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 at 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.


https://reviews.llvm.org/D47211

Files:
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86InstrCompiler.td
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86Subtarget.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/CodeGen/X86/cleanuppad-large-codemodel.ll
  llvm/test/CodeGen/X86/code-model.ll
  llvm/test/CodeGen/X86/fast-isel-call-cleanup.ll
  llvm/test/CodeGen/X86/fast-isel-constpool.ll
  llvm/test/CodeGen/X86/hipe-cc64.ll
  llvm/utils/UpdateTestChecks/asm.py
  llvm/utils/update_llc_test_checks.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47211.148060.patch
Type: text/x-patch
Size: 29942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/9c38081e/attachment.bin>


More information about the llvm-commits mailing list