Skip to content

Commit

Permalink
Corrected namespace of ControlFlowGraph to match file location
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunderberg committed Oct 27, 2022
1 parent 35a7dcd commit f04d4f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/tir/analysis/control_flow_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
#include "../../arith/unwrap_vector_expr.h"

namespace tvm {
namespace arith {
namespace tir {

using namespace tir;
using namespace arith;

namespace {
bool HasBufferLoad(PrimExpr expr) {
Expand Down Expand Up @@ -1637,5 +1637,5 @@ PrimExpr ControlFlowGraph::SimplifyInContext(PrimExpr expr, const tir::Stmt& con
return expr;
}

} // namespace arith
} // namespace tir
} // namespace tvm
62 changes: 32 additions & 30 deletions src/tir/analysis/control_flow_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define TVM_TIR_ANALYSIS_CONTROL_FLOW_GRAPH_H_

namespace tvm {
namespace arith {
namespace tir {

/*! \brief Represents an interaction with a buffer */
struct BufferTouch {
Expand All @@ -46,14 +46,14 @@ struct BufferTouch {
Assume,
};

BufferTouch(tir::Buffer buffer, PrimExpr predicate, PrimExpr value)
BufferTouch(Buffer buffer, PrimExpr predicate, PrimExpr value)
: buffer(buffer),
predicate(predicate),
value(value),
loop_var_expressions({}),
touch_type(AccessType::Assume) {}

BufferTouch(tir::Buffer buffer, PrimExpr predicate, PrimExpr value,
BufferTouch(Buffer buffer, PrimExpr predicate, PrimExpr value,
std::vector<std::pair<Var, PrimExpr>> loop_var_expressions, AccessType touch_type)
: buffer(buffer),
predicate(predicate),
Expand All @@ -62,7 +62,7 @@ struct BufferTouch {
touch_type(touch_type) {}

/*! \brief The buffer being touched */
tir::Buffer buffer;
Buffer buffer;

/*! \brief A predicate that is true when this touch applies
*
Expand Down Expand Up @@ -104,23 +104,23 @@ struct BufferTouch {
* subset. Returns false if it cannot be proven to be a subset of
* ther other subset.
*/
bool IsSubsetOf(const BufferTouch& other, Analyzer* analyzer) const;
bool IsSubsetOf(const BufferTouch& other, arith::Analyzer* analyzer) const;

/* \brief Checks if this touch affects distinct indicates from another
*
* Returns true if it can be proven that the two predicates cannot
* be simultaneously true. Returns false if it cannot be proven
* that the two predicates are distinct.
*/
bool IsDistinctFrom(const BufferTouch& other, Analyzer* analyzer) const;
bool IsDistinctFrom(const BufferTouch& other, arith::Analyzer* analyzer) const;

/* \brief Checks if this touch affects distinct indicates from another
*
* Returns true if it can be proven that the two predicates cannot
* be simultaneously true. Returns false if it cannot be proven
* that the two predicates are distinct.
*/
bool IsEquivalentTo(const BufferTouch& other, Analyzer* analyzer) const;
bool IsEquivalentTo(const BufferTouch& other, arith::Analyzer* analyzer) const;

friend std::ostream& operator<<(std::ostream& os, const BufferTouch& expr);
};
Expand Down Expand Up @@ -148,8 +148,8 @@ class BufferState {
* the original expression is returned.
*/
PrimExpr SubstituteKnownBufferValues(PrimExpr expr,
const Map<tir::Buffer, Array<tir::Var>>& axis_var_lookup,
Analyzer* analyzer) const;
const Map<Buffer, Array<Var>>& axis_var_lookup,
arith::Analyzer* analyzer) const;

/*! \brief Apply a condition to all known constraints
*
Expand All @@ -167,13 +167,13 @@ class BufferState {
*
* \param var_remap The variable remapping to apply.
*/
void Substitute(const Map<Var, PrimExpr>& var_remap, Analyzer* analyzer);
void Substitute(const Map<Var, PrimExpr>& var_remap, arith::Analyzer* analyzer);

/*! \brief Simplify the predicate of all constraints
*
* \param analyzer The analyzer with which to simplify
*/
void Simplify(Analyzer* analyzer);
void Simplify(arith::Analyzer* analyzer);

/*! \brief Update the known buffer values based on buffer touches
*
Expand All @@ -189,19 +189,21 @@ class BufferState {
*
* \param analyzer The analyzer to use for simplifications
*/
void ApplyTouches(const Map<tir::Buffer, Array<tir::Var>>& axis_var_lookup,
const std::vector<BufferTouch>& touch_points, Analyzer* analyzer);
void ApplyTouches(const Map<Buffer, Array<Var>>& axis_var_lookup,
const std::vector<BufferTouch>& touch_points, arith::Analyzer* analyzer);

void BackpropUnusedIndices(const Map<tir::Buffer, Array<tir::Var>>& axis_var_lookup,
const std::vector<BufferTouch>& touch_points, Analyzer* analyzer);
void BackpropUnusedIndices(const Map<Buffer, Array<Var>>& axis_var_lookup,
const std::vector<BufferTouch>& touch_points,
arith::Analyzer* analyzer);

/*! \brief Remove free parameters from the constraints
*
* \param free_predicate_parameters
*
* \param analyzer The analyzer with which to simplify after removal
*/
void RemoveFreeParameters(const Map<Var, Range>& free_predicate_parameters, Analyzer* analyzer);
void RemoveFreeParameters(const Map<Var, Range>& free_predicate_parameters,
arith::Analyzer* analyzer);

/*! \brief Check if two buffer states are equivalent
*
Expand All @@ -211,23 +213,23 @@ class BufferState {
*
* \return True if the two states are provably equivalent, false otherwise.
*/
bool IsEquivalentTo(const BufferState& other, Analyzer* analyzer) const;
bool IsEquivalentTo(const BufferState& other, arith::Analyzer* analyzer) const;

/* \brief Add known values provided by another state
*
* \param other The state with which to merge constraints
*
* \param analyzer The analyzer with which to simplify the result
*/
void Union(const BufferState& other, Analyzer* analyzer);
void Union(const BufferState& other, arith::Analyzer* analyzer);

/* \brief Remove all known values not consistent with another state
*
* \param other The state with which to merge constraints
*
* \param analyzer The analyzer with which to simplify the result
*/
void Intersection(const BufferState& other, Analyzer* analyzer);
void Intersection(const BufferState& other, arith::Analyzer* analyzer);

friend std::ostream& operator<<(std::ostream& os, const BufferState&);

Expand All @@ -241,7 +243,7 @@ class ControlFlowGraph {
public:
/* \brief Extract the touch pattern from a TIR statement
*/
explicit ControlFlowGraph(const tir::Stmt& stmt, size_t max_revisits = 5);
explicit ControlFlowGraph(const Stmt& stmt, size_t max_revisits = 5);

/* \brief Check if a write is overwritten without impacting final results
*
Expand All @@ -251,8 +253,8 @@ class ControlFlowGraph {
* overwritten without contributing to any later statements.
* Returns false otherwise.
*/
bool IsOverwrittenWithoutEffect(const tir::BufferStore& store, Analyzer* analyzer,
const tir::StmtNode* context = nullptr) const;
bool IsOverwrittenWithoutEffect(const BufferStore& store, arith::Analyzer* analyzer,
const StmtNode* context = nullptr) const;

/* \brief Simplify the expression, assuming it occurs within the given context
*
Expand All @@ -269,7 +271,7 @@ class ControlFlowGraph {
* \returns The simplified statement
*
*/
PrimExpr SimplifyInContext(PrimExpr expr, const tir::Stmt& context, Analyzer* analyzer) const;
PrimExpr SimplifyInContext(PrimExpr expr, const Stmt& context, arith::Analyzer* analyzer) const;

friend std::ostream& operator<<(std::ostream& os, const ControlFlowGraph& pattern);

Expand All @@ -286,7 +288,7 @@ class ControlFlowGraph {
*
* \returns Variables representing a position along the buffer's axis.
*/
Array<Var> GetIndexVariables(const tir::Buffer& buf, const Array<PrimExpr>& indices);
Array<Var> GetIndexVariables(const Buffer& buf, const Array<PrimExpr>& indices);

/*! \brief Return index variables representing locations within a
* buffer, if they have been generated before.
Expand All @@ -297,7 +299,7 @@ class ControlFlowGraph {
*
* \returns Variables representing a position along the buffer's axis.
*/
Optional<Array<Var>> GetIndexVariables(const tir::Buffer& buf) const;
Optional<Array<Var>> GetIndexVariables(const Buffer& buf) const;

/*! \brief Propagate known values from known BufferStore/assume
* subsequent control flow blocks
Expand Down Expand Up @@ -375,11 +377,11 @@ class ControlFlowGraph {
/* \brief The blocks that occur before this block */
std::vector<ControlFlowEdge> predecessors;

BufferTouch MakeBufferTouch(ControlFlowGraph* graph, const tir::Buffer& buf,
BufferTouch MakeBufferTouch(ControlFlowGraph* graph, const Buffer& buf,
const Array<PrimExpr>& indices, BufferTouch::AccessType touch_type,
PrimExpr known_value_expr) const;

std::pair<BufferTouch, Map<Var, Range>> MakeBufferTouch(const tir::Buffer& buf,
std::pair<BufferTouch, Map<Var, Range>> MakeBufferTouch(const Buffer& buf,
Array<Var> index_variables,
Array<PrimExpr> indices,
BufferTouch::AccessType touch_type,
Expand All @@ -395,7 +397,7 @@ class ControlFlowGraph {
* A map to look up the control flow block that contains the
* statement.
*/
std::unordered_map<const tir::StmtNode*, size_t> control_flow_lookup_;
std::unordered_map<const StmtNode*, size_t> control_flow_lookup_;

/*! \brief A map from free parameters to their range
*
Expand All @@ -419,7 +421,7 @@ class ControlFlowGraph {
* variables to represent the buffer's axes, reducing the amount of
* variable substitution required.
*/
Map<tir::Buffer, Array<tir::Var>> axis_var_lookup_;
Map<Buffer, Array<Var>> axis_var_lookup_;

/* \brief Assumptions that do not depend on buffer values
*
Expand All @@ -432,6 +434,6 @@ class ControlFlowGraph {
friend class ControlFlowGraphBuilder;
};

} // namespace arith
} // namespace tir
} // namespace tvm
#endif // TVM_TIR_ANALYSIS_CONTROL_FLOW_GRAPH_H_

0 comments on commit f04d4f9

Please sign in to comment.