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