From 272abe75f1590b5c02ccfe831b6455fb2bdb1d6f Mon Sep 17 00:00:00 2001
From: Russel Arbore <russel.jma@gmail.com>
Date: Sun, 17 Nov 2024 15:00:05 -0600
Subject: [PATCH] Fix inline pass, get fac example working

---
 Cargo.lock                 | 12 ++++++++++++
 Cargo.toml                 |  2 +-
 hercules_opt/src/inline.rs |  2 +-
 juno_frontend/src/lib.rs   |  1 +
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 7cbeacf8..440cdd3c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -442,6 +442,18 @@ dependencies = [
  "pin-project-lite",
 ]
 
+[[package]]
+name = "fac"
+version = "0.1.0"
+dependencies = [
+ "async-std",
+ "clap",
+ "hercules_rt",
+ "juno_build",
+ "rand",
+ "with_builtin_macros",
+]
+
 [[package]]
 name = "fastrand"
 version = "2.1.1"
diff --git a/Cargo.toml b/Cargo.toml
index 63579146..8fa3079b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,7 @@ members = [
 
 	"hercules_samples/dot",
 	"hercules_samples/matmul",
-	#"hercules_samples/fac",
+	"hercules_samples/fac",
 
 	"juno_frontend",
 	"juno_scheduler",
diff --git a/hercules_opt/src/inline.rs b/hercules_opt/src/inline.rs
index bd192c39..ecc8027f 100644
--- a/hercules_opt/src/inline.rs
+++ b/hercules_opt/src/inline.rs
@@ -197,7 +197,7 @@ fn inline_func(
 
             // Stich the control use of the original call node's region with
             // the predecessor control of the inlined function's return.
-            edit = edit.replace_all_uses(control, called_return_pred)?;
+            edit = edit.replace_all_uses(control, old_id_to_new_id(called_return_pred))?;
 
             // Stitch uses of parameter nodes in the inlined function to the IDs
             // of arguments provided to the call node.
diff --git a/juno_frontend/src/lib.rs b/juno_frontend/src/lib.rs
index 96fefb7f..cccadbdd 100644
--- a/juno_frontend/src/lib.rs
+++ b/juno_frontend/src/lib.rs
@@ -151,6 +151,7 @@ pub fn compile_ir(
     if x_dot {
         pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
     }
+    add_pass!(pm, verify, Inline);
     add_pass!(pm, verify, CCP);
     add_pass!(pm, verify, DCE);
     add_pass!(pm, verify, GVN);
-- 
GitLab