1#include "taichi/analysis/bls_analyzer.h"
2#include "taichi/ir/ir.h"
3#include "taichi/ir/statements.h"
4#include "taichi/ir/transforms.h"
5#include "taichi/ir/analysis.h"
6#include "taichi/ir/scratch_pad.h"
7#include "taichi/system/profiler.h"
8
9namespace taichi::lang {
10
11// TODO: rename scratch_pad to block_local_cache? Need to get rid of the
12// scratch_pad term
13
14namespace irpass {
15
16std::unique_ptr<ScratchPads> initialize_scratch_pad(OffloadedStmt *offload) {
17 TI_AUTO_PROF
18 TI_ASSERT(offload->task_type == OffloadedTaskType::struct_for);
19 std::unique_ptr<ScratchPads> pads;
20 pads = std::make_unique<ScratchPads>();
21 for (auto snode : offload->mem_access_opt.get_snodes_with_flag(
22 SNodeAccessFlag::block_local)) {
23 pads->insert(snode);
24 }
25 BLSAnalyzer bls_analyzer(offload, pads.get());
26 bool analysis_ok = bls_analyzer.run();
27 if (!analysis_ok) {
28 TI_ERROR("BLS analysis failed !");
29 }
30 pads->finalize();
31 return pads;
32}
33
34} // namespace irpass
35
36} // namespace taichi::lang
37