17 return llvm::isa<CallOp>(unwrap(inp));
21 auto range = llvm::cast<CallOp>(unwrap(op)).getODSOperandIndexAndLength(0);
26 auto range = llvm::cast<CallOp>(unwrap(op)).getODSOperandIndexAndLength(0);
27 assert(index >= 0 && index < range.second &&
"variadic operand index out of range");
29 static_cast<uintptr_t
>(range.first) <=
static_cast<uintptr_t
>(std::numeric_limits<intptr_t>::max()) &&
30 "operand index exceeds intptr_t range"
32 return mlirOperationGetOperand(op,
static_cast<intptr_t
>(range.first) + index);
38 ::llvm::SmallVector<::mlir::Value> vals;
39 vals.reserve(
static_cast<size_t>(count));
40 for (intptr_t i = 0; i < count; ++i)
41 vals.push_back(unwrap(values[i]));
42 ::llvm::cast<CallOp>(unwrap(op)).getArgOperandsMutable().assign(vals);
46 auto range = llvm::cast<CallOp>(unwrap(op)).getODSOperandIndexAndLength(1);
51 auto range = llvm::cast<CallOp>(unwrap(op)).getODSOperandIndexAndLength(1);
52 assert(index >= 0 && index < range.second &&
"variadic operand index out of range");
54 static_cast<uintptr_t
>(range.first) <=
static_cast<uintptr_t
>(std::numeric_limits<intptr_t>::max()) &&
55 "operand index exceeds intptr_t range"
57 return mlirOperationGetOperand(op,
static_cast<intptr_t
>(range.first) + index);
64 ::llvm::SmallVector<::mlir::Value> vals;
65 for (intptr_t g = 0; g < groupCount; ++g) {
66 assert(groups[g].size >= 0 &&
"group size must be non-negative");
67 for (intptr_t i = 0; i < groups[g].
size; ++i) {
68 vals.push_back(unwrap(groups[g].values[i]));
71 ::llvm::cast<CallOp>(unwrap(op)).getMapOperandsMutable().join().assign(vals);
73 ::llvm::SmallVector<int32_t> newGroupSizes;
74 newGroupSizes.reserve(
static_cast<size_t>(groupCount));
75 for (intptr_t g = 0; g < groupCount; ++g) {
77 groups[g].size <=
static_cast<intptr_t
>(std::numeric_limits<int32_t>::max()) &&
78 "group size exceeds int32_t range"
80 newGroupSizes.push_back(
static_cast<int32_t
>(groups[g].size));
82 MlirContext ctx = mlirOperationGetContext(op);
84 newGroupSizes.size() <=
static_cast<size_t>(std::numeric_limits<intptr_t>::max()) &&
85 "group count exceeds intptr_t range"
87 mlirOperationSetAttributeByName(
88 op, mlirStringRefCreateFromCString(
"mapOpGroupSizes"),
89 mlirDenseI32ArrayGet(ctx,
static_cast<intptr_t
>(newGroupSizes.size()), newGroupSizes.data())
94 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"callee"));
98 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"callee"), attr);
102 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"templateParams"));
106 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"templateParams"), attr);
110 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"numDimsPerMap"));
114 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"numDimsPerMap"), attr);
118 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"mapOpGroupSizes"));
122 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"mapOpGroupSizes"), attr);
126 intptr_t count = mlirOperationGetNumResults(op);
127 assert(count >= 0 &&
"result count less than start index");
132 return mlirOperationGetResult(op, 0 + index);
136 return llvm::cast<CallOp>(unwrap(inp)).calleeContainsWitnessGen();
140 return llvm::cast<CallOp>(unwrap(inp)).calleeIsStructCompute();
144 return wrap(llvm::cast<CallOp>(unwrap(inp)).getSingleResultTypeOfCompute());
148 return llvm::cast<CallOp>(unwrap(inp)).calleeIsStructConstrain();
152 return wrap(llvm::cast<CallOp>(unwrap(inp)).getSelfValueFromConstrain());
156 return wrap(llvm::cast<CallOp>(unwrap(inp)).getTypeSignature());
160 return llvm::cast<CallOp>(unwrap(inp)).calleeIsCompute();
164 return llvm::cast<CallOp>(unwrap(inp)).calleeIsConstrain();
168 return wrap(llvm::cast<CallOp>(unwrap(inp)).resolveCallable());
172 return wrap(llvm::cast<CallOp>(unwrap(inp)).getSelfValueFromCompute());
176 return wrap(llvm::cast<CallOp>(unwrap(inp)).getSingleResultTypeOfWitnessGen());
179MlirOperation
llzkFunction_FuncDefOpBuild(MlirOpBuilder builder, MlirLocation location, MlirIdentifier sym_name, MlirAttribute function_type, MlirAttribute arg_attrs, MlirAttribute res_attrs) {
180 MlirOperationState state = mlirOperationStateGet(mlirStringRefCreateFromCString(
"function.def"), location);
182 llvm::SmallVector<MlirNamedAttribute, 4> attributes;
183 if (!mlirAttributeIsNull(
reinterpret_cast<MlirAttribute&
>(sym_name))) {
184 attributes.push_back(mlirNamedAttributeGet(mlirIdentifierGet(ctx, mlirStringRefCreateFromCString(
"sym_name")),
reinterpret_cast<MlirAttribute&
>(sym_name)));
186 if (!mlirAttributeIsNull(function_type)) {
187 attributes.push_back(mlirNamedAttributeGet(mlirIdentifierGet(ctx, mlirStringRefCreateFromCString(
"function_type")), function_type));
189 if (!mlirAttributeIsNull(arg_attrs)) {
190 attributes.push_back(mlirNamedAttributeGet(mlirIdentifierGet(ctx, mlirStringRefCreateFromCString(
"arg_attrs")), arg_attrs));
192 if (!mlirAttributeIsNull(res_attrs)) {
193 attributes.push_back(mlirNamedAttributeGet(mlirIdentifierGet(ctx, mlirStringRefCreateFromCString(
"res_attrs")), res_attrs));
195 mlirOperationStateAddAttributes(&state, attributes.size(), attributes.data());
196 llvm::SmallVector<MlirRegion, 1> regions;
197 regions.push_back(mlirRegionCreate());
198 mlirOperationStateAddOwnedRegions(&state, regions.size(), regions.data());
204 return llvm::isa<FuncDefOp>(unwrap(inp));
208 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"sym_name"));
212 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"sym_name"), attr);
216 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"function_type"));
220 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"function_type"), attr);
224 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"arg_attrs"));
228 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"arg_attrs"), attr);
232 return mlirOperationGetAttributeByName(op, mlirStringRefCreateFromCString(
"res_attrs"));
236 mlirOperationSetAttributeByName(op, mlirStringRefCreateFromCString(
"res_attrs"), attr);
240 return mlirOperationGetRegion(op, 0);
244 return llvm::cast<FuncDefOp>(unwrap(inp)).isStructProduct();
248 llvm::cast<FuncDefOp>(unwrap(inp)).setAllowNonNativeFieldOpsAttr(newValue);
252 return llvm::cast<FuncDefOp>(unwrap(inp)).hasAllowNonNativeFieldOpsAttr();
256 return llvm::cast<FuncDefOp>(unwrap(inp)).nameIsProduct();
260 return llvm::cast<FuncDefOp>(unwrap(inp)).hasArgPublicAttr(index);
264 return llvm::cast<FuncDefOp>(unwrap(inp)).hasAllowWitnessAttr();
268 return llvm::cast<FuncDefOp>(unwrap(inp)).isStructConstrain();
272 return llvm::cast<FuncDefOp>(unwrap(inp)).nameIsCompute();
276 return llvm::cast<FuncDefOp>(unwrap(inp)).isDeclaration();
280 return wrap(llvm::cast<FuncDefOp>(unwrap(inp)).getSingleResultTypeOfCompute());
284 return wrap(llvm::cast<FuncDefOp>(unwrap(inp)).getSelfValueFromConstrain());
288 return llvm::cast<FuncDefOp>(unwrap(inp)).nameIsConstrain();
292 return llvm::cast<FuncDefOp>(unwrap(inp)).isStructCompute();
296 return wrap(llvm::cast<FuncDefOp>(unwrap(inp)).getCallableRegion());
300 llvm::cast<FuncDefOp>(unwrap(inp)).setAllowConstraintAttr(newValue);
304 return llvm::cast<FuncDefOp>(unwrap(inp)).hasAllowConstraintAttr();
308 return llvm::cast<FuncDefOp>(unwrap(inp)).isInStruct();
312 llvm::cast<FuncDefOp>(unwrap(inp)).setAllowWitnessAttr(newValue);
316 return wrap(llvm::cast<FuncDefOp>(unwrap(inp)).getSelfValueFromCompute());
320 return llvm::cast<FuncDefOp>(unwrap(inp)).hasArgName(index);
324 return wrap(llvm::cast<FuncDefOp>(unwrap(inp)).getFullyQualifiedName(requireParent));
328 MlirOperationState state = mlirOperationStateGet(mlirStringRefCreateFromCString(
"function.return"), location);
329 mlirOperationStateAddOperands(&state, operandsSize, operands);
335 return llvm::isa<ReturnOp>(unwrap(inp));
339 auto range = llvm::cast<ReturnOp>(unwrap(op)).getODSOperandIndexAndLength(0);
344 auto range = llvm::cast<ReturnOp>(unwrap(op)).getODSOperandIndexAndLength(0);
345 assert(index >= 0 && index < range.second &&
"variadic operand index out of range");
347 static_cast<uintptr_t
>(range.first) <=
static_cast<uintptr_t
>(std::numeric_limits<intptr_t>::max()) &&
348 "operand index exceeds intptr_t range"
350 return mlirOperationGetOperand(op,
static_cast<intptr_t
>(range.first) + index);
356 ::llvm::SmallVector<::mlir::Value> vals;
357 vals.reserve(
static_cast<size_t>(count));
358 for (intptr_t i = 0; i < count; ++i)
359 vals.push_back(unwrap(values[i]));
360 ::llvm::cast<ReturnOp>(unwrap(op)).getOperandsMutable().assign(vals);
MlirContext mlirOpBuilderGetContext(MlirOpBuilder builder)
Returns the MLIR context associated with builder.
MlirOperation mlirOpBuilderInsert(MlirOpBuilder builder, MlirOperation op)
Inserts op at the current insertion point of builder and returns it.
bool llzkFunction_FuncDefOpNameIsProduct(MlirOperation inp)
Return true iff the function name is FUNC_NAME_PRODUCT (if needed, a check that this FuncDefOp is loc...
MlirRegion llzkFunction_FuncDefOpGetCallableRegion(MlirOperation inp)
Required by FunctionOpInterface.
void llzkFunction_FuncDefOpSetResAttrs(MlirOperation op, MlirAttribute attr)
Set ResAttrs attribute of llzk::function::FuncDefOp Operation.
MlirOperation llzkFunction_FuncDefOpBuild(MlirOpBuilder builder, MlirLocation location, MlirIdentifier sym_name, MlirAttribute function_type, MlirAttribute arg_attrs, MlirAttribute res_attrs)
Build a llzk::function::FuncDefOp Operation.
MlirValue llzkFunction_ReturnOpGetOperandsAt(MlirOperation op, intptr_t index)
Get Operands operand at index from llzk::function::ReturnOp Operation.
bool llzkFunction_FuncDefOpIsStructProduct(MlirOperation inp)
Return true iff the function is within a StructDefOp and named FUNC_NAME_PRODUCT.
intptr_t llzkFunction_CallOpGetResult0Count(MlirOperation op)
Get number of Result0 results in llzk::function::CallOp Operation.
MlirAttribute llzkFunction_FuncDefOpGetFullyQualifiedName(MlirOperation inp, bool requireParent)
Return the full name for this function from the root module, including all surrounding symbol table n...
bool llzkFunction_CallOpCalleeIsStructConstrain(MlirOperation inp)
Return true iff the callee function name is FUNC_NAME_CONSTRAIN within a StructDefOp.
void llzkFunction_FuncDefOpSetFunctionType(MlirOperation op, MlirAttribute attr)
Set FunctionType attribute of llzk::function::FuncDefOp Operation.
MlirAttribute llzkFunction_CallOpGetMapOpGroupSizes(MlirOperation op)
Get MapOpGroupSizes attribute from llzk::function::CallOp Operation.
bool llzkFunction_CallOpCalleeIsCompute(MlirOperation inp)
Return true iff the callee function name is FUNC_NAME_COMPUTE (this does not check if the callee func...
MlirAttribute llzkFunction_CallOpGetTemplateParams(MlirOperation op)
Get TemplateParams attribute from llzk::function::CallOp Operation.
intptr_t llzkFunction_CallOpGetMapOperandsCount(MlirOperation op)
Get number of MapOperands operands in llzk::function::CallOp Operation.
intptr_t llzkFunction_CallOpGetArgOperandsCount(MlirOperation op)
Get number of ArgOperands operands in llzk::function::CallOp Operation.
void llzkFunction_CallOpSetMapOperands(MlirOperation op, intptr_t groupCount, MlirValueRange const *groups)
Set MapOperands operand groups of llzk::function::CallOp Operation.
void llzkFunction_ReturnOpSetOperands(MlirOperation op, intptr_t count, MlirValue const *values)
Set Operands operands of llzk::function::ReturnOp Operation.
bool llzkFunction_FuncDefOpHasAllowWitnessAttr(MlirOperation inp)
Return true iff the function def has the allow_witness attribute.
MlirValue llzkFunction_FuncDefOpGetSelfValueFromConstrain(MlirOperation inp)
Return the "self" value (i.e.
MlirAttribute llzkFunction_FuncDefOpGetResAttrs(MlirOperation op)
Get ResAttrs attribute from llzk::function::FuncDefOp Operation.
MlirType llzkFunction_CallOpGetSingleResultTypeOfCompute(MlirOperation inp)
Assuming the callee is FUNC_NAME_COMPUTE, return the single StructType result.
MlirOperation llzkFunction_ReturnOpBuild(MlirOpBuilder builder, MlirLocation location, intptr_t operandsSize, MlirValue const *operands)
Build a llzk::function::ReturnOp Operation.
bool llzkFunction_FuncDefOpIsDeclaration(MlirOperation inp)
Required by SymbolOpInterface.
void llzkFunction_CallOpSetCallee(MlirOperation op, MlirAttribute attr)
Set Callee attribute of llzk::function::CallOp Operation.
bool llzkFunction_CallOpCalleeContainsWitnessGen(MlirOperation inp)
Return true iff the callee function can contain witness generation code (this does not check if the c...
bool llzkFunction_FuncDefOpHasAllowConstraintAttr(MlirOperation inp)
Return true iff the function def has the allow_constraint attribute.
bool llzkFunction_FuncDefOpIsInStruct(MlirOperation inp)
Return true iff the function is within a StructDefOp.
void llzkFunction_FuncDefOpSetArgAttrs(MlirOperation op, MlirAttribute attr)
Set ArgAttrs attribute of llzk::function::FuncDefOp Operation.
void llzkFunction_FuncDefOpSetAllowConstraintAttr(MlirOperation inp, bool newValue)
Add (resp. remove) the allow_constraint attribute to (resp. from) the function def.
void llzkFunction_CallOpSetArgOperands(MlirOperation op, intptr_t count, MlirValue const *values)
Set ArgOperands operands of llzk::function::CallOp Operation.
bool llzkFunction_FuncDefOpHasArgName(MlirOperation inp, unsigned index)
Return true iff the argument at the given index has a function.arg_name attribute.
MlirValue llzkFunction_CallOpGetSelfValueFromConstrain(MlirOperation inp)
Return the "self" value (i.e.
bool llzkFunction_FuncDefOpHasArgPublicAttr(MlirOperation inp, unsigned index)
Return true iff the argument at the given index has pub attribute.
void llzkFunction_FuncDefOpSetAllowNonNativeFieldOpsAttr(MlirOperation inp, bool newValue)
Add (resp. remove) the allow_non_native_field_ops attribute to (resp. from) the function def.
bool llzkFunction_FuncDefOpIsStructConstrain(MlirOperation inp)
Return true iff the function is within a StructDefOp and named FUNC_NAME_CONSTRAIN.
MlirValue llzkFunction_CallOpGetArgOperandsAt(MlirOperation op, intptr_t index)
Get ArgOperands operand at index from llzk::function::CallOp Operation.
MlirType llzkFunction_FuncDefOpGetSingleResultTypeOfCompute(MlirOperation inp)
Assuming the name is FUNC_NAME_COMPUTE, return the single StructType result.
void llzkFunction_CallOpSetTemplateParams(MlirOperation op, MlirAttribute attr)
Set TemplateParams attribute of llzk::function::CallOp Operation.
void llzkFunction_CallOpSetNumDimsPerMap(MlirOperation op, MlirAttribute attr)
Set NumDimsPerMap attribute of llzk::function::CallOp Operation.
bool llzkOperationIsA_Function_ReturnOp(MlirOperation inp)
Returns true if the Operation is a llzk::function::ReturnOp.
bool llzkOperationIsA_Function_CallOp(MlirOperation inp)
Returns true if the Operation is a llzk::function::CallOp.
MlirAttribute llzkFunction_CallOpGetCallee(MlirOperation op)
Get Callee attribute from llzk::function::CallOp Operation.
MlirType llzkFunction_CallOpGetSingleResultTypeOfWitnessGen(MlirOperation inp)
Assuming the callee contains witness generation code, return the single StructType result.
MlirAttribute llzkFunction_FuncDefOpGetArgAttrs(MlirOperation op)
Get ArgAttrs attribute from llzk::function::FuncDefOp Operation.
bool llzkFunction_FuncDefOpNameIsConstrain(MlirOperation inp)
Return true iff the function name is FUNC_NAME_CONSTRAIN (if needed, a check that this FuncDefOp is l...
MlirValue llzkFunction_FuncDefOpGetSelfValueFromCompute(MlirOperation inp)
Return the "self" value (i.e.
bool llzkFunction_FuncDefOpIsStructCompute(MlirOperation inp)
Return true iff the function is within a StructDefOp and named FUNC_NAME_COMPUTE.
void llzkFunction_FuncDefOpSetAllowWitnessAttr(MlirOperation inp, bool newValue)
Add (resp. remove) the allow_witness attribute to (resp. from) the function def.
intptr_t llzkFunction_ReturnOpGetOperandsCount(MlirOperation op)
Get number of Operands operands in llzk::function::ReturnOp Operation.
MlirValue llzkFunction_CallOpGetMapOperandsAt(MlirOperation op, intptr_t index)
Get MapOperands operand at index from llzk::function::CallOp Operation.
bool llzkFunction_FuncDefOpHasAllowNonNativeFieldOpsAttr(MlirOperation inp)
Return true iff the function def has the allow_non_native_field_ops attribute.
void llzkFunction_FuncDefOpSetSymName(MlirOperation op, MlirAttribute attr)
Set SymName attribute of llzk::function::FuncDefOp Operation.
MlirRegion llzkFunction_FuncDefOpGetBody(MlirOperation op)
Get Body region from llzk::function::FuncDefOp Operation.
MlirType llzkFunction_CallOpGetTypeSignature(MlirOperation inp)
Return the FunctionType inferred from the arg operands and result types of this CallOp.
MlirValue llzkFunction_CallOpGetSelfValueFromCompute(MlirOperation inp)
Return the "self" value (i.e.
bool llzkFunction_CallOpCalleeIsStructCompute(MlirOperation inp)
Return true iff the callee function name is FUNC_NAME_COMPUTE within a StructDefOp.
MlirAttribute llzkFunction_FuncDefOpGetFunctionType(MlirOperation op)
Get FunctionType attribute from llzk::function::FuncDefOp Operation.
MlirValue llzkFunction_CallOpGetResult0At(MlirOperation op, intptr_t index)
Get Result0 result at index from llzk::function::CallOp Operation.
MlirOperation llzkFunction_CallOpResolveCallable(MlirOperation inp)
Required by CallOpInterface.
bool llzkFunction_FuncDefOpNameIsCompute(MlirOperation inp)
Return true iff the function name is FUNC_NAME_COMPUTE (if needed, a check that this FuncDefOp is loc...
bool llzkOperationIsA_Function_FuncDefOp(MlirOperation inp)
Returns true if the Operation is a llzk::function::FuncDefOp.
void llzkFunction_CallOpSetMapOpGroupSizes(MlirOperation op, MlirAttribute attr)
Set MapOpGroupSizes attribute of llzk::function::CallOp Operation.
MlirAttribute llzkFunction_CallOpGetNumDimsPerMap(MlirOperation op)
Get NumDimsPerMap attribute from llzk::function::CallOp Operation.
MlirAttribute llzkFunction_FuncDefOpGetSymName(MlirOperation op)
Get SymName attribute from llzk::function::FuncDefOp Operation.
bool llzkFunction_CallOpCalleeIsConstrain(MlirOperation inp)
Return true iff the callee function name is FUNC_NAME_CONSTRAIN (this does not check if the callee fu...
Representation of an mlir::ValueRange
intptr_t size
Number of values in the range.