summaryrefslogtreecommitdiffstats
path: root/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/examples/toy/Ch6/mlir/MLIRGen.cpp')
-rw-r--r--mlir/examples/toy/Ch6/mlir/MLIRGen.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
index da474e809b3..902c634a954 100644
--- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
@@ -99,7 +99,7 @@ private:
/// Entering a function creates a new scope, and the function arguments are
/// added to the mapping. When the processing of a function is terminated, the
/// scope is destroyed and the mappings created in this scope are dropped.
- llvm::ScopedHashTable<StringRef, mlir::Value *> symbolTable;
+ llvm::ScopedHashTable<StringRef, mlir::ValuePtr> symbolTable;
/// Helper conversion for a Toy AST location to an MLIR location.
mlir::Location loc(Location loc) {
@@ -109,7 +109,7 @@ private:
/// Declare a variable in the current scope, return success if the variable
/// wasn't declared yet.
- mlir::LogicalResult declare(llvm::StringRef var, mlir::Value *value) {
+ mlir::LogicalResult declare(llvm::StringRef var, mlir::ValuePtr value) {
if (symbolTable.count(var))
return mlir::failure();
symbolTable.insert(var, value);
@@ -132,7 +132,8 @@ private:
/// Emit a new function and add it to the MLIR module.
mlir::FuncOp mlirGen(FunctionAST &funcAST) {
// Create a scope in the symbol table to hold variable declarations.
- ScopedHashTableScope<llvm::StringRef, mlir::Value *> var_scope(symbolTable);
+ ScopedHashTableScope<llvm::StringRef, mlir::ValuePtr> var_scope(
+ symbolTable);
// Create an MLIR function for the given prototype.
mlir::FuncOp function(mlirGen(*funcAST.getProto()));
@@ -183,7 +184,7 @@ private:
}
/// Emit a binary operation
- mlir::Value *mlirGen(BinaryExprAST &binop) {
+ mlir::ValuePtr mlirGen(BinaryExprAST &binop) {
// First emit the operations for each side of the operation before emitting
// the operation itself. For example if the expression is `a + foo(a)`
// 1) First it will visiting the LHS, which will return a reference to the
@@ -195,10 +196,10 @@ private:
// and the result value is returned. If an error occurs we get a nullptr
// and propagate.
//
- mlir::Value *lhs = mlirGen(*binop.getLHS());
+ mlir::ValuePtr lhs = mlirGen(*binop.getLHS());
if (!lhs)
return nullptr;
- mlir::Value *rhs = mlirGen(*binop.getRHS());
+ mlir::ValuePtr rhs = mlirGen(*binop.getRHS());
if (!rhs)
return nullptr;
auto location = loc(binop.loc());
@@ -219,8 +220,8 @@ private:
/// This is a reference to a variable in an expression. The variable is
/// expected to have been declared and so should have a value in the symbol
/// table, otherwise emit an error and return nullptr.
- mlir::Value *mlirGen(VariableExprAST &expr) {
- if (auto *variable = symbolTable.lookup(expr.getName()))
+ mlir::ValuePtr mlirGen(VariableExprAST &expr) {
+ if (auto variable = symbolTable.lookup(expr.getName()))
return variable;
emitError(loc(expr.loc()), "error: unknown variable '")
@@ -233,7 +234,7 @@ private:
auto location = loc(ret.loc());
// 'return' takes an optional expression, handle that case here.
- mlir::Value *expr = nullptr;
+ mlir::ValuePtr expr = nullptr;
if (ret.getExpr().hasValue()) {
if (!(expr = mlirGen(*ret.getExpr().getValue())))
return mlir::failure();
@@ -241,7 +242,7 @@ private:
// Otherwise, this return operation has zero operands.
builder.create<ReturnOp>(location, expr ? makeArrayRef(expr)
- : ArrayRef<mlir::Value *>());
+ : ArrayRef<mlir::ValuePtr>());
return mlir::success();
}
@@ -263,7 +264,7 @@ private:
/// [[1.000000e+00, 2.000000e+00, 3.000000e+00],
/// [4.000000e+00, 5.000000e+00, 6.000000e+00]]>} : () -> tensor<2x3xf64>
///
- mlir::Value *mlirGen(LiteralExprAST &lit) {
+ mlir::ValuePtr mlirGen(LiteralExprAST &lit) {
auto type = getType(lit.getDims());
// The attribute is a vector with a floating point value per element
@@ -309,14 +310,14 @@ private:
/// Emit a call expression. It emits specific operations for the `transpose`
/// builtin. Other identifiers are assumed to be user-defined functions.
- mlir::Value *mlirGen(CallExprAST &call) {
+ mlir::ValuePtr mlirGen(CallExprAST &call) {
llvm::StringRef callee = call.getCallee();
auto location = loc(call.loc());
// Codegen the operands first.
- SmallVector<mlir::Value *, 4> operands;
+ SmallVector<mlir::ValuePtr, 4> operands;
for (auto &expr : call.getArgs()) {
- auto *arg = mlirGen(*expr);
+ auto arg = mlirGen(*expr);
if (!arg)
return nullptr;
operands.push_back(arg);
@@ -342,7 +343,7 @@ private:
/// Emit a print expression. It emits specific operations for two builtins:
/// transpose(x) and print(x).
mlir::LogicalResult mlirGen(PrintExprAST &call) {
- auto *arg = mlirGen(*call.getArg());
+ auto arg = mlirGen(*call.getArg());
if (!arg)
return mlir::failure();
@@ -351,12 +352,12 @@ private:
}
/// Emit a constant for a single number (FIXME: semantic? broadcast?)
- mlir::Value *mlirGen(NumberExprAST &num) {
+ mlir::ValuePtr mlirGen(NumberExprAST &num) {
return builder.create<ConstantOp>(loc(num.loc()), num.getValue());
}
/// Dispatch codegen for the right expression subclass using RTTI.
- mlir::Value *mlirGen(ExprAST &expr) {
+ mlir::ValuePtr mlirGen(ExprAST &expr) {
switch (expr.getKind()) {
case toy::ExprAST::Expr_BinOp:
return mlirGen(cast<BinaryExprAST>(expr));
@@ -380,7 +381,7 @@ private:
/// initializer and record the value in the symbol table before returning it.
/// Future expressions will be able to reference this variable through symbol
/// table lookup.
- mlir::Value *mlirGen(VarDeclExprAST &vardecl) {
+ mlir::ValuePtr mlirGen(VarDeclExprAST &vardecl) {
auto init = vardecl.getInitVal();
if (!init) {
emitError(loc(vardecl.loc()),
@@ -388,7 +389,7 @@ private:
return nullptr;
}
- mlir::Value *value = mlirGen(*init);
+ mlir::ValuePtr value = mlirGen(*init);
if (!value)
return nullptr;
@@ -408,7 +409,7 @@ private:
/// Codegen a list of expression, return failure if one of them hit an error.
mlir::LogicalResult mlirGen(ExprASTList &blockAST) {
- ScopedHashTableScope<StringRef, mlir::Value *> var_scope(symbolTable);
+ ScopedHashTableScope<StringRef, mlir::ValuePtr> var_scope(symbolTable);
for (auto &expr : blockAST) {
// Specific handling for variable declarations, return statement, and
// print. These can only appear in block list and not in nested
OpenPOWER on IntegriCloud