aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-05-03 12:45:45 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-05-04 13:13:12 +0100
commit74f4ee8d38f5aa58e4722725f3016f6420d4654b (patch)
treebe164dafb951987e1e8a25ac3be87c9555d0b6b3 /gcc/rust/backend/rust-compile.cc
parent21b9e1226cfbc4137a881a71c5e6f904fc5b364e (diff)
downloadgcc-74f4ee8d38f5aa58e4722725f3016f6420d4654b.zip
gcc-74f4ee8d38f5aa58e4722725f3016f6420d4654b.tar.gz
gcc-74f4ee8d38f5aa58e4722725f3016f6420d4654b.tar.bz2
Take advantage of OBJ_TYPE_REF'S in dyn calls
OBJ_TYPE_REF's are the gcc nodes that signify that this is a virtual call which gives a hint to the optimizers for devirtualization. Fixes #996 Fixes #854
Diffstat (limited to 'gcc/rust/backend/rust-compile.cc')
-rw-r--r--gcc/rust/backend/rust-compile.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index db22227..49155d2 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -312,6 +312,9 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
Location locus)
{
tree dynamic_object = TyTyResolveCompile::compile (ctx, ty);
+ tree dynamic_object_fields = TYPE_FIELDS (dynamic_object);
+ tree vtable_field = DECL_CHAIN (dynamic_object_fields);
+ rust_assert (TREE_CODE (TREE_TYPE (vtable_field)) == ARRAY_TYPE);
//' this assumes ordering and current the structure is
// __trait_object_ptr
@@ -326,8 +329,10 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
= address_expression (compiled_ref,
build_pointer_type (TREE_TYPE (compiled_ref)),
locus);
- std::vector<tree> vals;
- vals.push_back (address_of_compiled_ref);
+
+ std::vector<tree> vtable_ctor_elems;
+ std::vector<unsigned long> vtable_ctor_idx;
+ unsigned long i = 0;
for (auto &bound : ty->get_object_items ())
{
const Resolver::TraitItemReference *item = bound.first;
@@ -336,11 +341,16 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
auto address = compute_address_for_trait_item (item, predicate,
probed_bounds_for_receiver,
actual, actual, locus);
- vals.push_back (address);
+ vtable_ctor_elems.push_back (address);
+ vtable_ctor_idx.push_back (i++);
}
+ tree vtable_ctor = ctx->get_backend ()->array_constructor_expression (
+ TREE_TYPE (vtable_field), vtable_ctor_idx, vtable_ctor_elems, locus);
+
+ std::vector<tree> dyn_ctor = {address_of_compiled_ref, vtable_ctor};
return ctx->get_backend ()->constructor_expression (dynamic_object, false,
- vals, -1, locus);
+ dyn_ctor, -1, locus);
}
tree