mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-01 22:46:06 +00:00
llvm-reduce: Use consistent ReductionFunc types
Some of these were relying on ReducerWorkItem's operator Module&.
This commit is contained in:
parent
60834105d8
commit
23cc36e476
@ -26,6 +26,11 @@ public:
|
|||||||
|
|
||||||
bool isMIR() const { return MMI != nullptr; }
|
bool isMIR() const { return MMI != nullptr; }
|
||||||
|
|
||||||
|
LLVMContext &getContext() {
|
||||||
|
return M->getContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
Module &getModule() { return *M; }
|
||||||
const Module &getModule() const { return *M; }
|
const Module &getModule() const { return *M; }
|
||||||
|
|
||||||
void print(raw_ostream &ROS, void *p = nullptr) const;
|
void print(raw_ostream &ROS, void *p = nullptr) const;
|
||||||
|
@ -91,7 +91,7 @@ void writeBitcode(const ReducerWorkItem &M, raw_ostream &OutStream) {
|
|||||||
Index = std::make_unique<ModuleSummaryIndex>(
|
Index = std::make_unique<ModuleSummaryIndex>(
|
||||||
buildModuleSummaryIndex(M, nullptr, &PSI));
|
buildModuleSummaryIndex(M, nullptr, &PSI));
|
||||||
}
|
}
|
||||||
WriteBitcodeToFile(M, OutStream, Index.get());
|
WriteBitcodeToFile(M.getModule(), OutStream, Index.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Removes all aliases aren't inside any of the
|
/// Removes all aliases aren't inside any of the
|
||||||
/// desired Chunks.
|
/// desired Chunks.
|
||||||
static void extractAliasesFromModule(Oracle &O, Module &Program) {
|
static void extractAliasesFromModule(Oracle &O, ReducerWorkItem &Program) {
|
||||||
for (auto &GA : make_early_inc_range(Program.aliases())) {
|
for (auto &GA : make_early_inc_range(Program.getModule().aliases())) {
|
||||||
if (!O.shouldKeep()) {
|
if (!O.shouldKeep()) {
|
||||||
GA.replaceAllUsesWith(GA.getAliasee());
|
GA.replaceAllUsesWith(GA.getAliasee());
|
||||||
GA.eraseFromParent();
|
GA.eraseFromParent();
|
||||||
|
@ -56,7 +56,8 @@ static bool shouldRemoveArguments(const Function &F) {
|
|||||||
|
|
||||||
/// Removes out-of-chunk arguments from functions, and modifies their calls
|
/// Removes out-of-chunk arguments from functions, and modifies their calls
|
||||||
/// accordingly. It also removes allocations of out-of-chunk arguments.
|
/// 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<Argument *> InitArgsToKeep;
|
std::vector<Argument *> InitArgsToKeep;
|
||||||
std::vector<Function *> Funcs;
|
std::vector<Function *> Funcs;
|
||||||
// Get inside-chunk arguments, as well as their parent function
|
// Get inside-chunk arguments, as well as their parent function
|
||||||
|
@ -146,9 +146,9 @@ public:
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
/// Removes out-of-chunk attributes from module.
|
/// Removes out-of-chunk attributes from module.
|
||||||
static void extractAttributesFromModule(Oracle &O, Module &Program) {
|
static void extractAttributesFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
AttributeRemapper R(O, Program.getContext());
|
AttributeRemapper R(O, WorkItem.getContext());
|
||||||
R.visit(Program);
|
R.visit(WorkItem.getModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm::reduceAttributesDeltaPass(TestRunner &Test) {
|
void llvm::reduceAttributesDeltaPass(TestRunner &Test) {
|
||||||
|
@ -132,11 +132,11 @@ removeUninterestingBBsFromSwitch(SwitchInst &SwInst,
|
|||||||
|
|
||||||
/// Removes out-of-chunk arguments from functions, and modifies their calls
|
/// Removes out-of-chunk arguments from functions, and modifies their calls
|
||||||
/// accordingly. It also removes allocations of out-of-chunk arguments.
|
/// 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<BasicBlock *> BBsToDelete;
|
DenseSet<BasicBlock *> BBsToDelete;
|
||||||
df_iterator_default_set<BasicBlock *> Reachable;
|
df_iterator_default_set<BasicBlock *> Reachable;
|
||||||
|
|
||||||
for (auto &F : Program) {
|
for (auto &F : WorkItem.getModule()) {
|
||||||
if (F.empty())
|
if (F.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -183,11 +183,12 @@ void llvm::reduceBasicBlocksDeltaPass(TestRunner &Test) {
|
|||||||
runDeltaPass(Test, extractBasicBlocksFromModule, "Reducing Basic Blocks");
|
runDeltaPass(Test, extractBasicBlocksFromModule, "Reducing Basic Blocks");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void removeUnreachableBasicBlocksFromModule(Oracle &O, Module &M) {
|
static void removeUnreachableBasicBlocksFromModule(Oracle &O,
|
||||||
|
ReducerWorkItem &WorkItem) {
|
||||||
std::vector<BasicBlock *> DeadBlocks;
|
std::vector<BasicBlock *> DeadBlocks;
|
||||||
df_iterator_default_set<BasicBlock *> Reachable;
|
df_iterator_default_set<BasicBlock *> Reachable;
|
||||||
|
|
||||||
for (Function &F : M) {
|
for (Function &F : WorkItem.getModule()) {
|
||||||
if (F.empty())
|
if (F.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -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;
|
MDNodeList MDs;
|
||||||
// Collect all !dbg metadata attachments.
|
// Collect all !dbg metadata attachments.
|
||||||
for (const auto &DC : Program.debug_compile_units())
|
for (const auto &DC : Program.debug_compile_units())
|
||||||
|
@ -21,9 +21,10 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Removes all the bodies of defined functions that aren't inside any of the
|
/// Removes all the bodies of defined functions that aren't inside any of the
|
||||||
/// desired Chunks.
|
/// desired Chunks.
|
||||||
static void extractFunctionBodiesFromModule(Oracle &O, Module &Program) {
|
static void extractFunctionBodiesFromModule(Oracle &O,
|
||||||
|
ReducerWorkItem &WorkItem) {
|
||||||
// Delete out-of-chunk function bodies
|
// Delete out-of-chunk function bodies
|
||||||
for (auto &F : Program) {
|
for (auto &F : WorkItem.getModule()) {
|
||||||
if (!F.isDeclaration() && !hasAliasUse(F) && !O.shouldKeep()) {
|
if (!F.isDeclaration() && !hasAliasUse(F) && !O.shouldKeep()) {
|
||||||
F.deleteBody();
|
F.deleteBody();
|
||||||
F.setComdat(nullptr);
|
F.setComdat(nullptr);
|
||||||
@ -36,8 +37,8 @@ void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
|
|||||||
"Reducing Function Bodies");
|
"Reducing Function Bodies");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduceFunctionData(Oracle &O, Module &M) {
|
static void reduceFunctionData(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
for (Function &F : M) {
|
for (Function &F : WorkItem.getModule()) {
|
||||||
if (F.hasPersonalityFn()) {
|
if (F.hasPersonalityFn()) {
|
||||||
if (none_of(F,
|
if (none_of(F,
|
||||||
[](const BasicBlock &BB) {
|
[](const BasicBlock &BB) {
|
||||||
|
@ -25,7 +25,9 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Removes all the Defined Functions
|
/// Removes all the Defined Functions
|
||||||
/// that aren't inside any of the desired Chunks.
|
/// 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.
|
// Record all out-of-chunk functions.
|
||||||
SmallPtrSet<Constant *, 8> FuncsToRemove;
|
SmallPtrSet<Constant *, 8> FuncsToRemove;
|
||||||
for (Function &F : Program.functions()) {
|
for (Function &F : Program.functions()) {
|
||||||
|
@ -19,8 +19,8 @@ static bool shouldReduceAlign(GlobalObject &GO) {
|
|||||||
|
|
||||||
static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); }
|
static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); }
|
||||||
|
|
||||||
static void reduceGOs(Oracle &O, Module &Program) {
|
static void reduceGOs(Oracle &O, ReducerWorkItem &Program) {
|
||||||
for (auto &GO : Program.global_objects()) {
|
for (auto &GO : Program.getModule().global_objects()) {
|
||||||
if (shouldReduceSection(GO) && !O.shouldKeep())
|
if (shouldReduceSection(GO) && !O.shouldKeep())
|
||||||
GO.setSection("");
|
GO.setSection("");
|
||||||
if (shouldReduceAlign(GO) && !O.shouldKeep())
|
if (shouldReduceAlign(GO) && !O.shouldKeep())
|
||||||
|
@ -37,8 +37,8 @@ static bool shouldReduceThreadLocal(GlobalValue &GV) {
|
|||||||
return GV.isThreadLocal();
|
return GV.isThreadLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduceGVs(Oracle &O, Module &Program) {
|
static void reduceGVs(Oracle &O, ReducerWorkItem &Program) {
|
||||||
for (auto &GV : Program.global_values()) {
|
for (auto &GV : Program.getModule().global_values()) {
|
||||||
if (shouldReduceDSOLocal(GV) && !O.shouldKeep())
|
if (shouldReduceDSOLocal(GV) && !O.shouldKeep())
|
||||||
GV.setDSOLocal(false);
|
GV.setDSOLocal(false);
|
||||||
if (shouldReduceVisibility(GV) && !O.shouldKeep()) {
|
if (shouldReduceVisibility(GV) && !O.shouldKeep()) {
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
/// Removes all the Initialized GVs that aren't inside the desired Chunks.
|
/// 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
|
// Drop initializers of out-of-chunk GVs
|
||||||
for (auto &GV : Program.globals())
|
for (auto &GV : WorkItem.getModule().globals())
|
||||||
if (GV.hasInitializer() && !O.shouldKeep()) {
|
if (GV.hasInitializer() && !O.shouldKeep()) {
|
||||||
GV.setInitializer(nullptr);
|
GV.setInitializer(nullptr);
|
||||||
GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage);
|
GV.setLinkage(GlobalValue::LinkageTypes::ExternalLinkage);
|
||||||
|
@ -23,7 +23,9 @@ static bool shouldAlwaysKeep(const GlobalVariable &GV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Removes all the GVs that aren't inside the desired Chunks.
|
/// 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
|
// Get GVs inside desired chunks
|
||||||
std::vector<Constant *> InitGVsToKeep;
|
std::vector<Constant *> InitGVsToKeep;
|
||||||
for (auto &GV : Program.globals()) {
|
for (auto &GV : Program.globals()) {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
#include "llvm/IR/Operator.h"
|
#include "llvm/IR/Operator.h"
|
||||||
|
|
||||||
static void reduceFlagsInModule(Oracle &O, Module &Mod) {
|
static void reduceFlagsInModule(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
for (Function &F : Mod) {
|
for (Function &F : WorkItem.getModule()) {
|
||||||
for (Instruction &I : instructions(F)) {
|
for (Instruction &I : instructions(F)) {
|
||||||
if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(&I)) {
|
if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(&I)) {
|
||||||
if (OBO->hasNoSignedWrap() && !O.shouldKeep())
|
if (OBO->hasNoSignedWrap() && !O.shouldKeep())
|
||||||
|
@ -28,7 +28,8 @@ static bool shouldAlwaysKeep(const Instruction &I) {
|
|||||||
|
|
||||||
/// Removes out-of-chunk arguments from functions, and modifies their calls
|
/// Removes out-of-chunk arguments from functions, and modifies their calls
|
||||||
/// accordingly. It also removes allocations of out-of-chunk arguments.
|
/// 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<Instruction *> InitInstToKeep;
|
std::vector<Instruction *> InitInstToKeep;
|
||||||
|
|
||||||
for (auto &F : Program)
|
for (auto &F : Program)
|
||||||
|
@ -27,8 +27,8 @@ static void reduceInvokesInFunction(Oracle &O, Function &F) {
|
|||||||
// reduction.
|
// reduction.
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduceInvokesInModule(Oracle &O, Module &Mod) {
|
static void reduceInvokesInModule(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
for (Function &F : Mod) {
|
for (Function &F : WorkItem.getModule()) {
|
||||||
if (F.hasPersonalityFn())
|
if (F.hasPersonalityFn())
|
||||||
reduceInvokesInFunction(O, F);
|
reduceInvokesInFunction(O, F);
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@ static void removeVolatileInFunction(Oracle &O, Function &F) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void removeVolatileInModule(Oracle &O, Module &Mod) {
|
static void removeVolatileInModule(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
for (Function &F : Mod)
|
for (Function &F : WorkItem.getModule())
|
||||||
removeVolatileInFunction(O, F);
|
removeVolatileInFunction(O, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,9 @@ static void reduceAtomicSyncScopesInFunction(Oracle &O, Function &F) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduceAtomicSyncScopesInModule(Oracle &O, Module &Mod) {
|
static void reduceAtomicSyncScopesInModule(Oracle &O,
|
||||||
for (Function &F : Mod)
|
ReducerWorkItem &WorkItem) {
|
||||||
|
for (Function &F : WorkItem.getModule())
|
||||||
reduceAtomicSyncScopesInFunction(O, F);
|
reduceAtomicSyncScopesInFunction(O, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,8 +98,8 @@ static void reduceAtomicOrderingInFunction(Oracle &O, Function &F) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduceAtomicOrderingInModule(Oracle &O, Module &Mod) {
|
static void reduceAtomicOrderingInModule(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
for (Function &F : Mod)
|
for (Function &F : WorkItem.getModule())
|
||||||
reduceAtomicOrderingInFunction(O, F);
|
reduceAtomicOrderingInFunction(O, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,9 @@ static constexpr StringLiteral ListNamedMetadata[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Remove unneeded arguments to named metadata.
|
/// 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) {
|
for (StringRef MDName : ListNamedMetadata) {
|
||||||
NamedMDNode *NamedNode = M.getNamedMetadata(MDName);
|
NamedMDNode *NamedNode = M.getNamedMetadata(MDName);
|
||||||
if (!NamedNode)
|
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
|
/// Removes all the Named and Unnamed Metadata Nodes, as well as any debug
|
||||||
/// functions that aren't inside the desired Chunks.
|
/// 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
|
// Get out-of-chunk Named metadata nodes
|
||||||
SmallVector<NamedMDNode *> NamedNodesToDelete;
|
SmallVector<NamedMDNode *> NamedNodesToDelete;
|
||||||
for (NamedMDNode &MD : Program.named_metadata())
|
for (NamedMDNode &MD : Program.named_metadata())
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
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())
|
if (!Program.getModuleIdentifier().empty() && !O.shouldKeep())
|
||||||
Program.setModuleIdentifier("");
|
Program.setModuleIdentifier("");
|
||||||
if (!Program.getSourceFileName().empty() && !O.shouldKeep())
|
if (!Program.getSourceFileName().empty() && !O.shouldKeep())
|
||||||
|
@ -253,7 +253,9 @@ static Value *reduceInstruction(Oracle &O, Module &M, Instruction &I) {
|
|||||||
return nullptr;
|
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 (Function &F : Mod) {
|
||||||
for (BasicBlock &BB : F)
|
for (BasicBlock &BB : F)
|
||||||
for (Instruction &I : make_early_inc_range(BB)) {
|
for (Instruction &I : make_early_inc_range(BB)) {
|
||||||
|
@ -95,7 +95,9 @@ static void maybeRewriteCallWithDifferentBundles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Removes out-of-chunk operand bundles from calls.
|
/// 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);
|
OperandBundleRemapper R(O);
|
||||||
R.visit(Program);
|
R.visit(Program);
|
||||||
|
|
||||||
|
@ -18,8 +18,10 @@ using namespace llvm;
|
|||||||
using namespace PatternMatch;
|
using namespace PatternMatch;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extractOperandsFromModule(Oracle &O, Module &Program,
|
extractOperandsFromModule(Oracle &O, ReducerWorkItem &WorkItem,
|
||||||
function_ref<Value *(Use &)> ReduceValue) {
|
function_ref<Value *(Use &)> ReduceValue) {
|
||||||
|
Module &Program = WorkItem.getModule();
|
||||||
|
|
||||||
for (auto &F : Program.functions()) {
|
for (auto &F : Program.functions()) {
|
||||||
for (auto &I : instructions(&F)) {
|
for (auto &I : instructions(&F)) {
|
||||||
if (PHINode *Phi = dyn_cast<PHINode>(&I)) {
|
if (PHINode *Phi = dyn_cast<PHINode>(&I)) {
|
||||||
@ -118,8 +120,8 @@ void llvm::reduceOperandsOneDeltaPass(TestRunner &Test) {
|
|||||||
};
|
};
|
||||||
runDeltaPass(
|
runDeltaPass(
|
||||||
Test,
|
Test,
|
||||||
[ReduceValue](Oracle &O, Module &Program) {
|
[ReduceValue](Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
extractOperandsFromModule(O, Program, ReduceValue);
|
extractOperandsFromModule(O, WorkItem, ReduceValue);
|
||||||
},
|
},
|
||||||
"Reducing Operands to one");
|
"Reducing Operands to one");
|
||||||
}
|
}
|
||||||
@ -137,7 +139,7 @@ void llvm::reduceOperandsZeroDeltaPass(TestRunner &Test) {
|
|||||||
};
|
};
|
||||||
runDeltaPass(
|
runDeltaPass(
|
||||||
Test,
|
Test,
|
||||||
[ReduceValue](Oracle &O, Module &Program) {
|
[ReduceValue](Oracle &O, ReducerWorkItem &Program) {
|
||||||
extractOperandsFromModule(O, Program, ReduceValue);
|
extractOperandsFromModule(O, Program, ReduceValue);
|
||||||
},
|
},
|
||||||
"Reducing Operands to zero");
|
"Reducing Operands to zero");
|
||||||
@ -165,7 +167,7 @@ void llvm::reduceOperandsNaNDeltaPass(TestRunner &Test) {
|
|||||||
};
|
};
|
||||||
runDeltaPass(
|
runDeltaPass(
|
||||||
Test,
|
Test,
|
||||||
[ReduceValue](Oracle &O, Module &Program) {
|
[ReduceValue](Oracle &O, ReducerWorkItem &Program) {
|
||||||
extractOperandsFromModule(O, Program, ReduceValue);
|
extractOperandsFromModule(O, Program, ReduceValue);
|
||||||
},
|
},
|
||||||
"Reducing Operands to NaN");
|
"Reducing Operands to NaN");
|
||||||
|
@ -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()) {
|
for (Function &F : Program.functions()) {
|
||||||
SmallVector<std::pair<Use *, Value *>> Replacements;
|
SmallVector<std::pair<Use *, Value *>> Replacements;
|
||||||
opportunities(F, [&](Use &Op, ArrayRef<Value *> Candidates) {
|
opportunities(F, [&](Use &Op, ArrayRef<Value *> Candidates) {
|
||||||
|
@ -173,7 +173,9 @@ static void substituteOperandWithArgument(Function *OldF,
|
|||||||
NewF->setName(FName);
|
NewF->setName(FName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduceOperandsToArgs(Oracle &O, Module &Program) {
|
static void reduceOperandsToArgs(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
|
Module &Program = WorkItem.getModule();
|
||||||
|
|
||||||
SmallVector<Use *> OperandsToReduce;
|
SmallVector<Use *> OperandsToReduce;
|
||||||
for (Function &F : make_early_inc_range(Program.functions())) {
|
for (Function &F : make_early_inc_range(Program.functions())) {
|
||||||
if (!canReplaceFunction(&F))
|
if (!canReplaceFunction(&F))
|
||||||
|
@ -27,7 +27,10 @@ static StringRef SpecialGlobalNames[] = {"llvm.used", "llvm.compiler.used"};
|
|||||||
|
|
||||||
/// Removes all special globals aren't inside any of the
|
/// Removes all special globals aren't inside any of the
|
||||||
/// desired Chunks.
|
/// desired Chunks.
|
||||||
static void extractSpecialGlobalsFromModule(Oracle &O, Module &Program) {
|
static void extractSpecialGlobalsFromModule(Oracle &O,
|
||||||
|
ReducerWorkItem &WorkItem) {
|
||||||
|
Module &Program = WorkItem.getModule();
|
||||||
|
|
||||||
for (StringRef Name : SpecialGlobalNames) {
|
for (StringRef Name : SpecialGlobalNames) {
|
||||||
if (auto *Used = Program.getNamedGlobal(Name)) {
|
if (auto *Used = Program.getNamedGlobal(Name)) {
|
||||||
Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
|
Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) {
|
static void reduceUsingSimplifyCFG(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
|
Module &Program = WorkItem.getModule();
|
||||||
SmallVector<BasicBlock *, 16> ToSimplify;
|
SmallVector<BasicBlock *, 16> ToSimplify;
|
||||||
for (auto &F : Program)
|
for (auto &F : Program)
|
||||||
for (auto &BB : F)
|
for (auto &BB : F)
|
||||||
@ -33,7 +34,9 @@ static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) {
|
|||||||
void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) {
|
void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) {
|
||||||
runDeltaPass(Test, reduceUsingSimplifyCFG, "Reducing using SimplifyCFG");
|
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<BasicBlock *, 16> ToSimplify;
|
SmallVector<BasicBlock *, 16> ToSimplify;
|
||||||
|
|
||||||
for (auto &F : M) {
|
for (auto &F : M) {
|
||||||
@ -58,12 +61,18 @@ static void reduceConditionals(Oracle &O, Module &M, bool Direction) {
|
|||||||
|
|
||||||
void llvm::reduceConditionalsTrueDeltaPass(TestRunner &Test) {
|
void llvm::reduceConditionalsTrueDeltaPass(TestRunner &Test) {
|
||||||
runDeltaPass(
|
runDeltaPass(
|
||||||
Test, [](Oracle &O, Module &M) { reduceConditionals(O, M, true); },
|
Test,
|
||||||
|
[](Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
|
reduceConditionals(O, WorkItem, true);
|
||||||
|
},
|
||||||
"Reducing conditional branches to true");
|
"Reducing conditional branches to true");
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm::reduceConditionalsFalseDeltaPass(TestRunner &Test) {
|
void llvm::reduceConditionalsFalseDeltaPass(TestRunner &Test) {
|
||||||
runDeltaPass(
|
runDeltaPass(
|
||||||
Test, [](Oracle &O, Module &M) { reduceConditionals(O, M, false); },
|
Test,
|
||||||
|
[](Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
|
reduceConditionals(O, WorkItem, false);
|
||||||
|
},
|
||||||
"Reducing conditional branches to false");
|
"Reducing conditional branches to false");
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ static cl::opt<std::string> PassPipeline(
|
|||||||
cl::init("function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces)"),
|
cl::init("function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces)"),
|
||||||
cl::cat(LLVMReduceOptions));
|
cl::cat(LLVMReduceOptions));
|
||||||
|
|
||||||
static void runPasses(Oracle &O, Module &Program) {
|
static void runPasses(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
|
Module &Program = WorkItem.getModule();
|
||||||
LoopAnalysisManager LAM;
|
LoopAnalysisManager LAM;
|
||||||
FunctionAnalysisManager FAM;
|
FunctionAnalysisManager FAM;
|
||||||
CGSCCAnalysisManager CGAM;
|
CGSCCAnalysisManager CGAM;
|
||||||
|
@ -19,9 +19,10 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Calls simplifyInstruction in each instruction in functions, and replaces
|
/// Calls simplifyInstruction in each instruction in functions, and replaces
|
||||||
/// their values.
|
/// their values.
|
||||||
static void extractInstrFromModule(Oracle &O, Module &Program) {
|
static void extractInstrFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
|
||||||
std::vector<Instruction *> InstsToDelete;
|
std::vector<Instruction *> InstsToDelete;
|
||||||
|
|
||||||
|
Module &Program = WorkItem.getModule();
|
||||||
const DataLayout &DL = Program.getDataLayout();
|
const DataLayout &DL = Program.getDataLayout();
|
||||||
|
|
||||||
std::vector<Instruction *> InstToDelete;
|
std::vector<Instruction *> InstToDelete;
|
||||||
|
@ -15,7 +15,8 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Removes all aliases aren't inside any of the
|
/// Removes all aliases aren't inside any of the
|
||||||
/// desired Chunks.
|
/// 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) {
|
bool HasDebugInfo = any_of(Program.named_metadata(), [](NamedMDNode &NMD) {
|
||||||
return NMD.getName().startswith("llvm.dbg.");
|
return NMD.getName().startswith("llvm.dbg.");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user