[RISCV] Fix ISCVISAInfo::computeDefaultABI() result for xcheriot (#212129)
XCheriot was not considered in this function, so RV32E+XCheriot defaulted to ilp32e instead of cheriot when no -target-abi was given. Since this function does not have unit test coverage, this adds new tests for the ABI inference functions: RISCVISAInfo::computeDefaultABI() and RISCVABI::computeTargetABI. This change was created with the help of AI tools
This commit is contained in:
parent
d9e699957d
commit
b94b699857
4 changed files with 74 additions and 0 deletions
|
|
@ -1083,6 +1083,8 @@ RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
|
|||
|
||||
StringRef RISCVISAInfo::computeDefaultABI() const {
|
||||
if (XLen == 32) {
|
||||
if (Exts.count("xcheriot"))
|
||||
return "cheriot";
|
||||
if (Exts.count("e"))
|
||||
return "ilp32e";
|
||||
if (Exts.count("d"))
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ set(LLVM_LINK_COMPONENTS
|
|||
|
||||
add_llvm_target_unittest(RISCVTests
|
||||
MCInstrAnalysisTest.cpp
|
||||
RISCVBaseInfoTest.cpp
|
||||
RISCVInstrInfoTest.cpp
|
||||
RISCVSelectionDAGTest.cpp
|
||||
)
|
||||
|
|
|
|||
50
llvm/unittests/Target/RISCV/RISCVBaseInfoTest.cpp
Normal file
50
llvm/unittests/Target/RISCV/RISCVBaseInfoTest.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//===- RISCVBaseInfoTest.cpp ----------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MCTargetDesc/RISCVBaseInfo.h"
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/MC/TargetRegistry.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<MCSubtargetInfo> createSTI(StringRef TripleName,
|
||||
StringRef FeatureStr) {
|
||||
LLVMInitializeRISCVTargetInfo();
|
||||
LLVMInitializeRISCVTarget();
|
||||
LLVMInitializeRISCVTargetMC();
|
||||
std::string Error;
|
||||
Triple TT(TripleName);
|
||||
const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
|
||||
return std::unique_ptr<MCSubtargetInfo>(
|
||||
TheTarget->createMCSubtargetInfo(TT, /*CPU=*/"", FeatureStr));
|
||||
}
|
||||
|
||||
RISCVABI::ABI computeTargetABI(StringRef TripleName, StringRef FeatureStr,
|
||||
StringRef ABIName = "") {
|
||||
auto STI = createSTI(TripleName, FeatureStr);
|
||||
return RISCVABI::computeTargetABI(*STI, ABIName);
|
||||
}
|
||||
|
||||
TEST(ComputeTargetABI, SelectsExpectedABI) {
|
||||
EXPECT_EQ(computeTargetABI("riscv32", ""), RISCVABI::ABI_ILP32);
|
||||
EXPECT_EQ(computeTargetABI("riscv32", "+f"), RISCVABI::ABI_ILP32F);
|
||||
EXPECT_EQ(computeTargetABI("riscv32", "+f,+d"), RISCVABI::ABI_ILP32D);
|
||||
EXPECT_EQ(computeTargetABI("riscv64", ""), RISCVABI::ABI_LP64);
|
||||
EXPECT_EQ(computeTargetABI("riscv64", "+f"), RISCVABI::ABI_LP64F);
|
||||
EXPECT_EQ(computeTargetABI("riscv64", "+f,+d"), RISCVABI::ABI_LP64D);
|
||||
|
||||
// CHERIoT always selects the cheriot ABI by default.
|
||||
EXPECT_EQ(computeTargetABI("riscv32", "+xcheriot"), RISCVABI::ABI_CHERIOT);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -1243,6 +1243,27 @@ TEST(ParseArchString, RVYFeatureImplicationC) {
|
|||
EXPECT_FALSE((*MaybeISAInfo)->hasExtension("zcd"));
|
||||
}
|
||||
|
||||
static StringRef GetABIFromFeatures(unsigned XLen,
|
||||
std::vector<std::string> Features) {
|
||||
auto ISAInfo = RISCVISAInfo::parseFeatures(XLen, Features);
|
||||
EXPECT_THAT_EXPECTED(ISAInfo, Succeeded());
|
||||
return (*ISAInfo)->computeDefaultABI();
|
||||
}
|
||||
|
||||
TEST(ComputeDefaultABI, SelectsExpectedABI) {
|
||||
EXPECT_EQ(GetABIFromFeatures(32, {}), "ilp32");
|
||||
EXPECT_EQ(GetABIFromFeatures(32, {"+f"}), "ilp32f");
|
||||
EXPECT_EQ(GetABIFromFeatures(32, {"+f", "+d"}), "ilp32d");
|
||||
EXPECT_EQ(GetABIFromFeatures(32, {"+e"}), "ilp32e");
|
||||
EXPECT_EQ(GetABIFromFeatures(64, {}), "lp64");
|
||||
EXPECT_EQ(GetABIFromFeatures(64, {"+f"}), "lp64f");
|
||||
EXPECT_EQ(GetABIFromFeatures(64, {"+f", "+d"}), "lp64d");
|
||||
EXPECT_EQ(GetABIFromFeatures(64, {"+e"}), "lp64e");
|
||||
|
||||
// CHERIoT always selects the cheriot ABI by default.
|
||||
EXPECT_EQ(GetABIFromFeatures(32, {"+xcheriot"}), "cheriot");
|
||||
}
|
||||
|
||||
TEST(ParseArchString, ZcaZcbZcmpZcmtImpliesZce) {
|
||||
// Test Zca+Zcb+Zcmp+Zcmt implies Zce behavior.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue