1*82d56013Sjoerg //===- DeltaManager.cpp - Runs Delta Passes to reduce Input ---------------===//
2*82d56013Sjoerg //
3*82d56013Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*82d56013Sjoerg // See https://llvm.org/LICENSE.txt for license information.
5*82d56013Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*82d56013Sjoerg //
7*82d56013Sjoerg //===----------------------------------------------------------------------===//
8*82d56013Sjoerg //
9*82d56013Sjoerg // This file calls each specialized Delta pass in order to reduce the input IR
10*82d56013Sjoerg // file.
11*82d56013Sjoerg //
12*82d56013Sjoerg //===----------------------------------------------------------------------===//
13*82d56013Sjoerg
14*82d56013Sjoerg #include "DeltaManager.h"
15*82d56013Sjoerg #include "TestRunner.h"
16*82d56013Sjoerg #include "deltas/Delta.h"
17*82d56013Sjoerg #include "deltas/ReduceAliases.h"
18*82d56013Sjoerg #include "deltas/ReduceArguments.h"
19*82d56013Sjoerg #include "deltas/ReduceAttributes.h"
20*82d56013Sjoerg #include "deltas/ReduceBasicBlocks.h"
21*82d56013Sjoerg #include "deltas/ReduceFunctionBodies.h"
22*82d56013Sjoerg #include "deltas/ReduceFunctions.h"
23*82d56013Sjoerg #include "deltas/ReduceGlobalValues.h"
24*82d56013Sjoerg #include "deltas/ReduceGlobalVarInitializers.h"
25*82d56013Sjoerg #include "deltas/ReduceGlobalVars.h"
26*82d56013Sjoerg #include "deltas/ReduceInstructions.h"
27*82d56013Sjoerg #include "deltas/ReduceMetadata.h"
28*82d56013Sjoerg #include "deltas/ReduceModuleInlineAsm.h"
29*82d56013Sjoerg #include "deltas/ReduceOperandBundles.h"
30*82d56013Sjoerg #include "deltas/ReduceSpecialGlobals.h"
31*82d56013Sjoerg #include "llvm/Support/CommandLine.h"
32*82d56013Sjoerg
33*82d56013Sjoerg using namespace llvm;
34*82d56013Sjoerg
35*82d56013Sjoerg static cl::opt<std::string>
36*82d56013Sjoerg DeltaPasses("delta-passes",
37*82d56013Sjoerg cl::desc("Delta passes to run, separated by commas. By "
38*82d56013Sjoerg "default, run all delta passes."));
39*82d56013Sjoerg
40*82d56013Sjoerg #define DELTA_PASSES \
41*82d56013Sjoerg DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass) \
42*82d56013Sjoerg DELTA_PASS("aliases", reduceAliasesDeltaPass) \
43*82d56013Sjoerg DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass) \
44*82d56013Sjoerg DELTA_PASS("functions", reduceFunctionsDeltaPass) \
45*82d56013Sjoerg DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) \
46*82d56013Sjoerg DELTA_PASS("global-values", reduceGlobalValuesDeltaPass) \
47*82d56013Sjoerg DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass) \
48*82d56013Sjoerg DELTA_PASS("global-variables", reduceGlobalsDeltaPass) \
49*82d56013Sjoerg DELTA_PASS("metadata", reduceMetadataDeltaPass) \
50*82d56013Sjoerg DELTA_PASS("arguments", reduceArgumentsDeltaPass) \
51*82d56013Sjoerg DELTA_PASS("instructions", reduceInstructionsDeltaPass) \
52*82d56013Sjoerg DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \
53*82d56013Sjoerg DELTA_PASS("attributes", reduceAttributesDeltaPass) \
54*82d56013Sjoerg DELTA_PASS("module-inline-asm", reduceModuleInlineAsmDeltaPass)
55*82d56013Sjoerg
runAllDeltaPasses(TestRunner & Tester)56*82d56013Sjoerg static void runAllDeltaPasses(TestRunner &Tester) {
57*82d56013Sjoerg #define DELTA_PASS(NAME, FUNC) FUNC(Tester);
58*82d56013Sjoerg DELTA_PASSES
59*82d56013Sjoerg #undef DELTA_PASS
60*82d56013Sjoerg }
61*82d56013Sjoerg
runDeltaPassName(TestRunner & Tester,StringRef PassName)62*82d56013Sjoerg static void runDeltaPassName(TestRunner &Tester, StringRef PassName) {
63*82d56013Sjoerg #define DELTA_PASS(NAME, FUNC) \
64*82d56013Sjoerg if (PassName == NAME) { \
65*82d56013Sjoerg FUNC(Tester); \
66*82d56013Sjoerg return; \
67*82d56013Sjoerg }
68*82d56013Sjoerg DELTA_PASSES
69*82d56013Sjoerg #undef DELTA_PASS
70*82d56013Sjoerg errs() << "unknown pass \"" << PassName << "\"";
71*82d56013Sjoerg exit(1);
72*82d56013Sjoerg }
73*82d56013Sjoerg
printDeltaPasses(raw_ostream & OS)74*82d56013Sjoerg void llvm::printDeltaPasses(raw_ostream &OS) {
75*82d56013Sjoerg OS << "Delta passes (pass to `--delta-passes=` as a comma separated list):\n";
76*82d56013Sjoerg #define DELTA_PASS(NAME, FUNC) OS << " " << NAME << "\n";
77*82d56013Sjoerg DELTA_PASSES
78*82d56013Sjoerg #undef DELTA_PASS
79*82d56013Sjoerg }
80*82d56013Sjoerg
runDeltaPasses(TestRunner & Tester)81*82d56013Sjoerg void llvm::runDeltaPasses(TestRunner &Tester) {
82*82d56013Sjoerg if (DeltaPasses.empty()) {
83*82d56013Sjoerg runAllDeltaPasses(Tester);
84*82d56013Sjoerg } else {
85*82d56013Sjoerg StringRef Passes = DeltaPasses;
86*82d56013Sjoerg while (!Passes.empty()) {
87*82d56013Sjoerg auto Split = Passes.split(",");
88*82d56013Sjoerg runDeltaPassName(Tester, Split.first);
89*82d56013Sjoerg Passes = Split.second;
90*82d56013Sjoerg }
91*82d56013Sjoerg }
92*82d56013Sjoerg }
93