Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove support for LLVM 8 #60

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ license = "MIT"
build = "build.rs"

[dependencies]
llvm-sys-80 = { package = "llvm-sys", version = "80.3.0", optional = true }
llvm-sys-90 = { package = "llvm-sys", version = "90.2.0", optional = true }
llvm-sys-100 = { package = "llvm-sys", version = "100.2.0", optional = true }
llvm-sys-110 = { package = "llvm-sys", version = "110.0.0", optional = true }
Expand All @@ -32,7 +31,6 @@ itertools = "0.11"
[features]
# Select the LLVM version to be compatible with.
# You _must_ enable exactly one of the following features.
llvm-8 = ["llvm-sys-80", "llvm-8-or-lower", "llvm-8-or-greater"]
llvm-9 = ["llvm-sys-90", "llvm-9-or-lower", "llvm-9-or-greater"]
llvm-10 = ["llvm-sys-100", "llvm-10-or-lower", "llvm-10-or-greater"]
llvm-11 = ["llvm-sys-110", "llvm-11-or-lower", "llvm-11-or-greater"]
Expand All @@ -47,8 +45,7 @@ llvm-17 = ["llvm-sys-170", "llvm-17-or-lower", "llvm-17-or-greater"]
# For convenience, these automatically-enabled features allow us to avoid
# checking complex combinations of features all the time. They are not meant to
# be manually enabled; use the above llvm-x features instead
llvm-8-or-greater = []
llvm-9-or-greater = ["llvm-8-or-greater"]
llvm-9-or-greater = []
llvm-10-or-greater = ["llvm-9-or-greater"]
llvm-11-or-greater = ["llvm-10-or-greater"]
llvm-12-or-greater = ["llvm-11-or-greater"]
Expand All @@ -58,7 +55,6 @@ 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-8-or-lower = ["llvm-9-or-lower"]
llvm-9-or-lower = ["llvm-10-or-lower"]
llvm-10-or-lower = ["llvm-11-or-lower"]
llvm-11-or-lower = ["llvm-12-or-lower"]
Expand All @@ -78,7 +74,6 @@ llvm-17-or-lower = []
# This avoids activating all the optional dependencies when `strict-versioning`
# is activated.
strict-versioning = [
"llvm-sys-80?/strict-versioning",
"llvm-sys-90?/strict-versioning",
"llvm-sys-100?/strict-versioning",
"llvm-sys-110?/strict-versioning",
Expand Down
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ to the LLVM version you want:
llvm-ir = { version = "0.10.0", features = ["llvm-17"] }
```

Currently, the supported LLVM versions are `llvm-8`, `llvm-9`, `llvm-10`,
`llvm-11`, `llvm-12`, `llvm-13`, `llvm-14`, `llvm-15`, `llvm-16`, and `llvm-17`.
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`.

Then, the easiest way to get started is to parse some existing LLVM IR into
this crate's data structures.
To do this, you need LLVM bitcode (`*.bc`) files.
To do this, you need LLVM bitcode (`*.bc`) or text-format IR (`*.ll`) files.
If you currently have C/C++ sources (say, `source.c`), you can generate
`*.bc` files with `clang`'s `-c` and `-emit-llvm` flags:
```bash
Expand All @@ -61,6 +61,7 @@ In either case, once you have a bitcode file, then you can use `llvm-ir`'s
use llvm_ir::Module;
let module = Module::from_bc_path("path/to/my/file.bc")?;
```
or if you have a text-format IR file, you can use `Module::from_ir_path()`.

You may also be interested in the [`llvm-ir-analysis`] crate, which computes
control-flow graphs, dominator trees, etc for `llvm-ir` functions.
Expand All @@ -82,8 +83,15 @@ 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 8 through 17, selected by
feature flags `llvm-8` through `llvm-17`.
version. Currently, `llvm-ir` supports LLVM versions 9 through 17, selected by
feature flags `llvm-9` through `llvm-17`.

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.)
Newer LLVMs should be able to read bitcode produced by older LLVMs, so you
should be able to use this crate to parse bitcode older than the LLVM version
you select via crate feature, even bitcode produced by LLVMs older than LLVM 9.
However, this is not extensively tested by us.

`llvm-ir` works on stable Rust. As of this writing, it requires Rust 1.65+.

Expand Down Expand Up @@ -118,20 +126,12 @@ source locations), but makes no attempt to recover any other debug metadata.
LLVM files containing metadata can still be parsed in with no problems, but
the resulting `Module` structures will not contain any of the metadata,
except debug locations.
Work-in-progress on fixing this can be found on the `metadata` branch of this
repo, but be warned that the `metadata` branch doesn't even build at the time
of this writing, let alone provide any meaningful functionality for crate
users.

A few other features are missing from `llvm-ir`'s data structures because
getters for them are missing from the LLVM C API and the Rust `llvm-sys`
crate, only being present in the LLVM C++ API.
These include but are not limited to:

- the `nsw` and `nuw` flags on `Add`, `Sub`, `Mul`, and `Shl`, and likewise
the `exact` flag on `UDiv`, `SDiv`, `LShr`, and `AShr`. The C API has
functionality to create new instructions specifying values of these flags,
but not to query the values of these flags on existing instructions.
- the "fast-math flags" on various floating-point operations
- contents of inline assembly functions
- information about the clauses in the variadic `LandingPad` instruction
Expand All @@ -143,6 +143,11 @@ associated with a function
fit in 64 bits) -- see [#5](https://github.com/cdisselkoen/llvm-ir/issues/5)
- the "other labels" reachable from a `CallBr` terminator (which was
introduced in LLVM 9)
- (LLVM 16 and lower -- fixed in LLVM 17 and later) the `nsw` and `nuw` flags on
`Add`, `Sub`, `Mul`, and `Shl`, and likewise the `exact` flag on `UDiv`, `SDiv`,
`LShr`, and `AShr`. The C API has functionality to create new instructions
specifying values of these flags, but not to query the values of these flags on
existing instructions.
- (LLVM 9 and lower -- fixed in LLVM 10 and later) the opcode for the
`AtomicRMW` instruction, i.e., `Xchg`, `Add`, `Max`, `Min`, and the like.

Expand All @@ -151,11 +156,10 @@ More discussion about this is in
Any contributions to filling these gaps in the C API are greatly appreciated!

## Acknowledgments
`llvm-ir` is heavily inspired by the [`llvm-hs-pure` Haskell package].
Most of the data structures in `llvm-ir` are essentially translations from
Haskell to Rust of the data structures in `llvm-hs-pure` (with some tweaks).
To a lesser extent, `llvm-ir` borrows from the larger [`llvm-hs` Haskell
package] as well.
`llvm-ir` took its original inspiration from the [`llvm-hs-pure` Haskell package].
Most of the data structures in the original release of `llvm-ir` were
essentially translations from Haskell to Rust of the data structures in
`llvm-hs-pure` (with some tweaks).

## Changelog for 0.7.0

Expand All @@ -167,8 +171,9 @@ one of the features `llvm-8`, `llvm-9`, or `llvm-10`. Previously, we had the
`0.6.x` branch for LLVM 10, the `0.5.x` branch for LLVM 9, and didn't
officially support LLVM 8. Now, a single release supports LLVM 8, 9, and 10.
- (Note: Versions of this crate beyond 0.7.0 have added support for later LLVM
versions as well. For instance, 0.7.3 and later also supports LLVM 11; and
0.7.5 and later also supports LLVM 12.)
versions as well. For instance, 0.7.3 and later also support LLVM 11; and
0.7.5 and later also support LLVM 12. Crate version 0.11.0 removed support
for LLVM 8.)
- [`FunctionAttribute`] and [`ParameterAttribute`] are now proper enums with
descriptive variants such as `NoInline`, `StackProtect`, etc. Previously,
attributes were opaque numeric codes which were difficult to interpret.
Expand All @@ -189,8 +194,8 @@ number of breaking changes to the public interface:
[`module.types.named_struct_def()`] to get the definition for any named
struct type in the module.
- The required Rust version increased from 1.36+ to 1.39+.
- (Note: 0.7.2 increased the required Rust version again, to 1.43+;
and 0.8.1 increased it to 1.45+.)
- (Note: Versions of this crate beyond 0.7.0 have increased this requirement
further. For the current required Rust version, see "Compatibility" above.)

[`llvm-sys`]: https://crates.io/crates/llvm-sys
[`inkwell`]: https://github.com/TheDan64/inkwell
Expand Down
3 changes: 0 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
fn main() {
let mut versions = vec![];
if cfg!(feature = "llvm-8") {
versions.push(8);
}
if cfg!(feature = "llvm-9") {
versions.push(9);
}
Expand Down
2 changes: 0 additions & 2 deletions src/basicblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ impl BasicBlock {
name,
instrs: vec![],
term: Terminator::Unreachable(Unreachable {
#[cfg(feature = "llvm-9-or-greater")]
debugloc: None,
}),
}
Expand Down Expand Up @@ -116,7 +115,6 @@ fn term_needs_name(term: LLVMValueRef) -> bool {
match unsafe { LLVMGetInstructionOpcode(term) } {
LLVMOpcode::LLVMInvoke => true,
LLVMOpcode::LLVMCatchSwitch => true,
#[cfg(feature = "llvm-9-or-greater")]
LLVMOpcode::LLVMCallBr => true,
_ => false, // all other terminators have no result (destination) and thus don't need names
}
Expand Down
3 changes: 0 additions & 3 deletions src/from_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ macro_rules! wrap_with_len {
};
}

#[cfg(feature = "llvm-9-or-greater")]
macro_rules! wrap_with_len_maybe_null {
($llvmFunc:ident, $argty:ty, $wrapperFunc:ident) => {
pub unsafe fn $wrapperFunc(arg: $argty) -> Option<String> {
Expand Down Expand Up @@ -87,9 +86,7 @@ wrap_with_len!(
LLVMAttributeRef,
get_string_attribute_value
);
#[cfg(feature = "llvm-9-or-greater")]
wrap_with_len_maybe_null!(LLVMGetDebugLocFilename, LLVMValueRef, get_debugloc_filename);
#[cfg(feature = "llvm-9-or-greater")]
wrap_with_len_maybe_null!(
LLVMGetDebugLocDirectory,
LLVMValueRef,
Expand Down
23 changes: 0 additions & 23 deletions src/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "llvm-9-or-greater")]
use crate::debugloc::{DebugLoc, HasDebugLoc};
use crate::module::{Comdat, DLLStorageClass, Linkage, Visibility};
use crate::types::{TypeRef, Typed, Types};
Expand Down Expand Up @@ -26,7 +25,6 @@
// pub prefix: Option<ConstantRef>, // appears to not be exposed in the LLVM C API, only the C++ API
/// Personalities are used for exception handling. See [LLVM 14 docs on Personality Function](https://releases.llvm.org/14.0.0/docs/LangRef.html#personalityfn)
pub personality_function: Option<ConstantRef>,
#[cfg(feature = "llvm-9-or-greater")]
pub debugloc: Option<DebugLoc>,
// --TODO not yet implemented-- pub metadata: Vec<(String, MetadataRef<MetadataNode>)>,
}
Expand All @@ -41,7 +39,6 @@
}
}

#[cfg(feature = "llvm-9-or-greater")]
impl HasDebugLoc for Function {
fn get_debug_loc(&self) -> &Option<DebugLoc> {
&self.debugloc
Expand Down Expand Up @@ -73,7 +70,6 @@
alignment: 4,
garbage_collector_name: None,
personality_function: None,
#[cfg(feature = "llvm-9-or-greater")]
debugloc: None,
}
}
Expand All @@ -94,7 +90,6 @@
pub alignment: u32,
/// See [LLVM 14 docs on Garbage Collector Strategy Names](https://releases.llvm.org/14.0.0/docs/LangRef.html#gc)
pub garbage_collector_name: Option<String>,
#[cfg(feature = "llvm-9-or-greater")]
pub debugloc: Option<DebugLoc>,
}

Expand Down Expand Up @@ -175,7 +170,7 @@

impl MemoryEffect {
// See https://github.com/llvm/llvm-project/blob/7cbf1a2591520c2491aa35339f227775f4d3adf6/llvm/include/llvm/Support/ModRef.h#L27
pub(crate) fn from_llvm_bits(val : u64) -> Self {

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 10

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 10

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 10

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 9

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 9

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 9

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 12

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 12

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 12

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 15

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 15

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 15

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 14

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 14

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 14

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 13

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 13

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 13

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 11

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 11

associated function `from_llvm_bits` is never used

Check warning on line 173 in src/function.rs

View workflow job for this annotation

GitHub Actions / Test for LLVM 11

associated function `from_llvm_bits` is never used
match val {
0b00 => Self::None,
0b01 => Self::Read,
Expand Down Expand Up @@ -207,7 +202,6 @@
NoBuiltin,
NoCFCheck,
NoDuplicate,
#[cfg(feature = "llvm-9-or-greater")]
NoFree,
NoImplicitFloat,
NoInline,
Expand All @@ -217,10 +211,8 @@
NoRedZone,
NoReturn,
NoRecurse,
#[cfg(feature = "llvm-9-or-greater")]
WillReturn,
ReturnsTwice,
#[cfg(feature = "llvm-9-or-greater")]
NoSync,
NoUnwind,
#[cfg(feature = "llvm-11-or-greater")]
Expand All @@ -237,7 +229,6 @@
SanitizeMemory,
SanitizeThread,
SanitizeHWAddress,
#[cfg(feature = "llvm-9-or-greater")]
SanitizeMemTag,
ShadowCallStack,
SpeculativeLoadHardening,
Expand Down Expand Up @@ -286,7 +277,6 @@
Alignment(u64),
NoAlias,
NoCapture,
#[cfg(feature = "llvm-9-or-greater")]
NoFree,
Nest,
Returned,
Expand Down Expand Up @@ -438,7 +428,6 @@
}),
alignment: unsafe { LLVMGetAlignment(func) },
garbage_collector_name: unsafe { get_gc(func) },
#[cfg(feature = "llvm-9-or-greater")]
debugloc: DebugLoc::from_llvm_no_col(func),
};
(decl, local_ctr)
Expand Down Expand Up @@ -546,7 +535,6 @@
None
}
},
#[cfg(feature = "llvm-9-or-greater")]
debugloc: decl.debugloc,
// metadata: unimplemented!("Function.metadata"),
}
Expand Down Expand Up @@ -631,7 +619,6 @@
"nobuiltin",
"nocf_check",
"noduplicate",
#[cfg(feature = "llvm-9-or-greater")]
"nofree",
"noimplicitfloat",
"noinline",
Expand All @@ -641,10 +628,8 @@
"noredzone",
"noreturn",
"norecurse",
#[cfg(feature = "llvm-9-or-greater")]
"willreturn",
"returns_twice",
#[cfg(feature = "llvm-9-or-greater")]
"nosync",
"nounwind",
#[cfg(feature = "llvm-11-or-greater")]
Expand All @@ -662,7 +647,6 @@
"sanitize_memory",
"sanitize_thread",
"sanitize_hwaddress",
#[cfg(feature = "llvm-9-or-greater")]
"sanitize_memtag",
"shadowcallstack",
"speculative_load_hardening",
Expand Down Expand Up @@ -695,7 +679,6 @@
"align",
"noalias",
"nocapture",
#[cfg(feature = "llvm-9-or-greater")]
"nofree",
"nest",
"returned",
Expand All @@ -704,7 +687,6 @@
"dereferenceable_or_null",
"swiftself",
"swifterror",
#[cfg(feature = "llvm-9-or-greater")]
"immarg",
#[cfg(feature = "llvm-11-or-greater")]
"noundef",
Expand Down Expand Up @@ -768,7 +750,6 @@
Some("nobuiltin") => Self::NoBuiltin,
Some("nocf_check") => Self::NoCFCheck,
Some("noduplicate") => Self::NoDuplicate,
#[cfg(feature = "llvm-9-or-greater")]
Some("nofree") => Self::NoFree,
Some("noimplicitfloat") => Self::NoImplicitFloat,
Some("noinline") => Self::NoInline,
Expand All @@ -778,10 +759,8 @@
Some("noredzone") => Self::NoRedZone,
Some("noreturn") => Self::NoReturn,
Some("norecurse") => Self::NoRecurse,
#[cfg(feature = "llvm-9-or-greater")]
Some("willreturn") => Self::WillReturn,
Some("returns_twice") => Self::ReturnsTwice,
#[cfg(feature = "llvm-9-or-greater")]
Some("nosync") => Self::NoSync,
Some("nounwind") => Self::NoUnwind,
#[cfg(feature = "llvm-11-or-greater")]
Expand All @@ -798,7 +777,6 @@
Some("sanitize_memory") => Self::SanitizeMemory,
Some("sanitize_thread") => Self::SanitizeThread,
Some("sanitize_hwaddress") => Self::SanitizeHWAddress,
#[cfg(feature = "llvm-9-or-greater")]
Some("sanitize_memtag") => Self::SanitizeMemTag,
Some("shadowcallstack") => Self::ShadowCallStack,
Some("speculative_load_hardening") => Self::SpeculativeLoadHardening,
Expand Down Expand Up @@ -868,7 +846,6 @@
Some("align") => Self::Alignment(unsafe { LLVMGetEnumAttributeValue(a) }),
Some("noalias") => Self::NoAlias,
Some("nocapture") => Self::NoCapture,
#[cfg(feature = "llvm-9-or-greater")]
Some("nofree") => Self::NoFree,
Some("nest") => Self::Nest,
Some("returned") => Self::Returned,
Expand Down
Loading
Loading