souffle  2.0.2-371-g6315b36
Public Types | Public Member Functions | Private Attributes
souffle::ast2ram::ValueIndex Class Reference

#include <ValueIndex.h>

Collaboration diagram for souffle::ast2ram::ValueIndex:
Collaboration graph

Public Types

using generator_location_map = std::vector< std::pair< const ast::Argument *, Location > >
 A map from generative ast::Arguments to storage locations. More...
 
using record_definition_map = std::map< const ast::RecordInit *, Location >
 The type mapping record init expressions to their definition points, hence the point where they get grounded/bound. More...
 
using variable_reference_map = std::map< std::string, std::set< Location > >
 The type mapping variables (referenced by their names) to the locations where they are used. More...
 

Public Member Functions

void addVarReference (const ast::Variable &var, const Location &l)
 
void addVarReference (const ast::Variable &var, int ident, int pos, std::string rel="")
 
const LocationgetDefinitionPoint (const ast::RecordInit &init) const
 
const LocationgetDefinitionPoint (const ast::Variable &var) const
 
const LocationgetGeneratorLoc (const ast::Argument &arg) const
 
const variable_reference_mapgetVariableReferences () const
 
bool isDefined (const ast::Variable &var) const
 
bool isGenerator (const int level) const
 
bool isSomethingDefinedOn (int level) const
 
void print (std::ostream &out) const
 
void setGeneratorLoc (const ast::Argument &arg, const Location &loc)
 
void setRecordDefinition (const ast::RecordInit &init, const Location &l)
 
void setRecordDefinition (const ast::RecordInit &init, int ident, int pos, std::string rel="")
 
 ValueIndex ()
 
 ~ValueIndex ()
 

Private Attributes

generator_location_map arg_generator_locations
 The level of a nested ram operation that is handling a generator operation. More...
 
record_definition_map record_definitions
 The index of record definition points. More...
 
variable_reference_map var_references
 The index of variable accesses. More...
 

Detailed Description

Definition at line 36 of file ValueIndex.h.

Member Typedef Documentation

◆ generator_location_map

A map from generative ast::Arguments to storage locations.

Note, since in this case ast::Argument are indexed by their values (not their address) no standard map can be utilized. (By-value indexing induces an ad-hoc form of CSE.)

Definition at line 59 of file ValueIndex.h.

◆ record_definition_map

The type mapping record init expressions to their definition points, hence the point where they get grounded/bound.

Definition at line 51 of file ValueIndex.h.

◆ variable_reference_map

using souffle::ast2ram::ValueIndex::variable_reference_map = std::map<std::string, std::set<Location> >

The type mapping variables (referenced by their names) to the locations where they are used.

Definition at line 45 of file ValueIndex.h.

Constructor & Destructor Documentation

◆ ValueIndex()

souffle::ast2ram::ValueIndex::ValueIndex ( )
default

◆ ~ValueIndex()

souffle::ast2ram::ValueIndex::~ValueIndex ( )
default

Member Function Documentation

◆ addVarReference() [1/2]

void souffle::ast2ram::ValueIndex::addVarReference ( const ast::Variable var,
const Location l 
)

Definition at line 40 of file ValueIndex.cpp.

42  {
43  return var_references.find(var.getName()) != var_references.end();

◆ addVarReference() [2/2]

void souffle::ast2ram::ValueIndex::addVarReference ( const ast::Variable var,
int  ident,
int  pos,
std::string  rel = "" 
)

Definition at line 45 of file ValueIndex.cpp.

46  {
47  auto pos = var_references.find(var.getName());

References var_references.

◆ getDefinitionPoint() [1/2]

const Location & souffle::ast2ram::ValueIndex::getDefinitionPoint ( const ast::RecordInit init) const

Definition at line 90 of file ValueIndex.cpp.

92  {
93  // check for aggregator definitions
95  [&level](const auto& location) { return location.second.identifier == level; });
96 }
97 

◆ getDefinitionPoint() [2/2]

const Location & souffle::ast2ram::ValueIndex::getDefinitionPoint ( const ast::Variable var) const

Definition at line 53 of file ValueIndex.cpp.

56  {
57  if (dynamic_cast<const ast::Aggregator*>(&arg) != nullptr) {

◆ getGeneratorLoc()

const Location & souffle::ast2ram::ValueIndex::getGeneratorLoc ( const ast::Argument arg) const

Definition at line 63 of file ValueIndex.cpp.

64  {
65  // otherwise, unique for each appearance
66  for (const auto& cur : arg_generator_locations) {
67  if (cur.first == &arg) {
68  return cur.second;
69  }
70  }
71  }
72  fatal("arg `%s` has no generator location", arg);
73 }
74 
75 void ValueIndex::setRecordDefinition(const ast::RecordInit& init, const Location& l) {
76  record_definitions.insert({&init, l});
77 }
78 
79 void ValueIndex::setRecordDefinition(const ast::RecordInit& init, int ident, int pos, std::string rel) {
80  setRecordDefinition(init, Location({ident, pos, rel}));

◆ getVariableReferences()

const variable_reference_map& souffle::ast2ram::ValueIndex::getVariableReferences ( ) const
inline

Definition at line 63 of file ValueIndex.h.

63  {
64  return var_references;
65  }

References var_references.

◆ isDefined()

bool souffle::ast2ram::ValueIndex::isDefined ( const ast::Variable var) const

Definition at line 49 of file ValueIndex.cpp.

◆ isGenerator()

bool souffle::ast2ram::ValueIndex::isGenerator ( const int  level) const

Definition at line 99 of file ValueIndex.cpp.

100  : var_references) {
101  if (cur.second.begin()->identifier == level) {
102  return true;
103  }

◆ isSomethingDefinedOn()

bool souffle::ast2ram::ValueIndex::isSomethingDefinedOn ( int  level) const

Definition at line 105 of file ValueIndex.cpp.

106  : record_definitions) {
107  if (cur.second.identifier == level) {
108  return true;
109  }
110  }
111  // nothing defined on this level
112  return false;
113 }
114 
115 void ValueIndex::print(std::ostream& out) const {
116  out << "Variables:\n\t";
117  out << join(var_references, "\n\t");
118 }
119 
120 } // namespace souffle::ast2ram

◆ print()

void souffle::ast2ram::ValueIndex::print ( std::ostream &  out) const

Definition at line 122 of file ValueIndex.cpp.

◆ setGeneratorLoc()

void souffle::ast2ram::ValueIndex::setGeneratorLoc ( const ast::Argument arg,
const Location loc 
)

Definition at line 59 of file ValueIndex.cpp.

60  if (*cur.first == arg) {
61  return cur.second;

◆ setRecordDefinition() [1/2]

void souffle::ast2ram::ValueIndex::setRecordDefinition ( const ast::RecordInit init,
const Location l 
)

Definition at line 82 of file ValueIndex.cpp.

83  {
84  auto pos = record_definitions.find(&init);

References record_definitions.

◆ setRecordDefinition() [2/2]

void souffle::ast2ram::ValueIndex::setRecordDefinition ( const ast::RecordInit init,
int  ident,
int  pos,
std::string  rel = "" 
)

Definition at line 86 of file ValueIndex.cpp.

Field Documentation

◆ arg_generator_locations

generator_location_map souffle::ast2ram::ValueIndex::arg_generator_locations
private

The level of a nested ram operation that is handling a generator operation.

Definition at line 106 of file ValueIndex.h.

◆ record_definitions

record_definition_map souffle::ast2ram::ValueIndex::record_definitions
private

The index of record definition points.

Definition at line 103 of file ValueIndex.h.

Referenced by setRecordDefinition().

◆ var_references

variable_reference_map souffle::ast2ram::ValueIndex::var_references
private

The index of variable accesses.

Definition at line 100 of file ValueIndex.h.

Referenced by addVarReference(), and getVariableReferences().


The documentation for this class was generated from the following files:
souffle::ast2ram::ValueIndex::arg_generator_locations
generator_location_map arg_generator_locations
The level of a nested ram operation that is handling a generator operation.
Definition: ValueIndex.h:106
l
var l
Definition: htmlJsChartistMin.h:15
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
souffle::ast2ram::ValueIndex::setRecordDefinition
void setRecordDefinition(const ast::RecordInit &init, const Location &l)
Definition: ValueIndex.cpp:82
souffle::any_of
bool any_of(const Container &c, UnaryPredicate p)
A generic test checking whether any elements within a container satisfy a certain predicate.
Definition: FunctionalUtil.h:124
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ast2ram::ValueIndex::record_definitions
record_definition_map record_definitions
The index of record definition points.
Definition: ValueIndex.h:103
souffle::ast2ram::ValueIndex::var_references
variable_reference_map var_references
The index of variable accesses.
Definition: ValueIndex.h:100
souffle::ast2ram::ValueIndex::print
void print(std::ostream &out) const
Definition: ValueIndex.cpp:122