Skip to content

Commit e71fb23

Browse files
[PowerPC] Add an alias for -mregnames so that full register names used in assembly.
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 e71fb23

File tree

8 files changed

+167
-8
lines changed

8 files changed

+167
-8
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,6 +4789,10 @@ 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]>;
47924796
} // let Flags = [TargetSpecific]
47934797
def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
47944798
Group<m_ppc_Features_Group>,

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ 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;
9294
}
9395
// TODO: Finish this list and add an assert that we've handled them
9496
// all.
@@ -551,6 +553,9 @@ bool PPCTargetInfo::initFeatureMap(
551553
// off by default.
552554
Features["aix-small-local-exec-tls"] = false;
553555

556+
// By default full register names are not used in assembly.
557+
Features["regnames"] = false;
558+
554559
Features["spe"] = llvm::StringSwitch<bool>(CPU)
555560
.Case("8548", true)
556561
.Case("e500", true)
@@ -700,6 +705,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
700705
.Case("isa-v30-instructions", IsISA3_0)
701706
.Case("isa-v31-instructions", IsISA3_1)
702707
.Case("quadword-atomics", HasQuadwordAtomics)
708+
.Case("regnames", FullRegisterNames)
703709
.Default(false);
704710
}
705711

clang/lib/Basic/Targets/PPC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ 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;
8384

8485
protected:
8586
std::string ABI;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// REQUIRES: powerpc-registered-target
2+
// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
3+
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
4+
// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
5+
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
6+
// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
7+
// 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 \
9+
// 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 \
11+
// 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 \
13+
// RUN: -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
14+
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
77+
78+

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,11 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
614614
/// getVerboseConditionalRegName - This method expands the condition register
615615
/// when requested explicitly or targetting Darwin.
616616
const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
617-
unsigned RegEncoding)
617+
unsigned RegEncoding,
618+
const MCSubtargetInfo &STI)
618619
const {
619-
if (!FullRegNames)
620+
// __SP__
621+
if (!FullRegNames && !STI.hasFeature(PPC::FeatureFullRegisterNames))
620622
return nullptr;
621623
if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
622624
return nullptr;
@@ -635,8 +637,9 @@ const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
635637

636638
// showRegistersWithPrefix - This method determines whether registers
637639
// should be number-only or include the prefix.
638-
bool PPCInstPrinter::showRegistersWithPrefix() const {
639-
return FullRegNamesWithPercent || FullRegNames;
640+
bool PPCInstPrinter::showRegistersWithPrefix(const MCSubtargetInfo &STI) const {
641+
return FullRegNamesWithPercent || FullRegNames ||
642+
STI.hasFeature(PPC::FeatureFullRegisterNames);
640643
}
641644

642645
void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
@@ -648,12 +651,12 @@ void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
648651
Reg = PPC::getRegNumForOperand(MII.get(MI->getOpcode()), Reg, OpNo);
649652

650653
const char *RegName;
651-
RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg));
654+
RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg), STI);
652655
if (RegName == nullptr)
653656
RegName = getRegisterName(Reg);
654657
if (showRegistersWithPercentPrefix(RegName))
655658
O << "%";
656-
if (!showRegistersWithPrefix())
659+
if (!showRegistersWithPrefix(STI))
657660
RegName = PPC::stripRegisterPrefix(RegName);
658661

659662
O << RegName;

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

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

2930
public:
3031
PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,

llvm/lib/Target/PowerPC/PPC.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ 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+
341345
// Since new processors generally contain a superset of features of those that
342346
// came before them, the idea is to make implementations of new processors
343347
// less error prone and easier to read.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-linux-gnu < %s \
2+
; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
3+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu < %s \
4+
; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
5+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s \
6+
; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
7+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-linux-gnu < %s \
8+
; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
9+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu < %s \
10+
; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
11+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s \
12+
; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
13+
14+
15+
define dso_local signext i32 @IntNames(i32 noundef signext %a, i32 noundef signext %b) local_unnamed_addr #0 {
16+
; FULLNAMES-LABEL: IntNames:
17+
; FULLNAMES: # %bb.0: # %entry
18+
; FULLNAMES-NEXT: add r3, r4, r3
19+
; FULLNAMES-NEXT: extsw r3, r3
20+
; FULLNAMES-NEXT: blr
21+
;
22+
; NOFULLNAMES-LABEL: IntNames:
23+
; NOFULLNAMES: # %bb.0: # %entry
24+
; NOFULLNAMES-NEXT: add 3, 4, 3
25+
; NOFULLNAMES-NEXT: extsw 3, 3
26+
; NOFULLNAMES-NEXT: blr
27+
entry:
28+
%add = add nsw i32 %b, %a
29+
ret i32 %add
30+
}
31+
32+
define dso_local double @FPNames(double noundef %a, double noundef %b) local_unnamed_addr #0 {
33+
; FULLNAMES-LABEL: FPNames:
34+
; FULLNAMES: # %bb.0: # %entry
35+
; FULLNAMES-NEXT: xsadddp f1, f1, f2
36+
; FULLNAMES-NEXT: blr
37+
;
38+
; NOFULLNAMES-LABEL: FPNames:
39+
; NOFULLNAMES: # %bb.0: # %entry
40+
; NOFULLNAMES-NEXT: xsadddp 1, 1, 2
41+
; NOFULLNAMES-NEXT: blr
42+
entry:
43+
%add = fadd double %a, %b
44+
ret double %add
45+
}
46+
47+
define dso_local <4 x float> @VecNames(<4 x float> noundef %a, <4 x float> noundef %b) local_unnamed_addr #0 {
48+
; FULLNAMES-LABEL: VecNames:
49+
; FULLNAMES: # %bb.0: # %entry
50+
; FULLNAMES-NEXT: xvaddsp vs34, vs34, vs35
51+
; FULLNAMES-NEXT: blr
52+
;
53+
; NOFULLNAMES-LABEL: VecNames:
54+
; NOFULLNAMES: # %bb.0: # %entry
55+
; NOFULLNAMES-NEXT: xvaddsp 34, 34, 35
56+
; NOFULLNAMES-NEXT: blr
57+
entry:
58+
%add = fadd <4 x float> %a, %b
59+
ret <4 x float> %add
60+
}
61+
62+
attributes #0 = { nounwind willreturn "target-features"="+altivec" }

0 commit comments

Comments
 (0)