1 //===- AttributorTest.cpp - Attributor unit tests ------------------------===//
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 //===---------------------------------------------------------------------===//
8 
9 #include "llvm/Transforms/IPO/Attributor.h"
10 #include "AttributorTestBase.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Analysis/CGSCCPassManager.h"
13 #include "llvm/Analysis/CallGraphSCCPass.h"
14 #include "llvm/Analysis/LoopAnalysisManager.h"
15 #include "llvm/AsmParser/Parser.h"
16 #include "llvm/Support/Allocator.h"
17 #include "llvm/Testing/Support/Error.h"
18 #include "llvm/Transforms/Utils/CallGraphUpdater.h"
19 #include "gtest/gtest.h"
20 #include <memory>
21 
22 namespace llvm {
23 
TEST_F(AttributorTestBase,TestCast)24 TEST_F(AttributorTestBase, TestCast) {
25   const char *ModuleString = R"(
26     define i32 @foo(i32 %a, i32 %b) {
27     entry:
28       %c = add i32 %a, %b
29       ret i32 %c
30     }
31   )";
32 
33   Module &M = parseModule(ModuleString);
34 
35   SetVector<Function *> Functions;
36   AnalysisGetter AG;
37   for (Function &F : M)
38     Functions.insert(&F);
39 
40   CallGraphUpdater CGUpdater;
41   BumpPtrAllocator Allocator;
42   InformationCache InfoCache(M, AG, Allocator, nullptr);
43   Attributor A(Functions, InfoCache, CGUpdater);
44 
45   Function *F = M.getFunction("foo");
46 
47   const AbstractAttribute *AA =
48       &A.getOrCreateAAFor<AAIsDead>(IRPosition::function(*F));
49 
50   EXPECT_TRUE(AA);
51 
52   const auto *SFail = dyn_cast<AAAlign>(AA);
53   const auto *SSucc = dyn_cast<AAIsDead>(AA);
54 
55   ASSERT_EQ(SFail, nullptr);
56   ASSERT_TRUE(SSucc);
57 }
58 
59 } // namespace llvm