]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Replace usages of chainon
authorOwen Avery <powerboat9.gamer@gmail.com>
Mon, 30 Mar 2026 02:21:20 +0000 (22:21 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 14 Apr 2026 21:48:59 +0000 (23:48 +0200)
gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc: Include "rust-ggc.h".
(chain_asm_operand): Use GGC::ChainList.
(CompileAsm::asm_construct_outputs): Likewise.
(CompileAsm::asm_construct_inputs): Likewise.
(CompileLlvmAsm::construct_operands): Likewise.
(CompileLlvmAsm::construct_clobbers): Likewise.
* util/rust-ggc.h (class ChainList): New class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/backend/rust-compile-asm.cc
gcc/rust/util/rust-ggc.h

index be0305a6e50af7f2daf2b049105b7ed91acd6510..2ac65bd6520bee4080081eafe55b7bc67b546381 100644 (file)
@@ -1,16 +1,16 @@
 #include "rust-compile-asm.h"
 #include "rust-compile-expr.h"
 #include "rust-system.h"
+#include "rust-ggc.h"
 
 namespace Rust {
 namespace Compile {
 
-static tree
-chain_asm_operand (tree head, const char *constraint, tree value)
+static void
+chain_asm_operand (GGC::ChainList &ls, const char *constraint, tree value)
 {
   auto name = build_string (strlen (constraint) + 1, constraint);
-  return chainon (head,
-                 build_tree_list (build_tree_list (NULL_TREE, name), value));
+  ls.push_back (build_tree_list (build_tree_list (NULL_TREE, name), value));
 }
 
 CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}
@@ -107,7 +107,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
 {
   // TODO: Do i need to do this?
 
-  tree head = NULL_TREE;
+  GGC::ChainList ls;
   for (auto &operand : expr.get_operands ())
     {
       tl::optional<std::reference_wrapper<HIR::Expr>> out_expr
@@ -118,9 +118,9 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
       tree out_tree = CompileExpr::Compile (*out_expr, this->ctx);
       // expects a tree list
       // TODO: This assumes that the output is a register
-      head = chain_asm_operand (head, "=r", out_tree);
+      chain_asm_operand (ls, "=r", out_tree);
     }
-  return head;
+  return ls.get_head ();
 }
 
 tl::optional<std::reference_wrapper<HIR::Expr>>
@@ -147,7 +147,8 @@ tree
 CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
 {
   // TODO: Do i need to do this?
-  tree head = NULL_TREE;
+
+  GGC::ChainList ls;
   for (auto &operand : expr.get_operands ())
     {
       tl::optional<std::reference_wrapper<HIR::Expr>> in_expr
@@ -158,9 +159,9 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
       tree in_tree = CompileExpr::Compile (*in_expr, this->ctx);
       // expects a tree list
       // TODO: This assumes that the input is a register
-      head = chain_asm_operand (head, "r", in_tree);
+      chain_asm_operand (ls, "r", in_tree);
     }
-  return head;
+  return ls.get_head ();
 }
 
 tree
@@ -182,29 +183,28 @@ CompileLlvmAsm::CompileLlvmAsm (Context *ctx) : HIRCompileBase (ctx) {}
 tree
 CompileLlvmAsm::construct_operands (std::vector<HIR::LlvmOperand> operands)
 {
-  tree head = NULL_TREE;
+  GGC::ChainList ls;
   for (auto &operand : operands)
     {
       tree t = CompileExpr::Compile (*operand.expr, this->ctx);
       auto name = build_string (operand.constraint.size () + 1,
                                operand.constraint.c_str ());
-      head = chainon (head,
-                     build_tree_list (build_tree_list (NULL_TREE, name), t));
+      ls.push_back (build_tree_list (build_tree_list (NULL_TREE, name), t));
     }
-  return head;
+  return ls.get_head ();
 }
 
 tree
 CompileLlvmAsm::construct_clobbers (std::vector<AST::TupleClobber> clobbers)
 {
-  tree head = NULL_TREE;
+  GGC::ChainList ls;
   for (auto &clobber : clobbers)
     {
       auto name
        = build_string (clobber.symbol.size () + 1, clobber.symbol.c_str ());
-      head = chainon (head, build_tree_list (NULL_TREE, name));
+      ls.push_back (build_tree_list (NULL_TREE, name));
     }
-  return head;
+  return ls.get_head ();
 }
 
 tree
index e4ebabd412cd9b8bb6c9aaa559f4f94979dc9678..eb4b327fb9a6250820a986197016dd3dbee1fb61 100644 (file)
@@ -60,6 +60,44 @@ operator== (const std::string &a, const Ident &b)
   return b == a;
 }
 
+class ChainList
+{
+  tree head;
+  tree *tail_cdr;
+
+public:
+  ChainList () : head (NULL_TREE), tail_cdr (&head) {}
+
+  ChainList (ChainList &&oth)
+  {
+    head = oth.head;
+    if (oth.tail_cdr == &oth.head)
+      tail_cdr = &oth.head;
+    else
+      tail_cdr = oth.tail_cdr;
+    oth.head = NULL_TREE;
+    oth.tail_cdr = &oth.head;
+  }
+
+  ChainList &operator= (ChainList &&oth)
+  {
+    this->~ChainList ();
+    new (this) ChainList (std::move (oth));
+    return *this;
+  }
+
+  tree get_head () const { return head; }
+
+  // TREE_CHAIN (ent) will be modified
+  // making ent a node in this list
+  // do not push a single tree to multiple ChainList objects
+  void push_back (tree ent)
+  {
+    *tail_cdr = ent;
+    tail_cdr = &TREE_CHAIN (ent);
+  }
+};
+
 } // namespace GGC
 
 } // namespace Rust