From be55373cb4e8a25172631b5b10725588bf17b333 Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Tue, 4 Mar 2025 19:11:13 -0600 Subject: [PATCH 1/3] Add more llvm attrs --- hercules_cg/src/cpu.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hercules_cg/src/cpu.rs b/hercules_cg/src/cpu.rs index 37bf814d..f7fd34db 100644 --- a/hercules_cg/src/cpu.rs +++ b/hercules_cg/src/cpu.rs @@ -76,7 +76,7 @@ impl<'a> CPUContext<'a> { } else { write!( w, - "define dso_local nonnull noundef {} @{}_{}(", + "define dso_local nonnull noundef nounwind nosync willreturn norecurse {} @{}_{}(", self.get_type(return_type), self.module_name, self.function.name, @@ -346,7 +346,7 @@ impl<'a> CPUContext<'a> { let offset = offsets[&id].0; write!( body, - " {} = getelementptr i8, ptr %backing, i64 %dc{}\n", + " {} = getelementptr inbounds i8, ptr %backing, i64 %dc{}\n", self.get_value(id, false), offset.idx() )?; @@ -473,11 +473,14 @@ impl<'a> CPUContext<'a> { let opcode = match (op, op_ty) { (BinaryOperator::Add, OpTy::Float) => "fadd", - (BinaryOperator::Add, _) => "add", + (BinaryOperator::Add, OpTy::Unsigned) => "add nuw", + (BinaryOperator::Add, OpTy::Signed) => "add nsw", (BinaryOperator::Sub, OpTy::Float) => "fsub", - (BinaryOperator::Sub, _) => "sub", + (BinaryOperator::Sub, OpTy::Unsigned) => "sub nuw", + (BinaryOperator::Sub, OpTy::Signed) => "sub nsw", (BinaryOperator::Mul, OpTy::Float) => "fmul", - (BinaryOperator::Mul, _) => "mul", + (BinaryOperator::Mul, OpTy::Unsigned) => "mul nuw", + (BinaryOperator::Mul, OpTy::Signed) => "mul nsw", (BinaryOperator::Div, OpTy::Float) => "fdiv", (BinaryOperator::Div, OpTy::Unsigned) => "udiv", (BinaryOperator::Div, OpTy::Signed) => "sdiv", @@ -1005,7 +1008,7 @@ impl<'a> CPUContext<'a> { let name = format!("%gep.{}", Self::gen_filler_id()); write!( body, - " {} = getelementptr i8, ptr {}, i64 {}\n", + " {} = getelementptr inbounds i8, ptr {}, i64 {}\n", name, ptr, size )?; Ok(name) -- GitLab From 8fa5435430db7809ead2ef8e45b15a7aa080c4bb Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Tue, 4 Mar 2025 19:13:45 -0600 Subject: [PATCH 2/3] fix --- hercules_cg/src/cpu.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hercules_cg/src/cpu.rs b/hercules_cg/src/cpu.rs index f7fd34db..e13a7c3f 100644 --- a/hercules_cg/src/cpu.rs +++ b/hercules_cg/src/cpu.rs @@ -68,7 +68,7 @@ impl<'a> CPUContext<'a> { if self.types[return_type.idx()].is_primitive() { write!( w, - "define dso_local {} @{}_{}(", + "define dso_local nounwind nosync willreturn norecurse {} @{}_{}(", self.get_type(return_type), self.module_name, self.function.name, @@ -96,7 +96,7 @@ impl<'a> CPUContext<'a> { )?; write!( w, - "define dso_local void @{}_{}(", + "define dso_local nounwind nosync willreturn norecurse void @{}_{}(", self.module_name, self.function.name, )?; } -- GitLab From a64d57631d01937e8668378a44fa483b13c7be22 Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Tue, 4 Mar 2025 19:15:00 -0600 Subject: [PATCH 3/3] fix --- hercules_cg/src/cpu.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hercules_cg/src/cpu.rs b/hercules_cg/src/cpu.rs index e13a7c3f..c5ffe760 100644 --- a/hercules_cg/src/cpu.rs +++ b/hercules_cg/src/cpu.rs @@ -68,7 +68,7 @@ impl<'a> CPUContext<'a> { if self.types[return_type.idx()].is_primitive() { write!( w, - "define dso_local nounwind nosync willreturn norecurse {} @{}_{}(", + "define dso_local {} @{}_{}(", self.get_type(return_type), self.module_name, self.function.name, @@ -76,7 +76,7 @@ impl<'a> CPUContext<'a> { } else { write!( w, - "define dso_local nonnull noundef nounwind nosync willreturn norecurse {} @{}_{}(", + "define dso_local nonnull noundef {} @{}_{}(", self.get_type(return_type), self.module_name, self.function.name, @@ -96,7 +96,7 @@ impl<'a> CPUContext<'a> { )?; write!( w, - "define dso_local nounwind nosync willreturn norecurse void @{}_{}(", + "define dso_local void @{}_{}(", self.module_name, self.function.name, )?; } @@ -146,7 +146,7 @@ impl<'a> CPUContext<'a> { self.function.name, )?; } - write!(w, ") {{\n")?; + write!(w, ") nounwind nosync willreturn norecurse {{\n")?; let mut blocks: BTreeMap<_, _> = (0..self.function.nodes.len()) .filter(|idx| self.function.nodes[*idx].is_control()) -- GitLab