From 772930f8c60854d31ceb8bb37a451f3a7ef65e9e Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Mon, 22 Jul 2019 10:51:40 -0700 Subject: [PATCH] Update style/clang-format (NFC). Update to be consistent & so that future save + clang-format workflows don't introduce extra changes. PiperOrigin-RevId: 259361174 --- .../Linalg/Linalg1/include/linalg1/Ops.h | 2 +- .../Quantizer/Configurations/FxpMathConfig.h | 11 +-- mlir/lib/ExecutionEngine/OptUtils.cpp | 1 - mlir/lib/IR/AffineExpr.cpp | 38 +++++----- mlir/lib/Parser/Lexer.cpp | 71 ++++++++++++------- mlir/lib/Parser/Lexer.h | 6 +- mlir/lib/Parser/Token.cpp | 34 +++++---- mlir/lib/Parser/Token.h | 15 ++-- 8 files changed, 100 insertions(+), 78 deletions(-) diff --git a/mlir/examples/Linalg/Linalg1/include/linalg1/Ops.h b/mlir/examples/Linalg/Linalg1/include/linalg1/Ops.h index 2e662cf60252..5d57122929ad 100644 --- a/mlir/examples/Linalg/Linalg1/include/linalg1/Ops.h +++ b/mlir/examples/Linalg/Linalg1/include/linalg1/Ops.h @@ -18,9 +18,9 @@ #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_ diff --git a/mlir/include/mlir/Quantizer/Configurations/FxpMathConfig.h b/mlir/include/mlir/Quantizer/Configurations/FxpMathConfig.h index d0efe25675c5..467512f2b77c 100644 --- a/mlir/include/mlir/Quantizer/Configurations/FxpMathConfig.h +++ b/mlir/include/mlir/Quantizer/Configurations/FxpMathConfig.h @@ -36,14 +36,15 @@ namespace quantizer { /// methods: /// - addValueIdentityOp class FxpMathTargetConfig : public TargetConfiguration { - public: +public: /// Creates an FxpMathTargetConfig instance which can be further customized. static std::unique_ptr 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 diff --git a/mlir/lib/ExecutionEngine/OptUtils.cpp b/mlir/lib/ExecutionEngine/OptUtils.cpp index 90cf3fdddd8f..7831d67c62b0 100644 --- a/mlir/lib/ExecutionEngine/OptUtils.cpp +++ b/mlir/lib/ExecutionEngine/OptUtils.cpp @@ -88,7 +88,6 @@ static void populatePassManagers(llvm::legacy::PassManager &modulePM, std::function 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); diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp index 55c3ebdacd90..10aed66a0761 100644 --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -637,12 +637,12 @@ void SimpleAffineExprFlattener::visitAddExpr(AffineBinaryOpExpr expr) { 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. @@ -723,14 +723,14 @@ void SimpleAffineExprFlattener::visitConstantExpr(AffineConstantExpr expr) { 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); @@ -790,11 +790,11 @@ void SimpleAffineExprFlattener::visitDivExpr(AffineBinaryOpExpr expr, 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 dividend, int64_t divisor, AffineExpr localExpr) { diff --git a/mlir/lib/Parser/Lexer.cpp b/mlir/lib/Parser/Lexer.cpp index 1d06a3718c82..29d093d3af53 100644 --- a/mlir/lib/Parser/Lexer.cpp +++ b/mlir/lib/Parser/Lexer.cpp @@ -98,26 +98,37 @@ Token Lexer::lexToken() { 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::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::plus, tokStart); + case '*': + return formToken(Token::star, tokStart); case '-': if (*curPtr == '>') { ++curPtr; @@ -144,10 +155,19 @@ Token Lexer::lexToken() { LLVM_FALLTHROUGH; case '%': return lexPrefixedIdentifier(tokStart); - case '"': return lexString(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 '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': return lexNumber(tokStart); } } @@ -169,7 +189,7 @@ Token Lexer::lexComment() { 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(); } @@ -193,7 +213,7 @@ Token Lexer::lexBareIdentifierOrKeyword(const char *tokStart) { ++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') { @@ -205,10 +225,9 @@ Token Lexer::lexBareIdentifierOrKeyword(const char *tokStart) { } Token::Kind kind = llvm::StringSwitch(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); } @@ -269,7 +288,7 @@ Token Lexer::lexPrefixedIdentifier(const char *tokStart) { ++curPtr; } } else if (isalpha(*curPtr) || isPunct(*curPtr)) { - do { + do { ++curPtr; } while (isalpha(*curPtr) || isdigit(*curPtr) || isPunct(*curPtr)); } else { @@ -310,14 +329,16 @@ Token Lexer::lexNumber(const char *tokStart) { ++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(curPtr[1])) || ((curPtr[1] == '-' || curPtr[1] == '+') && isdigit(static_cast(curPtr[2])))) { curPtr += 2; - while (isdigit(*curPtr)) ++curPtr; + while (isdigit(*curPtr)) + ++curPtr; } } return formToken(Token::floatliteral, tokStart); @@ -338,13 +359,13 @@ Token Lexer::lexString(const char *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') diff --git a/mlir/lib/Parser/Lexer.h b/mlir/lib/Parser/Lexer.h index e51014cff975..7b731be54967 100644 --- a/mlir/lib/Parser/Lexer.h +++ b/mlir/lib/Parser/Lexer.h @@ -22,8 +22,8 @@ #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; @@ -48,7 +48,7 @@ public: 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); @@ -73,4 +73,4 @@ private: } // end namespace mlir -#endif // MLIR_LIB_PARSER_LEXER_H +#endif // MLIR_LIB_PARSER_LEXER_H diff --git a/mlir/lib/Parser/Token.cpp b/mlir/lib/Parser/Token.cpp index 4e01f5a6a53f..f944d69b9231 100644 --- a/mlir/lib/Parser/Token.cpp +++ b/mlir/lib/Parser/Token.cpp @@ -25,17 +25,13 @@ using namespace mlir; 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. @@ -71,8 +67,8 @@ Optional Token::getFloatingPointValue() const { /// For an inttype token, return its bitwidth. Optional 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; } @@ -137,10 +133,17 @@ Optional Token::getHashIdentifierNumber() const { /// 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" } } @@ -148,8 +151,11 @@ StringRef Token::getTokenSpelling(Kind kind) { /// 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" } } diff --git a/mlir/lib/Parser/Token.h b/mlir/lib/Parser/Token.h index 4e3b8318eee3..69c3207ab45c 100644 --- a/mlir/lib/Parser/Token.h +++ b/mlir/lib/Parser/Token.h @@ -37,8 +37,7 @@ public: #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; } @@ -47,12 +46,10 @@ public: 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 + template bool isAny(Kind k1, Kind k2, Kind k3, T... others) const { if (is(k1)) return true; @@ -62,8 +59,7 @@ public: bool isNot(Kind k) const { return kind != k; } /// Return true if this token isn't one of the specified kinds. - template - bool isNot(Kind k1, Kind k2, T... others) const { + template bool isNot(Kind k1, Kind k2, T... others) const { return !isAny(k1, k2, others...); } @@ -101,7 +97,6 @@ public: 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. @@ -118,4 +113,4 @@ private: } // end namespace mlir -#endif // MLIR_LIB_PARSER_TOKEN_H +#endif // MLIR_LIB_PARSER_TOKEN_H