|
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | 9 | #include "llvm/CodeGen/SelectionDAGAddressAnalysis.h" |
| 10 | +#include "SelectionDAGTestBase.h" |
10 | 11 | #include "llvm/Analysis/MemoryLocation.h" |
11 | | -#include "llvm/Analysis/OptimizationRemarkEmitter.h" |
12 | | -#include "llvm/Analysis/TargetTransformInfo.h" |
13 | | -#include "llvm/AsmParser/Parser.h" |
14 | | -#include "llvm/CodeGen/MachineModuleInfo.h" |
15 | | -#include "llvm/CodeGen/SelectionDAG.h" |
16 | | -#include "llvm/CodeGen/TargetLowering.h" |
17 | | -#include "llvm/IR/Module.h" |
18 | | -#include "llvm/MC/TargetRegistry.h" |
19 | | -#include "llvm/Support/SourceMgr.h" |
20 | | -#include "llvm/Support/TargetSelect.h" |
21 | | -#include "llvm/Target/TargetMachine.h" |
22 | | -#include "gtest/gtest.h" |
23 | 12 |
|
24 | 13 | namespace llvm { |
25 | 14 |
|
26 | | -class SelectionDAGAddressAnalysisTest : public testing::Test { |
27 | | -protected: |
28 | | - static void SetUpTestCase() { |
29 | | - InitializeAllTargets(); |
30 | | - InitializeAllTargetMCs(); |
31 | | - } |
32 | | - |
33 | | - void SetUp() override { |
34 | | - StringRef Assembly = "@g = global i32 0\n" |
35 | | - "@g_alias = alias i32, i32* @g\n" |
36 | | - "define i32 @f() {\n" |
37 | | - " %1 = load i32, i32* @g\n" |
38 | | - " ret i32 %1\n" |
39 | | - "}"; |
40 | | - |
41 | | - Triple TargetTriple("aarch64--"); |
42 | | - std::string Error; |
43 | | - const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error); |
44 | | - // FIXME: These tests do not depend on AArch64 specifically, but we have to |
45 | | - // initialize a target. A skeleton Target for unittests would allow us to |
46 | | - // always run these tests. |
47 | | - if (!T) |
48 | | - GTEST_SKIP(); |
49 | | - |
50 | | - TargetOptions Options; |
51 | | - TM = std::unique_ptr<TargetMachine>( |
52 | | - T->createTargetMachine(TargetTriple, "", "+sve", Options, std::nullopt, |
53 | | - std::nullopt, CodeGenOptLevel::Aggressive)); |
54 | | - if (!TM) |
55 | | - GTEST_SKIP(); |
56 | | - |
57 | | - SMDiagnostic SMError; |
58 | | - M = parseAssemblyString(Assembly, SMError, Context); |
59 | | - if (!M) |
60 | | - report_fatal_error(SMError.getMessage()); |
61 | | - M->setDataLayout(TM->createDataLayout()); |
62 | | - |
63 | | - F = M->getFunction("f"); |
64 | | - if (!F) |
65 | | - report_fatal_error("F?"); |
66 | | - G = M->getGlobalVariable("g"); |
67 | | - if (!G) |
68 | | - report_fatal_error("G?"); |
69 | | - AliasedG = M->getNamedAlias("g_alias"); |
70 | | - if (!AliasedG) |
71 | | - report_fatal_error("AliasedG?"); |
72 | | - |
73 | | - MachineModuleInfo MMI(TM.get()); |
74 | | - |
75 | | - MF = std::make_unique<MachineFunction>(*F, *TM, *TM->getSubtargetImpl(*F), |
76 | | - MMI.getContext(), 0); |
77 | | - |
78 | | - DAG = std::make_unique<SelectionDAG>(*TM, CodeGenOptLevel::None); |
79 | | - if (!DAG) |
80 | | - report_fatal_error("DAG?"); |
81 | | - OptimizationRemarkEmitter ORE(F); |
82 | | - FunctionAnalysisManager FAM; |
83 | | - FAM.registerPass([&] { return TM->getTargetIRAnalysis(); }); |
84 | | - |
85 | | - TargetTransformInfo TTI = TM->getTargetIRAnalysis().run(*F, FAM); |
86 | | - DAG->init(*MF, ORE, nullptr, nullptr, nullptr, nullptr, nullptr, MMI, |
87 | | - nullptr, TTI.hasBranchDivergence(F)); |
88 | | - } |
89 | | - |
90 | | - TargetLoweringBase::LegalizeTypeAction getTypeAction(EVT VT) { |
91 | | - return DAG->getTargetLoweringInfo().getTypeAction(Context, VT); |
92 | | - } |
93 | | - |
94 | | - EVT getTypeToTransformTo(EVT VT) { |
95 | | - return DAG->getTargetLoweringInfo().getTypeToTransformTo(Context, VT); |
96 | | - } |
97 | | - |
98 | | - LLVMContext Context; |
99 | | - std::unique_ptr<TargetMachine> TM; |
100 | | - std::unique_ptr<Module> M; |
101 | | - Function *F; |
102 | | - GlobalVariable *G; |
103 | | - GlobalAlias *AliasedG; |
104 | | - std::unique_ptr<MachineFunction> MF; |
105 | | - std::unique_ptr<SelectionDAG> DAG; |
106 | | -}; |
| 15 | +class SelectionDAGAddressAnalysisTest : public SelectionDAGTestBase {}; |
107 | 16 |
|
108 | 17 | TEST_F(SelectionDAGAddressAnalysisTest, sameFrameObject) { |
109 | 18 | SDLoc Loc; |
|
0 commit comments