Skip to content

Commit 4c6ae8e

Browse files
authored
[polly] Fix cppcheck SA comments reported in #82263 (#85749)
This patch addresses the (performance )suggestions by checkcpp static analyzer for couple of files. Here we use const reference for the suggested function arguments. Fixes #82263.
1 parent 349327f commit 4c6ae8e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

polly/lib/Support/GICHelper.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ APInt polly::APIntFromVal(__isl_take isl_val *Val) {
8383
}
8484

8585
template <typename ISLTy, typename ISL_CTX_GETTER, typename ISL_PRINTER>
86-
static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
87-
ISL_CTX_GETTER ctx_getter_fn,
88-
ISL_PRINTER printer_fn,
89-
std::string DefaultValue) {
86+
static inline std::string
87+
stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
88+
ISL_CTX_GETTER ctx_getter_fn, ISL_PRINTER printer_fn,
89+
const std::string &DefaultValue) {
9090
if (!isl_obj)
9191
return DefaultValue;
9292
isl_ctx *ctx = ctx_getter_fn(isl_obj);
@@ -134,12 +134,11 @@ ISL_C_OBJECT_TO_STRING(union_map)
134134
ISL_C_OBJECT_TO_STRING(union_pw_aff)
135135
ISL_C_OBJECT_TO_STRING(union_pw_multi_aff)
136136

137-
static void replace(std::string &str, const std::string &find,
138-
const std::string &replace) {
137+
static void replace(std::string &str, StringRef find, StringRef replace) {
139138
size_t pos = 0;
140139
while ((pos = str.find(find, pos)) != std::string::npos) {
141-
str.replace(pos, find.length(), replace);
142-
pos += replace.length();
140+
str.replace(pos, find.size(), replace);
141+
pos += replace.size();
143142
}
144143
}
145144

polly/lib/Transform/MatmulOptimizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ createMacroKernel(isl::schedule_node Node,
598598
/// @param MMI Parameters of the matrix multiplication operands.
599599
/// @return The size of the widest type of the matrix multiplication operands
600600
/// in bytes, including alignment padding.
601-
static uint64_t getMatMulAlignTypeSize(MatMulInfoTy MMI) {
601+
static uint64_t getMatMulAlignTypeSize(const MatMulInfoTy &MMI) {
602602
auto *S = MMI.A->getStatement()->getParent();
603603
auto &DL = S->getFunction().getParent()->getDataLayout();
604604
auto ElementSizeA = DL.getTypeAllocSize(MMI.A->getElementType());
@@ -613,7 +613,7 @@ static uint64_t getMatMulAlignTypeSize(MatMulInfoTy MMI) {
613613
/// @param MMI Parameters of the matrix multiplication operands.
614614
/// @return The size of the widest type of the matrix multiplication operands
615615
/// in bits.
616-
static uint64_t getMatMulTypeSize(MatMulInfoTy MMI) {
616+
static uint64_t getMatMulTypeSize(const MatMulInfoTy &MMI) {
617617
auto *S = MMI.A->getStatement()->getParent();
618618
auto &DL = S->getFunction().getParent()->getDataLayout();
619619
auto ElementSizeA = DL.getTypeSizeInBits(MMI.A->getElementType());
@@ -635,7 +635,7 @@ static uint64_t getMatMulTypeSize(MatMulInfoTy MMI) {
635635
/// @return The structure of type MicroKernelParamsTy.
636636
/// @see MicroKernelParamsTy
637637
static MicroKernelParamsTy getMicroKernelParams(const TargetTransformInfo *TTI,
638-
MatMulInfoTy MMI) {
638+
const MatMulInfoTy &MMI) {
639639
assert(TTI && "The target transform info should be provided.");
640640

641641
// Nvec - Number of double-precision floating-point numbers that can be hold
@@ -712,7 +712,7 @@ static void getTargetCacheParameters(const llvm::TargetTransformInfo *TTI) {
712712
static MacroKernelParamsTy
713713
getMacroKernelParams(const llvm::TargetTransformInfo *TTI,
714714
const MicroKernelParamsTy &MicroKernelParams,
715-
MatMulInfoTy MMI) {
715+
const MatMulInfoTy &MMI) {
716716
getTargetCacheParameters(TTI);
717717
// According to www.cs.utexas.edu/users/flame/pubs/TOMS-BLIS-Analytical.pdf,
718718
// it requires information about the first two levels of a cache to determine

0 commit comments

Comments
 (0)