souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Member Functions | Private Member Functions
souffle::ast::transform::ReorderLiteralsTransformer Class Reference

Transformation pass to reorder body literals. More...

#include <ReorderLiterals.h>

Inheritance diagram for souffle::ast::transform::ReorderLiteralsTransformer:
Inheritance graph
Collaboration diagram for souffle::ast::transform::ReorderLiteralsTransformer:
Collaboration graph

Public Member Functions

ReorderLiteralsTransformerclone () const override
 
std::string getName () const override
 
- Public Member Functions inherited from souffle::ast::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 
virtual ~Transformer ()=default
 

Static Public Member Functions

static ClausereorderClauseWithSips (const SipsMetric &sips, const Clause *clause)
 Reorder the clause based on a given SIPS function. More...
 

Private Member Functions

bool transform (TranslationUnit &translationUnit) override
 

Detailed Description

Transformation pass to reorder body literals.

Definition at line 34 of file ReorderLiterals.h.

Member Function Documentation

◆ clone()

ReorderLiteralsTransformer* souffle::ast::transform::ReorderLiteralsTransformer::clone ( ) const
inlineoverridevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 40 of file ReorderLiterals.h.

40  {
41  return new ReorderLiteralsTransformer();
42  }

◆ getName()

std::string souffle::ast::transform::ReorderLiteralsTransformer::getName ( ) const
inlineoverridevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 36 of file ReorderLiterals.h.

36  {
37  return "ReorderLiteralsTransformer";
38  }

◆ reorderClauseWithSips()

Clause * souffle::ast::transform::ReorderLiteralsTransformer::reorderClauseWithSips ( const SipsMetric sips,
const Clause clause 
)
static

Reorder the clause based on a given SIPS function.

Parameters
sipsFunctionSIPS metric to use
clauseclause to reorder
Returns
nullptr if no change, otherwise a new reordered clause

Definition at line 46 of file ReorderLiterals.cpp.

50  {
51  if (newOrdering[i] != i) {
52  changeNeeded = true;
53  }
54  }
55 
56  // reorder if needed
57  return changeNeeded ? reorderAtoms(clause, newOrdering) : nullptr;
58 }
59 
60 bool ReorderLiteralsTransformer::transform(TranslationUnit& translationUnit) {
61  bool changed = false;
62  Program& program = translationUnit.getProgram();
63 
64  // --- SIPS-based static reordering ---
65  // ordering is based on the given SIPS

References i.

◆ transform()

bool souffle::ast::transform::ReorderLiteralsTransformer::transform ( TranslationUnit translationUnit)
overrideprivatevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 67 of file ReorderLiterals.cpp.

69  {
70  sipsChosen = Global::config().get("SIPS");
71  }
72  auto sipsFunction = SipsMetric::create(sipsChosen, translationUnit);
73 
74  // literal reordering is a rule-local transformation
75  std::vector<Clause*> clausesToRemove;
76 
77  for (Clause* clause : program.getClauses()) {
78  Clause* newClause = reorderClauseWithSips(*sipsFunction, clause);
79  if (newClause != nullptr) {
80  // reordering needed - swap around
81  clausesToRemove.push_back(clause);
82  program.addClause(Own<Clause>(newClause));
83  }
84  }
85 
86  changed |= !clausesToRemove.empty();
87  for (auto* clause : clausesToRemove) {
88  program.removeClause(clause);
89  }
90 
91  // --- profile-guided reordering ---
92  if (Global::config().has("profile-use")) {
93  // parse supplied profile information
94  auto profilerSips = SipsMetric::create("profiler", translationUnit);
95 
96  // change the ordering of literals within clauses
97  std::vector<Clause*> clausesToRemove;
98  for (Clause* clause : program.getClauses()) {
99  Clause* newClause = reorderClauseWithSips(*profilerSips, clause);
100  if (newClause != nullptr) {
101  // reordering needed - swap around
102  clausesToRemove.push_back(clause);
103  program.addClause(Own<Clause>(newClause));
104  }
105  }
106 
107  changed |= !clausesToRemove.empty();
108  for (auto* clause : clausesToRemove) {
109  program.removeClause(clause);
110  }
111  }
112 
113  return changed;
114 }
115 
116 } // namespace souffle::ast::transform

References souffle::Global::config().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
souffle::ast::reorderAtoms
Clause * reorderAtoms(const Clause *clause, const std::vector< unsigned int > &newOrder)
Reorders the atoms of a clause to be in the given order.
Definition: Utils.cpp:264
souffle::ast::transform::ReorderLiteralsTransformer::transform
bool transform(TranslationUnit &translationUnit) override
Definition: ReorderLiterals.cpp:67
souffle::ast::SipsMetric::create
static std::unique_ptr< SipsMetric > create(const std::string &heuristic, const TranslationUnit &tu)
Create a SIPS metric based on a given heuristic.
Definition: SipsMetric.cpp:68
i
size_t i
Definition: json11.h:663
souffle::ast::transform::ReorderLiteralsTransformer::reorderClauseWithSips
static Clause * reorderClauseWithSips(const SipsMetric &sips, const Clause *clause)
Reorder the clause based on a given SIPS function.
Definition: ReorderLiterals.cpp:46
souffle::Global::config
static MainConfig & config()
Definition: Global.h:141