Optimize literal list construction in LLVM backend

Currently, list literals are always heap-allocated and their elements
are stored by emitting a GEP and store for each item in the literal.
This produces huge quantities of IR, causing compile times for e.g.
programs with large literals or ingested files to blow up.

Instead, if a list literal consists entirely of literal values, create a
global section for the literal and return a pointer to it.
This commit is contained in:
Ayaz Hafiz 2024-06-22 19:07:18 -05:00 committed by Brendan Hansknecht
parent 08019951be
commit 9abbcfaafc
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
2 changed files with 51 additions and 109 deletions

View file

@ -49,6 +49,17 @@ impl<'a> ListLiteralElement<'a> {
_ => None,
}
}
pub fn get_literal(&self) -> Option<Literal<'a>> {
match self {
Self::Literal(l) => Some(*l),
_ => None,
}
}
pub fn is_literal(&self) -> bool {
matches!(self, Self::Literal(_))
}
}
pub enum NumLiteral {