Skip to content

Commit 815b7c3

Browse files
Add unittest to improve test coverage for SelectionDAG::getNode().
It is easier to validate the undef/poison behaviour by probing getNode directly rather than relying on llc tests.
1 parent 7057eee commit 815b7c3

File tree

5 files changed

+405
-185
lines changed

5 files changed

+405
-185
lines changed

llvm/unittests/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_llvm_unittest(CodeGenTests
4242
ScalableVectorMVTsTest.cpp
4343
SchedBoundary.cpp
4444
SelectionDAGAddressAnalysisTest.cpp
45+
SelectionDAGNodeConstructionTest.cpp
4546
SelectionDAGPatternMatchTest.cpp
4647
TypeTraitsTest.cpp
4748
TargetOptionsTest.cpp

llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp

Lines changed: 2 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -7,103 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/CodeGen/SelectionDAGAddressAnalysis.h"
10+
#include "SelectionDAGTestBase.h"
1011
#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"
2312

2413
namespace llvm {
2514

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 {};
10716

10817
TEST_F(SelectionDAGAddressAnalysisTest, sameFrameObject) {
10918
SDLoc Loc;

0 commit comments

Comments
 (0)