[PATCH] D70724: [PowerPC] Add Support for indirect calls on AIX.

Sean Fertile via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 09:35:24 PST 2019


sfertile created this revision.
sfertile added reviewers: cebowleratibm, ZarkoCA, Xiangling_L.
Herald added subscribers: shchenz, jsji, kbarton, hiraditya, nemanjai.
Herald added a project: LLVM.
sfertile edited the summary of this revision.
Herald added a subscriber: wuzish.
sfertile edited the summary of this revision.
sfertile edited the summary of this revision.

Extends the desciptor based indirect call support for 32-bit codegen, and enables indirect calls for AIX.

In-depth Description:
In a function descriptor based ABI, a function pointer points at a descriptor structure as opposed to the functions entry point. The
descriptor takes the form of 3 pointers: 1 for the functions entry point, 1 for the TOC anchor of the module containing the function
definition, and 1 for the environment pointer.

  struct FunctionDescriptor {
    void *EntryPoint;
    void *TOCAnchor;
    void *EnvironmentPointer;
  };


An indirect call has several steps of loading the the information from the descriptor into the proper registers for setting up the call. Namely it has to:

1. Save the callers TOC pointer into the TOC save slot in the linkage area, and then load the callees TOC pointer into general purpose register 2.
2. Load the function descriptors entry point into the count register.
3. Load the environment pointer into general purpose register 11.
4. Perform the call by branching on count register.
5. Restore the callers TOC pointer after returning from the indirect call.

A couple important caveats to the above:

- There is no way to directly load a value from memory into the count register. Instead we populate the count register by loading the entry point address into a gpr and then moving the gpr to the count register.
- The TOC restore has to come immediately after the branch on count register instruction (ie the 1st instruction executed after we return from the call). This is an implementation limitation. We could in theory schedule the restore elsewhere as long as no uses of the TOC pointer fall in between the call an the restore, however to keep it simple we insert a pseudo instruction that represents both the indirect branch instruction and the load instruction that restores the callers toc from the linkage area. As they flow through the compiler as a single pseudo instruction, nothing can be inserted between them and the callers TOC must be valid at any use.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70724

Files:
  llvm/lib/Target/PowerPC/P9InstrResources.td
  llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstrFormats.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCSubtarget.h
  llvm/test/CodeGen/PowerPC/aix-trampoline.ll
  llvm/test/CodeGen/PowerPC/aix_indirect_call.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70724.231084.patch
Type: text/x-patch
Size: 19661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191126/2891c53e/attachment.bin>


More information about the llvm-commits mailing list