From 23cc36e4765912a1bcdbbc3fb8b0976a06dea043 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 16 Jan 2023 11:00:01 -0500 Subject: [PATCH] llvm-reduce: Use consistent ReductionFunc types Some of these were relying on ReducerWorkItem's operator Module&. --- llvm/tools/llvm-reduce/ReducerWorkItem.h | 5 +++++ llvm/tools/llvm-reduce/TestRunner.cpp | 2 +- llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp | 4 ++-- llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp | 3 ++- llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp | 6 +++--- llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp | 9 +++++---- llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp | 9 +++++---- llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp | 4 ++-- llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp | 4 ++-- .../llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp | 4 ++-- llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp | 4 +++- .../tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp | 4 ++-- llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp | 3 ++- llvm/tools/llvm-reduce/deltas/ReduceInvokes.cpp | 4 ++-- .../tools/llvm-reduce/deltas/ReduceMemoryOperations.cpp | 13 +++++++------ llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp | 8 ++++++-- llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp | 12 +++++++----- llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp | 4 +++- llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp | 5 ++++- .../tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp | 17 +++++++++++++---- llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp | 3 ++- llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp | 3 ++- llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp | 3 ++- 29 files changed, 102 insertions(+), 55 deletions(-) diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.h b/llvm/tools/llvm-reduce/ReducerWorkItem.h index ec19e3a..45efaef 100644 --- a/llvm/tools/llvm-reduce/ReducerWorkItem.h +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.h @@ -26,6 +26,11 @@ public: bool isMIR() const { return MMI != nullptr; } + LLVMContext &getContext() { + return M->getContext(); + } + + Module &getModule() { return *M; } const Module &getModule() const { return *M; } void print(raw_ostream &ROS, void *p = nullptr) const; diff --git a/llvm/tools/llvm-reduce/TestRunner.cpp b/llvm/tools/llvm-reduce/TestRunner.cpp index 286eb2a..c8849de 100644 --- a/llvm/tools/llvm-reduce/TestRunner.cpp +++ b/llvm/tools/llvm-reduce/TestRunner.cpp @@ -91,7 +91,7 @@ void writeBitcode(const ReducerWorkItem &M, raw_ostream &OutStream) { Index = std::make_unique( buildModuleSummaryIndex(M, nullptr, &PSI)); } - WriteBitcodeToFile(M, OutStream, Index.get()); + WriteBitcodeToFile(M.getModule(), OutStream, Index.get()); } } diff --git a/llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp b/llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp index db5376f..d889b3e 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp @@ -22,8 +22,8 @@ using namespace llvm; /// Removes all aliases aren't inside any of the /// desired Chunks. -static void extractAliasesFromModule(Oracle &O, Module &Program) { - for (auto &GA : make_early_inc_range(Program.aliases())) { +static void extractAliasesFromModule(Oracle &O, ReducerWorkItem &Program) { + for (auto &GA : make_early_inc_range(Program.getModule().aliases())) { if (!O.shouldKeep()) { GA.replaceAllUsesWith(GA.getAliasee()); GA.eraseFromParent(); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp index e251256..10bbc64 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -56,7 +56,8 @@ static bool shouldRemoveArguments(const Function &F) { /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. -static void extractArgumentsFromModule(Oracle &O, Module &Program) { +static void extractArgumentsFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); std::vector InitArgsToKeep; std::vector Funcs; // Get inside-chunk arguments, as well as their parent function diff --git a/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp b/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp index 036f0fb..df87ce7 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp @@ -146,9 +146,9 @@ public: } // namespace /// Removes out-of-chunk attributes from module. -static void extractAttributesFromModule(Oracle &O, Module &Program) { - AttributeRemapper R(O, Program.getContext()); - R.visit(Program); +static void extractAttributesFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + AttributeRemapper R(O, WorkItem.getContext()); + R.visit(WorkItem.getModule()); } void llvm::reduceAttributesDeltaPass(TestRunner &Test) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp index cb518a9..6858dac 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -132,11 +132,11 @@ removeUninterestingBBsFromSwitch(SwitchInst &SwInst, /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. -static void extractBasicBlocksFromModule(Oracle &O, Module &Program) { +static void extractBasicBlocksFromModule(Oracle &O, ReducerWorkItem &WorkItem) { DenseSet BBsToDelete; df_iterator_default_set Reachable; - for (auto &F : Program) { + for (auto &F : WorkItem.getModule()) { if (F.empty()) continue; @@ -183,11 +183,12 @@ void llvm::reduceBasicBlocksDeltaPass(TestRunner &Test) { runDeltaPass(Test, extractBasicBlocksFromModule, "Reducing Basic Blocks"); } -static void removeUnreachableBasicBlocksFromModule(Oracle &O, Module &M) { +static void removeUnreachableBasicBlocksFromModule(Oracle &O, + ReducerWorkItem &WorkItem) { std::vector DeadBlocks; df_iterator_default_set Reachable; - for (Function &F : M) { + for (Function &F : WorkItem.getModule()) { if (F.empty()) continue; diff --git a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp index 6ae535f..1ac580b 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp @@ -78,7 +78,9 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) { } } -static void extractDIMetadataFromModule(Oracle &O, Module &Program) { +static void extractDIMetadataFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + MDNodeList MDs; // Collect all !dbg metadata attachments. for (const auto &DC : Program.debug_compile_units()) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp index 98a280f..21875ba 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp @@ -21,9 +21,10 @@ using namespace llvm; /// Removes all the bodies of defined functions that aren't inside any of the /// desired Chunks. -static void extractFunctionBodiesFromModule(Oracle &O, Module &Program) { +static void extractFunctionBodiesFromModule(Oracle &O, + ReducerWorkItem &WorkItem) { // Delete out-of-chunk function bodies - for (auto &F : Program) { + for (auto &F : WorkItem.getModule()) { if (!F.isDeclaration() && !hasAliasUse(F) && !O.shouldKeep()) { F.deleteBody(); F.setComdat(nullptr); @@ -36,8 +37,8 @@ void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) { "Reducing Function Bodies"); } -static void reduceFunctionData(Oracle &O, Module &M) { - for (Function &F : M) { +static void reduceFunctionData(Oracle &O, ReducerWorkItem &WorkItem) { + for (Function &F : WorkItem.getModule()) { if (F.hasPersonalityFn()) { if (none_of(F, [](const BasicBlock &BB) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp index 0c1ec50..05127ec 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp @@ -25,7 +25,9 @@ using namespace llvm; /// Removes all the Defined Functions /// that aren't inside any of the desired Chunks. -static void extractFunctionsFromModule(Oracle &O, Module &Program) { +static void extractFunctionsFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + // Record all out-of-chunk functions. SmallPtrSet FuncsToRemove; for (Function &F : Program.functions()) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp index 8677a72..1d1463a 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp @@ -19,8 +19,8 @@ static bool shouldReduceAlign(GlobalObject &GO) { static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); } -static void reduceGOs(Oracle &O, Module &Program) { - for (auto &GO : Program.global_objects()) { +static void reduceGOs(Oracle &O, ReducerWorkItem &Program) { + for (auto &GO : Program.getModule().global_objects()) { if (shouldReduceSection(GO) && !O.shouldKeep()) GO.setSection(""); if (shouldReduceAlign(GO) && !O.shouldKeep()) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp index eb0ea4e..470d5ba 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp @@ -37,8 +37,8 @@ static bool shouldReduceThreadLocal(GlobalValue &GV) { return GV.isThreadLocal(); } -static void reduceGVs(Oracle &O, Module &Program) { - for (auto &GV : Program.global_values()) { +static void reduceGVs(Oracle &O, ReducerWorkItem &Program) { + for (auto &GV : Program.getModule().global_values()) { if (shouldReduceDSOLocal(GV) && !O.shouldKeep()) GV.setDSOLocal(false); if (shouldReduceVisibility(GV) && !O.shouldKeep()) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp index 9765b38..4c71252 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.cpp @@ -18,9 +18,9 @@ using namespace llvm; /// Removes all the Initialized GVs that aren't inside the desired Chunks. -static void extractGVsFromModule(Oracle &O, Module &Program) { +static void extractGVsFromModule(Oracle &O, ReducerWorkItem &WorkItem) { // Drop initializers of out-of-chunk GVs - for (auto &GV : Program.globals()) + for (auto &GV : WorkItem.getModule().globals()) if (GV.hasInitializer() && !O.shouldKeep()) { GV.setInitializer(nullptr); GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp index 4e25c0c..b448081 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp @@ -23,7 +23,9 @@ static bool shouldAlwaysKeep(const GlobalVariable &GV) { } /// Removes all the GVs that aren't inside the desired Chunks. -static void extractGVsFromModule(Oracle &O, Module &Program) { +static void extractGVsFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + // Get GVs inside desired chunks std::vector InitGVsToKeep; for (auto &GV : Program.globals()) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp index 78bbaf9..e0f2517 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceInstructionFlags.cpp @@ -17,8 +17,8 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/Operator.h" -static void reduceFlagsInModule(Oracle &O, Module &Mod) { - for (Function &F : Mod) { +static void reduceFlagsInModule(Oracle &O, ReducerWorkItem &WorkItem) { + for (Function &F : WorkItem.getModule()) { for (Instruction &I : instructions(F)) { if (auto *OBO = dyn_cast(&I)) { if (OBO->hasNoSignedWrap() && !O.shouldKeep()) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp index 8dd9872..7dfe028 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp @@ -28,7 +28,8 @@ static bool shouldAlwaysKeep(const Instruction &I) { /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. -static void extractInstrFromModule(Oracle &O, Module &Program) { +static void extractInstrFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); std::vector InitInstToKeep; for (auto &F : Program) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInvokes.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInvokes.cpp index 7c7d94b..421108a 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceInvokes.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceInvokes.cpp @@ -27,8 +27,8 @@ static void reduceInvokesInFunction(Oracle &O, Function &F) { // reduction. } -static void reduceInvokesInModule(Oracle &O, Module &Mod) { - for (Function &F : Mod) { +static void reduceInvokesInModule(Oracle &O, ReducerWorkItem &WorkItem) { + for (Function &F : WorkItem.getModule()) { if (F.hasPersonalityFn()) reduceInvokesInFunction(O, F); } diff --git a/llvm/tools/llvm-reduce/deltas/ReduceMemoryOperations.cpp b/llvm/tools/llvm-reduce/deltas/ReduceMemoryOperations.cpp index b64b455..c1db344 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceMemoryOperations.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceMemoryOperations.cpp @@ -34,8 +34,8 @@ static void removeVolatileInFunction(Oracle &O, Function &F) { } } -static void removeVolatileInModule(Oracle &O, Module &Mod) { - for (Function &F : Mod) +static void removeVolatileInModule(Oracle &O, ReducerWorkItem &WorkItem) { + for (Function &F : WorkItem.getModule()) removeVolatileInFunction(O, F); } @@ -64,8 +64,9 @@ static void reduceAtomicSyncScopesInFunction(Oracle &O, Function &F) { } } -static void reduceAtomicSyncScopesInModule(Oracle &O, Module &Mod) { - for (Function &F : Mod) +static void reduceAtomicSyncScopesInModule(Oracle &O, + ReducerWorkItem &WorkItem) { + for (Function &F : WorkItem.getModule()) reduceAtomicSyncScopesInFunction(O, F); } @@ -97,8 +98,8 @@ static void reduceAtomicOrderingInFunction(Oracle &O, Function &F) { } } -static void reduceAtomicOrderingInModule(Oracle &O, Module &Mod) { - for (Function &F : Mod) +static void reduceAtomicOrderingInModule(Oracle &O, ReducerWorkItem &WorkItem) { + for (Function &F : WorkItem.getModule()) reduceAtomicOrderingInFunction(O, F); } diff --git a/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp b/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp index bec39ad..d491858 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp @@ -42,7 +42,9 @@ static constexpr StringLiteral ListNamedMetadata[] = { }; /// Remove unneeded arguments to named metadata. -static void reduceNamedMetadataOperands(Oracle &O, Module &M) { +static void reduceNamedMetadataOperands(Oracle &O, ReducerWorkItem &WorkItem) { + Module &M = WorkItem.getModule(); + for (StringRef MDName : ListNamedMetadata) { NamedMDNode *NamedNode = M.getNamedMetadata(MDName); if (!NamedNode) @@ -67,7 +69,9 @@ static void reduceNamedMetadataOperands(Oracle &O, Module &M) { /// Removes all the Named and Unnamed Metadata Nodes, as well as any debug /// functions that aren't inside the desired Chunks. -static void extractMetadataFromModule(Oracle &O, Module &Program) { +static void extractMetadataFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + // Get out-of-chunk Named metadata nodes SmallVector NamedNodesToDelete; for (NamedMDNode &MD : Program.named_metadata()) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp index 7c31437..17930ab 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceModuleData.cpp @@ -14,7 +14,9 @@ using namespace llvm; -static void clearModuleData(Oracle &O, Module &Program) { +static void clearModuleData(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + if (!Program.getModuleIdentifier().empty() && !O.shouldKeep()) Program.setModuleIdentifier(""); if (!Program.getSourceFileName().empty() && !O.shouldKeep()) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp index 4acc77b..77131008 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp @@ -253,7 +253,9 @@ static Value *reduceInstruction(Oracle &O, Module &M, Instruction &I) { return nullptr; } -static void replaceOpcodesInModule(Oracle &O, Module &Mod) { +static void replaceOpcodesInModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Mod = WorkItem.getModule(); + for (Function &F : Mod) { for (BasicBlock &BB : F) for (Instruction &I : make_early_inc_range(BB)) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp index 0998d6b..6f9cafb 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp @@ -95,7 +95,9 @@ static void maybeRewriteCallWithDifferentBundles( } /// Removes out-of-chunk operand bundles from calls. -static void extractOperandBundesFromModule(Oracle &O, Module &Program) { +static void extractOperandBundesFromModule(Oracle &O, + ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); OperandBundleRemapper R(O); R.visit(Program); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp index 98d068f..6bf84f2 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp @@ -18,8 +18,10 @@ using namespace llvm; using namespace PatternMatch; static void -extractOperandsFromModule(Oracle &O, Module &Program, +extractOperandsFromModule(Oracle &O, ReducerWorkItem &WorkItem, function_ref ReduceValue) { + Module &Program = WorkItem.getModule(); + for (auto &F : Program.functions()) { for (auto &I : instructions(&F)) { if (PHINode *Phi = dyn_cast(&I)) { @@ -118,8 +120,8 @@ void llvm::reduceOperandsOneDeltaPass(TestRunner &Test) { }; runDeltaPass( Test, - [ReduceValue](Oracle &O, Module &Program) { - extractOperandsFromModule(O, Program, ReduceValue); + [ReduceValue](Oracle &O, ReducerWorkItem &WorkItem) { + extractOperandsFromModule(O, WorkItem, ReduceValue); }, "Reducing Operands to one"); } @@ -137,7 +139,7 @@ void llvm::reduceOperandsZeroDeltaPass(TestRunner &Test) { }; runDeltaPass( Test, - [ReduceValue](Oracle &O, Module &Program) { + [ReduceValue](Oracle &O, ReducerWorkItem &Program) { extractOperandsFromModule(O, Program, ReduceValue); }, "Reducing Operands to zero"); @@ -165,7 +167,7 @@ void llvm::reduceOperandsNaNDeltaPass(TestRunner &Test) { }; runDeltaPass( Test, - [ReduceValue](Oracle &O, Module &Program) { + [ReduceValue](Oracle &O, ReducerWorkItem &Program) { extractOperandsFromModule(O, Program, ReduceValue); }, "Reducing Operands to NaN"); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp index 8120bfa..a634c3a 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp @@ -187,7 +187,9 @@ opportunities(Function &F, } } -static void extractOperandsFromModule(Oracle &O, Module &Program) { +static void extractOperandsFromModule(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + for (Function &F : Program.functions()) { SmallVector> Replacements; opportunities(F, [&](Use &Op, ArrayRef Candidates) { diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp index c77cccb..0f949ab 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp @@ -173,7 +173,9 @@ static void substituteOperandWithArgument(Function *OldF, NewF->setName(FName); } -static void reduceOperandsToArgs(Oracle &O, Module &Program) { +static void reduceOperandsToArgs(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + SmallVector OperandsToReduce; for (Function &F : make_early_inc_range(Program.functions())) { if (!canReplaceFunction(&F)) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp b/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp index 0e35695..5b124a4 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceSpecialGlobals.cpp @@ -27,7 +27,10 @@ static StringRef SpecialGlobalNames[] = {"llvm.used", "llvm.compiler.used"}; /// Removes all special globals aren't inside any of the /// desired Chunks. -static void extractSpecialGlobalsFromModule(Oracle &O, Module &Program) { +static void extractSpecialGlobalsFromModule(Oracle &O, + ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); + for (StringRef Name : SpecialGlobalNames) { if (auto *Used = Program.getNamedGlobal(Name)) { Used->replaceAllUsesWith(getDefaultValue(Used->getType())); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp index 416b165..c49fcb9 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceUsingSimplifyCFG.cpp @@ -19,7 +19,8 @@ using namespace llvm; -static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) { +static void reduceUsingSimplifyCFG(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); SmallVector ToSimplify; for (auto &F : Program) for (auto &BB : F) @@ -33,7 +34,9 @@ static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) { void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) { runDeltaPass(Test, reduceUsingSimplifyCFG, "Reducing using SimplifyCFG"); } -static void reduceConditionals(Oracle &O, Module &M, bool Direction) { +static void reduceConditionals(Oracle &O, ReducerWorkItem &WorkItem, + bool Direction) { + Module &M = WorkItem.getModule(); SmallVector ToSimplify; for (auto &F : M) { @@ -58,12 +61,18 @@ static void reduceConditionals(Oracle &O, Module &M, bool Direction) { void llvm::reduceConditionalsTrueDeltaPass(TestRunner &Test) { runDeltaPass( - Test, [](Oracle &O, Module &M) { reduceConditionals(O, M, true); }, + Test, + [](Oracle &O, ReducerWorkItem &WorkItem) { + reduceConditionals(O, WorkItem, true); + }, "Reducing conditional branches to true"); } void llvm::reduceConditionalsFalseDeltaPass(TestRunner &Test) { runDeltaPass( - Test, [](Oracle &O, Module &M) { reduceConditionals(O, M, false); }, + Test, + [](Oracle &O, ReducerWorkItem &WorkItem) { + reduceConditionals(O, WorkItem, false); + }, "Reducing conditional branches to false"); } diff --git a/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp b/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp index 30fe6a8..acef29a 100644 --- a/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp +++ b/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp @@ -23,7 +23,8 @@ static cl::opt PassPipeline( cl::init("function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces)"), cl::cat(LLVMReduceOptions)); -static void runPasses(Oracle &O, Module &Program) { +static void runPasses(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); LoopAnalysisManager LAM; FunctionAnalysisManager FAM; CGSCCAnalysisManager CGAM; diff --git a/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp b/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp index 93556b7..fc21593 100644 --- a/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp +++ b/llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp @@ -19,9 +19,10 @@ using namespace llvm; /// Calls simplifyInstruction in each instruction in functions, and replaces /// their values. -static void extractInstrFromModule(Oracle &O, Module &Program) { +static void extractInstrFromModule(Oracle &O, ReducerWorkItem &WorkItem) { std::vector InstsToDelete; + Module &Program = WorkItem.getModule(); const DataLayout &DL = Program.getDataLayout(); std::vector InstToDelete; diff --git a/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp b/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp index efb0233..a65e55d 100644 --- a/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp +++ b/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp @@ -15,7 +15,8 @@ using namespace llvm; /// Removes all aliases aren't inside any of the /// desired Chunks. -static void stripDebugInfoImpl(Oracle &O, Module &Program) { +static void stripDebugInfoImpl(Oracle &O, ReducerWorkItem &WorkItem) { + Module &Program = WorkItem.getModule(); bool HasDebugInfo = any_of(Program.named_metadata(), [](NamedMDNode &NMD) { return NMD.getName().startswith("llvm.dbg."); }); -- 2.7.4