Skip to content

Commit ea43319

Browse files
committed
[PowerPC] Expand global named register support
Enable all valid registers for intrinsics that read from and write to global named registers.
1 parent f9d3e98 commit ea43319

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17317,25 +17317,29 @@ SDValue PPCTargetLowering::LowerFRAMEADDR(SDValue Op,
1731717317
return FrameAddr;
1731817318
}
1731917319

17320-
// FIXME? Maybe this could be a TableGen attribute on some registers and
17321-
// this table could be generated automatically from RegInfo.
17320+
#define GET_REGISTER_MATCHER
17321+
#include "PPCGenAsmMatcher.inc"
17322+
1732217323
Register PPCTargetLowering::getRegisterByName(const char* RegName, LLT VT,
1732317324
const MachineFunction &MF) const {
17324-
bool isPPC64 = Subtarget.isPPC64();
1732517325

17326-
bool is64Bit = isPPC64 && VT == LLT::scalar(64);
17327-
if (!is64Bit && VT != LLT::scalar(32))
17326+
bool Is64Bit = Subtarget.isPPC64() && VT == LLT::scalar(64);
17327+
if (!Is64Bit && VT != LLT::scalar(32))
1732817328
report_fatal_error("Invalid register global variable type");
1732917329

17330-
Register Reg = StringSwitch<Register>(RegName)
17331-
.Case("r1", is64Bit ? PPC::X1 : PPC::R1)
17332-
.Case("r2", isPPC64 ? Register() : PPC::R2)
17333-
.Case("r13", (is64Bit ? PPC::X13 : PPC::R13))
17334-
.Default(Register());
17330+
Register Reg = MatchRegisterName(RegName);
17331+
if (!Reg)
17332+
report_fatal_error(Twine("Invalid global name register \""
17333+
+ StringRef(RegName) + "\"."));
17334+
17335+
// Convert GPR to GP8R register for 64bit.
17336+
if (Is64Bit && StringRef(RegName).starts_with_insensitive("r"))
17337+
Reg = Reg.id() - PPC::R0 + PPC::X0;
1733517338

17336-
if (Reg)
17337-
return Reg;
17338-
report_fatal_error("Invalid register name global variable");
17339+
if (Subtarget.getRegisterInfo()->getReservedRegs(MF).test(Reg))
17340+
report_fatal_error(Twine("Trying to obtain non-reservable register \"" +
17341+
StringRef(RegName) + "\"."));
17342+
return Reg;
1733917343
}
1734017344

1734117345
bool PPCTargetLowering::isAccessedAsGotIndirect(SDValue GA) const {

llvm/test/CodeGen/PowerPC/named-reg-alloc-r0.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
; RUN: not --crash llc < %s -mtriple=powerpc-unknown-linux-gnu 2>&1 | FileCheck %s
2-
; RUN: not --crash llc < %s -mtriple=powerpc-unknown-linux-gnu 2>&1 | FileCheck %s
3-
; RUN: not --crash llc < %s -mtriple=powerpc64-unknown-linux-gnu 2>&1 | FileCheck %s
1+
; RUN: not --crash llc -O0 < %s -mtriple=powerpc-unknown-linux-gnu 2>&1 | FileCheck %s
2+
; RUN: not --crash llc -O0 < %s -mtriple=powerpc-unknown-linux-gnu 2>&1 | FileCheck %s
3+
; RUN: not --crash llc -O0 < %s -mtriple=powerpc64-unknown-linux-gnu 2>&1 | FileCheck %s
44

55
define i32 @get_reg() nounwind {
66
entry:
7-
; FIXME: Include an allocatable-specific error message
8-
; CHECK: Invalid register name global variable
7+
; CHECK: Trying to obtain non-reservable register "r0".
98
%reg = call i32 @llvm.read_register.i32(metadata !0)
109
ret i32 %reg
1110
}

llvm/test/CodeGen/PowerPC/named-reg-alloc-r2-64.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
define i64 @get_reg() nounwind {
55
entry:
6-
; FIXME: Include an allocatable-specific error message
7-
; CHECK: Invalid register name global variable
6+
; CHECK: Trying to obtain non-reservable register "r2".
87
%reg = call i64 @llvm.read_register.i64(metadata !0)
98
ret i64 %reg
109
}

llvm/test/CodeGen/PowerPC/named-reg-alloc-r2.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
define i32 @get_reg() nounwind {
55
entry:
6-
; FIXME: Include an allocatable-specific error message
7-
; CHECK-NOTPPC32: Invalid register name global variable
6+
; CHECK-NOTPPC32: Trying to obtain non-reservable register "r2".
87
%reg = call i32 @llvm.read_register.i32(metadata !0)
98
ret i32 %reg
109

0 commit comments

Comments
 (0)