summaryrefslogtreecommitdiffstats
path: root/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/examples/toy/Ch7/mlir/MLIRGen.cpp')
-rw-r--r--mlir/examples/toy/Ch7/mlir/MLIRGen.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
index b33137a1066..590b21e53a1 100644
--- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
@@ -108,11 +108,11 @@ 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, std::pair<mlir::Value *, VarDeclExprAST *>>
+ llvm::ScopedHashTable<StringRef, std::pair<mlir::ValuePtr, VarDeclExprAST *>>
symbolTable;
using SymbolTableScopeT =
llvm::ScopedHashTableScope<StringRef,
- std::pair<mlir::Value *, VarDeclExprAST *>>;
+ std::pair<mlir::ValuePtr, VarDeclExprAST *>>;
/// A mapping for the functions that have been code generated to MLIR.
llvm::StringMap<mlir::FuncOp> functionMap;
@@ -129,7 +129,7 @@ private:
/// Declare a variable in the current scope, return success if the variable
/// wasn't declared yet.
- mlir::LogicalResult declare(VarDeclExprAST &var, mlir::Value *value) {
+ mlir::LogicalResult declare(VarDeclExprAST &var, mlir::ValuePtr value) {
if (symbolTable.count(var.getName()))
return mlir::failure();
symbolTable.insert(var.getName(), {value, &var});
@@ -301,7 +301,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
@@ -313,7 +313,7 @@ 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;
auto location = loc(binop.loc());
@@ -329,7 +329,7 @@ private:
}
// Otherwise, this is a normal binary op.
- mlir::Value *rhs = mlirGen(*binop.getRHS());
+ mlir::ValuePtr rhs = mlirGen(*binop.getRHS());
if (!rhs)
return nullptr;
@@ -349,8 +349,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()).first)
+ mlir::ValuePtr mlirGen(VariableExprAST &expr) {
+ if (auto variable = symbolTable.lookup(expr.getName()).first)
return variable;
emitError(loc(expr.loc()), "error: unknown variable '")
@@ -363,7 +363,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();
@@ -371,7 +371,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();
}
@@ -450,7 +450,7 @@ private:
}
/// Emit an array literal.
- mlir::Value *mlirGen(LiteralExprAST &lit) {
+ mlir::ValuePtr mlirGen(LiteralExprAST &lit) {
mlir::Type type = getType(lit.getDims());
mlir::DenseElementsAttr dataAttribute = getConstantAttr(lit);
@@ -462,7 +462,7 @@ private:
/// Emit a struct literal. It will be emitted as an array of
/// other literals in an Attribute attached to a `toy.struct_constant`
/// operation.
- mlir::Value *mlirGen(StructLiteralExprAST &lit) {
+ mlir::ValuePtr mlirGen(StructLiteralExprAST &lit) {
mlir::ArrayAttr dataAttr;
mlir::Type dataType;
std::tie(dataAttr, dataType) = getConstantAttr(lit);
@@ -493,14 +493,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);
@@ -534,7 +534,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();
@@ -543,12 +543,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));
@@ -574,7 +574,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()),
@@ -582,7 +582,7 @@ private:
return nullptr;
}
- mlir::Value *value = mlirGen(*init);
+ mlir::ValuePtr value = mlirGen(*init);
if (!value)
return nullptr;
OpenPOWER on IntegriCloud