#ifndef LINALG1_OPS_H_
#define LINALG1_OPS_H_
-#include "linalg1/Types.h"
#include "linalg1/RangeOp.h"
#include "linalg1/SliceOp.h"
+#include "linalg1/Types.h"
#include "linalg1/ViewOp.h"
#endif // LINALG1_OPS_H_
/// methods:
/// - addValueIdentityOp
class FxpMathTargetConfig : public TargetConfiguration {
- public:
+public:
/// Creates an FxpMathTargetConfig instance which can be further customized.
static std::unique_ptr<FxpMathTargetConfig> create(SolverContext &context);
- protected:
+
+protected:
FxpMathTargetConfig(SolverContext &context) : TargetConfiguration(context) {}
};
-} // namespace quantizer
-} // namespace mlir
+} // namespace quantizer
+} // namespace mlir
-#endif // MLIR_QUANTIZER_CONFIGURATIONS_FXPMATHCONFIG_H
+#endif // MLIR_QUANTIZER_CONFIGURATIONS_FXPMATHCONFIG_H
std::function<llvm::Error(llvm::Module *)>
mlir::makeOptimizingTransformer(unsigned optLevel, unsigned sizeLevel) {
return [optLevel, sizeLevel](llvm::Module *m) -> llvm::Error {
-
llvm::legacy::PassManager modulePM;
llvm::legacy::FunctionPassManager funcPM(m);
populatePassManagers(modulePM, funcPM, optLevel, sizeLevel);
operandExprStack.pop_back();
}
- //
- // t = expr mod c <=> t = expr - c*q and c*q <= expr <= c*q + c - 1
- //
- // A mod expression "expr mod c" is thus flattened by introducing a new local
- // variable q (= expr floordiv c), such that expr mod c is replaced with
- // 'expr - c * q' and c * q <= expr <= c * q + c - 1 are added to localVarCst.
+//
+// t = expr mod c <=> t = expr - c*q and c*q <= expr <= c*q + c - 1
+//
+// A mod expression "expr mod c" is thus flattened by introducing a new local
+// variable q (= expr floordiv c), such that expr mod c is replaced with
+// 'expr - c * q' and c * q <= expr <= c * q + c - 1 are added to localVarCst.
void SimpleAffineExprFlattener::visitModExpr(AffineBinaryOpExpr expr) {
assert(operandExprStack.size() >= 2);
// This is a pure affine expr; the RHS will be a constant.
eq[getConstantIndex()] = expr.getValue();
}
- // t = expr floordiv c <=> t = q, c * q <= expr <= c * q + c - 1
- // A floordiv is thus flattened by introducing a new local variable q, and
- // replacing that expression with 'q' while adding the constraints
- // c * q <= expr <= c * q + c - 1 to localVarCst (done by
- // FlatAffineConstraints::addLocalFloorDiv).
- //
- // A ceildiv is similarly flattened:
- // t = expr ceildiv c <=> t = (expr + c - 1) floordiv c
+// t = expr floordiv c <=> t = q, c * q <= expr <= c * q + c - 1
+// A floordiv is thus flattened by introducing a new local variable q, and
+// replacing that expression with 'q' while adding the constraints
+// c * q <= expr <= c * q + c - 1 to localVarCst (done by
+// FlatAffineConstraints::addLocalFloorDiv).
+//
+// A ceildiv is similarly flattened:
+// t = expr ceildiv c <=> t = (expr + c - 1) floordiv c
void SimpleAffineExprFlattener::visitDivExpr(AffineBinaryOpExpr expr,
bool isCeil) {
assert(operandExprStack.size() >= 2);
lhs[getLocalVarStartIndex() + loc] = 1;
}
- // Add a local identifier (needed to flatten a mod, floordiv, ceildiv expr).
- // The local identifier added is always a floordiv of a pure add/mul affine
- // function of other identifiers, coefficients of which are specified in
- // dividend and with respect to a positive constant divisor. localExpr is the
- // simplified tree expression (AffineExpr) corresponding to the quantifier.
+// Add a local identifier (needed to flatten a mod, floordiv, ceildiv expr).
+// The local identifier added is always a floordiv of a pure add/mul affine
+// function of other identifiers, coefficients of which are specified in
+// dividend and with respect to a positive constant divisor. localExpr is the
+// simplified tree expression (AffineExpr) corresponding to the quantifier.
void SimpleAffineExprFlattener::addLocalFloorDivId(ArrayRef<int64_t> dividend,
int64_t divisor,
AffineExpr localExpr) {
case 0:
// This may either be a nul character in the source file or may be the EOF
// marker that llvm::MemoryBuffer guarantees will be there.
- if (curPtr-1 == curBuffer.end())
+ if (curPtr - 1 == curBuffer.end())
return formToken(Token::eof, tokStart);
LLVM_FALLTHROUGH;
- case ':': return formToken(Token::colon, tokStart);
- case ',': return formToken(Token::comma, tokStart);
- case '(': return formToken(Token::l_paren, tokStart);
- case ')': return formToken(Token::r_paren, tokStart);
- case '{': return formToken(Token::l_brace, tokStart);
- case '}': return formToken(Token::r_brace, tokStart);
+ case ':':
+ return formToken(Token::colon, tokStart);
+ case ',':
+ return formToken(Token::comma, tokStart);
+ case '(':
+ return formToken(Token::l_paren, tokStart);
+ case ')':
+ return formToken(Token::r_paren, tokStart);
+ case '{':
+ return formToken(Token::l_brace, tokStart);
+ case '}':
+ return formToken(Token::r_brace, tokStart);
case '[':
return formToken(Token::l_square, tokStart);
case ']':
return formToken(Token::r_square, tokStart);
- case '<': return formToken(Token::less, tokStart);
- case '>': return formToken(Token::greater, tokStart);
- case '=': return formToken(Token::equal, tokStart);
-
- case '+': return formToken(Token::plus, tokStart);
- case '*': return formToken(Token::star, tokStart);
+ case '<':
+ return formToken(Token::less, tokStart);
+ case '>':
+ return formToken(Token::greater, tokStart);
+ case '=':
+ return formToken(Token::equal, tokStart);
+
+ case '+':
+ return formToken(Token::plus, tokStart);
+ case '*':
+ return formToken(Token::star, tokStart);
case '-':
if (*curPtr == '>') {
++curPtr;
LLVM_FALLTHROUGH;
case '%':
return lexPrefixedIdentifier(tokStart);
- case '"': return lexString(tokStart);
-
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
+ case '"':
+ return lexString(tokStart);
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
return lexNumber(tokStart);
}
}
return lexToken();
case 0:
// If this is the end of the buffer, end the comment.
- if (curPtr-1 == curBuffer.end()) {
+ if (curPtr - 1 == curBuffer.end()) {
--curPtr;
return lexToken();
}
++curPtr;
// Check to see if this identifier is a keyword.
- StringRef spelling(tokStart, curPtr-tokStart);
+ StringRef spelling(tokStart, curPtr - tokStart);
// Check for i123.
if (tokStart[0] == 'i') {
}
Token::Kind kind = llvm::StringSwitch<Token::Kind>(spelling)
-#define TOK_KEYWORD(SPELLING) \
- .Case(#SPELLING, Token::kw_##SPELLING)
+#define TOK_KEYWORD(SPELLING) .Case(#SPELLING, Token::kw_##SPELLING)
#include "TokenKinds.def"
- .Default(Token::bare_identifier);
+ .Default(Token::bare_identifier);
return Token(kind, spelling);
}
++curPtr;
}
} else if (isalpha(*curPtr) || isPunct(*curPtr)) {
- do {
+ do {
++curPtr;
} while (isalpha(*curPtr) || isdigit(*curPtr) || isPunct(*curPtr));
} else {
++curPtr;
// Skip over [0-9]*([eE][-+]?[0-9]+)?
- while (isdigit(*curPtr)) ++curPtr;
+ while (isdigit(*curPtr))
+ ++curPtr;
if (*curPtr == 'e' || *curPtr == 'E') {
if (isdigit(static_cast<unsigned char>(curPtr[1])) ||
((curPtr[1] == '-' || curPtr[1] == '+') &&
isdigit(static_cast<unsigned char>(curPtr[2])))) {
curPtr += 2;
- while (isdigit(*curPtr)) ++curPtr;
+ while (isdigit(*curPtr))
+ ++curPtr;
}
}
return formToken(Token::floatliteral, tokStart);
case 0:
// If this is a random nul character in the middle of a string, just
// include it. If it is the end of file, then it is an error.
- if (curPtr-1 != curBuffer.end())
+ if (curPtr - 1 != curBuffer.end())
continue;
LLVM_FALLTHROUGH;
case '\n':
case '\v':
case '\f':
- return emitError(curPtr-1, "expected '\"' in string literal");
+ return emitError(curPtr - 1, "expected '\"' in string literal");
case '\\':
// Handle explicitly a few escapes.
if (*curPtr == '"' || *curPtr == '\\' || *curPtr == 'n' || *curPtr == 't')
#ifndef MLIR_LIB_PARSER_LEXER_H
#define MLIR_LIB_PARSER_LEXER_H
-#include "mlir/Parser.h"
#include "Token.h"
+#include "mlir/Parser.h"
namespace mlir {
class Location;
private:
// Helpers.
Token formToken(Token::Kind kind, const char *tokStart) {
- return Token(kind, StringRef(tokStart, curPtr-tokStart));
+ return Token(kind, StringRef(tokStart, curPtr - tokStart));
}
Token emitError(const char *loc, const Twine &message);
} // end namespace mlir
-#endif // MLIR_LIB_PARSER_LEXER_H
+#endif // MLIR_LIB_PARSER_LEXER_H
using llvm::SMLoc;
using llvm::SMRange;
-SMLoc Token::getLoc() const {
- return SMLoc::getFromPointer(spelling.data());
-}
+SMLoc Token::getLoc() const { return SMLoc::getFromPointer(spelling.data()); }
SMLoc Token::getEndLoc() const {
return SMLoc::getFromPointer(spelling.data() + spelling.size());
}
-SMRange Token::getLocRange() const {
- return SMRange(getLoc(), getEndLoc());
-}
+SMRange Token::getLocRange() const { return SMRange(getLoc(), getEndLoc()); }
/// For an integer token, return its value as an unsigned. If it doesn't fit,
/// return None.
/// For an inttype token, return its bitwidth.
Optional<unsigned> Token::getIntTypeBitwidth() const {
unsigned result = 0;
- if (spelling[1] == '0' ||
- spelling.drop_front().getAsInteger(10, result) || result == 0)
+ if (spelling[1] == '0' || spelling.drop_front().getAsInteger(10, result) ||
+ result == 0)
return None;
return result;
}
/// literal tokens since they have no fixed spelling.
StringRef Token::getTokenSpelling(Kind kind) {
switch (kind) {
- default: llvm_unreachable("This token kind has no fixed spelling");
-#define TOK_PUNCTUATION(NAME, SPELLING) case NAME: return SPELLING;
-#define TOK_OPERATOR(NAME, SPELLING) case NAME: return SPELLING;
-#define TOK_KEYWORD(SPELLING) case kw_##SPELLING: return #SPELLING;
+ default:
+ llvm_unreachable("This token kind has no fixed spelling");
+#define TOK_PUNCTUATION(NAME, SPELLING) \
+ case NAME: \
+ return SPELLING;
+#define TOK_OPERATOR(NAME, SPELLING) \
+ case NAME: \
+ return SPELLING;
+#define TOK_KEYWORD(SPELLING) \
+ case kw_##SPELLING: \
+ return #SPELLING;
#include "TokenKinds.def"
}
}
/// Return true if this is one of the keyword token kinds (e.g. kw_if).
bool Token::isKeyword() const {
switch (kind) {
- default: return false;
-#define TOK_KEYWORD(SPELLING) case kw_##SPELLING: return true;
+ default:
+ return false;
+#define TOK_KEYWORD(SPELLING) \
+ case kw_##SPELLING: \
+ return true;
#include "TokenKinds.def"
}
}
#include "TokenKinds.def"
};
- Token(Kind kind, StringRef spelling)
- : kind(kind), spelling(spelling) {}
+ Token(Kind kind, StringRef spelling) : kind(kind), spelling(spelling) {}
// Return the bytes that make up this token.
StringRef getSpelling() const { return spelling; }
Kind getKind() const { return kind; }
bool is(Kind K) const { return kind == K; }
- bool isAny(Kind k1, Kind k2) const {
- return is(k1) || is(k2);
- }
+ bool isAny(Kind k1, Kind k2) const { return is(k1) || is(k2); }
/// Return true if this token is one of the specified kinds.
- template <typename ...T>
+ template <typename... T>
bool isAny(Kind k1, Kind k2, Kind k3, T... others) const {
if (is(k1))
return true;
bool isNot(Kind k) const { return kind != k; }
/// Return true if this token isn't one of the specified kinds.
- template <typename ...T>
- bool isNot(Kind k1, Kind k2, T... others) const {
+ template <typename... T> bool isNot(Kind k1, Kind k2, T... others) const {
return !isAny(k1, k2, others...);
}
llvm::SMLoc getEndLoc() const;
llvm::SMRange getLocRange() const;
-
/// Given a punctuation or keyword token kind, return the spelling of the
/// token as a string. Warning: This will abort on markers, identifiers and
/// literal tokens since they have no fixed spelling.
} // end namespace mlir
-#endif // MLIR_LIB_PARSER_TOKEN_H
+#endif // MLIR_LIB_PARSER_TOKEN_H