From 82b8927f860cb9047a4bdc890f4b9354bd6822e9 Mon Sep 17 00:00:00 2001
From: rarbore2 <rarbore2@illinois.edu>
Date: Sun, 22 Dec 2024 00:21:40 -0600
Subject: [PATCH] LLVM parameter / return attributes

---
 hercules_cg/src/cpu.rs | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/hercules_cg/src/cpu.rs b/hercules_cg/src/cpu.rs
index a8f16790..eba161bb 100644
--- a/hercules_cg/src/cpu.rs
+++ b/hercules_cg/src/cpu.rs
@@ -64,12 +64,21 @@ struct LLVMBlock {
 impl<'a> CPUContext<'a> {
     fn codegen_function<W: Write>(&self, w: &mut W) -> Result<(), Error> {
         // Dump the function signature.
-        write!(
-            w,
-            "define {} @{}(",
-            self.get_type(self.function.return_type),
-            self.function.name
-        )?;
+        if self.types[self.function.return_type.idx()].is_primitive() {
+            write!(
+                w,
+                "define dso_local {} @{}(",
+                self.get_type(self.function.return_type),
+                self.function.name
+            )?;
+        } else {
+            write!(
+                w,
+                "define dso_local nonnull noundef {} @{}(",
+                self.get_type(self.function.return_type),
+                self.function.name
+            )?;
+        }
         let mut first_param = true;
         // The first set of parameters are dynamic constants.
         for idx in 0..self.function.num_dynamic_constants {
@@ -87,7 +96,16 @@ impl<'a> CPUContext<'a> {
             } else {
                 write!(w, ", ")?;
             }
-            write!(w, "{} %p{}", self.get_type(*ty), idx)?;
+            if self.types[ty.idx()].is_primitive() {
+                write!(w, "{} %p{}", self.get_type(*ty), idx)?;
+            } else {
+                write!(
+                    w,
+                    "{} noalias nofree nonnull noundef %p{}",
+                    self.get_type(*ty),
+                    idx
+                )?;
+            }
         }
         write!(w, ") {{\n")?;
 
-- 
GitLab