@@ -69,6 +69,11 @@ namespace xd {
69
69
state.setError ();
70
70
});
71
71
72
+ builder.add< ImmutableOp> ([](::llvm_dialects ::VerifierState & state, ImmutableOp & op) {
73
+ if (! op.verifier (state.out ()))
74
+ state.setError ();
75
+ });
76
+
72
77
builder.add< InsertElementOp> ([](::llvm_dialects ::VerifierState & state, InsertElementOp & op) {
73
78
if (! op.verifier (state.out ()))
74
79
state.setError ();
@@ -149,21 +154,21 @@ namespace xd {
149
154
::llvm ::AttrBuilder attrBuilder{context};
150
155
attrBuilder.addAttribute (::llvm ::Attribute ::NoUnwind);
151
156
attrBuilder.addAttribute (::llvm ::Attribute ::WillReturn);
152
- attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (::llvm ::MemoryEffects :: Location ::InaccessibleMem, :: llvm :: ModRefInfo ::Mod ));
157
+ attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (::llvm ::ModRefInfo ::Ref ));
153
158
m_attributeLists[0 ] = ::llvm ::AttributeList ::get (context, ::llvm ::AttributeList ::FunctionIndex, attrBuilder);
154
159
}
155
160
{
156
161
::llvm ::AttrBuilder attrBuilder{context};
157
162
attrBuilder.addAttribute (::llvm ::Attribute ::NoUnwind);
158
163
attrBuilder.addAttribute (::llvm ::Attribute ::WillReturn);
159
- attrBuilder.addMemoryAttr (::llvm ::MemoryEffects :: none ( ));
164
+ attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (:: llvm :: MemoryEffects :: Location ::InaccessibleMem, :: llvm :: ModRefInfo ::Mod ));
160
165
m_attributeLists[1 ] = ::llvm ::AttributeList ::get (context, ::llvm ::AttributeList ::FunctionIndex, attrBuilder);
161
166
}
162
167
{
163
168
::llvm ::AttrBuilder attrBuilder{context};
164
169
attrBuilder.addAttribute (::llvm ::Attribute ::NoUnwind);
165
170
attrBuilder.addAttribute (::llvm ::Attribute ::WillReturn);
166
- attrBuilder.addMemoryAttr (::llvm ::MemoryEffects (:: llvm :: ModRefInfo ::Ref ));
171
+ attrBuilder.addMemoryAttr (::llvm ::MemoryEffects :: none ( ));
167
172
m_attributeLists[2 ] = ::llvm ::AttributeList ::get (context, ::llvm ::AttributeList ::FunctionIndex, attrBuilder);
168
173
}
169
174
{
@@ -324,7 +329,7 @@ return true;
324
329
325
330
326
331
const ::llvm ::AttributeList attrs
327
- = ExampleDialect ::get (context).getAttributeList (1 );
332
+ = ExampleDialect ::get (context).getAttributeList (2 );
328
333
auto fnType = ::llvm ::FunctionType ::get (::llvm ::IntegerType ::get (context, 32 ), {
329
334
lhs- > getType (),
330
335
rhs- > getType (),
@@ -446,7 +451,7 @@ uint32_t const extra = getExtra();
446
451
447
452
448
453
const ::llvm ::AttributeList attrs
449
- = ExampleDialect ::get (context).getAttributeList (1 );
454
+ = ExampleDialect ::get (context).getAttributeList (2 );
450
455
451
456
std ::string mangledName =
452
457
::llvm_dialects ::getMangledName (s_name, {lhs- > getType ()});
541
546
542
547
543
548
const ::llvm ::AttributeList attrs
544
- = ExampleDialect ::get (context).getAttributeList (1 );
549
+ = ExampleDialect ::get (context).getAttributeList (2 );
545
550
546
551
std ::string mangledName =
547
552
::llvm_dialects ::getMangledName (s_name, {::llvm ::cast< XdVectorType> (vector- > getType ())- > getElementType ()});
@@ -645,7 +650,7 @@ index
645
650
646
651
647
652
const ::llvm ::AttributeList attrs
648
- = ExampleDialect ::get (context).getAttributeList (1 );
653
+ = ExampleDialect ::get (context).getAttributeList (2 );
649
654
650
655
std ::string mangledName =
651
656
::llvm_dialects ::getMangledName (s_name, {resultType});
@@ -815,7 +820,7 @@ source
815
820
816
821
817
822
const ::llvm ::AttributeList attrs
818
- = ExampleDialect ::get (context).getAttributeList (1 );
823
+ = ExampleDialect ::get (context).getAttributeList (2 );
819
824
auto fnType = ::llvm ::FunctionType ::get (XdHandleType ::get (context), {
820
825
}, false );
821
826
@@ -877,7 +882,7 @@ source
877
882
878
883
879
884
const ::llvm ::AttributeList attrs
880
- = ExampleDialect ::get (context).getAttributeList (1 );
885
+ = ExampleDialect ::get (context).getAttributeList (2 );
881
886
882
887
std ::string mangledName =
883
888
::llvm_dialects ::getMangledName (s_name, {resultType});
@@ -975,7 +980,7 @@ source
975
980
976
981
977
982
const ::llvm ::AttributeList attrs
978
- = ExampleDialect ::get (context).getAttributeList (1 );
983
+ = ExampleDialect ::get (context).getAttributeList (2 );
979
984
980
985
std ::string mangledName =
981
986
::llvm_dialects ::getMangledName (s_name, {resultType});
@@ -1064,6 +1069,75 @@ source
1064
1069
1065
1070
1066
1071
1072
+ const ::llvm ::StringLiteral ImmutableOp ::s_name{" xd.immutable.op" };
1073
+
1074
+ ImmutableOp* ImmutableOp ::create (llvm_dialects ::Builder& b, bool val, const llvm ::Twine & instName) {
1075
+ ::llvm ::LLVMContext& context = b.getContext ();
1076
+ (void)context;
1077
+ ::llvm ::Module& module = * b.GetInsertBlock ()- > getModule ();
1078
+
1079
+
1080
+ const ::llvm ::AttributeList attrs
1081
+ = ExampleDialect ::get (context).getAttributeList (4 );
1082
+ auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), {
1083
+ ::llvm ::IntegerType ::get (context, 1 ),
1084
+ }, false );
1085
+
1086
+ auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
1087
+ ::llvm ::SmallString< 32 > newName;
1088
+ for (unsigned i = 0 ; ! ::llvm ::isa< ::llvm ::Function> (fn.getCallee ()) ||
1089
+ ::llvm ::cast< ::llvm ::Function> (fn.getCallee ())- > getFunctionType () ! = fn.getFunctionType (); i++ ) {
1090
+ // If a function with the same name but a different types already exists,
1091
+ // we get a bitcast of a function or a function with the wrong type.
1092
+ // Try new names until we get one with the correct type.
1093
+ newName = " " ;
1094
+ ::llvm ::raw_svector_ostream newNameStream (newName);
1095
+ newNameStream << s_name << " _" << i;
1096
+ fn = module.getOrInsertFunction (newNameStream.str (), fnType, attrs);
1097
+ }
1098
+ assert (::llvm ::isa< ::llvm ::Function> (fn.getCallee ()));
1099
+ assert (fn.getFunctionType () == fnType);
1100
+ assert (::llvm ::cast< ::llvm ::Function> (fn.getCallee ())- > getFunctionType () == fn.getFunctionType ());
1101
+
1102
+
1103
+ ::llvm ::SmallVector< ::llvm ::Value* , 1 > args = {
1104
+ ::llvm ::ConstantInt ::get (::llvm ::IntegerType ::get (context, 1 ), val)
1105
+ };
1106
+
1107
+ return ::llvm ::cast< ImmutableOp> (b.CreateCall (fn, args, instName));
1108
+ }
1109
+
1110
+
1111
+ bool ImmutableOp ::verifier (::llvm ::raw_ostream & errs) {
1112
+ ::llvm ::LLVMContext & context = getModule ()- > getContext ();
1113
+ (void)context;
1114
+
1115
+ using ::llvm_dialects ::printable;
1116
+
1117
+ if (arg_size () ! = 1 ) {
1118
+ errs << " wrong number of arguments: " << arg_size ()
1119
+ << " , expected 1\n" ;
1120
+ return false ;
1121
+ }
1122
+
1123
+ if (getArgOperand (0 )- > getType () ! = ::llvm ::IntegerType ::get (context, 1 )) {
1124
+ errs << " argument 0 (val) has type: "
1125
+ << * getArgOperand (0 )- > getType () << ' \n ' ;
1126
+ errs << " expected: " << * ::llvm ::IntegerType ::get (context, 1 ) << ' \n ' ;
1127
+ return false ;
1128
+ }
1129
+ bool const val = getVal ();
1130
+ (void)val;
1131
+ return true ;
1132
+ }
1133
+
1134
+
1135
+ bool ImmutableOp ::getVal () {
1136
+ return ::llvm ::cast< ::llvm ::ConstantInt> (getArgOperand (0 ))- > getZExtValue () ;
1137
+ }
1138
+
1139
+
1140
+
1067
1141
const ::llvm ::StringLiteral InsertElementOp ::s_name{" xd.insertelement" };
1068
1142
1069
1143
InsertElementOp* InsertElementOp ::create (llvm_dialects ::Builder& b, ::llvm ::Value * vector, ::llvm ::Value * value, ::llvm ::Value * index, const llvm ::Twine & instName) {
@@ -1073,7 +1147,7 @@ source
1073
1147
1074
1148
1075
1149
const ::llvm ::AttributeList attrs
1076
- = ExampleDialect ::get (context).getAttributeList (1 );
1150
+ = ExampleDialect ::get (context).getAttributeList (2 );
1077
1151
1078
1152
std ::string mangledName =
1079
1153
::llvm_dialects ::getMangledName (s_name, {vector- > getType ()});
@@ -1539,7 +1613,7 @@ instName
1539
1613
1540
1614
1541
1615
const ::llvm ::AttributeList attrs
1542
- = ExampleDialect ::get (context).getAttributeList (0 );
1616
+ = ExampleDialect ::get (context).getAttributeList (1 );
1543
1617
auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), true );
1544
1618
1545
1619
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -1602,7 +1676,7 @@ data
1602
1676
1603
1677
1604
1678
const ::llvm ::AttributeList attrs
1605
- = ExampleDialect ::get (context).getAttributeList (1 );
1679
+ = ExampleDialect ::get (context).getAttributeList (2 );
1606
1680
auto fnType = ::llvm ::FunctionType ::get (::llvm ::IntegerType ::get (context, 64 ), true );
1607
1681
1608
1682
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -1676,7 +1750,7 @@ data
1676
1750
1677
1751
1678
1752
const ::llvm ::AttributeList attrs
1679
- = ExampleDialect ::get (context).getAttributeList (2 );
1753
+ = ExampleDialect ::get (context).getAttributeList (0 );
1680
1754
1681
1755
std ::string mangledName =
1682
1756
::llvm_dialects ::getMangledName (s_name, {initial- > getType ()});
@@ -1768,7 +1842,7 @@ initial
1768
1842
1769
1843
1770
1844
const ::llvm ::AttributeList attrs
1771
- = ExampleDialect ::get (context).getAttributeList (2 );
1845
+ = ExampleDialect ::get (context).getAttributeList (0 );
1772
1846
1773
1847
std ::string mangledName =
1774
1848
::llvm_dialects ::getMangledName (s_name, {initial- > getType ()});
@@ -1860,7 +1934,7 @@ initial
1860
1934
1861
1935
1862
1936
const ::llvm ::AttributeList attrs
1863
- = ExampleDialect ::get (context).getAttributeList (2 );
1937
+ = ExampleDialect ::get (context).getAttributeList (0 );
1864
1938
1865
1939
std ::string mangledName =
1866
1940
::llvm_dialects ::getMangledName (s_name, {initial- > getType ()});
@@ -1952,7 +2026,7 @@ initial
1952
2026
1953
2027
1954
2028
const ::llvm ::AttributeList attrs
1955
- = ExampleDialect ::get (context).getAttributeList (0 );
2029
+ = ExampleDialect ::get (context).getAttributeList (1 );
1956
2030
auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), true );
1957
2031
1958
2032
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -2015,7 +2089,7 @@ data
2015
2089
2016
2090
2017
2091
const ::llvm ::AttributeList attrs
2018
- = ExampleDialect ::get (context).getAttributeList (0 );
2092
+ = ExampleDialect ::get (context).getAttributeList (1 );
2019
2093
auto fnType = ::llvm ::FunctionType ::get (::llvm ::Type ::getVoidTy (context), true );
2020
2094
2021
2095
auto fn = module.getOrInsertFunction (s_name, fnType, attrs);
@@ -2133,6 +2207,14 @@ data
2133
2207
}
2134
2208
2135
2209
2210
+ template <>
2211
+ const ::llvm_dialects ::OpDescription &
2212
+ ::llvm_dialects ::OpDescription ::get< xd ::ImmutableOp> () {
2213
+ static const ::llvm_dialects ::OpDescription desc{false , " xd.immutable.op" };
2214
+ return desc;
2215
+ }
2216
+
2217
+
2136
2218
template <>
2137
2219
const ::llvm_dialects ::OpDescription &
2138
2220
::llvm_dialects ::OpDescription ::get< xd ::InsertElementOp> () {
0 commit comments