Update style/clang-format (NFC).

Update to be consistent & so that future save + clang-format workflows don't introduce extra changes.

PiperOrigin-RevId: 259361174
This commit is contained in:
Jacques Pienaar 2019-07-22 10:51:40 -07:00 committed by A. Unique TensorFlower
parent 83c97a6784
commit 772930f8c6
8 changed files with 100 additions and 78 deletions

View File

@ -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_

View File

@ -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<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

View File

@ -88,7 +88,6 @@ static void populatePassManagers(llvm::legacy::PassManager &modulePM,
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);

View File

@ -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<int64_t> dividend,
int64_t divisor,
AffineExpr localExpr) {

View File

@ -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<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);
}
@ -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<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);
@ -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')

View File

@ -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

View File

@ -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<double> Token::getFloatingPointValue() const {
/// 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;
}
@ -137,10 +133,17 @@ Optional<unsigned> 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"
}
}

View File

@ -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 <typename ...T>
template <typename... T>
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 <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...);
}
@ -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