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

Better function attributes and re-enable >O1 opt #843

Merged
merged 25 commits into from
Oct 16, 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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ doc-open: check-llvm
cargo doc --all-features --no-deps --workspace --open

.PHONY: bench
bench: build needs-cairo2 runtime
bench: needs-cairo2 runtime
cargo b --release --bin cairo-native-run
./scripts/bench-hyperfine.sh

.PHONY: bench-ci
Expand Down
30 changes: 21 additions & 9 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,16 @@ fn compile_func(
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "public").into(),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "linkage"),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
(
Identifier::new(context, "CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
// (
// Identifier::new(context, "CConv"),
// Attribute::parse(context, "#llvm.cconv<tailcc>").unwrap(),
// ),
],
Location::fused(
context,
Expand Down Expand Up @@ -1351,10 +1355,10 @@ fn generate_entry_point_wrapper<'c>(
Identifier::new(context, "callee"),
FlatSymbolRefAttribute::new(context, private_symbol).into(),
),
// (
// Identifier::new(context, "CConv"),
// Attribute::parse(context, "#llvm.cconv<tailcc>").unwrap(),
// ),
(
Identifier::new(context, "CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
])
.add_operands(&args)
.add_results(&[llvm::r#type::r#struct(context, ret_types, false)])
Expand Down Expand Up @@ -1385,6 +1389,14 @@ fn generate_entry_point_wrapper<'c>(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.emit_c_interface"),
Attribute::unit(context),
Expand Down
9 changes: 6 additions & 3 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn module_to_object(module: &Module<'_>, opt_level: OptLevel) -> Result<Vec<
OptLevel::Default => LLVMCodeGenOptLevel::LLVMCodeGenLevelDefault,
OptLevel::Aggressive => LLVMCodeGenOptLevel::LLVMCodeGenLevelAggressive,
},
LLVMRelocMode::LLVMRelocDynamicNoPic,
LLVMRelocMode::LLVMRelocPIC,
LLVMCodeModel::LLVMCodeModelDefault,
);

Expand All @@ -152,8 +152,11 @@ pub fn module_to_object(module: &Module<'_>, opt_level: OptLevel) -> Result<Vec<
let opt = match opt_level {
OptLevel::None => 0,
OptLevel::Less => 1,
OptLevel::Default => 1, // todo: change once slp-vectorizer pass is fixed on llvm
OptLevel::Aggressive => 1, // https://github.com/llvm/llvm-project/issues/107198
// slp-vectorizer pass did cause some issues, but after the change
// on function attributes it seems to not trigger them anymore.
// https://github.com/llvm/llvm-project/issues/107198
OptLevel::Default => 2,
OptLevel::Aggressive => 3,
};
let passes = CString::new(format!("default<O{opt}>")).unwrap();
let error = LLVMRunPasses(llvm_module, passes.as_ptr(), machine, opts);
Expand Down
10 changes: 5 additions & 5 deletions src/libfuncs/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use melior::{
attribute::{DenseI32ArrayAttribute, FlatSymbolRefAttribute},
operation::OperationBuilder,
r#type::IntegerType,
Block, Identifier, Location, Type, Value,
Attribute, Block, Identifier, Location, Type, Value,
},
Context,
};
Expand Down Expand Up @@ -195,10 +195,10 @@ pub fn build<'ctx, 'this>(
)
.into(),
),
// (
// Identifier::new(context, "CConv"),
// Attribute::parse(context, "#llvm.cconv<tailcc>").unwrap(),
// ),
(
Identifier::new(context, "CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
])
.add_operands(&arguments)
.add_results(&[llvm::r#type::r#struct(context, &result_types, false)])
Expand Down
17 changes: 15 additions & 2 deletions src/metadata/drop_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use melior::{
ir::{
attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute},
r#type::FunctionType,
Block, Location, Module, Region, Value,
Attribute, Block, Identifier, Location, Module, Region, Value,
},
Context,
};
Expand Down Expand Up @@ -85,7 +85,20 @@ impl DropOverridesMeta {
StringAttribute::new(context, &format!("drop${}", id.id)),
TypeAttribute::new(FunctionType::new(context, &[ty], &[]).into()),
region,
&[],
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
],
Location::unknown(context),
));
}
Expand Down
17 changes: 15 additions & 2 deletions src/metadata/dup_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use melior::{
ir::{
attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute},
r#type::FunctionType,
Block, Location, Module, Region, Value, ValueLike,
Attribute, Block, Identifier, Location, Module, Region, Value, ValueLike,
},
Context,
};
Expand Down Expand Up @@ -85,7 +85,20 @@ impl DupOverridesMeta {
StringAttribute::new(context, &format!("dup${}", id.id)),
TypeAttribute::new(FunctionType::new(context, &[ty], &[ty, ty]).into()),
region,
&[],
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
],
Location::unknown(context),
));
}
Expand Down
Loading
Loading