1 #include "mlir/IR/BuiltinAttributes.h"
2 #include "mlir/IR/BuiltinTypes.h"
3 #include "mlir/IR/Location.h"
4 #include "mlir/IR/MLIRContext.h"
5 #include "mlir/IR/OperationSupport.h"
7 mlir::MLIRContext Context
;
9 auto Identifier
= mlir::StringAttr::get(&Context
, "foo");
10 mlir::OperationName
OperationName("FooOp", &Context
);
12 mlir::Type
Type(nullptr);
13 mlir::Type IndexType
= mlir::IndexType::get(&Context
);
14 mlir::Type IntegerType
=
15 mlir::IntegerType::get(&Context
, 3, mlir::IntegerType::Unsigned
);
16 mlir::Type FloatType
= mlir::Float32Type::get(&Context
);
17 mlir::Type MemRefType
= mlir::MemRefType::get({4, 5}, FloatType
);
18 mlir::Type UnrankedMemRefType
= mlir::UnrankedMemRefType::get(IntegerType
, 6);
19 mlir::Type VectorType
= mlir::VectorType::get({1, 2}, FloatType
);
20 mlir::Type TupleType
=
21 mlir::TupleType::get(&Context
, mlir::TypeRange({IndexType
, FloatType
}));
24 mlir::detail::OutOfLineOpResult
Result(FloatType
, 42);
25 mlir::Value
Value(&Result
);
27 auto UnknownLoc
= mlir::UnknownLoc::get(&Context
);
28 auto FileLineColLoc
= mlir::FileLineColLoc::get(&Context
, "file", 7, 8);
29 auto OpaqueLoc
= mlir::OpaqueLoc::get
<uintptr_t>(9, &Context
);
30 auto NameLoc
= mlir::NameLoc::get(Identifier
);
31 auto CallSiteLoc
= mlir::CallSiteLoc::get(FileLineColLoc
, OpaqueLoc
);
32 auto FusedLoc
= mlir::FusedLoc::get(&Context
, {FileLineColLoc
, NameLoc
});
34 mlir::Attribute UnitAttr
= mlir::UnitAttr::get(&Context
);
35 mlir::Attribute FloatAttr
= mlir::FloatAttr::get(FloatType
, 1.0);
36 mlir::Attribute IntegerAttr
= mlir::IntegerAttr::get(IntegerType
, 10);
37 mlir::Attribute TypeAttr
= mlir::TypeAttr::get(IndexType
);
38 mlir::Attribute ArrayAttr
= mlir::ArrayAttr::get(&Context
, {UnitAttr
});
39 mlir::Attribute StringAttr
= mlir::StringAttr::get(&Context
, "foo");
40 mlir::Attribute ElementsAttr
= mlir::DenseElementsAttr::get(
41 VectorType
.cast
<mlir::ShapedType
>(), llvm::ArrayRef
<float>{2.0f
, 3.0f
});
44 // Reference symbols that might otherwise be stripped.
45 std::uintptr_t result
= 0;
46 auto dont_strip
= [&](const auto &val
) {
47 result
+= reinterpret_cast<std::uintptr_t>(&val
);
50 return result
; // Non-zero return value is OK.