Skip to content

Commit

Permalink
[PowerPC] Add an alias for -mregnames so that full register names use…
Browse files Browse the repository at this point in the history
…d 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.
  • Loading branch information
stefanp-ibm committed Nov 6, 2023
1 parent c16b94a commit 423ad04
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ CODEGENOPT(HIPCorrectlyRoundedDivSqrt, 1, 1) ///< -fno-hip-fp32-correctly-rounde
CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is enabled.
CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in assembly

/// When false, this attempts to generate code as if the result of an
/// overflowing conversion matches the overflowing behavior of a target's native
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4789,6 +4789,12 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
Group<m_ppc_Features_Group>;
def mprivileged : Flag<["-"], "mprivileged">,
Group<m_ppc_Features_Group>;

defm regnames : BoolOption<"m", "regnames",
CodeGenOpts<"PPCUseFullRegisterNames">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use full register names when writing assembly output">,
NegFlag<SetFalse, [], [ClangOption], "Use only register numbers when writing assembly output">>,
Group<m_Group>;
} // let Flags = [TargetSpecific]
def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
Group<m_ppc_Features_Group>,
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile;
Options.MCOptions.PPCUseFullRegisterNames =
CodeGenOpts.PPCUseFullRegisterNames;
Options.MisExpect = CodeGenOpts.MisExpect;

return true;
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5014,6 +5014,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
}

if (Triple.isPPC())
Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
options::OPT_mno_regnames);

if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);

Expand Down
8 changes: 8 additions & 0 deletions clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// REQUIRES: powerpc-registered-target
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -mregnames \
// RUN: %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -mno-regnames \
// RUN: %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES

// FULLNAMES: -mregnames
// NOFULLNAMES-NOT: -mregnames
6 changes: 6 additions & 0 deletions llvm/include/llvm/MC/MCAsmInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ class MCAsmInfo {
/// True if the target supports LEB128 directives.
bool HasLEB128Directives = true;

/// True if full register names are printed.
bool PPCUseFullRegisterNames = false;

//===--- Data Emission Directives -------------------------------------===//

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

bool hasLEB128Directives() const { return HasLEB128Directives; }

bool useFullRegisterNames() const { return PPCUseFullRegisterNames; }
void setFullRegisterNames(bool V) { PPCUseFullRegisterNames = V; }

const char *getZeroDirective() const { return ZeroDirective; }
bool doesZeroDirectiveSupportNonZeroValue() const {
return ZeroDirectiveSupportsNonZeroValue;
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/MC/MCTargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class MCTargetOptions {
// functions on Darwins.
bool EmitCompactUnwindNonCanonical : 1;

// Whether or not to use full register names on PowerPC.
bool PPCUseFullRegisterNames : 1;

MCTargetOptions();

/// getABIName - If this returns a non-empty string this represents the
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/LLVMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void LLVMTargetMachine::initAsmInfo() {

TmpAsmInfo->setRelaxELFRelocations(Options.RelaxELFRelocations);

TmpAsmInfo->setFullRegisterNames(Options.MCOptions.PPCUseFullRegisterNames);

if (Options.ExceptionModel != ExceptionHandling::None)
TmpAsmInfo->setExceptionsType(Options.ExceptionModel);

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/MC/MCAsmInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MCAsmInfo::MCAsmInfo() {
UseIntegratedAssembler = true;
ParseInlineAsmUsingAsmParser = false;
PreserveAsmComments = true;
PPCUseFullRegisterNames = false;
}

MCAsmInfo::~MCAsmInfo() = default;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCTargetOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MCTargetOptions::MCTargetOptions()
PreserveAsmComments(true), Dwarf64(false),
EmitDwarfUnwind(EmitDwarfUnwindType::Default),
MCUseDwarfDirectory(DefaultDwarfDirectory),
EmitCompactUnwindNonCanonical(false) {}
EmitCompactUnwindNonCanonical(false), PPCUseFullRegisterNames(false) {}

StringRef MCTargetOptions::getABIName() const {
return ABIName;
Expand Down
14 changes: 8 additions & 6 deletions llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MCTargetDesc/PPCInstPrinter.h"
#include "MCTargetDesc/PPCMCTargetDesc.h"
#include "MCTargetDesc/PPCPredicates.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrInfo.h"
Expand Down Expand Up @@ -596,7 +597,8 @@ void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
/// showRegistersWithPercentPrefix - Check if this register name should be
/// printed with a percentage symbol as prefix.
bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
if (!FullRegNamesWithPercent || TT.getOS() == Triple::AIX)
if ((!FullRegNamesWithPercent && !MAI.useFullRegisterNames()) ||
TT.getOS() == Triple::AIX)
return false;

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

/// getVerboseConditionalRegName - This method expands the condition register
/// when requested explicitly or targetting Darwin.
const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
unsigned RegEncoding)
const {
if (!FullRegNames)
const char *
PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
unsigned RegEncoding) const {
if (!FullRegNames && !MAI.useFullRegisterNames())
return nullptr;
if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
return nullptr;
Expand All @@ -636,7 +638,7 @@ const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
// showRegistersWithPrefix - This method determines whether registers
// should be number-only or include the prefix.
bool PPCInstPrinter::showRegistersWithPrefix() const {
return FullRegNamesWithPercent || FullRegNames;
return FullRegNamesWithPercent || FullRegNames || MAI.useFullRegisterNames();
}

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

0 comments on commit 423ad04

Please sign in to comment.