Skip to content

Commit 423ad04

Browse files
[PowerPC] Add an alias for -mregnames so that full register names used in assembly. (#70255)
This option already exists on GCC and so it is being added to LLVM so that we use the same option as them.
1 parent c16b94a commit 423ad04

File tree

11 files changed

+42
-7
lines changed

11 files changed

+42
-7
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ CODEGENOPT(HIPCorrectlyRoundedDivSqrt, 1, 1) ///< -fno-hip-fp32-correctly-rounde
197197
CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is enabled.
198198
CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
199199
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
200+
CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in assembly
200201

201202
/// When false, this attempts to generate code as if the result of an
202203
/// overflowing conversion matches the overflowing behavior of a target's native

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,6 +4789,12 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
47894789
Group<m_ppc_Features_Group>;
47904790
def mprivileged : Flag<["-"], "mprivileged">,
47914791
Group<m_ppc_Features_Group>;
4792+
4793+
defm regnames : BoolOption<"m", "regnames",
4794+
CodeGenOpts<"PPCUseFullRegisterNames">, DefaultFalse,
4795+
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use full register names when writing assembly output">,
4796+
NegFlag<SetFalse, [], [ClangOption], "Use only register numbers when writing assembly output">>,
4797+
Group<m_Group>;
47924798
} // let Flags = [TargetSpecific]
47934799
def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
47944800
Group<m_ppc_Features_Group>,

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
488488
Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
489489
Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
490490
Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile;
491+
Options.MCOptions.PPCUseFullRegisterNames =
492+
CodeGenOpts.PPCUseFullRegisterNames;
491493
Options.MisExpect = CodeGenOpts.MisExpect;
492494

493495
return true;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5014,6 +5014,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50145014
Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
50155015
}
50165016

5017+
if (Triple.isPPC())
5018+
Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
5019+
options::OPT_mno_regnames);
5020+
50175021
if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
50185022
Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
50195023

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// REQUIRES: powerpc-registered-target
2+
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -mregnames \
3+
// RUN: %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
4+
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -mno-regnames \
5+
// RUN: %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
6+
7+
// FULLNAMES: -mregnames
8+
// NOFULLNAMES-NOT: -mregnames

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ class MCAsmInfo {
240240
/// True if the target supports LEB128 directives.
241241
bool HasLEB128Directives = true;
242242

243+
/// True if full register names are printed.
244+
bool PPCUseFullRegisterNames = false;
245+
243246
//===--- Data Emission Directives -------------------------------------===//
244247

245248
/// This should be set to the directive used to get some number of zero (and
@@ -710,6 +713,9 @@ class MCAsmInfo {
710713

711714
bool hasLEB128Directives() const { return HasLEB128Directives; }
712715

716+
bool useFullRegisterNames() const { return PPCUseFullRegisterNames; }
717+
void setFullRegisterNames(bool V) { PPCUseFullRegisterNames = V; }
718+
713719
const char *getZeroDirective() const { return ZeroDirective; }
714720
bool doesZeroDirectiveSupportNonZeroValue() const {
715721
return ZeroDirectiveSupportsNonZeroValue;

llvm/include/llvm/MC/MCTargetOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class MCTargetOptions {
8989
// functions on Darwins.
9090
bool EmitCompactUnwindNonCanonical : 1;
9191

92+
// Whether or not to use full register names on PowerPC.
93+
bool PPCUseFullRegisterNames : 1;
94+
9295
MCTargetOptions();
9396

9497
/// getABIName - If this returns a non-empty string this represents the

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ void LLVMTargetMachine::initAsmInfo() {
8181

8282
TmpAsmInfo->setRelaxELFRelocations(Options.RelaxELFRelocations);
8383

84+
TmpAsmInfo->setFullRegisterNames(Options.MCOptions.PPCUseFullRegisterNames);
85+
8486
if (Options.ExceptionModel != ExceptionHandling::None)
8587
TmpAsmInfo->setExceptionsType(Options.ExceptionModel);
8688

llvm/lib/MC/MCAsmInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ MCAsmInfo::MCAsmInfo() {
6767
UseIntegratedAssembler = true;
6868
ParseInlineAsmUsingAsmParser = false;
6969
PreserveAsmComments = true;
70+
PPCUseFullRegisterNames = false;
7071
}
7172

7273
MCAsmInfo::~MCAsmInfo() = default;

llvm/lib/MC/MCTargetOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ MCTargetOptions::MCTargetOptions()
1919
PreserveAsmComments(true), Dwarf64(false),
2020
EmitDwarfUnwind(EmitDwarfUnwindType::Default),
2121
MCUseDwarfDirectory(DefaultDwarfDirectory),
22-
EmitCompactUnwindNonCanonical(false) {}
22+
EmitCompactUnwindNonCanonical(false), PPCUseFullRegisterNames(false) {}
2323

2424
StringRef MCTargetOptions::getABIName() const {
2525
return ABIName;

llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "MCTargetDesc/PPCInstPrinter.h"
1414
#include "MCTargetDesc/PPCMCTargetDesc.h"
1515
#include "MCTargetDesc/PPCPredicates.h"
16+
#include "llvm/MC/MCAsmInfo.h"
1617
#include "llvm/MC/MCExpr.h"
1718
#include "llvm/MC/MCInst.h"
1819
#include "llvm/MC/MCInstrInfo.h"
@@ -596,7 +597,8 @@ void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
596597
/// showRegistersWithPercentPrefix - Check if this register name should be
597598
/// printed with a percentage symbol as prefix.
598599
bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
599-
if (!FullRegNamesWithPercent || TT.getOS() == Triple::AIX)
600+
if ((!FullRegNamesWithPercent && !MAI.useFullRegisterNames()) ||
601+
TT.getOS() == Triple::AIX)
600602
return false;
601603

602604
switch (RegName[0]) {
@@ -613,10 +615,10 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
613615

614616
/// getVerboseConditionalRegName - This method expands the condition register
615617
/// when requested explicitly or targetting Darwin.
616-
const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
617-
unsigned RegEncoding)
618-
const {
619-
if (!FullRegNames)
618+
const char *
619+
PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
620+
unsigned RegEncoding) const {
621+
if (!FullRegNames && !MAI.useFullRegisterNames())
620622
return nullptr;
621623
if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
622624
return nullptr;
@@ -636,7 +638,7 @@ const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
636638
// showRegistersWithPrefix - This method determines whether registers
637639
// should be number-only or include the prefix.
638640
bool PPCInstPrinter::showRegistersWithPrefix() const {
639-
return FullRegNamesWithPercent || FullRegNames;
641+
return FullRegNamesWithPercent || FullRegNames || MAI.useFullRegisterNames();
640642
}
641643

642644
void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,

0 commit comments

Comments
 (0)