Skip to content

Commit 0fbb7ba

Browse files
committed
DRAFT circle-mlir version up externals
on-going draft to version up externals and fix changes. Signed-off-by: SaeHie Park <saehie.park@gmail.com>
1 parent 1d63a16 commit 0fbb7ba

26 files changed

+183
-118
lines changed

circle-mlir/circle-mlir/lib/dialect/include/circle-mlir/dialect/CircleDialect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef __CIRCLE_MLIR_DIALECT_CIRCLE_DIALECT_H__
2121
#define __CIRCLE_MLIR_DIALECT_CIRCLE_DIALECT_H__
2222

23+
#include <mlir/Bytecode/BytecodeOpInterface.h> // from @llvm-project
2324
#include <mlir/Dialect/Traits.h> // from @llvm-project
2425
#include <mlir/IR/Dialect.h> // from @llvm-project
2526
#include <mlir/IR/DialectImplementation.h> // from @llvm-project
@@ -46,6 +47,7 @@ class ControlType : public Type::TypeBase<ControlType, Type, TypeStorage>
4647
{
4748
public:
4849
using Base::Base;
50+
static constexpr StringLiteral name = "cir.control";
4951
};
5052

5153
#include "mlir/CircleOpInterface.h.inc"

circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef CIRCLE_OPS
2121
#define CIRCLE_OPS
2222

23-
include "mlir/IR/FunctionInterfaces.td"
23+
// include "mlir/IR/FunctionInterfaces.td"
2424
include "mlir/IR/OpBase.td"
2525
include "mlir/Interfaces/InferTypeOpInterface.td"
2626
include "mlir/Interfaces/SideEffectInterfaces.td"
@@ -81,6 +81,7 @@ class CIR_VariadicTensorOf<list<Type> allowedRuntimeTypes,
8181
Variadic<TensorOf<allowedOpTypes>>,
8282
CIR_RuntimeType<Variadic<TensorOf<allowedRuntimeTypes>>>;
8383

84+
def CIR_I4 : I<4>;
8485
def CIR_Int32Or64 : SignlessIntOfWidths<[32, 64]>;
8586

8687
def CIR_BoolTensor : CIR_TensorOf<[I1]>;
@@ -260,6 +261,8 @@ class CIR_Op<string mnemonic, list<Trait> traits = []> :
260261

261262
// Whether the Circle operator has options in the schema representation.
262263
bit hasOptions = 0b0;
264+
// Whether the Circle operator has options2 in the schema representation.
265+
bit hasOptions2 = 0b0;
263266

264267
// Use to specify a custom options type for Circle operators where
265268
// the option's name does not match the Cirlce operator's name.

circle-mlir/circle-mlir/lib/dialect/src/CircleDialect.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ParseResult parseOneResultSameOperandTypeOp(OpAsmParser &parser, OperationState
7373
parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() ||
7474
parser.parseType(type))
7575
return failure();
76-
auto fnType = type.dyn_cast<FunctionType>();
76+
auto fnType = mlir::dyn_cast<FunctionType>(type);
7777
if (!fnType)
7878
{
7979
parser.emitError(loc, "expected function type");
@@ -134,7 +134,7 @@ bool VerifyOperandsHaveSameShapesOrBroadcastableShape(Operation *op, ArrayRef<un
134134

135135
for (unsigned index : indices)
136136
{
137-
ShapedType shaped_type = op->getOperand(index).getType().dyn_cast<ShapedType>();
137+
ShapedType shaped_type = mlir::dyn_cast<ShapedType>(op->getOperand(index).getType());
138138
if (!shaped_type || !shaped_type.hasRank())
139139
{
140140
// Marks that we have an unknown rank input.
@@ -212,8 +212,8 @@ bool EqualsZero(Value value)
212212
return false;
213213
}
214214

215-
Type element_type = value.getType().cast<ShapedType>().getElementType();
216-
if (element_type.isa<FloatType>())
215+
Type element_type = mlir::cast<ShapedType>(value.getType()).getElementType();
216+
if (mlir::isa<FloatType>(element_type))
217217
{
218218
return constant.getSplatValue<APFloat>().isZero();
219219
}
@@ -315,7 +315,7 @@ bool ExtractConstantValues(mlir::Value &input, std::vector<int64_t> &values)
315315

316316
void CIRDialect::printType(Type type, DialectAsmPrinter &os) const
317317
{
318-
if (type.isa<ControlType>())
318+
if (mlir::isa<ControlType>(type))
319319
{
320320
os << "control";
321321
return;
@@ -357,7 +357,7 @@ namespace
357357
// Returns true if it is a shaped type of f32 elements.
358358
inline bool IsF32ShapedType(Type t)
359359
{
360-
if (auto shaped_type = t.dyn_cast_or_null<ShapedType>())
360+
if (auto shaped_type = mlir::dyn_cast_or_null<ShapedType>(t))
361361
{
362362
return shaped_type.getElementType().isF32();
363363
}
@@ -367,7 +367,7 @@ inline bool IsF32ShapedType(Type t)
367367
// Returns true if it is a shaped type of i64 elements.
368368
inline bool IsI64ShapedType(Type t)
369369
{
370-
if (auto shaped_type = t.dyn_cast_or_null<ShapedType>())
370+
if (auto shaped_type = mlir::dyn_cast_or_null<ShapedType>(t))
371371
{
372372
return shaped_type.getElementType().isInteger(64);
373373
}
@@ -391,11 +391,11 @@ namespace
391391

392392
bool InputOutputHasSameShape(mlir::Type input_type, mlir::Type output_type)
393393
{
394-
auto input_shaped_type = input_type.dyn_cast_or_null<ShapedType>();
394+
auto input_shaped_type = mlir::dyn_cast_or_null<ShapedType>(input_type);
395395
if (!input_shaped_type || !input_shaped_type.hasStaticShape())
396396
return false;
397397

398-
auto output_shaped_type = output_type.dyn_cast_or_null<ShapedType>();
398+
auto output_shaped_type = mlir::dyn_cast_or_null<ShapedType>(output_type);
399399
if (!output_shaped_type || !output_shaped_type.hasStaticShape())
400400
return false;
401401

@@ -500,13 +500,13 @@ Operation *CIRDialect::materializeConstant(OpBuilder &builder, Attribute value,
500500
{
501501
// If this is a constant bytes attribute or the result type doesn't match the
502502
// attribute type, then generate a tfl.pseudo_const.
503-
if (value.isa<ConstBytesAttr>() ||
504-
(value.isa<ElementsAttr>() && value.cast<ElementsAttr>().getType() != type))
505-
return builder.create<ConstOp>(loc, type, value.cast<ElementsAttr>());
503+
if (mlir::isa<ConstBytesAttr>(value) ||
504+
(mlir::isa<ElementsAttr>(value) && mlir::cast<ElementsAttr>(value).getType() != type))
505+
return builder.create<ConstOp>(loc, type, mlir::cast<ElementsAttr>(value));
506506
if (ConstOp::isBuildableWith(value, type))
507-
return builder.create<ConstOp>(loc, type, value.cast<ElementsAttr>());
507+
return builder.create<ConstOp>(loc, type, mlir::cast<ElementsAttr>(value));
508508
if (NoValueOp::isBuildableWith(value, type))
509-
return builder.create<NoValueOp>(loc, type, value.cast<UnitAttr>());
509+
return builder.create<NoValueOp>(loc, type, mlir::cast<UnitAttr>(value));
510510
return nullptr;
511511
}
512512

circle-mlir/circle-mlir/lib/dialect/src/ConstFold.inc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Attribute ConstFoldBinaryOp(Type result_type, Attribute operand1, Attribute oper
150150
operand2.dyn_cast_or_null<DenseElementsAttr>())
151151
{
152152
return ConstFoldBinaryOpDenseDense<AttrElementT, ElementValueT>(
153-
result_type, operand1.cast<DenseElementsAttr>(), operand2.cast<DenseElementsAttr>(),
153+
result_type, mlir::cast<DenseElementsAttr>(operand1), mlir::cast<DenseElementsAttr>(operand2),
154154
calculate);
155155
}
156156

@@ -169,13 +169,13 @@ Attribute ConstFoldBinaryOp(Type result_type, ArrayRef<Attribute> operands,
169169
{
170170
// Note: All types are wrapped in tensor types in Circle. E.g., f32 is
171171
// represented as tensor<f32>. So we are only handling tensor types here.
172-
auto type = result_type.dyn_cast<ShapedType>();
172+
auto type = mlir::dyn_cast<ShapedType>(result_type);
173173
if (!type)
174174
return {};
175175

176176
auto elemType = type.getElementType();
177177

178-
if (elemType.isa<FloatType>())
178+
if (mlir::isa<FloatType>(elemType))
179179
return ConstFoldBinaryOp<FloatAttr>(result_type, operands[0], operands[1], float_calculate);
180180

181181
if (elemType.isSignlessInteger())
@@ -191,12 +191,12 @@ Attribute ConstFoldUnaryOp(Type result_type, Attribute operand,
191191
llvm::function_ref<APFloat(APFloat)> calculate)
192192
{
193193
assert(IsF32ShapedType(result_type));
194-
auto result_shape_type = result_type.cast<ShapedType>();
194+
auto result_shape_type = mlir::cast<ShapedType>(result_type);
195195

196196
if (!result_shape_type.hasStaticShape())
197197
return {};
198198

199-
if (auto dense_elements = operand.dyn_cast_or_null<DenseElementsAttr>())
199+
if (auto dense_elements = mlir::dyn_cast_or_null<DenseElementsAttr>(operand))
200200
{
201201
SmallVector<APFloat, 16> new_values;
202202
const int num_elements = result_shape_type.getNumElements();

circle-mlir/circle-mlir/lib/dialect/src/NameUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ std::string GetNameFromLoc(Location loc)
4040
{
4141
Location curr_loc = locs.pop_back_val();
4242

43-
if (auto name_loc = curr_loc.dyn_cast<NameLoc>())
43+
if (auto name_loc = mlir::dyn_cast<NameLoc>(curr_loc))
4444
{
4545
// Add name in NameLoc. For NameLoc we also account for names due to ops
4646
// in functions where the op's name is first.
4747
auto name = name_loc.getName().strref().split('@').first;
4848
// Skip if the name is for op type.
49-
if (!name.endswith(":"))
49+
if (!name.ends_with(":"))
5050
{
5151
loc_names.push_back(name);
5252
if (!name.empty())
5353
names_is_nonempty = true;
5454
}
5555
continue;
5656
}
57-
else if (auto call_loc = curr_loc.dyn_cast<CallSiteLoc>())
57+
else if (auto call_loc = mlir::dyn_cast<CallSiteLoc>(curr_loc))
5858
{
5959
// Use location of the Callee to generate the name.
6060
locs.push_back(call_loc.getCallee());
6161
continue;
6262
}
63-
else if (auto fused_loc = curr_loc.dyn_cast<FusedLoc>())
63+
else if (auto fused_loc = mlir::dyn_cast<FusedLoc>(curr_loc))
6464
{
6565
// Push all locations in FusedLoc in reverse order, so locations are
6666
// visited based on order in FusedLoc.

circle-mlir/circle-mlir/lib/dialect/src/ops/CastOp.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor)
4141
}
4242

4343
// For now, only supports cast for the integer/float input type.
44-
auto elements_attr = operands[0].dyn_cast_or_null<mlir::DenseElementsAttr>();
44+
auto elements_attr = mlir::dyn_cast_or_null<mlir::DenseElementsAttr>(operands[0]);
4545
if (!elements_attr)
4646
{
4747
return nullptr;
4848
}
4949

50-
auto result_element_type = getType().cast<ShapedType>().getElementType();
51-
auto operand_element_type = getInput().getType().cast<ShapedType>().getElementType();
52-
auto operand_int_type = operand_element_type.dyn_cast<IntegerType>();
50+
auto result_element_type = mlir::cast<ShapedType>(getType()).getElementType();
51+
auto operand_element_type = mlir::cast<ShapedType>(getInput().getType()).getElementType();
52+
auto operand_int_type = mlir::dyn_cast<IntegerType>(operand_element_type);
5353
if (!result_element_type || !operand_element_type)
5454
{
5555
return nullptr;
5656
}
5757

5858
if (mlir::isa<mlir::IntegerType>(result_element_type))
5959
{
60-
auto result_int_type = result_element_type.dyn_cast<IntegerType>();
60+
auto result_int_type = mlir::dyn_cast<IntegerType>(result_element_type);
6161
const int output_bitwidth = result_int_type.getWidth();
6262
// check for INT64 <--> INT32
6363
if (operand_int_type)
@@ -97,7 +97,7 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor)
9797
else if (mlir::isa<mlir::FloatType>(result_element_type))
9898
{
9999
// Refer to https://llvm.org/doxygen/classllvm_1_1APFloat.html
100-
auto result_float_type = result_element_type.dyn_cast<FloatType>();
100+
auto result_float_type = mlir::dyn_cast<FloatType>(result_element_type);
101101
// To get the correct semantics of floating point from the type of this CastOp
102102
const llvm::fltSemantics &semantics = result_float_type.getFloatSemantics();
103103
auto cast = [&](const llvm::APInt &value) {

circle-mlir/circle-mlir/lib/dialect/src/ops/ConcatenationOp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ bool IsConcatenationOpConstFoldable(ConcatenationOp op, ArrayRef<Attribute> oper
150150
return false;
151151

152152
return llvm::all_of(
153-
operands, [](Attribute operand) { return operand && operand.isa<DenseElementsAttr>(); });
153+
operands, [](Attribute operand) { return operand && mlir::isa<DenseElementsAttr>(operand); });
154154
}
155155

156156
DenseElementsAttr ConstFoldConcatenateOpDense(ArrayRef<Attribute> operands,

circle-mlir/circle-mlir/lib/dialect/src/ops/ConstOp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ bool ConstOp::isBuildableWith(Attribute value, Type type)
8383
if (!typedAttr || typedAttr.getType() != type)
8484
return false;
8585
// Integer values must be signless.
86-
if (type.isa<IntegerType>() && !type.cast<IntegerType>().isSignless())
86+
if (mlir::isa<IntegerType>(type) && !mlir::cast<IntegerType>(type).isSignless())
8787
return false;
8888
// Integer, float, and element attributes are buildable.
89-
return value.isa<IntegerAttr, FloatAttr, ElementsAttr>();
89+
return mlir::isa<IntegerAttr, FloatAttr, ElementsAttr>(value);
9090
}
9191

9292
} // namespace Circle

circle-mlir/circle-mlir/lib/dialect/src/ops/FullyConnectedOp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ LogicalResult FullyConnectedOp::fold(FoldAdaptor adaptor, SmallVectorImpl<OpFold
9696
return failure();
9797

9898
// Bias tensor is optional.
99-
const bool has_bias = !(!getBias() || getBias().getType().isa<NoneType>());
99+
const bool has_bias = !(!getBias() || mlir::isa<NoneType>(getBias().getType()));
100100

101101
// Get the tensors.
102102
DenseElementsAttr input_tensor, weights_tensor, bias_tensor;

circle-mlir/circle-mlir/lib/dialect/src/ops/NoValueOp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OpFoldResult NoValueOp::fold(FoldAdaptor adaptor) { return getValueAttr(); }
3535

3636
bool NoValueOp::isBuildableWith(Attribute value, Type type)
3737
{
38-
return value.isa<UnitAttr>() && type.isa<NoneType>();
38+
return mlir::isa<UnitAttr>(value) && mlir::isa<NoneType>(type);
3939
}
4040

4141
} // namespace Circle

0 commit comments

Comments
 (0)