10enum class Type { BOOL, DOUBLE, SIZE_T, CONTAINER, TRAVERSAL, LOAD_ESTIMATOR, DATA_LAYOUT, NEWTON3, CELL_SIZE_FACTOR };
67 [&](
const auto &val) {
96 [](std::string s,
double d) { return std::move(s) +
',' + std::to_string(d); });
103 [[nodiscard]]
static std::string optionSetToString(
const std::set<T> &set) {
104 if (not set.empty()) {
105 auto comma_fold = [](std::string a, T b) {
return std::move(a) +
',' + b.to_string(); };
107 return std::accumulate(std::next(set.begin()), set.end(), set.begin()->to_string(), comma_fold);
112 template <
typename T>
113 [[nodiscard]]
static bool contains(
const std::set<T> &set,
const T &option) {
114 return set.find(option) != set.end();
117 template <
class T,
class SetT>
118 static void addHelper2(T value, SetT &set) {
119 if constexpr (std::is_same_v<T, typename SetT::value_type>) {
124 template <
class T,
class... SetT>
125 static void addHelper(T value, SetT &...sets) {
126 (addHelper2(value, sets), ...);
133namespace RuleSyntax {
135class CodeGenerationContext;
206 enum class SameProperty { container, traversal, dataLayout, newton3, loadEstimator, cellSizeFactor };
236 [[nodiscard]] std::string
toString()
const;
247 static std::string samePropertyToString(
SameProperty same);
261 explicit CodeGenerationContext(std::map<std::string, std::pair<const Define *, size_t>> initialAddressEnvironment);
296 [[nodiscard]]
size_t addressOf(
const std::string &name)
const;
346 size_t currentNeededStack;
347 size_t maxNeededStack;
349 std::map<std::string, std::pair<const Define *, size_t>> addressEnvironment;
350 size_t initialNumVariables;
351 std::map<std::string, const DefineList *> lists;
352 std::vector<ConfigurationOrder> configurationOrders;
462 enum Operator { LESS, GREATER, AND, OR, ADD, SUB, MUL, DIV };
467 std::shared_ptr<Expression>
left;
Class containing multiple options that form an algorithm configuration for the pairwise iteration.
Definition: Configuration.h:24
LoadEstimatorOption loadEstimator
Load Estimator option.
Definition: Configuration.h:126
TraversalOption traversal
Traversal option.
Definition: Configuration.h:122
double cellSizeFactor
CellSizeFactor.
Definition: Configuration.h:138
DataLayoutOption dataLayout
Data Layout option.
Definition: Configuration.h:130
ContainerOption container
Container option.
Definition: Configuration.h:118
Newton3Option newton3
Newton 3 option.
Definition: Configuration.h:134
A CodeGenerationContext keeps track of the needed stack size of the program, the mapping from variabl...
Definition: RuleBasedProgramTree.h:255
void addGlobalVariable(const Define &definition)
Adds a global variable definition that can be used in the program later.
Definition: RuleBasedProgramTree.cpp:126
void allocateStack(size_t num)
Allocates the given number of MemoryCells on the stack.
Definition: RuleBasedProgramTree.cpp:139
void freeStack(size_t num)
Frees the given number of MemoryCells on the stack.
Definition: RuleBasedProgramTree.cpp:144
size_t addConfigurationOrder(const ConfigurationOrder &configurationOrder)
Adds a configuration order and assigns it an index that can be used to refer to it later.
Definition: RuleBasedProgramTree.cpp:150
const std::vector< ConfigurationOrder > & getConfigurationOrders() const
Definition: RuleBasedProgramTree.cpp:155
ConfigurationPattern smallerConfigurationPatternByIndex(size_t idx) const
Definition: RuleBasedProgramTree.cpp:159
const DefineList * getList(const std::string &name)
Definition: RuleBasedProgramTree.cpp:148
const Define * definitionOf(const std::string &name) const
Definition: RuleBasedProgramTree.cpp:135
void addLocalVariable(const Define &definition)
Adds a local variable definition that can be used in the program later.
Definition: RuleBasedProgramTree.cpp:122
void addList(const std::string &name, const DefineList *list)
Adds a list definition that can be used later in the program.
Definition: RuleBasedProgramTree.cpp:146
~CodeGenerationContext()
Destructor.
size_t getNumLocalVariables() const
Definition: RuleBasedProgramTree.cpp:163
auto getMaxStackSize() const
Definition: RuleBasedProgramTree.h:307
size_t addressOf(const std::string &name) const
Definition: RuleBasedProgramTree.cpp:131
A VM that is capable of executing a program with simple instructions on a stack of MemoryCells.
Definition: RuleVM.h:18
std::variant< bool, double, size_t, ContainerOption, TraversalOption, LoadEstimatorOption, DataLayoutOption, Newton3Option > MemoryCell
The type of a memory cell in the stack the VM operates on.
Definition: RuleVM.h:24
Type typeOf(const RuleVM::MemoryCell &memoryCell)
Converts the type of a RuleVM memory cell to the type in the AST.
Definition: RuleBasedProgramTree.h:161
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
Type
Enum describing all types that are allowed in a rule program.
Definition: RuleBasedProgramTree.h:10
A configuration pattern that matches zero or more actual configurations, used in the rule language.
Definition: RuleBasedProgramTree.h:17
ConfigurationPattern()
Constructs a pattern that matches all configurations.
~ConfigurationPattern() noexcept
Destructor.
std::set< LoadEstimatorOption > _loadEstimators
The allowed load estimators.
Definition: RuleBasedProgramTree.h:29
std::set< TraversalOption > _traversals
The allowed traversals.
Definition: RuleBasedProgramTree.h:25
std::set< ContainerOption > _containers
The allowed containers.
Definition: RuleBasedProgramTree.h:21
std::set< double > _cellSizeFactors
The allowed cell size factors.
Definition: RuleBasedProgramTree.h:41
void add(const RuleVM::MemoryCell &value)
Adds a value to the allowed values of this configuration pattern.
Definition: RuleBasedProgramTree.h:65
std::string toString() const
Definition: RuleBasedProgramTree.h:89
std::set< Newton3Option > _newton3Options
The allowed newton3 options.
Definition: RuleBasedProgramTree.h:37
ConfigurationPattern(const ConfigurationPattern &configurationPattern)
Copy Constructor.
std::set< DataLayoutOption > _dataLayouts
The allowed data layouts.
Definition: RuleBasedProgramTree.h:33
bool matches(const Configuration &configuration) const
Definition: RuleBasedProgramTree.h:77
A binary operator in the rule language.
Definition: RuleBasedProgramTree.h:458
Type getType() const override
Definition: RuleBasedProgramTree.cpp:46
Operator
Enum of all binary operators.
Definition: RuleBasedProgramTree.h:462
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for evaluating this expression at runtime.
Definition: RuleBasedProgramTree.cpp:29
std::shared_ptr< Expression > left
The left subexpression of the operator.
Definition: RuleBasedProgramTree.h:467
Operator op
The operator to apply.
Definition: RuleBasedProgramTree.h:471
std::shared_ptr< Expression > right
The right subexpression of the operator.
Definition: RuleBasedProgramTree.h:475
A ConfigurationOrder statement in the rule language e.g.
Definition: RuleBasedProgramTree.h:193
std::vector< SameProperty > sameProperties
Vector containing all set same properties.
Definition: RuleBasedProgramTree.h:211
ConfigurationOrder()=default
Constructs a configuration order that says all configurations are better than all configurations.
ConfigurationPattern greater
The greater/better configuration pattern.
Definition: RuleBasedProgramTree.h:197
SameProperty
Enum containing all possible values of 'with same' options.
Definition: RuleBasedProgramTree.h:206
ConfigurationPattern smaller
The smaller/worse configuration pattern.
Definition: RuleBasedProgramTree.h:201
bool haveEqualSameProperties(const Configuration &conf1, const Configuration &conf2) const
Checks if two configurations have the equal same properties as required by this configuration order.
Definition: RuleBasedProgramTree.cpp:69
~ConfigurationOrder() override=default
Destructor.
std::string toString() const
Definition: RuleBasedProgramTree.cpp:61
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for this statement.
Definition: RuleBasedProgramTree.cpp:56
A list definition in the rule language.
Definition: RuleBasedProgramTree.h:385
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for this statement.
Definition: RuleBasedProgramTree.cpp:177
std::vector< Literal > values
The values in the list.
Definition: RuleBasedProgramTree.h:393
std::string listName
The name of the list.
Definition: RuleBasedProgramTree.h:389
A variable definition in the rule language.
Definition: RuleBasedProgramTree.h:493
std::shared_ptr< Expression > value
The value of the variable.
Definition: RuleBasedProgramTree.h:501
~Define() override
Destructor.
Definition: RuleBasedProgramTree.cpp:184
std::string variable
The name of the variable.
Definition: RuleBasedProgramTree.h:497
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for this statement.
Definition: RuleBasedProgramTree.cpp:186
An expression in the rule language.
Definition: RuleBasedProgramTree.h:166
virtual ~Expression()=default
Virtual default constructor.
virtual void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const =0
Generates code for evaluating this expression at runtime.
virtual Type getType() const =0
An if statement in the rule language.
Definition: RuleBasedProgramTree.h:521
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for this statement.
Definition: RuleBasedProgramTree.cpp:197
std::shared_ptr< Expression > condition
The condition of the if statement.
Definition: RuleBasedProgramTree.h:525
std::vector< std::shared_ptr< Statement > > consequences
The statements contained in the body of the if statement.
Definition: RuleBasedProgramTree.h:529
A literal in the rule language.
Definition: RuleBasedProgramTree.h:358
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for evaluating this expression at runtime.
Definition: RuleBasedProgramTree.cpp:169
RuleVM::MemoryCell value
The value of the literal.
Definition: RuleBasedProgramTree.h:362
Type getType() const override
Definition: RuleBasedProgramTree.cpp:167
Type type
The type of the literal in AST.
Definition: RuleBasedProgramTree.h:366
The AST of a rule program.
Definition: RuleBasedProgramTree.h:544
std::vector< std::shared_ptr< Statement > > statements
All statements in the program.
Definition: RuleBasedProgramTree.h:548
RuleVM::Program generateCode(CodeGenerationContext &context) const
Generates code for the whole program described by this AST.
Definition: RuleBasedProgramTree.cpp:210
A statement in the rule language.
Definition: RuleBasedProgramTree.h:142
virtual ~Statement()=default
Virtual default constructor.
virtual void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const =0
Generates code for this statement.
A unary operator in the rule language.
Definition: RuleBasedProgramTree.h:428
std::shared_ptr< Expression > child
Subexpression of unary operator.
Definition: RuleBasedProgramTree.h:437
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for evaluating this expression at runtime.
Definition: RuleBasedProgramTree.cpp:21
Operator op
Unary operator to apply.
Definition: RuleBasedProgramTree.h:441
Operator
Enum of all unary operators.
Definition: RuleBasedProgramTree.h:432
Type getType() const override
Definition: RuleBasedProgramTree.cpp:27
A variable access in the rule language.
Definition: RuleBasedProgramTree.h:408
Type getType() const override
Definition: RuleBasedProgramTree.cpp:16
const Define * definition
The definition of the variable to access.
Definition: RuleBasedProgramTree.h:412
Variable(const Define *definition)
Constructs a variable access in the rule language.
Definition: RuleBasedProgramTree.h:418
void generateCode(CodeGenerationContext &context, RuleVM::Program &program) const override
Generates code for evaluating this expression at runtime.
Definition: RuleBasedProgramTree.cpp:11
A program that can be executed by this VM.
Definition: RuleVM.h:135