From 91b9618d4b61c2dc7577b1f442bf5a549e93d8d2 Mon Sep 17 00:00:00 2001 From: Michele Scuttari Date: Sat, 5 Oct 2024 15:08:04 +0200 Subject: [PATCH 1/4] Make variables to parameters promotion optional --- lib/Frontend/FrontendActions.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index c8444a179..db68b131b 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -826,7 +826,10 @@ void CodeGenAction::buildMLIRLoweringPipeline(mlir::PassManager &pm) { pm.addPass(mlir::bmodelica::createEquationAccessSplitPass()); pm.addPass(mlir::bmodelica::createSingleValuedInductionEliminationPass()); pm.addPass(mlir::bmodelica::createSCCDetectionPass()); - pm.addPass(mlir::bmodelica::createVariablesPromotionPass()); + + if (ci.getCodeGenOptions().variablesToParametersPromotion) { + pm.addPass(mlir::bmodelica::createVariablesPromotionPass()); + } // Try to solve the cycles by substitution. pm.addPass(mlir::bmodelica::createSCCSolvingBySubstitutionPass()); From a123cb3fcfd14a07d8f282369bf2130bed418caa Mon Sep 17 00:00:00 2001 From: Michele Scuttari Date: Sat, 5 Oct 2024 18:55:42 +0200 Subject: [PATCH 2/4] Make single valued induction elimination optional --- include/public/marco/Frontend/CodegenOptions.h | 1 + lib/Frontend/CompilerInvocation.cpp | 2 ++ lib/Frontend/FrontendActions.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/public/marco/Frontend/CodegenOptions.h b/include/public/marco/Frontend/CodegenOptions.h index 610f31c67..a83debfa3 100644 --- a/include/public/marco/Frontend/CodegenOptions.h +++ b/include/public/marco/Frontend/CodegenOptions.h @@ -26,6 +26,7 @@ namespace marco::frontend bool cse = false; bool equationsRuntimeScheduling = false; bool omp = false; + bool singleValuedInductionElimination = false; bool loopFusion = false; bool loopCoalescing = false; bool loopTiling = false; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 1a8caa124..5f329779d 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -508,6 +508,7 @@ static void parseCodegenArgs(marco::frontend::CodegenOptions &options, if (options.optLevel.getSpeedupLevel() > 0) { options.debug = false; options.assertions = false; + options.singleValuedInductionElimination = true; } if (options.optLevel.getSpeedupLevel() > 1) { @@ -525,6 +526,7 @@ static void parseCodegenArgs(marco::frontend::CodegenOptions &options, if (options.optLevel.getSizeLevel() > 0) { options.debug = false; options.cse = true; + options.singleValuedInductionElimination = true; options.loopFusion = true; options.loopCoalescing = true; } diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index db68b131b..6e1d03383 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -824,7 +824,11 @@ void CodeGenAction::buildMLIRLoweringPipeline(mlir::PassManager &pm) { pm.addPass(mlir::createCanonicalizerPass()); pm.addPass(mlir::bmodelica::createMatchingPass()); pm.addPass(mlir::bmodelica::createEquationAccessSplitPass()); - pm.addPass(mlir::bmodelica::createSingleValuedInductionEliminationPass()); + + if (ci.getCodeGenOptions().singleValuedInductionElimination) { + pm.addPass(mlir::bmodelica::createSingleValuedInductionEliminationPass()); + } + pm.addPass(mlir::bmodelica::createSCCDetectionPass()); if (ci.getCodeGenOptions().variablesToParametersPromotion) { @@ -837,7 +841,10 @@ void CodeGenAction::buildMLIRLoweringPipeline(mlir::PassManager &pm) { // Simplify the possibly complex accesses introduced by equations // substitutions. pm.addPass(mlir::createCanonicalizerPass()); - pm.addPass(mlir::bmodelica::createSingleValuedInductionEliminationPass()); + + if (ci.getCodeGenOptions().singleValuedInductionElimination) { + pm.addPass(mlir::bmodelica::createSingleValuedInductionEliminationPass()); + } // Apply the selected solver. pm.addPass( From 86701e8cf649789d3cde3b0f4781ffe92c484932 Mon Sep 17 00:00:00 2001 From: Michele Scuttari Date: Sat, 5 Oct 2024 19:01:23 +0200 Subject: [PATCH 3/4] Format code --- .../public/marco/Frontend/CodegenOptions.h | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/include/public/marco/Frontend/CodegenOptions.h b/include/public/marco/Frontend/CodegenOptions.h index a83debfa3..b94195372 100644 --- a/include/public/marco/Frontend/CodegenOptions.h +++ b/include/public/marco/Frontend/CodegenOptions.h @@ -6,36 +6,34 @@ #include #include -namespace marco::frontend -{ - /// Code generation operations. - /// The default values are for compiling without optimizations. - /// The class extends the language options for C / C++ to enable the - /// integration with clang's diagnostics infrastructure. - struct CodegenOptions : public clang::CodeGenOptions - { - llvm::OptimizationLevel optLevel = llvm::OptimizationLevel::O0; +namespace marco::frontend { +/// Code generation operations. +/// The default values are for compiling without optimizations. +/// The class extends the language options for C / C++ to enable the +/// integration with clang's diagnostics infrastructure. +struct CodegenOptions : public clang::CodeGenOptions { + llvm::OptimizationLevel optLevel = llvm::OptimizationLevel::O0; - bool debug = true; - bool assertions = true; - bool inlining = false; - bool outputArraysPromotion = false; - bool heapToStackPromotion = false; - bool readOnlyVariablesPropagation = false; - bool variablesToParametersPromotion = false; - bool cse = false; - bool equationsRuntimeScheduling = false; - bool omp = false; - bool singleValuedInductionElimination = false; - bool loopFusion = false; - bool loopCoalescing = false; - bool loopTiling = false; + bool debug = true; + bool assertions = true; + bool inlining = false; + bool outputArraysPromotion = false; + bool heapToStackPromotion = false; + bool readOnlyVariablesPropagation = false; + bool variablesToParametersPromotion = false; + bool cse = false; + bool equationsRuntimeScheduling = false; + bool omp = false; + bool singleValuedInductionElimination = false; + bool loopFusion = false; + bool loopCoalescing = false; + bool loopTiling = false; - unsigned int bitWidth = 64; + unsigned int bitWidth = 64; - std::string cpu = "generic"; - std::vector features; - }; -} + std::string cpu = "generic"; + std::vector features; +}; +} // namespace marco::frontend #endif // MARCO_FRONTEND_CODEGENOPTIONS_H From bb7cf3167ee97547747d09b442bc3f5b8d53dde0 Mon Sep 17 00:00:00 2001 From: Michele Scuttari Date: Sat, 5 Oct 2024 19:02:45 +0200 Subject: [PATCH 4/4] Fix wrong wording --- include/public/marco/Frontend/CodegenOptions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/public/marco/Frontend/CodegenOptions.h b/include/public/marco/Frontend/CodegenOptions.h index b94195372..f7ea91d7b 100644 --- a/include/public/marco/Frontend/CodegenOptions.h +++ b/include/public/marco/Frontend/CodegenOptions.h @@ -7,7 +7,7 @@ #include namespace marco::frontend { -/// Code generation operations. +/// Code generation options. /// The default values are for compiling without optimizations. /// The class extends the language options for C / C++ to enable the /// integration with clang's diagnostics infrastructure.