Skip to content

Commit 6211b04

Browse files
committed
Replace usages of chainon
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>
1 parent 7327326 commit 6211b04

2 files changed

Lines changed: 55 additions & 17 deletions

File tree

gcc/rust/backend/rust-compile-asm.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#include "rust-compile-asm.h"
22
#include "rust-compile-expr.h"
33
#include "rust-system.h"
4+
#include "rust-ggc.h"
45

56
namespace Rust {
67
namespace Compile {
78

8-
static tree
9-
chain_asm_operand (tree head, const char *constraint, tree value)
9+
static void
10+
chain_asm_operand (GGC::ChainList &ls, const char *constraint, tree value)
1011
{
1112
auto name = build_string (strlen (constraint) + 1, constraint);
12-
return chainon (head,
13-
build_tree_list (build_tree_list (NULL_TREE, name), value));
13+
ls.push_back (build_tree_list (build_tree_list (NULL_TREE, name), value));
1414
}
1515

1616
CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}
@@ -107,7 +107,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
107107
{
108108
// TODO: Do i need to do this?
109109

110-
tree head = NULL_TREE;
110+
GGC::ChainList ls;
111111
for (auto &operand : expr.get_operands ())
112112
{
113113
tl::optional<std::reference_wrapper<HIR::Expr>> out_expr
@@ -118,9 +118,9 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
118118
tree out_tree = CompileExpr::Compile (*out_expr, this->ctx);
119119
// expects a tree list
120120
// TODO: This assumes that the output is a register
121-
head = chain_asm_operand (head, "=r", out_tree);
121+
chain_asm_operand (ls, "=r", out_tree);
122122
}
123-
return head;
123+
return ls.get_head ();
124124
}
125125

126126
tl::optional<std::reference_wrapper<HIR::Expr>>
@@ -147,7 +147,8 @@ tree
147147
CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
148148
{
149149
// TODO: Do i need to do this?
150-
tree head = NULL_TREE;
150+
151+
GGC::ChainList ls;
151152
for (auto &operand : expr.get_operands ())
152153
{
153154
tl::optional<std::reference_wrapper<HIR::Expr>> in_expr
@@ -158,9 +159,9 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
158159
tree in_tree = CompileExpr::Compile (*in_expr, this->ctx);
159160
// expects a tree list
160161
// TODO: This assumes that the input is a register
161-
head = chain_asm_operand (head, "r", in_tree);
162+
chain_asm_operand (ls, "r", in_tree);
162163
}
163-
return head;
164+
return ls.get_head ();
164165
}
165166

166167
tree
@@ -182,29 +183,28 @@ CompileLlvmAsm::CompileLlvmAsm (Context *ctx) : HIRCompileBase (ctx) {}
182183
tree
183184
CompileLlvmAsm::construct_operands (std::vector<HIR::LlvmOperand> operands)
184185
{
185-
tree head = NULL_TREE;
186+
GGC::ChainList ls;
186187
for (auto &operand : operands)
187188
{
188189
tree t = CompileExpr::Compile (*operand.expr, this->ctx);
189190
auto name = build_string (operand.constraint.size () + 1,
190191
operand.constraint.c_str ());
191-
head = chainon (head,
192-
build_tree_list (build_tree_list (NULL_TREE, name), t));
192+
ls.push_back (build_tree_list (build_tree_list (NULL_TREE, name), t));
193193
}
194-
return head;
194+
return ls.get_head ();
195195
}
196196

197197
tree
198198
CompileLlvmAsm::construct_clobbers (std::vector<AST::TupleClobber> clobbers)
199199
{
200-
tree head = NULL_TREE;
200+
GGC::ChainList ls;
201201
for (auto &clobber : clobbers)
202202
{
203203
auto name
204204
= build_string (clobber.symbol.size () + 1, clobber.symbol.c_str ());
205-
head = chainon (head, build_tree_list (NULL_TREE, name));
205+
ls.push_back (build_tree_list (NULL_TREE, name));
206206
}
207-
return head;
207+
return ls.get_head ();
208208
}
209209

210210
tree

gcc/rust/util/rust-ggc.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,44 @@ operator== (const std::string &a, const Ident &b)
6060
return b == a;
6161
}
6262

63+
class ChainList
64+
{
65+
tree head;
66+
tree *tail_cdr;
67+
68+
public:
69+
ChainList () : head (NULL_TREE), tail_cdr (&head) {}
70+
71+
ChainList (ChainList &&oth)
72+
{
73+
head = oth.head;
74+
if (oth.tail_cdr == &oth.head)
75+
tail_cdr = &oth.head;
76+
else
77+
tail_cdr = oth.tail_cdr;
78+
oth.head = NULL_TREE;
79+
oth.tail_cdr = &oth.head;
80+
}
81+
82+
ChainList &operator= (ChainList &&oth)
83+
{
84+
this->~ChainList ();
85+
new (this) ChainList (std::move (oth));
86+
return *this;
87+
}
88+
89+
tree get_head () const { return head; }
90+
91+
// TREE_CHAIN (ent) will be modified
92+
// making ent a node in this list
93+
// do not push a single tree to multiple ChainList objects
94+
void push_back (tree ent)
95+
{
96+
*tail_cdr = ent;
97+
tail_cdr = &TREE_CHAIN (ent);
98+
}
99+
};
100+
63101
} // namespace GGC
64102

65103
} // namespace Rust

0 commit comments

Comments
 (0)