Hi, I have tried to use SplitEdge function, but failed. Actually the third parameter is a variable of type Pass and it need to be non-null. But I could not figure out how to use it. Please help me out. Regards, Chayan On Sat, Jul 17, 2010 at 10:16 PM, Nick Lewycky <nicholas at mxc.ca> wrote:> Chayan Sarkar wrote: >> >> Hi all, >> >> Suppose in a CFG bb1 has two succesor bb3 and bb4, and bb3 has two >> predecessor bb1 and bb2. Now how can I insert a basic block between >> bb1 and bb3 that at the edge bb1-->bb3 . >> >> In general how can I insert a basic block on an edge? > > Use llvm::SplitEdge in Transforms/Utils/BasicBlockUtils.h. > > The technique is to create a new bb with a single branch to bb3, then modify > bb1's use of bb3 to point to 'new bb' instead, then fix up any phi nodes in > bb3 by replacing uses of bb1 with 'new bb'. > > Nick >
Chayan Sarkar wrote:> Hi, > > I have tried to use SplitEdge function, but failed. Actually the third > parameter is a variable of type Pass and it need to be non-null. But I > could not figure out how to use it. Please help me out.The only reason it needs a non-NULL Pass* is to call llvm::SplitBlock which uses P->getAnalysisIfAvailable unconditionally. Feel free to wrap those calls in 'if (P) { ... }' and send us a patch. Of course, the obvious question is why aren't you doing your transforms inside of a Pass? Nick> Regards, > Chayan > > On Sat, Jul 17, 2010 at 10:16 PM, Nick Lewycky<nicholas at mxc.ca> wrote: >> Chayan Sarkar wrote: >>> >>> Hi all, >>> >>> Suppose in a CFG bb1 has two succesor bb3 and bb4, and bb3 has two >>> predecessor bb1 and bb2. Now how can I insert a basic block between >>> bb1 and bb3 that at the edge bb1-->bb3 . >>> >>> In general how can I insert a basic block on an edge? >> >> Use llvm::SplitEdge in Transforms/Utils/BasicBlockUtils.h. >> >> The technique is to create a new bb with a single branch to bb3, then modify >> bb1's use of bb3 to point to 'new bb' instead, then fix up any phi nodes in >> bb3 by replacing uses of bb1 with 'new bb'. >> >> Nick >> >
Hi All, Still I could not figure out how to use Pass* while calling SplitEdge() function. Can anyone provide me some example? Regards, Chayan On Sun, Jul 18, 2010 at 11:49 PM, Nick Lewycky <nicholas at mxc.ca> wrote:> Chayan Sarkar wrote: >> >> Hi, >> >> I have tried to use SplitEdge function, but failed. Actually the third >> parameter is a variable of type Pass and it need to be non-null. But I >> could not figure out how to use it. Please help me out. > > The only reason it needs a non-NULL Pass* is to call llvm::SplitBlock which > uses P->getAnalysisIfAvailable unconditionally. Feel free to wrap those > calls in 'if (P) { ... }' and send us a patch. > > Of course, the obvious question is why aren't you doing your transforms > inside of a Pass? > > Nick > >> Regards, >> Chayan >> >> On Sat, Jul 17, 2010 at 10:16 PM, Nick Lewycky<nicholas at mxc.ca> wrote: >>> >>> Chayan Sarkar wrote: >>>> >>>> Hi all, >>>> >>>> Suppose in a CFG bb1 has two succesor bb3 and bb4, and bb3 has two >>>> predecessor bb1 and bb2. Now how can I insert a basic block between >>>> bb1 and bb3 that at the edge bb1-->bb3 . >>>> >>>> In general how can I insert a basic block on an edge? >>> >>> Use llvm::SplitEdge in Transforms/Utils/BasicBlockUtils.h. >>> >>> The technique is to create a new bb with a single branch to bb3, then >>> modify >>> bb1's use of bb3 to point to 'new bb' instead, then fix up any phi nodes >>> in >>> bb3 by replacing uses of bb1 with 'new bb'. >>> >>> Nick >>> >> > >