1 /* 2 * Copyright (c) 2015-2019, NVIDIA CORPORATION. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #ifndef OUTLINER_H_ 19 #define OUTLINER_H_ 20 21 /** \file 22 * \brief Various definitions for the outliner module 23 */ 24 25 #include "gbldefs.h" 26 #include "global.h" 27 #include "symtab.h" 28 #include "ili.h" 29 #include <stdio.h> 30 31 extern FILE *par_file1; 32 extern FILE *par_file2; 33 extern FILE *par_curfile; 34 35 /* For OpenMP target accelerator, 36 * the compilers outlines the same region multiple times. 37 * Therefore outliner has following states. */ 38 typedef enum 39 { 40 outliner_not_active = 0, /* Not outlining, temp files are empty */ 41 outliner_active_host_par1 = 1, /* Host outlining, building ILI from parfile1 ilm */ 42 outliner_active_host_par2 = 2, /* Host outlining, building ILI from parfile2 ilm */ 43 outliner_active_switchfile = 3, /* Outlining recurs */ 44 outliner_reset = 4, /* Reset files, go back to main ilm file. */ 45 outliner_error = 5 46 } outliner_states_t; 47 48 49 int ll_has_cuda_constructor(void); 50 void ll_save_cuda_constructor(void); 51 52 /** 53 \brief ... 54 */ 55 bool ll_ilm_is_rewriting(void); 56 57 /** 58 \brief ... 59 */ 60 int ll_ad_outlined_func2(ILI_OP result_opc, ILI_OP call_opc, int sptr, 61 int nargs, int *args); 62 63 /** 64 \brief ... 65 */ 66 SPTR ll_create_task_sptr(void); 67 68 /** 69 \brief ... 70 */ 71 int ll_get_gtid_addr_ili(void); 72 73 /** 74 \brief ... 75 */ 76 int ll_get_gtid_val_ili(void); 77 78 /** 79 \brief ... 80 */ 81 SPTR ll_get_gtid(void); 82 83 /** 84 \brief ... 85 */ 86 SPTR ll_get_hostprog_arg(int func_sptr, int whicharg); 87 88 /** 89 \brief ... 90 */ 91 SPTR ll_get_shared_arg(SPTR func_sptr); 92 93 /** 94 \brief ... 95 */ 96 int ll_get_uplevel_arg(void); 97 98 /** 99 \brief ... 100 */ 101 int ll_get_uplevel_offset(int sptr); 102 103 /** 104 \brief ... 105 */ 106 SPTR ll_get_uplevel_sym(void); 107 108 /** 109 \brief ... 110 */ 111 int ll_has_more_outlined(void); 112 113 /** 114 \brief ... 115 */ 116 int ll_load_outlined_args(int scope_blk_sptr, SPTR callee_sptr, bool clone); 117 118 /** 119 \brief ... 120 */ 121 int ll_make_outlined_call2(int func_sptr, int uplevel_ili); 122 123 /** 124 \brief ... 125 */ 126 int ll_make_outlined_call(int func_sptr, int arg1, int arg2, int arg3); 127 128 /** 129 \brief Create function and parameter list for an outlined function 130 \param stblk_sptr references the arguments for the function to be outlined 131 \param scope_sptr references the scope 132 \param opc current opc 133 */ 134 SPTR ll_make_outlined_func_wopc(SPTR stblk_sptr, SPTR scope_sptr, ILM_OP opc); 135 136 /** 137 \brief Create function and parameter list for an outlined function 138 \param stblk_sptr references the arguments for the function to be outlined 139 \param scope_sptr references the scope 140 */ 141 SPTR ll_make_outlined_func(SPTR stblk_sptr, SPTR scope_sptr); 142 143 /** 144 \brief Create function and parameter list for an outlined function 145 \param stblk_sptr references the arguments for the function to be outlined 146 \param scope_sptr references the scope 147 */ 148 SPTR ll_make_outlined_func_target_device(SPTR stblk_sptr, SPTR scope_sptr, ILM_OP opc); 149 150 /** 151 \brief Create function for OpenMP target and parameter list for an outlined function 152 \param stblk_sptr references the arguments for the function to be outlined 153 \param scope_sptr references the scope 154 */ 155 SPTR ll_make_outlined_omptarget_func(SPTR stblk_sptr, SPTR scope_sptr, ILM_OP opc); 156 157 /** 158 \brief ... 159 */ 160 int ll_make_outlined_garg(int nargs, int *argili, DTYPE *arg_dtypes); 161 162 /** 163 \brief ... 164 */ 165 int ll_make_outlined_gjsr(int func_sptr, int nargs, int arg1, int arg2, int arg3); 166 167 /** 168 \brief ... 169 */ 170 int ll_make_outlined_task_call(int func_sptr, SPTR task_sptr); 171 172 /** 173 \brief Create function and parameter list for an outlined task 174 \param stblk_sptr references the arguments for the task to be outlined 175 */ 176 SPTR ll_make_outlined_task(SPTR stblk_sptr, SPTR scope_sptr); 177 178 /** 179 \brief ... 180 */ 181 int *ll_make_sections_args(SPTR lbSym, SPTR ubSym, SPTR stSym, SPTR lastSym); 182 183 /** 184 \brief ... 185 */ 186 DTYPE ll_make_uplevel_type(SPTR stblk_sptr); 187 188 /** 189 \brief ... 190 */ 191 int llProcessNextTmpfile(void); 192 193 /** 194 \brief ... 195 */ 196 int ll_reset_parfile(void); 197 198 /** 199 \brief ... 200 */ 201 int ll_rewrite_ilms(int lineno, int ilmx, int len); 202 203 /** 204 \brief ... 205 */ 206 int ll_save_gtid_val(int bih); 207 208 /** 209 \brief ... 210 */ 211 SPTR llvmAddConcurEntryBlk(int bih); 212 213 /** 214 \brief ... 215 */ 216 int llvmGetExpbCurIlt(void); 217 218 /** 219 \brief ... 220 */ 221 int llvm_get_unique_sym(void); 222 223 /** 224 \brief ... 225 */ 226 int llvm_ilms_rewrite_mode(void); 227 228 /** 229 \brief Dump the list of variables for the parallel regions specified by 230 'sptr'. 231 232 These variables should be used to make the uplevel struct when making a call 233 to this outlined region. 234 */ 235 void dump_parsyms(int sptr, int isTeams); 236 237 /** 238 \brief ... 239 */ 240 void finish_taskdup_routine(int curilm, int fnsptr, INT offset); 241 242 /** 243 \brief ... 244 */ 245 void ilm_outlined_pad_ilm(int curilm); 246 247 /** 248 \brief ... 249 */ 250 void ll_make_ftn_outlined_params(int func_sptr, int paramct, DTYPE *argtype); 251 252 /** 253 \brief ... 254 */ 255 void ll_open_parfiles(void); 256 257 /** 258 \brief ... 259 */ 260 void ll_reset_gtid(void); 261 262 /** 263 \brief ... 264 */ 265 void ll_reset_outlined_func(void); 266 267 /** 268 \brief ... 269 */ 270 void ll_set_outlined_currsub(bool); 271 272 /** 273 \brief ... 274 */ 275 void ll_unlink_parfiles(void); 276 277 /** 278 \brief ... 279 */ 280 void llvmAddConcurExitBlk(int bih); 281 282 /** 283 \brief ... 284 */ 285 void llvmSetExpbCurIlt(void); 286 287 /** 288 \brief ... 289 */ 290 void llvm_set_unique_sym(int sptr); 291 292 /** 293 \brief ... 294 */ 295 void ll_write_ilm_end(void); 296 297 /** 298 \brief ... 299 */ 300 void ll_write_ilm_header(int outlined_sptr, int curilm); 301 302 /** 303 \brief ... 304 */ 305 void llWriteNopILM(int lineno, int ilmx, int len); 306 307 /** 308 \brief ... 309 */ 310 void restartRewritingILM(int curilm); 311 312 /** 313 \brief ... 314 */ 315 void setOutlinedPragma(int func_sptr, int saved); 316 317 /** 318 \brief ... 319 */ 320 void setRewritingILM(void); 321 322 /** 323 \brief ... 324 */ 325 void start_taskdup(int task_fnsptr, int curilm); 326 327 /** 328 \brief ... 329 */ 330 void stop_taskdup(int task_fnsptr, int curilm); 331 332 /** 333 \brief ... 334 */ 335 void unsetRewritingILM(void); 336 337 /** 338 \brief ... 339 */ 340 void update_acc_with_fn(int fnsptr); 341 342 /** 343 \brief Return size of shared variable for task 344 */ 345 ISZ_T getTaskSharedSize(SPTR scope_sptr); 346 347 #if defined(OMP_OFFLOAD_LLVM) || defined(OMP_OFFLOAD_PGI) 348 /** 349 \brief Create an outlining function, which has function parameter for each symbol. 350 */ 351 SPTR ll_make_outlined_ompaccel_func(SPTR, SPTR, bool); 352 353 /** 354 \brief Create an function call to the outlininin function. 355 */ 356 int ll_make_outlined_ompaccel_call(SPTR, SPTR); 357 358 /** 359 \brief Disable symbol replacement at ILM while generating device code 360 */ 361 void ompaccel_symreplacer(bool); 362 363 /** 364 \brief It is called when there is breduction ilm to avoid host reduction which is implemented by critical regions 365 */ 366 void ompaccel_notify_reduction(bool); 367 368 /** 369 \brief 370 */ 371 bool ompaccel_is_reduction_region(); 372 373 /** 374 \brief 375 */ 376 int mk_function_call(DTYPE, int, DTYPE *, int *, SPTR); 377 #endif 378 379 /** 380 \brief test whether do outlining elision for the current opc or not. 381 */ 382 bool outlined_is_eliminated(ILM_OP opc); 383 384 /** 385 \brief test whether recompile the ILMs or not. 386 */ 387 bool outlined_need_recompile(); 388 389 void ll_set_ompaccel_currfunc(bool isILMrecompile); 390 #endif /* OUTLINER_H_ */ 391