From 6f55c097876f7f458bfee279c2c82d77b2c061bf Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 13 Mar 2024 22:21:22 +0530 Subject: [PATCH 1/3] DEV: Added support for --fast tag --- src/bin/lc.cpp | 53 +++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/bin/lc.cpp b/src/bin/lc.cpp index 53c560c..70edb54 100644 --- a/src/bin/lc.cpp +++ b/src/bin/lc.cpp @@ -63,7 +63,6 @@ std::string construct_outfile(std::string &arg_file, std::string &ArgO) { } #define DeclareLCompilersUtilVars \ - LCompilers::CompilerOptions compiler_options; \ LCompilers::diag::Diagnostics diagnostics; \ LCompilers::LocationManager lm; \ { \ @@ -74,12 +73,9 @@ std::string construct_outfile(std::string &arg_file, std::string &ArgO) { lm.init_simple(input); \ lm.file_ends.push_back(input.size()); \ } \ - compiler_options.po.always_run = true; \ - compiler_options.po.run_fun = "f"; \ - compiler_options.po.realloc_lhs = true; \ diagnostics.diagnostics.clear(); \ -int emit_wat(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t *asr) { +int emit_wat(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t *asr, LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; LCompilers::Result> r2 = LCompilers::asr_to_wasm_bytes_stream(*asr, al, diagnostics, compiler_options); @@ -100,7 +96,7 @@ int emit_wat(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUni return 0; } -int emit_c(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr) { +int emit_c(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr, LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; // Apply ASR passes @@ -118,7 +114,7 @@ int emit_c(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_ return 0; } -int emit_cpp(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr) { +int emit_cpp(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr, LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; // Apply ASR passes @@ -136,7 +132,7 @@ int emit_cpp(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUni return 0; } -int emit_fortran(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr) { +int emit_fortran(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr, LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; auto res = LCompilers::asr_to_fortran(*asr, diagnostics, false, 4); @@ -149,7 +145,7 @@ int emit_fortran(Allocator &al, std::string &infile, LCompilers::ASR::Translatio return 0; } -int emit_llvm(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr) { +int emit_llvm(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUnit_t* asr, LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; LCompilers::PassManager pass_manager; @@ -180,7 +176,8 @@ int emit_llvm(Allocator &al, std::string &infile, LCompilers::ASR::TranslationUn int compile_to_binary_wasm( Allocator &al, const std::string &infile, - const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr) { + const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr, + LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; LCompilers::Result res = LCompilers::asr_to_wasm(*asr, al, outfile, false, diagnostics, compiler_options); if (!res.ok) { @@ -191,7 +188,8 @@ int compile_to_binary_wasm( } int compile_to_c(Allocator &al, const std::string &infile, - const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr) { + const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr, + LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; // Apply ASR passes @@ -213,7 +211,8 @@ int compile_to_c(Allocator &al, const std::string &infile, } int compile_to_cpp(Allocator &al, const std::string &infile, - const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr) { + const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr, + LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; // Apply ASR passes @@ -235,7 +234,8 @@ int compile_to_cpp(Allocator &al, const std::string &infile, } int compile_to_fortran(Allocator &al, const std::string &infile, - const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr) { + const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr, + LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; auto res = LCompilers::asr_to_fortran(*asr, diagnostics, false, 4); @@ -252,7 +252,8 @@ int compile_to_fortran(Allocator &al, const std::string &infile, } int compile_to_binary_object(Allocator &al, const std::string &infile, - const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr) { + const std::string &outfile, LCompilers::ASR::TranslationUnit_t* asr, + LCompilers::CompilerOptions& compiler_options) { DeclareLCompilersUtilVars; LCompilers::PassManager pass_manager; @@ -616,6 +617,9 @@ int mainApp(int argc, const char **argv) { bool parse_all_comments = false; LCompilers::CompilerOptions co; + co.po.always_run = true; + co.po.run_fun = "f"; + co.po.realloc_lhs = true; co.po.runtime_library_dir = LCompilers::LC::get_runtime_library_dir(); CLI::App app{"LFortran: modern interactive LLVM-based Fortran compiler"}; @@ -640,6 +644,7 @@ int mainApp(int argc, const char **argv) { app.add_flag("--get-rtl-header-dir", print_rtl_header_dir, "Print the path to the runtime library header file"); app.add_flag("--get-rtl-dir", print_rtl_dir, "Print the path to the runtime library file"); app.add_flag("--parse-all-comments", parse_all_comments, "Parse all comments in the input code"); + app.add_flag("--fast", co.po.fast, "Best performance (disable strict standard compliance)"); app.get_formatter()->column_width(25); app.require_subcommand(0, 1); @@ -678,15 +683,15 @@ int mainApp(int argc, const char **argv) { std::cout<< LCompilers::pickle(*tu, co.use_colors, co.indent, true) << std::endl; return 0; } else if (show_wat) { - return emit_wat(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu); + return emit_wat(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (show_c) { - return emit_c(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu); + return emit_c(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (show_cpp) { - return emit_cpp(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu); + return emit_cpp(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (show_fortran) { - return emit_fortran(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu); + return emit_fortran(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (show_llvm) { - return emit_llvm(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu); + return emit_llvm(al, infile, (LCompilers::ASR::TranslationUnit_t*)tu, co); } // compile to binary @@ -699,19 +704,19 @@ int mainApp(int argc, const char **argv) { std::string tmp_file; if (backend == Backend::wasm) { - status = compile_to_binary_wasm(al, infile, outfile, (LCompilers::ASR::TranslationUnit_t*)tu); + status = compile_to_binary_wasm(al, infile, outfile, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (backend == Backend::c) { tmp_file = outfile + "__generated__.c"; - status = compile_to_c(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu); + status = compile_to_c(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (backend == Backend::cpp) { tmp_file = outfile + "__generated__.cpp"; - status = compile_to_cpp(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu); + status = compile_to_cpp(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (backend == Backend::fortran) { tmp_file = outfile + "__generated__.f90"; - status = compile_to_fortran(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu); + status = compile_to_fortran(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu, co); } else if (backend == Backend::llvm) { tmp_file = arg_c ? outfile : (outfile + "__generated__.o"); - status = compile_to_binary_object(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu); + status = compile_to_binary_object(al, infile, tmp_file, (LCompilers::ASR::TranslationUnit_t*)tu, co); } if (status != 0) { From 3bb4b8ed16b4c39f8ae33a28e1713ea155a3ed50 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 13 Mar 2024 22:21:53 +0530 Subject: [PATCH 2/3] DEV: Removed is_fast and its associated methods --- src/libasr/pass/pass_manager.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/libasr/pass/pass_manager.h b/src/libasr/pass/pass_manager.h index 1e272f6..063c324 100644 --- a/src/libasr/pass/pass_manager.h +++ b/src/libasr/pass/pass_manager.h @@ -107,7 +107,6 @@ namespace LCompilers { {"insert_deallocate", &pass_insert_deallocate} }; - bool is_fast; bool apply_default_passes; bool c_skip_pass; // This will contain the passes that are to be skipped in C @@ -197,7 +196,7 @@ namespace LCompilers { } } - PassManager(): is_fast{false}, apply_default_passes{false}, + PassManager(): apply_default_passes{false}, c_skip_pass{false} { _passes = { "nested_vars", @@ -288,12 +287,10 @@ namespace LCompilers { PassOptions& pass_options, diag::Diagnostics &diagnostics) { if( !_user_defined_passes.empty() ) { - pass_options.fast = true; apply_passes(al, asr, _user_defined_passes, pass_options, diagnostics); } else if( apply_default_passes ) { - pass_options.fast = is_fast; - if( is_fast ) { + if( pass_options.fast ) { apply_passes(al, asr, _with_optimization_passes, pass_options, diagnostics); } else { @@ -372,14 +369,6 @@ namespace LCompilers { } } - void use_optimization_passes() { - is_fast = true; - } - - void do_not_use_optimization_passes() { - is_fast = false; - } - void use_default_passes(bool _c_skip_pass=false) { apply_default_passes = true; c_skip_pass = _c_skip_pass; From da2e2354ae62ebbb92655e9c6da3990b8eb1e88d Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 13 Mar 2024 22:22:05 +0530 Subject: [PATCH 3/3] TEST: Enabled fast tests --- integration_tests/CMakeLists.txt | 90 ++++++++++++++++---------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index d1c3d73..bb03534 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -175,66 +175,66 @@ endmacro(RUN) # x86 --- compile to x86 binary directly # wasm --- compile to WASM binary directly -RUN(NAME expr1.c LABELS gcc c wasm llvm NOFAST) +RUN(NAME expr1.c LABELS gcc c wasm llvm) RUN(NAME expr2.c LABELS gcc c wasm llvm NOFAST) -RUN(NAME expr3.c FAIL LABELS gcc c wasm llvm NOFAST) +RUN(NAME expr3.c FAIL LABELS gcc c wasm llvm) -RUN(NAME switch_case_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME switch_case_02.cpp LABELS gcc llvm NOFAST) +RUN(NAME switch_case_01.cpp LABELS gcc llvm) +RUN(NAME switch_case_02.cpp LABELS gcc llvm) # arrays -RUN(NAME array_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_02.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_03.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_04.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_05.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_06.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_07.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_08.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_09.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_10.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_11.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_12.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_13.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_14.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_15.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_16.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_17.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_18.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_19.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_20.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_21.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_22.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_23.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_24.cpp LABELS gcc llvm NOFAST) -RUN(NAME array_25.cpp LABELS gcc llvm NOFAST) - -RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST) -RUN(NAME struct_03.cpp LABELS gcc llvm NOFAST) -RUN(NAME struct_04.cpp LABELS gcc llvm NOFAST) -RUN(NAME struct_05.cpp LABELS gcc llvm NOFAST) -RUN(NAME struct_06.cpp LABELS gcc llvm NOFAST) +RUN(NAME array_01.cpp LABELS gcc llvm) +RUN(NAME array_02.cpp LABELS gcc llvm) +RUN(NAME array_03.cpp LABELS gcc llvm) +RUN(NAME array_04.cpp LABELS gcc llvm) +RUN(NAME array_05.cpp LABELS gcc llvm) +RUN(NAME array_06.cpp LABELS gcc llvm) +RUN(NAME array_07.cpp LABELS gcc llvm) +RUN(NAME array_08.cpp LABELS gcc llvm) +RUN(NAME array_09.cpp LABELS gcc llvm) +RUN(NAME array_10.cpp LABELS gcc llvm) +RUN(NAME array_11.cpp LABELS gcc llvm) +RUN(NAME array_12.cpp LABELS gcc llvm) +RUN(NAME array_13.cpp LABELS gcc llvm) +RUN(NAME array_14.cpp LABELS gcc llvm) +RUN(NAME array_15.cpp LABELS gcc llvm) +RUN(NAME array_16.cpp LABELS gcc llvm) +RUN(NAME array_17.cpp LABELS gcc llvm) +RUN(NAME array_18.cpp LABELS gcc llvm) +RUN(NAME array_19.cpp LABELS gcc llvm) +RUN(NAME array_20.cpp LABELS gcc llvm) +RUN(NAME array_21.cpp LABELS gcc llvm) +RUN(NAME array_22.cpp LABELS gcc llvm) +RUN(NAME array_23.cpp LABELS gcc llvm) +RUN(NAME array_24.cpp LABELS gcc llvm) +RUN(NAME array_25.cpp LABELS gcc llvm) + +RUN(NAME struct_01.cpp LABELS gcc llvm) +RUN(NAME struct_02.cpp LABELS gcc llvm) +RUN(NAME struct_03.cpp LABELS gcc llvm) +RUN(NAME struct_04.cpp LABELS gcc llvm) +RUN(NAME struct_05.cpp LABELS gcc llvm) +RUN(NAME struct_06.cpp LABELS gcc llvm) RUN(NAME pointer_01.cpp LABELS gcc) RUN(NAME pointer_02.cpp LABELS gcc) -RUN(NAME pointer_03.cpp LABELS gcc llvm NOFAST) +RUN(NAME pointer_03.cpp LABELS gcc llvm) RUN(NAME function_01.cpp LABELS gcc llvm NOFAST) RUN(NAME nbody_01.cpp LABELS gcc llvm NOFAST) RUN(NAME nbody_02.cpp LABELS gcc llvm NOFAST) -RUN(NAME enum_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME enum_02.cpp LABELS gcc llvm NOFAST) -RUN(NAME enum_03.cpp LABELS gcc llvm NOFAST) -RUN(NAME enum_04.cpp LABELS gcc llvm NOFAST) +RUN(NAME enum_01.cpp LABELS gcc llvm) +RUN(NAME enum_02.cpp LABELS gcc llvm) +RUN(NAME enum_03.cpp LABELS gcc llvm) +RUN(NAME enum_04.cpp LABELS gcc llvm) -RUN(NAME union_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME union_02.cpp LABELS gcc llvm NOFAST) +RUN(NAME union_01.cpp LABELS gcc llvm) +RUN(NAME union_02.cpp LABELS gcc llvm) -RUN(NAME vector_01.cpp LABELS gcc llvm NOFAST) -RUN(NAME vector_02.cpp LABELS gcc llvm NOFAST) +RUN(NAME vector_01.cpp LABELS gcc llvm) +RUN(NAME vector_02.cpp LABELS gcc llvm) RUN(NAME loop_01.cpp LABELS gcc llvm NOFAST)