Repository navigation
Description
This issue lists the remaining work on #388, with one item for each place in the code. In these places a code generator decides what an MLIR type is from its printed text, for example ty.to_string().starts_with("memref<"). Each item changes the place to ask the type itself.
Merged so far: #4589, #4604, #4606, #4609, #4610, #4611, #4613.
Line numbers are from f8bd285, the branch of #4613.
1. Open PRs
- codegen: ask the MLIR type in the AST generator's statements #4613: the statements in
lower/stmt.rs. - codegen: ask the type for the extents of a copied row and of a vector #4620: two places in
lower/stmt.rsthat codegen: ask the MLIR type in the AST generator's statements #4613 missed:copy_into_new_buffer(stmt.rs:483) andstore_vector_in_a_new_buffer(stmt.rs:849). The description of codegen: ask the MLIR type in the AST generator's statements #4613 says thatstmt.rshas no text tests after it. That statement is wrong. codegen: ask the MLIR type in the AST generator's statements #4613 merged before the follow-up commit, so codegen: ask the type for the extents of a copied row and of a vector #4620 fixes the two places. - codegen: load the tensor references of a GPU region in parameter order #4595: load the parameters of a GPU region in a fixed order (AST code generator: a GPU region loads its reference parameters in a different order on each run #4592). It is not part of MLIR types are decided by parsing their printed form in 60 places, 51 of them in the typed AST backend #388.
2. Small places in the AST code generator
Each of these places has the type value already. #4621 (open) changes all of them except lower/tensors.rs:119, which #4595 removed.
-
lower/expr.rs:511: the rank of a row's slot. It counts thexcharacters aftermemref<memref<. -
lower/expr.rs:3600anderase_memref_extents(generator.rs:206): a cast between two slots cuts the text and removes the extents from it. -
lower/expr.rs:3720: the shape of a strided view. -
lower/expr.rs:6535(tensor_sizes) andlower/expr.rs:6743(clone): the sizes and the element come from the text. -
lower/expr.rs:5438: the placeholder value after amatchwith no matching arm. It usesstrip_prefix('i')andis_float_text. -
lower/control_flow.rs:83and:91: the placeholder value of a block compares the text with"f32"and"i1". -
lower/control_flow.rs:746: aforloop asksstarts_with("tensor<"). -
lower/mod.rs:1377and:1515: the struct name of a closure.llvm_struct_namedoes this already. -
lower/mod.rs:1678andstrip_memref_space(generator.rs:230). -
lower/tensors.rs:430: takes the text after byte 7. -
lower/tensors.rs:858: a gradient askscontains("f32")and three more.is_float_arithdoes this already. -
lower/seam_cert.rs:74: askscontains("i1"). The typei16and the typei128also match it. -
lower/tensors.rs:119: askedstarts_with("memref<memref<"). codegen: load the tensor references of a GPU region in parameter order #4595 removed it. - Four places that this list missed, also in codegen: ask the MLIR type in the AST generator's tensor methods and loops #4621:
matmul_intotook the element from the text after the lastx.reshapeandtransposeread the extents withtrim_start_matches("memref<"). Aforloop over a tensor read its element, and a loop over an iterator read its struct name, from the text. Printing a tensor in another memory space built its type from text.
3. The type lowering of the AST code generator
lower_type and lower_type_str build the text of a type, and lower_type parses that text. The places below read that text. The change makes lower_type build the type with melior, and keeps the text only for printing. It may need two PRs: one for the type lowering and one for the enum layout.
-
lower_type(generator.rs:2918) andlower_type_str(generator.rs:3155).lower_type_strhas 13 callers: 6 ingenerator.rs, 6 inlower/expr.rsand 1 inlower/mod.rs. - The enum layout (
generator.rs:2669to:2708) asksstarts_with("memref<")and compares text with"none". It records the payload types as text inenum_payloadsandenum_tensor_payloads, and thematchparses them again. - The text helpers of the enum layout:
scalar_type_bits,is_float_text,enum_byte_slot, andllvm_type_size_alignwithsplit_top_level. -
field_type_str(generator.rs:2727). - A borrowed tensor in
lower_type(generator.rs:2976). -
returns_through_slot(generator.rs:338). The flat code generator has its own copy, and the two copies must agree. -
tensor_descriptor_str, with 6 callers.tensor_descriptor_tyis its typed copy.
4. The flat code generator
The flat code generator writes MLIR as text, and it keeps each type as a string. The fix is the MlirTy value that #388 proposes: a type value that the generator matches on and prints with Display.
-
MlirTyinsrc/mlir_ty.rs. Register types, argument types and field types (AggLayout::field_tys) becomeMlirTy. -
flat.rs:2060and:3128: the C ABI check asksstarts_with("!llvm.struct"). -
memref_lead_dims_and_elem(flat.rs:2195) andmemref_lead_dim(flat.rs:2209). -
flat/emit/aggregate.rs:is_scalar_field, the two!llvm.structtests at:239and:270,memref_rankanddescriptor_rank.memref_rankgives 2 formemref<?xindex>. -
flat/emit/call.rs:111and:274: a cast compares two types as text without their spaces. -
flat/emit/parallel.rs:202. -
flat/emit/tensor.rs:memref_element(:13) givesf32formemref<4xvector<4xf32>>. The zero values at:540and:939askstarts_with('f'). - The helpers that both code generators use:
memref_spaceandmemref_in_space_of(lower/mod.rs:2262), andfits_on_the_stack(codegen/mod.rs:41).
How to check each PR
- The
vxcfrom main and thevxcfrom the branch emit MLIR for all 1,820 programs undertests/*/pass/, with each code generator. The outputs must be the same. cargo test --workspace --no-fail-fastpasses.
Done when
- No code generator decides what an MLIR type is from its text.
- No
Type::parsecall parses text that the generator built from another type. Todaysrc/codegenhas 84Type::parsecalls.
Generated With Claude Code
Activity