WaSH Docs
common.hpp
1 #pragma once
2 
3 #include "clang/Frontend/FrontendActions.h"
4 #include "clang/Frontend/TextDiagnosticPrinter.h"
5 #include "clang/Rewrite/Core/Rewriter.h"
6 #include "clang/Tooling/CommonOptionsParser.h"
7 #include "clang/Tooling/Refactoring.h"
8 #include "clang/Tooling/RefactoringCallbacks.h"
9 #include "clang/Tooling/Tooling.h"
10 #include "clang/ASTMatchers/ASTMatchFinder.h"
11 #include "clang/ASTMatchers/ASTMatchers.h"
12 #include "llvm/Support/CommandLine.h"
13 
14 #include <any>
15 #include <fstream>
16 #include <iostream>
17 #include <string>
18 #include <unordered_set>
19 #include <variant>
20 #include <memory>
21 #include <cstdlib>
22 #include <vector>
23 #include <initializer_list>
24 #include <algorithm>
25 #include <filesystem>
26 #include <random>
27 #include <optional>
28 
29 using namespace llvm;
30 using namespace clang;
31 using namespace clang::ast_matchers;
32 using namespace clang::tooling;
33 
34 enum class Implementations { wser, wisb, west, cstone, wone };
35 
45 struct WashOptions {
46  Implementations impl; // Which API implementation to use Default: WONE (OMP+MPI)
47  bool openmp; // Whether to enable OpenMP on this output (-DWASH_OMP_SUPPORT/-fopenmp) Default: Yes
48  bool mpi; // Whether to enable MPI on this output (-DWASH_MPI_SUPPORT/-lmpi) Default: Determined by mpicxx cmd
49  bool hdf5; // Whether to enable HDF5 on this output (-DWASH_HDF5_SUPPORT/-lHDF5) Default: Determiend by env var
50  bool debug; // Whether to use debug flags on this output. Default: false
51  uint8_t dim; // The number of dimensions to use (can be overriden by source code)
52  std::string input_path; // Path to the input souce directory
53  std::string output_name; // Path + Name of output binary (may be appended if multiple created)
54  std::string temp_path; // Temporary path of files used in compilation
55  std::vector<std::string> args; // List of command line arguments to use in compilation
56 };
57 
59  uint8_t openmp; // 0 - Not Supported; 1 - Can be compiled with/optionally run with; 2 - Required
60  uint8_t mpi; // 0 - Not Supported; 1 - Can be compiled with/optionally run with; 2 - Required
61  uint8_t cuda; // 0 - Not Supported; 1 - Can be compiled with/optionally run with; 2 - Required
62  uint8_t dim; // 0x80 & (dim) = Dim required; 0x40 & (dim) = Defuault dim (others supported)
63 
64  std::string name;
65  std::string source_dir;
66 };
67 
68 extern Implementations default_impl;
69 extern std::unordered_map<Implementations, ImplementationFeatures> api_impls;
70 extern std::vector<std::string> UserFiles; // User source files copied in
71 extern std::vector<std::string> BackendFiles; // Backend files `src/impl/xyza`
72 extern std::vector<std::string> PublicHeaders; // `include/` public API headers
73 extern std::vector<std::string> AllFiles; // All files in the temp directory
74 extern std::vector<std::string> NoFiles; // Jut doesn't run the pass (Why?)
75 
76 namespace ws2st {
77  // Disambiguate a SCALAR/VECTOR implementation
78  enum class ForceType { SCALAR, VECTOR };
79 
84  typedef void(* WashCallbackFn)(const MatchFinder::MatchResult &, Replacements &);
85  typedef void(* WashComputeFn)(const WashOptions& opts);
86 
91  std::vector<std::string> reads_from;
92  std::vector<std::string> writes_to;
93  };
94 
99  struct WashProgramMeta {
100  std::vector<std::string> scalar_force_list;
101  std::vector<std::string> vector_force_list;
102  std::unordered_map<std::string, FullSourceLoc> force_meta;
103 
104  std::vector<std::pair<std::string, std::string>> variable_list;
105  int simulation_dimension;
106 
107  std::vector<std::string> kernels_list;
108  std::vector<std::string> init_kernels_list;
109  std::string neighbour_kernel;
110  std::unordered_map<std::string, std::unique_ptr<KernelDependencies>> kernels_dependency_map;
111  std::vector<bool> domain_sync_locations;
112  std::vector<bool> domain_sync_before;
113 
114  };
115 
116  // Global meta information about the simulation
117  extern std::shared_ptr<WashProgramMeta> program_meta;
118 }
119 
127 std::optional<std::string> getSourceText(ASTContext *ctx, SourceRange srcRange);
Definition: common.hpp:58
Struct to hold two vectors of dependencies (appropriately named)
Definition: common.hpp:90
Options about how the Wash analysis will behave.
Definition: common.hpp:45
Meta information about the simulation which is defined globally and can be read/written to by the cal...
Definition: common.hpp:99
Definition: arguments.cpp:3