use std::str::FromStr;
#[derive(Eq, PartialEq, Debug)]
pub enum OptimizationPass {
AlignmentLowering,
Asyncify,
AvoidReinterprets,
Dae,
DaeOptimizing,
CoalesceLocals,
CoalesceLocalsLearning,
CodePushing,
CodeFolding,
ConstHoisting,
Dce,
Dealign,
Denan,
Directize,
Dfo,
Dwarfdump,
DuplicateImportElimination,
DuplicateFunctionElimination,
EmitTargetFeatures,
EmscriptenPic,
EmscriptenPicMainModule,
ExtractFunction,
Flatten,
FpcastEmu,
FuncMetrics,
GenerateDyncalls,
GenerateI64Dyncalls,
GenerateStackIr,
InlineMain,
Inlining,
InliningOptimizing,
LegalizeJsInterface,
LegalizeJsInterfaceMinimally,
LocalCse,
LogExecution,
I64ToI32Lowering,
InstrumentLocals,
InstrumentMemory,
Licm,
LimitSegments,
MemoryPacking,
MergeBlocks,
MergeLocals,
Metrics,
MinifyImports,
MinifyImportsAndExports,
MinifyImportsAndExportsAndModules,
ModAsyncifyAlwaysAndOnlyUnwind,
ModAsyncifyNeverUnwind,
Nm,
NoExitRuntime,
OptimizeAddedConstants,
OptimizeAddedConstantsPropagate,
OptimizeInstructions,
OptimizeStackIr,
PickLoadSigns,
PostAssemblyscript,
PostAssemblyscriptFinalize,
PostEmscripten,
Precompute,
PrecomputePropagate,
Print,
PrintMinified,
PrintFeatures,
PrintFull,
PrintCallGraph,
PrintFunctionMap,
PrintStackIr,
RemoveNonJsOps,
RemoveImports,
RemoveMemory,
RemoveUnusedBrs,
RemoveUnusedModuleElements,
RemoveUnusedNonfunctionModuleElements,
RemoveUnusedNames,
ReorderFunctions,
ReorderLocals,
Rereloop,
ReplaceStackPointer,
Rse,
Roundtrip,
SafeHeap,
SimplifyGlobals,
SimplifyGlobalsOptimizing,
SimplifyLocals,
SimplifyLocalsNonesting,
SimplifyLocalsNotee,
SimplifyLocalsNostructure,
SimplifyLocalsNoteeNostructure,
Souperify,
SouperifySingleUse,
SpillPointers,
StubUnsupportedJs,
Ssa,
SsaNomerge,
Strip,
StackCheck,
StripDebug,
StripDwarf,
StripProducers,
StripTargetFeatures,
TrapModeClamp,
TrapModeJs,
Untee,
Vacuum
}
impl FromStr for OptimizationPass {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"alignment-lowering" => Ok(OptimizationPass::AlignmentLowering),
"asyncify" => Ok(OptimizationPass::Asyncify),
"avoid-reinterprets" => Ok(OptimizationPass::AvoidReinterprets),
"dae" => Ok(OptimizationPass::Dae),
"dae-optimizing" => Ok(OptimizationPass::DaeOptimizing),
"coalesce-locals" => Ok(OptimizationPass::CoalesceLocals),
"coalesce-locals-learning" => Ok(OptimizationPass::CoalesceLocalsLearning),
"code-pushing" => Ok(OptimizationPass::CodePushing),
"code-folding" => Ok(OptimizationPass::CodeFolding),
"const-hoisting" => Ok(OptimizationPass::ConstHoisting),
"dce" => Ok(OptimizationPass::Dce),
"dealign" => Ok(OptimizationPass::Dealign),
"denan" => Ok(OptimizationPass::Denan),
"directize" => Ok(OptimizationPass::Directize),
"dfo" => Ok(OptimizationPass::Dfo),
"dwarfdump" => Ok(OptimizationPass::Dwarfdump),
"duplicate-import-elimination" => Ok(OptimizationPass::DuplicateImportElimination),
"duplicate-function-elimination" => Ok(OptimizationPass::DuplicateFunctionElimination),
"emit-target-features" => Ok(OptimizationPass::EmitTargetFeatures),
"emscripten-pic" => Ok(OptimizationPass::EmscriptenPic),
"emscripten-pic-main-module" => Ok(OptimizationPass::EmscriptenPicMainModule),
"extract-function" => Ok(OptimizationPass::ExtractFunction),
"flatten" => Ok(OptimizationPass::Flatten),
"fpcast-emu" => Ok(OptimizationPass::FpcastEmu),
"func-metrics" => Ok(OptimizationPass::FuncMetrics),
"generate-dyncalls" => Ok(OptimizationPass::GenerateDyncalls),
"generate-i64-dyncalls" => Ok(OptimizationPass::GenerateI64Dyncalls),
"generate-stack-ir" => Ok(OptimizationPass::GenerateStackIr),
"inline-main" => Ok(OptimizationPass::InlineMain),
"inlining" => Ok(OptimizationPass::Inlining),
"inlining-optimizing" => Ok(OptimizationPass::InliningOptimizing),
"legalize-js-interface" => Ok(OptimizationPass::LegalizeJsInterface),
"legalize-js-interface-minimally" => Ok(OptimizationPass::LegalizeJsInterfaceMinimally),
"local-cse" => Ok(OptimizationPass::LocalCse),
"log-execution" => Ok(OptimizationPass::LogExecution),
"i64-to-i32-lowering" => Ok(OptimizationPass::I64ToI32Lowering),
"instrument-locals" => Ok(OptimizationPass::InstrumentLocals),
"instrument-memory" => Ok(OptimizationPass::InstrumentMemory),
"licm" => Ok(OptimizationPass::Licm),
"limit-segments" => Ok(OptimizationPass::LimitSegments),
"memory-packing" => Ok(OptimizationPass::MemoryPacking),
"merge-blocks" => Ok(OptimizationPass::MergeBlocks),
"merge-locals" => Ok(OptimizationPass::MergeLocals),
"metrics" => Ok(OptimizationPass::Metrics),
"minify-imports" => Ok(OptimizationPass::MinifyImports),
"minify-imports-and-exports" => Ok(OptimizationPass::MinifyImportsAndExports),
"minify-imports-and-exports-and-modules" => Ok(OptimizationPass::MinifyImportsAndExportsAndModules),
"mod-asyncify-always-and-only-unwind" => Ok(OptimizationPass::ModAsyncifyAlwaysAndOnlyUnwind),
"mod-asyncify-never-unwind" => Ok(OptimizationPass::ModAsyncifyNeverUnwind),
"nm" => Ok(OptimizationPass::Nm),
"no-exit-runtime" => Ok(OptimizationPass::NoExitRuntime),
"optimize-added-constants" => Ok(OptimizationPass::OptimizeAddedConstants),
"optimize-added-constants-propagate" => Ok(OptimizationPass::OptimizeAddedConstantsPropagate),
"optimize-instructions" => Ok(OptimizationPass::OptimizeInstructions),
"optimize-stack-ir" => Ok(OptimizationPass::OptimizeStackIr),
"pick-load-signs" => Ok(OptimizationPass::PickLoadSigns),
"post-assemblyscript" => Ok(OptimizationPass::PostAssemblyscript),
"post-assemblyscript-finalize" => Ok(OptimizationPass::PostAssemblyscriptFinalize),
"post-emscripten" => Ok(OptimizationPass::PostEmscripten),
"precompute" => Ok(OptimizationPass::Precompute),
"precompute-propagate" => Ok(OptimizationPass::PrecomputePropagate),
"print" => Ok(OptimizationPass::Print),
"print-minified" => Ok(OptimizationPass::PrintMinified),
"print-features" => Ok(OptimizationPass::PrintFeatures),
"print-full" => Ok(OptimizationPass::PrintFull),
"print-call-graph" => Ok(OptimizationPass::PrintCallGraph),
"print-function-map" => Ok(OptimizationPass::PrintFunctionMap),
"print-stack-ir" => Ok(OptimizationPass::PrintStackIr),
"remove-non-js-ops" => Ok(OptimizationPass::RemoveNonJsOps),
"remove-imports" => Ok(OptimizationPass::RemoveImports),
"remove-memory" => Ok(OptimizationPass::RemoveMemory),
"remove-unused-brs" => Ok(OptimizationPass::RemoveUnusedBrs),
"remove-unused-module-elements" => Ok(OptimizationPass::RemoveUnusedModuleElements),
"remove-unused-nonfunction-module-elements" => Ok(OptimizationPass::RemoveUnusedNonfunctionModuleElements),
"remove-unused-names" => Ok(OptimizationPass::RemoveUnusedNames),
"reorder-functions" => Ok(OptimizationPass::ReorderFunctions),
"reorder-locals" => Ok(OptimizationPass::ReorderLocals),
"rereloop" => Ok(OptimizationPass::Rereloop),
"replace-stack-pointer" => Ok(OptimizationPass::ReplaceStackPointer),
"rse" => Ok(OptimizationPass::Rse),
"roundtrip" => Ok(OptimizationPass::Roundtrip),
"safe-heap" => Ok(OptimizationPass::SafeHeap),
"simplify-globals" => Ok(OptimizationPass::SimplifyGlobals),
"simplify-globals-optimizing" => Ok(OptimizationPass::SimplifyGlobalsOptimizing),
"simplify-locals" => Ok(OptimizationPass::SimplifyLocals),
"simplify-locals-nonesting" => Ok(OptimizationPass::SimplifyLocalsNonesting),
"simplify-locals-notee" => Ok(OptimizationPass::SimplifyLocalsNotee),
"simplify-locals-nostructure" => Ok(OptimizationPass::SimplifyLocalsNostructure),
"simplify-locals-notee-nostructure" => Ok(OptimizationPass::SimplifyLocalsNoteeNostructure),
"souperify" => Ok(OptimizationPass::Souperify),
"souperify-single-use" => Ok(OptimizationPass::SouperifySingleUse),
"spill-pointers" => Ok(OptimizationPass::SpillPointers),
"stub-unsupported-js" => Ok(OptimizationPass::StubUnsupportedJs),
"ssa" => Ok(OptimizationPass::Ssa),
"ssa-nomerge" => Ok(OptimizationPass::SsaNomerge),
"strip" => Ok(OptimizationPass::Strip),
"stack-check" => Ok(OptimizationPass::StackCheck),
"strip-debug" => Ok(OptimizationPass::StripDebug),
"strip-dwarf" => Ok(OptimizationPass::StripDwarf),
"strip-producers" => Ok(OptimizationPass::StripProducers),
"strip-target-features" => Ok(OptimizationPass::StripTargetFeatures),
"trap-mode-clamp" => Ok(OptimizationPass::TrapModeClamp),
"trap-mode-js" => Ok(OptimizationPass::TrapModeJs),
"untee" => Ok(OptimizationPass::Untee),
"vacuum" => Ok(OptimizationPass::Vacuum),
_ => Err(()),
}
}
}
trait OptimizationPassDescription {
fn description(&self) -> &'static str;
}
impl OptimizationPassDescription for OptimizationPass {
fn description(&self) -> &'static str {
match self {
OptimizationPass::AlignmentLowering => "lower unaligned loads and stores to smaller aligned ones",
OptimizationPass::Asyncify => "async/await style transform, allowing pausing and resuming",
OptimizationPass::AvoidReinterprets => "Tries to avoid reinterpret operations via more loads",
OptimizationPass::Dae => "removes arguments to calls in an lto-like manner",
OptimizationPass::DaeOptimizing => "optimizes where we removed",
OptimizationPass::CoalesceLocals => "reduce # of locals by coalescing",
OptimizationPass::CoalesceLocalsLearning => "reduce # of locals by coalescing and learning",
OptimizationPass::CodePushing => "push code forward, potentially making it not always execute",
OptimizationPass::CodeFolding => "fold code, merging duplicates",
OptimizationPass::ConstHoisting => "hoist repeated constants to a local",
OptimizationPass::Dce => "removes unreachable code",
OptimizationPass::Dealign => "forces all loads and stores to have alignment 1",
OptimizationPass::Denan => "instrument the wasm to convert NaNs into 0 at runtime",
OptimizationPass::Directize => "turns indirect calls into direct ones",
OptimizationPass::Dfo => "optimizes using the DataFlow SSA IR",
OptimizationPass::Dwarfdump => "dump DWARF debug info sections from the read binary",
OptimizationPass::DuplicateImportElimination => "removes duplicate imports",
OptimizationPass::DuplicateFunctionElimination => "removes duplicate functions",
OptimizationPass::EmitTargetFeatures => "emit the target features section in the output",
OptimizationPass::EmscriptenPic => "Convert PIC ABI from llvm to emscripten",
OptimizationPass::EmscriptenPicMainModule => "Convert PIC ABI from llvm to emscripten",
OptimizationPass::ExtractFunction => "leaves just one function (useful for debugging)",
OptimizationPass::Flatten => "flattens out code, removing nesting",
OptimizationPass::FpcastEmu => "calls to (sometimes) work",
OptimizationPass::FuncMetrics => "reports function metrics",
OptimizationPass::GenerateDyncalls => "generate dynCall fuctions used by emscripten ABI",
OptimizationPass::GenerateI64Dyncalls => "via the wasm table without JavaScript BigInt support).",
OptimizationPass::GenerateStackIr => "generate Stack IR",
OptimizationPass::InlineMain => "inline __original_main into main",
OptimizationPass::Inlining => "inline functions (you probably want inlining-optimizing)",
OptimizationPass::InliningOptimizing => "inline functions and optimizes where we inlined",
OptimizationPass::LegalizeJsInterface => "legalizes i64 types on the import/export boundary",
OptimizationPass::LegalizeJsInterfaceMinimally => "manner, only on things only JS will call",
OptimizationPass::LocalCse => "common subexpression elimination inside basic blocks",
OptimizationPass::LogExecution => "instrument the build with logging of where execution goes",
OptimizationPass::I64ToI32Lowering => "lower all uses of i64s to use i32s instead",
OptimizationPass::InstrumentLocals => "instrument the build with code to intercept all loads and stores",
OptimizationPass::InstrumentMemory => "instrument the build with code to intercept all loads and stores",
OptimizationPass::Licm => "loop invariant code motion",
OptimizationPass::LimitSegments => "attempt to merge segments to fit within web limits",
OptimizationPass::MemoryPacking => "packs memory into separate segments, skipping zeros",
OptimizationPass::MergeBlocks => "merges blocks to their parents",
OptimizationPass::MergeLocals => "merges locals when beneficial",
OptimizationPass::Metrics => "reports metrics",
OptimizationPass::MinifyImports => "emits a mapping to the minified ones",
OptimizationPass::MinifyImportsAndExports => "the minified ones",
OptimizationPass::MinifyImportsAndExportsAndModules => "the minified ones, and minifies the modules as well",
OptimizationPass::ModAsyncifyAlwaysAndOnlyUnwind => "and we never rewind",
OptimizationPass::ModAsyncifyNeverUnwind => "apply the assumption that asyncify never unwinds",
OptimizationPass::Nm => "name list",
OptimizationPass::NoExitRuntime => "will never be exited",
OptimizationPass::OptimizeAddedConstants => "optimizes added constants into load/store offsets",
OptimizationPass::OptimizeAddedConstantsPropagate => "them across locals too",
OptimizationPass::OptimizeInstructions => "optimizes instruction combinations",
OptimizationPass::OptimizeStackIr => "optimize Stack IR",
OptimizationPass::PickLoadSigns => "pick load signs based on their uses",
OptimizationPass::PostAssemblyscript => "eliminates redundant ARC patterns in AssemblyScript output",
OptimizationPass::PostAssemblyscriptFinalize => "eliminates collapsed ARC patterns after other optimizations",
OptimizationPass::PostEmscripten => "miscellaneous optimizations for Emscripten-generated code",
OptimizationPass::Precompute => "computes compile-time evaluatable expressions",
OptimizationPass::PrecomputePropagate => "them through locals",
OptimizationPass::Print => "print in s-expression format",
OptimizationPass::PrintMinified => "print in minified s-expression format",
OptimizationPass::PrintFeatures => "print options for enabled features",
OptimizationPass::PrintFull => "print in full s-expression format",
OptimizationPass::PrintCallGraph => "print call graph",
OptimizationPass::PrintFunctionMap => "print a map of function indexes to names",
OptimizationPass::PrintStackIr => "print out Stack IR (useful for internal debugging)",
OptimizationPass::RemoveNonJsOps => "removes operations incompatible with js",
OptimizationPass::RemoveImports => "removes imports and replaces them with nops",
OptimizationPass::RemoveMemory => "removes memory segments",
OptimizationPass::RemoveUnusedBrs => "removes breaks from locations that are not needed",
OptimizationPass::RemoveUnusedModuleElements => "removes unused module elements",
OptimizationPass::RemoveUnusedNonfunctionModuleElements => "removes unused module elements that are not functions",
OptimizationPass::RemoveUnusedNames => "removes names from locations that are never branched to",
OptimizationPass::ReorderFunctions => "sorts functions by access frequency",
OptimizationPass::ReorderLocals => "sorts locals by access frequency",
OptimizationPass::Rereloop => "re-optimize control flow using the relooper algorithm",
OptimizationPass::ReplaceStackPointer => "imported functions.",
OptimizationPass::Rse => "remove redundant local.sets",
OptimizationPass::Roundtrip => "write the module to binary, then read it",
OptimizationPass::SafeHeap => "instrument loads and stores to check for invalid behavior",
OptimizationPass::SimplifyGlobals => "miscellaneous globals-related optimizations",
OptimizationPass::SimplifyGlobalsOptimizing => "where we replaced global.gets with constants",
OptimizationPass::SimplifyLocals => "miscellaneous locals-related optimizations",
OptimizationPass::SimplifyLocalsNonesting => "preserves flatness)",
OptimizationPass::SimplifyLocalsNotee => "miscellaneous locals-related optimizations (no tees)",
OptimizationPass::SimplifyLocalsNostructure => "miscellaneous locals-related optimizations (no structure)",
OptimizationPass::SimplifyLocalsNoteeNostructure => "miscellaneous locals-related optimizations (no tees or structure)",
OptimizationPass::Souperify => "emit Souper IR in text form",
OptimizationPass::SouperifySingleUse => "emit Souper IR in text form (single-use nodes only)",
OptimizationPass::SpillPointers => "spill pointers to the C stack (useful for Boehm-style GC)",
OptimizationPass::StubUnsupportedJs => "stub out unsupported JS operations",
OptimizationPass::Ssa => "ssa-ify variables so that they have a single assignment",
OptimizationPass::SsaNomerge => "ssa-ify variables so that they have a single assignment, ignoring merges",
OptimizationPass::Strip => "deprecated; same as strip-debug",
OptimizationPass::StackCheck => "enforce limits on llvm's __stack_pointer global",
OptimizationPass::StripDebug => "strip debug info (including the names section)",
OptimizationPass::StripDwarf => "strip dwarf debug info",
OptimizationPass::StripProducers => "strip the wasm producers section",
OptimizationPass::StripTargetFeatures => "strip the wasm target features section",
OptimizationPass::TrapModeClamp => "replace trapping operations with clamping semantics",
OptimizationPass::TrapModeJs => "replace trapping operations with js semantics",
OptimizationPass::Untee => "removes local.tees, replacing them with sets and gets",
OptimizationPass::Vacuum => "removes obviously unneeded code"
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_from_str() {
assert_eq!(OptimizationPass::AlignmentLowering, OptimizationPass::from_str("alignment-lowering").expect("from_str expected to work"));
}
#[test]
fn test_description() {
assert_eq!(OptimizationPass::AlignmentLowering.description(), "lower unaligned loads and stores to smaller aligned ones");
}
}