From c2d3833c1269d250d8676fbe3daf9d727c000851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D0=BE=D0=B2=D1=81=D0=BA=D0=B8=D0=B9?= Date: Sun, 4 May 2025 14:18:45 +0300 Subject: [PATCH] feat: add SKIP_OPTIMIZATIONS option to CMakeLists.txt --- CMakeLists.txt | 7 ++ src/passes/CMakeLists.txt | 232 ++++++++++++++++++++------------------ src/passes/pass.cpp | 69 ++++++------ src/passes/passes.h | 17 +-- 4 files changed, 172 insertions(+), 153 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16e2add800f..f8d542c6735 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,9 @@ option(EMSCRIPTEN_ENABLE_SINGLE_FILE "Enable SINGLE_FILE mode in emscripten buil option(ENABLE_WERROR "Enable -Werror" ON) +# Turn this on to skip all optimizations but leave ones which just print +option(SKIP_OPTIMIZATIONS "Skip all optimizations but Print* ones" OFF) + # For git users, attempt to generate a more useful version string if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) find_package(Git QUIET REQUIRED) @@ -480,6 +483,10 @@ if(BUILD_MIMALLOC) endif() endif() +if(SKIP_OPTIMIZATIONS) + add_definitions(-DSKIP_OPTIMIZATIONS) +endif() + add_subdirectory(src/ir) add_subdirectory(src/asmjs) add_subdirectory(src/cfg) diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index 6fab09b1bc2..feafef214a6 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -17,126 +17,134 @@ set(passes_SOURCES pass.cpp string-utils.cpp test_passes.cpp - AbstractTypeRefining.cpp - AlignmentLowering.cpp - Asyncify.cpp - AvoidReinterprets.cpp - CoalesceLocals.cpp - CodePushing.cpp - CodeFolding.cpp - ConstantFieldPropagation.cpp - ConstHoisting.cpp - DataFlowOpts.cpp - DeadArgumentElimination.cpp - DeadCodeElimination.cpp - DeAlign.cpp - DebugLocationPropagation.cpp - DeNaN.cpp - Directize.cpp - DuplicateImportElimination.cpp - DuplicateFunctionElimination.cpp - DWARF.cpp - EncloseWorld.cpp - ExtractFunction.cpp - Flatten.cpp - FuncCastEmulation.cpp - GenerateDynCalls.cpp - GlobalEffects.cpp - GlobalRefining.cpp - GlobalStructInference.cpp - GlobalTypeOptimization.cpp - GUFA.cpp - hash-stringify-walker.cpp - Outlining.cpp - Heap2Local.cpp - HeapStoreOptimization.cpp - I64ToI32Lowering.cpp - Inlining.cpp - InstrumentLocals.cpp - InstrumentMemory.cpp - Intrinsics.cpp - J2CLItableMerging.cpp - J2CLOpts.cpp - JSPI.cpp - LegalizeJSInterface.cpp - LimitSegments.cpp - LLVMMemoryCopyFillLowering.cpp - LocalCSE.cpp - LocalSubtyping.cpp - LogExecution.cpp - LoopInvariantCodeMotion.cpp - Memory64Lowering.cpp - MemoryPacking.cpp - MergeBlocks.cpp - MergeSimilarFunctions.cpp - MergeLocals.cpp - Metrics.cpp - MinifyImportsAndExports.cpp - MinimizeRecGroups.cpp - Monomorphize.cpp - MultiMemoryLowering.cpp - NameList.cpp - NameTypes.cpp - NoInline.cpp - LLVMNontrappingFPToIntLowering.cpp - OnceReduction.cpp - OptimizeAddedConstants.cpp - OptimizeCasts.cpp - OptimizeInstructions.cpp - OptimizeForJS.cpp - PickLoadSigns.cpp - Poppify.cpp - PostEmscripten.cpp - Precompute.cpp Print.cpp PrintCallGraph.cpp PrintFeatures.cpp PrintFunctionMap.cpp - RoundTrip.cpp - SetGlobals.cpp - SignaturePruning.cpp - SignatureRefining.cpp - SignExtLowering.cpp - StringLifting.cpp - StringLowering.cpp - Strip.cpp - StripTargetFeatures.cpp - TraceCalls.cpp - RedundantSetElimination.cpp - RemoveImports.cpp - RemoveMemoryInit.cpp - RemoveNonJSOps.cpp - RemoveUnusedBrs.cpp - RemoveUnusedNames.cpp - RemoveUnusedModuleElements.cpp - RemoveUnusedTypes.cpp - ReorderFunctions.cpp - ReorderGlobals.cpp - ReorderLocals.cpp - ReReloop.cpp - TrapMode.cpp TypeGeneralizing.cpp - TypeRefining.cpp - TypeMerging.cpp - TypeSSA.cpp - SafeHeap.cpp - SeparateDataSegments.cpp - SimplifyGlobals.cpp - SimplifyLocals.cpp - Souperify.cpp - SpillPointers.cpp - StackCheck.cpp - StripEH.cpp - SSAify.cpp - TupleOptimization.cpp - TranslateEH.cpp - TypeFinalizing.cpp - Unsubtyping.cpp - Untee.cpp - Vacuum.cpp ${CMAKE_CURRENT_BINARY_DIR}/WasmIntrinsics.cpp ${passes_HEADERS} ) + +if(NOT SKIP_OPTIMIZATIONS) + list( + APPEND + passes_SOURCES + AbstractTypeRefining.cpp + AlignmentLowering.cpp + Asyncify.cpp + AvoidReinterprets.cpp + CoalesceLocals.cpp + CodePushing.cpp + CodeFolding.cpp + ConstantFieldPropagation.cpp + ConstHoisting.cpp + DataFlowOpts.cpp + DeadArgumentElimination.cpp + DeadCodeElimination.cpp + DeAlign.cpp + DebugLocationPropagation.cpp + DeNaN.cpp + Directize.cpp + DuplicateImportElimination.cpp + DuplicateFunctionElimination.cpp + DWARF.cpp + EncloseWorld.cpp + ExtractFunction.cpp + Flatten.cpp + FuncCastEmulation.cpp + GenerateDynCalls.cpp + GlobalEffects.cpp + GlobalRefining.cpp + GlobalStructInference.cpp + GlobalTypeOptimization.cpp + GUFA.cpp + hash-stringify-walker.cpp + Outlining.cpp + Heap2Local.cpp + HeapStoreOptimization.cpp + I64ToI32Lowering.cpp + Inlining.cpp + InstrumentLocals.cpp + InstrumentMemory.cpp + Intrinsics.cpp + J2CLItableMerging.cpp + J2CLOpts.cpp + JSPI.cpp + LegalizeJSInterface.cpp + LimitSegments.cpp + LLVMMemoryCopyFillLowering.cpp + LocalCSE.cpp + LocalSubtyping.cpp + LogExecution.cpp + LoopInvariantCodeMotion.cpp + Memory64Lowering.cpp + MemoryPacking.cpp + MergeBlocks.cpp + MergeSimilarFunctions.cpp + MergeLocals.cpp + Metrics.cpp + MinifyImportsAndExports.cpp + MinimizeRecGroups.cpp + Monomorphize.cpp + MultiMemoryLowering.cpp + NameList.cpp + NameTypes.cpp + NoInline.cpp + LLVMNontrappingFPToIntLowering.cpp + OnceReduction.cpp + OptimizeAddedConstants.cpp + OptimizeCasts.cpp + OptimizeInstructions.cpp + OptimizeForJS.cpp + PickLoadSigns.cpp + Poppify.cpp + PostEmscripten.cpp + Precompute.cpp + RoundTrip.cpp + SetGlobals.cpp + SignaturePruning.cpp + SignatureRefining.cpp + SignExtLowering.cpp + StringLowering.cpp + Strip.cpp + StripTargetFeatures.cpp + TraceCalls.cpp + RedundantSetElimination.cpp + RemoveImports.cpp + RemoveMemoryInit.cpp + RemoveNonJSOps.cpp + RemoveUnusedBrs.cpp + RemoveUnusedNames.cpp + RemoveUnusedModuleElements.cpp + RemoveUnusedTypes.cpp + ReorderFunctions.cpp + ReorderGlobals.cpp + ReorderLocals.cpp + ReReloop.cpp + TrapMode.cpp + TypeGeneralizing.cpp + TypeRefining.cpp + TypeMerging.cpp + TypeSSA.cpp + SafeHeap.cpp + SeparateDataSegments.cpp + SimplifyGlobals.cpp + SimplifyLocals.cpp + Souperify.cpp + SpillPointers.cpp + StackCheck.cpp + StripEH.cpp + SSAify.cpp + TupleOptimization.cpp + TranslateEH.cpp + TypeFinalizing.cpp + Unsubtyping.cpp + Untee.cpp + Vacuum.cpp + ) +endif() + # The below condition is intended for removal once the suffix_tree and # suffix_tree_node source files no longer depend on LLVM code in the # third_party folder diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 2042bc71d3a..69856071ff1 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -90,6 +90,37 @@ bool PassRegistry::isPassHidden(std::string name) { // PassRunner void PassRegistry::registerPasses() { + registerPass("print", "print in s-expression format", createPrinterPass); + registerPass("print-minified", + "print in minified s-expression format", + createMinifiedPrinterPass); + registerPass("print-features", + "print options for enabled features", + createPrintFeaturesPass); + registerPass( + "print-full", "print in full s-expression format", createFullPrinterPass); + registerPass( + "print-call-graph", "print call graph", createPrintCallGraphPass); + + // Register PrintFunctionMap using its normal name. + registerPass("print-function-map", + "print a map of function indexes to names", + createPrintFunctionMapPass); + // Also register it as "symbolmap" so that wasm-opt --symbolmap=foo is the + // same as wasm-as --symbolmap=foo even though the latter is not a pass + // (wasm-as cannot run arbitrary passes). + // TODO: switch emscripten to this name, then remove the old one + registerPass( + "symbolmap", "(alias for print-function-map)", createPrintFunctionMapPass); + + // Register passes used for internal testing. These don't show up in --help. + registerTestPass("catch-pop-fixup", + "fixup nested pops within catches", + createCatchPopFixupPass); + registerTestPass("experimental-type-generalizing", + "generalize types (not yet sound)", + createTypeGeneralizingPass); +#ifndef SKIP_OPTIMIZATIONS registerPass("alignment-lowering", "lower unaligned loads and stores to smaller aligned ones", createAlignmentLoweringPass); @@ -383,32 +414,9 @@ void PassRegistry::registerPasses() { "computes compile-time evaluatable expressions and propagates " "them through locals", createPrecomputePropagatePass); - registerPass("print", "print in s-expression format", createPrinterPass); - registerPass("print-minified", - "print in minified s-expression format", - createMinifiedPrinterPass); - registerPass("print-features", - "print options for enabled features", - createPrintFeaturesPass); - registerPass( - "print-full", "print in full s-expression format", createFullPrinterPass); - registerPass( - "print-call-graph", "print call graph", createPrintCallGraphPass); - - // Register PrintFunctionMap using its normal name. - registerPass("print-function-map", - "print a map of function indexes to names", - createPrintFunctionMapPass); - // Also register it as "symbolmap" so that wasm-opt --symbolmap=foo is the - // same as wasm-as --symbolmap=foo even though the latter is not a pass - // (wasm-as cannot run arbitrary passes). - // TODO: switch emscripten to this name, then remove the old one - registerPass( - "symbolmap", "(alias for print-function-map)", createPrintFunctionMapPass); - - registerPass("propagate-globals-globally", - "propagate global values to other globals (useful for tests)", - createPropagateGlobalsGloballyPass); + registerPass("propagate-globals-globally", + "propagate global values to other globals (useful for tests)", + createPropagateGlobalsGloballyPass); registerPass("remove-non-js-ops", "removes operations incompatible with js", createRemoveNonJSOpsPass); @@ -588,14 +596,7 @@ void PassRegistry::registerPasses() { registerPass("vacuum", "removes obviously unneeded code", createVacuumPass); // registerPass( // "lower-i64", "lowers i64 into pairs of i32s", createLowerInt64Pass); - - // Register passes used for internal testing. These don't show up in --help. - registerTestPass("catch-pop-fixup", - "fixup nested pops within catches", - createCatchPopFixupPass); - registerTestPass("experimental-type-generalizing", - "generalize types (not yet sound)", - createTypeGeneralizingPass); +#endif } void PassRunner::addIfNoDWARFIssues(std::string passName) { diff --git a/src/passes/passes.h b/src/passes/passes.h index e051e466e72..14b0d4f8869 100644 --- a/src/passes/passes.h +++ b/src/passes/passes.h @@ -22,6 +22,15 @@ namespace wasm { class Pass; // Normal passes: +Pass* createMinifiedPrinterPass(); +Pass* createFullPrinterPass(); +Pass* createPrinterPass(); +Pass* createPrintCallGraphPass(); +Pass* createPrintFeaturesPass(); +Pass* createPrintFunctionMapPass(); +Pass* createTypeGeneralizingPass(); + +#ifndef SKIP_OPTIMIZATIONS Pass* createAbstractTypeRefiningPass(); Pass* createAlignmentLoweringPass(); Pass* createAsyncifyPass(); @@ -51,7 +60,6 @@ Pass* createExtractFunctionPass(); Pass* createExtractFunctionIndexPass(); Pass* createFlattenPass(); Pass* createFuncCastEmulationPass(); -Pass* createFullPrinterPass(); Pass* createFunctionMetricsPass(); Pass* createGenerateDynCallsPass(); Pass* createGenerateI64DynCallsPass(); @@ -88,7 +96,6 @@ Pass* createMemoryPackingPass(); Pass* createMergeBlocksPass(); Pass* createMergeSimilarFunctionsPass(); Pass* createMergeLocalsPass(); -Pass* createMinifiedPrinterPass(); Pass* createMinifyImportsPass(); Pass* createMinifyImportsAndExportsPass(); Pass* createMinifyImportsAndExportsAndModulesPass(); @@ -125,10 +132,6 @@ Pass* createPoppifyPass(); Pass* createPostEmscriptenPass(); Pass* createPrecomputePass(); Pass* createPrecomputePropagatePass(); -Pass* createPrinterPass(); -Pass* createPrintCallGraphPass(); -Pass* createPrintFeaturesPass(); -Pass* createPrintFunctionMapPass(); Pass* createPropagateGlobalsGloballyPass(); Pass* createRemoveNonJSOpsPass(); Pass* createRemoveImportsPass(); @@ -181,7 +184,6 @@ Pass* createTranslateToExnrefPass(); Pass* createTrapModeClamp(); Pass* createTrapModeJS(); Pass* createTupleOptimizationPass(); -Pass* createTypeGeneralizingPass(); Pass* createTypeRefiningPass(); Pass* createTypeRefiningGUFAPass(); Pass* createTypeFinalizingPass(); @@ -191,6 +193,7 @@ Pass* createTypeUnFinalizingPass(); Pass* createUnsubtypingPass(); Pass* createUnteePass(); Pass* createVacuumPass(); +#endif // Test passes: Pass* createCatchPopFixupPass();