-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recognize IfExpr in CompUniqueBoundsPB (#581)
* Recognize IfExpr in CompUniqueBoundsPB * Remove statement checking from CompUniqueBoundsPB since we have now requried to instantiate one CompUniqueBoundsPB object per statement
- Loading branch information
Showing
11 changed files
with
401 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef FREE_TENSOR_NORMALIZE_CONDITIONAL_EXPR_H | ||
#define FREE_TENSOR_NORMALIZE_CONDITIONAL_EXPR_H | ||
|
||
#include <vector> | ||
|
||
#include <expr.h> | ||
|
||
namespace freetensor { | ||
|
||
/** | ||
* Break a expression into several conditional parts. | ||
* | ||
* This function is used for analyzing expressions with `IfExpr` inside. The | ||
* result will be several parts with conditions, where each part is no longer | ||
* with `IfExpr`. | ||
* | ||
* @param expr : The expression to be analyzed. | ||
* @return : A vector of pairs, where the first element is the value of the | ||
* expression, and the second element is the condition of the expression. The | ||
* condition may be null, which means the expression is always true. | ||
*/ | ||
std::vector<std::pair<Expr /* value */, Expr /* condition, maybe null */>> | ||
normalizeConditionalExpr(const Expr &expr); | ||
|
||
} // namespace freetensor | ||
|
||
#endif // FREE_TENSOR_NORMALIZE_CONDITIONAL_EXPR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <analyze/all_uses.h> | ||
#include <analyze/comp_unique_bounds.h> | ||
|
||
namespace freetensor { | ||
|
||
namespace { | ||
|
||
class CountHeavyOps : public Visitor { | ||
int cnt_ = 0; | ||
|
||
public: | ||
int cnt() const { return cnt_; } | ||
|
||
protected: | ||
void visitExpr(const Expr &op) { | ||
Visitor::visitExpr(op); | ||
if (!op->isConst() && op->nodeType() != ASTNodeType::Add && | ||
op->nodeType() != ASTNodeType::Sub && | ||
op->nodeType() != ASTNodeType::Mul) { | ||
cnt_++; | ||
} | ||
} | ||
}; | ||
|
||
} // Anonymous namespace | ||
|
||
int CompUniqueBounds::Bound::countHeavyOps(const Expr &op) { | ||
CountHeavyOps visitor; | ||
visitor(op); | ||
return visitor.cnt(); | ||
} | ||
|
||
int CompUniqueBounds::Bound::countScope( | ||
const Expr &expr, | ||
const std::unordered_map<std::string, int> &orderedScope) { | ||
int scope = 0; | ||
for (auto &&use : allUses(expr)) | ||
scope = std::max(scope, orderedScope.at(use)); | ||
return scope; | ||
} | ||
|
||
} // namespace freetensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.