-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change ops to be consistent in their MLIR ASM style #583
Comments
Recently I'm trying to propose a CIR assembly style guide. Here are some initial drafts that I have worked out so far. Since I just worked the draft out alone based on my biased and limited personal experience, it can be neither comprehensive nor consistent for now, so any suggestions, feedbacks, and discussions are very welcomed and valuable! RFC: CIR Assembly Style GuideNaming ConventionThe name of a type, an attribute, or an operation should be in !cir.int
!cir.long_double<!cir.float>
!cir.data_member
#cir.cmp3way_info
#cir.dyn_cast_info
cir.binop
cir.get_member The name of a type parameter, an attribute parameter, or an operation argument and result, when defined in TableGen and printed in CIR assembly, should be in Any keywords that appear in the syntax of a type, an attribute, or an operation, should be in Assembly Syntax ConventionGeneral Syntax FormatEach operation should follow the following general syntax: cir.op <args> <regions> `:` <typing> <attr> Where:
Argument ListThe argument list should include all the arguments (except for some attributes as specified in the “placement of attribute” section later) to the operation. Don't use parenthesis around the argument list. The most common format of an argument list is just a comma-separated list: %3 = cir.libc.memchr %0, %1, %2 : (!cir.ptr<!cir.void>, !s32i, !u64i) -> !cir.ptr<!cir.void> Beyond that, one can also use auxiliary keywords and some mini-syntaxes in the argument list to make the operation’s assembly more readable: cir.store %0 to %1 : !s32i, !cir.ptr<!s32i>
%2 = cir.get_runtime_member %0[%1] : (!cir.ptr<!struct>, !cir.data_member<!s32i in !struct>) -> !cir.ptr<!s32i> RegionsFor operations that introduces regions, the regions should follow the argument list in the assembly. One may use auxiliary keywords in the region list to make the assembly more readable: cir.if %0 {
...
} else {
...
} : !cir.bool
cir.ternary %2 true {
...
cir.yield %0 : !s32i
} false {
...
cir.yield %1 : !s32i
} : !cir.bool -> !s32i Type SpecificationsThe type specification gives the types of operation operands and results. Type specifications are placed after the argument list, separated from it with a colon. If the operation has trait %1 = cir.cos %0 : !cir.float
%2 = cir.binop add %0, %1 : !s32i Otherwise, the type specification can be further split into two type lists separated by a right arrow ( If the operation has trait %2 = cir.ptr_diff %0, %1 : !cir.ptr<!s32i> -> !u64i Otherwise, the type specification should include a type for each of the operands and the results. Examples: %2 = cir.get_runtime_member %0[%1] : (!cir.ptr<!struct>, !cir.data_member<!s32i in !struct>) -> !cir.ptr<!s32i> Placement of AttributesAttributes on an operation can be classified into the following categories:
For attributes in the first category, put them in the argument list. One may place the attribute at any appropriate position within the argument list to make the assembly readable. Example: %0 = cir.const #cir.int<42> : !s32i
%1 = cir.unary inc %0 : !s32i
%2 = cir.binop add %0, %1 : !s32i
%1 = cir.load %0 volatile : !cir.ptr<!s32i> -> !s32i
%1 = cir.dyn_cast ptrcast %0 : !cir.ptr<!struct> -> !cir.ptr<!cir.void> #cir.dyn_cast_info For the second category of attributes, put them in the %2 = cir.cmp3way %0, %1 : !s32i -> !u8i #cir.cmp3way<...> One may use auxiliary keywords when specifying these attributes to make the assembly more readable: %0 = cir.alloca !s32i init : !cir.ptr<!s32i> name("var") For the third category of attributes, put them at the end of the Unresolved ProblemsTODO |
Wow, amazing. Can you make this into a PR to gh-pages? So we can do any text suggestions as part of that PR and land it as part of the docs once it's ready? |
Opened #619 . |
This PR adds documentation for CIR assembly style guide. Follows #583 .
Some reference:
Originally posted by @bcardosolopes in #578 (comment)
The text was updated successfully, but these errors were encountered: