بنقرة واحدة
dead-code-eliminator
Eliminate unreachable and unused code to reduce program size and improve performance.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Eliminate unreachable and unused code to reduce program size and improve performance.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Implement abstract machines for defining and executing operational semantics of programming languages.
Implements alias and points-to analysis for pointer programs. Use for: (1) Optimizing compilers, (2) Verifying memory safety, (3) Program understanding, (4) Parallelization.
Define program meaning through logical assertions and proof rules (Hoare logic).
Transforms closures to explicit environments. Use when: (1) Implementing functional languages, (2) Building compilers, (3) Understanding closures.
Implements common subexpression elimination (CSE). Use when: (1) Building compilers, (2) Optimizing code, (3) Program analysis.
Implements general dataflow analysis framework. Use when: (1) Building compilers, (2) Static analysis tools, (3) Program verification.
استنادا إلى تصنيف SOC المهني
| name | dead-code-eliminator |
| description | Eliminate unreachable and unused code to reduce program size and improve performance. |
| version | 1.0.0 |
| tags | ["compilation","optimization","llvm","pldi"] |
| difficulty | intermediate |
| languages | ["c++","rust","python"] |
| dependencies | ["dataflow-analysis-framework","control-flow-analysis"] |
Dead code elimination (DCE) removes code that has no effect on program output, including unreachable code, unused computations, and redundant assignments. It is a fundamental optimization in compilers.
| Concept | Description |
|---|---|
| Dead Code | Code that has no effect on program output |
| Unreachable Code | Code that cannot be executed |
| Live Variable | Variable that may be used later |
| Critical Instruction | Instruction with side effects |
| Fixpoint | State where no more changes occur |
constant-propagation-pass - Often combined with DCEinline-expander - Creates dead code opportunitiesdataflow-analysis-framework - Foundation for livenessssa-constructor - Simplifies analysis| Reference | Why It Matters |
|---|---|
| Muchnick, "Advanced Compiler Design and Implementation", Ch. 18 (1997) | Comprehensive treatment |
| Click & Cooper, "Combining Analyses, Optimizing and Using Them" (1995) | Modern DCE approach |
| LLVM Dead Code Elimination Pass | Production implementation |
| Approach | Pros | Cons |
|---|---|---|
| Simple DCE | Fast, easy | Misses opportunities |
| Aggressive DCE | Removes more code | More complex |
| ADCE with interprocedural | Global optimization | Very expensive |
A high-quality implementation should have:
| Criterion | What to Look For |
|---|---|
| Soundness | Never removes code that affects output |
| Completeness | Removes all provably dead code |
| Speed | Fast enough for production use |
| Iteration | Reaches fixpoint |
✅ Good: Removes all dead code, preserves semantics, fast ⚠️ Warning: Removes some but not all dead code ❌ Bad: Removes code that affects program output
Real-world DCE implementations:
| Tool | Why It Matters |
|---|---|
| LLVM DCE pass | Production DCE in LLVM |
| GCC DCE | GCC's dead code elimination |
| Soot DCE | Java bytecode DCE |
| GraalVM DCE | Truffle-based DCE |
Current DCE research:
| Direction | Key Papers | Challenge |
|---|---|---|
| Interprocedural DCE | "Whole-program DCE" | Cross-module analysis |
| Type-based DCE | "Type-driven DCE" | Type information |
| Dynamically dead | "Dynamic Dead Code" | Runtime dead code |
Common DCE bugs:
| Pitfall | Real Example | Prevention |
|---|---|---|
| Side effects | Removing print statements | Track I/O precisely |
| Volatile | Removing volatile reads | Handle volatile |
| Finalizers | Removing finalize() | Don't remove finalizers |
| Self-modifying | Removing JIT code | Handle dynamic code |