clang 24.0.0git
LowerToLLVMMetadata.h
Go to the documentation of this file.
1//===- LowerToLLVMMetadata.h - CIR metadata lowering ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef CLANG_CIR_LOWERING_DIRECTTOLLVM_LOWERTOLLVMMETADATA_H
10#define CLANG_CIR_LOWERING_DIRECTTOLLVM_LOWERTOLLVMMETADATA_H
11
12#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
13#include "mlir/IR/Attributes.h"
14#include "mlir/IR/BuiltinAttributes.h"
15#include "mlir/IR/BuiltinTypes.h"
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19
20namespace mlir {
21class MLIRContext;
22} // namespace mlir
23
24namespace cir {
25class MaxWorkGroupSizeAttr;
26
27namespace direct {
28
30public:
31 explicit LLVMMetadataNodeBuilder(mlir::MLIRContext *ctx) : ctx(ctx) {}
32
33 mlir::LLVM::MDConstantAttr getI32(unsigned value) const {
34 mlir::IntegerType intTy = mlir::IntegerType::get(ctx, 32);
35 mlir::IntegerAttr intAttr = mlir::IntegerAttr::get(intTy, value);
36 return mlir::LLVM::MDConstantAttr::get(ctx, intAttr);
37 }
38
39 mlir::LLVM::MDStringAttr getString(llvm::StringRef value) const {
40 return mlir::LLVM::MDStringAttr::get(ctx,
41 mlir::StringAttr::get(ctx, value));
42 }
43
44 mlir::LLVM::MDNodeAttr
46 return mlir::LLVM::MDNodeAttr::get(ctx, metadata);
47 }
48
49 mlir::LLVM::MDNodeAttr getI32Node(llvm::ArrayRef<unsigned> values) const {
51 for (unsigned value : values)
52 metadata.push_back(getI32(value));
53 return getNode(metadata);
54 }
55
56 mlir::LLVM::MDNodeAttr getStringNode(mlir::ArrayAttr attrs) const {
58 for (mlir::StringAttr attr : attrs.getAsRange<mlir::StringAttr>())
59 metadata.push_back(getString(attr.getValue()));
60 return getNode(metadata);
61 }
62
63private:
64 mlir::MLIRContext *ctx;
65};
66
68public:
69 FunctionMetadataLowering(mlir::MLIRContext *ctx);
70
71 bool lower(mlir::NamedAttribute attr, bool includeFunctionOnlyAttrs);
73
74private:
75 void lower(cir::MaxWorkGroupSizeAttr maxWGSize);
76
77 mlir::MLIRContext *ctx;
79};
80
81} // namespace direct
82} // namespace cir
83
84#endif // CLANG_CIR_LOWERING_DIRECTTOLLVM_LOWERTOLLVMMETADATA_H
void appendAttrs(llvm::SmallVectorImpl< mlir::NamedAttribute > &result) const
bool lower(mlir::NamedAttribute attr, bool includeFunctionOnlyAttrs)
mlir::LLVM::MDStringAttr getString(llvm::StringRef value) const
mlir::LLVM::MDNodeAttr getI32Node(llvm::ArrayRef< unsigned > values) const
mlir::LLVM::MDNodeAttr getNode(llvm::ArrayRef< mlir::Attribute > metadata) const
mlir::LLVM::MDConstantAttr getI32(unsigned value) const
LLVMMetadataNodeBuilder(mlir::MLIRContext *ctx)
mlir::LLVM::MDNodeAttr getStringNode(mlir::ArrayAttr attrs) const