[PATCH] D73664: [PowerPC][Future] Add Support For Functions That Do Not Use A TOC.

Stefan Pintilie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 13:59:13 PST 2020


stefanp created this revision.
stefanp added reviewers: nemanjai, lei, power-llvm-team, hfinkel.
Herald added subscribers: steven.zhang, shchenz, jsji, kbarton, hiraditya.
Herald added a project: LLVM.

On PowerPC most functions require a valid TOC pointer.

This is the case because either the function itself needs to use this pointer to access the TOC or because other functions that are called from that function expect a valid TOC pointer in the register R2 <https://reviews.llvm.org/source/clang-tools-extra/>. The main exception to this is leaf functions that do not access the TOC since they are guaranteed not to need a valid TOC pointer.

This patch introduces a feature that will allow more functions to not require a valid TOC pointer in R2 <https://reviews.llvm.org/source/clang-tools-extra/>.

The feature works as follows:

- If a function requires a TOC pointer because it accesses the TOC then that will remain as it was before.
- If a funcction requires a TOC pointer only because it has a call to another function that may require a TOC pointer then we can modify the call site as follows:

Call Site Before

  bl callee
  nop
   

Call Site After

  bl callee at notoc

The @notoc relocation tells the linker that the caller does not have a
valid TOC pointer and the nop after the call is removed because it is no
longer needed as we do not need to restore R2 <https://reviews.llvm.org/source/clang-tools-extra/> after the call.

This work is done as preparation for upcoming PCRelative work to be done under the future CPU.
The support will only be added under future CPU for now.


https://reviews.llvm.org/D73664

Files:
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/BinaryFormat/ELFRelocs/PowerPC64.def
  llvm/include/llvm/MC/MCExpr.h
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCFixupKinds.h
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
  llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp
  llvm/lib/Target/PowerPC/PPCScheduleP9.td
  llvm/lib/Target/PowerPC/PPCSubtarget.cpp
  llvm/lib/Target/PowerPC/PPCSubtarget.h
  llvm/test/CodeGen/PowerPC/pcrel-call-linkage.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73664.241280.patch
Type: text/x-patch
Size: 27521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200129/cd820c8b/attachment.bin>


More information about the llvm-commits mailing list