Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hercules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
Hercules
Commits
add0dc9c
Commit
add0dc9c
authored
3 months ago
by
Aaron Councilman
Browse files
Options
Downloads
Patches
Plain Diff
Only use zero collection constants in Juno
parent
1e9f5808
Branches
zero-collection-constants
No related tags found
No related merge requests found
Pipeline
#202351
passed
3 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
juno_frontend/src/codegen.rs
+80
-49
80 additions, 49 deletions
juno_frontend/src/codegen.rs
with
80 additions
and
49 deletions
juno_frontend/src/codegen.rs
+
80
−
49
View file @
add0dc9c
...
@@ -380,14 +380,7 @@ impl CodeGenerator<'_> {
...
@@ -380,14 +380,7 @@ impl CodeGenerator<'_> {
(
self
.build_union
(
*
tag
,
value
,
union_type
),
block
)
(
self
.build_union
(
*
tag
,
value
,
union_type
),
block
)
}
}
Expr
::
Constant
{
val
,
..
}
=>
{
Expr
::
Constant
{
val
,
..
}
=>
{
let
const_id
=
self
.build_constant
(
val
,
types
);
(
self
.build_constant
(
val
,
types
),
cur_block
)
let
mut
val
=
self
.builder
.allocate_node
();
let
val_node
=
val
.id
();
val
.build_constant
(
const_id
);
self
.builder
.add_node
(
val
);
(
val_node
,
cur_block
)
}
}
Expr
::
Zero
{
typ
}
=>
{
Expr
::
Zero
{
typ
}
=>
{
let
type_id
=
types
.lower_type
(
&
mut
self
.builder.builder
,
*
typ
);
let
type_id
=
types
.lower_type
(
&
mut
self
.builder.builder
,
*
typ
);
...
@@ -676,49 +669,87 @@ impl CodeGenerator<'_> {
...
@@ -676,49 +669,87 @@ impl CodeGenerator<'_> {
&
mut
self
,
&
mut
self
,
(
lit
,
typ
):
&
semant
::
Constant
,
(
lit
,
typ
):
&
semant
::
Constant
,
types
:
&
mut
TypeSolverInst
<
'a
>
,
types
:
&
mut
TypeSolverInst
<
'a
>
,
)
->
ConstantID
{
)
->
NodeID
{
match
lit
{
let
const_id
=
Literal
::
Unit
=>
self
.builder.builder
.create_constant_prod
(
vec!
[]
.into
()),
match
lit
{
Literal
::
Bool
(
val
)
=>
self
.builder.builder
.create_constant_bool
(
*
val
),
Literal
::
Unit
=>
{
Literal
::
Integer
(
val
)
=>
{
let
type_id
=
types
.lower_type
(
&
mut
self
.builder.builder
,
*
typ
);
let
p
=
types
.as_numeric_type
(
&
mut
self
.builder.builder
,
*
typ
);
self
.builder.builder
.create_constant_zero
(
type_id
)
match
p
{
Primitive
::
I8
=>
self
.builder.builder
.create_constant_i8
(
*
val
as
i8
),
Primitive
::
I16
=>
self
.builder.builder
.create_constant_i16
(
*
val
as
i16
),
Primitive
::
I32
=>
self
.builder.builder
.create_constant_i32
(
*
val
as
i32
),
Primitive
::
I64
=>
self
.builder.builder
.create_constant_i64
(
*
val
as
i64
),
Primitive
::
U8
=>
self
.builder.builder
.create_constant_u8
(
*
val
as
u8
),
Primitive
::
U16
=>
self
.builder.builder
.create_constant_u16
(
*
val
as
u16
),
Primitive
::
U32
=>
self
.builder.builder
.create_constant_u32
(
*
val
as
u32
),
Primitive
::
U64
=>
self
.builder.builder
.create_constant_u64
(
*
val
as
u64
),
Primitive
::
F32
=>
self
.builder.builder
.create_constant_f32
(
*
val
as
f32
),
Primitive
::
F64
=>
self
.builder.builder
.create_constant_f64
(
*
val
as
f64
),
_
=>
panic!
(
"Internal error in build_constant for integer"
),
}
}
}
Literal
::
Bool
(
val
)
=>
self
.builder.builder
.create_constant_bool
(
*
val
),
Literal
::
Float
(
val
)
=>
{
Literal
::
Integer
(
val
)
=>
{
let
p
=
types
.as_numeric_type
(
&
mut
self
.builder.builder
,
*
typ
);
let
p
=
types
.as_numeric_type
(
&
mut
self
.builder.builder
,
*
typ
);
match
p
{
match
p
{
Primitive
::
F32
=>
self
.builder.builder
.create_constant_f32
(
*
val
as
f32
),
Primitive
::
I8
=>
self
.builder.builder
.create_constant_i8
(
*
val
as
i8
),
Primitive
::
F64
=>
self
.builder.builder
.create_constant_f64
(
*
val
as
f64
),
Primitive
::
I16
=>
self
.builder.builder
.create_constant_i16
(
*
val
as
i16
),
_
=>
panic!
(
"Internal error in build_constant for float"
),
Primitive
::
I32
=>
self
.builder.builder
.create_constant_i32
(
*
val
as
i32
),
Primitive
::
I64
=>
self
.builder.builder
.create_constant_i64
(
*
val
as
i64
),
Primitive
::
U8
=>
self
.builder.builder
.create_constant_u8
(
*
val
as
u8
),
Primitive
::
U16
=>
self
.builder.builder
.create_constant_u16
(
*
val
as
u16
),
Primitive
::
U32
=>
self
.builder.builder
.create_constant_u32
(
*
val
as
u32
),
Primitive
::
U64
=>
self
.builder.builder
.create_constant_u64
(
*
val
as
u64
),
Primitive
::
F32
=>
self
.builder.builder
.create_constant_f32
(
*
val
as
f32
),
Primitive
::
F64
=>
self
.builder.builder
.create_constant_f64
(
*
val
as
f64
),
_
=>
panic!
(
"Internal error in build_constant for integer"
),
}
}
}
}
Literal
::
Float
(
val
)
=>
{
Literal
::
Tuple
(
vals
)
=>
{
let
p
=
types
.as_numeric_type
(
&
mut
self
.builder.builder
,
*
typ
);
let
mut
constants
=
vec!
[];
match
p
{
for
val
in
vals
{
Primitive
::
F32
=>
self
.builder.builder
.create_constant_f32
(
*
val
as
f32
),
constants
.push
(
self
.build_constant
(
val
,
types
));
Primitive
::
F64
=>
self
.builder.builder
.create_constant_f64
(
*
val
as
f64
),
_
=>
panic!
(
"Internal error in build_constant for float"
),
}
}
}
self
.builder.builder
.create_constant_prod
(
constants
.into
())
Literal
::
Tuple
(
vals
)
=>
{
}
let
type_id
=
types
.lower_type
(
&
mut
self
.builder.builder
,
*
typ
);
Literal
::
Sum
(
tag
,
val
)
=>
{
let
zero_const
=
self
.builder.builder
.create_constant_zero
(
type_id
);
let
constant
=
self
.build_constant
(
val
,
types
);
let
type_id
=
types
.lower_type
(
&
mut
self
.builder.builder
,
*
typ
);
let
mut
zero_node
=
self
.builder
.allocate_node
();
self
.builder
let
zero_id
=
zero_node
.id
();
.builder
zero_node
.build_constant
(
zero_const
);
.create_constant_sum
(
type_id
,
*
tag
as
u32
,
constant
)
self
.builder
.add_node
(
zero_node
);
.unwrap
()
}
let
mut
cur_node
=
zero_id
;
}
for
(
idx
,
val
)
in
vals
.iter
()
.enumerate
()
{
let
index
=
self
.builder.builder
.create_field_index
(
idx
);
let
val_id
=
self
.build_constant
(
val
,
types
);
let
mut
write
=
self
.builder
.allocate_node
();
let
write_id
=
write
.id
();
write
.build_write
(
cur_node
,
val_id
,
vec!
[
index
]
.into
());
self
.builder
.add_node
(
write
);
cur_node
=
write_id
;
}
return
cur_node
;
}
Literal
::
Sum
(
tag
,
val
)
=>
{
let
type_id
=
types
.lower_type
(
&
mut
self
.builder.builder
,
*
typ
);
let
zero_const
=
self
.builder.builder
.create_constant_zero
(
type_id
);
let
mut
zero_node
=
self
.builder
.allocate_node
();
let
zero_id
=
zero_node
.id
();
zero_node
.build_constant
(
zero_const
);
self
.builder
.add_node
(
zero_node
);
let
val_id
=
self
.build_constant
(
val
,
types
);
let
tag_index
=
self
.builder.builder
.create_variant_index
(
*
tag
);
let
mut
write
=
self
.builder
.allocate_node
();
let
write_id
=
write
.id
();
write
.build_write
(
zero_id
,
val_id
,
vec!
[
tag_index
]
.into
());
self
.builder
.add_node
(
write
);
return
write_id
;
}
};
let
mut
const_node
=
self
.builder
.allocate_node
();
let
node_id
=
const_node
.id
();
const_node
.build_constant
(
const_id
);
self
.builder
.add_node
(
const_node
);
node_id
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment