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
97 lines
3.2 KiB
C++
97 lines
3.2 KiB
C++
//===- unittests/Passes/PassBuilderBindingsTest.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 "llvm-c/Core.h"
|
|
#include "llvm-c/Transforms/PassBuilder.h"
|
|
#include "llvm-c/Types.h"
|
|
#include "gtest/gtest.h"
|
|
#include <string.h>
|
|
|
|
using namespace llvm;
|
|
|
|
class PassBuilderCTest : public testing::Test {
|
|
void SetUp() override {
|
|
char *Triple = LLVMGetDefaultTargetTriple();
|
|
if (strlen(Triple) == 0) {
|
|
GTEST_SKIP();
|
|
LLVMDisposeMessage(Triple);
|
|
return;
|
|
}
|
|
LLVMInitializeAllTargetInfos();
|
|
char *Err;
|
|
LLVMTargetRef Target;
|
|
if (LLVMGetTargetFromTriple(Triple, &Target, &Err)) {
|
|
FAIL() << "Failed to create target from default triple (" << Triple
|
|
<< "): " << Err;
|
|
}
|
|
TM = LLVMCreateTargetMachine(Target, Triple, "generic", "",
|
|
LLVMCodeGenLevelDefault, LLVMRelocDefault,
|
|
LLVMCodeModelDefault);
|
|
LLVMDisposeMessage(Triple);
|
|
Context = LLVMContextCreate();
|
|
Module = LLVMModuleCreateWithNameInContext("test", Context);
|
|
LLVMTypeRef FT =
|
|
LLVMFunctionType(LLVMVoidTypeInContext(Context), nullptr, 0, 0);
|
|
Function = LLVMAddFunction(Module, "test", FT);
|
|
}
|
|
|
|
void TearDown() override {
|
|
char *Triple = LLVMGetDefaultTargetTriple();
|
|
if (strlen(Triple) == 0) {
|
|
LLVMDisposeMessage(Triple);
|
|
return; // Skipped, so nothing to tear down
|
|
}
|
|
LLVMDisposeMessage(Triple);
|
|
LLVMDisposeTargetMachine(TM);
|
|
LLVMDisposeModule(Module);
|
|
LLVMContextDispose(Context);
|
|
}
|
|
|
|
public:
|
|
LLVMTargetMachineRef TM;
|
|
LLVMModuleRef Module;
|
|
LLVMValueRef Function;
|
|
LLVMContextRef Context;
|
|
};
|
|
|
|
TEST_F(PassBuilderCTest, Basic) {
|
|
LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
|
|
LLVMPassBuilderOptionsSetLoopUnrolling(Options, 1);
|
|
LLVMPassBuilderOptionsSetVerifyEach(Options, 1);
|
|
LLVMPassBuilderOptionsSetDebugLogging(Options, 0);
|
|
LLVMPassBuilderOptionsSetAAPipeline(Options, "basic-aa");
|
|
if (LLVMErrorRef E = LLVMRunPasses(Module, "default<O2>", TM, Options)) {
|
|
char *Msg = LLVMGetErrorMessage(E);
|
|
LLVMDisposePassBuilderOptions(Options);
|
|
FAIL() << "Failed to run passes: " << Msg;
|
|
}
|
|
LLVMDisposePassBuilderOptions(Options);
|
|
}
|
|
|
|
TEST_F(PassBuilderCTest, InvalidPassIsError) {
|
|
LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
|
|
LLVMErrorRef E1 = LLVMRunPasses(Module, "", TM, Options);
|
|
LLVMErrorRef E2 = LLVMRunPasses(Module, "does-not-exist-pass", TM, Options);
|
|
ASSERT_TRUE(E1);
|
|
ASSERT_TRUE(E2);
|
|
LLVMConsumeError(E1);
|
|
LLVMConsumeError(E2);
|
|
LLVMDisposePassBuilderOptions(Options);
|
|
}
|
|
|
|
TEST_F(PassBuilderCTest, Function) {
|
|
LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
|
|
if (LLVMErrorRef E =
|
|
LLVMRunPassesOnFunction(Function, "no-op-function", TM, Options)) {
|
|
char *Msg = LLVMGetErrorMessage(E);
|
|
LLVMDisposePassBuilderOptions(Options);
|
|
FAIL() << "Failed to run passes on function: " << Msg;
|
|
}
|
|
LLVMDisposePassBuilderOptions(Options);
|
|
}
|