Skip to content

Commit 6a6ade0

Browse files
committed
Fix default value for -mapx-relax-relocations option.
Rename the pass of suppressing APX features for relocation.
1 parent a98371a commit 6a6ade0

File tree

9 files changed

+68
-38
lines changed

9 files changed

+68
-38
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get u
201201
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
202202
CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in assembly
203203
CODEGENOPT(X86RelaxRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
204-
CODEGENOPT(X86APXRelaxRelocations, 1, 0) ///< -Wa,-mrelax-relocations={yes,no}
204+
CODEGENOPT(X86APXRelaxRelocations, 1, 0) ///< -Wa,-mapx-relax-relocations={yes,no}
205205
CODEGENOPT(X86Sse2Avx , 1, 0) ///< -Wa,-msse2avx
206206

207207
/// When false, this attempts to generate code as if the result of an

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7444,7 +7444,7 @@ def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
74447444
MarshallingInfoNegativeFlag<CodeGenOpts<"X86RelaxRelocations">>;
74457445
def mapx_relax_relocations_yes : Flag<["-"], "mapx-relax-relocations=yes">,
74467446
HelpText<"Enable x86 APX relax relocations">,
7447-
MarshallingInfoNegativeFlag<CodeGenOpts<"X86APXRelaxRelocations">>;
7447+
MarshallingInfoFlag<CodeGenOpts<"X86APXRelaxRelocations">>;
74487448
def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
74497449
HelpText<"Save temporary labels in the symbol table. "
74507450
"Note this may change .s semantics and shouldn't generally be used "

llvm/lib/Target/X86/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ set(sources
8989
GISel/X86InstructionSelector.cpp
9090
GISel/X86LegalizerInfo.cpp
9191
GISel/X86RegisterBankInfo.cpp
92-
X86SuppressEGPRAndNDDForReloc.cpp
92+
X86SuppressAPXForReloc.cpp
9393
)
9494

9595
add_llvm_target(X86CodeGen ${sources}

llvm/lib/Target/X86/X86.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ FunctionPass *createX86LoadValueInjectionRetHardeningPass();
169169
FunctionPass *createX86SpeculativeLoadHardeningPass();
170170
FunctionPass *createX86SpeculativeExecutionSideEffectSuppression();
171171
FunctionPass *createX86ArgumentStackSlotPass();
172-
FunctionPass *createX86SuppressEGPRAndNDDForRelocPass();
172+
FunctionPass *createX86SuppressAPXForRelocationPass();
173173

174174
void initializeCompressEVEXPassPass(PassRegistry &);
175175
void initializeFPSPass(PassRegistry &);
@@ -205,6 +205,7 @@ void initializeX86ReturnThunksPass(PassRegistry &);
205205
void initializeX86SpeculativeExecutionSideEffectSuppressionPass(PassRegistry &);
206206
void initializeX86SpeculativeLoadHardeningPassPass(PassRegistry &);
207207
void initializeX86TileConfigPass(PassRegistry &);
208+
void initializeX86SuppressAPXForRelocationPassPass(PassRegistry &);
208209

209210
namespace X86AS {
210211
enum : unsigned {

llvm/lib/Target/X86/X86SuppressEGPRAndNDDForReloc.cpp renamed to llvm/lib/Target/X86/X86SuppressAPXForReloc.cpp

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==- X86SuppressEGPRAndNDDForReloc.cpp - Suppress EGPR/NDD for relocations -=//
1+
//===- X86SuppressAPXForReloc.cpp - Suppress APX features for relocations -===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,12 +7,12 @@
77
//===----------------------------------------------------------------------===//
88
/// \file
99
///
10-
/// This pass is added to suppress EGPR and NDD for relocations. It's used
10+
/// This pass is added to suppress APX features for relocations. It's used
1111
/// together with disabling emitting APX relocation types for backward
1212
/// compatibility with old version of linker (like before LD 2.43). It can avoid
1313
/// the instructions updated incorrectly by old version of linker if the
14-
/// instructions are with APX EGPR/NDD features + the relocations other than APX
15-
/// ones (like GOTTPOFF).
14+
/// instructions are with APX EGPR/NDD/NF features + the relocations other than
15+
/// APX ones (like GOTTPOFF).
1616
///
1717
//===----------------------------------------------------------------------===//
1818

@@ -23,44 +23,52 @@
2323
#include "X86Subtarget.h"
2424

2525
#include "llvm/CodeGen/MachineFunctionPass.h"
26+
#include "llvm/CodeGen/MachineOperand.h"
2627
#include "llvm/CodeGen/MachineRegisterInfo.h"
28+
#include "llvm/CodeGen/Passes.h"
29+
#include "llvm/InitializePasses.h"
2730
#include "llvm/Target/TargetMachine.h"
2831

2932
using namespace llvm;
3033

31-
#define DEBUG_TYPE "x86-suppress-egpr-and-ndd-for-relocation"
34+
#define DEBUG_TYPE "x86-suppress-apx-for-relocation"
3235

33-
static cl::opt<bool> X86SuppressEGPRAndNDDForReloc(
36+
static cl::opt<bool> X86SuppressAPXForReloc(
3437
DEBUG_TYPE,
35-
cl::desc("Suppress EGPR and NDD for instructions with relocations on "
36-
"x86-64 ELF"),
38+
cl::desc("Suppress APX features (EGPR, NDD and NF) for instructions with "
39+
"relocations on x86-64 ELF"),
3740
cl::init(true));
3841

3942
namespace {
40-
class X86SuppressEGPRAndNDDForRelocPass : public MachineFunctionPass {
43+
class X86SuppressAPXForRelocationPass : public MachineFunctionPass {
4144
public:
42-
X86SuppressEGPRAndNDDForRelocPass() : MachineFunctionPass(ID) {}
45+
X86SuppressAPXForRelocationPass() : MachineFunctionPass(ID) {}
4346

4447
StringRef getPassName() const override {
45-
return "X86 Suppress EGPR and NDD for relocation";
48+
return "X86 Suppress APX features for relocation";
4649
}
4750

4851
bool runOnMachineFunction(MachineFunction &MF) override;
4952

50-
private:
5153
static char ID;
5254
};
5355
} // namespace
5456

55-
char X86SuppressEGPRAndNDDForRelocPass::ID = 0;
57+
char X86SuppressAPXForRelocationPass::ID = 0;
5658

57-
FunctionPass *llvm::createX86SuppressEGPRAndNDDForRelocPass() {
58-
return new X86SuppressEGPRAndNDDForRelocPass();
59+
INITIALIZE_PASS_BEGIN(X86SuppressAPXForRelocationPass, DEBUG_TYPE,
60+
"X86 Suppress APX features for relocation", false, false)
61+
INITIALIZE_PASS_END(X86SuppressAPXForRelocationPass, DEBUG_TYPE,
62+
"X86 Suppress APX features for relocation", false, false)
63+
64+
FunctionPass *llvm::createX86SuppressAPXForRelocationPass() {
65+
return new X86SuppressAPXForRelocationPass();
5966
}
6067

61-
static void suppressEGPRRegClass(MachineFunction &MF, MachineInstr &MI) {
68+
static void suppressEGPRRegClass(MachineFunction &MF, MachineInstr &MI,
69+
unsigned int OpNum) {
6270
MachineRegisterInfo *MRI = &MF.getRegInfo();
63-
auto Reg = MI.getOperand(0).getReg();
71+
auto Reg = MI.getOperand(OpNum).getReg();
6472
if (!Reg.isVirtual()) {
6573
assert(!X86II::isApxExtendedReg(Reg) && "APX EGPR is used unexpectedly.");
6674
return;
@@ -71,10 +79,10 @@ static void suppressEGPRRegClass(MachineFunction &MF, MachineInstr &MI) {
7179
MRI->setRegClass(Reg, NewRC);
7280
}
7381

74-
bool X86SuppressEGPRAndNDDForRelocPass::runOnMachineFunction(
82+
bool X86SuppressAPXForRelocationPass::runOnMachineFunction(
7583
MachineFunction &MF) {
7684
if (MF.getTarget().Options.MCOptions.X86APXRelaxRelocations ||
77-
!X86SuppressEGPRAndNDDForReloc)
85+
!X86SuppressAPXForReloc)
7886
return false;
7987
const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
8088
if (!ST.hasEGPR() && !ST.hasNDD() && !ST.hasNF())
@@ -113,28 +121,48 @@ bool X86SuppressEGPRAndNDDForRelocPass::runOnMachineFunction(
113121
case X86::XOR64rm: {
114122
for (auto &MO : MI.operands()) {
115123
if (MO.getTargetFlags() == X86II::MO_GOTTPOFF ||
116-
MO.getTargetFlags() == X86II::MO_GOTPCREL)
117-
suppressEGPRRegClass(MF, MI);
124+
MO.getTargetFlags() == X86II::MO_GOTPCREL) {
125+
suppressEGPRRegClass(MF, MI, 0);
126+
break;
127+
}
118128
}
119129
break;
120130
}
121131
case X86::MOV64rm: {
122-
if (MI.getOperand(4).getTargetFlags() == X86II::MO_GOTTPOFF)
123-
suppressEGPRRegClass(MF, MI);
132+
for (auto &MO : MI.operands()) {
133+
if (MO.getTargetFlags() == X86II::MO_GOTTPOFF) {
134+
suppressEGPRRegClass(MF, MI, 0);
135+
break;
136+
}
137+
}
124138
break;
125139
}
126140
case X86::ADD64rm_NF:
127141
case X86::ADD64rm_ND:
128-
case X86::ADD64mr_ND:
129-
case X86::ADD64mr_NF_ND:
130142
case X86::ADD64rm_NF_ND: {
131-
// TODO: implement this if there is a case of NDD/NF instructions with
132-
// GOTTPOFF relocation (update the instructions to ADD64rm/ADD64mr and
133-
// suppress EGPR)
134-
for (auto &MO : MI.operands())
143+
for (auto &MO : MI.operands()) {
144+
if (MO.getTargetFlags() == X86II::MO_GOTTPOFF) {
145+
suppressEGPRRegClass(MF, MI, 0);
146+
const MCInstrDesc &NewDesc = ST.getInstrInfo()->get(X86::ADD64rm);
147+
MI.setDesc(NewDesc);
148+
if (Opcode == X86::ADD64rm_ND || Opcode == X86::ADD64rm_NF_ND) {
149+
MI.tieOperands(0, 1);
150+
MI.getOperand(1).setIsKill(false);
151+
suppressEGPRRegClass(MF, MI, 1);
152+
}
153+
break;
154+
}
155+
}
156+
break;
157+
}
158+
case X86::ADD64mr_ND:
159+
case X86::ADD64mr_NF_ND: {
160+
for ([[maybe_unused]] auto &MO : MI.operands()) {
135161
assert((MO.getTargetFlags() != X86II::MO_GOTTPOFF) &&
136-
"Suppressing NDD/NF instructions with relocation is "
162+
"Suppressing this instruction with relocation is "
137163
"unimplemented!");
164+
break;
165+
}
138166
break;
139167
}
140168
}

llvm/lib/Target/X86/X86TargetMachine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
105105
initializeX86FixupInstTuningPassPass(PR);
106106
initializeX86FixupVectorConstantsPassPass(PR);
107107
initializeX86DynAllocaExpanderPass(PR);
108+
initializeX86SuppressAPXForRelocationPassPass(PR);
108109
}
109110

110111
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
@@ -568,7 +569,7 @@ void X86PassConfig::addPreRegAlloc() {
568569
else
569570
addPass(createX86FastPreTileConfigPass());
570571

571-
addPass(createX86SuppressEGPRAndNDDForRelocPass());
572+
addPass(createX86SuppressAPXForRelocationPass());
572573
}
573574

574575
void X86PassConfig::addMachineSSAOptimization() {

llvm/test/CodeGen/X86/O0-pipeline.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
; CHECK-NEXT: X86 EFLAGS copy lowering
4646
; CHECK-NEXT: X86 DynAlloca Expander
4747
; CHECK-NEXT: Fast Tile Register Preconfigure
48-
; CHECK-NEXT: X86 Suppress EGPR and NDD for relocation
48+
; CHECK-NEXT: X86 Suppress APX features for relocation
4949
; CHECK-NEXT: Eliminate PHI nodes for register allocation
5050
; CHECK-NEXT: Two-Address instruction pass
5151
; CHECK-NEXT: Fast Register Allocator

llvm/test/CodeGen/X86/apx/tls-desc.ll renamed to llvm/test/CodeGen/X86/apx/tls.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
; RUN: ld.lld %t.o %t1.o -o %t.so
1919
; RUN: llvm-objdump --no-print-imm-hex -dr %t.so | FileCheck %s --check-prefix=GOTTPOFF_LD_NOAPXRELAX
2020

21-
; RUN: llc -mattr=+egpr %s -mtriple=x86_64 -filetype=obj -o %t.o -x86-suppress-egpr-and-ndd-for-relocation=false
21+
; RUN: llc -mattr=+egpr %s -mtriple=x86_64 -filetype=obj -o %t.o -x86-suppress-apx-for-relocation=false
2222
; RUN: llvm-objdump --no-print-imm-hex -dr %t.o | FileCheck %s --check-prefix=GOTTPOFF_NOAPXRELAX_APXINSTR
2323
; RUN: echo '.tbss; .globl b,c,d,e,f,g,h,i,j; b: .zero 4;c: .zero 4;d: .zero 4;e: .zero 4;f: .zero 4;g: .zero 4;h: .zero 4;i: .zero 4;j: .zero 4' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
2424
; RUN: ld.lld %t.o %t1.o -o %t.so

llvm/test/CodeGen/X86/opt-pipeline.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
; CHECK-NEXT: MachineDominator Tree Construction
134134
; CHECK-NEXT: Machine Natural Loop Construction
135135
; CHECK-NEXT: Tile Register Pre-configure
136-
; CHECK-NEXT: X86 Suppress EGPR and NDD for relocation
136+
; CHECK-NEXT: X86 Suppress APX features for relocation
137137
; CHECK-NEXT: Detect Dead Lanes
138138
; CHECK-NEXT: Init Undef Pass
139139
; CHECK-NEXT: Process Implicit Definitions

0 commit comments

Comments
 (0)