Skip to content

Commit

Permalink
Add basic support for LLVM 18 (#63)
Browse files Browse the repository at this point in the history
* Basic support for LLVM 18. Rebuild test files for it. Loop test hit some new optimisation, so had a fair bit of churn. LLVM 17 compatibility test was changede from ll to bc: The bitcode files guarantee forwards compatibility, which we need now that LLVM 18 dropped support for the webkit_jscc calling convention

* Fix some LLVM 17 mentions in LLVM 18 test file

* Remove the following constant expression types that have been removed in LLVM 18:

 - and
 - or
 - lshr
 - ashr
 - zext
 - sext
 - fptrunc
 - fpext
 - fptoui
 - fptosi
 - uitofp
 - sitofp

* Tab to space conversion in constant.rs
  • Loading branch information
Benjins authored May 18, 2024
1 parent 42dd506 commit d721f54
Show file tree
Hide file tree
Showing 39 changed files with 1,311 additions and 2,162 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- 15
- 16
- 17
- 18

steps:
- name: Checkout sources
Expand Down
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ llvm-sys-140 = { package = "llvm-sys", version = "140.0.0", optional = true }
llvm-sys-150 = { package = "llvm-sys", version = "150.1.0", optional = true }
llvm-sys-160 = { package = "llvm-sys", version = "160.1.2", optional = true }
llvm-sys-170 = { package = "llvm-sys", version = "170.0.1", optional = true }
llvm-sys-181 = { package = "llvm-sys", version = "181.0.0", optional = true }
either = "1.9"
log = "0.4"

Expand All @@ -40,6 +41,7 @@ llvm-14 = ["llvm-sys-140", "llvm-14-or-lower", "llvm-14-or-greater"]
llvm-15 = ["llvm-sys-150", "llvm-15-or-lower", "llvm-15-or-greater"]
llvm-16 = ["llvm-sys-160", "llvm-16-or-lower", "llvm-16-or-greater"]
llvm-17 = ["llvm-sys-170", "llvm-17-or-lower", "llvm-17-or-greater"]
llvm-18 = ["llvm-sys-181", "llvm-18-or-lower", "llvm-18-or-greater"]

###
# For convenience, these automatically-enabled features allow us to avoid
Expand All @@ -54,6 +56,7 @@ llvm-14-or-greater = ["llvm-13-or-greater"]
llvm-15-or-greater = ["llvm-14-or-greater"]
llvm-16-or-greater = ["llvm-15-or-greater"]
llvm-17-or-greater = ["llvm-16-or-greater"]
llvm-18-or-greater = ["llvm-17-or-greater"]

llvm-9-or-lower = ["llvm-10-or-lower"]
llvm-10-or-lower = ["llvm-11-or-lower"]
Expand All @@ -63,7 +66,8 @@ llvm-13-or-lower = ["llvm-14-or-lower"]
llvm-14-or-lower = ["llvm-15-or-lower"]
llvm-15-or-lower = ["llvm-16-or-lower"]
llvm-16-or-lower = ["llvm-17-or-lower"]
llvm-17-or-lower = []
llvm-17-or-lower = ["llvm-18-or-lower"]
llvm-18-or-lower = []
###

# The `strict-versioning` feature requires an exact match between the
Expand All @@ -83,6 +87,7 @@ strict-versioning = [
"llvm-sys-150?/strict-versioning",
"llvm-sys-160?/strict-versioning",
"llvm-sys-170?/strict-versioning",
"llvm-sys-181?/strict-versioning",
]

# The `prefer-dynamic` feature is only available on llvm-sys versions >= 120.
Expand All @@ -93,6 +98,7 @@ prefer-dynamic = [
"llvm-sys-150?/prefer-dynamic",
"llvm-sys-160?/prefer-dynamic",
"llvm-sys-170?/prefer-dynamic",
"llvm-sys-181?/prefer-dynamic",
]

[package.metadata.docs.rs]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ add it as a dependency in your `Cargo.toml`, selecting the feature corresponding
to the LLVM version you want:
```toml
[dependencies]
llvm-ir = { version = "0.11.0", features = ["llvm-17"] }
llvm-ir = { version = "0.11.0", features = ["llvm-18"] }
```

Currently, the supported LLVM versions are `llvm-9`, `llvm-10`, `llvm-11`,
`llvm-12`, `llvm-13`, `llvm-14`, `llvm-15`, `llvm-16`, and `llvm-17`.
`llvm-12`, `llvm-13`, `llvm-14`, `llvm-15`, `llvm-16`, `llvm-17`, and `llvm-18`.

Then, the easiest way to get started is to parse some existing LLVM IR into
this crate's data structures.
Expand Down Expand Up @@ -83,8 +83,8 @@ using.
## Compatibility
Starting with `llvm-ir` 0.7.0, LLVM versions are selected by a Cargo feature
flag. This means that a single crate version can be used for any supported LLVM
version. Currently, `llvm-ir` supports LLVM versions 9 through 17, selected by
feature flags `llvm-9` through `llvm-17`.
version. Currently, `llvm-ir` supports LLVM versions 9 through 18, selected by
feature flags `llvm-9` through `llvm-18`.

You should select the LLVM version corresponding to the version of the LLVM
library you are linking against (i.e., that is available on your system.)
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ fn main() {
if cfg!(feature = "llvm-17") {
versions.push(17);
}
if cfg!(feature = "llvm-18") {
versions.push(18);
}
match versions.len() {
0 => panic!("llvm-ir: Please select an LLVM version using a Cargo feature."),
1 => {},
Expand Down
4 changes: 2 additions & 2 deletions refresh-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Requires ghp-import to be installed (e.g. via pip3)

rm -rf target/doc && # purge old docs that may include docs for deps
cargo doc --no-deps --features=llvm-17 && # document just this crate
cargo doc --no-deps --features=llvm-18 && # document just this crate
echo "<meta http-equiv=refresh content=0;url=llvm_ir/index.html>" > target/doc/index.html && # put in the top-level redirect
ghp-import -np target/doc && # publish to gh-pages branch
rm -rf target/doc && # kill the docs that were just this crate
cargo doc --features=llvm-17 # regenerate all docs (including deps) for local use
cargo doc --features=llvm-18 # regenerate all docs (including deps) for local use
Loading

0 comments on commit d721f54

Please sign in to comment.