From 6fb1fecc71c6c604943717d6a72f4810090017a6 Mon Sep 17 00:00:00 2001 From: MrAzteca Date: Wed, 25 Sep 2024 23:52:39 +0200 Subject: [PATCH] Update LLVM 19. (#763) * Update LLVM 19. * update ffi.cpp * remove unused ffi functions * Make dependencies non-path-relative. * change ci * use lambda repos2 * update all ci * use oficial deps * upd readme * update dockerfile * update bench script * relax libc version * relax libc version * remove ffi cpp code no longer needed * remove ffi * upd env.sh --------- Co-authored-by: Edgar --- .github/workflows/bench-hyperfine.yml | 52 ++--- .github/workflows/ci.yml | 46 ++-- .github/workflows/publish.yml | 10 +- .github/workflows/release.yml | 10 +- .github/workflows/rustdoc.yml | 10 +- Cargo.lock | 138 ++++++------ Cargo.toml | 42 ++-- Dockerfile | 20 +- Makefile | 12 +- README.md | 42 ++-- build.rs | 16 -- env.sh | 24 +-- runtime/Cargo.toml | 2 +- scripts/bench-hyperfine.sh | 4 +- src/compiler.rs | 16 +- src/context.rs | 20 +- src/ffi.cpp | 291 -------------------------- src/ffi.rs | 187 +---------------- 18 files changed, 244 insertions(+), 698 deletions(-) delete mode 100644 build.rs delete mode 100644 src/ffi.cpp diff --git a/.github/workflows/bench-hyperfine.yml b/.github/workflows/bench-hyperfine.yml index 012084b9d..feb5513c4 100644 --- a/.github/workflows/bench-hyperfine.yml +++ b/.github/workflows/bench-hyperfine.yml @@ -19,9 +19,9 @@ jobs: runs-on: ubuntu-latest env: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ steps: - uses: actions/checkout@v4 - name: check and free hdd space left @@ -50,11 +50,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Install hyperfine uses: taiki-e/install-action@v2 with: @@ -86,12 +86,12 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body-path: bench-hyperfine.md edit-mode: replace - + build-binaries: env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ RUST_LOG: cairo_native=debug,cairo_native_test=debug strategy: matrix: @@ -101,18 +101,18 @@ jobs: steps: - name: Cache binary uses: actions/cache@v3 - id: cache-binary + id: cache-binary with: path: bin/cairo-native-run-${{ matrix.branch }} key: binary-${{ github.event.pull_request[matrix.branch].sha }} - + - name: Cache runtime-library uses: actions/cache@v3 - id: cache-library + id: cache-library with: path: lib/libcairo-native-runtime-${{ matrix.branch }}.a - key: library-${{ github.event.pull_request[matrix.branch].sha }} - + key: library-${{ github.event.pull_request[matrix.branch].sha }} + - name: check and free hdd space left if: ${{ steps.cache-binary.outputs.cache-hit != 'true' }} run: | @@ -137,29 +137,29 @@ jobs: - name: Install Rust if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} uses: dtolnay/rust-toolchain@1.81.0 - + - name: add llvm deb repository if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - + - name: Install LLVM if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} - run: sudo apt-get update && sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get update && sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Checkout base commit if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request[matrix.branch].sha }} - + - name: Fetch Rust cache if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} uses: Swatinem/rust-cache@v2 - + - name: Build binary if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} run: | @@ -167,7 +167,7 @@ jobs: mkdir lib bin cp target/release/cairo-native-run bin/cairo-native-run-${{ matrix.branch }} cp target/release/libcairo_native_runtime.a lib/libcairo-native-runtime-${{ matrix.branch }}.a - + hyperfine-prs: name: Bench PR (linux, amd64) needs: [ build-binaries ] @@ -219,10 +219,10 @@ jobs: --export-markdown "${f%.*}.md" \ --export-json "${f%.*}.json" \ --warmup 3 \ - -n "head $(basename $f) (JIT)" "./bin/cairo-native-run-head --run-mode=jit -s $f --opt-level 3 --available-gas 18446744073709551615" \ - -n "base $(basename $f) (JIT)" "./bin/cairo-native-run-base --run-mode=jit -s $f --opt-level 3 --available-gas 18446744073709551615" \ - -n "head $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-head.a ./bin/cairo-native-run-head --run-mode=aot -s $f --opt-level 3 --available-gas 18446744073709551615" \ - -n "base $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-base.a ./bin/cairo-native-run-base --run-mode=aot -s $f --opt-level 3 --available-gas 18446744073709551615" \ + -n "head $(basename $f) (JIT)" "./bin/cairo-native-run-head --run-mode=jit -s $f --opt-level 3 --available-gas 19446744073709551615" \ + -n "base $(basename $f) (JIT)" "./bin/cairo-native-run-base --run-mode=jit -s $f --opt-level 3 --available-gas 19446744073709551615" \ + -n "head $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-head.a ./bin/cairo-native-run-head --run-mode=aot -s $f --opt-level 3 --available-gas 19446744073709551615" \ + -n "base $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-base.a ./bin/cairo-native-run-base --run-mode=aot -s $f --opt-level 3 --available-gas 19446744073709551615" \ >> /dev/stderr done - name: Print tables @@ -243,7 +243,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} comment-author: "github-actions[bot]" body-includes: Benchmarking - + - name: Create or update bench comment continue-on-error: true uses: peter-evans/create-or-update-comment@v4 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dee8fb75..a3b76e004 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,9 +16,9 @@ jobs: name: clippy runs-on: ubuntu-latest env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.81.0 @@ -28,11 +28,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Clippy run: make check @@ -83,9 +83,9 @@ jobs: udeps: runs-on: ubuntu-latest env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ RUSTUP_TOOLCHAIN: nightly # udeps needs nightly steps: - uses: actions/checkout@v4 @@ -97,11 +97,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: "Download and run cargo-udeps" run: | wget -O - -c https://github.com/est31/cargo-udeps/releases/download/v0.1.50/cargo-udeps-v0.1.50-x86_64-unknown-linux-gnu.tar.gz | tar -xz @@ -111,9 +111,9 @@ jobs: name: test (linux, amd64) runs-on: ubuntu-latest env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ RUST_LOG: cairo_native=debug,cairo_native_test=debug steps: - uses: actions/checkout@v4 @@ -143,12 +143,12 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - run: sudo apt-get update && sudo apt-get upgrade -y - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Install deps run: make deps - name: Build cairo-native-runtime library. @@ -164,9 +164,9 @@ jobs: env: CARGO_TERM_COLOR: always LIBRARY_PATH: /opt/homebrew/lib - MLIR_SYS_180_PREFIX: /opt/homebrew/opt/llvm@18 - LLVM_SYS_181_PREFIX: /opt/homebrew/opt/llvm@18 - TABLEGEN_180_PREFIX: /opt/homebrew/opt/llvm@18 + MLIR_SYS_190_PREFIX: /opt/homebrew/opt/llvm@19 + LLVM_SYS_191_PREFIX: /opt/homebrew/opt/llvm@19 + TABLEGEN_190_PREFIX: /opt/homebrew/opt/llvm@19 RUST_LOG: cairo_native=debug,cairo_native_test=debug steps: - uses: actions/checkout@v4 @@ -207,9 +207,9 @@ jobs: output: lcov-4.info env: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ RUST_LOG: cairo_native=debug steps: - uses: actions/checkout@v4 @@ -239,11 +239,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Install testing tools uses: taiki-e/install-action@v2 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 343c5a58c..554118a8a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,9 +13,9 @@ jobs: release: runs-on: ubuntu-latest env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} steps: - name: Checkout @@ -32,11 +32,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: publish the runtime run: cargo publish --token ${CRATES_TOKEN} --all-features -p cairo-native-runtime - name: publish the crate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eae84c486..2ec185740 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,9 +13,9 @@ jobs: release: runs-on: ubuntu-latest env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ steps: - name: Checkout uses: actions/checkout@v3 @@ -31,11 +31,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: build release run: make build - name: Release diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index 328f0c5f5..c7a8b2fbb 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -13,9 +13,9 @@ jobs: name: GitHub Pages runs-on: ubuntu-latest env: - MLIR_SYS_180_PREFIX: /usr/lib/llvm-18/ - LLVM_SYS_181_PREFIX: /usr/lib/llvm-18/ - TABLEGEN_180_PREFIX: /usr/lib/llvm-18/ + MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.81.0 @@ -23,11 +23,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools + run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools - name: Build docs run: make doc - name: Deploy Documentation diff --git a/Cargo.lock b/Cargo.lock index d104810f4..97cf3008d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,9 +103,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.88" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "aquamarine" @@ -320,6 +320,26 @@ dependencies = [ "which", ] +[[package]] +name = "bindgen" +version = "0.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools 0.13.0", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.77", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -997,7 +1017,7 @@ dependencies = [ "lazy_static", "libc", "rand", - "starknet-curve 0.5.0", + "starknet-curve 0.5.1", "starknet-types-core", ] @@ -1064,9 +1084,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.18" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ "jobserver", "libc", @@ -1138,9 +1158,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" dependencies = [ "clap_builder", "clap_derive", @@ -1148,9 +1168,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" dependencies = [ "anstream", "anstyle", @@ -1160,9 +1180,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -1194,9 +1214,9 @@ dependencies = [ [[package]] name = "comrak" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d061c6d53fe98c25efda0d91b7f6b4b4020a51dad78a3eac5028710aa26f8e7" +checksum = "c93ab3577cca16b4a1d80a88c2e0cd8b6e969e51696f0bbb0d1dcb0157109832" dependencies = [ "caseless", "derive_builder", @@ -2182,9 +2202,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", @@ -2284,9 +2304,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -2322,9 +2342,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "llvm-sys" -version = "181.2.0" +version = "191.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d320f9d2723c97d4b78f9190a61ed25cc7cfbe456668c08e6e7dd8e50ceb8500" +checksum = "893cddf1adf0354b93411e413553dd4daf5c43195d73f1acfa1e394bdd371456" dependencies = [ "anyhow", "cc", @@ -2379,9 +2399,9 @@ dependencies = [ [[package]] name = "melior" -version = "0.18.6" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3085c0169aa3b735d8e7df582baee23c2aeb280ea62cc7f71effda28d8e281" +checksum = "c5d97014786c173a839839e2a068e82516ad1eb94fca1d40013d3c5e224e7c1e" dependencies = [ "dashmap", "melior-macro", @@ -2391,9 +2411,9 @@ dependencies = [ [[package]] name = "melior-macro" -version = "0.11.6" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d58c356ebaa7855da67aad1306a0d032b68919d3c65b0b5dcecf10d9bdf6a9" +checksum = "ef7ae0ba2f96784ec407d58374c8477f5b04ec8c57a114cafef0c8f165c4b288" dependencies = [ "comrak", "convert_case", @@ -2439,11 +2459,11 @@ dependencies = [ [[package]] name = "mlir-sys" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1b5806a63bc959cd5c4e5db8cadd20e40045d41969d325132748db8af11b7f" +checksum = "fae0a14b0940736a243fef4a4d96d8cdf8a253272031b63c5e4b1bea207c82b0" dependencies = [ - "bindgen", + "bindgen 0.70.1", ] [[package]] @@ -2755,9 +2775,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plotters" @@ -2789,9 +2809,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "d30538d42559de6b034bc76fd6dd4c38961b1ee5c6c56e3808c50128fdbc22ce" [[package]] name = "powerfmt" @@ -2816,9 +2836,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "pretty_assertions" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", "yansi", @@ -3003,9 +3023,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "62871f2d65009c0256aed1b9cfeeb8ac272833c404e13d53d400cd0dad7a2ac0" dependencies = [ "bitflags", ] @@ -3523,9 +3543,9 @@ dependencies = [ [[package]] name = "starknet-curve" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56935b306dcf0b8f14bb2a1257164b8478bb8be4801dfae0923f5b266d1b457c" +checksum = "bcde6bd74269b8161948190ace6cf069ef20ac6e79cd2ba09b320efa7500b6de" dependencies = [ "starknet-types-core", ] @@ -3544,9 +3564,9 @@ dependencies = [ [[package]] name = "starknet-types-core" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6bacf0ba19bc721e518bc4bf389ff13daa8a7c5db5fd320600473b8aa9fcbd" +checksum = "9b889ee5734db8b3c8a6551135c16764bf4ce1ab4955fffbb2ac5b6706542b64" dependencies = [ "lambdaworks-crypto", "lambdaworks-math 0.7.0", @@ -3618,11 +3638,11 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tblgen-alt" -version = "0.3.6" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ae726d43658a13a9cd479de814be1311fea69236cd821e931a4fb9ca4d70e50" +checksum = "0ecbc9175dd38627cd01d546e7b41c9a115e5773f4c98f64e2185c81ec5f45ab" dependencies = [ - "bindgen", + "bindgen 0.69.4", "cc", "paste", "thiserror", @@ -3687,18 +3707,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -3811,9 +3831,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap 2.5.0", "serde", @@ -3941,30 +3961,30 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "unicode_categories" @@ -4291,9 +4311,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "c52ac009d615e79296318c1bcce2d422aaca15ad08515e344feeda07df67a587" dependencies = [ "memchr", ] @@ -4324,9 +4344,9 @@ checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" [[package]] name = "yansi" -version = "0.5.1" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" diff --git a/Cargo.toml b/Cargo.toml index 4e54df248..7e63c406f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,12 +39,12 @@ required-features = ["scarb"] [features] default = ["build-cli", "with-runtime"] build-cli = [ - "dep:clap", - "dep:tracing-subscriber", - "dep:anyhow", - "dep:cairo-lang-test-plugin", - "dep:cairo-lang-runner", - "dep:colored", + "dep:clap", + "dep:tracing-subscriber", + "dep:anyhow", + "dep:cairo-lang-test-plugin", + "dep:cairo-lang-runner", + "dep:colored", ] scarb = ["build-cli", "dep:scarb-ui", "dep:scarb-metadata"] with-debug-utils = [] @@ -68,19 +68,21 @@ cairo-lang-diagnostics = "2.8.2" educe = "0.5.11" # can't update until https://github.com/magiclen/educe/issues/27 itertools = "0.13.0" lazy_static = "1.4" -libc = "0.2.155" -llvm-sys = "181.1.0" -melior = { version = "0.18.4", features = ["ods-dialects"] } -mlir-sys = "0.2.2" +libc = "0.2" +llvm-sys = "191.0.0" +melior = { version = "0.19.0", features = [ + "ods-dialects", +] } +mlir-sys = { version = "0.3.0"} num-bigint = "0.4.4" num-traits = "0.2" starknet-types-core = { version = "0.1.5", default-features = false, features = [ - "std", - "serde", - "num-traits", + "std", + "serde", + "num-traits", ] } tempfile = "3.6" -thiserror = "1.0.59" +thiserror = "1.0.64" tracing = "0.1" utf8_iter = "1.0.4" @@ -92,12 +94,12 @@ cairo-lang-starknet = "2.8.2" cairo-lang-utils = "2.8.2" cairo-lang-starknet-classes = "2.8.2" cairo-native-runtime = { version = "0.2.0", path = "runtime", optional = true } -clap = { version = "4.5", features = ["derive"], optional = true } +clap = { version = "4.5.18", features = ["derive"], optional = true } libloading = "0.8.3" tracing-subscriber = { version = "0.3.18", features = [ - "env-filter", - "json", - "registry", + "env-filter", + "json", + "registry", ], optional = true } serde = { version = "1.0", features = ["derive"] } anyhow = { version = "1.0", optional = true } @@ -106,7 +108,7 @@ cairo-lang-runner = { version = "2.8.2", optional = true } colored = { version = "2.1.0", optional = true } # needed to interface with cairo-lang-* keccak = "0.1.5" -k256 = "0.13.3" +k256 = "0.13.4" p256 = "0.13.2" sha2 = "0.10.8" # needed for the syscall handler stub scarb-metadata = { git = "https://github.com/software-mansion/scarb.git", rev = "v2.8.2", optional = true } @@ -129,7 +131,7 @@ walkdir = "2.5.0" serde_json = { version = "1.0.117" } [build-dependencies] -cc = "1.1.14" +cc = "1.1.21" [profile.optimized-dev] inherits = "dev" diff --git a/Dockerfile b/Dockerfile index ad01a144e..24c5c73a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,15 +10,15 @@ RUN apt update -y && apt install -y lsb-release \ libz-dev \ libzstd-dev -# Install LLVM 18 -RUN echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-18 main" > /etc/apt/sources.list.d/llvm-18.list -RUN echo "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-18 main" >> /etc/apt/sources.list.d/llvm-18.list +# Install LLVM 19 +RUN echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main" > /etc/apt/sources.list.d/llvm-19.list +RUN echo "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main" >> /etc/apt/sources.list.d/llvm-19.list RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - RUN apt update -y && apt install -y \ - libmlir-18-dev \ - libpolly-18-dev \ - llvm-18-dev \ - mlir-18-tools + libmlir-19-dev \ + libpolly-19-dev \ + llvm-19-dev \ + mlir-19-tools # Install rust RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y @@ -29,8 +29,8 @@ COPY . /cairo_native/ # Compile cairo_native WORKDIR /cairo_native/ -ENV MLIR_SYS_180_PREFIX=/usr/lib/llvm-18 -ENV LLVM_SYS_181_PREFIX=/usr/lib/llvm-18 -ENV TABLEGEN_180_PREFIX=/usr/lib/llvm-18 +ENV MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 +ENV LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 +ENV TABLEGEN_190_PREFIX=/usr/lib/llvm-19 RUN make deps RUN make build diff --git a/Makefile b/Makefile index e18e5b9f2..c66cabdd4 100644 --- a/Makefile +++ b/Makefile @@ -29,13 +29,13 @@ usage: check-llvm needs-cairo2 .PHONY: check-llvm check-llvm: -ifndef MLIR_SYS_180_PREFIX - $(error Could not find a suitable LLVM 18 toolchain (mlir), please set MLIR_SYS_180_PREFIX env pointing to the LLVM 18 dir) +ifndef MLIR_SYS_190_PREFIX + $(error Could not find a suitable LLVM 19 toolchain (mlir), please set MLIR_SYS_190_PREFIX env pointing to the LLVM 19 dir) endif -ifndef TABLEGEN_180_PREFIX - $(error Could not find a suitable LLVM 18 toolchain (tablegen), please set TABLEGEN_180_PREFIX env pointing to the LLVM 18 dir) +ifndef TABLEGEN_190_PREFIX + $(error Could not find a suitable LLVM 19 toolchain (tablegen), please set TABLEGEN_190_PREFIX env pointing to the LLVM 19 dir) endif - @echo "LLVM is correctly set at $(MLIR_SYS_180_PREFIX)." + @echo "LLVM is correctly set at $(MLIR_SYS_190_PREFIX)." .PHONY: needs-cairo2 needs-cairo2: @@ -135,7 +135,7 @@ endif .PHONY: deps-macos deps-macos: build-cairo-2-compiler-macos install-scarb-macos - -brew install llvm@18 --quiet + -brew install llvm@19 --quiet @echo "You can execute the env-macos.sh script to setup the needed env variables." cairo-repo-2-dir = cairo2 diff --git a/README.md b/README.md index 266e1baf9..6fb737235 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ use. This can be done by adding `cairo-native = "0.1.0"` to your Cargo.toml ### Dependencies - Linux or macOS (aarch64 included) only for now -- LLVM 18 with MLIR: On debian you can use [apt.llvm.org](https://apt.llvm.org/), +- LLVM 19 with MLIR: On debian you can use [apt.llvm.org](https://apt.llvm.org/), on macOS you can use brew - Rust 1.78.0 or later, since we make use of the u128 [abi change](https://blog.rust-lang.org/2024/03/30/i128-layout-update.html). @@ -61,14 +61,14 @@ make deps ``` #### Linux -Since Linux distributions change widely, you need to install LLVM 18 via your +Since Linux distributions change widely, you need to install LLVM 19 via your package manager, compile it or check if the current release has a Linux binary. If you are on Debian/Ubuntu, check out the repository https://apt.llvm.org/ Then you can install with: ```bash -sudo apt-get install llvm-18 llvm-18-dev llvm-18-runtime clang-18 clang-tools-18 lld-18 libpolly-18-dev libmlir-18-dev mlir-18-tools +sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools ``` If you decide to build from source, here are some indications: @@ -77,23 +77,23 @@ If you decide to build from source, here are some indications: ```bash # Go to https://github.com/llvm/llvm-project/releases -# Download the latest LLVM 18 release: -# The blob to download is called llvm-project-18.x.x.src.tar.xz +# Download the latest LLVM 19 release: +# The blob to download is called llvm-project-19.x.x.src.tar.xz # For example -wget https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.7/llvm-project-18.1.7.src.tar.xz -tar xf llvm-project-18.1.7.src.tar.xz +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.0/llvm-project-19.1.0.src.tar.xz +tar xf llvm-project-19.1.0.src.tar.xz -cd llvm-project-18.1.7.src.tar +cd llvm-project-19.1.0.src.tar mkdir build cd build -# The following cmake command configures the build to be installed to /opt/llvm-18 +# The following cmake command configures the build to be installed to /opt/llvm-19 cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld;polly" \ -DLLVM_BUILD_EXAMPLES=OFF \ -DLLVM_TARGETS_TO_BUILD="Native" \ - -DCMAKE_INSTALL_PREFIX=/opt/llvm-18 \ + -DCMAKE_INSTALL_PREFIX=/opt/llvm-19 \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DLLVM_PARALLEL_LINK_JOBS=4 \ -DLLVM_ENABLE_BINDINGS=OFF \ @@ -105,14 +105,14 @@ ninja install -Setup a environment variable called `MLIR_SYS_180_PREFIX`, `LLVM_SYS_181_PREFIX` -and `TABLEGEN_180_PREFIX` pointing to the llvm directory: +Setup a environment variable called `MLIR_SYS_190_PREFIX`, `LLVM_SYS_191_PREFIX` +and `TABLEGEN_190_PREFIX` pointing to the llvm directory: ```bash -# For Debian/Ubuntu using the repository, the path will be /usr/lib/llvm-18 -export MLIR_SYS_180_PREFIX=/usr/lib/llvm-18 -export LLVM_SYS_181_PREFIX=/usr/lib/llvm-18 -export TABLEGEN_180_PREFIX=/usr/lib/llvm-18 +# For Debian/Ubuntu using the repository, the path will be /usr/lib/llvm-19 +export MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 +export LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 +export TABLEGEN_190_PREFIX=/usr/lib/llvm-19 ``` Alternatively, if installed from Debian/Ubuntu repository, then you can use @@ -123,7 +123,7 @@ source env.sh ``` #### MacOS -The makefile `deps` target (which you should have ran before) installs LLVM 18 +The makefile `deps` target (which you should have ran before) installs LLVM 19 with brew for you, afterwards you need to execute the `env.sh` script to setup the needed environment variables. @@ -350,14 +350,14 @@ Options: - [hyperfine](https://github.com/sharkdp/hyperfine): `cargo install hyperfine` - [cairo 2.8.2](https://github.com/starkware-libs/cairo) - Cairo Corelibs -- LLVM 18 with MLIR +- LLVM 19 with MLIR You need to setup some environment variables: ```bash -$MLIR_SYS_180_PREFIX=/path/to/llvm18 # Required for non-standard LLVM install locations. -$LLVM_SYS_181_PREFIX=/path/to/llvm18 # Required for non-standard LLVM install locations. -$TABLEGEN_180_PREFIX=/path/to/llvm18 # Required for non-standard LLVM install locations. +$MLIR_SYS_190_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations. +$LLVM_SYS_191_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations. +$TABLEGEN_190_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations. ``` You can then run the `bench` makefile target: diff --git a/build.rs b/build.rs deleted file mode 100644 index 85c513ff6..000000000 --- a/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::env::var; - -fn main() { - let mlir_path = var("MLIR_SYS_180_PREFIX").expect("MLIR path should be set."); - - cc::Build::new() - .cpp(true) - .flag("-std=c++17") - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-comment") - .include(format!("{mlir_path}/include")) - .file("src/ffi.cpp") - .compile("ffi"); - - println!("cargo:rerun-if-changed=src/ffi.cpp"); -} diff --git a/env.sh b/env.sh index 5539203ef..df9e250f5 100644 --- a/env.sh +++ b/env.sh @@ -8,27 +8,27 @@ case $(uname) in Darwin) # If installed with brew LIBRARY_PATH=/opt/homebrew/lib - MLIR_SYS_180_PREFIX="$(brew --prefix llvm@18)" - LLVM_SYS_181_PREFIX="$(brew --prefix llvm@18)" - TABLEGEN_180_PREFIX="$(brew --prefix llvm@18)" + MLIR_SYS_190_PREFIX="$(brew --prefix llvm@19)" + LLVM_SYS_191_PREFIX="$(brew --prefix llvm@19)" + TABLEGEN_190_PREFIX="$(brew --prefix llvm@19)" CAIRO_NATIVE_RUNTIME_LIBDIR="$(pwd)/target/debug" export LIBRARY_PATH - export MLIR_SYS_180_PREFIX - export LLVM_SYS_181_PREFIX - export TABLEGEN_180_PREFIX + export MLIR_SYS_190_PREFIX + export LLVM_SYS_191_PREFIX + export TABLEGEN_190_PREFIX export CAIRO_NATIVE_RUNTIME_LIBDIR ;; Linux) # If installed from Debian/Ubuntu repository: - MLIR_SYS_180_PREFIX=/usr/lib/llvm-18 - LLVM_SYS_181_PREFIX=/usr/lib/llvm-18 - TABLEGEN_180_PREFIX=/usr/lib/llvm-18 + MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 + LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 + TABLEGEN_190_PREFIX=/usr/lib/llvm-19 CAIRO_NATIVE_RUNTIME_LIBDIR="$(pwd)/target/debug" - export MLIR_SYS_180_PREFIX - export LLVM_SYS_181_PREFIX - export TABLEGEN_180_PREFIX + export MLIR_SYS_190_PREFIX + export LLVM_SYS_191_PREFIX + export TABLEGEN_190_PREFIX export CAIRO_NATIVE_RUNTIME_LIBDIR ;; esac diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 835935adc..988a09f5d 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -13,7 +13,7 @@ starknet-types-core = { version = "0.1.5", default-features = false, features = "std", "serde", "hash" ] } cairo-lang-sierra-gas = "2.8.2" -libc = "0.2.158" +libc = "0.2" starknet-curve = "0.5.0" lazy_static = "1.5.0" rand = "0.8.5" diff --git a/scripts/bench-hyperfine.sh b/scripts/bench-hyperfine.sh index 24b8c8348..47e9453c6 100755 --- a/scripts/bench-hyperfine.sh +++ b/scripts/bench-hyperfine.sh @@ -2,7 +2,7 @@ # Configuration. ROOT_DIR="$(dirname "$(dirname "${0%/*}")")" -MLIR_DIR="$MLIR_SYS_180_PREFIX" +MLIR_DIR="$MLIR_SYS_190_PREFIX" CAIRO_SRCS=$(find \ "$ROOT_DIR/programs/benches" \ @@ -25,7 +25,7 @@ then fi if [[ -z "$MLIR_DIR" ]] then - echo "${bold}MLIR_DIR is empty. Did you forget to set MLIR_SYS_180_PREFIX?${normal}" + echo "${bold}MLIR_DIR is empty. Did you forget to set MLIR_SYS_190_PREFIX?${normal}" exit 1 fi diff --git a/src/compiler.rs b/src/compiler.rs index f8af22602..1e990f616 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -47,11 +47,6 @@ use crate::{ debug::libfunc_to_name, error::Error, - ffi::{ - mlirLLVMDICompileUnitAttrGet, mlirLLVMDIFileAttrGet, mlirLLVMDIModuleAttrGet, - mlirLLVMDIModuleAttrGetScope, mlirLLVMDISubprogramAttrGet, mlirLLVMDISubroutineTypeAttrGet, - mlirLLVMDistinctAttrCreate, - }, libfuncs::{BranchArg, LibfuncBuilder, LibfuncHelper}, metadata::{ gas::{GasCost, GasMetadata}, @@ -93,6 +88,12 @@ use melior::{ }, Context, }; +use mlir_sys::{ + mlirDisctinctAttrCreate, mlirLLVMDICompileUnitAttrGet, mlirLLVMDIFileAttrGet, + mlirLLVMDIModuleAttrGet, mlirLLVMDIModuleAttrGetScope, mlirLLVMDISubprogramAttrGet, + mlirLLVMDISubroutineTypeAttrGet, MlirLLVMDIEmissionKind_MlirLLVMDIEmissionKindFull, + MlirLLVMDINameTableKind_MlirLLVMDINameTableKindDefault, +}; use std::{ cell::Cell, collections::{hash_map::Entry, BTreeMap, HashMap, HashSet}, @@ -304,7 +305,8 @@ fn compile_func( file_attr.to_raw(), StringAttribute::new(context, "cairo-native").to_raw(), false, - crate::ffi::DiEmissionKind::Full, + MlirLLVMDIEmissionKind_MlirLLVMDIEmissionKindFull, + MlirLLVMDINameTableKind_MlirLLVMDINameTableKindDefault, )) }; @@ -323,7 +325,7 @@ fn compile_func( let module_scope = mlirLLVMDIModuleAttrGetScope(di_module); Attribute::from_raw({ - let id = mlirLLVMDistinctAttrCreate( + let id = mlirDisctinctAttrCreate( StringAttribute::new(context, &format!("fn_{}", function.id.id)).to_raw(), ); diff --git a/src/context.rs b/src/context.rs index 11bc8a53a..c6b249219 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,10 +1,6 @@ use crate::{ error::Error, - ffi::{ - get_data_layout_rep, get_target_triple, mlirLLVMDICompileUnitAttrGet, - mlirLLVMDIFileAttrGet, mlirLLVMDIModuleAttrGet, mlirLLVMDistinctAttrCreate, - mlirModuleCleanup, - }, + ffi::{get_data_layout_rep, get_target_triple}, metadata::{ gas::{GasMetadata, MetadataComputationConfig}, runtime_bindings::RuntimeBindingsMeta, @@ -32,6 +28,11 @@ use melior::{ utility::{register_all_dialects, register_all_llvm_translations, register_all_passes}, Context, }; +use mlir_sys::{ + mlirDisctinctAttrCreate, mlirLLVMDICompileUnitAttrGet, mlirLLVMDIFileAttrGet, + mlirLLVMDIModuleAttrGet, MlirLLVMDIEmissionKind_MlirLLVMDIEmissionKindFull, + MlirLLVMDINameTableKind_MlirLLVMDINameTableKindDefault, +}; use std::sync::OnceLock; /// Context of IRs, dialects and passes for Cairo programs compilation. @@ -86,7 +87,7 @@ impl NativeContext { let di_unit_id = unsafe { let id = StringAttribute::new(&self.context, "compile_unit_id").to_raw(); - mlirLLVMDistinctAttrCreate(id) + mlirDisctinctAttrCreate(id) }; let op = OperationBuilder::new( @@ -110,7 +111,8 @@ impl NativeContext { file_attr.to_raw(), StringAttribute::new(&self.context, "cairo-native").to_raw(), false, - crate::ffi::DiEmissionKind::Full, + MlirLLVMDIEmissionKind_MlirLLVMDIEmissionKindFull, + MlirLLVMDINameTableKind_MlirLLVMDINameTableKindDefault, ); let context = &self.context; @@ -202,10 +204,6 @@ impl NativeContext { run_pass_manager(&self.context, &mut module)?; - unsafe { - mlirModuleCleanup(module.to_raw()); - } - if let Ok(x) = std::env::var("NATIVE_DEBUG_DUMP") { if x == "1" || x == "true" { std::fs::write("dump.mlir", module.as_operation().to_string()) diff --git a/src/ffi.cpp b/src/ffi.cpp deleted file mode 100644 index 9c9c85ddc..000000000 --- a/src/ffi.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace mlir::LLVM; -using namespace mlir; - -extern "C" const void *LLVMStructType_getFieldTypeAt(const void *ty_ptr, - unsigned index) { - mlir::LLVM::LLVMStructType type = - mlir::LLVM::LLVMStructType::getFromOpaquePointer(ty_ptr); - - return type.getBody()[index].getAsOpaquePointer(); -} - -extern "C" LLVMModuleRef mlirTranslateModuleToLLVMIR(MlirOperation module, - LLVMContextRef context) { - mlir::Operation *moduleOp = unwrap(module); - - llvm::LLVMContext *ctx = llvm::unwrap(context); - - std::unique_ptr llvmModule = - mlir::translateModuleToLLVMIR(moduleOp, *ctx); - - LLVMModuleRef moduleRef = llvm::wrap(llvmModule.release()); - - return moduleRef; -} - -enum MlirLLVMTypeEncoding { - MlirLLVMTypeEncodingAddress = 0x1, - MlirLLVMTypeEncodingBoolean = 0x2, - MlirLLVMTypeEncodingComplexFloat = 0x31, - MlirLLVMTypeEncodingFloatT = 0x4, - MlirLLVMTypeEncodingSigned = 0x5, - MlirLLVMTypeEncodingSignedChar = 0x6, - MlirLLVMTypeEncodingUnsigned = 0x7, - MlirLLVMTypeEncodingUnsignedChar = 0x08, - MlirLLVMTypeEncodingImaginaryFloat = 0x09, - MlirLLVMTypeEncodingPackedDecimal = 0x0a, - MlirLLVMTypeEncodingNumericString = 0x0b, - MlirLLVMTypeEncodingEdited = 0x0c, - MlirLLVMTypeEncodingSignedFixed = 0x0d, - MlirLLVMTypeEncodingUnsignedFixed = 0x0e, - MlirLLVMTypeEncodingDecimalFloat = 0x0f, - MlirLLVMTypeEncodingUTF = 0x10, - MlirLLVMTypeEncodingUCS = 0x11, - MlirLLVMTypeEncodingASCII = 0x12, - MlirLLVMTypeEncodingLoUser = 0x80, - MlirLLVMTypeEncodingHiUser = 0xff, -}; -typedef enum MlirLLVMTypeEncoding MlirLLVMTypeEncoding; - -extern "C" MlirAttribute -mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag, - MlirAttribute name, uint64_t sizeInBits, - MlirLLVMTypeEncoding encoding) { - - return wrap(DIBasicTypeAttr::get( - unwrap(ctx), tag, cast(unwrap(name)), sizeInBits, encoding)); -} - -enum MlirLLVMDIFlags { - MlirLLVMDIFlagsZero = 0, - MlirLLVMDIFlagsBit0 = 1, - MlirLLVMDIFlagsBit1 = 2, - MlirLLVMDIFlagsPrivate = 1, - MlirLLVMDIFlagsProtected = 2, - MlirLLVMDIFlagsPublic = 3, - MlirLLVMDIFlagsFwdDecl = 4, - MlirLLVMDIFlagsAppleBlock = 8, - MlirLLVMDIFlagsReservedBit4 = 16, - MlirLLVMDIFlagsVirtual = 32, - MlirLLVMDIFlagsArtificial = 64, - MlirLLVMDIFlagsExplicit = 128, - MlirLLVMDIFlagsPrototyped = 256, - MlirLLVMDIFlagsObjcClassComplete = 512, - MlirLLVMDIFlagsObjectPointer = 1024, - MlirLLVMDIFlagsVector = 2048, - MlirLLVMDIFlagsStaticMember = 4096, - MlirLLVMDIFlagsLValueReference = 8192, - MlirLLVMDIFlagsRValueReference = 16384, - MlirLLVMDIFlagsExportSymbols = 32768, - MlirLLVMDIFlagsSingleInheritance = 65536, - MlirLLVMDIFlagsMultipleInheritance = 65536, - MlirLLVMDIFlagsVirtualInheritance = 65536, - MlirLLVMDIFlagsIntroducedVirtual = 262144, - MlirLLVMDIFlagsBitField = 524288, - MlirLLVMDIFlagsNoReturn = 1048576, - MlirLLVMDIFlagsTypePassByValue = 4194304, - MlirLLVMDIFlagsTypePassByReference = 8388608, - MlirLLVMDIFlagsEnumClass = 16777216, - MlirLLVMDIFlagsThunk = 33554432, - MlirLLVMDIFlagsNonTrivial = 67108864, - MlirLLVMDIFlagsBigEndian = 134217728, - MlirLLVMDIFlagsLittleEndian = 268435456, - MlirLLVMDIFlagsAllCallsDescribed = 536870912, -}; -typedef enum MlirLLVMDIFlags MlirLLVMDIFlags; - -extern "C" MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) { - return wrap(DINullTypeAttr::get(unwrap(ctx))); -} - -extern "C" MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, - MlirAttribute name, - MlirAttribute directory) { - return wrap(DIFileAttr::get(unwrap(ctx), cast(unwrap(name)), - cast(unwrap(directory)))); -} - -enum MlirLLVMDIEmissionKind { - MlirLLVMDIEmissionKindNone = 0, - MlirLLVMDIEmissionKindFull = 1, - MlirLLVMDIEmissionKindLineTablesOnly = 2, - MlirLLVMDIEmissionKindDebugDirectivesOnly = 3, -}; -typedef enum MlirLLVMDIEmissionKind MlirLLVMDIEmissionKind; - -enum MlirLLVMDINameTableKind { - MlirLLVMDINameTableKindDefault = 0, - MlirLLVMDINameTableKindGNU = 1, - MlirLLVMDINameTableKindNone = 2, - MlirLLVMDINameTableKindApple = 3, -}; -typedef enum MlirLLVMDINameTableKind MlirLLVMDINameTableKind; - -enum MlirLLVMDISubprogramFlags { - MlirLLVMDISubprogramFlagsVirtual = 1, - MlirLLVMDISubprogramFlagsPureVirtual = 2, - MlirLLVMDISubprogramFlagsLocalToUnit = 4, - MlirLLVMDISubprogramFlagsDefinition = 8, - MlirLLVMDISubprogramFlagsOptimized = 16, - MlirLLVMDISubprogramFlagsPure = 32, - MlirLLVMDISubprogramFlagsElemental = 64, - MlirLLVMDISubprogramFlagsRecursive = 128, - MlirLLVMDISubprogramFlagsMainSubprogram = 256, - MlirLLVMDISubprogramFlagsDeleted = 512, - MlirLLVMDISubprogramFlagsObjCDirect = 2048, -}; -typedef enum MlirLLVMDISubprogramFlags MlirLLVMDISubprogramFlags; - -extern "C" MlirAttribute -mlirLLVMDistinctAttrCreate(MlirAttribute referenced_attr) { - return wrap(DistinctAttr::create(unwrap(referenced_attr))); -} - -extern "C" MlirAttribute -mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id, - unsigned int sourceLanguage, MlirAttribute file, - MlirAttribute producer, bool isOptimized, - MlirLLVMDIEmissionKind emissionKind) { - return wrap(DICompileUnitAttr::get( - unwrap(ctx), cast(unwrap(id)), sourceLanguage, - cast(unwrap(file)), cast(unwrap(producer)), - isOptimized, DIEmissionKind(emissionKind))); -} - -extern "C" void mlirModuleCleanup(MlirModule mod) { - auto x = unwrap(mod); - if (!x.getOps().empty()) { - for (auto &op : x.getOps().begin()->getBlock()->getOperations()) { - if (llvm::CastInfo::isPossible(op)) { - LLVMFuncOp x = llvm::CastInfo::doCast(op); - if (x.getSymName().starts_with("_mlir_ciface")) { - x->setLoc(mlir::UnknownLoc::get(x->getContext())); - } - } - } - } -} - -extern "C" MlirAttribute mlirLLVMDICompileUnitAttrGetScope(MlirContext ctx, - MlirAttribute cu, - MlirOperation op) { - return wrap(cast(unwrap(cu)).getFile()); -} - -extern "C" MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, - MlirLLVMDIFlags value) { - return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value))); -} - -extern "C" MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, - MlirAttribute scope, - MlirAttribute file, - unsigned int line, - unsigned int column) { - return wrap( - DILexicalBlockAttr::get(unwrap(ctx), cast(unwrap(scope)), - cast(unwrap(file)), line, column)); -} - -extern "C" MlirAttribute mlirLLVMDILexicalBlockAttrGetScope(MlirAttribute block) { - return wrap(cast(unwrap(block)).getScope()); -} - -extern "C" MlirAttribute -mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention, - intptr_t nTypes, MlirAttribute const *types) { - SmallVector attrStorage; - attrStorage.reserve(nTypes); - - return wrap(DISubroutineTypeAttr::get( - unwrap(ctx), callingConvention, - llvm::map_to_vector(unwrapList(nTypes, types, attrStorage), - [](Attribute a) { return cast(a); }))); -} - -extern "C" MlirAttribute mlirLLVMDISubprogramAttrGet( - MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit, - MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName, - MlirAttribute file, unsigned int line, unsigned int scopeLine, - MlirLLVMDISubprogramFlags subprogramFlags, MlirAttribute type) { - return wrap(DISubprogramAttr::get( - unwrap(ctx), cast(unwrap(id)), - cast(unwrap(compileUnit)), - cast(unwrap(scope)), cast(unwrap(name)), - cast(unwrap(linkageName)), cast(unwrap(file)), - line, scopeLine, DISubprogramFlags(subprogramFlags), - cast(unwrap(type)))); -} - -extern "C" MlirAttribute -mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) { - return wrap(cast(unwrap(diSubprogram)).getScope()); -} - -extern "C" MlirAttribute mlirLLVMDIModuleAttrGet( - MlirContext ctx, MlirAttribute file, MlirAttribute scope, - MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath, - MlirAttribute apinotes, unsigned int line, bool isDecl) { - return wrap(DIModuleAttr::get( - unwrap(ctx), cast(unwrap(file)), - cast(unwrap(scope)), cast(unwrap(name)), - cast(unwrap(configMacros)), - cast(unwrap(includePath)), cast(unwrap(apinotes)), - line, isDecl)); -} - -extern "C" MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) { - return wrap(cast(unwrap(diModule)).getScope()); -} - -extern "C" MlirAttribute mlirLLVMDICompositeTypeAttrGet( - MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file, - uint32_t line, MlirAttribute scope, MlirAttribute baseType, int64_t flags, - uint64_t sizeInBits, uint64_t alignInBits, intptr_t nElements, - MlirAttribute const *elements) { - SmallVector elementsStorage; - elementsStorage.reserve(nElements); - - return wrap(DICompositeTypeAttr::get( - unwrap(ctx), tag, cast(unwrap(name)), - cast(unwrap(file)), line, cast(unwrap(scope)), - cast(unwrap(baseType)), DIFlags(flags), sizeInBits, - alignInBits, - llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage), - [](Attribute a) { return cast(a); }))); -} - -extern "C" MlirAttribute -mlirLLVMDIDerivedTypeAttrGet(MlirContext ctx, unsigned int tag, - MlirAttribute name, MlirAttribute baseType, - uint64_t sizeInBits, uint32_t alignInBits, - uint64_t offsetInBits) { - return wrap(DIDerivedTypeAttr::get(unwrap(ctx), tag, - cast(unwrap(name)), - cast(unwrap(baseType)), - sizeInBits, alignInBits, offsetInBits)); -} - -extern "C" MlirAttribute -mlirLLVMDILocalVariableAttrGet(MlirContext ctx, MlirAttribute scope, - MlirAttribute name, MlirAttribute diFile, - unsigned int line, unsigned int arg, - unsigned int alignInBits, MlirAttribute diType) { - - return wrap(DILocalVariableAttr::get( - unwrap(ctx), cast(unwrap(scope)), - cast(unwrap(name)), cast(unwrap(diFile)), line, - arg, alignInBits, cast(unwrap(diType)))); -} diff --git a/src/ffi.rs b/src/ffi.rs index 5eed35275..a53a1343e 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -26,10 +26,10 @@ use llvm_sys::{ }, }; use melior::ir::{Module, Type, TypeLike}; -use mlir_sys::{mlirTranslateModuleToLLVMIR, MlirAttribute, MlirContext, MlirModule}; +use mlir_sys::{mlirLLVMStructTypeGetElementType, mlirTranslateModuleToLLVMIR}; use std::{ borrow::Cow, - ffi::{c_void, CStr, CString}, + ffi::{CStr, CString}, io::Write, mem::MaybeUninit, path::Path, @@ -38,184 +38,15 @@ use std::{ }; use tempfile::NamedTempFile; -#[repr(C)] -#[allow(unused)] -pub enum DiEmissionKind { - None, - Full, - LineTablesOnly, - DebugDirectivesOnly, -} - -#[repr(C)] -#[allow(unused)] -pub enum MlirLLVMTypeEncoding { - Address = 0x1, - Boolean = 0x2, - ComplexFloat = 0x31, - FloatT = 0x4, - Signed = 0x5, - SignedChar = 0x6, - Unsigned = 0x7, - UnsignedChar = 0x08, - ImaginaryFloat = 0x09, - PackedDecimal = 0x0a, - NumericString = 0x0b, - Edited = 0x0c, - SignedFixed = 0x0d, - UnsignedFixed = 0x0e, - DecimalFloat = 0x0f, - Utf = 0x10, - Ucs = 0x11, - Ascii = 0x12, - LoUser = 0x80, - HiUser = 0xff, -} - -#[repr(C)] -#[allow(unused)] -#[allow(non_camel_case_types)] -pub enum MlirLLVMDWTag { - DW_TAG_null = 0x00, - - DW_TAG_array_type = 0x01, - DW_TAG_class_type = 0x02, - DW_TAG_entry_point = 0x03, - DW_TAG_enumeration_type = 0x04, - DW_TAG_formal_parameter = 0x05, - DW_TAG_imported_declaration = 0x08, - DW_TAG_label = 0x0a, - DW_TAG_lexical_block = 0x0b, - DW_TAG_member = 0x0d, - DW_TAG_pointer_type = 0x0f, - DW_TAG_reference_type = 0x10, - DW_TAG_compile_unit = 0x11, - DW_TAG_string_type = 0x12, - DW_TAG_structure_type = 0x13, - DW_TAG_subroutine_type = 0x15, - DW_TAG_typedef = 0x16, - DW_TAG_union_type = 0x17, - DW_TAG_unspecified_parameters = 0x18, - DW_TAG_variant = 0x19, - DW_TAG_common_block = 0x1a, - DW_TAG_common_inclusion = 0x1b, - DW_TAG_inheritance = 0x1c, - DW_TAG_inlined_subroutine = 0x1d, - DW_TAG_module = 0x1e, - DW_TAG_ptr_to_member_type = 0x1f, - DW_TAG_set_type = 0x20, - DW_TAG_subrange_type = 0x21, - DW_TAG_with_stmt = 0x22, - DW_TAG_access_declaration = 0x23, - DW_TAG_base_type = 0x24, - DW_TAG_catch_block = 0x25, - DW_TAG_const_type = 0x26, - DW_TAG_constant = 0x27, - DW_TAG_enumerator = 0x28, - DW_TAG_file_type = 0x29, - DW_TAG_friend = 0x2a, - DW_TAG_namelist = 0x2b, - DW_TAG_namelist_item = 0x2c, - DW_TAG_packed_type = 0x2d, - DW_TAG_subprogram = 0x2e, - DW_TAG_template_type_parameter = 0x2f, - DW_TAG_template_value_parameter = 0x30, - DW_TAG_thrown_type = 0x31, - DW_TAG_try_block = 0x32, - DW_TAG_variant_part = 0x33, - DW_TAG_variable = 0x34, - DW_TAG_volatile_type = 0x35, - // DWARF 3. - DW_TAG_dwarf_procedure = 0x36, - DW_TAG_restrict_type = 0x37, - DW_TAG_interface_type = 0x38, - DW_TAG_namespace = 0x39, - DW_TAG_imported_module = 0x3a, - DW_TAG_unspecified_type = 0x3b, - DW_TAG_partial_unit = 0x3c, - DW_TAG_imported_unit = 0x3d, - DW_TAG_condition = 0x3f, - DW_TAG_shared_type = 0x40, - // DWARF 4. - DW_TAG_type_unit = 0x41, - DW_TAG_rvalue_reference_type = 0x42, - DW_TAG_template_alias = 0x43, - // DWARF 5. - DW_TAG_coarray_type = 0x44, - DW_TAG_generic_subrange = 0x45, - DW_TAG_dynamic_type = 0x46, - DW_TAG_atomic_type = 0x47, - DW_TAG_call_site = 0x48, - DW_TAG_call_site_parameter = 0x49, - DW_TAG_skeleton_unit = 0x4a, - DW_TAG_immutable_type = 0x4b, -} - -extern "C" { - fn LLVMStructType_getFieldTypeAt(ty_ptr: *const c_void, index: u32) -> *const c_void; - - pub fn mlirLLVMDistinctAttrCreate(attr: MlirAttribute) -> MlirAttribute; - - pub fn mlirLLVMDICompileUnitAttrGet( - mlir_context: MlirContext, - id: MlirAttribute, - source_lang: u32, - file: MlirAttribute, - producer: MlirAttribute, - is_optimized: bool, - emission_kind: DiEmissionKind, - ) -> MlirAttribute; - - pub fn mlirLLVMDIFileAttrGet( - mlir_context: MlirContext, - name: MlirAttribute, - dir: MlirAttribute, - ) -> MlirAttribute; - - pub fn mlirLLVMDISubprogramAttrGet( - mlir_context: MlirContext, - id: MlirAttribute, - compile_unit: MlirAttribute, - scope: MlirAttribute, - name: MlirAttribute, - linkage_name: MlirAttribute, - file: MlirAttribute, - line: u32, - scope_line: u32, - subprogram_flags: i32, - ty: MlirAttribute, - ) -> MlirAttribute; - - pub fn mlirLLVMDISubroutineTypeAttrGet( - mlir_context: MlirContext, - cconv: u32, - ntypes: usize, - types: *const MlirAttribute, - ) -> MlirAttribute; - - pub fn mlirLLVMDIModuleAttrGet( - mlir_context: MlirContext, - file: MlirAttribute, - scope: MlirAttribute, - name: MlirAttribute, - configMacros: MlirAttribute, - includePath: MlirAttribute, - apinotes: MlirAttribute, - line: u32, - is_decl: bool, - ) -> MlirAttribute; - - pub fn mlirLLVMDIModuleAttrGetScope(di_module: MlirAttribute) -> MlirAttribute; - - pub fn mlirModuleCleanup(module: MlirModule); -} - /// For any `!llvm.struct<...>` type, return the MLIR type of the field at the requested index. pub fn get_struct_field_type_at<'c>(r#type: &Type<'c>, index: usize) -> Type<'c> { - let mut ty_ptr = r#type.to_raw(); - - ty_ptr.ptr = unsafe { LLVMStructType_getFieldTypeAt(ty_ptr.ptr, index as u32) }; - unsafe { Type::from_raw(ty_ptr) } + assert!(r#type.is_llvm_struct_type()); + unsafe { + Type::from_raw(mlirLLVMStructTypeGetElementType( + r#type.to_raw(), + index as isize, + )) + } } /// Optimization levels.