Reputation: 87
I am currently building a static code analyzer and I wanted to use Clang, llvm. What I wanted as an output is a LLVM-IR in a SSA form(as a text file), when giving a c code as an input. I found this page(How to make clang compile to llvm IR) page, so I've got an LLVM-IR, and in the LLVM reference page, it says "LLVM is a Static Single Assignment (SSA) based representation that ...". So I thought it would already be in a SSA-form, but when I looked into the output, it had something like this.
; label:3
(...)
%or.cond = or i1 %7, %8
br i1 %or.cond, label %13, label %9
; label:9
(...)
%or.cond1 = and i1 %11, %12
br i1 %or.cond1, label %16, label %13
which is representing, the below if statement.
if (tx < offset || ty < offset || tx >= (width-offset) || ty >= (width-offset))
but as far as I know, if it has a SSA-form it shouldn't assign twice the same register.. right? Do you think this is not in a SSA-form? or am I missing something?
Anyway, assuming that this is not the SSA-form that I was looking for, I've searched and found that I should use mem2reg optimization. But, I think the code above is already in register form, but anyway as I do below two commands,
clang-3.6 -emit-llvm -o foo.bc -c foo.cl opt -mem2reg -dce foo.bc
the second command gives me a Segmentation error. So I'm kind of stuck in here so can anybody tell me that I did something wrong or how to generate a SSA-Form IR?
Upvotes: 2
Views: 922