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: &Context, bytes: "foo");
10mlir::OperationName OperationName("FooOp", &Context);
11
12mlir::Type Type(nullptr);
13mlir::Type IndexType = mlir::IndexType::get(context: &Context);
14mlir::Type IntegerType =
15 mlir::IntegerType::get(context: &Context, width: 3, signedness: mlir::IntegerType::Unsigned);
16mlir::Type FloatType = mlir::Float32Type::get(context: &Context);
17mlir::Type MemRefType = mlir::MemRefType::get(shape: {4, 5}, elementType: FloatType);
18mlir::Type UnrankedMemRefType = mlir::UnrankedMemRefType::get(elementType: IntegerType, memorySpace: 6);
19mlir::Type VectorType = mlir::VectorType::get(shape: {1, 2}, elementType: FloatType);
20mlir::Type TupleType =
21 mlir::TupleType::get(context: &Context, elementTypes: mlir::TypeRange({IndexType, FloatType}));
22
23
24mlir::detail::OutOfLineOpResult Result(FloatType, 42);
25mlir::Value Value(&Result);
26
27auto UnknownLoc = mlir::UnknownLoc::get(context: &Context);
28auto FileLineColLoc = mlir::FileLineColLoc::get(context: &Context, fileName: "file", line: 7, column: 8);
29auto OpaqueLoc = mlir::OpaqueLoc::get<uintptr_t>(underlyingLocation: 9, context: &Context);
30auto NameLoc = mlir::NameLoc::get(name: Identifier);
31auto CallSiteLoc = mlir::CallSiteLoc::get(callee: FileLineColLoc, caller: OpaqueLoc);
32auto FusedLoc = mlir::FusedLoc::get(context: &Context, locs: {FileLineColLoc, NameLoc});
33
34mlir::Attribute UnitAttr = mlir::UnitAttr::get(context: &Context);
35mlir::Attribute FloatAttr = mlir::FloatAttr::get(type: FloatType, value: 1.0);
36mlir::Attribute IntegerAttr = mlir::IntegerAttr::get(type: IntegerType, value: 10);
37mlir::Attribute TypeAttr = mlir::TypeAttr::get(type: IndexType);
38mlir::Attribute ArrayAttr = mlir::ArrayAttr::get(context: &Context, value: {UnitAttr});
39mlir::Attribute StringAttr = mlir::StringAttr::get(context: &Context, bytes: "foo");
40mlir::Attribute ElementsAttr = mlir::DenseElementsAttr::get(
41 type: mlir::cast<mlir::ShapedType>(Val&: VectorType), values: 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

source code of cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp