forked from OSchip/llvm-project
[lld-macho] Add support for -mcpu, -mattr, -code-model in LTO
`-mcpu` and `-code-model` tests were copied from similar ones in LLD-ELF. There doesn't seem to be an equivalent test for `-mattr` in LLD-ELF, so I've verified our behavior by cribbing a test from CodeGen/X86/recip-fastmath.ll. Reviewed By: #lld-macho, compnerd, MaskRay Differential Revision: https://reviews.llvm.org/D92912
This commit is contained in:
parent
863f7a745e
commit
29d3b0e471
|
@ -654,6 +654,17 @@ static bool isPie(opt::InputArgList &args) {
|
|||
return args.hasArg(OPT_pie);
|
||||
}
|
||||
|
||||
static void parseClangOption(StringRef opt, const Twine &msg) {
|
||||
std::string err;
|
||||
raw_string_ostream os(err);
|
||||
|
||||
const char *argv[] = {"lld", opt.data()};
|
||||
if (cl::ParseCommandLineOptions(2, argv, "", &os))
|
||||
return;
|
||||
os.flush();
|
||||
error(msg + ": " + StringRef(err).trim());
|
||||
}
|
||||
|
||||
bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
|
||||
raw_ostream &stdoutOS, raw_ostream &stderrOS) {
|
||||
lld::stdoutOS = &stdoutOS;
|
||||
|
@ -788,6 +799,14 @@ bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
|
|||
error("-sub_library " + searchName + " does not match a supplied dylib");
|
||||
}
|
||||
|
||||
// Parse LTO options.
|
||||
if (auto *arg = args.getLastArg(OPT_mcpu))
|
||||
parseClangOption(saver.save("-mcpu=" + StringRef(arg->getValue())),
|
||||
arg->getSpelling());
|
||||
|
||||
for (auto *arg : args.filtered(OPT_mllvm))
|
||||
parseClangOption(arg->getValue(), arg->getSpelling());
|
||||
|
||||
initLLVM();
|
||||
compileBitcodeFiles();
|
||||
replaceCommonSymbols();
|
||||
|
|
|
@ -27,6 +27,9 @@ using namespace llvm::sys;
|
|||
static lto::Config createConfig() {
|
||||
lto::Config c;
|
||||
c.Options = initTargetOptionsFromCodeGenFlags();
|
||||
c.CodeModel = getCodeModelFromCMModel();
|
||||
c.CPU = getCPUStr();
|
||||
c.MAttrs = getMAttrs();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
|
@ -876,7 +876,9 @@ def not_for_dyld_shared_cache : Flag<["-"], "not_for_dyld_shared_cache">,
|
|||
Group<grp_rare>;
|
||||
def mllvm : Separate<["-"], "mllvm">,
|
||||
HelpText<"Options to pass to LLVM">,
|
||||
Flags<[HelpHidden]>,
|
||||
Group<grp_rare>;
|
||||
def mcpu : Separate<["-"], "mcpu">,
|
||||
HelpText<"Processor family target for LTO code generation">,
|
||||
Group<grp_rare>;
|
||||
|
||||
def grp_deprecated : OptionGroup<"deprecated">, HelpText<"DEPRECATED">;
|
||||
|
@ -1210,10 +1212,6 @@ def uikitformac_version_min : Flag<["-"], "uikitformac_version_min">,
|
|||
HelpText<"Alias for -maccatalyst_version_min">,
|
||||
Flags<[HelpHidden]>,
|
||||
Group<grp_undocumented>;
|
||||
def mcpu : Flag<["-"], "mcpu">,
|
||||
HelpText<"This option is undocumented in ld64">,
|
||||
Flags<[HelpHidden]>,
|
||||
Group<grp_undocumented>;
|
||||
def no_compact_unwind : Flag<["-"], "no_compact_unwind">,
|
||||
HelpText<"This option is undocumented in ld64">,
|
||||
Flags<[HelpHidden]>,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
; REQUIRES: x86
|
||||
; RUN: llvm-as %s -o %t.o
|
||||
; RUN: %lld -lSystem %t.o -o %ts -mllvm -code-model=small
|
||||
; RUN: %lld -lSystem %t.o -o %tl -mllvm -code-model=large
|
||||
; RUN: llvm-objdump -d %ts | FileCheck %s --check-prefix=CHECK-SMALL
|
||||
; RUN: llvm-objdump -d %tl | FileCheck %s --check-prefix=CHECK-LARGE
|
||||
|
||||
target triple = "x86_64-apple-darwin"
|
||||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
@data = internal constant [0 x i32] []
|
||||
|
||||
define i32* @main() nounwind readonly {
|
||||
entry:
|
||||
; CHECK-SMALL-LABEL: <_main>:
|
||||
; CHECK-SMALL: leaq [[#]](%rip), %rax
|
||||
; CHECK-LARGE-LABEL: <_main>:
|
||||
; CHECK-LARGE: movabsq $[[#]], %rax
|
||||
ret i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0)
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
; REQUIRES: x86
|
||||
; RUN: llvm-as %s -o %t.o
|
||||
|
||||
; RUN: %lld %t.o -o %t.dylib -dylib
|
||||
; RUN: llvm-objdump -d --section="__text" --no-leading-addr --no-show-raw-insn %t.dylib | FileCheck %s
|
||||
; CHECK: nop{{$}}
|
||||
|
||||
; RUN: %lld -mcpu znver1 %t.o -o %t.znver1.dylib -dylib
|
||||
; RUN: llvm-objdump -d --section="__text" --no-leading-addr --no-show-raw-insn %t.znver1.dylib | FileCheck %s --check-prefix=ZNVER1
|
||||
|
||||
; ZNVER1: nopw
|
||||
; ZNVER1-NOT: nop{{$}}
|
||||
|
||||
target triple = "x86_64-apple-darwin"
|
||||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
define void @foo() #0 {
|
||||
entry:
|
||||
call void asm sideeffect ".p2align 4, 0x90", "~{dirflag},~{fpsr},~{flags}"()
|
||||
ret void
|
||||
}
|
||||
|
||||
attributes #0 = { "frame-pointer"="all" }
|
|
@ -0,0 +1,35 @@
|
|||
; REQUIRES: x86
|
||||
; RUN: llvm-as %s -o %t.o
|
||||
|
||||
;; Verify that LTO behavior can be tweaked using -mattr.
|
||||
|
||||
; RUN: %lld -mcpu haswell -mllvm -mattr=+fma %t.o -o %t.dylib -dylib
|
||||
; RUN: llvm-objdump -d --section="__text" --no-leading-addr --no-show-raw-insn %t.dylib | FileCheck %s --check-prefix=FMA
|
||||
|
||||
; RUN: %lld -mcpu haswell -mllvm -mattr=-fma %t.o -o %t.dylib -dylib
|
||||
; RUN: llvm-objdump -d --section="__text" --no-leading-addr --no-show-raw-insn %t.dylib | FileCheck %s --check-prefix=NO-FMA
|
||||
|
||||
; FMA: <_foo>:
|
||||
; FMA-NEXT: vrcpss %xmm0, %xmm0, %xmm1
|
||||
; FMA-NEXT: vfmsub213ss 7(%rip), %xmm1, %xmm0 # 2d4
|
||||
; FMA-NEXT: vfnmadd132ss %xmm1, %xmm1, %xmm0
|
||||
; FMA-NEXT: retq
|
||||
|
||||
; NO-FMA: <_foo>:
|
||||
; NO-FMA-NEXT: vrcpss %xmm0, %xmm0, %xmm1
|
||||
; NO-FMA-NEXT: vmulss %xmm1, %xmm0, %xmm0
|
||||
; NO-FMA-NEXT: vmovss 16(%rip), %xmm2 # 2e0
|
||||
; NO-FMA-NEXT: vsubss %xmm0, %xmm2, %xmm0
|
||||
; NO-FMA-NEXT: vmulss %xmm0, %xmm1, %xmm0
|
||||
; NO-FMA-NEXT: vaddss %xmm0, %xmm1, %xmm0
|
||||
; NO-FMA-NEXT: retq
|
||||
|
||||
target triple = "x86_64-apple-darwin"
|
||||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
define float @foo(float %x) #0 {
|
||||
%div = fdiv fast float 1.0, %x
|
||||
ret float %div
|
||||
}
|
||||
|
||||
attributes #0 = { "unsafe-fp-math"="true" "reciprocal-estimates"="divf,vec-divf" }
|
Loading…
Reference in New Issue