Bram Adams
2006-Oct-02 20:49 UTC
[LLVMdev] Extracting all BasicBlocks of a Function into new Function
Hi, Op 2-okt-06, om 21:35 heeft Chris Lattner het volgende geschreven:> I think the easiest way to do this is to do the 'complement' as you > describe, but specially handle the varargs case. Basically you > need to > call va_start in the original function, and pass the valist pointer > down. > This shouldn't be too hard.OK. I've been rethinking my use of lib/Transforms/Utils/ CodeExtractor::ExtractCodeRegion(...) to obtain my first goal, but I don't think I need such a complex algorithm after all. Basically, I only need to clone a Function's signature, move the full body to the clone and call the clone from the original Function instead. Determining in- and outgoing variables is unnecessary, as the original Function's signature is the same as the clone's one. Also, both here as in the "complement" case a CallInst needs to be synthesized, but the users of the original Function don't need to change in the former case. That's why I'd like this approach more instead of the latter one (e.g. in the case of function pointers or of external libraries probably not all uses can be found). It seems that all I'd need would be the following naïve approach: 1) clone the original Function's signature (clone has empty body) 2) make mapping of the original Function's Arguments to the clone's ones 3) iterate over the original Function's BasicBlocks, modifying their parent one by one; the BasicBlocks' mutual connections remain intact 4) move the symbol table to the clone 5) replace all uses of the original Arguments by the clone's ones in the clone's body 6) synthesize a CallInst to the clone So, I wonder what problems may show up in this algorithm (steps 4, 5 and 6 seem to be crucial). The vararg-case could be a problem in step 5, although the va_start intrinsic isn't tied to the surrounding Function at first sight. Kind regards, Bram Adams GH-SEL, INTEC, Ghent University (Belgium)
Bram Adams
2006-Oct-03 16:11 UTC
[LLVMdev] Extracting all BasicBlocks of a Function into new Function
Hi, I've got the algorithm working for non-vararg cases. Tomorrow, I'll have a look at the vararg case (only modify step 6?). Kind regards, Bram Adams GH-SEL, INTEC, Ghent University (Belgium) Bram Adams wrote:> It seems that all I'd need would be the following naïve approach: > 1) clone the original Function's signature (clone has empty body) > 2) make mapping of the original Function's Arguments to the clone's > ones > 3) iterate over the original Function's BasicBlocks, modifying > their parent one by one; the BasicBlocks' mutual connections remain > intact > 4) move the symbol table to the clone > 5) replace all uses of the original Arguments by the clone's ones > in the clone's body > 6) synthesize a CallInst to the clone > > So, I wonder what problems may show up in this algorithm (steps 4, 5 > and 6 seem to be crucial). The vararg-case could be a problem in step > 5, although the va_start intrinsic isn't tied to the surrounding > Function at first sight. >
Chris Lattner
2006-Oct-03 18:48 UTC
[LLVMdev] Extracting all BasicBlocks of a Function into new Function
On Mon, 2 Oct 2006, Bram Adams wrote:> So, I wonder what problems may show up in this algorithm (steps 4, 5 > and 6 seem to be crucial). The vararg-case could be a problem in step > 5, although the va_start intrinsic isn't tied to the surrounding > Function at first sight.There is an implicit dependency between vastart and the function it lives in. Specifically, if you have: void foo(int X, ...) { P = va_start(); use(P); } You can't change this to: void foo(int X, ...) { bar(X); } void bar(int X, ...) { P = va_start(); use(P); } You'd have to change it to something like: void foo(int X, ...) { P = va_start(); bar(X, P); } void bar(int X, valist P) { use(P); } -Chris -- http://nondot.org/sabre/ http://llvm.org/
Bram Adams
2006-Oct-03 19:24 UTC
[LLVMdev] Extracting all BasicBlocks of a Function into new Function
Hi, Op 3-okt-06, om 20:48 heeft Chris Lattner het volgende geschreven:> You'd have to change it to something like: > > void foo(int X, ...) { > P = va_start(); > bar(X, P); > } > > void bar(int X, valist P) { > use(P); > }Can the other va_...-intrinsics be used in bar as were the "P = va_start" in bar? The va_start probably is unnecessary now in bar, but where dus the va_end need to be: at the end of foo or of bar or doesn't it matter? Thanks for the remark, Bram Adams GH-SEL, INTEC, Ghent University (Belgium)
Seemingly Similar Threads
- [LLVMdev] Extracting all BasicBlocks of a Function into new Function
- [LLVMdev] Extracting all BasicBlocks of a Function into new Function
- [LLVMdev] Extracting all BasicBlocks of a Function into new Function
- [LLVMdev] Extracting all BasicBlocks of a Function into new Function
- [LLVMdev] Extracting all BasicBlocks of a Function into new Function