
ShadowCallStack implementation uses s2 register on RISC-V, but that choice is problematic for reasons described in: https://lists.riscv.org/g/sig-toolchains/message/544, https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/370, and https://github.com/google/android-riscv64/issues/72 The concern over the register choice was also brought up in https://reviews.llvm.org/D84414. https://reviews.llvm.org/D84414#2228666 said: ``` "If the register choice is the only concern about this work, then I think we can probably land it as-is and fixup the register choice if we see major drawbacks later. Yes, it's an ABI issue, but on the other hand the shadow call stack is not a standard ABI anyway."" ``` Since we have now found a sufficient reason to fixup the register choice, we should go ahead and update the implementation. We propose using x3(gp) which is now the platform register in the RISC-V ABI. Reviewed By: asb, hiraditya, mcgrathr, craig.topper Differential Revision: https://reviews.llvm.org/D146463
90 lines
2.9 KiB
C++
90 lines
2.9 KiB
C++
//===-- RISCVTargetParser.cpp - Parser for target features ------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements a target parser to recognise hardware features
|
|
// for RISC-V CPUs.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/TargetParser/RISCVTargetParser.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
#include "llvm/TargetParser/Triple.h"
|
|
|
|
namespace llvm {
|
|
namespace RISCV {
|
|
|
|
struct CPUInfo {
|
|
StringLiteral Name;
|
|
CPUKind Kind;
|
|
StringLiteral DefaultMarch;
|
|
bool isInvalid() const { return DefaultMarch.empty(); }
|
|
bool is64Bit() const { return DefaultMarch.starts_with("rv64"); }
|
|
};
|
|
|
|
constexpr CPUInfo RISCVCPUInfo[] = {
|
|
#define PROC(ENUM, NAME, DEFAULT_MARCH) \
|
|
{NAME, CK_##ENUM, DEFAULT_MARCH},
|
|
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
|
|
};
|
|
|
|
bool checkCPUKind(CPUKind Kind, bool IsRV64) {
|
|
if (Kind == CK_INVALID)
|
|
return false;
|
|
return RISCVCPUInfo[static_cast<unsigned>(Kind)].is64Bit() == IsRV64;
|
|
}
|
|
|
|
bool checkTuneCPUKind(CPUKind Kind, bool IsRV64) {
|
|
if (Kind == CK_INVALID)
|
|
return false;
|
|
#define TUNE_PROC(ENUM, NAME) \
|
|
if (Kind == CK_##ENUM) \
|
|
return true;
|
|
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
|
|
return RISCVCPUInfo[static_cast<unsigned>(Kind)].is64Bit() == IsRV64;
|
|
}
|
|
|
|
CPUKind parseCPUKind(StringRef CPU) {
|
|
return llvm::StringSwitch<CPUKind>(CPU)
|
|
#define PROC(ENUM, NAME, DEFAULT_MARCH) .Case(NAME, CK_##ENUM)
|
|
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
|
|
.Default(CK_INVALID);
|
|
}
|
|
|
|
CPUKind parseTuneCPUKind(StringRef TuneCPU, bool IsRV64) {
|
|
return llvm::StringSwitch<CPUKind>(TuneCPU)
|
|
#define PROC(ENUM, NAME, DEFAULT_MARCH) .Case(NAME, CK_##ENUM)
|
|
#define TUNE_PROC(ENUM, NAME) .Case(NAME, CK_##ENUM)
|
|
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
|
|
.Default(CK_INVALID);
|
|
}
|
|
|
|
StringRef getMArchFromMcpu(StringRef CPU) {
|
|
CPUKind Kind = parseCPUKind(CPU);
|
|
return RISCVCPUInfo[static_cast<unsigned>(Kind)].DefaultMarch;
|
|
}
|
|
|
|
void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64) {
|
|
for (const auto &C : RISCVCPUInfo) {
|
|
if (C.Kind != CK_INVALID && IsRV64 == C.is64Bit())
|
|
Values.emplace_back(C.Name);
|
|
}
|
|
}
|
|
|
|
void fillValidTuneCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64) {
|
|
for (const auto &C : RISCVCPUInfo) {
|
|
if (C.Kind != CK_INVALID && IsRV64 == C.is64Bit())
|
|
Values.emplace_back(C.Name);
|
|
}
|
|
#define TUNE_PROC(ENUM, NAME) Values.emplace_back(StringRef(NAME));
|
|
#include "llvm/TargetParser/RISCVTargetParserDef.inc"
|
|
}
|
|
|
|
} // namespace RISCV
|
|
} // namespace llvm
|