Skip to content

Commit 72d6c11

Browse files
authored
Update macro parameter names with parentheses (#2913)
Signed-off-by: Mike Essenmacher <[email protected]>
1 parent 2e9bcf2 commit 72d6c11

File tree

13 files changed

+114
-109
lines changed

13 files changed

+114
-109
lines changed

src/Accelerators/Accelerator.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
#define CREATE_ACCEL_ENUM(name) name,
3434
#define DECLARE_ACCEL_INIT_FUNCTION(name) extern Accelerator *create##name();
3535
#define INVOKE_ACCEL_INIT_FUNCTION(name, kinds) \
36-
if (!kinds.empty() && \
36+
if (!(kinds).empty() && \
3737
llvm::is_contained(kinds, accel::Accelerator::Kind::name)) \
3838
create##name()->setName(#name);
3939
#define CREATE_ACCEL_CL_ENUM(name) \
4040
clEnumValN(accel::Accelerator::Kind::name, #name, #name " accelerator"),
4141
#define ACCEL_CL_ENUM_FROM_STRING(name, var, str) \
42-
if (str.compare(std::string(#name)) == 0) { \
43-
var = accel::Accelerator::Kind::name; \
42+
if ((str).compare(std::string(#name)) == 0) { \
43+
(var) = accel::Accelerator::Kind::name; \
4444
return true; \
4545
}
4646
#define ACCEL_CL_ENUM_TO_STRING(name, map) \
@@ -165,4 +165,4 @@ extern void initAccelerators(llvm::ArrayRef<Accelerator::Kind> kinds);
165165

166166
} // namespace accel
167167
} // namespace onnx_mlir
168-
#endif
168+
#endif

src/Accelerators/NNPA/Runtime/zDNNExtension/zDNNExtension.c

-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ void checkStatus(zdnn_status status, const char *zdnn_name) {
116116
}
117117
}
118118

119-
#define CHECK_ZDNN_STATUS(status, zdnn_name) checkStatus(status, zdnn_name)
120-
121119
void getUnmappedShape(const zdnn_ztensor *t, UnmappedShape *shape) {
122120
const zdnn_tensor_desc *desc = t->transformed_desc;
123121
shape->e4 = desc->dim4;

src/Accelerators/NNPA/Runtime/zDNNExtension/zDNNExtension.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern bool OMStatusMessagesEnabled;
5858
// Misc Macros
5959
// -----------------------------------------------------------------------------
6060

61-
#define CEIL(a, b) (uint64_t)((a + b - 1) / b) // positive numbers only
61+
#define CEIL(a, b) (uint64_t)(((a) + (b)-1) / (b)) // positive numbers only
6262

6363
// -----------------------------------------------------------------------------
6464
// Common structures
@@ -159,7 +159,7 @@ inline void omUnreachable() {
159159
*/
160160
void checkStatus(zdnn_status status, const char *zdnn_name);
161161

162-
#define CHECK_ZDNN_STATUS(status, zdnn_name) checkStatus(status, zdnn_name)
162+
#define CHECK_ZDNN_STATUS(status, zdnn_name) checkStatus((status), (zdnn_name))
163163

164164
/**
165165
* \brief Get the unmapped shape (4D) of ztensor.

src/Accelerators/NNPA/Support/Stickify/Stickify.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ zdnn_status verify_transformed_descriptor(const zdnn_tensor_desc *tfrmd_desc);
4242

4343
#define ZDNN_MAX_DIMS 4 // number of dims in AIU's Tensor Descriptor
4444

45-
#define CEIL(a, b) (uint64_t)((a + b - 1) / b) // positive numbers only
46-
#define MIN(a, b) ((a > b) ? b : a)
47-
#define MAX(a, b) ((a < b) ? b : a)
45+
#define CEIL(a, b) (uint64_t)(((a) + (b)-1) / (b)) // positive numbers only
46+
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
47+
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
4848
#define BIT_SIZEOF(a) (sizeof(a) * 8)
4949

5050
// padded = next multiple of AIU_2BYTE_CELLS_PER_STICK
5151
#define PADDED(x) \
52-
((uint32_t)CEIL(x, AIU_2BYTE_CELLS_PER_STICK) * AIU_2BYTE_CELLS_PER_STICK)
52+
((uint32_t)CEIL((x), AIU_2BYTE_CELLS_PER_STICK) * AIU_2BYTE_CELLS_PER_STICK)
5353
#define ZDNN_STATUS_OK ZDNN_OK
5454

5555
typedef enum elements_mode {
@@ -92,8 +92,8 @@ DECLARE_DATA_FORMAT_STR(ZDNN_FORMAT_4DKERNEL)
9292
static short get_data_layout_num_gates(zdnn_data_layouts layout) {
9393

9494
#define CASE_RTN_GATES(a, b) \
95-
case a: \
96-
return b;
95+
case (a): \
96+
return (b);
9797

9898
switch (layout) {
9999
CASE_RTN_GATES(ZDNN_BIDIR_ZRH, 3);
@@ -109,8 +109,8 @@ static short get_data_layout_num_gates(zdnn_data_layouts layout) {
109109
static short get_data_layout_dims(zdnn_data_layouts layout) {
110110

111111
#define CASE_RTN_DIM(a, b) \
112-
case a: \
113-
return b;
112+
case (a): \
113+
return (b);
114114

115115
switch (layout) {
116116
CASE_RTN_DIM(ZDNN_1D, 1);
@@ -152,7 +152,7 @@ uint32_t get_rnn_concatenated_dim2(uint32_t val, zdnn_concat_info info) {
152152
short get_func_code_num_gates(nnpa_function_code func_code) {
153153

154154
#define CASE_RTN_GATES(a, b) \
155-
case a: \
155+
case (a): \
156156
return get_data_layout_num_gates(b); // piggyback thus no need to hardcode
157157

158158
switch (func_code) {
@@ -167,7 +167,7 @@ short get_func_code_num_gates(nnpa_function_code func_code) {
167167
const char *get_data_layout_str(zdnn_data_layouts layout) {
168168

169169
#define CASE_RTN_STR(a) \
170-
case a: \
170+
case (a): \
171171
return DATA_LAYOUT_STR_##a;
172172

173173
switch (layout) {
@@ -194,7 +194,7 @@ const char *get_data_layout_str(zdnn_data_layouts layout) {
194194
const char *get_data_format_str(zdnn_data_formats format) {
195195

196196
#define CASE_RTN_STR(a) \
197-
case a: \
197+
case (a): \
198198
return DATA_FORMAT_STR_##a;
199199

200200
switch (format) {
@@ -209,8 +209,8 @@ const char *get_data_format_str(zdnn_data_formats format) {
209209
short get_data_type_size(zdnn_data_types type) {
210210

211211
#define CASE_RTN_SIZE(a, b) \
212-
case a: \
213-
return b;
212+
case (a): \
213+
return (b);
214214

215215
switch (type) {
216216
CASE_RTN_SIZE(BFLOAT, 2);

src/Runtime/OMSort.inc

+21-21
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
//
5555
#define compareFunctionBody(typeName, direction, load, dataPtr, idx1p, idx2p) \
5656
{ \
57-
uint64_t idx1 = *((uint64_t *)idx1p); \
58-
uint64_t idx2 = *((uint64_t *)idx2p); \
59-
typeName *data = (typeName *)dataPtr; \
57+
uint64_t idx1 = *((uint64_t *)(idx1p)); \
58+
uint64_t idx2 = *((uint64_t *)(idx2p)); \
59+
typeName *data = (typeName *)(dataPtr); \
6060
load(typeName, v1, data[idx1]); \
6161
load(typeName, v2, data[idx2]); \
6262
return (direction(v1, v2) || (v1 == v2 && idx1 < idx2)) ? -1 : 1; \
@@ -89,15 +89,15 @@ typedef int(
8989
#pragma GCC diagnostic ignored "-Wcast-qual"
9090
#endif
9191

92-
#define Load(typeName, to, from) typeName to = from
92+
#define Load(typeName, to, from) typeName (to) = (from)
9393

9494
// Convert f16 elements to f32 for comparison because we don't have logic to
9595
// compare f16 elements directly on all platforms.
9696
// TODO: Use Convert(_Float16, to, from) on supported platforms.
9797
// Or consider converting the whole tensor to f32, sort as f32, and then
9898
// convert the sorted tensor back to f16. That may be faster than
9999
// converting elements for each comparison during sorting.
100-
#define LoadF16AsF32(typeName, to, from) float to = om_f16_to_f32(from)
100+
#define LoadF16AsF32(typeName, to, from) float (to) = om_f16_to_f32(from)
101101

102102
// declare ascending functions
103103
#define Ascending(lhs, rhs) ((lhs) < (rhs))
@@ -169,35 +169,35 @@ typedef struct indexStack {
169169

170170
#define STACK_INIT(stack, stackSize) \
171171
do { \
172-
assert(stackSize > 0); \
173-
stack.stackData = (uint64_t *)alloca(stackSize * sizeof(uint64_t)); \
174-
assert(stack.stackData != NULL); \
175-
stack.stackSize = stackSize; \
176-
stack.stackTop = 0; \
172+
assert((stackSize) > 0); \
173+
(stack).stackData = (uint64_t *)alloca((stackSize) * sizeof(uint64_t)); \
174+
assert((stack).stackData != NULL); \
175+
(stack).stackSize = (stackSize); \
176+
(stack).stackTop = 0; \
177177
} while (0)
178-
#define STACK_ISEMPTY(stack) (stack.stackTop == 0)
178+
#define STACK_ISEMPTY(stack) ((stack).stackTop == 0)
179179
#define STACK_PUSH(stack, begin, end) \
180180
do { \
181-
assert(stack.stackTop <= stack.stackSize - 2); \
182-
stack.stackData[(stack.stackTop)++] = begin; \
183-
stack.stackData[(stack.stackTop)++] = end; \
181+
assert((stack).stackTop <= (stack).stackSize - 2); \
182+
(stack).stackData[((stack).stackTop)++] = (begin); \
183+
(stack).stackData[((stack).stackTop)++] = (end); \
184184
} while (0)
185185
#define STACK_POP(stack, begin, end) \
186186
do { \
187-
assert(stack.stackTop >= 2); \
188-
end = stack.stackData[--(stack.stackTop)]; \
189-
begin = stack.stackData[--(stack.stackTop)]; \
187+
assert((stack).stackTop >= 2); \
188+
(end) = (stack).stackData[--((stack).stackTop)]; \
189+
(begin) = (stack).stackData[--((stack).stackTop)]; \
190190
} while (0)
191191
#define STACK_PRINT(stack) \
192192
do { \
193-
assert(stack.stackTop >= 0); \
193+
assert((stack).stackTop >= 0); \
194194
fprintf(stderr, "Stack: ["); \
195-
for (int64_t i = 0; (i + 1) < stack.stackTop; i += 2) { \
195+
for (int64_t i = 0; (i + 1) < (stack).stackTop; i += 2) { \
196196
fprintf( \
197-
stderr, "<%ld:%ld>, ", stack.stackData[i], stack.stackData[i + 1]); \
197+
stderr, "<%ld:%ld>, ", (stack).stackData[i], (stack).stackData[i + 1]);\
198198
} \
199199
fprintf( \
200-
stderr, "] (Top=%ld,Size=%ld)\n", stack.stackTop, stack.stackSize); \
200+
stderr, "] (Top=%ld,Size=%ld)\n", (stack).stackTop, (stack).stackSize);\
201201
fflush(stderr); \
202202
} while (0)
203203

src/Runtime/OMTensor.inc

+11-11
Original file line numberDiff line numberDiff line change
@@ -480,42 +480,42 @@ static void printData(FILE *fout, const OMTensor *tensor) {
480480
/* Helper macros to print data for 1-4D tensors */
481481
#define LOOP_1(INDEX, IV, UB) \
482482
fprintf(fout, "["); \
483-
for (int64_t IV = 0; IV < UB; ++IV) { \
483+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
484484
if (IV) \
485485
fprintf(fout, ", "); \
486-
indexes[INDEX] = IV; \
486+
indexes[(INDEX)] = (IV); \
487487
int64_t elemOffset = computeElemOffset(tensor->_strides, indexes, rank); \
488488
printElement(fout, dataPtr, elemOffset, dataType); \
489489
} \
490490
fprintf(fout, "]");
491491

492492
#define LOOP_2(INDEX, IV, UB, ...) \
493493
fprintf(fout, "["); \
494-
for (int64_t IV = 0; IV < UB; ++IV) { \
494+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
495495
if (IV) \
496496
fprintf(fout, ", "); \
497-
indexes[INDEX] = IV; \
498-
LOOP_1(INDEX + 1, __VA_ARGS__) \
497+
indexes[(INDEX)] = (IV); \
498+
LOOP_1((INDEX) + 1, __VA_ARGS__) \
499499
} \
500500
fprintf(fout, "]");
501501

502502
#define LOOP_3(INDEX, IV, UB, ...) \
503503
fprintf(fout, "["); \
504-
for (int64_t IV = 0; IV < UB; ++IV) { \
504+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
505505
if (IV) \
506506
fprintf(fout, ", "); \
507-
indexes[INDEX] = IV; \
508-
LOOP_2(INDEX + 1, __VA_ARGS__) \
507+
indexes[(INDEX)] = (IV); \
508+
LOOP_2((INDEX) + 1, __VA_ARGS__) \
509509
} \
510510
fprintf(fout, "]");
511511

512512
#define LOOP_4(INDEX, IV, UB, ...) \
513513
fprintf(fout, "["); \
514-
for (int64_t IV = 0; IV < UB; ++IV) { \
514+
for (int64_t (IV) = 0; (IV) < (UB); ++(IV)) { \
515515
if (IV) \
516516
fprintf(fout, ", "); \
517-
indexes[INDEX] = IV; \
518-
LOOP_3(INDEX + 1, __VA_ARGS__) \
517+
indexes[(INDEX)] = (IV); \
518+
LOOP_3((INDEX) + 1, __VA_ARGS__) \
519519
} \
520520
fprintf(fout, "]");
521521

src/Runtime/jni/jnilog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static pthread_key_t log_inited;
4040
static pthread_key_t log_level;
4141
static pthread_key_t log_fp;
4242

43-
#define THREAD_LOCAL_INIT(key, func) pthread_once(key, func)
43+
#define THREAD_LOCAL_INIT(key, func) pthread_once((key), (func))
4444

4545
INLINE void key_init() {
4646
pthread_key_create(&log_inited, NULL);

0 commit comments

Comments
 (0)