[PATCH] D74691: [Attributor] Detect SCCs with unbounded cycles

omar ahmed via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 23 16:10:40 PST 2020


omarahmed added a comment.



In D74691#1888461 <https://reviews.llvm.org/D74691#1888461>, @baziotis wrote:

> > btw, I recommend that you try to answer questions by following the code - it's always a learning experience).
>
> Since we took that road, let's have a little more fun. Let's start simple by printing the SCCs we get. A simple way to do that is with sth like:
>
>   for (scc_iterator<Function *> It = scc_begin(&F), IE = scc_end(&F); It != IE;
>        ++It) {
>  
>     const std::vector<BasicBlock *> &SCCBBs = *It;
>     for (BasicBlock *BB : SCCBBs) {
>       dbgs() << *BB << "\n";
>     }
>     dbgs() << "----- END -----\n\n\n\n\n";
>   }
>
>
> But, we can actually do better if we take a graphical view of the CFG, with `view-cfg`. You can do that with sth like:
>  `./bin/opt -view-cfg test.ll`
>  Assuming that you are in the `llvm-project` dir, that you have built `opt` and that your file is `test.ll`. Now, this will generate a `.dot` file.
>  This is a special "graphics" format for which we should not care about right now. If you do that, you'll probably see something like:
>
>   ...
>   Writing '/tmp/cfgnon_loop_inside_loop-a0c3a3.dot'...  done. 
>   Trying 'xdg-open' program... Remember to erase graph file: /tmp/cfgnon_loop_inside_loop-a0c3a3.dot
>   gio: file:///tmp/cfgnon_loop_inside_loop-a0c3a3.dot: No application is registered as handling this file 
>
>
> For me, it created `/tmp/cfgnon_loop_inside_loop-a0c3a3.dot` (you won't necessarily have the same name, that's ok). Then, it will try to find
>  default program to open it (with the `xdg-open` command), which as you can see, for me it didn't work. Basically, you now have to have a program that understands
>  that file. The `dot` app will do the job, but you'll probably won't have it by default. Search online for how to install graphviz package. For example, in Ubuntu I think you can do it with `sudo apt-get install graphviz`.
>  Finally, you should be able to create a PDF out of the `.dot` file as: 
>  `dot -Tpdf /tmp/cfgnon_loop_inside_loop-a0c3a3.dot -o <pdf_filename>.pdf`
>  Then, you can open the pdf and expect to see sth like this: https://imgur.com/a/oW2xgNt
>  I think viewing CFGs like that, at times can be //very// helpful. In this case for example, it becomes instantly apparent that the `for` and the `while` don't form a SCC.


wow, that grapical approach is beautiful , thanks

regarding the old approach i tested it with the if-then-else test i listed before

  define i32* @external_sink_ret2_nrw(i32* %n0, i32* %r0, i32* %w0) {
  entry:
    %tobool = icmp ne i32* %n0, null
    br i1 %tobool, label %if.end, label %if.then
  
  if.then:                                          ; preds = %entry
    br label %return
  
  if.end:                                           ; preds = %entry
    %0 = load i32, i32* %r0, align 4
    store i32 %0, i32* %w0, align 4
    br label %return
  
  return:                                           ; preds = %if.end, %if.then
    ret i32* %w0
  }

and it seems to work fine with it after adding the analysis and maxTripCount part but it fails in another tests , I will work on them tmw and submit another diff


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74691/new/

https://reviews.llvm.org/D74691





More information about the llvm-commits mailing list