diff options
author | Cherry Zhang <cherryyz@google.com> | 2019-07-02 16:47:48 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-07-02 16:47:48 +0000 |
commit | e2790e1eab7bfaae5a733ed742a59a518253a645 (patch) | |
tree | b3c80682051e61f7267a88209da91bec78937dff /gcc | |
parent | dab0477b0bbcc90418a7e1aec40b465de3ec842c (diff) | |
download | gcc-e2790e1eab7bfaae5a733ed742a59a518253a645.zip gcc-e2790e1eab7bfaae5a733ed742a59a518253a645.tar.gz gcc-e2790e1eab7bfaae5a733ed742a59a518253a645.tar.bz2 |
compiler: use builtin memset for non-pointer memclr
For zeroing a range of memory that doesn't contain pointer, we
can use builtin memset directly.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184438
* go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_memset.
From-SVN: r272944
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/go/go-gcc.cc | 9 | ||||
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 14 | ||||
-rw-r--r-- | gcc/go/gofrontend/runtime.def | 8 | ||||
-rw-r--r-- | gcc/go/gofrontend/statements.cc | 18 |
6 files changed, 40 insertions, 15 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index 9842c85..60d1187 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,7 @@ +2019-07-02 Cherry Zhang <cherryyz@google.com> + + * go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_memset. + 2019-06-21 Cherry Zhang <cherryyz@google.com> * go-gcc.cc (Gcc_backend::Gcc_backend): Define math/bits diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index 879149e..d9fc1a7 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -613,6 +613,15 @@ Gcc_backend::Gcc_backend() NULL_TREE), false, false); + // We use __builtin_memset for zeroing data. + this->define_builtin(BUILT_IN_MEMSET, "__builtin_memset", "memset", + build_function_type_list(void_type_node, + ptr_type_node, + integer_type_node, + size_type_node, + NULL_TREE), + false, false); + // Used by runtime/internal/sys and math/bits. this->define_builtin(BUILT_IN_CTZ, "__builtin_ctz", "ctz", build_function_type_list(integer_type_node, diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 7ee3e11..11cba0f 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -1e042a49d6f2e95d371301aa7b911522dc5877f4 +7f753feb8df400d6ed17cdbdfb364f7f3a42fb31 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 2f33dee..d521551 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -8910,10 +8910,16 @@ Builtin_call_expression::flatten_append(Gogo* gogo, Named_object* function, a2 = Expression::make_type_info(element_type, TYPE_INFO_SIZE); a2 = Expression::make_binary(OPERATOR_MULT, a2, ref, loc); - Runtime::Function code = (element_type->has_pointer() - ? Runtime::MEMCLRHASPTR - : Runtime::MEMCLRNOPTR); - call = Runtime::make_call(code, loc, 2, a1, a2); + if (element_type->has_pointer()) + call = Runtime::make_call(Runtime::MEMCLRHASPTR, loc, 2, a1, a2); + else + { + Type* int32_type = Type::lookup_integer_type("int32"); + Expression* zero = + Expression::make_integer_ul(0, int32_type, loc); + call = Runtime::make_call(Runtime::BUILTIN_MEMSET, loc, 3, a1, + zero, a2); + } if (element_type->has_pointer()) { diff --git a/gcc/go/gofrontend/runtime.def b/gcc/go/gofrontend/runtime.def index ec7ec76..f510a65 100644 --- a/gcc/go/gofrontend/runtime.def +++ b/gcc/go/gofrontend/runtime.def @@ -351,10 +351,6 @@ DEF_GO_RUNTIME(GCWRITEBARRIER, "runtime.gcWriteBarrier", DEF_GO_RUNTIME(TYPEDMEMMOVE, "runtime.typedmemmove", P3(TYPE, POINTER, POINTER), R0()) -// Clear memory that contains no pointer. -DEF_GO_RUNTIME(MEMCLRNOPTR, "runtime.memclrNoHeapPointers", - P2(POINTER, UINTPTR), R0()) - // Clear memory that contains pointer. DEF_GO_RUNTIME(MEMCLRHASPTR, "runtime.memclrHasPointers", P2(POINTER, UINTPTR), R0()) @@ -414,6 +410,10 @@ DEF_GO_RUNTIME(UNREACHABLE, "__builtin_unreachable", P0(), R0()) DEF_GO_RUNTIME(BUILTIN_MEMMOVE, "__builtin_memmove", P3(POINTER, POINTER, UINTPTR), R0()) +// Memset, used for zeroing memory. +DEF_GO_RUNTIME(BUILTIN_MEMSET, "__builtin_memset", + P3(POINTER, INT32, UINTPTR), R0()) + // Various intrinsics. // Get the caller's PC, used for runtime.getcallerpc. diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index c095588..968c8a0 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -6882,12 +6882,18 @@ For_range_statement::lower_array_range_clear(Gogo* gogo, Temporary_statement* ts2 = Statement::make_temporary(NULL, e2, loc); b->add_statement(ts2); - Expression* arg1 = Expression::make_temporary_reference(ts1, loc); - Expression* arg2 = Expression::make_temporary_reference(ts2, loc); - Runtime::Function code = (elem_type->has_pointer() - ? Runtime::MEMCLRHASPTR - : Runtime::MEMCLRNOPTR); - Expression* call = Runtime::make_call(code, loc, 2, arg1, arg2); + Expression* ptr_arg = Expression::make_temporary_reference(ts1, loc); + Expression* sz_arg = Expression::make_temporary_reference(ts2, loc); + Expression* call; + if (elem_type->has_pointer()) + call = Runtime::make_call(Runtime::MEMCLRHASPTR, loc, 2, ptr_arg, sz_arg); + else + { + Type* int32_type = Type::lookup_integer_type("int32"); + Expression* zero = Expression::make_integer_ul(0, int32_type, loc); + call = Runtime::make_call(Runtime::BUILTIN_MEMSET, loc, 3, ptr_arg, + zero, sz_arg); + } Statement* cs3 = Statement::make_statement(call, true); b->add_statement(cs3); |