Qs on building LLVM passes

Hi,

I have couple of questions that those who design unconventional passes would be interested in.

  1. How to move a virtual register data to another new virtual register?

It seems like that there is no LLVM instruction similar to mov machine instruction.

Arithmetic or logical operators could be used for integer variables

but what about pointer variables?

  1. What is typically IR-level pass execution order? Especially when we separately execute

the front-end, IR optimizer, and back-end, this information seems to be needed.

  1. In code generator, how can we add new instruction in a way that back-end consider

this added instruction for its instruction scheduling and register allocation?

Thanks in advance.

  • Keun Soo
  1. How to move a virtual register data to another new virtual register?
    It seems like that there is no LLVM instruction similar to mov machine instruction.
    Arithmetic or logical operators could be used for integer variables
    but what about pointer variables?

Why do you need to copy a value? Virtual registers are immutable (SSA form), so you don’t need to worry about the value getting overwritten.

  1. What is typically IR-level pass execution order? Especially when we separately execute
    the front-end, IR optimizer, and back-end, this information seems to be needed.

Take a look at tools/opt/opt.cpp. You can see what the “-std-compile-opts” sequence does in there. You can also look at tools/llvm-ld/Optimize.cpp for a standard set of link-time optimizations.

–Owen

Keun Soo Yim wrote:

Hi,

I have couple of questions that those who design unconventional passes would be interested in.

1. How to move a virtual register data to another new virtual register?

It seems like that there is no LLVM instruction similar to mov machine instruction.

Arithmetic or logical operators could be used for integer variables

but what about pointer variables?

The trick to copying values is to use bitcast where the source and destination types are the same.

Of course, if you're doing this, you should understand that you're being very naughty indeed. :slight_smile:

Nick

You will want to add this in the appropriate .td file. The .td files are full of "recipes" which match nodes in the DAG. The appropriate instruction is selected from those recipes that match a pattern in the DAG.

-bw