Skip to content

Latest commit

 

History

History
286 lines (211 loc) · 7.75 KB

File metadata and controls

286 lines (211 loc) · 7.75 KB

Polygeist LLVM 22.0.0 Compatibility Analysis & Patch Strategy

Critical Finding ⚠️

Polygeist Current Status:

  • Tracked LLVM Commit: 26eb4285b56edd8c897642078d91f16ff0fd3472
  • LLVM Version: 18.0.0 (NOT 22.0.0)
  • Gap: ~4 major LLVM versions behind (18 → 19 → 20 → 21 → 22)

Conclusion: You are 100% correct - Polygeist does NOT support LLVM 22 out of the box and requires patches.

Research Sources

Why Patches Are Needed

API Changes Between LLVM 18 → 22

LLVM/MLIR undergoes breaking API changes between major versions:

  1. MLIR Dialect Changes

    • New operations added
    • Deprecated operations removed
    • IR structure modifications
  2. C++ API Changes

    • Function signature changes
    • Class hierarchy modifications
    • Namespace reorganizations
  3. CMake Build Changes

    • Build system updates
    • Dependency handling changes
    • Plugin registration changes

Specific Areas Requiring Patches

Based on LLVM upgrade patterns, these areas will need patches:

1. MLIR Operation Definitions (HIGH PRIORITY)

  • File: lib/polygeist/Ops.cpp, include/polygeist/Ops.td
  • Issue: MLIR operation builder signatures changed
  • Fix: Update to new OpBuilder API

2. MLIR Pass Infrastructure (HIGH PRIORITY)

  • File: lib/polygeist/Passes/*.cpp
  • Issue: Pass registration API changed in LLVM 20+
  • Fix: Update from old PassRegistration<> to new registerPass()

3. Clang Frontend Integration (CRITICAL)

  • File: tools/cgeist/cgeist.cpp, lib/polygeist/ClangFrontend.cpp
  • Issue: Clang AST API changes
  • Fix: Update AST traversal and type handling

4. LLVM IR Conversion (MEDIUM PRIORITY)

  • File: lib/polygeist/Conversions/*.cpp
  • Issue: LLVM IR builder API changes
  • Fix: Update IR construction calls

5. CMake Build System (MEDIUM PRIORITY)

  • File: CMakeLists.txt, AddClang.cmake
  • Issue: LLVM CMake module changes
  • Fix: Update find_package(MLIR) and add_mlir_library()

Patch Strategy

Option 1: Upstream Patches (RECOMMENDED)

Check for existing LLVM 22 support work:

# Check Polygeist issues for LLVM 22 support
https://github.com/llvm/Polygeist/issues?q=is%3Aissue+llvm

# Check recent commits for version bumps
https://github.com/llvm/Polygeist/commits/main

If found: Use community patches If not found: We need to create patches

Option 2: Create Custom Patches

Step-by-step approach:

Patch 1: Update MLIR Operation Builders

// OLD (LLVM 18):
void buildOp(OpBuilder &builder, OperationState &state, ...) {
    builder.createOperation(state);
}

// NEW (LLVM 22):
void buildOp(OpBuilder &builder, OperationState &state, ...) {
    builder.create<OpType>(builder.getUnknownLoc(), ...);
}

Patch 2: Update Pass Registration

// OLD (LLVM 18):
void registerMyPass() {
    PassRegistration<MyPass>("my-pass", "Description");
}

// NEW (LLVM 22):
void registerMyPass() {
    mlir::registerPass([]() -> std::unique_ptr<Pass> {
        return std::make_unique<MyPass>();
    });
}

Patch 3: Update Clang AST Handling

// OLD (LLVM 18):
QualType getType(const Expr *E) {
    return E->getType();
}

// NEW (LLVM 22):
QualType getType(const Expr *E) {
    return E->getType().getCanonicalType();
}

Option 3: Pin to LLVM 18 (FALLBACK)

If patches are too complex, we can:

  1. Keep Polygeist on LLVM 18
  2. Use LLVM 22 for everything else (ClangIR, MLIR passes)
  3. Create conversion layer between LLVM 18 MLIR → LLVM 22 MLIR

Recommended Implementation Plan

Phase 1: Investigation (CURRENT)

  1. ✅ Confirm Polygeist uses LLVM 18
  2. ⏭️ Check Polygeist GitHub for LLVM 22 PRs/issues
  3. ⏭️ Test build Polygeist with LLVM 22 (collect errors)

Phase 2: Patch Identification

  1. Build Polygeist against LLVM 22 → collect ALL errors
  2. Categorize errors by:
    • MLIR API changes
    • Clang API changes
    • CMake changes
  3. Create patch list

Phase 3: Patch Creation

Create individual patches for each category:

patches/
├── 001-mlir-operation-builders.patch
├── 002-pass-registration.patch
├── 003-clang-ast-api.patch
├── 004-llvm-ir-conversion.patch
└── 005-cmake-build-system.patch

Phase 4: Dockerfile Integration

# Download Polygeist
RUN git clone https://github.com/llvm/Polygeist.git /opt/polygeist-source

# Apply LLVM 22 compatibility patches
WORKDIR /opt/polygeist-source
COPY patches/polygeist-llvm22/*.patch ./patches/
RUN for patch in patches/*.patch; do \
        patch -p1 < "$patch" || echo "Patch $patch failed"; \
    done

# Build with LLVM 22
RUN mkdir build && cd build && \
    cmake .. \
        -DLLVM_DIR=/usr/lib/llvm-22/lib/cmake/llvm \
        -DMLIR_DIR=/usr/lib/llvm-22/lib/cmake/mlir \
        -DCMAKE_BUILD_TYPE=Release && \
    ninja

Next Steps (ACTION ITEMS)

IMMEDIATE (Do First):

  1. Check Polygeist Issues for LLVM 22 work

    https://github.com/llvm/Polygeist/issues
    https://github.com/llvm/Polygeist/pulls
  2. Attempt build with LLVM 22 (collect errors)

    cd /tmp/polygeist-research
    mkdir build && cd build
    cmake .. \
        -DLLVM_DIR=/usr/lib/llvm-22/lib/cmake/llvm \
        -DMLIR_DIR=/usr/lib/llvm-22/lib/cmake/mlir
    ninja 2>&1 | tee build-errors.log
  3. Analyze build errors → create patch requirements list

MEDIUM TERM:

  1. Create patch files for each error category
  2. Test patches individually
  3. Integrate into Dockerfile

ALTERNATIVE (If patching too complex):

Use LLVM 18 for Polygeist, LLVM 22 for everything else:

# LLVM 22 - Main tools
ENV PATH="/usr/lib/llvm-22/bin:${PATH}"
ENV LLVM_DIR="/usr/lib/llvm-22/lib/cmake/llvm"
ENV MLIR_DIR="/usr/lib/llvm-22/lib/cmake/mlir"

# LLVM 18 - Polygeist only
RUN apt-get install llvm-18 llvm-18-dev
RUN git clone https://github.com/llvm/Polygeist.git && \
    cd Polygeist && \
    mkdir build && cd build && \
    cmake .. \
        -DLLVM_DIR=/usr/lib/llvm-18/lib/cmake/llvm \
        -DMLIR_DIR=/usr/lib/llvm-18/lib/cmake/mlir

Then create conversion layer:

C/C++ → Polygeist (LLVM 18) → MLIR (18) → Convert to MLIR (22) → Obfuscation passes (22)

Key Patch Areas Summary

Component Priority Complexity Estimated Effort
MLIR Op Builders HIGH Medium 4-6 hours
Pass Registration HIGH Low 1-2 hours
Clang AST API CRITICAL High 8-12 hours
LLVM IR Conversion MEDIUM Medium 3-4 hours
CMake Build MEDIUM Low 1-2 hours
TOTAL - - 17-26 hours

Decision Point

QUESTION FOR YOU:

  1. Attempt full LLVM 22 patches (17-26 hours of work, might fail)
  2. Use dual LLVM versions (18 for Polygeist, 22 for everything else)
  3. Skip Polygeist (focus on ClangIR only, which is LLVM 22 compatible)

My Recommendation: Option 2 or 3

  • Option 2: Keep working pipeline, add Polygeist as LLVM 18 addon
  • Option 3: Focus on ClangIR (which works with LLVM 22 out of box)

ClangIR is officially part of LLVM now and has native LLVM 22 support, making it the safer choice.


What should we do?

A) Try patching Polygeist for LLVM 22 (high risk, high effort) B) Use Polygeist with LLVM 18 (safe, proven) C) Focus on ClangIR only (safe, modern, LLVM 22 native)

Let me know your preference and I'll proceed accordingly!


Version: 1.0.0 Date: 2025-12-01 Status: Awaiting decision