Skip to content

Commit ae38254

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 0764e55 commit ae38254

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
@@ -17367,25 +17367,29 @@ SDValue PPCTargetLowering::LowerFRAMEADDR(SDValue Op,
1736717367
return FrameAddr;
1736817368
}
1736917369

17370-
// FIXME? Maybe this could be a TableGen attribute on some registers and
17371-
// this table could be generated automatically from RegInfo.
17370+
#define GET_REGISTER_MATCHER
17371+
#include "PPCGenAsmMatcher.inc"
17372+
1737217373
Register PPCTargetLowering::getRegisterByName(const char* RegName, LLT VT,
1737317374
const MachineFunction &MF) const {
17374-
bool isPPC64 = Subtarget.isPPC64();
1737517375

17376-
bool is64Bit = isPPC64 && VT == LLT::scalar(64);
17377-
if (!is64Bit && VT != LLT::scalar(32))
17376+
bool Is64Bit = Subtarget.isPPC64() && VT == LLT::scalar(64);
17377+
if (!Is64Bit && VT != LLT::scalar(32))
1737817378
report_fatal_error("Invalid register global variable type");
1737917379

17380-
Register Reg = StringSwitch<Register>(RegName)
17381-
.Case("r1", is64Bit ? PPC::X1 : PPC::R1)
17382-
.Case("r2", isPPC64 ? Register() : PPC::R2)
17383-
.Case("r13", (is64Bit ? PPC::X13 : PPC::R13))
17384-
.Default(Register());
17380+
Register Reg = MatchRegisterName(RegName);
17381+
if (!Reg)
17382+
report_fatal_error(Twine("Invalid global name register \""
17383+
+ StringRef(RegName) + "\"."));
17384+
17385+
// Convert GPR to GP8R register for 64bit.
17386+
if (Is64Bit && StringRef(RegName).starts_with_insensitive("r"))
17387+
Reg = Reg.id() - PPC::R0 + PPC::X0;
1738517388

17386-
if (Reg)
17387-
return Reg;
17388-
report_fatal_error("Invalid register name global variable");
17389+
if (Subtarget.getRegisterInfo()->getReservedRegs(MF).test(Reg))
17390+
report_fatal_error(Twine("Trying to obtain non-reservable register \"" +
17391+
StringRef(RegName) + "\"."));
17392+
return Reg;
1738917393
}
1739017394

1739117395
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)