How do I add custom data load and write back through TIR?

This is the relationship and the source of the data:

In the picture, the top is what I have and the bottom is what I want.

Among them:

x == A,y == B,z == C;

GM2LM is data loading.

LM2GM is data write back.

How can I add something to TIR to facilitate my code generation?

I would advise you to take a look at the cache_read and cache_write methods of the schedules. In my particular case (I don’t know if this is exactly what you are looking for) I use this 2 methods to generate read and write stages, and then tag this stages with specific pragmas. Then, I have 2 separate passes that replace the loops tagged with this pragmas with my own load and store macros.

Thank you for your answer. I would like to know how to tag read/write stages with specific pragmas.

The way to do it is using the “pragma” method of the stage. There are examples here and here.

Thank you very much for your answer, I think I get it.