[PATCH] D130777: Enable embedded lto for XCOFF.

2023-08-31 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

This needs rebase after fatLTO support.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130777/new/

https://reviews.llvm.org/D130777

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130777: Enable embedded lto for XCOFF.

2022-07-29 Thread Sean Fertile via Phabricator via cfe-commits
sfertile created this revision.
sfertile added reviewers: hubert.reinterpretcast, DiggerLin, nemanjai, MaskRay, 
tejohnson, mehdi_amini, phosek, arda.
Herald added subscribers: ormris, StephenFan, steven_wu, kbarton, hiraditya, 
inglorion, mgorny.
Herald added a project: All.
sfertile requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

The traditional system compiler (xlc) on AIX uses a 'fat' object format for LTO 
by default, embedding the intermediate representation into a special '.ipa' 
section in native XCOFF object files. Then at link time depending on command 
line options either a native link or an ipa link can be performed. This patch 
adds support for embedding the pre-link IR into the module which is then 
codegened to a native XCOFF object with the bitcode emebededed in the .info 
section. The .info section representation starts with a magic number, followed 
by an 8-byte size, an identifier string and a 4-byte unsigned difference, 
finally followed by the payload. The magic number and identifier string indcate 
to the linker that the embedded metadata is bitcode and it is appropriate for 
use in LTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130777

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/PowerPC/aix-embedded-bitcode.c
  clang/test/CodeGen/embed-lto-metadata.c
  clang/test/Driver/embedded-lto.c
  llvm/include/llvm/Bitcode/EmbedBitcodePass.h
  llvm/include/llvm/MC/MCStreamer.h
  llvm/include/llvm/MC/MCXCOFFStreamer.h
  llvm/lib/Bitcode/Writer/CMakeLists.txt
  llvm/lib/Bitcode/Writer/EmbedBitcodePass.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCStreamer.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/Bitcode/embed-multiple.ll
  llvm/test/Bitcode/embed-unsupported-object-format.ll
  llvm/test/Bitcode/embed.ll
  llvm/test/CodeGen/PowerPC/aix-embeded-bitcode.ll
  llvm/test/CodeGen/PowerPC/aix-embeded-module-padding.ll
  llvm/test/Transforms/Util/embeded-lto-TLI-mappings.ll

Index: llvm/test/Transforms/Util/embeded-lto-TLI-mappings.ll
===
--- /dev/null
+++ llvm/test/Transforms/Util/embeded-lto-TLI-mappings.ll
@@ -0,0 +1,20 @@
+; RUN: opt -vector-library=MASSV  -passes='function(inject-tli-mappings),embed-bitcode' -S < %s | FileCheck %s
+
+target triple = "powerpc-unknown-aix"
+
+; CHECK: @llvm.compiler.used = appending global [3 x ptr] [ptr @__sind2, ptr @__log10f4, ptr @llvm.embedded.module], section "llvm.metadata"
+
+define double @sin_f64(double %in) {
+  %call = tail call double @sin(double %in)
+  ret double %call
+}
+
+declare double @sin(double) #0
+
+define float @call_llvm.log10.f32(float %in) {
+  %call = tail call float @llvm.log10.f32(float %in)
+  ret float %call
+}
+
+declare float @llvm.log10.f32(float) #0
+attributes #0 = { nounwind readnone }
Index: llvm/test/CodeGen/PowerPC/aix-embeded-module-padding.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-embeded-module-padding.ll
@@ -0,0 +1,20 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | \
+; RUN: FileCheck %s
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | \
+; RUN: FileCheck %s
+
+target datalayout = "E-m:a-p:32:32-i64:64-n32"
+target triple = "powerpc-ibm-aix7.2.0.0"
+
+@c = local_unnamed_addr global i8 -85, align 1
+@llvm.embedded.module = private constant [1647 x i8] c"BC\C0\DE5\14\00\00\05\00\00\00b\0C0$MY\BEf\9D\FB\B4O\1B\C8$D\012\05\00!\0C\00\00_\01\00\00\0B\02!\00\02\00\00\00\16\00\00\00\07\81#\91A\C8\04I\06\1029\92\01\84\0C%\05\08\19\1E\04\8Bb\80\0CE\02B\92\0BBd\102\148\08\18K\0A22\88Hp\C4!#D\12\87\8C\10A\92\02d\C8\08\B1\14 CF\88 \C9\0122\84\18*(*\901|\B0\\\91 \C3\C8\00\00\00\89 \00\00\0B\00\00\002\22\C8\08 bF\00!+$\98\0C!%$\98\0C\19'\0C\85\A4\90`2d\\ $c\82\80\98#@\08\03\01s\04`\00\00\13,xx\87{(\07y\80\87qh\83t\10\87vh\83pH\07|\B8\037\90\037\80\037\80\83\0DX)\B4A;\E8A8\B4\01<\E8\C1\1C\C8\81\1E\CC\81\1C\B4A:\D8\01\1D\E8\81\1D\D0A\1B\B8\C3\1C\C8\81\D2\03B\84\04\90!#EB\00\8D\10\86}$\A41\16\E27\16'\00\16_\D8!\01\01 \08@\00\00\80\00\00\00\00\04\80\C4\06\81\C2d\01\00\00Y \00\00\00\07\00\00\002\1E\98\0C\19\11L\90\8C\09\C6\04CB\AD\06\D0J\A0\08\CAa\04\00\00\00\B1\18\00\00\9B\00\00\003\08\80\1C\C4\E1\1Cf\14\01=\88C8\84\C3\8CB\80\07yx\07s\98q\0C\E6\00\0F\ED\10\0E\F4\80\0E3\0CB\1E\C2\C1\1D\CE\A1\1Cf0\05=\88C8\84\83\1B\CC\03=\C8C=\8C\03=\CCx\8Ctp\07{\08\07yH\87pp\07zp\03vx\87p