0 | {--
  1 | Copyright (C) 2026  Joel Berkeley
  2 |
  3 | This program is free software: you can redistribute it and/or modify
  4 | it under the terms of the GNU Affero General Public License as published
  5 | by the Free Software Foundation, either version 3 of the License, or
  6 | (at your option) any later version.
  7 |
  8 | This program is distributed in the hope that it will be useful,
  9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11 | GNU Affero General Public License for more details.
 12 |
 13 | You should have received a copy of the GNU Affero General Public License
 14 | along with this program.  If not, see <https://www.gnu.org/licenses/>.
 15 | --}
 16 | ||| For internal spidr use only.
 17 | module Compiler.Stablehlo.Dialect.ChloOps
 18 |
 19 | import Compiler.FFI
 20 | import Compiler.MLIR.IR.BuiltinAttributes
 21 | import Compiler.MLIR.IR.Builders
 22 | import Compiler.MLIR.IR.Location
 23 | import Compiler.MLIR.IR.MLIRContext
 24 | import Compiler.MLIR.IR.OpDefinition
 25 | import Compiler.MLIR.IR.Operation
 26 | import Compiler.MLIR.IR.Region
 27 | import Compiler.MLIR.IR.Types
 28 | import Compiler.MLIR.IR.Value
 29 | import Compiler.MLIR.IR.ValueRange
 30 | import Compiler.Stablehlo.Dialect.StablehloOps
 31 |
 32 | ffi : String -> String
 33 | ffi = libxla "c/stablehlo/dialect/ChloOps.h"
 34 |
 35 | %foreign (ffi "MLIRContext_loadDialect_ChloDialect")
 36 | prim__loadDialectChloDialect : AnyPtr -> PrimIO ()
 37 |
 38 | export
 39 | loadDialectChloDialect : HasIO io => MLIRContext -> io ()
 40 | loadDialectChloDialect (MkMLIRContext ctx) = primIO $ prim__loadDialectChloDialect ctx
 41 |
 42 | %foreign (ffi "AcosOp_delete")
 43 | prim__deleteAcosOp : AnyPtr -> PrimIO ()
 44 |
 45 | public export
 46 | data AcosOp = MkAcosOp GCAnyPtr
 47 |
 48 | %foreign (ffi "AcosOp_create")
 49 | prim__acosOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
 50 |
 51 | namespace AcosOp
 52 |   export
 53 |   create : HasIO io => OpBuilder -> Location -> Value -> io AcosOp
 54 |   create = UnaryElementwiseOp.create MkAcosOp prim__acosOpCreate prim__deleteAcosOp
 55 |
 56 | %foreign (ffi "AcosOp_getOperation")
 57 | prim__acosOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
 58 |
 59 | export
 60 | Op AcosOp where
 61 |   getOperation (MkAcosOp op) = getOperationAux op prim__acosOpGetOperation
 62 |
 63 | %foreign (ffi "AcoshOp_delete")
 64 | prim__deleteAcoshOp : AnyPtr -> PrimIO ()
 65 |
 66 | public export
 67 | data AcoshOp = MkAcoshOp GCAnyPtr
 68 |
 69 | %foreign (ffi "AcoshOp_create")
 70 | prim__acoshOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
 71 |
 72 | namespace AcoshOp
 73 |   export
 74 |   create : HasIO io => OpBuilder -> Location -> Value -> io AcoshOp
 75 |   create = UnaryElementwiseOp.create MkAcoshOp prim__acoshOpCreate prim__deleteAcoshOp
 76 |
 77 | %foreign (ffi "AcoshOp_getOperation")
 78 | prim__acoshOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
 79 |
 80 | export
 81 | Op AcoshOp where
 82 |   getOperation (MkAcoshOp op) = getOperationAux op prim__acoshOpGetOperation
 83 |
 84 | %foreign (ffi "AsinOp_delete")
 85 | prim__deleteAsinOp : AnyPtr -> PrimIO ()
 86 |
 87 | public export
 88 | data AsinOp = MkAsinOp GCAnyPtr
 89 |
 90 | %foreign (ffi "AsinOp_create")
 91 | prim__asinOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
 92 |
 93 | namespace AsinOp
 94 |   export
 95 |   create : HasIO io => OpBuilder -> Location -> Value -> io AsinOp
 96 |   create = UnaryElementwiseOp.create MkAsinOp prim__asinOpCreate prim__deleteAsinOp
 97 |
 98 | %foreign (ffi "AsinOp_getOperation")
 99 | prim__asinOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
100 |
101 | export
102 | Op AsinOp where
103 |   getOperation (MkAsinOp op) = getOperationAux op prim__asinOpGetOperation
104 |
105 | %foreign (ffi "AsinhOp_delete")
106 | prim__deleteAsinhOp : AnyPtr -> PrimIO ()
107 |
108 | public export
109 | data AsinhOp = MkAsinhOp GCAnyPtr
110 |
111 | %foreign (ffi "AsinhOp_create")
112 | prim__asinhOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
113 |
114 | namespace AsinhOp
115 |   export
116 |   create : HasIO io => OpBuilder -> Location -> Value -> io AsinhOp
117 |   create = UnaryElementwiseOp.create MkAsinhOp prim__asinhOpCreate prim__deleteAsinhOp
118 |
119 | %foreign (ffi "AsinhOp_getOperation")
120 | prim__asinhOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
121 |
122 | export
123 | Op AsinhOp where
124 |   getOperation (MkAsinhOp op) = getOperationAux op prim__asinhOpGetOperation
125 |
126 | %foreign (ffi "AtanOp_delete")
127 | prim__deleteAtanOp : AnyPtr -> PrimIO ()
128 |
129 | public export
130 | data AtanOp = MkAtanOp GCAnyPtr
131 |
132 | %foreign (ffi "AtanOp_create")
133 | prim__atanOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
134 |
135 | namespace AtanOp
136 |   export
137 |   create : HasIO io => OpBuilder -> Location -> Value -> io AtanOp
138 |   create = UnaryElementwiseOp.create MkAtanOp prim__atanOpCreate prim__deleteAtanOp
139 |
140 | %foreign (ffi "AtanOp_getOperation")
141 | prim__atanOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
142 |
143 | export
144 | Op AtanOp where
145 |   getOperation (MkAtanOp op) = getOperationAux op prim__atanOpGetOperation
146 |
147 | %foreign (ffi "AtanhOp_delete")
148 | prim__deleteAtanhOp : AnyPtr -> PrimIO ()
149 |
150 | public export
151 | data AtanhOp = MkAtanhOp GCAnyPtr
152 |
153 | %foreign (ffi "AtanhOp_create")
154 | prim__atanhOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
155 |
156 | namespace AtanhOp
157 |   export
158 |   create : HasIO io => OpBuilder -> Location -> Value -> io AtanhOp
159 |   create = UnaryElementwiseOp.create MkAtanhOp prim__atanhOpCreate prim__deleteAtanhOp
160 |
161 | %foreign (ffi "AtanhOp_getOperation")
162 | prim__atanhOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
163 |
164 | export
165 | Op AtanhOp where
166 |   getOperation (MkAtanhOp op) = getOperationAux op prim__atanhOpGetOperation
167 |
168 | %foreign (ffi "CoshOp_delete")
169 | prim__deleteCoshOp : AnyPtr -> PrimIO ()
170 |
171 | public export
172 | data CoshOp = MkCoshOp GCAnyPtr
173 |
174 | %foreign (ffi "CoshOp_create")
175 | prim__coshOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
176 |
177 | namespace CoshOp
178 |   export
179 |   create : HasIO io => OpBuilder -> Location -> Value -> io CoshOp
180 |   create = UnaryElementwiseOp.create MkCoshOp prim__coshOpCreate prim__deleteCoshOp
181 |
182 | %foreign (ffi "CoshOp_getOperation")
183 | prim__coshOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
184 |
185 | export
186 | Op CoshOp where
187 |   getOperation (MkCoshOp op) = getOperationAux op prim__coshOpGetOperation
188 |
189 | %foreign (ffi "SinhOp_delete")
190 | prim__deleteSinhOp : AnyPtr -> PrimIO ()
191 |
192 | public export
193 | data SinhOp = MkSinhOp GCAnyPtr
194 |
195 | %foreign (ffi "SinhOp_create")
196 | prim__sinhOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
197 |
198 | namespace SinhOp
199 |   export
200 |   create : HasIO io => OpBuilder -> Location -> Value -> io SinhOp
201 |   create = UnaryElementwiseOp.create MkSinhOp prim__sinhOpCreate prim__deleteSinhOp
202 |
203 | %foreign (ffi "SinhOp_getOperation")
204 | prim__sinhOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
205 |
206 | export
207 | Op SinhOp where
208 |   getOperation (MkSinhOp op) = getOperationAux op prim__sinhOpGetOperation
209 |
210 | %foreign (ffi "ErfOp_delete")
211 | prim__deleteErfOp : AnyPtr -> PrimIO ()
212 |
213 | public export
214 | data ErfOp = MkErfOp GCAnyPtr
215 |
216 | %foreign (ffi "ErfOp_create")
217 | prim__erfOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
218 |
219 | namespace ErfOp
220 |   export
221 |   create : HasIO io => OpBuilder -> Location -> Value -> io ErfOp
222 |   create = UnaryElementwiseOp.create MkErfOp prim__erfOpCreate prim__deleteErfOp
223 |
224 | %foreign (ffi "ErfOp_getOperation")
225 | prim__erfOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
226 |
227 | export
228 | Op ErfOp where
229 |   getOperation (MkErfOp op) = getOperationAux op prim__erfOpGetOperation
230 |
231 | %foreign (ffi "ErfInvOp_delete")
232 | prim__deleteErfInvOp : AnyPtr -> PrimIO ()
233 |
234 | public export
235 | data ErfInvOp = MkErfInvOp GCAnyPtr
236 |
237 | %foreign (ffi "ErfInvOp_create")
238 | prim__erfInvOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
239 |
240 | namespace ErfInvOp
241 |   export
242 |   create : HasIO io => OpBuilder -> Location -> Value -> io ErfInvOp
243 |   create = UnaryElementwiseOp.create MkErfInvOp prim__erfInvOpCreate prim__deleteErfInvOp
244 |
245 | %foreign (ffi "ErfInvOp_getOperation")
246 | prim__erfInvOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
247 |
248 | export
249 | Op ErfInvOp where
250 |   getOperation (MkErfInvOp op) = getOperationAux op prim__erfInvOpGetOperation
251 |
252 | %foreign (ffi "SquareOp_delete")
253 | prim__deleteSquareOp : AnyPtr -> PrimIO ()
254 |
255 | public export
256 | data SquareOp = MkSquareOp GCAnyPtr
257 |
258 | %foreign (ffi "SquareOp_create")
259 | prim__squareOpCreate : GCAnyPtr -> GCAnyPtr -> GCAnyPtr -> PrimIO AnyPtr
260 |
261 | namespace SquareOp
262 |   export
263 |   create : HasIO io => OpBuilder -> Location -> Value -> io SquareOp
264 |   create = UnaryElementwiseOp.create MkSquareOp prim__squareOpCreate prim__deleteSquareOp
265 |
266 | %foreign (ffi "SquareOp_getOperation")
267 | prim__squareOpGetOperation : GCAnyPtr -> PrimIO AnyPtr
268 |
269 | export
270 | Op SquareOp where
271 |   getOperation (MkSquareOp op) = getOperationAux op prim__squareOpGetOperation
272 |