[inferbo][cost] Add tests for global constant array of structs initialization

Summary: Weaknesses to be resolved in the following diffs

Reviewed By: skcho

Differential Revision: D26315739

fbshipit-source-id: 942a981bd
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent 3593e41de1
commit f6f47cd7c9

@ -11,6 +11,12 @@ void access_constant_global_Bad() {
a[ConstantGlobal[0]] = 3;
}
void access_via_assignment_constant_global_Bad_FN() {
int a[5];
const int* arr = ConstantGlobal;
a[arr[0]] = 3;
}
static int StaticGlobal[][3] = {
{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}};

@ -232,6 +232,9 @@ codetoanalyze/objc/performance/mutable_copy_test.m, MyMutableObj.objects, 5, On
codetoanalyze/objc/performance/mutable_copy_test.m, MyMutableObj.setMObjects:, 3, OnUIThread:false, []
codetoanalyze/objc/performance/mutable_copy_test.m, loop_over_mutable_copy_linear, 31 + 3 ⋅ b->_mObjects->elements.length.ub + 3 ⋅ (b->_mObjects->elements.length.ub + 1), OnUIThread:false, [{b->_mObjects->elements.length.ub + 1},Loop,{b->_mObjects->elements.length.ub},Loop]
codetoanalyze/objc/performance/purity.m, loop, 6006 + 1000 ⋅ |fun_ptr|, OnUIThread:false, []
codetoanalyze/objc/performance/struct_test.m, __infer_globals_initializer_mSpecs, 4, OnUIThread:false, []
codetoanalyze/objc/performance/struct_test.m, const_struct_field_read_constant_FP, 4 + mSpecs.fileName->strlen.ub, OnUIThread:false, [{mSpecs.fileName->strlen.ub},Modeled call to NSString.stringWithUTF8String:]
codetoanalyze/objc/performance/struct_test.m, loop_array_struct_constant, 9, OnUIThread:false, []
codetoanalyze/objc/performance/switch_continue.m, test_switch_FN, 600, OnUIThread:false, []
codetoanalyze/objc/performance/switch_continue.m, unroll_loop, 15 + (n - 1) + 11 ⋅ (max(1, n)), OnUIThread:false, [{max(1, n)},Loop,{n - 1},Loop]
codetoanalyze/objc/performance/two_loops_symbolic.m, nop, 1, OnUIThread:false, []

@ -0,0 +1,32 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
typedef struct MSpec_t {
const char* fileName;
} MSpec;
#define SPEC_FILE_NAME(name) .fileName = (name),
static const MSpec mSpecs[] = {
{SPEC_FILE_NAME("api")},
{SPEC_FILE_NAME("graph")},
{SPEC_FILE_NAME("disk")},
{SPEC_FILE_NAME("io")},
};
void const_struct_field_read_constant_FP() {
MSpec spec = mSpecs[0];
NSString* fileName =
@(spec.fileName); // filename is constant, so this should be O(1)
}
void loop_array_struct_constant() {
const MSpec* const endSpec = ((const MSpec*)mSpecs) + ARRAY_COUNT(mSpecs);
for (const MSpec* spec = (const MSpec*)mSpecs; spec < endSpec; spec++) {
}
}
Loading…
Cancel
Save