From 9ad0f02749f1a6566693a8d5dc33775b31cddbd5 Mon Sep 17 00:00:00 2001 From: Sid Manning Date: Fri, 7 Sep 2018 13:36:21 +0000 Subject: [PATCH] Add support for getRegisterByName. Support required to build the Hexagon Linux kernel. Differential Revision: https://reviews.llvm.org/D51363 llvm-svn: 341658 --- llvm/lib/Target/Hexagon/HexagonISelLowering.cpp | 13 +++++++++++++ llvm/lib/Target/Hexagon/HexagonISelLowering.h | 3 +++ llvm/test/CodeGen/Hexagon/namedreg.ll | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 llvm/test/CodeGen/Hexagon/namedreg.ll diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp index 7cab0c5..b74be76 100644 --- a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/CodeGen/CallingConvLower.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" @@ -240,6 +241,18 @@ bool HexagonTargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const { return true; } +unsigned HexagonTargetLowering::getRegisterByName(const char* RegName, EVT VT, + SelectionDAG &DAG) const { + // Just support r19, the linux kernel uses it. + unsigned Reg = StringSwitch(RegName) + .Case("r19", Hexagon::R19) + .Default(0); + if (Reg) + return Reg; + + report_fatal_error("Invalid register name global variable"); +} + /// LowerCallResult - Lower the result values of an ISD::CALL into the /// appropriate copies out of appropriate physical registers. This assumes that /// Chain/Glue are the input chain/glue to use, and that TheCall is the call diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.h b/llvm/lib/Target/Hexagon/HexagonISelLowering.h index 376d68c..d6d6ec6 100644 --- a/llvm/lib/Target/Hexagon/HexagonISelLowering.h +++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.h @@ -223,6 +223,9 @@ namespace HexagonISD { bool mayBeEmittedAsTailCall(const CallInst *CI) const override; + unsigned getRegisterByName(const char* RegName, EVT VT, + SelectionDAG &DAG) const override; + /// If a physical register, this returns the register that receives the /// exception address on entry to an EH pad. unsigned diff --git a/llvm/test/CodeGen/Hexagon/namedreg.ll b/llvm/test/CodeGen/Hexagon/namedreg.ll new file mode 100644 index 0000000..72ca508 --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/namedreg.ll @@ -0,0 +1,13 @@ +; RUN: llc -mattr=+reserved-r19 -march=hexagon < %s | FileCheck %s +define dso_local i32 @r19f() #0 { +entry: + %0 = call i32 @llvm.read_register.i32(metadata !0) + ret i32 %0 +} + +declare i32 @llvm.read_register.i32(metadata) #1 + +!llvm.named.register.r19 = !{!0} + +!0 = !{!"r19"} +; CHECK: r0 = r19 -- 2.7.4