Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Codegen: use malloc_atomic whenever possible. Fixes #4081
- Loading branch information
Showing
3 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,49 @@ module Crystal | |
end | ||
end | ||
|
||
# Returns `true` if the type has inner pointers. | ||
# This is useful to know because if a type doesn't have | ||
# inner pointers we can use `malloc_atomic` instead of | ||
# `malloc` in `Pointer.malloc` for a tiny performance boost. | ||
def has_inner_pointers? | ||
case self | ||
when void? | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
asterite
Author
Member
|
||
# We consider Void to have pointers, so doing | ||
# Pointer(Void).malloc(...).as(ReferenceType) | ||
# will consider potential inner pointers as such. | ||
true | ||
when PointerInstanceType | ||
true | ||
when ProcInstanceType | ||
# A proc can have closure data which might have pointers | ||
true | ||
when StaticArrayInstanceType | ||
self.element_type.has_inner_pointers? | ||
when TupleInstanceType | ||
self.tuple_types.any? &.has_inner_pointers? | ||
when NamedTupleInstanceType | ||
self.entries.any? &.type.has_inner_pointers? | ||
when PrimitiveType | ||
false | ||
when EnumType | ||
false | ||
when UnionType | ||
self.union_types.any? &.has_inner_pointers? | ||
when AliasType | ||
self.aliased_type.has_inner_pointers? | ||
when TypeDefType | ||
self.typedef.has_inner_pointers? | ||
when InstanceVarContainer | ||
if struct? | ||
all_instance_vars.each_value.any? &.type.has_inner_pointers? | ||
else | ||
true | ||
end | ||
else | ||
true | ||
end | ||
end | ||
|
||
def llvm_name | ||
String.build do |io| | ||
llvm_name io | ||
|
Shouldn't this be
.void?