52 lines · cpp
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"6 7mlir::MLIRContext Context;8 9auto Identifier = mlir::StringAttr::get(&Context, "foo");10mlir::OperationName OperationName("FooOp", &Context);11 12mlir::Type Type(nullptr);13mlir::Type IndexType = mlir::IndexType::get(&Context);14mlir::Type IntegerType =15 mlir::IntegerType::get(&Context, 3, mlir::IntegerType::Unsigned);16mlir::Type FloatType = mlir::Float32Type::get(&Context);17mlir::Type MemRefType = mlir::MemRefType::get({4, 5}, FloatType);18mlir::Type UnrankedMemRefType = mlir::UnrankedMemRefType::get(IntegerType, 6);19mlir::Type VectorType = mlir::VectorType::get({1, 2}, FloatType);20mlir::Type TupleType =21 mlir::TupleType::get(&Context, mlir::TypeRange({IndexType, FloatType}));22 23 24mlir::detail::OutOfLineOpResult Result(FloatType, 42);25mlir::Value Value(&Result);26 27auto UnknownLoc = mlir::UnknownLoc::get(&Context);28auto FileLineColLoc = mlir::FileLineColLoc::get(&Context, "file", 7, 8);29auto OpaqueLoc = mlir::OpaqueLoc::get<uintptr_t>(9, &Context);30auto NameLoc = mlir::NameLoc::get(Identifier);31auto CallSiteLoc = mlir::CallSiteLoc::get(FileLineColLoc, OpaqueLoc);32auto FusedLoc = mlir::FusedLoc::get(&Context, {FileLineColLoc, NameLoc});33 34mlir::Attribute UnitAttr = mlir::UnitAttr::get(&Context);35mlir::Attribute FloatAttr = mlir::FloatAttr::get(FloatType, 1.0);36mlir::Attribute IntegerAttr = mlir::IntegerAttr::get(IntegerType, 10);37mlir::Attribute TypeAttr = mlir::TypeAttr::get(IndexType);38mlir::Attribute ArrayAttr = mlir::ArrayAttr::get(&Context, {UnitAttr});39mlir::Attribute StringAttr = mlir::StringAttr::get(&Context, "foo");40mlir::Attribute ElementsAttr = mlir::DenseElementsAttr::get(41 mlir::cast<mlir::ShapedType>(VectorType), llvm::ArrayRef<float>{2.0f, 3.0f});42 43int main() {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);48 };49 dont_strip(Value);50 return result; // Non-zero return value is OK.51}52