Skip to content

Commit 3a730d8

Browse files
committed
Pass CPU string to LTO pipeline.
Previously an empty CPU string was passed to the LTO engine which resulted in a generic CPU for which certain features like NOPL were disabled. This fixes that. Patch by Pratik Bhatu! llvm-svn: 323801
1 parent cb6422d commit 3a730d8

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lld/Common/TargetOptionsCommandFlags.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ llvm::TargetOptions lld::InitTargetOptionsFromCodeGenFlags() {
3030
llvm::Optional<llvm::CodeModel::Model> lld::GetCodeModelFromCMModel() {
3131
return getCodeModel();
3232
}
33+
34+
std::string lld::GetCPUStr() { return ::getCPUStr(); }

lld/ELF/LTO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static std::unique_ptr<lto::LTO> createLTO() {
8787
Conf.DisableVerify = Config->DisableVerify;
8888
Conf.DiagHandler = diagnosticHandler;
8989
Conf.OptLevel = Config->LTOO;
90+
Conf.CPU = GetCPUStr();
9091

9192
// Set up a custom pipeline if we've been asked to.
9293
Conf.OptPipeline = Config->LTONewPmPasses;

lld/include/lld/Common/TargetOptionsCommandFlags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
namespace lld {
1919
llvm::TargetOptions InitTargetOptionsFromCodeGenFlags();
2020
llvm::Optional<llvm::CodeModel::Model> GetCodeModelFromCMModel();
21+
std::string GetCPUStr();
2122
}

lld/test/ELF/lto/cpu-string.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; REQUIRES: x86
2+
; RUN: llvm-as %s -o %t.o
3+
4+
; RUN: ld.lld %t.o -o %t.so -shared
5+
; RUN: llvm-objdump -d -section=".text" -no-leading-addr -no-show-raw-insn %t.so | FileCheck %s
6+
7+
; RUN: ld.lld -mllvm -mcpu=znver1 %t.o -o %m.so -shared
8+
; RUN: llvm-objdump -d -section=".text" -no-leading-addr -no-show-raw-insn %m.so | FileCheck -check-prefix=ZNVER1 %s
9+
10+
; CHECK: nop{{$}}
11+
12+
; ZNVER1: nopw
13+
14+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
15+
target triple = "x86_64-unknown-linux-gnu"
16+
17+
define void @foo() #0 {
18+
entry:
19+
call void asm sideeffect ".p2align 4, 0x90", "~{dirflag},~{fpsr},~{flags}"()
20+
ret void
21+
}
22+
23+
attributes #0 = { "no-frame-pointer-elim"="true" }

0 commit comments

Comments
 (0)