[RISCV][VLOPT] Add vector narrowing integer right shift instructions to isSupportedIn...
[llvm-project.git] / llvm / unittests / Passes / PassBuilderBindings / PassBuilderBindingsTest.cpp
blob4e17b1ad09e2b350e2ddbd16c1d388035a1d3c2a
1 //===- unittests/Passes/PassBuilderBindingsTest.cpp -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm-c/Core.h"
10 #include "llvm-c/Transforms/PassBuilder.h"
11 #include "llvm-c/Types.h"
12 #include "gtest/gtest.h"
13 #include <string.h>
15 using namespace llvm;
17 class PassBuilderCTest : public testing::Test {
18 void SetUp() override {
19 char *Triple = LLVMGetDefaultTargetTriple();
20 if (strlen(Triple) == 0) {
21 GTEST_SKIP();
22 LLVMDisposeMessage(Triple);
23 return;
25 LLVMInitializeAllTargetInfos();
26 char *Err;
27 LLVMTargetRef Target;
28 if (LLVMGetTargetFromTriple(Triple, &Target, &Err)) {
29 FAIL() << "Failed to create target from default triple (" << Triple
30 << "): " << Err;
32 TM = LLVMCreateTargetMachine(Target, Triple, "generic", "",
33 LLVMCodeGenLevelDefault, LLVMRelocDefault,
34 LLVMCodeModelDefault);
35 LLVMDisposeMessage(Triple);
36 Context = LLVMContextCreate();
37 Module = LLVMModuleCreateWithNameInContext("test", Context);
38 LLVMTypeRef FT =
39 LLVMFunctionType(LLVMVoidTypeInContext(Context), nullptr, 0, 0);
40 Function = LLVMAddFunction(Module, "test", FT);
43 void TearDown() override {
44 char *Triple = LLVMGetDefaultTargetTriple();
45 if (strlen(Triple) == 0) {
46 LLVMDisposeMessage(Triple);
47 return; // Skipped, so nothing to tear down
49 LLVMDisposeMessage(Triple);
50 LLVMDisposeTargetMachine(TM);
51 LLVMDisposeModule(Module);
52 LLVMContextDispose(Context);
55 public:
56 LLVMTargetMachineRef TM;
57 LLVMModuleRef Module;
58 LLVMValueRef Function;
59 LLVMContextRef Context;
62 TEST_F(PassBuilderCTest, Basic) {
63 LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
64 LLVMPassBuilderOptionsSetLoopUnrolling(Options, 1);
65 LLVMPassBuilderOptionsSetVerifyEach(Options, 1);
66 LLVMPassBuilderOptionsSetDebugLogging(Options, 0);
67 LLVMPassBuilderOptionsSetAAPipeline(Options, "basic-aa");
68 if (LLVMErrorRef E = LLVMRunPasses(Module, "default<O2>", TM, Options)) {
69 char *Msg = LLVMGetErrorMessage(E);
70 LLVMDisposePassBuilderOptions(Options);
71 FAIL() << "Failed to run passes: " << Msg;
73 LLVMDisposePassBuilderOptions(Options);
76 TEST_F(PassBuilderCTest, InvalidPassIsError) {
77 LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
78 LLVMErrorRef E1 = LLVMRunPasses(Module, "", TM, Options);
79 LLVMErrorRef E2 = LLVMRunPasses(Module, "does-not-exist-pass", TM, Options);
80 ASSERT_TRUE(E1);
81 ASSERT_TRUE(E2);
82 LLVMConsumeError(E1);
83 LLVMConsumeError(E2);
84 LLVMDisposePassBuilderOptions(Options);
87 TEST_F(PassBuilderCTest, Function) {
88 LLVMPassBuilderOptionsRef Options = LLVMCreatePassBuilderOptions();
89 if (LLVMErrorRef E =
90 LLVMRunPassesOnFunction(Function, "no-op-function", TM, Options)) {
91 char *Msg = LLVMGetErrorMessage(E);
92 LLVMDisposePassBuilderOptions(Options);
93 FAIL() << "Failed to run passes on function: " << Msg;
95 LLVMDisposePassBuilderOptions(Options);