Jlm
Loading...
Searching...
No Matches
JlcCommandGraphGeneratorTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#include <gtest/gtest.h>
7
11
12#include <cassert>
13
14TEST(JlcCommandGraphGeneratorTests, TestJlcCompiling)
15{
16 using namespace jlm::tooling;
17 using namespace jlm::util;
18
19 // Arrange
20 JlcCommandLineOptions commandLineOptions;
21 commandLineOptions.Compilations_.push_back({ FilePath("foo.c"),
22 FilePath("foo.d"),
23 FilePath("foo.o"),
24 "foo.o",
25 true,
26 true,
27 true,
28 false });
29
30 // Act
31 auto commandGraph = JlcCommandGraphGenerator::Generate(commandLineOptions);
32
33 // Assert
34 EXPECT_EQ(commandGraph->NumNodes(), 5u);
35 auto & commandNode = commandGraph->GetExitNode().IncomingEdges().begin()->GetSource();
36 auto command = dynamic_cast<const LlcCommand *>(&commandNode.GetCommand());
37 EXPECT_NE(command, nullptr);
38 EXPECT_EQ(command->OutputFile(), "foo.o");
39}
40
41TEST(JlcCommandGraphGeneratorTests, TestJlcLinking)
42{
43 using namespace jlm::tooling;
44 using namespace jlm::util;
45
46 // Arrange
47 JlcCommandLineOptions commandLineOptions;
48 commandLineOptions.Compilations_.push_back(
49 { FilePath("foo.o"), FilePath(""), FilePath("foo.o"), "foo.o", false, false, false, true });
50 commandLineOptions.OutputFile_ = FilePath("foobar");
51
52 // Act
53 auto commandGraph = JlcCommandGraphGenerator::Generate(commandLineOptions);
54
55 // Assert
56 EXPECT_EQ(commandGraph->NumNodes(), 3u);
57 auto & commandNode = commandGraph->GetExitNode().IncomingEdges().begin()->GetSource();
58 auto command = dynamic_cast<const ClangCommand *>(&commandNode.GetCommand());
59 EXPECT_EQ(command->InputFiles()[0], "foo.o");
60 EXPECT_EQ(command->OutputFile(), "foobar");
61}
62
63TEST(JlcCommandGraphGeneratorTests, TestJlmOptOptimizations)
64{
65 using namespace jlm::tooling;
66 using namespace jlm::util;
67
68 // Arrange
69 JlcCommandLineOptions commandLineOptions;
70 commandLineOptions.Compilations_.push_back(
71 { FilePath("foo.o"), FilePath(""), FilePath("foo.o"), "foo.o", true, true, true, true });
72 commandLineOptions.OutputFile_ = FilePath("foobar");
73 commandLineOptions.JlmOptOptimizations_.push_back(
74 JlmOptCommandLineOptions::OptimizationId::CommonNodeElimination);
75 commandLineOptions.JlmOptOptimizations_.push_back(
76 JlmOptCommandLineOptions::OptimizationId::DeadNodeElimination);
77
78 // Act
79 auto commandGraph = JlcCommandGraphGenerator::Generate(commandLineOptions);
80
81 // Assert
82 auto & clangCommandNode = commandGraph->GetEntryNode().OutgoingEdges().begin()->GetSink();
83 auto & jlmOptCommandNode = clangCommandNode.OutgoingEdges().begin()->GetSink();
84 auto & jlmOptCommand = *dynamic_cast<const JlmOptCommand *>(&jlmOptCommandNode.GetCommand());
85 auto & optimizations = jlmOptCommand.GetCommandLineOptions().GetOptimizationIds();
86
87 EXPECT_EQ(optimizations.size(), 2u);
88 EXPECT_EQ(optimizations[0], JlmOptCommandLineOptions::OptimizationId::CommonNodeElimination);
89 EXPECT_EQ(optimizations[1], JlmOptCommandLineOptions::OptimizationId::DeadNodeElimination);
90}
91
92TEST(JlcCommandGraphGeneratorTests, TestJlmOptStatistics)
93{
94 using namespace jlm::util;
95
96 // Arrange
97 HashSet<Statistics::Id> expectedStatistics(
98 { Statistics::Id::Aggregation, Statistics::Id::AndersenAnalysis });
99
100 jlm::tooling::JlcCommandLineOptions commandLineOptions;
101 commandLineOptions.Compilations_.push_back(
102 { FilePath("foo.o"), FilePath(""), FilePath("foo.o"), "foo.o", true, true, true, true });
103 commandLineOptions.OutputFile_ = FilePath("foobar");
104 commandLineOptions.JlmOptPassStatistics_ = expectedStatistics;
105
106 // Act
107 auto commandGraph = jlm::tooling::JlcCommandGraphGenerator::Generate(commandLineOptions);
108
109 // Assert
110 auto & clangCommandNode = commandGraph->GetEntryNode().OutgoingEdges().begin()->GetSink();
111 auto & jlmOptCommandNode = clangCommandNode.OutgoingEdges().begin()->GetSink();
112 auto & jlmOptCommand =
113 *dynamic_cast<const jlm::tooling::JlmOptCommand *>(&jlmOptCommandNode.GetCommand());
114 auto & statisticsCollectorSettings =
116
117 EXPECT_EQ(statisticsCollectorSettings.GetDemandedStatistics(), expectedStatistics);
118}
TEST(JlcCommandGraphGeneratorTests, TestJlcCompiling)
static std::unique_ptr< CommandGraph > Generate(const JlcCommandLineOptions &commandLineOptions)
std::vector< Compilation > Compilations_
std::vector< JlmOptCommandLineOptions::OptimizationId > JlmOptOptimizations_
const util::StatisticsCollectorSettings & GetStatisticsCollectorSettings() const noexcept
const std::vector< OptimizationId > & GetOptimizationIds() const noexcept
const JlmOptCommandLineOptions & GetCommandLineOptions() const noexcept
Definition Command.hpp:362