[OpenMP] Misc. changes that add or remove pointer/bound checks

-- Added or moved checks to appropriate places.
-- Removed ineffective null check where the pointer is already being
   dereferenced around the code.
-- Initialized variables that can be used without definitions.
-- Added call to dlclose/FreeLibrary in OMPT tool activation.
-- Added a new build compiler definition.

Differential Revision: https://reviews.llvm.org/D98584
This commit is contained in:
Hansang Bae 2021-03-11 17:34:06 -06:00
parent 4259301aaf
commit 467f39249d
9 changed files with 45 additions and 26 deletions

View File

@ -300,7 +300,7 @@ static void __kmp_tree_barrier_gather(
kmp_uint32 branch_factor = 1 << branch_bits;
kmp_uint32 child;
kmp_uint32 child_tid;
kmp_uint64 new_state;
kmp_uint64 new_state = 0;
KA_TRACE(
20, ("__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
@ -873,7 +873,7 @@ static void __kmp_hierarchical_barrier_gather(
kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
kmp_uint32 nproc = this_thr->th.th_team_nproc;
kmp_info_t **other_threads = team->t.t_threads;
kmp_uint64 new_state;
kmp_uint64 new_state = 0;
int level = team->t.t_level;
if (other_threads[0]
@ -1629,6 +1629,7 @@ int __kmp_barrier_gomp_cancel(int gtid) {
void __kmp_end_split_barrier(enum barrier_type bt, int gtid) {
KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_end_split_barrier);
KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
KMP_DEBUG_ASSERT(bt < bs_last_barrier);
int tid = __kmp_tid_from_gtid(gtid);
kmp_info_t *this_thr = __kmp_threads[gtid];
kmp_team_t *team = this_thr->th.th_team;
@ -1670,6 +1671,9 @@ void __kmp_end_split_barrier(enum barrier_type bt, int gtid) {
void __kmp_join_barrier(int gtid) {
KMP_TIME_PARTITIONED_BLOCK(OMP_join_barrier);
KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
kmp_info_t *this_thr = __kmp_threads[gtid];
kmp_team_t *team;
kmp_uint nproc;
@ -1706,7 +1710,6 @@ void __kmp_join_barrier(int gtid) {
KMP_MB();
// Verify state
KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_team));
KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_root));
KMP_DEBUG_ASSERT(this_thr == team->t.t_threads[tid]);
@ -1931,6 +1934,7 @@ void __kmp_fork_barrier(int gtid, int tid) {
#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
#ifdef KMP_DEBUG
KMP_DEBUG_ASSERT(team);
kmp_info_t **other_threads = team->t.t_threads;
int i;
@ -2011,7 +2015,7 @@ void __kmp_fork_barrier(int gtid, int tid) {
if (KMP_MASTER_TID(ds_tid) &&
(ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
codeptr = team->t.ompt_team_info.master_return_address;
codeptr = team ? team->t.ompt_team_info.master_return_address : NULL;
if (ompt_enabled.ompt_callback_sync_region_wait) {
ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,

View File

@ -1847,6 +1847,8 @@ int __kmp_dispatch_next_algorithm(int gtid,
"__kmp_dispatch_next_algorithm: T#%%d exit status:%%d p_last:%%d "
"p_lb:%%%s p_ub:%%%s p_st:%%%s\n",
traits_t<T>::spec, traits_t<T>::spec, traits_t<ST>::spec);
KMP_DEBUG_ASSERT(p_last);
KMP_DEBUG_ASSERT(p_st);
KD_TRACE(10, (buff, gtid, status, *p_last, *p_lb, *p_ub, *p_st));
__kmp_str_free(&buff);
}

View File

@ -4055,12 +4055,12 @@ static void __kmp_initialize_info(kmp_info_t *this_thr, kmp_team_t *team,
/* this_thr->th.th_info.ds.ds_gtid is setup in
kmp_allocate_thread/create_worker.
this_thr->th.th_serial_team is setup in __kmp_allocate_thread */
kmp_info_t *master = team->t.t_threads[0];
KMP_DEBUG_ASSERT(this_thr != NULL);
KMP_DEBUG_ASSERT(this_thr->th.th_serial_team);
KMP_DEBUG_ASSERT(team);
KMP_DEBUG_ASSERT(team->t.t_threads);
KMP_DEBUG_ASSERT(team->t.t_dispatch);
kmp_info_t *master = team->t.t_threads[0];
KMP_DEBUG_ASSERT(master);
KMP_DEBUG_ASSERT(master->th.th_root);
@ -5751,7 +5751,7 @@ void *__kmp_launch_thread(kmp_info_t *this_thr) {
}
#if OMPT_SUPPORT
ompt_data_t *thread_data;
ompt_data_t *thread_data = nullptr;
if (ompt_enabled.enabled) {
thread_data = &(this_thr->th.ompt_thread_info.thread_data);
*thread_data = ompt_data_none;

View File

@ -167,6 +167,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
"signed?<%s>, loc = %%s\n",
traits_t<T>::spec, traits_t<T>::spec,
traits_t<ST>::spec, traits_t<T>::spec);
check_loc(loc);
KD_TRACE(100,
(buff, *plastiter, *plower, *pupper, *pstride, loc->psource));
__kmp_str_free(&buff);

View File

@ -1714,6 +1714,7 @@ static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
__kmp_str_buf_print(buffer, " %s='",
__kmp_barrier_pattern_env_name[i]);
}
KMP_DEBUG_ASSERT(j < bs_last_barrier && k < bs_last_barrier);
__kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
__kmp_barrier_pattern_name[k]);
}

View File

@ -1221,6 +1221,7 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
gtid, loc_ref, *((kmp_int32 *)flags), sizeof_kmp_task_t,
sizeof_shareds, task_entry));
KMP_DEBUG_ASSERT(parent_task);
if (parent_task->td_flags.final) {
if (flags->merged_if0) {
}
@ -1682,10 +1683,8 @@ kmp_int32 __kmpc_omp_task_parts(ident_t *loc_ref, kmp_int32 gtid,
if (UNLIKELY(ompt_enabled.enabled)) {
parent = new_taskdata->td_parent;
if (ompt_enabled.ompt_callback_task_create) {
ompt_data_t task_data = ompt_data_none;
ompt_callbacks.ompt_callback(ompt_callback_task_create)(
parent ? &(parent->ompt_task_info.task_data) : &task_data,
parent ? &(parent->ompt_task_info.frame) : NULL,
&(parent->ompt_task_info.task_data), &(parent->ompt_task_info.frame),
&(new_taskdata->ompt_task_info.task_data), ompt_task_explicit, 0,
OMPT_GET_RETURN_ADDRESS(0));
}
@ -1782,10 +1781,9 @@ kmp_int32 __kmpc_omp_task(ident_t *loc_ref, kmp_int32 gtid,
OMPT_GET_FRAME_ADDRESS(0);
}
if (ompt_enabled.ompt_callback_task_create) {
ompt_data_t task_data = ompt_data_none;
ompt_callbacks.ompt_callback(ompt_callback_task_create)(
parent ? &(parent->ompt_task_info.task_data) : &task_data,
parent ? &(parent->ompt_task_info.frame) : NULL,
&(parent->ompt_task_info.task_data),
&(parent->ompt_task_info.frame),
&(new_taskdata->ompt_task_info.task_data),
ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
OMPT_LOAD_RETURN_ADDRESS(gtid));
@ -1845,10 +1843,8 @@ kmp_int32 __kmp_omp_taskloop_task(ident_t *loc_ref, kmp_int32 gtid,
if (!parent->ompt_task_info.frame.enter_frame.ptr)
parent->ompt_task_info.frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
if (ompt_enabled.ompt_callback_task_create) {
ompt_data_t task_data = ompt_data_none;
ompt_callbacks.ompt_callback(ompt_callback_task_create)(
parent ? &(parent->ompt_task_info.task_data) : &task_data,
parent ? &(parent->ompt_task_info.frame) : NULL,
&(parent->ompt_task_info.task_data), &(parent->ompt_task_info.frame),
&(new_taskdata->ompt_task_info.task_data),
ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
codeptr_ra);
@ -1873,7 +1869,7 @@ template <bool ompt>
static kmp_int32 __kmpc_omp_taskwait_template(ident_t *loc_ref, kmp_int32 gtid,
void *frame_address,
void *return_address) {
kmp_taskdata_t *taskdata;
kmp_taskdata_t *taskdata = nullptr;
kmp_info_t *thread;
int thread_finished = FALSE;
KMP_SET_THREAD_STATE_BLOCK(TASKWAIT);
@ -2007,7 +2003,7 @@ kmp_int32 __kmpc_omp_taskwait(ident_t *loc_ref, kmp_int32 gtid) {
// __kmpc_omp_taskyield: switch to a different task
kmp_int32 __kmpc_omp_taskyield(ident_t *loc_ref, kmp_int32 gtid, int end_part) {
kmp_taskdata_t *taskdata;
kmp_taskdata_t *taskdata = NULL;
kmp_info_t *thread;
int thread_finished = FALSE;
@ -2533,7 +2529,7 @@ void __kmpc_end_taskgroup(ident_t *loc, int gtid) {
kmp_team_t *team;
ompt_data_t my_task_data;
ompt_data_t my_parallel_data;
void *codeptr;
void *codeptr = nullptr;
if (UNLIKELY(ompt_enabled.enabled)) {
team = thread->th.th_team;
my_task_data = taskdata->ompt_task_info.task_data;
@ -3593,8 +3589,7 @@ void __kmp_task_team_setup(kmp_info_t *this_thr, kmp_team_t *team, int always) {
KA_TRACE(20, ("__kmp_task_team_setup: Primary T#%d created new task_team %p"
" for team %d at parity=%d\n",
__kmp_gtid_from_thread(this_thr),
team->t.t_task_team[this_thr->th.th_task_state],
((team != NULL) ? team->t.t_id : -1),
team->t.t_task_team[this_thr->th.th_task_state], team->t.t_id,
this_thr->th.th_task_state));
}
@ -3607,14 +3602,14 @@ void __kmp_task_team_setup(kmp_info_t *this_thr, kmp_team_t *team, int always) {
// for serialized teams.
if (team->t.t_nproc > 1) {
int other_team = 1 - this_thr->th.th_task_state;
KMP_DEBUG_ASSERT(other_team >= 0 && other_team < 2);
if (team->t.t_task_team[other_team] == NULL) { // setup other team as well
team->t.t_task_team[other_team] =
__kmp_allocate_task_team(this_thr, team);
KA_TRACE(20, ("__kmp_task_team_setup: Primary T#%d created second new "
"task_team %p for team %d at parity=%d\n",
__kmp_gtid_from_thread(this_thr),
team->t.t_task_team[other_team],
((team != NULL) ? team->t.t_id : -1), other_team));
team->t.t_task_team[other_team], team->t.t_id, other_team));
} else { // Leave the old task team struct in place for the upcoming region;
// adjust as needed
kmp_task_team_t *task_team = team->t.t_task_team[other_team];
@ -3632,8 +3627,7 @@ void __kmp_task_team_setup(kmp_info_t *this_thr, kmp_team_t *team, int always) {
KA_TRACE(20, ("__kmp_task_team_setup: Primary T#%d reset next task_team "
"%p for team %d at parity=%d\n",
__kmp_gtid_from_thread(this_thr),
team->t.t_task_team[other_team],
((team != NULL) ? team->t.t_id : -1), other_team));
team->t.t_task_team[other_team], team->t.t_id, other_team));
}
}
@ -3676,7 +3670,7 @@ void __kmp_task_team_sync(kmp_info_t *this_thr, kmp_team_t *team) {
("__kmp_task_team_sync: Thread T#%d task team switched to task_team "
"%p from Team #%d (parity=%d)\n",
__kmp_gtid_from_thread(this_thr), this_thr->th.th_task_team,
((team != NULL) ? team->t.t_id : -1), this_thr->th.th_task_state));
team->t.t_id, this_thr->th.th_task_state));
}
// __kmp_task_team_wait: Primary thread waits for outstanding tasks after the

View File

@ -51,6 +51,8 @@
#define KMP_COMPILER "Intel(R) C++ Compiler 18.0"
#elif __INTEL_COMPILER == 1900
#define KMP_COMPILER "Intel(R) C++ Compiler 19.0"
#elif __INTEL_COMPILER == 1910
#define KMP_COMPILER "Intel(R) C++ Compiler 19.1"
#elif __INTEL_COMPILER >= 9900
#define KMP_COMPILER "Intel(R) C++ Compiler mainline"
#endif

View File

@ -102,6 +102,14 @@ ompt_callbacks_internal_t ompt_callbacks;
static ompt_start_tool_result_t *ompt_start_tool_result = NULL;
#if KMP_OS_WINDOWS
static HMODULE ompt_tool_module = NULL;
#define OMPT_DLCLOSE(Lib) FreeLibrary(Lib)
#else
static void *ompt_tool_module = NULL;
#define OMPT_DLCLOSE(Lib) dlclose(Lib)
#endif
/*****************************************************************************
* forward declarations
****************************************************************************/
@ -314,12 +322,14 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
OMPT_VERBOSE_INIT_CONTINUED_PRINT("Success.\n");
OMPT_VERBOSE_INIT_PRINT(
"Tool was started and is using the OMPT interface.\n");
ompt_tool_module = h;
break;
}
OMPT_VERBOSE_INIT_CONTINUED_PRINT(
"Found but not using the OMPT interface.\n");
OMPT_VERBOSE_INIT_PRINT("Continuing search...\n");
}
OMPT_DLCLOSE(h);
}
fname = __kmp_str_token(NULL, sep, &buf);
}
@ -495,6 +505,8 @@ void ompt_fini() {
ompt_start_tool_result->finalize(&(ompt_start_tool_result->tool_data));
}
if (ompt_tool_module)
OMPT_DLCLOSE(ompt_tool_module);
memset(&ompt_enabled, 0, sizeof(ompt_enabled));
}
@ -675,6 +687,8 @@ OMPT_API_ROUTINE int ompt_get_place_proc_ids(int place_num, int ids_size,
#else
int i, count;
int tmp_ids[ids_size];
for (int j = 0; j < ids_size; j++)
tmp_ids[j] = 0;
if (!KMP_AFFINITY_CAPABLE())
return 0;
if (place_num < 0 || place_num >= (int)__kmp_affinity_num_masks)

View File

@ -103,7 +103,8 @@ inline kmp_info_t *ompt_get_thread() {
}
inline void ompt_set_thread_state(kmp_info_t *thread, ompt_state_t state) {
thread->th.ompt_thread_info.state = state;
if (thread)
thread->th.ompt_thread_info.state = state;
}
inline const char *ompt_get_runtime_version() {