Skip to content

Commit f94c514

Browse files
Changed the patch to use CodeGenOpts instead of target features.
I simplified the clang test significantly. I also completely removed the llc test. Since the code gen opt is now internal there is no good way that I know of to test it using llc.
1 parent ea4d54e commit f94c514

File tree

17 files changed

+50
-155
lines changed

17 files changed

+50
-155
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(UseFullRegisterNames, 1, 0) ///< Print full register names in assembly -mregnames
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,10 +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-
def mregnames : Flag<["-"], "mregnames">, Group<m_ppc_Features_Group>,
4793-
Visibility<[ClangOption]>;
4794-
def mno_regnames : Flag<["-"], "mno-regnames">, Group<m_ppc_Features_Group>,
4795-
Visibility<[ClangOption]>;
4792+
4793+
defm regnames : BoolOption<"m", "regnames",
4794+
CodeGenOpts<"UseFullRegisterNames">, 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>;
47964798
} // let Flags = [TargetSpecific]
47974799
def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
47984800
Group<m_ppc_Features_Group>,

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
8989
IsISA3_1 = true;
9090
} else if (Feature == "+quadword-atomics") {
9191
HasQuadwordAtomics = true;
92-
} else if (Feature == "+regnames") {
93-
FullRegisterNames = true;
9492
}
9593
// TODO: Finish this list and add an assert that we've handled them
9694
// all.
@@ -553,9 +551,6 @@ bool PPCTargetInfo::initFeatureMap(
553551
// off by default.
554552
Features["aix-small-local-exec-tls"] = false;
555553

556-
// By default full register names are not used in assembly.
557-
Features["regnames"] = false;
558-
559554
Features["spe"] = llvm::StringSwitch<bool>(CPU)
560555
.Case("8548", true)
561556
.Case("e500", true)
@@ -705,7 +700,6 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
705700
.Case("isa-v30-instructions", IsISA3_0)
706701
.Case("isa-v31-instructions", IsISA3_1)
707702
.Case("quadword-atomics", HasQuadwordAtomics)
708-
.Case("regnames", FullRegisterNames)
709703
.Default(false);
710704
}
711705

clang/lib/Basic/Targets/PPC.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
8080
bool IsISA3_0 = false;
8181
bool IsISA3_1 = false;
8282
bool HasQuadwordAtomics = false;
83-
bool FullRegisterNames = false;
8483

8584
protected:
8685
std::string ABI;

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ 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.UseFullRegisterNames = CodeGenOpts.UseFullRegisterNames;
491492
Options.MisExpect = CodeGenOpts.MisExpect;
492493

493494
return true;

clang/lib/Driver/ToolChains/Clang.cpp

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

5017+
if (const Arg *A = Args.getLastArg(options::OPT_mregnames,
5018+
options::OPT_mno_regnames)) {
5019+
if (A->getOption().matches(options::OPT_mregnames))
5020+
Args.AddLastArg(CmdArgs, options::OPT_mregnames);
5021+
}
5022+
50175023
if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
50185024
Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
50195025

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,9 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
17801780
Opts.setDebugInfo(llvm::codegenoptions::LimitedDebugInfo);
17811781
}
17821782

1783+
if (const Arg *A = Args.getLastArg(OPT_mregnames))
1784+
Opts.UseFullRegisterNames = true;
1785+
17831786
for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) {
17841787
auto Split = StringRef(Arg).split('=');
17851788
Opts.DebugPrefixMap.emplace_back(Split.first, Split.second);
Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,20 @@
11
// REQUIRES: powerpc-registered-target
2-
// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
2+
// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
33
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
4-
// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
4+
// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
55
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
6-
// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
6+
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -mregnames \
77
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
8-
// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
8+
// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames \
99
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
10-
// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
10+
// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames \
1111
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
12-
// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
12+
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -mno-regnames \
1313
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
1414

15-
// Also check the assembly to make sure that the full names are used.
16-
// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
17-
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
18-
// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
19-
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
20-
// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -mregnames \
21-
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
22-
// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mno-regnames \
23-
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
24-
// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mno-regnames \
25-
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
26-
// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -mno-regnames \
27-
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
28-
29-
30-
31-
// FULLNAMES-LABEL: @IntNames
32-
// FULLNAMES-SAME: #0
33-
// NOFULLNAMES-LABEL: @IntNames
34-
// NOFULLNAMES-SAME: #0
35-
// ASMFULLNAMES-LABEL: IntNames:
36-
// ASMFULLNAMES: add r3, r4, r3
37-
// ASMFULLNAMES: blr
38-
// ASMNOFULLNAMES-LABEL: IntNames:
39-
// ASMNOFULLNAMES: add 3, 4, 3
40-
// ASMNOFULLNAMES: blr
41-
int IntNames(int a, int b) {
42-
return a + b;
43-
}
44-
45-
// FULLNAMES-LABEL: @FPNames
46-
// FULLNAMES-SAME: #0
47-
// NOFULLNAMES-LABEL: @FPNames
48-
// NOFULLNAMES-SAME: #0
49-
// ASMFULLNAMES-LABEL: FPNames:
50-
// ASMFULLNAMES: xsadddp f1, f1, f2
51-
// ASMFULLNAMES: blr
52-
// ASMNOFULLNAMES-LABEL: FPNames:
53-
// ASMNOFULLNAMES: xsadddp 1, 1, 2
54-
// ASMNOFULLNAMES: blr
55-
double FPNames(double a, double b) {
56-
return a + b;
57-
}
58-
59-
// FULLNAMES-LABEL: @VecNames
60-
// FULLNAMES-SAME: #0
61-
// NOFULLNAMES-LABEL: @VecNames
62-
// NOFULLNAMES-SAME: #0
63-
// ASMFULLNAMES-LABEL: VecNames:
64-
// ASMFULLNAMES: xvaddsp vs34, vs34, vs35
65-
// ASMFULLNAMES: blr
66-
// ASMNOFULLNAMES-LABEL: VecNames:
67-
// ASMNOFULLNAMES: xvaddsp 34, 34, 35
68-
// ASMNOFULLNAMES: blr
69-
vector float VecNames(vector float a, vector float b) {
70-
return a + b;
71-
}
72-
73-
// FULLNAMES: attributes #0 = {
74-
// FULLNAMES-SAME: +regnames
75-
// NOFULLNAMES: attributes #0 = {
76-
// NOFULLNAMES-SAME: -regnames
15+
// FULLNAMES: clang
16+
// FULLNAMES-SAME: -mregnames
17+
// NOFULLNAMES: clang
18+
// NOFULLNAMES-SAME-NOT: -mregnames
7719

7820

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 UseFullRegisterNames = 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 UseFullRegisterNames; }
717+
void setFullRegisterNames(bool V) { UseFullRegisterNames = 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 UseFullRegisterNames : 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.UseFullRegisterNames);
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+
UseFullRegisterNames = 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), UseFullRegisterNames(false) {}
2323

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

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

Lines changed: 7 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"
@@ -614,8 +615,8 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
614615
/// getVerboseConditionalRegName - This method expands the condition register
615616
/// when requested explicitly or targetting Darwin.
616617
const char *PPCInstPrinter::getVerboseConditionRegName(
617-
unsigned RegNum, unsigned RegEncoding, const MCSubtargetInfo &STI) const {
618-
if (!FullRegNames && !STI.hasFeature(PPC::FeatureFullRegisterNames))
618+
unsigned RegNum, unsigned RegEncoding) const {
619+
if (!FullRegNames && !MAI.useFullRegisterNames())
619620
return nullptr;
620621
if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
621622
return nullptr;
@@ -634,9 +635,9 @@ const char *PPCInstPrinter::getVerboseConditionRegName(
634635

635636
// showRegistersWithPrefix - This method determines whether registers
636637
// should be number-only or include the prefix.
637-
bool PPCInstPrinter::showRegistersWithPrefix(const MCSubtargetInfo &STI) const {
638+
bool PPCInstPrinter::showRegistersWithPrefix() const {
638639
return FullRegNamesWithPercent || FullRegNames ||
639-
STI.hasFeature(PPC::FeatureFullRegisterNames);
640+
MAI.useFullRegisterNames();
640641
}
641642

642643
void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
@@ -648,12 +649,12 @@ void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
648649
Reg = PPC::getRegNumForOperand(MII.get(MI->getOpcode()), Reg, OpNo);
649650

650651
const char *RegName;
651-
RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg), STI);
652+
RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg));
652653
if (RegName == nullptr)
653654
RegName = getRegisterName(Reg);
654655
if (showRegistersWithPercentPrefix(RegName))
655656
O << "%";
656-
if (!showRegistersWithPrefix(STI))
657+
if (!showRegistersWithPrefix())
657658
RegName = PPC::stripRegisterPrefix(RegName);
658659

659660
O << RegName;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class PPCInstPrinter : public MCInstPrinter {
2222
Triple TT;
2323
private:
2424
bool showRegistersWithPercentPrefix(const char *RegName) const;
25-
bool showRegistersWithPrefix(const MCSubtargetInfo &STI) const;
26-
const char *getVerboseConditionRegName(unsigned RegNum, unsigned RegEncoding,
27-
const MCSubtargetInfo &STI) const;
25+
bool showRegistersWithPrefix() const;
26+
const char *getVerboseConditionRegName(unsigned RegNum,
27+
unsigned RegEncoding) const;
2828

2929
public:
3030
PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,

llvm/lib/Target/PowerPC/PPC.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,6 @@ def FeaturePredictableSelectIsExpensive :
338338
def FeatureFastMFLR : SubtargetFeature<"fast-MFLR", "HasFastMFLR", "true",
339339
"MFLR is a fast instruction">;
340340

341-
def FeatureFullRegisterNames :
342-
SubtargetFeature<"regnames", "FullRegisterNames", "true",
343-
"Use full register names in assembly.">;
344-
345341
// Since new processors generally contain a superset of features of those that
346342
// came before them, the idea is to make implementations of new processors
347343
// less error prone and easier to read.

llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)