Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 0130826

Browse files
River707tensorflower-gardener
authored andcommitted
NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.
ValuePtr was a temporary typedef during the transition to a value-typed Value. PiperOrigin-RevId: 286945714
1 parent da4098b commit 0130826

File tree

192 files changed

+2160
-2271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+2160
-2271
lines changed

bindings/python/pybind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct PythonValueHandle {
9595
assert(value.hasType() && value.getType().isa<FunctionType>() &&
9696
"can only call function-typed values");
9797

98-
std::vector<ValuePtr> argValues;
98+
std::vector<Value> argValues;
9999
argValues.reserve(args.size());
100100
for (auto arg : args)
101101
argValues.push_back(arg.value.getValue());

examples/toy/Ch2/include/toy/Ops.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def AddOp : Toy_Op<"add"> {
8989

9090
// Allow building an AddOp with from the two input operands.
9191
let builders = [
92-
OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
92+
OpBuilder<"Builder *b, OperationState &state, Value lhs, Value rhs">
9393
];
9494
}
9595

@@ -120,7 +120,7 @@ def GenericCallOp : Toy_Op<"generic_call"> {
120120
// Add custom build methods for the generic call operation.
121121
let builders = [
122122
OpBuilder<"Builder *builder, OperationState &state, "
123-
"StringRef callee, ArrayRef<ValuePtr> arguments">
123+
"StringRef callee, ArrayRef<Value> arguments">
124124
];
125125
}
126126

@@ -136,7 +136,7 @@ def MulOp : Toy_Op<"mul"> {
136136

137137
// Allow building a MulOp with from the two input operands.
138138
let builders = [
139-
OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
139+
OpBuilder<"Builder *b, OperationState &state, Value lhs, Value rhs">
140140
];
141141
}
142142

@@ -210,7 +210,7 @@ def TransposeOp : Toy_Op<"transpose"> {
210210

211211
// Allow building a TransposeOp with from the input operand.
212212
let builders = [
213-
OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
213+
OpBuilder<"Builder *b, OperationState &state, Value input">
214214
];
215215

216216
// Invoke a static verify method to verify this transpose operation.

examples/toy/Ch2/mlir/Dialect.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
8585
// AddOp
8686

8787
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
88-
mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
88+
mlir::Value lhs, mlir::Value rhs) {
8989
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
9090
state.addOperands({lhs, rhs});
9191
}
@@ -94,8 +94,7 @@ void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
9494
// GenericCallOp
9595

9696
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
97-
StringRef callee,
98-
ArrayRef<mlir::ValuePtr> arguments) {
97+
StringRef callee, ArrayRef<mlir::Value> arguments) {
9998
// Generic call always returns an unranked Tensor initially.
10099
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
101100
state.addOperands(arguments);
@@ -106,7 +105,7 @@ void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
106105
// MulOp
107106

108107
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
109-
mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
108+
mlir::Value lhs, mlir::Value rhs) {
110109
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
111110
state.addOperands({lhs, rhs});
112111
}
@@ -153,7 +152,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
153152
// TransposeOp
154153

155154
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
156-
mlir::ValuePtr value) {
155+
mlir::Value value) {
157156
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
158157
state.addOperands(value);
159158
}

examples/toy/Ch2/mlir/MLIRGen.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class MLIRGenImpl {
9090
/// Entering a function creates a new scope, and the function arguments are
9191
/// added to the mapping. When the processing of a function is terminated, the
9292
/// scope is destroyed and the mappings created in this scope are dropped.
93-
llvm::ScopedHashTable<StringRef, mlir::ValuePtr> symbolTable;
93+
llvm::ScopedHashTable<StringRef, mlir::Value> symbolTable;
9494

9595
/// Helper conversion for a Toy AST location to an MLIR location.
9696
mlir::Location loc(Location loc) {
@@ -100,7 +100,7 @@ class MLIRGenImpl {
100100

101101
/// Declare a variable in the current scope, return success if the variable
102102
/// wasn't declared yet.
103-
mlir::LogicalResult declare(llvm::StringRef var, mlir::ValuePtr value) {
103+
mlir::LogicalResult declare(llvm::StringRef var, mlir::Value value) {
104104
if (symbolTable.count(var))
105105
return mlir::failure();
106106
symbolTable.insert(var, value);
@@ -123,8 +123,7 @@ class MLIRGenImpl {
123123
/// Emit a new function and add it to the MLIR module.
124124
mlir::FuncOp mlirGen(FunctionAST &funcAST) {
125125
// Create a scope in the symbol table to hold variable declarations.
126-
ScopedHashTableScope<llvm::StringRef, mlir::ValuePtr> var_scope(
127-
symbolTable);
126+
ScopedHashTableScope<llvm::StringRef, mlir::Value> var_scope(symbolTable);
128127

129128
// Create an MLIR function for the given prototype.
130129
mlir::FuncOp function(mlirGen(*funcAST.getProto()));
@@ -175,7 +174,7 @@ class MLIRGenImpl {
175174
}
176175

177176
/// Emit a binary operation
178-
mlir::ValuePtr mlirGen(BinaryExprAST &binop) {
177+
mlir::Value mlirGen(BinaryExprAST &binop) {
179178
// First emit the operations for each side of the operation before emitting
180179
// the operation itself. For example if the expression is `a + foo(a)`
181180
// 1) First it will visiting the LHS, which will return a reference to the
@@ -187,10 +186,10 @@ class MLIRGenImpl {
187186
// and the result value is returned. If an error occurs we get a nullptr
188187
// and propagate.
189188
//
190-
mlir::ValuePtr lhs = mlirGen(*binop.getLHS());
189+
mlir::Value lhs = mlirGen(*binop.getLHS());
191190
if (!lhs)
192191
return nullptr;
193-
mlir::ValuePtr rhs = mlirGen(*binop.getRHS());
192+
mlir::Value rhs = mlirGen(*binop.getRHS());
194193
if (!rhs)
195194
return nullptr;
196195
auto location = loc(binop.loc());
@@ -211,7 +210,7 @@ class MLIRGenImpl {
211210
/// This is a reference to a variable in an expression. The variable is
212211
/// expected to have been declared and so should have a value in the symbol
213212
/// table, otherwise emit an error and return nullptr.
214-
mlir::ValuePtr mlirGen(VariableExprAST &expr) {
213+
mlir::Value mlirGen(VariableExprAST &expr) {
215214
if (auto variable = symbolTable.lookup(expr.getName()))
216215
return variable;
217216

@@ -225,15 +224,15 @@ class MLIRGenImpl {
225224
auto location = loc(ret.loc());
226225

227226
// 'return' takes an optional expression, handle that case here.
228-
mlir::ValuePtr expr = nullptr;
227+
mlir::Value expr = nullptr;
229228
if (ret.getExpr().hasValue()) {
230229
if (!(expr = mlirGen(*ret.getExpr().getValue())))
231230
return mlir::failure();
232231
}
233232

234233
// Otherwise, this return operation has zero operands.
235234
builder.create<ReturnOp>(location, expr ? makeArrayRef(expr)
236-
: ArrayRef<mlir::ValuePtr>());
235+
: ArrayRef<mlir::Value>());
237236
return mlir::success();
238237
}
239238

@@ -255,7 +254,7 @@ class MLIRGenImpl {
255254
/// [[1.000000e+00, 2.000000e+00, 3.000000e+00],
256255
/// [4.000000e+00, 5.000000e+00, 6.000000e+00]]>} : () -> tensor<2x3xf64>
257256
///
258-
mlir::ValuePtr mlirGen(LiteralExprAST &lit) {
257+
mlir::Value mlirGen(LiteralExprAST &lit) {
259258
auto type = getType(lit.getDims());
260259

261260
// The attribute is a vector with a floating point value per element
@@ -301,12 +300,12 @@ class MLIRGenImpl {
301300

302301
/// Emit a call expression. It emits specific operations for the `transpose`
303302
/// builtin. Other identifiers are assumed to be user-defined functions.
304-
mlir::ValuePtr mlirGen(CallExprAST &call) {
303+
mlir::Value mlirGen(CallExprAST &call) {
305304
llvm::StringRef callee = call.getCallee();
306305
auto location = loc(call.loc());
307306

308307
// Codegen the operands first.
309-
SmallVector<mlir::ValuePtr, 4> operands;
308+
SmallVector<mlir::Value, 4> operands;
310309
for (auto &expr : call.getArgs()) {
311310
auto arg = mlirGen(*expr);
312311
if (!arg)
@@ -343,12 +342,12 @@ class MLIRGenImpl {
343342
}
344343

345344
/// Emit a constant for a single number (FIXME: semantic? broadcast?)
346-
mlir::ValuePtr mlirGen(NumberExprAST &num) {
345+
mlir::Value mlirGen(NumberExprAST &num) {
347346
return builder.create<ConstantOp>(loc(num.loc()), num.getValue());
348347
}
349348

350349
/// Dispatch codegen for the right expression subclass using RTTI.
351-
mlir::ValuePtr mlirGen(ExprAST &expr) {
350+
mlir::Value mlirGen(ExprAST &expr) {
352351
switch (expr.getKind()) {
353352
case toy::ExprAST::Expr_BinOp:
354353
return mlirGen(cast<BinaryExprAST>(expr));
@@ -372,15 +371,15 @@ class MLIRGenImpl {
372371
/// initializer and record the value in the symbol table before returning it.
373372
/// Future expressions will be able to reference this variable through symbol
374373
/// table lookup.
375-
mlir::ValuePtr mlirGen(VarDeclExprAST &vardecl) {
374+
mlir::Value mlirGen(VarDeclExprAST &vardecl) {
376375
auto init = vardecl.getInitVal();
377376
if (!init) {
378377
emitError(loc(vardecl.loc()),
379378
"missing initializer in variable declaration");
380379
return nullptr;
381380
}
382381

383-
mlir::ValuePtr value = mlirGen(*init);
382+
mlir::Value value = mlirGen(*init);
384383
if (!value)
385384
return nullptr;
386385

@@ -400,7 +399,7 @@ class MLIRGenImpl {
400399

401400
/// Codegen a list of expression, return failure if one of them hit an error.
402401
mlir::LogicalResult mlirGen(ExprASTList &blockAST) {
403-
ScopedHashTableScope<StringRef, mlir::ValuePtr> var_scope(symbolTable);
402+
ScopedHashTableScope<StringRef, mlir::Value> var_scope(symbolTable);
404403
for (auto &expr : blockAST) {
405404
// Specific handling for variable declarations, return statement, and
406405
// print. These can only appear in block list and not in nested

examples/toy/Ch3/include/toy/Ops.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def AddOp : Toy_Op<"add", [NoSideEffect]> {
8989

9090
// Allow building an AddOp with from the two input operands.
9191
let builders = [
92-
OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
92+
OpBuilder<"Builder *b, OperationState &state, Value lhs, Value rhs">
9393
];
9494
}
9595

@@ -120,7 +120,7 @@ def GenericCallOp : Toy_Op<"generic_call"> {
120120
// Add custom build methods for the generic call operation.
121121
let builders = [
122122
OpBuilder<"Builder *builder, OperationState &state, "
123-
"StringRef callee, ArrayRef<ValuePtr> arguments">
123+
"StringRef callee, ArrayRef<Value> arguments">
124124
];
125125
}
126126

@@ -136,7 +136,7 @@ def MulOp : Toy_Op<"mul", [NoSideEffect]> {
136136

137137
// Allow building a MulOp with from the two input operands.
138138
let builders = [
139-
OpBuilder<"Builder *b, OperationState &state, ValuePtr lhs, ValuePtr rhs">
139+
OpBuilder<"Builder *b, OperationState &state, Value lhs, Value rhs">
140140
];
141141
}
142142

@@ -216,7 +216,7 @@ def TransposeOp : Toy_Op<"transpose", [NoSideEffect]> {
216216

217217
// Allow building a TransposeOp with from the input operand.
218218
let builders = [
219-
OpBuilder<"Builder *b, OperationState &state, ValuePtr input">
219+
OpBuilder<"Builder *b, OperationState &state, Value input">
220220
];
221221

222222
// Invoke a static verify method to verify this transpose operation.

examples/toy/Ch3/mlir/Dialect.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static mlir::LogicalResult verify(ConstantOp op) {
8585
// AddOp
8686

8787
void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
88-
mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
88+
mlir::Value lhs, mlir::Value rhs) {
8989
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
9090
state.addOperands({lhs, rhs});
9191
}
@@ -94,8 +94,7 @@ void AddOp::build(mlir::Builder *builder, mlir::OperationState &state,
9494
// GenericCallOp
9595

9696
void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
97-
StringRef callee,
98-
ArrayRef<mlir::ValuePtr> arguments) {
97+
StringRef callee, ArrayRef<mlir::Value> arguments) {
9998
// Generic call always returns an unranked Tensor initially.
10099
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
101100
state.addOperands(arguments);
@@ -106,7 +105,7 @@ void GenericCallOp::build(mlir::Builder *builder, mlir::OperationState &state,
106105
// MulOp
107106

108107
void MulOp::build(mlir::Builder *builder, mlir::OperationState &state,
109-
mlir::ValuePtr lhs, mlir::ValuePtr rhs) {
108+
mlir::Value lhs, mlir::Value rhs) {
110109
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
111110
state.addOperands({lhs, rhs});
112111
}
@@ -153,7 +152,7 @@ static mlir::LogicalResult verify(ReturnOp op) {
153152
// TransposeOp
154153

155154
void TransposeOp::build(mlir::Builder *builder, mlir::OperationState &state,
156-
mlir::ValuePtr value) {
155+
mlir::Value value) {
157156
state.addTypes(UnrankedTensorType::get(builder->getF64Type()));
158157
state.addOperands(value);
159158
}

0 commit comments

Comments
 (0)