LHS of an expression

hello all,
If i have an IR instruction of the form
%tmp10 = call sbyte* %malloc( uint 4 ) ; <sbyte*> [#uses=1]
%tmp10 = cast sbyte* %tmp10 to int* ; <int*> [#uses=1]
store int* %tmp10, int** %t

which is nothin but a malloc call how can i get %tmp into maybe a variable
set.

If i have a store instruction then it is pretty much simpler as the
getOperand(1) can give me the LHS of the expression but in the above case
how can we get it.

I tried searching for some stuff and got a method called getLHS() method
using BinaryOperator and takes Binops as parameter but i dont think that
is of much help if i am having a malloc instruction.

Can anybody please guide me on this thing please?
Thanks in advance..
Abhinav

Hi Abhinav,

If i have an IR instruction of the form
%tmp10 = call sbyte* %malloc( uint 4 ) ; <sbyte*> [#uses=1]
%tmp10 = cast sbyte* %tmp10 to int* ; <int*> [#uses=1]
store int* %tmp10, int** %t

which is nothin but a malloc call how can i get %tmp into maybe a variable
set.

If i have a store instruction then it is pretty much simpler as the
getOperand(1) can give me the LHS of the expression but in the above case
how can we get it.

I tried searching for some stuff and got a method called getLHS() method
using BinaryOperator and takes Binops as parameter but i dont think that
is of much help if i am having a malloc instruction.

Can anybody please guide me on this thing please?

The LHS of the instruction is a pointer to the instruction itself
(except in cases like the store instr, which you've figured out
already). You can think of the variables that are printed out in the
.ll file as syntactic sugar to help with debugging. So, if you want
variables in a set, you can do something like:

MallocInst *M = new MallocInst(...);

std::set<Instruction*> LHSs;

LHSs.insert(M);

-bw

Hi Bill,
Thanks a lot for your response.But my problem still remains.The thing is i
am having a data type std::vector<Value*> as i am checking for the
variables in Store Instructions and Malloc Instructions.For store the case
is straightforward as discussed earlier.I want the same Value* variable
for malloc inst as well.
bcos i cannot have a different set for only instructions.

can there be some way that i can get only the Value* and not the entire
Instruction* ?
Please help.
Thanks.
Hope my doubt is not that silly..

Hi Bill,
Thanks a lot for your response.But my problem still remains.The thing is i
am having a data type std::vector<Value*> as i am checking for the
variables in Store Instructions and Malloc Instructions.For store the case
is straightforward as discussed earlier.I want the same Value* variable
for malloc inst as well.
bcos i cannot have a different set for only instructions.

can there be some way that i can get only the Value* and not the entire
Instruction* ?
Please help.

I'm not sure I understand the problem. Instructions are inherited from
Values, so you can store both Store and Malloc instructions in the
same vector. You will, of course, need to get the different LHSs of
them. To do this, use something along the lines of:

std::vector<Value*> LHSs;

for (std::vector<Value*>::iterator I = v.begin(), E = v.end(); I != E; ++I) {
  if (StoreInst *S = dyn_cast<StoreInst*>(*I)) {
    // Get the LHS for the store instruction
    LHSs.push_back(S->getOperand(1));
  } else if (MallocInst *M = dyn_cast<MallocInst*>(*I)) {
    // M *is* the LHS of this instruction.
    LHSs.push_back(M);
  } else {
    assert(0 && "Some other instruction's in my list. This is bad!");
  }
}

// Process the LHSs vector.

Does this help? Or did I get it wrong? :slight_smile:

-bw

Oh Thanks a lot Bill,
I did not get that thing when u first told it but now i tried it and it
worked fine.
Thanks once again.
cheers.