how to set BaseOpcode when using multiclass for relation model in td file

Hi,

I am trying to relate normal instructions with predicate instructions. I have read the document How To Use Instruction Mappings — LLVM 12 documentation.
If normal instruction and the corresponding instruction are related, they should have the same BaseOpcode.

The document covers class/def only. It doesn’t cover multiclass/defm.
for example:
class VFORM<…> {…}
multiclass MFORM<…> {
def _aa: VFORM<…>;
def _bb: VFORM<…>;
}
defm MOV: MFORM<…>;
defm P_MOV: MFORM<…>;

P_MOV_aa and P_MOV_bb are the corresponding predicate instruction of MOV_aa and MOV_bb.
when relating P_MOV_aa with MOV_aa and P_MOV_bb with MOV_bb, they should have the same BaseOpcode.
I think the normal instruction definition name is the best option for BaseOpcode, such as “MOV_aa” and “MOV_bb”.
Could I get the instruction definition name automatically and assign it to BaseOpcode in td file?
Or is there a convenint way to set BaseOpcode for normal/predicate instruction when using multiclass/defm?

I think that you for example should be able to do something like this:

multiclass MFORM<string BaseName, …> {

let BaseOpcode = BaseName in {

def BaseName#_aa : VFORM<…>;

def BaseName#_bb : VFORM<…>;

}

}

defm “” : MFORM<”MOV”, …>;

defm “” : MFORM<”P_MOV”, …>;

/Björn

(just some additional info related to my earlier answer)

And if you have a ColFields named “PredSense” (as in the example in the document you linked),

and aa is maps to PredSense being “true” and bb maps to PredSense being “false”,

then a more complete example would be

multiclass MFORM<string BaseName, …> {

let BaseOpcode = BaseName in {

let PredSense = “true” in

def BaseName#_aa : VFORM<…>;

let PredSense = “false” in

def BaseName#_bb : VFORM<…>;

}

}

defm “” : MFORM<”MOV”, …>;

defm “” : MFORM<”P_MOV”, …>;

(unless you wrap those PredSense settings into the VFORM class somehow)

/Björn