CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
91 lines
2.8 KiB
C++
91 lines
2.8 KiB
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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Plugin/CodeGenTestPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
#include "llvm/CodeGen/Passes.h"
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
|
#include "llvm/Config/config.h"
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
#include "llvm/MC/TargetRegistry.h"
|
|
#include "llvm/Support/DynamicLibrary.h"
|
|
#include "llvm/Support/FileSystem.h"
|
|
#include "llvm/Support/Path.h"
|
|
#include "llvm/Support/TargetSelect.h"
|
|
#include "llvm/Target/RegisterTargetPassConfigCallback.h"
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace llvm {
|
|
class CGPluginTests : public testing::Test {
|
|
protected:
|
|
static void SetUpTestCase() {
|
|
InitializeAllTargetMCs();
|
|
InitializeAllTargetInfos();
|
|
InitializeAllTargets();
|
|
}
|
|
};
|
|
} // namespace llvm
|
|
|
|
TEST_F(CGPluginTests, LoadPlugin) {
|
|
#if !defined(LLVM_ENABLE_PLUGINS)
|
|
// Skip the test if plugins are disabled.
|
|
GTEST_SKIP();
|
|
#endif
|
|
|
|
auto PluginPath{std::string{"CGTestPlugin"} + LLVM_PLUGIN_EXT};
|
|
|
|
std::string Error;
|
|
auto Library = sys::DynamicLibrary::getLibrary(PluginPath.c_str(), &Error);
|
|
ASSERT_TRUE(Library.isValid()) << Error;
|
|
sys::DynamicLibrary::closeLibrary(Library);
|
|
}
|
|
|
|
TEST_F(CGPluginTests, ExecuteCallback) {
|
|
#if !defined(LLVM_ENABLE_PLUGINS)
|
|
// Skip the test if plugins are disabled.
|
|
GTEST_SKIP();
|
|
#endif
|
|
|
|
volatile bool CallbackExecuted = false;
|
|
volatile bool MPassExecuted = false;
|
|
|
|
RegisterTargetPassConfigCallback X{[&](auto &TM, auto &PM, auto *TPC) {
|
|
CallbackExecuted = true;
|
|
TPC->insertPass(&GCLoweringID, &CodeGenTest::ID);
|
|
}};
|
|
|
|
CodeGenTest::RunCallback = [&] { MPassExecuted = true; };
|
|
|
|
TargetOptions Options;
|
|
std::unique_ptr<MCContext> MCC;
|
|
for (auto T : TargetRegistry::targets()) {
|
|
if (!T.hasTargetMachine())
|
|
continue;
|
|
Triple TT{T.getName(), "", ""};
|
|
auto *TM = T.createTargetMachine(TT, "", "", Options, std::nullopt,
|
|
std::nullopt, CodeGenOptLevel::Default);
|
|
ASSERT_TRUE(TM);
|
|
|
|
legacy::PassManager PM;
|
|
MCC.reset(new MCContext(TT, TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
|
|
TM->getMCSubtargetInfo()));
|
|
auto *PtrMCC = MCC.get();
|
|
CallbackExecuted = false;
|
|
MPassExecuted = false;
|
|
if (TM->addPassesToEmitMC(PM, PtrMCC, outs()) == true)
|
|
continue;
|
|
ASSERT_TRUE(CallbackExecuted) << T.getName() << " callback failed";
|
|
ASSERT_TRUE(MPassExecuted) << T.getName() << " MachinePass failed";
|
|
}
|
|
}
|