Go to the documentation of this file.
33 #include "llvm/IR/PassManager.h"
34 #include "llvm/IR/Module.h"
35 #include "llvm/IR/Function.h"
36 #include "llvm/Analysis/LoopInfo.h"
37 #include "llvm/IR/Value.h"
38 #include "llvm/Passes/PassBuilder.h"
39 #include "llvm/Passes/PassPlugin.h"
40 #include "llvm/ADT/StringMap.h"
41 #include "llvm/ADT/SetVector.h"
42 #include "llvm/Support/Error.h"
43 #include "llvm/ADT/SmallVector.h"
44 #include "llvm/ADT/iterator_range.h"
45 #include "llvm/Support/FormatVariadic.h"
49 #define OMP_STATIC_INIT_SCHED 2
50 #define OMP_STATIC_INIT_PLASTITER 3
51 #define OMP_STATIC_INIT_PLOWER 4
52 #define OMP_STATIC_INIT_PUPPER 5
53 #define OMP_STATIC_INIT_PSTRIDE 6
54 #define OMP_STATIC_INIT_INCR 7
55 #define OMP_STATIC_INIT_CHUNK 8
56 #define OMP_STATIC_INIT_OPERAND_N (OMP_STATIC_INIT_CHUNK + 1)
58 #include <system_error>
62 #define KERNEL_INFO_PREFIX ".omp_offloading.entry"
63 #define OFFLOADINFO_METADATA_NAME "omp_offload.info"
64 #define OUTLINED_FUNC_NAME_FMT "__omp_offloading_{0:x-}_{1:x-}_{2}_l{3:d}"
65 #define ADD_FUNC_PASS(P) (createModuleToFunctionPassAdaptor(P))
66 #define ADD_LOOP_PASS(P) (createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor(P)))
96 template <
typename IRUnitT,
typename InvT>
97 bool invalidate(IRUnitT& IR,
const PreservedAnalyses &PA,
110 Result run(Module &M, ModuleAnalysisManager &AM);
112 friend AnalysisInfoMixin<ModelManagerPass>;
125 Result run(Function &F, FunctionAnalysisManager &AM);
127 friend AnalysisInfoMixin<ModelManagerFunctionProxy>;
139 Result run(Loop &L, LoopAnalysisManager &AM,
140 LoopStandardAnalysisResults &AR);
142 friend AnalysisInfoMixin<ModelManagerLoopProxy>;
162 template <
typename IRUnitT,
typename InvT>
163 bool invalidate(IRUnitT& IR,
const PreservedAnalyses &PA,
175 return md_list.begin();
179 return md_list.end();
183 return make_range(md_begin(), md_end());
188 return kernel_list.begin();
192 return kernel_list.end();
195 inline iterator_range<func_iterator>
kernels() {
196 return make_range(kernel_begin(), kernel_end());
206 kernel_list.emplace_back(kernel);
207 offload_func_list.emplace_back(offload);
217 auto kernel_it = kernel_begin();
218 auto offload_it = offload_func_list.begin();
219 for (;kernel_it != kernel_end(); kernel_it++, offload_it++) {
220 if (kernel == *kernel_it)
return *offload_it;
231 md_iterator getMetadata(Function *offload);
240 void setOffloadMetadata(Module &M);
248 int getKernelLine(Function *kernel);
261 public AnalysisInfoMixin<OmpKernelAnalysisPass> {
264 Result run(Module &M, ModuleAnalysisManager &AM);
266 friend AnalysisInfoMixin<OmpKernelAnalysisPass>;
281 Value *schedule_type,
282 Value *last_iter_flag,
289 info.insert(schedule_type);
290 info.insert(last_iter_flag);
291 info.insert(lower_bound);
292 info.insert(upper_bound);
294 info.insert(increment);
301 info.insert(
nullptr);
304 bool invalidate(Function &F,
const PreservedAnalyses &PA,
305 FunctionAnalysisManager::Invalidator &Inv);
307 explicit operator bool() const noexcept {
317 return info.contains(V);
358 public AnalysisInfoMixin<OmpStaticShecudleAnalysis> {
362 Result run(Function &F, FunctionAnalysisManager &AM);
365 friend AnalysisInfoMixin<OmpStaticShecudleAnalysis>;
371 public PassInfoMixin<RemoveScheduleRuntimePass> {
373 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
378 #endif //CGRAOmpPass_H
Value * get_upper_bound()
Definition: CGRAOmpPass.hpp:329
An interface for each LLVM pass to get the target CGRAModel. It can be obtained as an analysis result...
Definition: CGRAOmpPass.hpp:76
Definition: OptionPlugin.cpp:128
OmpScheduleInfo(CallBase *caller, Value *schedule_type, Value *last_iter_flag, Value *lower_bound, Value *upper_bound, Value *stride, Value *increment, Value *chunk)
Definition: CGRAOmpPass.hpp:280
Info_t::iterator end()
Definition: CGRAOmpPass.hpp:313
FunctionList offload_func_list
Definition: CGRAOmpPass.hpp:252
void add_kernel(Function *offload, Function *kernel)
add kernel function as an entry
Definition: CGRAOmpPass.hpp:205
FunctionList kernel_list
Definition: CGRAOmpPass.hpp:251
Value * get_stride()
Definition: CGRAOmpPass.hpp:332
MetadataList md_list
Definition: CGRAOmpPass.hpp:250
Value * get_lower_bound()
Definition: CGRAOmpPass.hpp:326
Definition: CGRAOmpPass.hpp:370
Function * getOffloadFunction(Function *kernel)
Get the Offload Function pointer from the kernel function.
Definition: CGRAOmpPass.hpp:216
A module pass to find functions annotated as OpenMP kernels.
Definition: CGRAOmpPass.hpp:260
static AnalysisKey Key
Definition: CGRAOmpPass.hpp:268
SmallVector< Function * > FunctionList
Definition: CGRAOmpPass.hpp:169
static AnalysisKey Key
Definition: CGRAOmpPass.hpp:367
bool valid
Definition: CGRAOmpPass.hpp:350
SmallVector< OffloadMetadata_t > MetadataList
Definition: CGRAOmpPass.hpp:166
Module Pass to give the ModuleManager.
Definition: CGRAOmpPass.hpp:107
CGRAModel * getModel() const
Get the CGRAModel object.
Definition: CGRAOmpPass.hpp:93
Value * get_last_iter_flag()
Definition: CGRAOmpPass.hpp:323
CGRAModel * model
Definition: CGRAOmpPass.hpp:100
Definition: AGVerifyPass.hpp:50
CallBase * get_caller()
Definition: CGRAOmpPass.hpp:342
Value * get_increment()
Definition: CGRAOmpPass.hpp:335
A proxy to access model manager from function passes.
Definition: CGRAOmpPass.hpp:122
func_iterator kernel_end()
Definition: CGRAOmpPass.hpp:191
iterator_range< func_iterator > kernels()
Definition: CGRAOmpPass.hpp:195
static AnalysisKey Key
Definition: CGRAOmpPass.hpp:113
A function pass to analyze OpenMP static scheduling.
Definition: CGRAOmpPass.hpp:357
MetadataList::iterator md_iterator
Definition: CGRAOmpPass.hpp:167
static AnalysisKey Key
Definition: CGRAOmpPass.hpp:143
CGRAModel * model
Definition: CGRAOmpPass.hpp:114
FunctionList::iterator func_iterator
Definition: CGRAOmpPass.hpp:170
A base class of CGRA model for DFG extraction.
Definition: CGRAModel.hpp:71
A proxy to access model manager from loop passes.
Definition: CGRAOmpPass.hpp:136
Value * get_schedule_type()
Definition: CGRAOmpPass.hpp:320
Info_t::iterator begin()
Definition: CGRAOmpPass.hpp:310
bool contains(Value *V)
Definition: CGRAOmpPass.hpp:316
#define OMP_STATIC_INIT_OPERAND_N
Definition: CGRAOmpPass.hpp:56
func_iterator kernel_begin()
Definition: CGRAOmpPass.hpp:187
A set of information regarding OpenMP target kernel.
Definition: CGRAOmpPass.hpp:150
md_iterator md_end()
Definition: CGRAOmpPass.hpp:178
Bundled values related to OpenMP statinc scheduling.
Definition: CGRAOmpPass.hpp:277
Value * get_chunk()
Definition: CGRAOmpPass.hpp:338
SetVector< Value * > Info_t
Definition: CGRAOmpPass.hpp:278
CallBase * caller
Definition: CGRAOmpPass.hpp:349
md_iterator md_begin()
Definition: CGRAOmpPass.hpp:174
iterator_range< md_iterator > metadata()
Definition: CGRAOmpPass.hpp:182
static AnalysisKey Key
Definition: CGRAOmpPass.hpp:128
OmpScheduleInfo()
Definition: CGRAOmpPass.hpp:298
ModelManager(CGRAModel *CM)
Construct a new ModelManager object.
Definition: CGRAOmpPass.hpp:84
Info_t info
Definition: CGRAOmpPass.hpp:348