[LLVMdev] RE : IR code modification/transformation

Frits van Bommel fvbommel at gmail.com
Thu Aug 11 05:31:22 PDT 2011


Re-adding the list, below message was sent to me alone:

On 11 August 2011 13:45, Rinaldini Julien <julien.rinaldini at heig-vd.ch> wrote:
> Thx for all answers...
>
> I'll try that. But in a long term what I want to do will be a bit more complicated... It was just an example. In this case, the goal is to replace all add with sub that return the same result, like:
>
> var = var + 2 will become:
>
> y  = 1234 - (1234-2)
> var = var + y
>
> So I want to read all parameters of the instruction, like the var name, the number, the type,...

Parameters (operands): Add->getOperand(n) (for n = 0, 1, ... ,
Add->getNumOperands()).
A few other "parameters" like nuw/nsw/exact can be accessed as
Add->hasNoUnsignedWrap()/setHasNoUnsignedWrap() and friends.

Var name: Add->getName() / Add->setName().
Can efficiently be transfered to the new instruction with Sub->takeName(Add).
The number is automatically assigned if it doesn't have a name. I'm
not sure if there's an easy way to determine it other than printing it
to a (string)stream and parsing the result.

The type is usually automatically determined from the operands, but
can be accessed as Add->getType(), which is inherited from Value too.

Most of these methods are inherited from the User or Value superclasses.




More information about the llvm-dev mailing list