_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
If you want to check for loop invariance, LICM has logic for doing
what you want. To track the evolution of a variable inside a loop,
there's already an
analysis, ScalarEvolution. In general, I'd recommend to check how loop
passes in LLVM perform this kind of analysis before writing your own.
--
Davide
"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare
On 10 Mar 2018, at 09:37, Craig Topper <craig....@gmail.com> wrote:The code you've pasted there is inconsistent in variable names. Your created an instruction called 'op1' but your print uses 'v1'. What should be an '->' is just a '-'. You also have a variable in your print called 'op' but that's not declared in your code. Also the result of dyn_cast should always be checked for null before using the result.~CraigOn Fri, Mar 9, 2018 at 9:18 AM, Zhou Zhizhong via llvm-dev <llvm...@lists.llvm.org> wrote:Hi,
I’m writing a loop-free LLVM pass, my thought is to track if the value inside the loop is changed, so I look up the Instruction StoreInst first and try to get its value in a set. I checked getValueOperand(), getValueName() in the API document but unfortunately they failed the compilation.
if (isa<StoreInst>(I)){
Value* v = I.getOperand(0);
Instruction* op1 = dyn_cast<Instruction>(v);
errs()<<“v:” <<“\t”<< v << “,\t" << v->getName()<<“,\t"<<op1<<\n”
Thanks for the useful tips, I’ll dive into LICM and ScalarEvolution to get more insights.
From what I have done yesterday, I inserted the lable name of this for loop into a std::stack, so when its successor jumps to the start of the loop, my stored stack can detect this and break out of the loop, now I’m considering to add a Counter to control the loop times to reach the lowest fixed point, but the problem would be how many times should I set, and that’s related with the value of my variables(that’s why I ask this question). If the affected values remain unchanged somewhat, then I should stop the loop and get the final result.
Anyway, I’ll see the analysis code first.
Thanks,
Ethan