@@ -1579,38 +1579,38 @@ LogicalResult AddressOfOp::verify() {
1579
1579
// Builder, printer and verifier for LLVM::GlobalOp.
1580
1580
// ===----------------------------------------------------------------------===//
1581
1581
1582
- // / Returns the name used for the linkage attribute. This *must* correspond to
1583
- // / the name of the attribute in ODS.
1584
- static StringRef getLinkageAttrName () { return " linkage" ; }
1585
-
1586
- // / Returns the name used for the unnamed_addr attribute. This *must* correspond
1587
- // / to the name of the attribute in ODS.
1588
- static StringRef getUnnamedAddrAttrName () { return " unnamed_addr" ; }
1589
-
1590
1582
void GlobalOp::build (OpBuilder &builder, OperationState &result, Type type,
1591
1583
bool isConstant, Linkage linkage, StringRef name,
1592
1584
Attribute value, uint64_t alignment, unsigned addrSpace,
1593
- bool dsoLocal, ArrayRef<NamedAttribute> attrs) {
1594
- result.addAttribute (SymbolTable::getSymbolAttrName (),
1585
+ bool dsoLocal, bool threadLocal,
1586
+ ArrayRef<NamedAttribute> attrs) {
1587
+ result.addAttribute (getSymNameAttrName (result.name ),
1595
1588
builder.getStringAttr (name));
1596
- result.addAttribute (" global_type " , TypeAttr::get (type));
1589
+ result.addAttribute (getGlobalTypeAttrName (result. name ) , TypeAttr::get (type));
1597
1590
if (isConstant)
1598
- result.addAttribute (" constant" , builder.getUnitAttr ());
1591
+ result.addAttribute (getConstantAttrName (result.name ),
1592
+ builder.getUnitAttr ());
1599
1593
if (value)
1600
- result.addAttribute (" value " , value);
1594
+ result.addAttribute (getValueAttrName (result. name ) , value);
1601
1595
if (dsoLocal)
1602
- result.addAttribute (" dso_local" , builder.getUnitAttr ());
1596
+ result.addAttribute (getDsoLocalAttrName (result.name ),
1597
+ builder.getUnitAttr ());
1598
+ if (threadLocal)
1599
+ result.addAttribute (getThreadLocal_AttrName (result.name ),
1600
+ builder.getUnitAttr ());
1603
1601
1604
1602
// Only add an alignment attribute if the "alignment" input
1605
1603
// is different from 0. The value must also be a power of two, but
1606
1604
// this is tested in GlobalOp::verify, not here.
1607
1605
if (alignment != 0 )
1608
- result.addAttribute (" alignment" , builder.getI64IntegerAttr (alignment));
1606
+ result.addAttribute (getAlignmentAttrName (result.name ),
1607
+ builder.getI64IntegerAttr (alignment));
1609
1608
1610
- result.addAttribute (:: getLinkageAttrName (),
1609
+ result.addAttribute (getLinkageAttrName (result. name ),
1611
1610
LinkageAttr::get (builder.getContext (), linkage));
1612
1611
if (addrSpace != 0 )
1613
- result.addAttribute (" addr_space" , builder.getI32IntegerAttr (addrSpace));
1612
+ result.addAttribute (getAddrSpaceAttrName (result.name ),
1613
+ builder.getI32IntegerAttr (addrSpace));
1614
1614
result.attributes .append (attrs.begin (), attrs.end ());
1615
1615
result.addRegion ();
1616
1616
}
@@ -1622,6 +1622,8 @@ void GlobalOp::print(OpAsmPrinter &p) {
1622
1622
if (!str.empty ())
1623
1623
p << str << ' ' ;
1624
1624
}
1625
+ if (getThreadLocal_ ())
1626
+ p << " thread_local " ;
1625
1627
if (getConstant ())
1626
1628
p << " constant " ;
1627
1629
p.printSymbolName (getSymName ());
@@ -1632,10 +1634,11 @@ void GlobalOp::print(OpAsmPrinter &p) {
1632
1634
// Note that the alignment attribute is printed using the
1633
1635
// default syntax here, even though it is an inherent attribute
1634
1636
// (as defined in https://mlir.llvm.org/docs/LangRef/#attributes)
1635
- p.printOptionalAttrDict ((*this )->getAttrs (),
1636
- {SymbolTable::getSymbolAttrName (), " global_type" ,
1637
- " constant" , " value" , getLinkageAttrName (),
1638
- getUnnamedAddrAttrName ()});
1637
+ p.printOptionalAttrDict (
1638
+ (*this )->getAttrs (),
1639
+ {SymbolTable::getSymbolAttrName (), getGlobalTypeAttrName (),
1640
+ getConstantAttrName (), getValueAttrName (), getLinkageAttrName (),
1641
+ getUnnamedAddrAttrName (), getThreadLocal_AttrName ()});
1639
1642
1640
1643
// Print the trailing type unless it's a string global.
1641
1644
if (getValueOrNull ().dyn_cast_or_null <StringAttr>())
@@ -1702,28 +1705,35 @@ static RetTy parseOptionalLLVMKeyword(OpAsmParser &parser,
1702
1705
ParseResult GlobalOp::parse (OpAsmParser &parser, OperationState &result) {
1703
1706
MLIRContext *ctx = parser.getContext ();
1704
1707
// Parse optional linkage, default to External.
1705
- result.addAttribute (:: getLinkageAttrName (),
1708
+ result.addAttribute (getLinkageAttrName (result. name ),
1706
1709
LLVM::LinkageAttr::get (
1707
1710
ctx, parseOptionalLLVMKeyword<Linkage>(
1708
1711
parser, result, LLVM::Linkage::External)));
1712
+
1713
+ if (succeeded (parser.parseOptionalKeyword (" thread_local" )))
1714
+ result.addAttribute (getThreadLocal_AttrName (result.name ),
1715
+ parser.getBuilder ().getUnitAttr ());
1716
+
1709
1717
// Parse optional UnnamedAddr, default to None.
1710
- result.addAttribute (:: getUnnamedAddrAttrName (),
1718
+ result.addAttribute (getUnnamedAddrAttrName (result. name ),
1711
1719
parser.getBuilder ().getI64IntegerAttr (
1712
1720
parseOptionalLLVMKeyword<UnnamedAddr, int64_t >(
1713
1721
parser, result, LLVM::UnnamedAddr::None)));
1714
1722
1715
1723
if (succeeded (parser.parseOptionalKeyword (" constant" )))
1716
- result.addAttribute (" constant" , parser.getBuilder ().getUnitAttr ());
1724
+ result.addAttribute (getConstantAttrName (result.name ),
1725
+ parser.getBuilder ().getUnitAttr ());
1717
1726
1718
1727
StringAttr name;
1719
- if (parser.parseSymbolName (name, SymbolTable::getSymbolAttrName ( ),
1728
+ if (parser.parseSymbolName (name, getSymNameAttrName (result. name ),
1720
1729
result.attributes ) ||
1721
1730
parser.parseLParen ())
1722
1731
return failure ();
1723
1732
1724
1733
Attribute value;
1725
1734
if (parser.parseOptionalRParen ()) {
1726
- if (parser.parseAttribute (value, " value" , result.attributes ) ||
1735
+ if (parser.parseAttribute (value, getValueAttrName (result.name ),
1736
+ result.attributes ) ||
1727
1737
parser.parseRParen ())
1728
1738
return failure ();
1729
1739
}
@@ -1755,7 +1765,8 @@ ParseResult GlobalOp::parse(OpAsmParser &parser, OperationState &result) {
1755
1765
return failure ();
1756
1766
}
1757
1767
1758
- result.addAttribute (" global_type" , TypeAttr::get (types[0 ]));
1768
+ result.addAttribute (getGlobalTypeAttrName (result.name ),
1769
+ TypeAttr::get (types[0 ]));
1759
1770
return success ();
1760
1771
}
1761
1772
@@ -1976,7 +1987,7 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
1976
1987
builder.getStringAttr (name));
1977
1988
result.addAttribute (getFunctionTypeAttrName (result.name ),
1978
1989
TypeAttr::get (type));
1979
- result.addAttribute (:: getLinkageAttrName (),
1990
+ result.addAttribute (getLinkageAttrName (result. name ),
1980
1991
LinkageAttr::get (builder.getContext (), linkage));
1981
1992
result.attributes .append (attrs.begin (), attrs.end ());
1982
1993
if (dsoLocal)
@@ -2036,7 +2047,7 @@ buildLLVMFunctionType(OpAsmParser &parser, SMLoc loc, ArrayRef<Type> inputs,
2036
2047
ParseResult LLVMFuncOp::parse (OpAsmParser &parser, OperationState &result) {
2037
2048
// Default to external linkage if no keyword is provided.
2038
2049
result.addAttribute (
2039
- :: getLinkageAttrName (),
2050
+ getLinkageAttrName (result. name ),
2040
2051
LinkageAttr::get (parser.getContext (),
2041
2052
parseOptionalLLVMKeyword<Linkage>(
2042
2053
parser, result, LLVM::Linkage::External)));
0 commit comments