From f0595505164491d38b6123dc656004c9c54c18b0 Mon Sep 17 00:00:00 2001 From: melonedo Date: Fri, 2 Sep 2022 10:52:34 +0800 Subject: [PATCH] gollvm: encode platform info in CallingConvId Previously gollvm encodes platform info in llvm::CallingConv::Id which may not be unique among all platforms. Replacing it with a local enum solves the problem. Change-Id: Ief01878a8c0b3a1200b575087196a758314c5c22 Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/427737 Reviewed-by: Ian Lance Taylor Reviewed-by: Than McIntosh --- README.md | 2 +- bridge/CMakeLists.txt | 2 +- bridge/go-llvm-backend.h | 2 +- bridge/go-llvm-cabi-oracle.cpp | 33 ++++++++++--------- bridge/go-llvm-cabi-oracle.h | 4 +-- bridge/go-llvm-typemanager.cpp | 2 +- bridge/go-llvm-typemanager.h | 8 ++--- bridge/go-llvm.cpp | 13 +++++--- bridge/go-llvm.h | 2 +- driver/CallingConv.h | 25 ++++++++++++++ driver/CompileGo.cpp | 12 ++++--- passes/CMakeLists.txt | 2 ++ passes/GoStatepoints.cpp | 2 +- unittests/BackendCore/BackendArrayStruct.cpp | 4 +-- .../BackendCore/BackendCABIOracleTests.cpp | 20 +++++------ unittests/BackendCore/BackendCallTests.cpp | 6 ++-- unittests/BackendCore/BackendCoreTests.cpp | 4 +-- unittests/BackendCore/BackendDebugEmit.cpp | 8 ++--- unittests/BackendCore/BackendExprTests.cpp | 8 ++--- unittests/BackendCore/BackendFcnTests.cpp | 4 +-- unittests/BackendCore/BackendNodeTests.cpp | 4 +-- .../BackendCore/BackendPointerExprTests.cpp | 4 +-- unittests/BackendCore/BackendStmtTests.cpp | 4 +-- .../BackendCore/BackendTreeIntegrity.cpp | 4 +-- unittests/BackendCore/BackendVarTests.cpp | 4 +-- unittests/BackendCore/TestUtils.cpp | 15 +++++---- unittests/BackendCore/TestUtils.h | 12 ++++--- unittests/CMakeLists.txt | 1 + 28 files changed, 128 insertions(+), 83 deletions(-) create mode 100644 driver/CallingConv.h diff --git a/README.md b/README.md index 0c563c9..1ba6551 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ TEST(BackendCoreTests, ComplexTypes) { Type *ft = Type::getFloatTy(C); Type *dt = Type::getDoubleTy(C); - std::unique_ptr be(go_get_backend(C, llvm::CallingConv::X86_64_SysV)); + std::unique_ptr be(go_get_backend(C, gollvm::driver::CallingConvId::X86_64_SysV)); Btype *c32 = be->complex_type(64); ASSERT_TRUE(c32 != NULL); ASSERT_EQ(c32->type(), mkTwoFieldLLvmStruct(C, ft, ft)); diff --git a/bridge/CMakeLists.txt b/bridge/CMakeLists.txt index 29b71c1..e4bc389 100644 --- a/bridge/CMakeLists.txt +++ b/bridge/CMakeLists.txt @@ -61,4 +61,4 @@ add_dependencies(LLVMCppGoFrontEnd libmpfr libmpc libgmp) include_directories(${EXTINSTALLDIR}/include) include_directories(${GOFRONTEND_SOURCE_DIR}) - +include_directories(${DRIVER_UTILS_SOURCE_DIR}) diff --git a/bridge/go-llvm-backend.h b/bridge/go-llvm-backend.h index 9c7f7e4..bb0bf0d 100644 --- a/bridge/go-llvm-backend.h +++ b/bridge/go-llvm-backend.h @@ -19,6 +19,6 @@ class Backend; -extern Backend *go_get_backend(llvm::LLVMContext &Context, llvm::CallingConv::ID cconv); +extern Backend *go_get_backend(llvm::LLVMContext &Context, gollvm::driver::CallingConvId cconv); #endif // !defined(GO_LLVM_BACKEND_H) diff --git a/bridge/go-llvm-cabi-oracle.cpp b/bridge/go-llvm-cabi-oracle.cpp index 45c2406..7ba851f 100644 --- a/bridge/go-llvm-cabi-oracle.cpp +++ b/bridge/go-llvm-cabi-oracle.cpp @@ -16,6 +16,8 @@ #include "llvm/IR/DataLayout.h" #include "llvm/Support/raw_ostream.h" +#include "CallingConv.h" + //...................................................................... // Given an LLVM type, classify it according to whether it would @@ -146,12 +148,12 @@ EightByteInfo::EightByteInfo(Btype *bt, TypeManager *tmgr) : typeManager_(tmgr) { explode(bt); - llvm::CallingConv::ID cconv = tmgr->callingConv(); + gollvm::driver::CallingConvId cconv = tmgr->callingConv(); switch (cconv) { - case llvm::CallingConv::X86_64_SysV: + case gollvm::driver::CallingConvId::X86_64_SysV: determineABITypesForX86_64_SysV(); break; - case llvm::CallingConv::ARM_AAPCS: + case gollvm::driver::CallingConvId::ARM_AAPCS: setHFA(); if (getHFA().number == 0 && tmgr->typeSize(bt) <= 16) { // For HFA and indirect cases, we don't need do this. @@ -159,7 +161,7 @@ EightByteInfo::EightByteInfo(Btype *bt, TypeManager *tmgr) } break; default: - llvm::errs() << "unsupported llvm::CallingConv::ID " << cconv << "\n"; + llvm::errs() << "unsupported gollvm::driver::CallingConvId " << static_cast(cconv) << "\n"; break; } } @@ -544,18 +546,18 @@ class ABIState { public: ABIState(TypeManager *typm) : argCount_(0) { assert(typm != nullptr); - llvm::CallingConv::ID cconv = typm->callingConv(); + gollvm::driver::CallingConvId cconv = typm->callingConv(); switch (cconv) { - case llvm::CallingConv::X86_64_SysV: + case gollvm::driver::CallingConvId::X86_64_SysV: availIntRegs_ = 6; availSSERegs_ = 8; break; - case llvm::CallingConv::ARM_AAPCS: + case gollvm::driver::CallingConvId::ARM_AAPCS: availIntRegs_ = 8; availSIMDFPRegs_ = 8; break; default: - llvm::errs() << "unsupported llvm::CallingConv::ID " << cconv << "\n"; + llvm::errs() << "unsupported gollvm::driver::CallingConvId " << static_cast(cconv) << "\n"; break; } } @@ -610,7 +612,7 @@ CABIOracle::CABIOracle(const std::vector &fcnParamTypes, , fcnTypeForABI_(nullptr) , typeManager_(typeManager) , followsCabi_(followsCabi) - , ccID_(llvm::CallingConv::MaxID) + , ccID_(gollvm::driver::CallingConvId::MaxID) , cc_(nullptr) { setCC(); @@ -624,7 +626,7 @@ CABIOracle::CABIOracle(BFunctionType *ft, , fcnTypeForABI_(nullptr) , typeManager_(typeManager) , followsCabi_(ft->followsCabi()) - , ccID_(llvm::CallingConv::MaxID) + , ccID_(gollvm::driver::CallingConvId::MaxID) , cc_(nullptr) { setCC(); @@ -636,21 +638,22 @@ void CABIOracle::setCC() assert(typeManager_ != nullptr); ccID_ = typeManager_->callingConv(); // Supported architectures at present. - assert(ccID_ == llvm::CallingConv::X86_64_SysV || - ccID_ == llvm::CallingConv::ARM_AAPCS); + assert(ccID_ == gollvm::driver::CallingConvId::X86_64_SysV || + ccID_ == gollvm::driver::CallingConvId::ARM_AAPCS || + ccID_ == gollvm::driver::CallingConvId::RISCV64_C); if (cc_ != nullptr) { return; } switch (ccID_) { - case llvm::CallingConv::X86_64_SysV: + case gollvm::driver::CallingConvId::X86_64_SysV: cc_ = std::unique_ptr(new CABIOracleX86_64_SysV(typeManager_)); break; - case llvm::CallingConv::ARM_AAPCS: + case gollvm::driver::CallingConvId::ARM_AAPCS: cc_ = std::unique_ptr(new CABIOracleARM_AAPCS(typeManager_)); break; default: - llvm::errs() << "unsupported llvm::CallingConv::ID " << ccID_ << "\n"; + llvm::errs() << "unsupported gollvm::driver::CallingConvId " << static_cast(ccID_) << "\n"; break; } } diff --git a/bridge/go-llvm-cabi-oracle.h b/bridge/go-llvm-cabi-oracle.h index c186c38..86b79f5 100644 --- a/bridge/go-llvm-cabi-oracle.h +++ b/bridge/go-llvm-cabi-oracle.h @@ -20,8 +20,8 @@ #ifndef LLVMGOFRONTEND_GO_LLVM_CABI_ORACLE_H #define LLVMGOFRONTEND_GO_LLVM_CABI_ORACLE_H +#include "CallingConv.h" #include "go-llvm-btype.h" -#include "llvm/IR/CallingConv.h" class TypeManager; class EightByteInfo; @@ -198,7 +198,7 @@ class CABIOracle { TypeManager *typeManager_; std::vector infov_; bool followsCabi_; - llvm::CallingConv::ID ccID_; + gollvm::driver::CallingConvId ccID_; std::unique_ptr cc_; // The main entry for cabi analysis. diff --git a/bridge/go-llvm-typemanager.cpp b/bridge/go-llvm-typemanager.cpp index ba57edc..4301233 100644 --- a/bridge/go-llvm-typemanager.cpp +++ b/bridge/go-llvm-typemanager.cpp @@ -23,7 +23,7 @@ #include "llvm/IR/Type.h" TypeManager::TypeManager(llvm::LLVMContext &context, - llvm::CallingConv::ID conv, + gollvm::driver::CallingConvId conv, unsigned addrspace) : context_(context) , datalayout_(nullptr) diff --git a/bridge/go-llvm-typemanager.h b/bridge/go-llvm-typemanager.h index 789b5d5..d77a3ab 100644 --- a/bridge/go-llvm-typemanager.h +++ b/bridge/go-llvm-typemanager.h @@ -20,7 +20,7 @@ #include "namegen.h" #include "backend.h" -#include "llvm/IR/CallingConv.h" +#include "CallingConv.h" namespace llvm { class DataLayout; @@ -43,7 +43,7 @@ enum PTDisp { Concrete, Placeholder }; class TypeManager { public: TypeManager(llvm::LLVMContext &context, - llvm::CallingConv::ID cconv, + gollvm::driver::CallingConvId cconv, unsigned addrspace); ~TypeManager(); @@ -246,7 +246,7 @@ class TypeManager { const llvm::DataLayout *datalayout() const { return datalayout_; } // Calling convention - llvm::CallingConv::ID callingConv() const { return cconv_; } + gollvm::driver::CallingConvId callingConv() const { return cconv_; } // For named types, this returns the declared type name. If a type // is unnamed, then it returns a stringified representation of the @@ -287,7 +287,7 @@ class TypeManager { // Context information needed for the LLVM backend. llvm::LLVMContext &context_; const llvm::DataLayout *datalayout_; - llvm::CallingConv::ID cconv_; + gollvm::driver::CallingConvId cconv_; unsigned addressSpace_; unsigned traceLevel_; diff --git a/bridge/go-llvm.cpp b/bridge/go-llvm.cpp index 312b38b..8ee5a24 100644 --- a/bridge/go-llvm.cpp +++ b/bridge/go-llvm.cpp @@ -45,7 +45,7 @@ Llvm_backend::Llvm_backend(llvm::LLVMContext &context, Llvm_linemap *linemap, unsigned addrspace, llvm::Triple triple, - llvm::CallingConv::ID cconv) + gollvm::driver::CallingConvId cconv) : TypeManager(context, cconv, addrspace) , context_(context) , module_(module) @@ -83,16 +83,21 @@ Llvm_backend::Llvm_backend(llvm::LLVMContext &context, if (!module_) { ownModule_.reset(new llvm::Module("gomodule", context)); switch (cconv) { - case llvm::CallingConv::X86_64_SysV: + case gollvm::driver::CallingConvId::X86_64_SysV: ownModule_->setTargetTriple("x86_64-unknown-linux-gnu"); ownModule_->setDataLayout("e-m:e-i64:64-f80:128-n8:16:32:64-S128"); triple_ = llvm::Triple("x86_64-unknown-linux-gnu"); break; - case llvm::CallingConv::ARM_AAPCS: + case gollvm::driver::CallingConvId::ARM_AAPCS: ownModule_->setTargetTriple("aarch64-unknown-linux-gnu"); ownModule_->setDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"); triple_ = llvm::Triple("aarch64-unknown-linux-gnu"); break; + case gollvm::driver::CallingConvId::RISCV64_C: + ownModule_->setTargetTriple("riscv64-unknown-linux-gnu"); + ownModule_->setDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128"); + triple_ = llvm::Triple("riscv64-unknown-linux-gnu"); + break; default: std::cerr <<"Unsupported calling convention\n"; } @@ -4158,6 +4163,6 @@ const char *go_localize_identifier(const char *ident) { return ident; } // Return a new backend generator. -Backend *go_get_backend(llvm::LLVMContext &context, llvm::CallingConv::ID cconv) { +Backend *go_get_backend(llvm::LLVMContext &context, gollvm::driver::CallingConvId cconv) { return new Llvm_backend(context, nullptr, nullptr, 0, llvm::Triple(), cconv); } diff --git a/bridge/go-llvm.h b/bridge/go-llvm.h index 880ae39..cd4d855 100644 --- a/bridge/go-llvm.h +++ b/bridge/go-llvm.h @@ -82,7 +82,7 @@ class Llvm_backend : public Backend, public TypeManager, public NameGen { unsigned addrspace, llvm::Triple triple, /* Temporarily set the parameter as optional to workaround the unit tests. */ - llvm::CallingConv::ID cconv=llvm::CallingConv::X86_64_SysV); + gollvm::driver::CallingConvId cconv=gollvm::driver::CallingConvId::X86_64_SysV); ~Llvm_backend(); // Types. diff --git a/driver/CallingConv.h b/driver/CallingConv.h new file mode 100644 index 0000000..cfd791f --- /dev/null +++ b/driver/CallingConv.h @@ -0,0 +1,25 @@ +//===-- CallingConv.h -----------------------------------------------------===// +// +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// +//===----------------------------------------------------------------------===// +// +// Defines the CallingConvId type. +// +//===----------------------------------------------------------------------===// + +#ifndef GOLLVM_DRIVER_CALLINGCONV_H +#define GOLLVM_DRIVER_CALLINGCONV_H + +namespace gollvm { +namespace driver { + +// Used inplace of llvm::CallingConv::Id which does not record arch and cpu +enum class CallingConvId { X86_64_SysV, ARM_AAPCS, RISCV64_C, MaxID }; + +} // end namespace driver +} // end namespace gollvm + +#endif // GOLLVM_DRIVER_CALLINGCONV_H diff --git a/driver/CompileGo.cpp b/driver/CompileGo.cpp index b317c9b..3312a7a 100644 --- a/driver/CompileGo.cpp +++ b/driver/CompileGo.cpp @@ -24,6 +24,7 @@ #include "Action.h" #include "ArchCpuSetup.h" #include "Artifact.h" +#include "CallingConv.h" #include "Driver.h" #include "ToolChain.h" @@ -105,7 +106,7 @@ class CompileGoImpl { Triple triple_; const ToolChain &toolchain_; Driver &driver_; - CallingConv::ID cconv_; + CallingConvId cconv_; LLVMContext context_; const char *progname_; std::string executablePath_; @@ -154,7 +155,7 @@ CompileGoImpl::CompileGoImpl(CompileGo &cg, triple_(tc.driver().triple()), toolchain_(tc), driver_(tc.driver()), - cconv_(CallingConv::MaxID), + cconv_(CallingConvId::MaxID), progname_(tc.driver().progname()), executablePath_(executablePath), args_(tc.driver().args()), @@ -723,10 +724,13 @@ void CompileGoImpl::setCConv() assert(triple_.getArch() != Triple::UnknownArch); switch (triple_.getArch()) { case Triple::x86_64: - cconv_ = CallingConv::X86_64_SysV; + cconv_ = CallingConvId::X86_64_SysV; break; case Triple::aarch64: - cconv_ = CallingConv::ARM_AAPCS; + cconv_ = CallingConvId::ARM_AAPCS; + break; + case Triple::riscv64: + cconv_ = CallingConvId::RISCV64_C; break; default: errs() << "currently Gollvm is not supported on architecture " diff --git a/passes/CMakeLists.txt b/passes/CMakeLists.txt index b70279c..af9c25a 100644 --- a/passes/CMakeLists.txt +++ b/passes/CMakeLists.txt @@ -18,3 +18,5 @@ add_llvm_library(LLVMCppGoPasses DEPENDS intrinsics_gen ) + +include_directories(${DRIVER_UTILS_SOURCE_DIR}) diff --git a/passes/GoStatepoints.cpp b/passes/GoStatepoints.cpp index 3542a4f..6453db4 100644 --- a/passes/GoStatepoints.cpp +++ b/passes/GoStatepoints.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "CallingConv.h" #include "GoStatepoints.h" #include "GoStackMap.h" #include "GollvmPasses.h" @@ -35,7 +36,6 @@ #include "llvm/IR/Argument.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/CallingConv.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" diff --git a/unittests/BackendCore/BackendArrayStruct.cpp b/unittests/BackendCore/BackendArrayStruct.cpp index 4f40d9c..a488338 100644 --- a/unittests/BackendCore/BackendArrayStruct.cpp +++ b/unittests/BackendCore/BackendArrayStruct.cpp @@ -18,11 +18,11 @@ using namespace goBackendUnitTests; namespace { class BackendArrayStructTests - : public testing::TestWithParam {}; + : public testing::TestWithParam {}; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendArrayStructTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendCABIOracleTests.cpp b/unittests/BackendCore/BackendCABIOracleTests.cpp index c1535ba..3f3c902 100644 --- a/unittests/BackendCore/BackendCABIOracleTests.cpp +++ b/unittests/BackendCore/BackendCABIOracleTests.cpp @@ -19,11 +19,11 @@ using namespace goBackendUnitTests; namespace { class BackendCABIOracleTests - : public testing::TestWithParam {}; + : public testing::TestWithParam {}; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendCABIOracleTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; @@ -72,7 +72,7 @@ TEST_P(BackendCABIOracleTests, Basic) { TEST(BackendCABIOracleTests, ExtendedAmd64) { LLVMContext C; std::unique_ptr bep( - new Llvm_backend(C, nullptr, nullptr, 0, llvm::Triple(), llvm::CallingConv::X86_64_SysV)); + new Llvm_backend(C, nullptr, nullptr, 0, llvm::Triple(), gollvm::driver::CallingConvId::X86_64_SysV)); Llvm_backend *be = bep.get(); Btype *bi8t = be->integer_type(false, 8); @@ -256,7 +256,7 @@ TEST(BackendCABIOracleTests, ExtendedAmd64) { TEST(BackendCABIOracleTests, ExtendedArm64) { LLVMContext C; std::unique_ptr bep( - new Llvm_backend(C, nullptr, nullptr, 0, llvm::Triple(), llvm::CallingConv::ARM_AAPCS)); + new Llvm_backend(C, nullptr, nullptr, 0, llvm::Triple(), gollvm::driver::CallingConvId::ARM_AAPCS)); Llvm_backend *be = bep.get(); Btype *bi8t = be->integer_type(false, 8); @@ -439,7 +439,7 @@ TEST(BackendCABIOracleTests, ExtendedArm64) { } TEST(BackendCABIOracleTests, RecursiveCall1Amd64) { - FcnTestHarness h(llvm::CallingConv::X86_64_SysV); + FcnTestHarness h(gollvm::driver::CallingConvId::X86_64_SysV); Llvm_backend *be = h.be(); // type s1 struct { @@ -564,7 +564,7 @@ TEST(BackendCABIOracleTests, RecursiveCall1Amd64) { } TEST(BackendCABIOracleTests, RecursiveCall1Arm64) { - FcnTestHarness h(llvm::CallingConv::ARM_AAPCS); + FcnTestHarness h(gollvm::driver::CallingConvId::ARM_AAPCS); Llvm_backend *be = h.be(); // type s1 struct { @@ -686,7 +686,7 @@ TEST(BackendCABIOracleTests, RecursiveCall1Arm64) { } TEST(BackendCABIOracleTests, PassAndReturnArraysAmd64) { - FcnTestHarness h(llvm::CallingConv::X86_64_SysV); + FcnTestHarness h(gollvm::driver::CallingConvId::X86_64_SysV); Llvm_backend *be = h.be(); Btype *bf32t = be->float_type(32); @@ -733,7 +733,7 @@ TEST(BackendCABIOracleTests, PassAndReturnArraysAmd64) { } TEST(BackendCABIOracleTests, PassAndReturnArraysArm64) { - FcnTestHarness h(llvm::CallingConv::ARM_AAPCS); + FcnTestHarness h(gollvm::driver::CallingConvId::ARM_AAPCS); Llvm_backend *be = h.be(); Btype *bf32t = be->float_type(32); @@ -850,7 +850,7 @@ TEST_P(BackendCABIOracleTests, CallBuiltinFunction) { } TEST(BackendCABIOracleTests, PassAndReturnComplexAmd64) { - FcnTestHarness h(llvm::CallingConv::X86_64_SysV); + FcnTestHarness h(gollvm::driver::CallingConvId::X86_64_SysV); Llvm_backend *be = h.be(); Btype *bc64t = be->complex_type(64); @@ -926,7 +926,7 @@ TEST(BackendCABIOracleTests, PassAndReturnComplexAmd64) { } TEST(BackendCABIOracleTests, PassAndReturnComplexArm64) { - FcnTestHarness h(llvm::CallingConv::ARM_AAPCS); + FcnTestHarness h(gollvm::driver::CallingConvId::ARM_AAPCS); Llvm_backend *be = h.be(); Btype *bc64t = be->complex_type(64); diff --git a/unittests/BackendCore/BackendCallTests.cpp b/unittests/BackendCore/BackendCallTests.cpp index e835bde..b8d7eaf 100644 --- a/unittests/BackendCore/BackendCallTests.cpp +++ b/unittests/BackendCore/BackendCallTests.cpp @@ -17,12 +17,12 @@ using namespace goBackendUnitTests; namespace { -class BackendCallTests : public testing::TestWithParam { +class BackendCallTests : public testing::TestWithParam { }; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendCallTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; @@ -235,7 +235,7 @@ TEST_P(BackendCallTests, CallToNoReturnFunction) { // expected result. However, the processing method of static link and dynamic // link is the same, but the instruction is slightly different. TEST(BackendCallTests, TestMakeGetgDynamicArm64) { - FcnTestHarness h(llvm::CallingConv::ARM_AAPCS, "foo"); + FcnTestHarness h(gollvm::driver::CallingConvId::ARM_AAPCS, "foo"); Llvm_backend *be = h.be(); be->module().setPICLevel(llvm::PICLevel::BigPIC); Bfunction *func = h.func(); diff --git a/unittests/BackendCore/BackendCoreTests.cpp b/unittests/BackendCore/BackendCoreTests.cpp index dbed58b..30923a0 100644 --- a/unittests/BackendCore/BackendCoreTests.cpp +++ b/unittests/BackendCore/BackendCoreTests.cpp @@ -15,12 +15,12 @@ using namespace goBackendUnitTests; namespace { -class BackendCoreTests : public testing::TestWithParam { +class BackendCoreTests : public testing::TestWithParam { }; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendCoreTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendDebugEmit.cpp b/unittests/BackendCore/BackendDebugEmit.cpp index 2875ba4..7859104 100644 --- a/unittests/BackendCore/BackendDebugEmit.cpp +++ b/unittests/BackendCore/BackendDebugEmit.cpp @@ -20,12 +20,12 @@ namespace { // changed). Perhaps there is some other way to verify this // functionality. -class BackendDebugEmit : public testing::TestWithParam { +class BackendDebugEmit : public testing::TestWithParam { }; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendDebugEmit, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; @@ -60,7 +60,7 @@ TEST_P(BackendDebugEmit, TestSimpleDecl) { TEST(BackendDebugEmit, TestSimpleDecl2Amd64) { // Test that parameters of empty function are handled correctly. - FcnTestHarness h(llvm::CallingConv::X86_64_SysV); + FcnTestHarness h(gollvm::driver::CallingConvId::X86_64_SysV); Llvm_backend *be = h.be(); Btype *bi64t = be->integer_type(false, 64); Btype *bst = mkBackendStruct(be, bi64t, "f1", @@ -89,7 +89,7 @@ TEST(BackendDebugEmit, TestSimpleDecl2Amd64) { TEST(BackendDebugEmit, TestSimpleDecl2Arm64) { // Test that parameters of empty function are handled correctly. - FcnTestHarness h(llvm::CallingConv::ARM_AAPCS); + FcnTestHarness h(gollvm::driver::CallingConvId::ARM_AAPCS); Llvm_backend *be = h.be(); Btype *bi64t = be->integer_type(false, 64); Btype *bst = mkBackendStruct(be, bi64t, "f1", bi64t, "f2", bi64t, "f3", diff --git a/unittests/BackendCore/BackendExprTests.cpp b/unittests/BackendCore/BackendExprTests.cpp index eab503f..a476f06 100644 --- a/unittests/BackendCore/BackendExprTests.cpp +++ b/unittests/BackendCore/BackendExprTests.cpp @@ -17,12 +17,12 @@ using namespace goBackendUnitTests; namespace { -class BackendExprTests : public testing::TestWithParam { +class BackendExprTests : public testing::TestWithParam { }; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendExprTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; @@ -1429,7 +1429,7 @@ TEST_P(BackendExprTests, TestConditionalExpression2) { } TEST(BackendExprTests, TestConditionalExpression3Amd64) { - FcnTestHarness h(llvm::CallingConv::X86_64_SysV); + FcnTestHarness h(gollvm::driver::CallingConvId::X86_64_SysV); Llvm_backend *be = h.be(); Btype *bi32t = be->integer_type(false, 32); Btype *abt = be->array_type(bi32t, mkInt64Const(be, int64_t(16))); @@ -1494,7 +1494,7 @@ TEST(BackendExprTests, TestConditionalExpression3Amd64) { } TEST(BackendExprTests, TestConditionalExpression3Arm64) { - FcnTestHarness h(llvm::CallingConv::ARM_AAPCS); + FcnTestHarness h(gollvm::driver::CallingConvId::ARM_AAPCS); Llvm_backend *be = h.be(); Btype *bi32t = be->integer_type(false, 32); Btype *abt = be->array_type(bi32t, mkInt64Const(be, int64_t(16))); diff --git a/unittests/BackendCore/BackendFcnTests.cpp b/unittests/BackendCore/BackendFcnTests.cpp index 0cf95db..2af5163 100644 --- a/unittests/BackendCore/BackendFcnTests.cpp +++ b/unittests/BackendCore/BackendFcnTests.cpp @@ -16,11 +16,11 @@ using namespace goBackendUnitTests; namespace { -class BackendFcnTests : public testing::TestWithParam {}; +class BackendFcnTests : public testing::TestWithParam {}; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendFcnTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendNodeTests.cpp b/unittests/BackendCore/BackendNodeTests.cpp index 34255bf..13a3a5a 100644 --- a/unittests/BackendCore/BackendNodeTests.cpp +++ b/unittests/BackendCore/BackendNodeTests.cpp @@ -18,12 +18,12 @@ using namespace goBackendUnitTests; namespace { -class BackendNodeTests : public testing::TestWithParam { +class BackendNodeTests : public testing::TestWithParam { }; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendNodeTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendPointerExprTests.cpp b/unittests/BackendCore/BackendPointerExprTests.cpp index 58978ec..f5882ca 100644 --- a/unittests/BackendCore/BackendPointerExprTests.cpp +++ b/unittests/BackendCore/BackendPointerExprTests.cpp @@ -18,11 +18,11 @@ using namespace goBackendUnitTests; namespace { class BackendPointerExprTests - : public testing::TestWithParam {}; + : public testing::TestWithParam {}; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendPointerExprTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendStmtTests.cpp b/unittests/BackendCore/BackendStmtTests.cpp index 866f3ed..7e47928 100644 --- a/unittests/BackendCore/BackendStmtTests.cpp +++ b/unittests/BackendCore/BackendStmtTests.cpp @@ -15,12 +15,12 @@ using namespace goBackendUnitTests; namespace { -class BackendStmtTests : public testing::TestWithParam { +class BackendStmtTests : public testing::TestWithParam { }; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendStmtTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendTreeIntegrity.cpp b/unittests/BackendCore/BackendTreeIntegrity.cpp index df6b32b..0c52b9c 100644 --- a/unittests/BackendCore/BackendTreeIntegrity.cpp +++ b/unittests/BackendCore/BackendTreeIntegrity.cpp @@ -16,11 +16,11 @@ using namespace goBackendUnitTests; namespace { class BackendTreeIntegrity - : public testing::TestWithParam {}; + : public testing::TestWithParam {}; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendTreeIntegrity, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/BackendVarTests.cpp b/unittests/BackendCore/BackendVarTests.cpp index 763602e..526cd9d 100644 --- a/unittests/BackendCore/BackendVarTests.cpp +++ b/unittests/BackendCore/BackendVarTests.cpp @@ -20,11 +20,11 @@ using namespace goBackendUnitTests; namespace { -class BackendVarTests : public testing::TestWithParam {}; +class BackendVarTests : public testing::TestWithParam {}; INSTANTIATE_TEST_SUITE_P( UnitTest, BackendVarTests, - goBackendUnitTests::CConvs, + goBackendUnitTests::cconvs(), [](const testing::TestParamInfo &info) { std::string name = goBackendUnitTests::ccName(info.param); return name; diff --git a/unittests/BackendCore/TestUtils.cpp b/unittests/BackendCore/TestUtils.cpp index bfca6c1..73475e1 100644 --- a/unittests/BackendCore/TestUtils.cpp +++ b/unittests/BackendCore/TestUtils.cpp @@ -12,14 +12,17 @@ namespace goBackendUnitTests { -std::string ccName(llvm::CallingConv::ID cc) { - assert(cc == llvm::CallingConv::X86_64_SysV || - cc == llvm::CallingConv::ARM_AAPCS); +std::string ccName(gollvm::driver::CallingConvId cc) { + assert(cc == gollvm::driver::CallingConvId::X86_64_SysV || + cc == gollvm::driver::CallingConvId::ARM_AAPCS || + cc == gollvm::driver::CallingConvId::RISCV64_C); switch (cc) { - case llvm::CallingConv::X86_64_SysV: + case gollvm::driver::CallingConvId::X86_64_SysV: return "X8664SysV"; - case llvm::CallingConv::ARM_AAPCS: + case gollvm::driver::CallingConvId::ARM_AAPCS: return "ARMAAPCS"; + case gollvm::driver::CallingConvId::RISCV64_C: + return "RISCV64C"; default: return ""; } @@ -384,7 +387,7 @@ std::string repr(Bnode *node) { return trimsp(vis.result()); } -FcnTestHarness::FcnTestHarness(llvm::CallingConv::ID cconv, const char *fcnName) +FcnTestHarness::FcnTestHarness(gollvm::driver::CallingConvId cconv, const char *fcnName) : context_() , be_(new Llvm_backend(context_, nullptr, nullptr, 0, llvm::Triple(), cconv)) , func_(nullptr) diff --git a/unittests/BackendCore/TestUtils.h b/unittests/BackendCore/TestUtils.h index 366fbf7..fa6774e 100644 --- a/unittests/BackendCore/TestUtils.h +++ b/unittests/BackendCore/TestUtils.h @@ -32,11 +32,13 @@ namespace goBackendUnitTests { // All supported calling conventions -auto CConvs = testing::Values(llvm::CallingConv::X86_64_SysV, - llvm::CallingConv::ARM_AAPCS); +inline auto cconvs() { + return testing::Values(gollvm::driver::CallingConvId::X86_64_SysV, + gollvm::driver::CallingConvId::ARM_AAPCS); +} -// Convert llvm::CallingConv::ID to its coresponding string name. -std::string ccName(llvm::CallingConv::ID); +// Convert gollvm::driver::CallingConvId to its coresponding string name. +std::string ccName(gollvm::driver::CallingConvId); // Return string representation of LLVM value (handling null ptr) std::string repr(llvm::Value *val); @@ -158,7 +160,7 @@ class FcnTestHarness { public: // Create test harness. If name specified, then create a // default function "fcnName(i1, i2 int32) int64". - FcnTestHarness(llvm::CallingConv::ID cconv, const char *fcnName = nullptr); + FcnTestHarness(gollvm::driver::CallingConvId cconv, const char *fcnName = nullptr); ~FcnTestHarness(); // Create function to work on diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index cac798a..b20037a 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -24,6 +24,7 @@ endfunction() include_directories(${EXTINSTALLDIR}/include) include_directories(${BRIDGE_SOURCE_DIR}) include_directories(${GOFRONTEND_SOURCE_DIR}) +include_directories(${DRIVER_UTILS_SOURCE_DIR}) add_subdirectory(DriverUtils) add_subdirectory(Driver)