mlir::Attribute FloatAttr = mlir::FloatAttr::get(FloatType, 1.0);
mlir::Attribute IntegerAttr = mlir::IntegerAttr::get(IntegerType, 10);
mlir::Attribute TypeAttr = mlir::TypeAttr::get(IndexType);
-mlir::Attribute ArrayAttr = mlir::ArrayAttr::get({UnitAttr}, &Context);
-mlir::Attribute StringAttr = mlir::StringAttr::get("foo", &Context);
+mlir::Attribute ArrayAttr = mlir::ArrayAttr::get(&Context, {UnitAttr});
+mlir::Attribute StringAttr = mlir::StringAttr::get(&Context, "foo");
mlir::Attribute ElementsAttr = mlir::DenseElementsAttr::get(
VectorType.cast<mlir::ShapedType>(), llvm::ArrayRef<float>{2.0f, 3.0f});
static constexpr llvm::StringRef inType() { return "in_type"; }
static constexpr llvm::StringRef lenpName() { return "len_param_count"; }
mlir::Type getAllocatedType();
-
+
bool hasLenParams() { return bool{(*this)->getAttr(lenpName())}; }
-
+
unsigned numLenParams() {
if (auto val = (*this)->getAttrOfType<mlir::IntegerAttr>(lenpName()))
return val.getInt();
return 0;
}
-
+
operand_range getLenParams() {
return {operand_begin(), operand_begin() + numLenParams()};
}
-
+
unsigned numShapeOperands() {
return operand_end() - operand_begin() + numLenParams();
}
-
+
operand_range getShapeOperands() {
return {operand_begin() + numLenParams(), operand_end()};
}
-
+
static mlir::Type getRefTy(mlir::Type ty);
/// Get the input type of the allocation
}];
let arguments = (ins AnyReferenceLike:$memref, AnyIntegerLike:$len);
-
+
let results = (outs fir_BoxCharType);
let assemblyFormat = [{
p.printFunctionalType((*this)->getOperandTypes(),
(*this)->getResultTypes());
}];
-
+
let verifier = [{
auto refTy = ref().getType();
if (fir::isa_ref_type(refTy)) {
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>,
OpBuilderDAG<(ins "Type":$type, "ValueRange":$operands,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>];
-
+
let extraClassDeclaration = [{
static constexpr llvm::StringRef baseType() { return "base_type"; }
mlir::Type getBaseType();
let printer = [{
p << getOperationName() << ' '
- << (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue()
+ << (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue()
<< ", " << (*this)->getAttr(typeAttrName());
if (getNumOperands()) {
p << '(';
CArg<"ValueRange", "llvm::None">:$iterArgs,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>
];
-
+
let extraClassDeclaration = [{
mlir::Block *getBody() { return ®ion().front(); }
mlir::Value getIterateVar() { return getBody()->getArgument(1); }
}];
let arguments = (ins FirRealAttr:$constant);
-
+
let results = (outs fir_RealType:$res);
let assemblyFormat = "`(` $constant `)` attr-dict `:` type($res)";
-
+
let verifier = [{
if (!getType().isa<fir::RealType>())
return emitOpError("must be a !fir.real type");
}];
let results = (outs fir_ComplexType);
-
+
let parser = [{
fir::RealAttr realp;
fir::RealAttr imagp;
def fir_AddrOfOp : fir_OneResultOp<"address_of", [NoSideEffect]> {
let summary = "convert a symbol to an SSA value";
-
+
let description = [{
Convert a symbol (a function or global reference) to an SSA-value to be
used in other Operations.
def fir_ConvertOp : fir_OneResultOp<"convert", [NoSideEffect]> {
let summary = "encapsulates all Fortran scalar type conversions";
-
+
let description = [{
Generalized type conversion. Convert the ssa value from type T to type U.
Not all pairs of types have conversions. When types T and U are the same
mlir::Type resultType() {
return fir::AllocaOp::wrapResultType(getType());
}
-
+
/// Return the initializer attribute if it exists, or a null attribute.
Attribute getValueOrNull() { return initVal().getValueOr(Attribute()); }
}
mlir::FlatSymbolRefAttr getSymbol() {
- return mlir::FlatSymbolRefAttr::get(
+ return mlir::FlatSymbolRefAttr::get(getContext(),
(*this)->getAttrOfType<mlir::StringAttr>(
- mlir::SymbolTable::getSymbolAttrName()).getValue(), getContext());
+ mlir::SymbolTable::getSymbolAttrName()).getValue());
}
}];
}
}];
let printer = [{
- p << getOperationName() << ' ' << (*this)->getAttr(lenParamAttrName())
+ p << getOperationName() << ' ' << (*this)->getAttr(lenParamAttrName())
<< ", " << (*this)->getAttr(intAttrName());
}];
fir::StringLitOp Fortran::lower::FirOpBuilder::createStringLit(
mlir::Location loc, mlir::Type eleTy, llvm::StringRef data) {
- auto strAttr = mlir::StringAttr::get(data, getContext());
+ auto strAttr = mlir::StringAttr::get(getContext(), data);
auto valTag = mlir::Identifier::get(fir::StringLitOp::value(), getContext());
mlir::NamedAttribute dataAttr(valTag, strAttr);
auto sizeTag = mlir::Identifier::get(fir::StringLitOp::size(), getContext());
ModuleOp module) {
auto *context = module.getContext();
if (module.lookupSymbol<LLVM::LLVMFuncOp>("printf"))
- return SymbolRefAttr::get("printf", context);
+ return SymbolRefAttr::get(context, "printf");
// Create a function declaration for printf, the signature is:
// * `i32 (i8*, ...)`
PatternRewriter::InsertionGuard insertGuard(rewriter);
rewriter.setInsertionPointToStart(module.getBody());
rewriter.create<LLVM::LLVMFuncOp>(module.getLoc(), "printf", llvmFnType);
- return SymbolRefAttr::get("printf", context);
+ return SymbolRefAttr::get(context, "printf");
}
/// Return a value representing an access into a global string with the given
ModuleOp module) {
auto *context = module.getContext();
if (module.lookupSymbol<LLVM::LLVMFuncOp>("printf"))
- return SymbolRefAttr::get("printf", context);
+ return SymbolRefAttr::get(context, "printf");
// Create a function declaration for printf, the signature is:
// * `i32 (i8*, ...)`
PatternRewriter::InsertionGuard insertGuard(rewriter);
rewriter.setInsertionPointToStart(module.getBody());
rewriter.create<LLVM::LLVMFuncOp>(module.getLoc(), "printf", llvmFnType);
- return SymbolRefAttr::get("printf", context);
+ return SymbolRefAttr::get(context, "printf");
}
/// Return a value representing an access into a global string with the given
auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, context));
auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, context));
auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {m, n}, context));
- auto maps = ArrayAttr::get({mapA, mapB, mapC}, context);
+ auto maps = ArrayAttr::get(context, {mapA, mapB, mapC});
return indexingMaps == maps;
}
auto mapA = AffineMapAttr::get(AffineMap::get(3, 0, {k, n}, context));
auto mapB = AffineMapAttr::get(AffineMap::get(3, 0, {m, k}, context));
auto mapC = AffineMapAttr::get(AffineMap::get(3, 0, {n, m}, context));
- auto maps = ArrayAttr::get({mapA, mapB, mapC}, context);
+ auto maps = ArrayAttr::get(context, {mapA, mapB, mapC});
return indexingMaps == maps;
}
using Base::Base;
using ValueType = ArrayRef<Attribute>;
- static ArrayAttr get(ArrayRef<Attribute> value, MLIRContext *context);
+ static ArrayAttr get(MLIRContext *context, ArrayRef<Attribute> value);
ArrayRef<Attribute> getValue() const;
Attribute operator[](unsigned idx) const;
/// attributes. This method assumes that the provided list is unordered. If
/// the caller can guarantee that the attributes are ordered by name,
/// getWithSorted should be used instead.
- static DictionaryAttr get(ArrayRef<NamedAttribute> value,
- MLIRContext *context);
+ static DictionaryAttr get(MLIRContext *context,
+ ArrayRef<NamedAttribute> value);
/// Construct a dictionary with an array of values that is known to already be
/// sorted by name and uniqued.
using Attribute::Attribute;
using ValueType = bool;
- static BoolAttr get(bool value, MLIRContext *context);
+ static BoolAttr get(MLIRContext *context, bool value);
/// Enable conversion to IntegerAttr. This uses conversion vs. inheritance to
/// avoid bringing in all of IntegerAttrs methods.
using Base::Base;
/// Get or create a new OpaqueAttr with the provided dialect and string data.
- static OpaqueAttr get(Identifier dialect, StringRef attrData, Type type,
- MLIRContext *context);
+ static OpaqueAttr get(MLIRContext *context, Identifier dialect,
+ StringRef attrData, Type type);
/// Get or create a new OpaqueAttr with the provided dialect and string data.
/// If the given identifier is not a valid namespace for a dialect, then a
using ValueType = StringRef;
/// Get an instance of a StringAttr with the given string.
- static StringAttr get(StringRef bytes, MLIRContext *context);
+ static StringAttr get(MLIRContext *context, StringRef bytes);
/// Get an instance of a StringAttr with the given string and Type.
static StringAttr get(StringRef bytes, Type type);
using Base::Base;
/// Construct a symbol reference for the given value name.
- static FlatSymbolRefAttr get(StringRef value, MLIRContext *ctx);
+ static FlatSymbolRefAttr get(MLIRContext *ctx, StringRef value);
/// Construct a symbol reference for the given value name, and a set of nested
/// references that are further resolve to a nested symbol.
- static SymbolRefAttr get(StringRef value,
- ArrayRef<FlatSymbolRefAttr> references,
- MLIRContext *ctx);
+ static SymbolRefAttr get(MLIRContext *ctx, StringRef value,
+ ArrayRef<FlatSymbolRefAttr> references);
/// Returns the name of the top level symbol reference, i.e. the root of the
/// reference path.
using ValueType = StringRef;
/// Construct a symbol reference for the given value name.
- static FlatSymbolRefAttr get(StringRef value, MLIRContext *ctx) {
- return SymbolRefAttr::get(value, ctx);
+ static FlatSymbolRefAttr get(MLIRContext *ctx, StringRef value) {
+ return SymbolRefAttr::get(ctx, value);
}
/// Returns the name of the held symbol reference.
if (attributes.empty())
return (void)static_cast<ConcreteType *>(this)->removeAttr(nameOut);
Operation *op = this->getOperation();
- op->setAttr(nameOut, DictionaryAttr::get(attributes, op->getContext()));
+ op->setAttr(nameOut, DictionaryAttr::get(op->getContext(), attributes));
}
template <typename ConcreteType>
if (attributes.empty())
return (void)this->getOperation()->removeAttr(nameOut);
Operation *op = this->getOperation();
- op->setAttr(nameOut, DictionaryAttr::get(attributes, op->getContext()));
+ op->setAttr(nameOut, DictionaryAttr::get(op->getContext(), attributes));
}
template <typename ConcreteType>
attrs = newAttrs;
}
void setAttrs(ArrayRef<NamedAttribute> newAttrs) {
- setAttrs(DictionaryAttr::get(newAttrs, getContext()));
+ setAttrs(DictionaryAttr::get(getContext(), newAttrs));
}
/// Return the specified attribute if present, null otherwise.
/*defaultImplementation=*/[{
this->getOperation()->setAttr(
mlir::SymbolTable::getSymbolAttrName(),
- StringAttr::get(name, this->getOperation()->getContext()));
+ StringAttr::get(this->getOperation()->getContext(), name));
}]
>,
InterfaceMethod<"Gets the visibility of this symbol.",
MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements,
MlirAttribute const *elements) {
SmallVector<Attribute, 8> attrs;
- return wrap(ArrayAttr::get(
- unwrapList(static_cast<size_t>(numElements), elements, attrs),
- unwrap(ctx)));
+ return wrap(
+ ArrayAttr::get(unwrap(ctx), unwrapList(static_cast<size_t>(numElements),
+ elements, attrs)));
}
intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr) {
attributes.emplace_back(
Identifier::get(unwrap(elements[i].name), unwrap(ctx)),
unwrap(elements[i].attribute));
- return wrap(DictionaryAttr::get(attributes, unwrap(ctx)));
+ return wrap(DictionaryAttr::get(unwrap(ctx), attributes));
}
intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr) {
}
MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value) {
- return wrap(BoolAttr::get(value, unwrap(ctx)));
+ return wrap(BoolAttr::get(unwrap(ctx), value));
}
bool mlirBoolAttrGetValue(MlirAttribute attr) {
MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
intptr_t dataLength, const char *data,
MlirType type) {
- return wrap(
- OpaqueAttr::get(Identifier::get(unwrap(dialectNamespace), unwrap(ctx)),
- StringRef(data, dataLength), unwrap(type), unwrap(ctx)));
+ return wrap(OpaqueAttr::get(
+ unwrap(ctx), Identifier::get(unwrap(dialectNamespace), unwrap(ctx)),
+ StringRef(data, dataLength), unwrap(type)));
}
MlirStringRef mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr) {
}
MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str) {
- return wrap(StringAttr::get(unwrap(str), unwrap(ctx)));
+ return wrap(StringAttr::get(unwrap(ctx), unwrap(str)));
}
MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str) {
refs.reserve(numReferences);
for (intptr_t i = 0; i < numReferences; ++i)
refs.push_back(unwrap(references[i]).cast<FlatSymbolRefAttr>());
- return wrap(SymbolRefAttr::get(unwrap(symbol), refs, unwrap(ctx)));
+ return wrap(SymbolRefAttr::get(unwrap(ctx), unwrap(symbol), refs));
}
MlirStringRef mlirSymbolRefAttrGetRootReference(MlirAttribute attr) {
}
MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol) {
- return wrap(FlatSymbolRefAttr::get(unwrap(symbol), unwrap(ctx)));
+ return wrap(FlatSymbolRefAttr::get(unwrap(ctx), unwrap(symbol)));
}
MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr) {
auto blob = convertModuleToBlob(llvmModule, loc, name);
if (!blob)
return {};
- return StringAttr::get({blob->data(), blob->size()}, loc->getContext());
+ return StringAttr::get(loc->getContext(), {blob->data(), blob->size()});
}
std::unique_ptr<OperationPass<gpu::GPUModuleOp>>
// Set SPIR-V binary shader data as an attribute.
vulkanLaunchCallOp->setAttr(
kSPIRVBlobAttrName,
- StringAttr::get({binary.data(), binary.size()}, loc->getContext()));
+ StringAttr::get(loc->getContext(), {binary.data(), binary.size()}));
// Set entry point name as an attribute.
vulkanLaunchCallOp->setAttr(
kSPIRVEntryPointAttrName,
- StringAttr::get(launchOp.getKernelName(), loc->getContext()));
+ StringAttr::get(loc->getContext(), launchOp.getKernelName()));
launchOp.erase();
}
rewriter.create<LLVM::ConstantOp>(loc, llvmI32Type, executionModeAttr);
structValue = rewriter.create<LLVM::InsertValueOp>(
loc, structType, structValue, executionMode,
- ArrayAttr::get({rewriter.getIntegerAttr(rewriter.getI32Type(), 0)},
- context));
+ ArrayAttr::get(context,
+ {rewriter.getIntegerAttr(rewriter.getI32Type(), 0)}));
// Insert extra operands if they exist into execution mode info struct.
for (unsigned i = 0, e = values.size(); i < e; ++i) {
Value entry = rewriter.create<LLVM::ConstantOp>(loc, llvmI32Type, attr);
structValue = rewriter.create<LLVM::InsertValueOp>(
loc, structType, structValue, entry,
- ArrayAttr::get({rewriter.getIntegerAttr(rewriter.getI32Type(), 1),
- rewriter.getIntegerAttr(rewriter.getI32Type(), i)},
- context));
+ ArrayAttr::get(context,
+ {rewriter.getIntegerAttr(rewriter.getI32Type(), 1),
+ rewriter.getIntegerAttr(rewriter.getI32Type(), i)}));
}
rewriter.create<LLVM::ReturnOp>(loc, ArrayRef<Value>({structValue}));
rewriter.eraseOp(op);
switch (funcOp.function_control()) {
#define DISPATCH(functionControl, llvmAttr) \
case functionControl: \
- newFuncOp->setAttr("passthrough", ArrayAttr::get({llvmAttr}, context)); \
+ newFuncOp->setAttr("passthrough", ArrayAttr::get(context, {llvmAttr})); \
break;
DISPATCH(spirv::FunctionControl::Inline,
- StringAttr::get("alwaysinline", context));
+ StringAttr::get(context, "alwaysinline"));
DISPATCH(spirv::FunctionControl::DontInline,
- StringAttr::get("noinline", context));
+ StringAttr::get(context, "noinline"));
DISPATCH(spirv::FunctionControl::Pure,
- StringAttr::get("readonly", context));
+ StringAttr::get(context, "readonly"));
DISPATCH(spirv::FunctionControl::Const,
- StringAttr::get("readnone", context));
+ StringAttr::get(context, "readnone"));
#undef DISPATCH
if (failed(applyPartialConversion(m, target, std::move(patterns))))
signalPassFailure();
m->setAttr(LLVM::LLVMDialect::getDataLayoutAttrName(),
- StringAttr::get(this->dataLayout, m.getContext()));
+ StringAttr::get(m.getContext(), this->dataLayout));
}
};
} // end namespace
if (positionAttrs.size() > 1) {
auto oneDVectorType = reducedVectorTypeBack(vectorType);
auto nMinusOnePositionAttrs =
- ArrayAttr::get(positionAttrs.drop_back(), context);
+ ArrayAttr::get(context, positionAttrs.drop_back());
extracted = rewriter.create<LLVM::ExtractValueOp>(
loc, typeConverter->convertType(oneDVectorType), extracted,
nMinusOnePositionAttrs);
if (positionAttrs.size() > 1) {
oneDVectorType = reducedVectorTypeBack(destVectorType);
auto nMinusOnePositionAttrs =
- ArrayAttr::get(positionAttrs.drop_back(), context);
+ ArrayAttr::get(context, positionAttrs.drop_back());
extracted = rewriter.create<LLVM::ExtractValueOp>(
loc, typeConverter->convertType(oneDVectorType), extracted,
nMinusOnePositionAttrs);
// Potential insertion of resulting 1-D vector into array.
if (positionAttrs.size() > 1) {
auto nMinusOnePositionAttrs =
- ArrayAttr::get(positionAttrs.drop_back(), context);
+ ArrayAttr::get(context, positionAttrs.drop_back());
inserted = rewriter.create<LLVM::InsertValueOp>(loc, llvmResultType,
adaptor.dest(), inserted,
nMinusOnePositionAttrs);
}
ArrayRef<Attribute> mappingAsAttrs(mapping.data(), mapping.size());
ploopOp->setAttr(getMappingAttrName(),
- ArrayAttr::get(mappingAsAttrs, ploopOp.getContext()));
+ ArrayAttr::get(ploopOp.getContext(), mappingAsAttrs));
return success();
}
} // namespace gpu
if (genericAttrNamesSet.count(attr.first.strref()) > 0)
genericAttrs.push_back(attr);
if (!genericAttrs.empty()) {
- auto genericDictAttr = DictionaryAttr::get(genericAttrs, op.getContext());
+ auto genericDictAttr = DictionaryAttr::get(op.getContext(), genericAttrs);
p << genericDictAttr;
}
// Handle the corner case of the result being a rank 0 shaped type. Return an
// emtpy ArrayAttr.
if (mapsConsumer.empty() && !mapsProducer.empty())
- return ArrayAttr::get(ArrayRef<Attribute>(), context);
+ return ArrayAttr::get(context, ArrayRef<Attribute>());
if (mapsProducer.empty() || mapsConsumer.empty() ||
mapsProducer[0].getNumDims() < mapsConsumer[0].getNumDims() ||
mapsProducer.size() != mapsConsumer[0].getNumDims())
numLhsDims, /*numSymbols =*/0, reassociations, context)));
reassociations.clear();
}
- return ArrayAttr::get(reassociationMaps, context);
+ return ArrayAttr::get(context, reassociationMaps);
}
namespace {
// wrong, so abort.
if (!inversePermutation(concatAffineMaps(newIndexingMaps)))
return nullptr;
- return ArrayAttr::get(
- llvm::to_vector<4>(llvm::map_range(
- newIndexingMaps,
- [](AffineMap map) -> Attribute { return AffineMapAttr::get(map); })),
- context);
+ return ArrayAttr::get(context,
+ llvm::to_vector<4>(llvm::map_range(
+ newIndexingMaps, [](AffineMap map) -> Attribute {
+ return AffineMapAttr::get(map);
+ })));
}
/// Modify the region of indexed generic op to drop arguments corresponding to
rewriter.startRootUpdate(op);
op.indexing_mapsAttr(newIndexingMapAttr);
- op.iterator_typesAttr(ArrayAttr::get(newIteratorTypes, context));
+ op.iterator_typesAttr(ArrayAttr::get(context, newIteratorTypes));
(void)replaceBlockArgForUnitDimLoops(op, unitDims, rewriter);
rewriter.finalizeRootUpdate(op);
return success();
RankedTensorType::get(newShape, type.getElementType()),
AffineMap::get(indexMap.getNumDims(), indexMap.getNumSymbols(),
newIndexExprs, context),
- ArrayAttr::get(reassociationMaps, context)};
+ ArrayAttr::get(context, reassociationMaps)};
return info;
}
applyPermutationToVector(itTypesVector, interchangeVector);
op->setAttr(getIndexingMapsAttrName(),
- ArrayAttr::get(newIndexingMaps, context));
+ ArrayAttr::get(context, newIndexingMaps));
op->setAttr(getIteratorTypesAttrName(),
- ArrayAttr::get(itTypesVector, context));
+ ArrayAttr::get(context, itTypesVector));
return op;
}
});
for (auto &var : interfaceVarSet) {
interfaceVars.push_back(SymbolRefAttr::get(
- cast<spirv::GlobalVariableOp>(var).sym_name(), funcOp.getContext()));
+ funcOp.getContext(), cast<spirv::GlobalVariableOp>(var).sym_name()));
}
return success();
}
return a;
}
// If this is reached, all inputs were statically known passing.
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
}
static LogicalResult verify(AssumingAllOp op) {
// Both operands are not needed if one is a scalar.
if (operands[0] &&
operands[0].cast<DenseIntElementsAttr>().getNumElements() == 0)
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
if (operands[1] &&
operands[1].cast<DenseIntElementsAttr>().getNumElements() == 0)
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
if (operands[0] && operands[1]) {
auto lhsShape = llvm::to_vector<6>(
operands[1].cast<DenseIntElementsAttr>().getValues<int64_t>());
SmallVector<int64_t, 6> resultShape;
if (OpTrait::util::staticallyKnownBroadcastable(lhsShape, rhsShape))
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
}
// Lastly, see if folding can be completed based on what constraints are known
return nullptr;
if (OpTrait::util::staticallyKnownBroadcastable(lhsShape, rhsShape))
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
// Because a failing witness result here represents an eventual assertion
// failure, we do not replace it with a constant witness.
OpFoldResult CstrEqOp::fold(ArrayRef<Attribute> operands) {
if (llvm::all_of(operands,
[&](Attribute a) { return a && a == operands[0]; }))
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
// Because a failing witness result here represents an eventual assertion
// failure, we do not try to replace it with a constant witness. Similarly, we
OpFoldResult ShapeEqOp::fold(ArrayRef<Attribute> operands) {
if (lhs() == rhs())
- return BoolAttr::get(true, getContext());
+ return BoolAttr::get(getContext(), true);
auto lhs = operands[0].dyn_cast_or_null<DenseIntElementsAttr>();
if (lhs == nullptr)
return {};
auto rhs = operands[1].dyn_cast_or_null<DenseIntElementsAttr>();
if (rhs == nullptr)
return {};
- return BoolAttr::get(lhs == rhs, getContext());
+ return BoolAttr::get(getContext(), lhs == rhs);
}
//===----------------------------------------------------------------------===//
if (lhs() == rhs()) {
auto val = applyCmpPredicateToEqualOperands(getPredicate());
- return BoolAttr::get(val, getContext());
+ return BoolAttr::get(getContext(), val);
}
auto lhs = operands.front().dyn_cast_or_null<IntegerAttr>();
return {};
auto val = applyCmpPredicate(getPredicate(), lhs.getValue(), rhs.getValue());
- return BoolAttr::get(val, getContext());
+ return BoolAttr::get(getContext(), val);
}
//===----------------------------------------------------------------------===//
if (traitAttrsSet.count(attr.first.strref()) > 0)
attrs.push_back(attr);
- auto dictAttr = DictionaryAttr::get(attrs, op.getContext());
+ auto dictAttr = DictionaryAttr::get(op.getContext(), attrs);
p << op.getOperationName() << " " << dictAttr << " " << op.lhs() << ", ";
p << op.rhs() << ", " << op.acc();
if (op.masks().size() == 2)
auto attrs = llvm::map_range(values, [context](int64_t v) -> Attribute {
return IntegerAttr::get(IntegerType::get(context, 64), APInt(64, v));
});
- return ArrayAttr::get(llvm::to_vector<8>(attrs), context);
+ return ArrayAttr::get(context, llvm::to_vector<8>(attrs));
}
static LogicalResult verify(InsertStridedSliceOp op) {
UnitAttr Builder::getUnitAttr() { return UnitAttr::get(context); }
BoolAttr Builder::getBoolAttr(bool value) {
- return BoolAttr::get(value, context);
+ return BoolAttr::get(context, value);
}
DictionaryAttr Builder::getDictionaryAttr(ArrayRef<NamedAttribute> value) {
- return DictionaryAttr::get(value, context);
+ return DictionaryAttr::get(context, value);
}
IntegerAttr Builder::getIndexAttr(int64_t value) {
}
StringAttr Builder::getStringAttr(StringRef bytes) {
- return StringAttr::get(bytes, context);
+ return StringAttr::get(context, bytes);
}
ArrayAttr Builder::getArrayAttr(ArrayRef<Attribute> value) {
- return ArrayAttr::get(value, context);
+ return ArrayAttr::get(context, value);
}
FlatSymbolRefAttr Builder::getSymbolRefAttr(Operation *value) {
return getSymbolRefAttr(symName.getValue());
}
FlatSymbolRefAttr Builder::getSymbolRefAttr(StringRef value) {
- return SymbolRefAttr::get(value, getContext());
+ return SymbolRefAttr::get(getContext(), value);
}
SymbolRefAttr
Builder::getSymbolRefAttr(StringRef value,
ArrayRef<FlatSymbolRefAttr> nestedReferences) {
- return SymbolRefAttr::get(value, nestedReferences, getContext());
+ return SymbolRefAttr::get(getContext(), value, nestedReferences);
}
ArrayAttr Builder::getBoolArrayAttr(ArrayRef<bool> values) {
// ArrayAttr
//===----------------------------------------------------------------------===//
-ArrayAttr ArrayAttr::get(ArrayRef<Attribute> value, MLIRContext *context) {
+ArrayAttr ArrayAttr::get(MLIRContext *context, ArrayRef<Attribute> value) {
return Base::get(context, value);
}
return findDuplicateElement(array);
}
-DictionaryAttr DictionaryAttr::get(ArrayRef<NamedAttribute> value,
- MLIRContext *context) {
+DictionaryAttr DictionaryAttr::get(MLIRContext *context,
+ ArrayRef<NamedAttribute> value) {
if (value.empty())
return DictionaryAttr::getEmpty(context);
assert(llvm::all_of(value,
// SymbolRefAttr
//===----------------------------------------------------------------------===//
-FlatSymbolRefAttr SymbolRefAttr::get(StringRef value, MLIRContext *ctx) {
+FlatSymbolRefAttr SymbolRefAttr::get(MLIRContext *ctx, StringRef value) {
return Base::get(ctx, value, llvm::None).cast<FlatSymbolRefAttr>();
}
-SymbolRefAttr SymbolRefAttr::get(StringRef value,
- ArrayRef<FlatSymbolRefAttr> nestedReferences,
- MLIRContext *ctx) {
+SymbolRefAttr SymbolRefAttr::get(MLIRContext *ctx, StringRef value,
+ ArrayRef<FlatSymbolRefAttr> nestedReferences) {
return Base::get(ctx, value, nestedReferences);
}
IntegerAttr IntegerAttr::get(Type type, const APInt &value) {
if (type.isSignlessInteger(1))
- return BoolAttr::get(value.getBoolValue(), type.getContext());
+ return BoolAttr::get(type.getContext(), value.getBoolValue());
return Base::get(type.getContext(), type, value);
}
// OpaqueAttr
//===----------------------------------------------------------------------===//
-OpaqueAttr OpaqueAttr::get(Identifier dialect, StringRef attrData, Type type,
- MLIRContext *context) {
+OpaqueAttr OpaqueAttr::get(MLIRContext *context, Identifier dialect,
+ StringRef attrData, Type type) {
return Base::get(context, dialect, attrData, type);
}
// StringAttr
//===----------------------------------------------------------------------===//
-StringAttr StringAttr::get(StringRef bytes, MLIRContext *context) {
+StringAttr StringAttr::get(MLIRContext *context, StringRef bytes) {
return get(bytes, NoneType::get(context));
}
newAttrs.insert(attr);
for (auto &attr : getAttrs())
newAttrs.insert(attr);
- dest->setAttrs(DictionaryAttr::get(newAttrs.takeVector(), getContext()));
+ dest->setAttrs(DictionaryAttr::get(getContext(), newAttrs.takeVector()));
// Clone the body.
getBody().cloneInto(&dest.getBody(), mapper);
storage->setType(NoneType::get(ctx));
}
-BoolAttr BoolAttr::get(bool value, MLIRContext *context) {
+BoolAttr BoolAttr::get(MLIRContext *context, bool value) {
return value ? context->getImpl().trueAttr : context->getImpl().falseAttr;
}
ArrayRef<NamedAttribute> attributes,
BlockRange successors, unsigned numRegions) {
return create(location, name, resultTypes, operands,
- DictionaryAttr::get(attributes, location.getContext()),
+ DictionaryAttr::get(location.getContext(), attributes),
successors, numRegions);
}
assert(within->isAncestor(symbol) && "expected 'within' to be an ancestor");
MLIRContext *ctx = symbol->getContext();
- auto leafRef = FlatSymbolRefAttr::get(symbolName, ctx);
+ auto leafRef = FlatSymbolRefAttr::get(ctx, symbolName);
results.push_back(leafRef);
// Early exit for when 'within' is the parent of 'symbol'.
getNameIfSymbol(symbolTableOp, symbolNameId);
if (!symbolTableName)
return failure();
- results.push_back(SymbolRefAttr::get(*symbolTableName, nestedRefs, ctx));
+ results.push_back(SymbolRefAttr::get(ctx, *symbolTableName, nestedRefs));
symbolTableOp = symbolTableOp->getParentOp();
if (symbolTableOp == within)
break;
nestedRefs.insert(nestedRefs.begin(),
- FlatSymbolRefAttr::get(*symbolTableName, ctx));
+ FlatSymbolRefAttr::get(ctx, *symbolTableName));
} while (true);
return success();
}
/// Sets the name of the given symbol operation.
void SymbolTable::setSymbolName(Operation *symbol, StringRef name) {
symbol->setAttr(getSymbolAttrName(),
- StringAttr::get(name, symbol->getContext()));
+ StringAttr::get(symbol->getContext(), name));
}
/// Returns the visibility of the given symbol operation.
"unknown symbol visibility kind");
StringRef visName = vis == Visibility::Private ? "private" : "nested";
- symbol->setAttr(getVisibilityAttrName(), StringAttr::get(visName, ctx));
+ symbol->setAttr(getVisibilityAttrName(), StringAttr::get(ctx, visName));
}
/// Returns the nearest symbol table from a given operation `from`. Returns
// doesn't support parent references.
if (SymbolTable::getNearestSymbolTable(limit->getParentOp()) ==
symbol->getParentOp())
- return {{SymbolRefAttr::get(symName, symbol->getContext()), limit}};
+ return {{SymbolRefAttr::get(symbol->getContext(), symName), limit}};
return {};
}
template <typename IRUnit>
static SmallVector<SymbolScope, 1> collectSymbolScopes(StringRef symbol,
IRUnit *limit) {
- return {{SymbolRefAttr::get(symbol, limit->getContext()), limit}};
+ return {{SymbolRefAttr::get(limit->getContext(), symbol), limit}};
}
/// Returns true if the given reference 'SubRef' is a sub reference of the
if (auto dictAttr = container.dyn_cast<DictionaryAttr>()) {
auto newAttrs = llvm::to_vector<4>(dictAttr.getValue());
updateAttrs(make_second_range(newAttrs));
- return DictionaryAttr::get(newAttrs, dictAttr.getContext());
+ return DictionaryAttr::get(dictAttr.getContext(), newAttrs);
}
auto newAttrs = llvm::to_vector<4>(container.cast<ArrayAttr>().getValue());
updateAttrs(newAttrs);
- return ArrayAttr::get(newAttrs, container.getContext());
+ return ArrayAttr::get(container.getContext(), newAttrs);
}
/// Generates a new symbol reference attribute with a new leaf reference.
return newLeafAttr;
auto nestedRefs = llvm::to_vector<2>(oldAttr.getNestedReferences());
nestedRefs.back() = newLeafAttr;
- return SymbolRefAttr::get(oldAttr.getRootReference(), nestedRefs,
- oldAttr.getContext());
+ return SymbolRefAttr::get(oldAttr.getContext(), oldAttr.getRootReference(),
+ nestedRefs);
}
/// The implementation of SymbolTable::replaceAllSymbolUses below.
// Generate a new attribute to replace the given attribute.
MLIRContext *ctx = limit->getContext();
- FlatSymbolRefAttr newLeafAttr = FlatSymbolRefAttr::get(newSymbol, ctx);
+ FlatSymbolRefAttr newLeafAttr = FlatSymbolRefAttr::get(ctx, newSymbol);
for (SymbolScope &scope : collectSymbolScopes(symbol, limit)) {
SymbolRefAttr newAttr = generateNewRefAttr(scope.symbol, newLeafAttr);
auto walkFn = [&](SymbolTable::SymbolUse symbolUse,
if (useRef != scope.symbol) {
if (scope.symbol.isa<FlatSymbolRefAttr>()) {
replacementRef =
- SymbolRefAttr::get(newSymbol, useRef.getNestedReferences(), ctx);
+ SymbolRefAttr::get(ctx, newSymbol, useRef.getNestedReferences());
} else {
auto nestedRefs = llvm::to_vector<4>(useRef.getNestedReferences());
nestedRefs[scope.symbol.getNestedReferences().size() - 1] =
newLeafAttr;
replacementRef =
- SymbolRefAttr::get(useRef.getRootReference(), nestedRefs, ctx);
+ SymbolRefAttr::get(ctx, useRef.getRootReference(), nestedRefs);
}
}
return Attribute();
return type ? StringAttr::get(val, type)
- : StringAttr::get(val, getContext());
+ : StringAttr::get(getContext(), val);
}
// Parse a symbol reference attribute.
std::string nameStr = getToken().getSymbolReference();
consumeToken(Token::at_identifier);
- nestedRefs.push_back(SymbolRefAttr::get(nameStr, getContext()));
+ nestedRefs.push_back(SymbolRefAttr::get(getContext(), nameStr));
}
return builder.getSymbolRefAttr(nameStr, nestedRefs);
body << " ::mlir::MLIRContext* ctx = getContext();\n";
body << " ::mlir::Builder odsBuilder(ctx); (void)odsBuilder;\n";
- body << " return ::mlir::DictionaryAttr::get({\n";
+ body << " return ::mlir::DictionaryAttr::get(";
+ body << " ctx, {\n";
interleave(
derivedAttrs, body,
[&](const NamedAttribute &namedAttr) {
<< "}";
},
",\n");
- body << "\n }, ctx);";
+ body << "});";
}
}
}
}
const char *getEndInfo = R"(
- ::mlir::Attribute dict = ::mlir::DictionaryAttr::get(fields, context);
+ ::mlir::Attribute dict = ::mlir::DictionaryAttr::get(context, fields);
return dict.dyn_cast<{0}>();
}
)";
newValues.push_back(wrongAttr);
// Make a new DictionaryAttr and validate.
- auto badDictionary = mlir::DictionaryAttr::get(newValues, &context);
+ auto badDictionary = mlir::DictionaryAttr::get(&context, newValues);
ASSERT_FALSE(test::TestStruct::classof(badDictionary));
}
auto wrongAttr = mlir::NamedAttribute(wrongId, expectedValues[0].second);
newValues.push_back(wrongAttr);
- auto badDictionary = mlir::DictionaryAttr::get(newValues, &context);
+ auto badDictionary = mlir::DictionaryAttr::get(&context, newValues);
ASSERT_FALSE(test::TestStruct::classof(badDictionary));
}
auto wrongAttr = mlir::NamedAttribute(id, elementsAttr);
newValues.push_back(wrongAttr);
- auto badDictionary = mlir::DictionaryAttr::get(newValues, &context);
+ auto badDictionary = mlir::DictionaryAttr::get(&context, newValues);
ASSERT_FALSE(test::TestStruct::classof(badDictionary));
}
expectedValues.begin() + 1, expectedValues.end());
// Make a new DictionaryAttr and validate it is not a validate TestStruct.
- auto badDictionary = mlir::DictionaryAttr::get(newValues, &context);
+ auto badDictionary = mlir::DictionaryAttr::get(&context, newValues);
ASSERT_FALSE(test::TestStruct::classof(badDictionary));
}