On Wednesday 09 July 2008 13:24, Devang Patel wrote:> Is it possible to explain intended use of original unoptimized version ?bugpoint. I want to run it on the IR produced by our frontend. This will help us generate new LLVM tests we can send upstream. We've fixed bugs that aren't caught by the upstream tests and it would be nice to capture the problem and make the test available to everyone.> You do not need to optimize LLVM IR before processing next function.You do if the functions you compile are mega-humongous.> If your compiler works like > > for each function > generate_ir > optimizeYep.> then it seems you're doing > > for each function > generate_ir > convert_to_llvm_ir > optimize_llvm_irYep.> If you're doing this then you may try > > for each function > generate_ir > convert_to_llvm_ir > optimize_llvm_ir_moduleWe in fact did used to do it this way. Then we ran out of memory. And there are other issues to. We'd added things in our copy of LLVM that looks to our middle-end for various bits of information. Some of that information goes away after we get each function so delaying optimization means we don't have all of the useful information we'd like. And BTW, there are many things we had to fix in LLVM to allow us to do this. It seems LLVM keeps around a lot of global state that needs to be reset if you do function-at-a-time processing. I'm hoping to send these fixes back upstream as soon as I deal with the red tape that's recently been put in place here.> Now, you have access to un-optimized functions before you do > optimize_llvm_ir_module. Would that work ?It will work for this particular code I'm looking at but in general it won't. And I'm loathe to change how our compiler flow works just for this. It's one more difference we'd have to deal with when tracking down bugs. -Dave
On Wednesday 09 July 2008 13:49, David Greene wrote:> > then it seems you're doing > > > > for each function > > generate_ir > > convert_to_llvm_ir > > optimize_llvm_ir > > Yep.Ok, I've mostly got a mechanism to do what I want: 1. As each function comes in for op/codegen, clone it and save off the clone and its associated ValueMap (I call these clones "pristine" functions. 2. After all processing is done, clone the resulting Module (this has all of the global data and the optimized functions). Save the ValueMap from this operation. 3. Merge the ValueMaps from the Module clone and all the pristine function ValueMaps so that if V->V' in the Module map and V->V'' in the pristine function map, make V''->V' in the Module map. 4. Fix up arguments to the pristine functions _a_la_ what is done in CloneModule. 5. Delete the function bodies of all functions in the cloned Module (these are the optimized bodies) by calling deleteBody on them. 6. Call CloneFunctionInto to clone the pristine functions into the cloned Module. 7. Fix up linkages (set function linkages in the Module to what they are in the pristine function clones (they were changed to External by deleteBody). 8. Delete all the pristine Function clones, they are now cloned into the cloned Module. This should work as I understand things, but I have a question about Function::deleteBody. It calls dropAllReferences which has the following scary comment: /// dropAllReferences() - This method causes all the subinstructions to "let /// go" of all references that they are maintaining. This allows one to /// 'delete' a whole module at a time, even though there may be circular /// references... first all references are dropped, and all use counts go to /// zero. Then everything is deleted for real. Note that no operations are /// valid on an object that has "dropped all references", except operator /// delete. /// /// Since no other object in the module can have references into the body of a /// function, dropping all references deletes the entire body of the function, /// including any contained basic blocks. /// Is it really true I can't do anything else to a Function after calling this? Can I clone into it via CloneFunctionInto? -Dave
On Jul 11, 2008, at 9:59 AM, David Greene wrote:> On Wednesday 09 July 2008 13:49, David Greene wrote: > >>> then it seems you're doing >>> >>> for each function >>> generate_ir >>> convert_to_llvm_ir >>> optimize_llvm_ir >> >> Yep. > > Ok, I've mostly got a mechanism to do what I want: > > 1. As each function comes in for op/codegen, clone it and save off > the clone and its associated ValueMap (I call these clones > "pristine" > functions. > > 2. After all processing is done, clone the resulting Module (this > has all of > the global data and the optimized functions). Save the ValueMap > from this > operation.The global data is also optimized at this point. Will it map properly with un-optimized pristine functions ? - Devang> > > 3. Merge the ValueMaps from the Module clone and all the pristine > function > ValueMaps so that if V->V' in the Module map and V->V'' in the > pristine > function map, make V''->V' in the Module map. > > 4. Fix up arguments to the pristine functions _a_la_ what is done in > CloneModule. > > 5. Delete the function bodies of all functions in the cloned Module > (these are > the optimized bodies) by calling deleteBody on them. > > 6. Call CloneFunctionInto to clone the pristine functions into the > cloned > Module. > > 7. Fix up linkages (set function linkages in the Module to what they > are in > the pristine function clones (they were changed to External by > deleteBody). > > 8. Delete all the pristine Function clones, they are now cloned into > the > cloned Module. > > This should work as I understand things, but I have a question about > Function::deleteBody. It calls dropAllReferences which has the > following > scary comment: > > /// dropAllReferences() - This method causes all the > subinstructions to "let > /// go" of all references that they are maintaining. This allows > one to > /// 'delete' a whole module at a time, even though there may be > circular > /// references... first all references are dropped, and all use > counts go to > /// zero. Then everything is deleted for real. Note that no > operations are > /// valid on an object that has "dropped all references", except > operator > /// delete. > /// > /// Since no other object in the module can have references into > the body of > a > /// function, dropping all references deletes the entire body of the > function, > /// including any contained basic blocks. > /// > > Is it really true I can't do anything else to a Function after > calling this? > Can I clone into it via CloneFunctionInto? > > -Dave > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev