@@ -129,6 +129,11 @@ namespace xd {
129
129
state.setError ();
130
130
});
131
131
132
+ builder.add< StringAttrOp> ([](::llvm_dialects ::VerifierState & state, StringAttrOp & op) {
133
+ if (! op.verifier (state.out ()))
134
+ state.setError ();
135
+ });
136
+
132
137
builder.add< WriteOp> ([](::llvm_dialects ::VerifierState & state, WriteOp & op) {
133
138
if (! op.verifier (state.out ()))
134
139
state.setError ();
@@ -154,21 +159,21 @@ namespace xd {
154
159
::llvm ::AttrBuilder attrBuilder{context};
155
160
attrBuilder.addAttribute (::llvm ::Attribute ::NoUnwind);
156
161
attrBuilder.addAttribute (::llvm ::Attribute ::WillReturn);
157
- attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (:: llvm :: ModRefInfo ::Ref ));
162
+ attrBuilder.addMemoryAttr (::llvm ::MemoryEffects :: none ( ));
158
163
m_attributeLists[0 ] = ::llvm ::AttributeList ::get (context, ::llvm ::AttributeList ::FunctionIndex, attrBuilder);
159
164
}
160
165
{
161
166
::llvm ::AttrBuilder attrBuilder{context};
162
167
attrBuilder.addAttribute (::llvm ::Attribute ::NoUnwind);
163
168
attrBuilder.addAttribute (::llvm ::Attribute ::WillReturn);
164
- attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (::llvm ::MemoryEffects :: Location ::InaccessibleMem, :: llvm :: ModRefInfo ::Mod ));
169
+ attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (::llvm ::ModRefInfo ::Ref ));
165
170
m_attributeLists[1 ] = ::llvm ::AttributeList ::get (context, ::llvm ::AttributeList ::FunctionIndex, attrBuilder);
166
171
}
167
172
{
168
173
::llvm ::AttrBuilder attrBuilder{context};
169
174
attrBuilder.addAttribute (::llvm ::Attribute ::NoUnwind);
170
175
attrBuilder.addAttribute (::llvm ::Attribute ::WillReturn);
171
- attrBuilder.addMemoryAttr (::llvm ::MemoryEffects :: none ( ));
176
+ attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (:: llvm :: MemoryEffects :: Location ::InaccessibleMem, :: llvm :: ModRefInfo ::Mod ));
172
177
m_attributeLists[2 ] = ::llvm ::AttributeList ::get (context, ::llvm ::AttributeList ::FunctionIndex, attrBuilder);
173
178
}
174
179
{
@@ -329,7 +334,7 @@ return true;
329
334
330
335
331
336
const ::llvm ::AttributeList attrs
332
- = ExampleDialect ::get (context).getAttributeList (2 );
337
+ = ExampleDialect ::get (context).getAttributeList (0 );
333
338
auto fnType = ::llvm ::FunctionType ::get (::llvm ::IntegerType ::get (context, 32 ), {
334
339
lhs- > getType (),
335
340
rhs- > getType (),
@@ -451,7 +456,7 @@ uint32_t const extra = getExtra();
451
456
452
457
453
458
const ::llvm ::AttributeList attrs
454
- = ExampleDialect ::get (context).getAttributeList (2 );
459
+ = ExampleDialect ::get (context).getAttributeList (0 );
455
460
456
461
std ::string mangledName =
457
462
::llvm_dialects ::getMangledName (s_name, {lhs- > getType ()});
546
551
547
552
548
553
const ::llvm ::AttributeList attrs
549
- = ExampleDialect ::get (context).getAttributeList (2 );
554
+ = ExampleDialect ::get (context).getAttributeList (0 );
550
555
551
556
std ::string mangledName =
552
557
::llvm_dialects ::getMangledName (s_name, {::llvm ::cast< XdVectorType> (vector- > getType ())- > getElementType ()});
@@ -650,7 +655,7 @@ index
650
655
651
656
652
657
const ::llvm ::AttributeList attrs
653
- = ExampleDialect ::get (context).getAttributeList (2 );
658
+ = ExampleDialect ::get (context).getAttributeList (0 );
654
659
655
660
std ::string mangledName =
656
661
::llvm_dialects ::getMangledName (s_name, {resultType});
@@ -820,7 +825,7 @@ source
820
825
821
826
822
827
const ::llvm ::AttributeList attrs
823
- = ExampleDialect ::get (context).getAttributeList (2 );
828
+ = ExampleDialect ::get (context).getAttributeList (0 );
824
829
auto fnType = ::llvm ::FunctionType ::get (XdHandleType ::get (context), {
825
830
}, false );
826
831
@@ -882,7 +887,7 @@ source
882
887
883
888
884
889
const ::llvm ::AttributeList attrs
885
- = ExampleDialect ::get (context).getAttributeList (2 );
890
+ = ExampleDialect ::get (context).getAttributeList (0 );
886
891
887
892
std ::string mangledName =
888
893
::llvm_dialects ::getMangledName (s_name, {resultType});
@@ -980,7 +985,7 @@ source
980
985
981
986
982
987
const ::llvm ::AttributeList attrs
983
- = ExampleDialect ::get (context).getAttributeList (2 );
988
+ = ExampleDialect ::get (context).getAttributeList (0 );
984
989
985
990
std ::string mangledName =
986
991
::llvm_dialects ::getMangledName (s_name, {resultType});
@@ -1113,7 +1118,7 @@ source
1113
1118
(void)context;
1114
1119
1115
1120
using ::llvm_dialects ::printable;
1116
-
1121
+
1117
1122
if (arg_size () ! = 1 ) {
1118
1123
errs << " wrong number of arguments: " << arg_size ()
1119
1124
<< " , expected 1\n" ;
@@ -1147,7 +1152,7 @@ source
1147
1152
1148
1153
1149
1154
const ::llvm ::AttributeList attrs
1150
- = ExampleDialect ::get (context).getAttributeList (2 );
1155
+ = ExampleDialect ::get (context).getAttributeList (0 );
1151
1156
1152
1157
std ::string mangledName =
1153
1158
::llvm_dialects ::getMangledName (s_name, {vector- > getType ()});
@@ -1607,7 +1612,7 @@ instName
1607
1612
1608
1613
1609
1614
const ::llvm ::AttributeList attrs
1610
- = ExampleDialect ::get (context).getAttributeList (1 );
1615
+ = ExampleDialect ::get (context).getAttributeList (2 );
1611
1616
auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), true );
1612
1617
1613
1618
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -1670,7 +1675,7 @@ data
1670
1675
1671
1676
1672
1677
const ::llvm ::AttributeList attrs
1673
- = ExampleDialect ::get (context).getAttributeList (2 );
1678
+ = ExampleDialect ::get (context).getAttributeList (0 );
1674
1679
auto fnType = ::llvm ::FunctionType ::get (::llvm ::IntegerType ::get (context, 64 ), true );
1675
1680
1676
1681
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -1744,7 +1749,7 @@ data
1744
1749
1745
1750
1746
1751
const ::llvm ::AttributeList attrs
1747
- = ExampleDialect ::get (context).getAttributeList (0 );
1752
+ = ExampleDialect ::get (context).getAttributeList (1 );
1748
1753
1749
1754
std ::string mangledName =
1750
1755
::llvm_dialects ::getMangledName (s_name, {initial- > getType ()});
@@ -1836,7 +1841,7 @@ initial
1836
1841
1837
1842
1838
1843
const ::llvm ::AttributeList attrs
1839
- = ExampleDialect ::get (context).getAttributeList (0 );
1844
+ = ExampleDialect ::get (context).getAttributeList (1 );
1840
1845
1841
1846
std ::string mangledName =
1842
1847
::llvm_dialects ::getMangledName (s_name, {initial- > getType ()});
@@ -1928,7 +1933,7 @@ initial
1928
1933
1929
1934
1930
1935
const ::llvm ::AttributeList attrs
1931
- = ExampleDialect ::get (context).getAttributeList (0 );
1936
+ = ExampleDialect ::get (context).getAttributeList (1 );
1932
1937
1933
1938
std ::string mangledName =
1934
1939
::llvm_dialects ::getMangledName (s_name, {initial- > getType ()});
@@ -2011,6 +2016,75 @@ initial
2011
2016
2012
2017
2013
2018
2019
+ const ::llvm ::StringLiteral StringAttrOp ::s_name{" xd.string.attr.op" };
2020
+
2021
+ StringAttrOp* StringAttrOp ::create (llvm_dialects ::Builder& b, ::llvm ::StringRef val, const llvm ::Twine & instName) {
2022
+ ::llvm ::LLVMContext& context = b.getContext ();
2023
+ (void)context;
2024
+ ::llvm ::Module& module = * b.GetInsertBlock ()- > getModule ();
2025
+
2026
+
2027
+ const ::llvm ::AttributeList attrs
2028
+ = ExampleDialect ::get (context).getAttributeList (4 );
2029
+ auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), {
2030
+ ::llvm ::PointerType ::get (::llvm ::Type ::getInt8Ty (context), 0 ),
2031
+ }, false );
2032
+
2033
+ auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
2034
+ ::llvm ::SmallString< 32 > newName;
2035
+ for (unsigned i = 0 ; ! ::llvm ::isa< ::llvm ::Function> (fn.getCallee ()) ||
2036
+ ::llvm ::cast< ::llvm ::Function> (fn.getCallee ())- > getFunctionType () ! = fn.getFunctionType (); i++ ) {
2037
+ // If a function with the same name but a different types already exists,
2038
+ // we get a bitcast of a function or a function with the wrong type.
2039
+ // Try new names until we get one with the correct type.
2040
+ newName = " " ;
2041
+ ::llvm ::raw_svector_ostream newNameStream (newName);
2042
+ newNameStream << s_name << " _" << i;
2043
+ fn = module.getOrInsertFunction (newNameStream.str (), fnType, attrs);
2044
+ }
2045
+ assert (::llvm ::isa< ::llvm ::Function> (fn.getCallee ()));
2046
+ assert (fn.getFunctionType () == fnType);
2047
+ assert (::llvm ::cast< ::llvm ::Function> (fn.getCallee ())- > getFunctionType () == fn.getFunctionType ());
2048
+
2049
+
2050
+ ::llvm ::SmallVector< ::llvm ::Value* , 1 > args = {
2051
+ b.CreateGlobalString (val)
2052
+ };
2053
+
2054
+ return ::llvm ::cast< StringAttrOp> (b.CreateCall (fn, args, instName));
2055
+ }
2056
+
2057
+
2058
+ bool StringAttrOp ::verifier (::llvm ::raw_ostream & errs) {
2059
+ ::llvm ::LLVMContext & context = getModule ()- > getContext ();
2060
+ (void)context;
2061
+
2062
+ using ::llvm_dialects ::printable;
2063
+
2064
+ if (arg_size () ! = 1 ) {
2065
+ errs << " wrong number of arguments: " << arg_size ()
2066
+ << " , expected 1\n" ;
2067
+ return false ;
2068
+ }
2069
+
2070
+ if (getArgOperand (0 )- > getType () ! = ::llvm ::PointerType ::get (::llvm ::Type ::getInt8Ty (context), 0 )) {
2071
+ errs << " argument 0 (val) has type: "
2072
+ << * getArgOperand (0 )- > getType () << ' \n ' ;
2073
+ errs << " expected: " << * ::llvm ::PointerType ::get (::llvm ::Type ::getInt8Ty (context), 0 ) << ' \n ' ;
2074
+ return false ;
2075
+ }
2076
+ ::llvm ::StringRef const val = getVal ();
2077
+ (void)val;
2078
+ return true ;
2079
+ }
2080
+
2081
+
2082
+ ::llvm ::StringRef StringAttrOp ::getVal () {
2083
+ return ::llvm ::cast< ::llvm ::ConstantDataArray> (::llvm ::cast< ::llvm ::GlobalVariable> (getArgOperand (0 ))- > getInitializer ())- > getAsString () ;
2084
+ }
2085
+
2086
+
2087
+
2014
2088
const ::llvm ::StringLiteral WriteOp ::s_name{" xd.write" };
2015
2089
2016
2090
WriteOp* WriteOp ::create (llvm_dialects ::Builder& b, ::llvm ::Value * data, const llvm ::Twine & instName) {
@@ -2020,7 +2094,7 @@ initial
2020
2094
2021
2095
2022
2096
const ::llvm ::AttributeList attrs
2023
- = ExampleDialect ::get (context).getAttributeList (1 );
2097
+ = ExampleDialect ::get (context).getAttributeList (2 );
2024
2098
auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), true );
2025
2099
2026
2100
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -2083,7 +2157,7 @@ data
2083
2157
2084
2158
2085
2159
const ::llvm ::AttributeList attrs
2086
- = ExampleDialect ::get (context).getAttributeList (1 );
2160
+ = ExampleDialect ::get (context).getAttributeList (2 );
2087
2161
auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), true );
2088
2162
2089
2163
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -2297,6 +2371,14 @@ data
2297
2371
}
2298
2372
2299
2373
2374
+ template <>
2375
+ const ::llvm_dialects ::OpDescription &
2376
+ ::llvm_dialects ::OpDescription ::get< xd ::StringAttrOp> () {
2377
+ static const ::llvm_dialects ::OpDescription desc{false , " xd.string.attr.op" };
2378
+ return desc;
2379
+ }
2380
+
2381
+
2300
2382
template <>
2301
2383
const ::llvm_dialects ::OpDescription &
2302
2384
::llvm_dialects ::OpDescription ::get< xd ::WriteOp> () {
0 commit comments