Address RVO issue on some compilers
Suppresses pessimizing-move during clang compilation as for some gcc
toolchains RVO is not ensured until C++17 thus an explicit call to
std::move might be required to avoid compilation error for non-copyable
ojects (e.g. std::unique_ptr)
Resolves: COMPMID-3599
Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Change-Id: Ie3fa44fb0cf631655aecbeb6c82021a68f500a33
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4230
Reviewed-by: Giorgio Arena <giorgio.arena@arm.com>
Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
diff --git a/SConscript b/SConscript
index 656336d..2b70ca1 100644
--- a/SConscript
+++ b/SConscript
@@ -42,14 +42,14 @@
Default(obj)
return obj
-def build_library(name, sources, static=False, libs=[]):
+def build_library(name, build_env, sources, static=False, libs=[]):
if static:
- obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
+ obj = build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
else:
if env['set_soname']:
- obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
+ obj = build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
else:
- obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
+ obj = build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
obj = install_lib(obj)
Default(obj)
@@ -137,6 +137,9 @@
version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
arm_compute_env.AlwaysBuild(version_file)
+default_cpp_compiler = 'g++' if env['os'] != 'android' else 'clang++'
+cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
+
# Generate embed files
generate_embed = [ version_file ]
if env['opencl'] and env['embed_kernels']:
@@ -282,26 +285,29 @@
bootcode_o = build_bootcode_objs(bootcode_files)
Export('bootcode_o')
-arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
+arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, core_files, static=True)
Export('arm_compute_core_a')
if env['os'] != 'bare_metal' and not env['standalone']:
- arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
+ arm_compute_core_so = build_library('arm_compute_core', arm_compute_env, core_files, static=False)
Export('arm_compute_core_so')
-arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
+arm_compute_a = build_library('arm_compute-static', arm_compute_env, runtime_files, static=True, libs = [ arm_compute_core_a ])
Export('arm_compute_a')
if env['os'] != 'bare_metal' and not env['standalone']:
- arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
+ arm_compute_so = build_library('arm_compute', arm_compute_env, runtime_files, static=False, libs = [ "arm_compute_core" ])
Depends(arm_compute_so, arm_compute_core_so)
Export('arm_compute_so')
-arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
+arm_compute_graph_env = arm_compute_env.Clone();
+if 'clang++' in cpp_compiler:
+ arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-pessimizing-move'])
+arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True, libs = [ arm_compute_a])
Export('arm_compute_graph_a')
if env['os'] != 'bare_metal' and not env['standalone']:
- arm_compute_graph_so = build_library('arm_compute_graph', graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"])
+ arm_compute_graph_so = build_library('arm_compute_graph', arm_compute_graph_env, graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"])
Depends(arm_compute_graph_so, arm_compute_so)
Export('arm_compute_graph_so')
diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h
index 873957e..ee5dc3e 100644
--- a/arm_compute/graph/backends/FunctionHelpers.h
+++ b/arm_compute/graph/backends/FunctionHelpers.h
@@ -47,13 +47,6 @@
{
namespace detail
{
-// Address rule DR-9R5 (1579. Return by converting move constructor)
-#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5))
-#define RETURN_UNIQUE_PTR(x) (x)
-#else /* defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5)) */
-#define RETURN_UNIQUE_PTR(x) (std::move(x))
-#endif /* defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5)) */
-
/** Returns backing tensor of a given tensor
*
* @tparam TargetInfo Target information
@@ -128,7 +121,7 @@
<< " InPlace : " << is_in_place_operation(input, output)
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Creates a backend argminmax layer function
@@ -165,7 +158,7 @@
<< " axis: " << axis
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend batch normalization layer function
@@ -209,7 +202,7 @@
<< " InPlace: " << is_in_place_operation(input, output)
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend batch normalization layer function
@@ -266,7 +259,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "")
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend fused depthwise convolution batch normalization layer function
@@ -322,7 +315,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "")
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend bounding box transform layer function
@@ -360,7 +353,7 @@
<< " BoundingBox Info img H: " << bbox_info.img_height() << " "
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend channel shuffle layer function
@@ -395,7 +388,7 @@
<< " Num groups: " << num_groups
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend layer concatenate function
@@ -451,7 +444,7 @@
<< qss.str()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend convolution layer function
@@ -542,7 +535,7 @@
<< qss.str()
<< (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "")
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend deconvolution layer function
@@ -648,7 +641,7 @@
<< qss.str()
<< (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "")
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend depth to space layer function
@@ -687,7 +680,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend dequantize layer function
@@ -726,7 +719,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend detection output layer function
*
@@ -771,7 +764,7 @@
<< " DetectionOutputLayer info: " << detect_info
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend detection post process layer function
@@ -826,7 +819,7 @@
<< " DetectionPostProcessLayer info: " << detect_info
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend element-wise operation layer function
@@ -895,7 +888,7 @@
<< " Shape: " << input1->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend unary element-wise operation layer function
@@ -943,7 +936,7 @@
<< " Shape: " << input->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend flatten layer function
@@ -981,7 +974,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend fully connected layer function
@@ -1037,7 +1030,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend generate proposals layer function
@@ -1086,7 +1079,7 @@
<< " Scores Out shape: " << scores_out->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend l2 normalization layer function
@@ -1130,7 +1123,7 @@
<< " Epsilon: " << epsilon
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend normalization layer function
@@ -1172,7 +1165,7 @@
<< " Normalization info: " << norm_info.type()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend normalize planar YUV layer function
@@ -1212,7 +1205,7 @@
<< " Shape: " << input->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend pad layer function
@@ -1251,7 +1244,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend permute layer function
@@ -1290,7 +1283,7 @@
<< " Permutation vector: " << perm
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend pooling layer function
@@ -1329,7 +1322,7 @@
<< " Pooling info: " << pool_info.pool_type
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend PRelu layer function
@@ -1367,7 +1360,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend print layer function
@@ -1438,7 +1431,7 @@
<< " PriorBoxLayer info: " << prior_info
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend quantization layer function
@@ -1475,7 +1468,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend reduction operation layer function
@@ -1519,7 +1512,7 @@
<< " Keep dimensions:" << keep_dims
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend reorg layer function
@@ -1556,7 +1549,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend reshape layer function
@@ -1593,7 +1586,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend resize layer function
@@ -1632,7 +1625,7 @@
<< " Interpolation: " << policy
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend ROI align layer function
@@ -1677,7 +1670,7 @@
<< " ROIPooling height: " << pool_info.pooled_height()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend slice layer function
@@ -1714,7 +1707,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend softmax layer function
@@ -1753,7 +1746,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend layer stack function
@@ -1796,7 +1789,7 @@
<< " Axis: " << axis
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
/** Create a backend slice layer function
@@ -1838,7 +1831,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
} // namespace detail
} // namespace backends
diff --git a/src/graph/backends/CL/CLFunctionsFactory.cpp b/src/graph/backends/CL/CLFunctionsFactory.cpp
index 6196418..5c98ce3 100644
--- a/src/graph/backends/CL/CLFunctionsFactory.cpp
+++ b/src/graph/backends/CL/CLFunctionsFactory.cpp
@@ -167,7 +167,7 @@
wrap_function->register_tensor(input2);
wrap_function->register_tensor(output);
- return RETURN_UNIQUE_PTR(wrap_function);
+ return std::move(wrap_function);
}
template <>
std::unique_ptr<IFunction> create_detection_post_process_layer<CPPDetectionPostProcessLayer, CLTargetInfo>(DetectionPostProcessLayerNode &node)
@@ -223,7 +223,7 @@
wrap_function->register_tensor(output2);
wrap_function->register_tensor(output3);
- return RETURN_UNIQUE_PTR(wrap_function);
+ return std::move(wrap_function);
}
} // namespace detail
diff --git a/src/graph/backends/GLES/GCFunctionsFactory.cpp b/src/graph/backends/GLES/GCFunctionsFactory.cpp
index 7d9d388..ac14425 100644
--- a/src/graph/backends/GLES/GCFunctionsFactory.cpp
+++ b/src/graph/backends/GLES/GCFunctionsFactory.cpp
@@ -120,7 +120,7 @@
<< " Output shape: " << output->info()->tensor_shape()
<< (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "")
<< std::endl);
- return func;
+ return std::move(func);
}
template <>
@@ -172,7 +172,7 @@
<< " Depth multiplier: " << depth_multiplier
<< (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "")
<< std::endl);
- return func;
+ return std::move(func);
}
template <>
@@ -226,7 +226,7 @@
<< " Shape: " << input1->info()->tensor_shape()
<< std::endl);
- return func;
+ return std::move(func);
}
} //namespace detail
diff --git a/src/graph/backends/NEON/NEFunctionFactory.cpp b/src/graph/backends/NEON/NEFunctionFactory.cpp
index b2bd870..6a96f0a 100644
--- a/src/graph/backends/NEON/NEFunctionFactory.cpp
+++ b/src/graph/backends/NEON/NEFunctionFactory.cpp
@@ -32,7 +32,6 @@
#include "arm_compute/graph/nodes/Nodes.h"
#include "arm_compute/runtime/CPP/CPPFunctions.h"
#include "arm_compute/runtime/NEON/NEFunctions.h"
-#include "src/core/NEON/NEKernels.h"
#include "support/Cast.h"
#include "support/ToolchainSupport.h"
@@ -116,7 +115,7 @@
<< " Normalization info: " << norm_info.type()
<< std::endl);
- return RETURN_UNIQUE_PTR(func);
+ return std::move(func);
}
} // namespace detail