* [HSA] Handle __builtin_{bzero,mempcpy}
@ 2015-12-04 13:43 Martin Liška
0 siblings, 0 replies; only message in thread
From: Martin Liška @ 2015-12-04 13:43 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 119 bytes --]
Hello.
The patch handles builtins mentioned in the email subject and was installed
to the HSA branch.
Thanks,
Martin
[-- Attachment #2: 0002-HSA-implement-__builtin_bzero.patch --]
[-- Type: text/x-patch, Size: 1616 bytes --]
From b56ba10d46c03cadfda16c6658dd3134f5da09f8 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 3 Dec 2015 13:31:28 +0100
Subject: [PATCH 2/3] HSA: implement __builtin_bzero
gcc/ChangeLog:
2015-12-03 Martin Liska <mliska@suse.cz>
* hsa-gen.c (build_memset_value): Provide special case
for zero value.
(gen_hsa_insns_for_call): Handle BUILT_IN_BZERO.
---
gcc/hsa-gen.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 85ba148..503f1fc 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -2649,6 +2649,9 @@ gen_hsa_memory_copy (hsa_bb *hbb, hsa_op_address *target, hsa_op_address *src,
static unsigned HOST_WIDE_INT
build_memset_value (unsigned HOST_WIDE_INT constant, unsigned byte_size)
{
+ if (constant == 0)
+ return 0;
+
HOST_WIDE_INT v = constant;
for (unsigned i = 1; i < byte_size; i++)
@@ -5434,6 +5437,32 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb)
break;
}
+ case BUILT_IN_BZERO:
+ {
+ tree dst = gimple_call_arg (stmt, 0);
+ tree byte_size = gimple_call_arg (stmt, 1);
+
+ if (!tree_fits_uhwi_p (byte_size))
+ {
+ gen_hsa_insns_for_direct_call (stmt, hbb);
+ return;
+ }
+
+ unsigned n = tree_to_uhwi (byte_size);
+
+ if (n > HSA_MEMORY_BUILTINS_LIMIT)
+ {
+ gen_hsa_insns_for_direct_call (stmt, hbb);
+ return;
+ }
+
+ hsa_op_address *dst_addr;
+ dst_addr = get_address_from_value (dst, hbb);
+
+ gen_hsa_memory_set (hbb, dst_addr, 0, n);
+
+ break;
+ }
case BUILT_IN_ALLOCA:
case BUILT_IN_ALLOCA_WITH_ALIGN:
{
--
2.6.3
[-- Attachment #3: 0003-HSA-implement-__builtin_mempcpy.patch --]
[-- Type: text/x-patch, Size: 1952 bytes --]
From cf61d78b048df8ce68c7d7586304faebce1c339e Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 3 Dec 2015 15:10:14 +0100
Subject: [PATCH 3/3] HSA: implement __builtin_mempcpy
---
gcc/hsa-gen.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 503f1fc..25ef914 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -1180,7 +1180,6 @@ hsa_op_address::operator new (size_t)
return hsa_allocp_operand_address->allocate_raw ();
}
-
/* Constructor of an operand referring to HSAIL code. */
hsa_op_code_ref::hsa_op_code_ref () : hsa_op_base (BRIG_KIND_OPERAND_CODE_REF),
@@ -5047,7 +5046,8 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb)
}
tree fndecl = gimple_call_fndecl (stmt);
- switch (DECL_FUNCTION_CODE (fndecl))
+ enum built_in_function builtin = DECL_FUNCTION_CODE (fndecl);
+ switch (builtin)
{
case BUILT_IN_FABS:
case BUILT_IN_FABSF:
@@ -5366,6 +5366,7 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb)
break;
}
case BUILT_IN_MEMCPY:
+ case BUILT_IN_MEMPCPY:
{
tree byte_size = gimple_call_arg (stmt, 2);
@@ -5393,7 +5394,25 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb)
tree lhs = gimple_call_lhs (stmt);
if (lhs)
- gen_hsa_insns_for_single_assignment (lhs, dst, hbb);
+ {
+ hsa_op_reg *lhs_reg = hsa_cfun->reg_for_gimple_ssa (lhs);
+ hsa_op_with_type *dst_reg = hsa_reg_or_immed_for_gimple_op (dst,
+ hbb);
+ hsa_op_with_type *tmp;
+
+ if (builtin == BUILT_IN_MEMPCPY)
+ {
+ tmp = new hsa_op_reg (dst_reg->m_type);
+ hsa_insn_basic *add = new hsa_insn_basic
+ (3, BRIG_OPCODE_ADD, tmp->m_type,
+ tmp, dst_reg, new hsa_op_immed (n, dst_reg->m_type));
+ hbb->append_insn (add);
+ }
+ else
+ tmp = dst_reg;
+
+ hsa_build_append_simple_mov (lhs_reg, tmp, hbb);
+ }
break;
}
--
2.6.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-12-04 13:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 13:43 [HSA] Handle __builtin_{bzero,mempcpy} Martin Liška
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).