[Mlir-commits] [mlir] [MLIR][LLVM] Implement LLVM dialect support for global aliases (PR #125295)
Bruno Cardoso Lopes
llvmlistbot at llvm.org
Mon Feb 3 16:07:50 PST 2025
================
@@ -2422,6 +2422,178 @@ LogicalResult GlobalDtorsOp::verify() {
return success();
}
+//===----------------------------------------------------------------------===//
+// Builder, printer and verifier for LLVM::GlobalOp.
+//===----------------------------------------------------------------------===//
+
+void AliasOp::build(OpBuilder &builder, OperationState &result, Type type,
+ Linkage linkage, StringRef name, unsigned addrSpace,
+ bool dsoLocal, bool threadLocal, SymbolRefAttr comdat,
+ ArrayRef<NamedAttribute> attrs,
+ ArrayRef<Attribute> dbgExprs) {
+ result.addAttribute(getSymNameAttrName(result.name),
+ builder.getStringAttr(name));
+ result.addAttribute(getAliasTypeAttrName(result.name), TypeAttr::get(type));
+ if (dsoLocal)
+ result.addAttribute(getDsoLocalAttrName(result.name),
+ builder.getUnitAttr());
+ if (threadLocal)
+ result.addAttribute(getThreadLocal_AttrName(result.name),
+ builder.getUnitAttr());
+ if (comdat)
+ result.addAttribute(getComdatAttrName(result.name), comdat);
+
+ result.addAttribute(getLinkageAttrName(result.name),
+ LinkageAttr::get(builder.getContext(), linkage));
+ if (addrSpace != 0)
+ result.addAttribute(getAddrSpaceAttrName(result.name),
+ builder.getI32IntegerAttr(addrSpace));
+ result.attributes.append(attrs.begin(), attrs.end());
+
+ result.addRegion();
+}
+
+void AliasOp::print(OpAsmPrinter &p) {
+ p << ' ' << stringifyLinkage(getLinkage()) << ' ';
+ StringRef visibility = stringifyVisibility(getVisibility_());
+ if (!visibility.empty())
+ p << visibility << ' ';
+ if (getThreadLocal_())
+ p << "thread_local ";
+ if (auto unnamedAddr = getUnnamedAddr()) {
+ StringRef str = stringifyUnnamedAddr(*unnamedAddr);
+ if (!str.empty())
+ p << str << ' ';
+ }
+ p.printSymbolName(getSymName());
+ if (auto comdat = getComdat())
+ p << " comdat(" << *comdat << ')';
+
+ // Note that the alignment attribute is printed using the
+ // default syntax here, even though it is an inherent attribute
+ // (as defined in https://mlir.llvm.org/docs/LangRef/#attributes)
+ p.printOptionalAttrDict((*this)->getAttrs(),
+ {SymbolTable::getSymbolAttrName(),
+ getAliasTypeAttrName(), getLinkageAttrName(),
+ getUnnamedAddrAttrName(), getThreadLocal_AttrName(),
+ getVisibility_AttrName(), getComdatAttrName(),
+ getUnnamedAddrAttrName()});
+
+ // Print the trailing type
+ p << " : " << getType();
+
+ Region &initializer = getInitializerRegion();
+ if (!initializer.empty()) {
+ p << ' ';
+ p.printRegion(initializer, /*printEntryBlockArgs=*/false);
+ }
+}
+
+// operation ::= `llvm.mlir.alias` linkage? visibility?
+// (`unnamed_addr` | `local_unnamed_addr`)?
+// `thread_local`? `@` identifier
+// `(` attribute? `)` (`comdat(` symbol-ref-id `)`)?
+// attribute-list? (`:` type)? region
+//
+// The type can be omitted for string attributes, in which case it will be
+// inferred from the value of the string as [strlen(value) x i8].
+ParseResult AliasOp::parse(OpAsmParser &parser, OperationState &result) {
----------------
bcardosolopes wrote:
Took a stab into some level of sharing, don't want to abuse templates much tho
https://github.com/llvm/llvm-project/pull/125295
More information about the Mlir-commits
mailing list