Skip to content

Commit

Permalink
dont use call intrinsic (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l authored Apr 8, 2024
1 parent e571acd commit 6ae0575
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 229 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ walkdir = "2"
serde_json = { version = "1.0" }

[build-dependencies]
cc = "1.0"
cc = "1.0.90"

[profile.optimized-dev]
inherits = "dev"
Expand Down
27 changes: 8 additions & 19 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use melior::{
arith::{self, CmpiPredicate},
cf, func, index,
llvm::{self, LoadStoreOptions},
memref,
memref, ods,
},
ir::{
attribute::{IntegerAttribute, StringAttribute, TypeAttribute},
Expand Down Expand Up @@ -591,28 +591,17 @@ fn compile_func(
))
.result(0)?
.into();
let is_volatile = block
.append_operation(arith::constant(
block.append_operation(
ods::llvm::intr_memcpy(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into())
.into(),
Location::unknown(context),
))
.result(0)?
.into();

block.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy.inline"),
&[
pre_entry_block.argument(0)?.into(),
ptr,
num_bytes,
is_volatile,
],
&[],
Location::unknown(context),
));
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
Location::unknown(context),
)
.into(),
);
}
Some(false) => {
for (value, (type_id, type_info)) in
Expand Down
128 changes: 52 additions & 76 deletions src/libfuncs/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ use melior::{
arith::{self, CmpiPredicate},
cf,
llvm::{self, r#type::opaque_pointer, LoadStoreOptions},
ods,
},
ir::{
attribute::{
DenseI32ArrayAttribute, DenseI64ArrayAttribute, IntegerAttribute, StringAttribute,
},
attribute::{DenseI32ArrayAttribute, DenseI64ArrayAttribute, IntegerAttribute},
operation::OperationBuilder,
r#type::IntegerType,
Block, Location, Value, ValueLike,
Expand Down Expand Up @@ -368,21 +367,17 @@ pub fn build_append<'ctx, 'this>(
.append_operation(arith::muli(memmove_len, elem_stride, location))
.result(0)?
.into();
let is_volatile = memmove_block
.append_operation(arith::constant(
memmove_block.append_operation(
ods::llvm::intr_memmove(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
Location::unknown(context),
))
.result(0)?
.into();
memmove_block.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memmove"),
&[dst_ptr, src_ptr, memmove_len, is_volatile],
&[],
location,
));
dst_ptr,
src_ptr,
memmove_len,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
)
.into(),
);

let k0 = memmove_block
.append_operation(arith::constant(
Expand Down Expand Up @@ -821,23 +816,18 @@ pub fn build_get<'ctx, 'this>(
"realloc returned nullptr",
)?;

let is_volatile = valid_block
.append_operation(arith::constant(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
Location::unknown(context),
))
.result(0)?
.into();

// TODO: Support clone-only types (those that are not copy).
valid_block.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy.inline"),
&[target_ptr, elem_ptr, elem_size, is_volatile],
&[],
location,
));
valid_block.append_operation(
ods::llvm::intr_memcpy(
context,
target_ptr,
elem_ptr,
elem_size,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
)
.into(),
);

valid_block.append_operation(helper.br(0, &[range_check, target_ptr], location));
}
Expand Down Expand Up @@ -988,22 +978,17 @@ pub fn build_pop_front<'ctx, 'this>(
"realloc returned nullptr",
)?;

let is_volatile = valid_block
.append_operation(arith::constant(
valid_block.append_operation(
ods::llvm::intr_memcpy(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
Location::unknown(context),
))
.result(0)?
.into();

valid_block.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy.inline"),
&[target_ptr, ptr, elem_size, is_volatile],
&[],
location,
));
target_ptr,
ptr,
elem_size,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
)
.into(),
);

let k1 = valid_block
.append_operation(arith::constant(
Expand Down Expand Up @@ -1217,22 +1202,17 @@ pub fn build_snapshot_pop_back<'ctx, 'this>(
"realloc returned nullptr",
)?;

let is_volatile = valid_block
.append_operation(arith::constant(
valid_block.append_operation(
ods::llvm::intr_memcpy(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
Location::unknown(context),
))
.result(0)?
.into();

valid_block.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy.inline"),
&[target_ptr, ptr, elem_size, is_volatile],
&[],
location,
));
target_ptr,
ptr,
elem_size,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
)
.into(),
);

let value = valid_block
.append_operation(llvm::insert_value(
Expand Down Expand Up @@ -1437,21 +1417,17 @@ pub fn build_slice<'ctx, 'this>(
.result(0)?
.into();

let is_volatile = slice_block
.append_operation(arith::constant(
slice_block.append_operation(
ods::llvm::intr_memcpy(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
dst_ptr,
src_ptr,
dst_size,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
))
.result(0)?
.into();
slice_block.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy"),
&[dst_ptr, src_ptr, dst_size, is_volatile],
&[],
location,
));
)
.into(),
);

let k0 = slice_block
.append_operation(arith::constant(
Expand Down
47 changes: 20 additions & 27 deletions src/libfuncs/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ use melior::{
dialect::{
arith,
llvm::{self, r#type::opaque_pointer, AllocaOptions, LoadStoreOptions},
ods,
},
ir::{
attribute::{IntegerAttribute, StringAttribute, TypeAttribute},
attribute::{IntegerAttribute, TypeAttribute},
r#type::IntegerType,
Block, Location,
},
Expand Down Expand Up @@ -103,21 +104,17 @@ pub fn build_into_box<'ctx, 'this>(
.iter()
.all(|type_id| registry.get_type(type_id).unwrap().is_zst(registry)) =>
{
let is_volatile = entry
.append_operation(arith::constant(
entry.append_operation(
ods::llvm::intr_memcpy(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
ptr,
entry.argument(0)?.into(),
value_len,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
))
.result(0)?
.into();
entry.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy.inline"),
&[ptr, entry.argument(0)?.into(), value_len, is_volatile],
&[],
location,
));
)
.into(),
);
}
_ => {
entry.append_operation(llvm::store(
Expand Down Expand Up @@ -188,21 +185,17 @@ pub fn build_unbox<'ctx, 'this>(
.result(0)?
.into();

let is_volatile = entry
.append_operation(arith::constant(
entry.append_operation(
ods::llvm::intr_memcpy(
context,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()).into(),
stack_ptr,
entry.argument(0)?.into(),
value_len,
IntegerAttribute::new(0, IntegerType::new(context, 1).into()),
location,
))
.result(0)?
.into();
entry.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.memcpy.inline"),
&[stack_ptr, entry.argument(0)?.into(), value_len, is_volatile],
&[],
location,
));
)
.into(),
);

stack_ptr
}
Expand Down
24 changes: 8 additions & 16 deletions src/libfuncs/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use cairo_lang_sierra::{
use melior::{
dialect::{
arith::{self, CmpiPredicate},
llvm,
llvm, ods,
},
ir::{attribute::StringAttribute, r#type::IntegerType, Attribute, Block, Location, ValueLike},
ir::{r#type::IntegerType, Attribute, Block, Location},
Context,
};

Expand Down Expand Up @@ -108,13 +108,9 @@ pub fn build_withdraw_gas<'ctx, 'this>(
.into();

let resulting_gas = entry
.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.usub.sat"),
&[current_gas, gas_cost_val],
&[gas_cost_val.r#type()],
location,
))
.append_operation(
ods::llvm::intr_usub_sat(context, current_gas, gas_cost_val, location).into(),
)
.result(0)?
.into();

Expand Down Expand Up @@ -168,13 +164,9 @@ pub fn build_builtin_withdraw_gas<'ctx, 'this>(
.into();

let resulting_gas = entry
.append_operation(llvm::call_intrinsic(
context,
StringAttribute::new(context, "llvm.usub.sat"),
&[current_gas, gas_cost_val],
&[gas_cost_val.r#type()],
location,
))
.append_operation(
ods::llvm::intr_usub_sat(context, current_gas, gas_cost_val, location).into(),
)
.result(0)?
.into();

Expand Down
Loading

0 comments on commit 6ae0575

Please sign in to comment.