prosyslab-classroom / cs524-program-analysis

54 stars 13 forks source link

[Question][Hw7] Extracting type <ty> of certain instructions #48

Closed AnHaechan closed 4 months ago

AnHaechan commented 2 years ago

Hi,

Problem. I'm having trouble with finding appropratie API for finding <ty> in instructions like %add = add <ty> <op1> <op2> or %cmp = icmp <cond> <ty> <op1> <op2>.

Why It is needed. For a given instruction %cmp = icmp <cond> <ty> <op1> <op2>, if I have <ty>, type constraints {Env(<op1>) = <ty>}, {Env(<op2>)= <ty>} can be added, instead of merely adding {Env(<op1>) = Env(<op2>)}(Although I guess the latter one can be enough for this assignment).

What have I tried Using Llvm.type_of on %cmp gives the type of %cmp (thus always i1), not the type of operands. Also Llvm.operand seemed not capable of returning <ty>, as it only returns <op1>, <op2>, .... I've taken some time to throughly check through LLVM Ocaml binding and LlvmUtils, but really couldn't find one.

If there is any possible method, can you help me out? Thanks!

AnHaechan commented 2 years ago

Maybe for icmp <cond> <ty> <op1> <op2> Llvm.operand instr 1 |> Llvm.type_of can work?

kangwoosukeq commented 2 years ago

Yes. I think you can obtain <ty> with Llvm.operand and Llvm.type_of.