[clang] [CIR] Add metadata type, attributes and metadata_as_value op. (PR #204190)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 22 21:54:34 PDT 2026
================
@@ -464,6 +464,21 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
return cir::ConstantOp::create(*this, loc, cir::ZeroAttr::get(ty));
}
+ //===--------------------------------------------------------------------===//
+ // Metadata creation helpers
+ //===--------------------------------------------------------------------===//
+ cir::MDStringAttr getMDStringAttr(llvm::StringRef str) {
+ return cir::MDStringAttr::get(getContext(), getStringAttr(str));
+ }
+
+ cir::MDNodeAttr getMDNodeAttr(llvm::ArrayRef<mlir::Attribute> operands) {
+ return cir::MDNodeAttr::get(getContext(), operands);
+ }
+
+ mlir::Value createMetadataAsValue(mlir::Location loc, mlir::Attribute md) {
+ return cir::MetadataAsValueOp::create(*this, loc, md);
----------------
skc7 wrote:
Both create forms exist in the generated `CIROps.cpp.inc`: the type-omitting one (`create(OpBuilder&, Location, Attribute)`) infers the fixed `!cir.metadata` result via `inferReturnTypes`, and the explicit-type one (`create(OpBuilder&, Location, Type, Attribute)`) is used where a Type is already in hand. `createMetadataAsValue` uses the former. `materializeConstant` uses the latter. Both build the same op.
https://github.com/llvm/llvm-project/pull/204190
More information about the cfe-commits
mailing list