summaryrefslogtreecommitdiffstats
path: root/mlir/examples
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-12-22 21:59:55 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-22 22:00:23 -0800
commit35807bc4c5c9d8abc31ba0b2f955a82abf276e12 (patch)
treed083d37d993a774239081509a50e3e6c65366421 /mlir/examples
parent22954a0e408afde1d8686dffb3a3dcab107a2cd3 (diff)
downloadbcm5719-llvm-35807bc4c5c9d8abc31ba0b2f955a82abf276e12.tar.gz
bcm5719-llvm-35807bc4c5c9d8abc31ba0b2f955a82abf276e12.zip
NFC: Introduce new ValuePtr/ValueRef typedefs to simplify the transition to Value being value-typed.
This is an initial step to refactoring the representation of OpResult as proposed in: https://groups.google.com/a/tensorflow.org/g/mlir/c/XXzzKhqqF_0/m/v6bKb08WCgAJ This change will make it much simpler to incrementally transition all of the existing code to use value-typed semantics. PiperOrigin-RevId: 286844725
Diffstat (limited to 'mlir/examples')
-rw-r--r--mlir/examples/toy/Ch2/include/toy/Ops.td8
-rw-r--r--mlir/examples/toy/Ch2/mlir/Dialect.cpp9
-rw-r--r--mlir/examples/toy/Ch2/mlir/MLIRGen.cpp41
-rw-r--r--mlir/examples/toy/Ch3/include/toy/Ops.td8
-rw-r--r--mlir/examples/toy/Ch3/mlir/Dialect.cpp9
-rw-r--r--mlir/examples/toy/Ch3/mlir/MLIRGen.cpp41
-rw-r--r--mlir/examples/toy/Ch3/mlir/ToyCombine.cpp2
-rw-r--r--mlir/examples/toy/Ch4/include/toy/Ops.td8
-rw-r--r--mlir/examples/toy/Ch4/mlir/Dialect.cpp13
-rw-r--r--mlir/examples/toy/Ch4/mlir/MLIRGen.cpp41
-rw-r--r--mlir/examples/toy/Ch4/mlir/ToyCombine.cpp2
-rw-r--r--mlir/examples/toy/Ch5/include/toy/Ops.td8
-rw-r--r--mlir/examples/toy/Ch5/mlir/Dialect.cpp13
-rw-r--r--mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp36
-rw-r--r--mlir/examples/toy/Ch5/mlir/MLIRGen.cpp41
-rw-r--r--mlir/examples/toy/Ch5/mlir/ToyCombine.cpp2
-rw-r--r--mlir/examples/toy/Ch6/include/toy/Ops.td8
-rw-r--r--mlir/examples/toy/Ch6/mlir/Dialect.cpp13
-rw-r--r--mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp36
-rw-r--r--mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp24
-rw-r--r--mlir/examples/toy/Ch6/mlir/MLIRGen.cpp41
-rw-r--r--mlir/examples/toy/Ch6/mlir/ToyCombine.cpp2
-rw-r--r--mlir/examples/toy/Ch7/include/toy/Ops.td10
-rw-r--r--mlir/examples/toy/Ch7/mlir/Dialect.cpp15
-rw-r--r--mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp36
-rw-r--r--mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp24
-rw-r--r--mlir/examples/toy/Ch7/mlir/MLIRGen.cpp40
-rw-r--r--mlir/examples/toy/Ch7/mlir/ToyCombine.cpp2
28 files changed, 272 insertions, 261 deletions
diff --git a/mlir/examples/toy/Ch2/include/toy/Ops.td b/mlir/examples/toy/Ch2/include/toy/Ops.td
index f7c011915ff..dd88b097ab1 100644
--- a/mlir/examples/toy/Ch2/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch2/include/toy/Ops.td
@@ -98,7 +98,7 @@ def AddOp : Toy_Op<"add"> {
// Allow building an AddOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -129,7 +129,7 @@ def GenericCallOp : Toy_Op<"generic_call"> {
// Add custom build methods for the generic call operation.
let builders = [
OpBuilder<"Builder *builder, OperationState &state, "
- "StringRef callee, ArrayRef<Value *> arguments">
+ "StringRef callee, ArrayRef<ValuePtr> arguments">
];
}
@@ -145,7 +145,7 @@ def MulOp : Toy_Op<"mul"> {
// Allow building a MulOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -219,7 +219,7 @@ def TransposeOp : Toy_Op<"transpose"> {
// Allow building a TransposeOp with from the input operand.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
];
// Invoke a static verify method to verify this transpose operation.
diff --git a/mlir/examples/toy/Ch2/mlir/Dialect.cpp b/mlir/examples/toy/Ch2/mlir/Dialect.cpp
index 86f648dbe0e..4a3232dabe3 100644
--- a/mlir/examples/toy/Ch2/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch2/mlir/Dialect.cpp
@@ -94,7 +94,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
// AddOp
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -103,7 +103,8 @@ void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
// GenericCallOp
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
- StringRef callee, ArrayRef<mlir::Value *> arguments) {
+ StringRef callee,
+ ArrayRef<mlir::ValuePtr> arguments) {
// Generic call always returns an unranked Tensor initially.
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(arguments);
@@ -114,7 +115,7 @@ void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
// MulOp
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -161,7 +162,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
// TransposeOp
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *value) {
+ mlir::ValuePtr value) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(value);
}
diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
index da474e809b3..902c634a954 100644
--- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch2/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
diff --git a/mlir/examples/toy/Ch3/include/toy/Ops.td b/mlir/examples/toy/Ch3/include/toy/Ops.td
index 921e503e416..6c400169da2 100644
--- a/mlir/examples/toy/Ch3/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch3/include/toy/Ops.td
@@ -98,7 +98,7 @@ def AddOp : Toy_Op<"add", [NoSideEffect]> {
// Allow building an AddOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -129,7 +129,7 @@ def GenericCallOp : Toy_Op<"generic_call"> {
// Add custom build methods for the generic call operation.
let builders = [
OpBuilder<"Builder *builder, OperationState &state, "
- "StringRef callee, ArrayRef<Value *> arguments">
+ "StringRef callee, ArrayRef<ValuePtr> arguments">
];
}
@@ -145,7 +145,7 @@ def MulOp : Toy_Op<"mul", [NoSideEffect]> {
// Allow building a MulOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -225,7 +225,7 @@ def TransposeOp : Toy_Op<"transpose", [NoSideEffect]> {
// Allow building a TransposeOp with from the input operand.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
];
// Invoke a static verify method to verify this transpose operation.
diff --git a/mlir/examples/toy/Ch3/mlir/Dialect.cpp b/mlir/examples/toy/Ch3/mlir/Dialect.cpp
index 86f648dbe0e..4a3232dabe3 100644
--- a/mlir/examples/toy/Ch3/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch3/mlir/Dialect.cpp
@@ -94,7 +94,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
// AddOp
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -103,7 +103,8 @@ void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
// GenericCallOp
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
- StringRef callee, ArrayRef<mlir::Value *> arguments) {
+ StringRef callee,
+ ArrayRef<mlir::ValuePtr> arguments) {
// Generic call always returns an unranked Tensor initially.
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(arguments);
@@ -114,7 +115,7 @@ void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
// MulOp
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -161,7 +162,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
// TransposeOp
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *value) {
+ mlir::ValuePtr value) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(value);
}
diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
index da474e809b3..902c634a954 100644
--- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch3/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
diff --git a/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp
index 1b9dcd20291..42a10397513 100644
--- a/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp
+++ b/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp
@@ -48,7 +48,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern<TransposeOp> {
matchAndRewrite(TransposeOp op,
mlir::PatternRewriter &rewriter) const override {
// Look through the input of the current transpose.
- mlir::Value *transposeInput = op.getOperand();
+ mlir::ValuePtr transposeInput = op.getOperand();
TransposeOp transposeInputOp =
llvm::dyn_cast_or_null<TransposeOp>(transposeInput->getDefiningOp());
diff --git a/mlir/examples/toy/Ch4/include/toy/Ops.td b/mlir/examples/toy/Ch4/include/toy/Ops.td
index aec1cc3cfc9..ef5b30a862b 100644
--- a/mlir/examples/toy/Ch4/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch4/include/toy/Ops.td
@@ -100,7 +100,7 @@ def AddOp : Toy_Op<"add",
// Allow building an AddOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -151,7 +151,7 @@ def GenericCallOp : Toy_Op<"generic_call",
// Add custom build methods for the generic call operation.
let builders = [
OpBuilder<"Builder *builder, OperationState &state, "
- "StringRef callee, ArrayRef<Value *> arguments">
+ "StringRef callee, ArrayRef<ValuePtr> arguments">
];
}
@@ -168,7 +168,7 @@ def MulOp : Toy_Op<"mul",
// Allow building a MulOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -245,7 +245,7 @@ def TransposeOp : Toy_Op<"transpose",
// Allow building a TransposeOp with from the input operand.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
];
// Invoke a static verify method to verify this transpose operation.
diff --git a/mlir/examples/toy/Ch4/mlir/Dialect.cpp b/mlir/examples/toy/Ch4/mlir/Dialect.cpp
index 7003cbdcc81..8be1094cf15 100644
--- a/mlir/examples/toy/Ch4/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch4/mlir/Dialect.cpp
@@ -55,7 +55,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// Handle the given inlined terminator(toy.return) by replacing it with a new
/// operation as necessary.
void handleTerminator(Operation *op,
- ArrayRef<Value *> valuesToRepl) const final {
+ ArrayRef<ValuePtr> valuesToRepl) const final {
// Only "toy.return" needs to be handled here.
auto returnOp = cast<ReturnOp>(op);
@@ -70,7 +70,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// operation that takes 'input' as the only operand, and produces a single
/// result of 'resultType'. If a conversion can not be generated, nullptr
/// should be returned.
- Operation *materializeCallConversion(OpBuilder &builder, Value *input,
+ Operation *materializeCallConversion(OpBuilder &builder, ValuePtr input,
Type resultType,
Location conversionLoc) const final {
return builder.create<CastOp>(conversionLoc, resultType, input);
@@ -144,7 +144,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
// AddOp
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -164,7 +164,8 @@ void CastOp::inferShapes() { getResult()->setType(getOperand()->getType()); }
// GenericCallOp
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
- StringRef callee, ArrayRef<mlir::Value *> arguments) {
+ StringRef callee,
+ ArrayRef<mlir::ValuePtr> arguments) {
// Generic call always returns an unranked Tensor initially.
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(arguments);
@@ -185,7 +186,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
// MulOp
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -236,7 +237,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
// TransposeOp
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *value) {
+ mlir::ValuePtr value) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(value);
}
diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
index da474e809b3..902c634a954 100644
--- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch4/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
diff --git a/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp
index 47e1abc6c74..604e9fa6c83 100644
--- a/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp
+++ b/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp
@@ -53,7 +53,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern<TransposeOp> {
matchAndRewrite(TransposeOp op,
mlir::PatternRewriter &rewriter) const override {
// Look through the input of the current transpose.
- mlir::Value *transposeInput = op.getOperand();
+ mlir::ValuePtr transposeInput = op.getOperand();
TransposeOp transposeInputOp =
llvm::dyn_cast_or_null<TransposeOp>(transposeInput->getDefiningOp());
diff --git a/mlir/examples/toy/Ch5/include/toy/Ops.td b/mlir/examples/toy/Ch5/include/toy/Ops.td
index e40b661fd34..b3bda1d647b 100644
--- a/mlir/examples/toy/Ch5/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch5/include/toy/Ops.td
@@ -100,7 +100,7 @@ def AddOp : Toy_Op<"add",
// Allow building an AddOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -151,7 +151,7 @@ def GenericCallOp : Toy_Op<"generic_call",
// Add custom build methods for the generic call operation.
let builders = [
OpBuilder<"Builder *builder, OperationState &state, "
- "StringRef callee, ArrayRef<Value *> arguments">
+ "StringRef callee, ArrayRef<ValuePtr> arguments">
];
}
@@ -168,7 +168,7 @@ def MulOp : Toy_Op<"mul",
// Allow building a MulOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -246,7 +246,7 @@ def TransposeOp : Toy_Op<"transpose",
// Allow building a TransposeOp with from the input operand.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
];
// Invoke a static verify method to verify this transpose operation.
diff --git a/mlir/examples/toy/Ch5/mlir/Dialect.cpp b/mlir/examples/toy/Ch5/mlir/Dialect.cpp
index 7003cbdcc81..8be1094cf15 100644
--- a/mlir/examples/toy/Ch5/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch5/mlir/Dialect.cpp
@@ -55,7 +55,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// Handle the given inlined terminator(toy.return) by replacing it with a new
/// operation as necessary.
void handleTerminator(Operation *op,
- ArrayRef<Value *> valuesToRepl) const final {
+ ArrayRef<ValuePtr> valuesToRepl) const final {
// Only "toy.return" needs to be handled here.
auto returnOp = cast<ReturnOp>(op);
@@ -70,7 +70,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// operation that takes 'input' as the only operand, and produces a single
/// result of 'resultType'. If a conversion can not be generated, nullptr
/// should be returned.
- Operation *materializeCallConversion(OpBuilder &builder, Value *input,
+ Operation *materializeCallConversion(OpBuilder &builder, ValuePtr input,
Type resultType,
Location conversionLoc) const final {
return builder.create<CastOp>(conversionLoc, resultType, input);
@@ -144,7 +144,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
// AddOp
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -164,7 +164,8 @@ void CastOp::inferShapes() { getResult()->setType(getOperand()->getType()); }
// GenericCallOp
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
- StringRef callee, ArrayRef<mlir::Value *> arguments) {
+ StringRef callee,
+ ArrayRef<mlir::ValuePtr> arguments) {
// Generic call always returns an unranked Tensor initially.
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(arguments);
@@ -185,7 +186,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
// MulOp
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -236,7 +237,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
// TransposeOp
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *value) {
+ mlir::ValuePtr value) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(value);
}
diff --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
index 4ab8c5b501c..3fa761c7404 100644
--- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
@@ -43,8 +43,8 @@ static MemRefType convertTensorToMemRef(TensorType type) {
}
/// Insert an allocation and deallocation for the given MemRefType.
-static Value *insertAllocAndDealloc(MemRefType type, Location loc,
- PatternRewriter &rewriter) {
+static ValuePtr insertAllocAndDealloc(MemRefType type, Location loc,
+ PatternRewriter &rewriter) {
auto alloc = rewriter.create<AllocOp>(loc, type);
// Make sure to allocate at the beginning of the block.
@@ -63,11 +63,11 @@ static Value *insertAllocAndDealloc(MemRefType type, Location loc,
/// to the operands of the input operation, and the set of loop induction
/// variables for the iteration. It returns a value to store at the current
/// index of the iteration.
-using LoopIterationFn = function_ref<Value *(PatternRewriter &rewriter,
- ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs)>;
+using LoopIterationFn = function_ref<ValuePtr(PatternRewriter &rewriter,
+ ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs)>;
-static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
+static void lowerOpToLoops(Operation *op, ArrayRef<ValuePtr> operands,
PatternRewriter &rewriter,
LoopIterationFn processIteration) {
auto tensorType = (*op->result_type_begin()).cast<TensorType>();
@@ -78,7 +78,7 @@ static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
auto alloc = insertAllocAndDealloc(memRefType, loc, rewriter);
// Create an empty affine loop for each of the dimensions within the shape.
- SmallVector<Value *, 4> loopIvs;
+ SmallVector<ValuePtr, 4> loopIvs;
for (auto dim : tensorType.getShape()) {
auto loop = rewriter.create<AffineForOp>(loc, /*lb=*/0, dim, /*step=*/1);
loop.getBody()->clear();
@@ -94,7 +94,7 @@ static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
// Generate a call to the processing function with the rewriter, the memref
// operands, and the loop induction variables. This function will return the
// value to store at the current index.
- Value *valueToStore = processIteration(rewriter, operands, loopIvs);
+ ValuePtr valueToStore = processIteration(rewriter, operands, loopIvs);
rewriter.create<AffineStoreOp>(loc, valueToStore, alloc,
llvm::makeArrayRef(loopIvs));
@@ -113,13 +113,13 @@ struct BinaryOpLowering : public ConversionPattern {
: ConversionPattern(BinaryOp::getOperationName(), 1, ctx) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const final {
auto loc = op->getLoc();
lowerOpToLoops(
op, operands, rewriter,
- [loc](PatternRewriter &rewriter, ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs) {
+ [loc](PatternRewriter &rewriter, ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs) {
// Generate an adaptor for the remapped operands of the BinaryOp. This
// allows for using the nice named accessors that are generated by the
// ODS.
@@ -163,7 +163,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {
// Create these constants up-front to avoid large amounts of redundant
// operations.
auto valueShape = memRefType.getShape();
- SmallVector<Value *, 8> constantIndices;
+ SmallVector<ValuePtr, 8> constantIndices;
for (auto i : llvm::seq<int64_t>(
0, *std::max_element(valueShape.begin(), valueShape.end())))
constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
@@ -172,7 +172,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {
// will need to generate a store for each of the elements. The following
// functor recursively walks the dimensions of the constant shape,
// generating a store when the recursion hits the base case.
- SmallVector<Value *, 2> indices;
+ SmallVector<ValuePtr, 2> indices;
auto valueIt = constantValue.getValues<FloatAttr>().begin();
std::function<void(uint64_t)> storeElements = [&](uint64_t dimension) {
// The last dimension is the base case of the recursion, at this point
@@ -231,22 +231,22 @@ struct TransposeOpLowering : public ConversionPattern {
: ConversionPattern(toy::TransposeOp::getOperationName(), 1, ctx) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const final {
auto loc = op->getLoc();
lowerOpToLoops(
op, operands, rewriter,
- [loc](PatternRewriter &rewriter, ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs) {
+ [loc](PatternRewriter &rewriter, ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs) {
// Generate an adaptor for the remapped operands of the TransposeOp.
// This allows for using the nice named accessors that are generated
// by the ODS.
toy::TransposeOpOperandAdaptor transposeAdaptor(memRefOperands);
- Value *input = transposeAdaptor.input();
+ ValuePtr input = transposeAdaptor.input();
// Transpose the elements by generating a load from the reverse
// indices.
- SmallVector<Value *, 2> reverseIvs(llvm::reverse(loopIvs));
+ SmallVector<ValuePtr, 2> reverseIvs(llvm::reverse(loopIvs));
return rewriter.create<AffineLoadOp>(loc, input, reverseIvs);
});
return matchSuccess();
diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
index da474e809b3..902c634a954 100644
--- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch5/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
diff --git a/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp
index 47e1abc6c74..604e9fa6c83 100644
--- a/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp
+++ b/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp
@@ -53,7 +53,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern<TransposeOp> {
matchAndRewrite(TransposeOp op,
mlir::PatternRewriter &rewriter) const override {
// Look through the input of the current transpose.
- mlir::Value *transposeInput = op.getOperand();
+ mlir::ValuePtr transposeInput = op.getOperand();
TransposeOp transposeInputOp =
llvm::dyn_cast_or_null<TransposeOp>(transposeInput->getDefiningOp());
diff --git a/mlir/examples/toy/Ch6/include/toy/Ops.td b/mlir/examples/toy/Ch6/include/toy/Ops.td
index e40b661fd34..b3bda1d647b 100644
--- a/mlir/examples/toy/Ch6/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch6/include/toy/Ops.td
@@ -100,7 +100,7 @@ def AddOp : Toy_Op<"add",
// Allow building an AddOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -151,7 +151,7 @@ def GenericCallOp : Toy_Op<"generic_call",
// Add custom build methods for the generic call operation.
let builders = [
OpBuilder<"Builder *builder, OperationState &state, "
- "StringRef callee, ArrayRef<Value *> arguments">
+ "StringRef callee, ArrayRef<ValuePtr> arguments">
];
}
@@ -168,7 +168,7 @@ def MulOp : Toy_Op<"mul",
// Allow building a MulOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -246,7 +246,7 @@ def TransposeOp : Toy_Op<"transpose",
// Allow building a TransposeOp with from the input operand.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
];
// Invoke a static verify method to verify this transpose operation.
diff --git a/mlir/examples/toy/Ch6/mlir/Dialect.cpp b/mlir/examples/toy/Ch6/mlir/Dialect.cpp
index 7003cbdcc81..8be1094cf15 100644
--- a/mlir/examples/toy/Ch6/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch6/mlir/Dialect.cpp
@@ -55,7 +55,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// Handle the given inlined terminator(toy.return) by replacing it with a new
/// operation as necessary.
void handleTerminator(Operation *op,
- ArrayRef<Value *> valuesToRepl) const final {
+ ArrayRef<ValuePtr> valuesToRepl) const final {
// Only "toy.return" needs to be handled here.
auto returnOp = cast<ReturnOp>(op);
@@ -70,7 +70,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// operation that takes 'input' as the only operand, and produces a single
/// result of 'resultType'. If a conversion can not be generated, nullptr
/// should be returned.
- Operation *materializeCallConversion(OpBuilder &builder, Value *input,
+ Operation *materializeCallConversion(OpBuilder &builder, ValuePtr input,
Type resultType,
Location conversionLoc) const final {
return builder.create<CastOp>(conversionLoc, resultType, input);
@@ -144,7 +144,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
// AddOp
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -164,7 +164,8 @@ void CastOp::inferShapes() { getResult()->setType(getOperand()->getType()); }
// GenericCallOp
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
- StringRef callee, ArrayRef<mlir::Value *> arguments) {
+ StringRef callee,
+ ArrayRef<mlir::ValuePtr> arguments) {
// Generic call always returns an unranked Tensor initially.
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(arguments);
@@ -185,7 +186,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
// MulOp
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -236,7 +237,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
// TransposeOp
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *value) {
+ mlir::ValuePtr value) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(value);
}
diff --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
index 4ab8c5b501c..3fa761c7404 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
@@ -43,8 +43,8 @@ static MemRefType convertTensorToMemRef(TensorType type) {
}
/// Insert an allocation and deallocation for the given MemRefType.
-static Value *insertAllocAndDealloc(MemRefType type, Location loc,
- PatternRewriter &rewriter) {
+static ValuePtr insertAllocAndDealloc(MemRefType type, Location loc,
+ PatternRewriter &rewriter) {
auto alloc = rewriter.create<AllocOp>(loc, type);
// Make sure to allocate at the beginning of the block.
@@ -63,11 +63,11 @@ static Value *insertAllocAndDealloc(MemRefType type, Location loc,
/// to the operands of the input operation, and the set of loop induction
/// variables for the iteration. It returns a value to store at the current
/// index of the iteration.
-using LoopIterationFn = function_ref<Value *(PatternRewriter &rewriter,
- ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs)>;
+using LoopIterationFn = function_ref<ValuePtr(PatternRewriter &rewriter,
+ ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs)>;
-static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
+static void lowerOpToLoops(Operation *op, ArrayRef<ValuePtr> operands,
PatternRewriter &rewriter,
LoopIterationFn processIteration) {
auto tensorType = (*op->result_type_begin()).cast<TensorType>();
@@ -78,7 +78,7 @@ static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
auto alloc = insertAllocAndDealloc(memRefType, loc, rewriter);
// Create an empty affine loop for each of the dimensions within the shape.
- SmallVector<Value *, 4> loopIvs;
+ SmallVector<ValuePtr, 4> loopIvs;
for (auto dim : tensorType.getShape()) {
auto loop = rewriter.create<AffineForOp>(loc, /*lb=*/0, dim, /*step=*/1);
loop.getBody()->clear();
@@ -94,7 +94,7 @@ static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
// Generate a call to the processing function with the rewriter, the memref
// operands, and the loop induction variables. This function will return the
// value to store at the current index.
- Value *valueToStore = processIteration(rewriter, operands, loopIvs);
+ ValuePtr valueToStore = processIteration(rewriter, operands, loopIvs);
rewriter.create<AffineStoreOp>(loc, valueToStore, alloc,
llvm::makeArrayRef(loopIvs));
@@ -113,13 +113,13 @@ struct BinaryOpLowering : public ConversionPattern {
: ConversionPattern(BinaryOp::getOperationName(), 1, ctx) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const final {
auto loc = op->getLoc();
lowerOpToLoops(
op, operands, rewriter,
- [loc](PatternRewriter &rewriter, ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs) {
+ [loc](PatternRewriter &rewriter, ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs) {
// Generate an adaptor for the remapped operands of the BinaryOp. This
// allows for using the nice named accessors that are generated by the
// ODS.
@@ -163,7 +163,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {
// Create these constants up-front to avoid large amounts of redundant
// operations.
auto valueShape = memRefType.getShape();
- SmallVector<Value *, 8> constantIndices;
+ SmallVector<ValuePtr, 8> constantIndices;
for (auto i : llvm::seq<int64_t>(
0, *std::max_element(valueShape.begin(), valueShape.end())))
constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
@@ -172,7 +172,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {
// will need to generate a store for each of the elements. The following
// functor recursively walks the dimensions of the constant shape,
// generating a store when the recursion hits the base case.
- SmallVector<Value *, 2> indices;
+ SmallVector<ValuePtr, 2> indices;
auto valueIt = constantValue.getValues<FloatAttr>().begin();
std::function<void(uint64_t)> storeElements = [&](uint64_t dimension) {
// The last dimension is the base case of the recursion, at this point
@@ -231,22 +231,22 @@ struct TransposeOpLowering : public ConversionPattern {
: ConversionPattern(toy::TransposeOp::getOperationName(), 1, ctx) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const final {
auto loc = op->getLoc();
lowerOpToLoops(
op, operands, rewriter,
- [loc](PatternRewriter &rewriter, ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs) {
+ [loc](PatternRewriter &rewriter, ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs) {
// Generate an adaptor for the remapped operands of the TransposeOp.
// This allows for using the nice named accessors that are generated
// by the ODS.
toy::TransposeOpOperandAdaptor transposeAdaptor(memRefOperands);
- Value *input = transposeAdaptor.input();
+ ValuePtr input = transposeAdaptor.input();
// Transpose the elements by generating a load from the reverse
// indices.
- SmallVector<Value *, 2> reverseIvs(llvm::reverse(loopIvs));
+ SmallVector<ValuePtr, 2> reverseIvs(llvm::reverse(loopIvs));
return rewriter.create<AffineLoadOp>(loc, input, reverseIvs);
});
return matchSuccess();
diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
index d35cc5c576a..c3180b4a92d 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
@@ -51,7 +51,7 @@ public:
: ConversionPattern(toy::PrintOp::getOperationName(), 1, context) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const override {
auto memRefType = (*op->operand_type_begin()).cast<MemRefType>();
auto memRefShape = memRefType.getShape();
@@ -64,14 +64,14 @@ public:
// Get a symbol reference to the printf function, inserting it if necessary.
auto printfRef = getOrInsertPrintf(rewriter, parentModule, llvmDialect);
- Value *formatSpecifierCst = getOrCreateGlobalString(
+ ValuePtr formatSpecifierCst = getOrCreateGlobalString(
loc, rewriter, "frmt_spec", StringRef("%f \0", 4), parentModule,
llvmDialect);
- Value *newLineCst = getOrCreateGlobalString(
+ ValuePtr newLineCst = getOrCreateGlobalString(
loc, rewriter, "nl", StringRef("\n\0", 2), parentModule, llvmDialect);
// Create a loop for each of the dimensions within the shape.
- SmallVector<Value *, 4> loopIvs;
+ SmallVector<ValuePtr, 4> loopIvs;
for (unsigned i = 0, e = memRefShape.size(); i != e; ++i) {
auto lowerBound = rewriter.create<ConstantIndexOp>(loc, 0);
auto upperBound = rewriter.create<ConstantIndexOp>(loc, memRefShape[i]);
@@ -97,7 +97,7 @@ public:
auto elementLoad = rewriter.create<LoadOp>(loc, printOp.input(), loopIvs);
rewriter.create<CallOp>(
loc, printfRef, rewriter.getIntegerType(32),
- ArrayRef<Value *>({formatSpecifierCst, elementLoad}));
+ ArrayRef<ValuePtr>({formatSpecifierCst, elementLoad}));
// Notify the rewriter that this operation has been removed.
rewriter.eraseOp(op);
@@ -130,10 +130,10 @@ private:
/// Return a value representing an access into a global string with the given
/// name, creating the string if necessary.
- static Value *getOrCreateGlobalString(Location loc, OpBuilder &builder,
- StringRef name, StringRef value,
- ModuleOp module,
- LLVM::LLVMDialect *llvmDialect) {
+ static ValuePtr getOrCreateGlobalString(Location loc, OpBuilder &builder,
+ StringRef name, StringRef value,
+ ModuleOp module,
+ LLVM::LLVMDialect *llvmDialect) {
// Create the global at the entry of the module.
LLVM::GlobalOp global;
if (!(global = module.lookupSymbol<LLVM::GlobalOp>(name))) {
@@ -147,13 +147,13 @@ private:
}
// Get the pointer to the first character in the global string.
- Value *globalPtr = builder.create<LLVM::AddressOfOp>(loc, global);
- Value *cst0 = builder.create<LLVM::ConstantOp>(
+ ValuePtr globalPtr = builder.create<LLVM::AddressOfOp>(loc, global);
+ ValuePtr cst0 = builder.create<LLVM::ConstantOp>(
loc, LLVM::LLVMType::getInt64Ty(llvmDialect),
builder.getIntegerAttr(builder.getIndexType(), 0));
return builder.create<LLVM::GEPOp>(
loc, LLVM::LLVMType::getInt8PtrTy(llvmDialect), globalPtr,
- ArrayRef<Value *>({cst0, cst0}));
+ ArrayRef<ValuePtr>({cst0, cst0}));
}
};
} // end anonymous namespace
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
diff --git a/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp
index 47e1abc6c74..604e9fa6c83 100644
--- a/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp
+++ b/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp
@@ -53,7 +53,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern<TransposeOp> {
matchAndRewrite(TransposeOp op,
mlir::PatternRewriter &rewriter) const override {
// Look through the input of the current transpose.
- mlir::Value *transposeInput = op.getOperand();
+ mlir::ValuePtr transposeInput = op.getOperand();
TransposeOp transposeInputOp =
llvm::dyn_cast_or_null<TransposeOp>(transposeInput->getDefiningOp());
diff --git a/mlir/examples/toy/Ch7/include/toy/Ops.td b/mlir/examples/toy/Ch7/include/toy/Ops.td
index 0d48f74e9fe..94f1bcf3e82 100644
--- a/mlir/examples/toy/Ch7/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch7/include/toy/Ops.td
@@ -112,7 +112,7 @@ def AddOp : Toy_Op<"add",
// Allow building an AddOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -164,7 +164,7 @@ def GenericCallOp : Toy_Op<"generic_call",
// Add custom build methods for the generic call operation.
let builders = [
OpBuilder<"Builder *builder, OperationState &state, "
- "StringRef callee, ArrayRef<Value *> arguments">
+ "StringRef callee, ArrayRef<ValuePtr> arguments">
];
}
@@ -181,7 +181,7 @@ def MulOp : Toy_Op<"mul",
// Allow building a MulOp with from the two input operands.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *lhs, Value *rhs">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
];
}
@@ -260,7 +260,7 @@ def StructAccessOp : Toy_Op<"struct_access", [NoSideEffect]> {
// Allow building a StructAccessOp with just a struct value and an index.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input, size_t index">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input, size_t index">
];
let verifier = [{ return ::verify(*this); }];
@@ -299,7 +299,7 @@ def TransposeOp : Toy_Op<"transpose",
// Allow building a TransposeOp with from the input operand.
let builders = [
- OpBuilder<"Builder *b, OperationState &state, Value *input">
+ OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
];
// Invoke a static verify method to verify this transpose operation.
diff --git a/mlir/examples/toy/Ch7/mlir/Dialect.cpp b/mlir/examples/toy/Ch7/mlir/Dialect.cpp
index 2beaa870a89..0ce896db5de 100644
--- a/mlir/examples/toy/Ch7/mlir/Dialect.cpp
+++ b/mlir/examples/toy/Ch7/mlir/Dialect.cpp
@@ -56,7 +56,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// Handle the given inlined terminator(toy.return) by replacing it with a new
/// operation as necessary.
void handleTerminator(Operation *op,
- ArrayRef<Value *> valuesToRepl) const final {
+ ArrayRef<ValuePtr> valuesToRepl) const final {
// Only "toy.return" needs to be handled here.
auto returnOp = cast<ReturnOp>(op);
@@ -71,7 +71,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface {
/// operation that takes 'input' as the only operand, and produces a single
/// result of 'resultType'. If a conversion can not be generated, nullptr
/// should be returned.
- Operation *materializeCallConversion(OpBuilder &builder, Value *input,
+ Operation *materializeCallConversion(OpBuilder &builder, ValuePtr input,
Type resultType,
Location conversionLoc) const final {
return builder.create<CastOp>(conversionLoc, resultType, input);
@@ -195,7 +195,7 @@ void ConstantOp::inferShapes() { getResult()->setType(value().getType()); }
// AddOp
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -215,7 +215,8 @@ void CastOp::inferShapes() { getResult()->setType(getOperand()->getType()); }
// GenericCallOp
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
- StringRef callee, ArrayRef<mlir::Value *> arguments) {
+ StringRef callee,
+ ArrayRef<mlir::ValuePtr> arguments) {
// Generic call always returns an unranked Tensor initially.
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(arguments);
@@ -236,7 +237,7 @@ Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
// MulOp
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *lhs, mlir::Value *rhs) {
+ mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands({lhs, rhs});
}
@@ -287,7 +288,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
// StructAccessOp
void StructAccessOp::build(mlir::Builder *b, mlir::OperationState &state,
- mlir::Value *input, size_t index) {
+ mlir::ValuePtr input, size_t index) {
// Extract the result type from the input type.
StructType structTy = input->getType().cast<StructType>();
assert(index < structTy.getNumElementTypes());
@@ -314,7 +315,7 @@ static mlir::LogicalResult verify(StructAccessOp op) {
// TransposeOp
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
- mlir::Value *value) {
+ mlir::ValuePtr value) {
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
state.addOperands(value);
}
diff --git a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
index 4ab8c5b501c..3fa761c7404 100644
--- a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
@@ -43,8 +43,8 @@ static MemRefType convertTensorToMemRef(TensorType type) {
}
/// Insert an allocation and deallocation for the given MemRefType.
-static Value *insertAllocAndDealloc(MemRefType type, Location loc,
- PatternRewriter &rewriter) {
+static ValuePtr insertAllocAndDealloc(MemRefType type, Location loc,
+ PatternRewriter &rewriter) {
auto alloc = rewriter.create<AllocOp>(loc, type);
// Make sure to allocate at the beginning of the block.
@@ -63,11 +63,11 @@ static Value *insertAllocAndDealloc(MemRefType type, Location loc,
/// to the operands of the input operation, and the set of loop induction
/// variables for the iteration. It returns a value to store at the current
/// index of the iteration.
-using LoopIterationFn = function_ref<Value *(PatternRewriter &rewriter,
- ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs)>;
+using LoopIterationFn = function_ref<ValuePtr(PatternRewriter &rewriter,
+ ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs)>;
-static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
+static void lowerOpToLoops(Operation *op, ArrayRef<ValuePtr> operands,
PatternRewriter &rewriter,
LoopIterationFn processIteration) {
auto tensorType = (*op->result_type_begin()).cast<TensorType>();
@@ -78,7 +78,7 @@ static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
auto alloc = insertAllocAndDealloc(memRefType, loc, rewriter);
// Create an empty affine loop for each of the dimensions within the shape.
- SmallVector<Value *, 4> loopIvs;
+ SmallVector<ValuePtr, 4> loopIvs;
for (auto dim : tensorType.getShape()) {
auto loop = rewriter.create<AffineForOp>(loc, /*lb=*/0, dim, /*step=*/1);
loop.getBody()->clear();
@@ -94,7 +94,7 @@ static void lowerOpToLoops(Operation *op, ArrayRef<Value *> operands,
// Generate a call to the processing function with the rewriter, the memref
// operands, and the loop induction variables. This function will return the
// value to store at the current index.
- Value *valueToStore = processIteration(rewriter, operands, loopIvs);
+ ValuePtr valueToStore = processIteration(rewriter, operands, loopIvs);
rewriter.create<AffineStoreOp>(loc, valueToStore, alloc,
llvm::makeArrayRef(loopIvs));
@@ -113,13 +113,13 @@ struct BinaryOpLowering : public ConversionPattern {
: ConversionPattern(BinaryOp::getOperationName(), 1, ctx) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const final {
auto loc = op->getLoc();
lowerOpToLoops(
op, operands, rewriter,
- [loc](PatternRewriter &rewriter, ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs) {
+ [loc](PatternRewriter &rewriter, ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs) {
// Generate an adaptor for the remapped operands of the BinaryOp. This
// allows for using the nice named accessors that are generated by the
// ODS.
@@ -163,7 +163,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {
// Create these constants up-front to avoid large amounts of redundant
// operations.
auto valueShape = memRefType.getShape();
- SmallVector<Value *, 8> constantIndices;
+ SmallVector<ValuePtr, 8> constantIndices;
for (auto i : llvm::seq<int64_t>(
0, *std::max_element(valueShape.begin(), valueShape.end())))
constantIndices.push_back(rewriter.create<ConstantIndexOp>(loc, i));
@@ -172,7 +172,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {
// will need to generate a store for each of the elements. The following
// functor recursively walks the dimensions of the constant shape,
// generating a store when the recursion hits the base case.
- SmallVector<Value *, 2> indices;
+ SmallVector<ValuePtr, 2> indices;
auto valueIt = constantValue.getValues<FloatAttr>().begin();
std::function<void(uint64_t)> storeElements = [&](uint64_t dimension) {
// The last dimension is the base case of the recursion, at this point
@@ -231,22 +231,22 @@ struct TransposeOpLowering : public ConversionPattern {
: ConversionPattern(toy::TransposeOp::getOperationName(), 1, ctx) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const final {
auto loc = op->getLoc();
lowerOpToLoops(
op, operands, rewriter,
- [loc](PatternRewriter &rewriter, ArrayRef<Value *> memRefOperands,
- ArrayRef<Value *> loopIvs) {
+ [loc](PatternRewriter &rewriter, ArrayRef<ValuePtr> memRefOperands,
+ ArrayRef<ValuePtr> loopIvs) {
// Generate an adaptor for the remapped operands of the TransposeOp.
// This allows for using the nice named accessors that are generated
// by the ODS.
toy::TransposeOpOperandAdaptor transposeAdaptor(memRefOperands);
- Value *input = transposeAdaptor.input();
+ ValuePtr input = transposeAdaptor.input();
// Transpose the elements by generating a load from the reverse
// indices.
- SmallVector<Value *, 2> reverseIvs(llvm::reverse(loopIvs));
+ SmallVector<ValuePtr, 2> reverseIvs(llvm::reverse(loopIvs));
return rewriter.create<AffineLoadOp>(loc, input, reverseIvs);
});
return matchSuccess();
diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
index d35cc5c576a..c3180b4a92d 100644
--- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
@@ -51,7 +51,7 @@ public:
: ConversionPattern(toy::PrintOp::getOperationName(), 1, context) {}
PatternMatchResult
- matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
+ matchAndRewrite(Operation *op, ArrayRef<ValuePtr> operands,
ConversionPatternRewriter &rewriter) const override {
auto memRefType = (*op->operand_type_begin()).cast<MemRefType>();
auto memRefShape = memRefType.getShape();
@@ -64,14 +64,14 @@ public:
// Get a symbol reference to the printf function, inserting it if necessary.
auto printfRef = getOrInsertPrintf(rewriter, parentModule, llvmDialect);
- Value *formatSpecifierCst = getOrCreateGlobalString(
+ ValuePtr formatSpecifierCst = getOrCreateGlobalString(
loc, rewriter, "frmt_spec", StringRef("%f \0", 4), parentModule,
llvmDialect);
- Value *newLineCst = getOrCreateGlobalString(
+ ValuePtr newLineCst = getOrCreateGlobalString(
loc, rewriter, "nl", StringRef("\n\0", 2), parentModule, llvmDialect);
// Create a loop for each of the dimensions within the shape.
- SmallVector<Value *, 4> loopIvs;
+ SmallVector<ValuePtr, 4> loopIvs;
for (unsigned i = 0, e = memRefShape.size(); i != e; ++i) {
auto lowerBound = rewriter.create<ConstantIndexOp>(loc, 0);
auto upperBound = rewriter.create<ConstantIndexOp>(loc, memRefShape[i]);
@@ -97,7 +97,7 @@ public:
auto elementLoad = rewriter.create<LoadOp>(loc, printOp.input(), loopIvs);
rewriter.create<CallOp>(
loc, printfRef, rewriter.getIntegerType(32),
- ArrayRef<Value *>({formatSpecifierCst, elementLoad}));
+ ArrayRef<ValuePtr>({formatSpecifierCst, elementLoad}));
// Notify the rewriter that this operation has been removed.
rewriter.eraseOp(op);
@@ -130,10 +130,10 @@ private:
/// Return a value representing an access into a global string with the given
/// name, creating the string if necessary.
- static Value *getOrCreateGlobalString(Location loc, OpBuilder &builder,
- StringRef name, StringRef value,
- ModuleOp module,
- LLVM::LLVMDialect *llvmDialect) {
+ static ValuePtr getOrCreateGlobalString(Location loc, OpBuilder &builder,
+ StringRef name, StringRef value,
+ ModuleOp module,
+ LLVM::LLVMDialect *llvmDialect) {
// Create the global at the entry of the module.
LLVM::GlobalOp global;
if (!(global = module.lookupSymbol<LLVM::GlobalOp>(name))) {
@@ -147,13 +147,13 @@ private:
}
// Get the pointer to the first character in the global string.
- Value *globalPtr = builder.create<LLVM::AddressOfOp>(loc, global);
- Value *cst0 = builder.create<LLVM::ConstantOp>(
+ ValuePtr globalPtr = builder.create<LLVM::AddressOfOp>(loc, global);
+ ValuePtr cst0 = builder.create<LLVM::ConstantOp>(
loc, LLVM::LLVMType::getInt64Ty(llvmDialect),
builder.getIntegerAttr(builder.getIndexType(), 0));
return builder.create<LLVM::GEPOp>(
loc, LLVM::LLVMType::getInt8PtrTy(llvmDialect), globalPtr,
- ArrayRef<Value *>({cst0, cst0}));
+ ArrayRef<ValuePtr>({cst0, cst0}));
}
};
} // end anonymous namespace
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;
diff --git a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp
index ebd4f5d1103..d18396c63bb 100644
--- a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp
+++ b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp
@@ -71,7 +71,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern<TransposeOp> {
matchAndRewrite(TransposeOp op,
mlir::PatternRewriter &rewriter) const override {
// Look through the input of the current transpose.
- mlir::Value *transposeInput = op.getOperand();
+ mlir::ValuePtr transposeInput = op.getOperand();
TransposeOp transposeInputOp =
llvm::dyn_cast_or_null<TransposeOp>(transposeInput->getDefiningOp());
OpenPOWER on IntegriCloud