[cfe-commits] [PATCH] Allow PCHReader to be used without having a pre-initialized Preprocessor

Douglas Gregor dgregor at apple.com
Thu Jun 18 08:04:41 PDT 2009


On Jun 17, 2009, at 7:46 PM, Eli Friedman wrote:

> On Wed, Jun 17, 2009 at 7:28 PM, Chris Lattner<clattner at apple.com>  
> wrote:
>>
>> On Jun 17, 2009, at 6:53 PM, Eli Friedman wrote:
>>
>>> On Wed, Jun 17, 2009 at 6:19 PM, Argyrios Kyrtzidis<kyrtzidis at apple.com 
>>> >
>>> wrote:
>>>>
>>>> Currently PCHReader depends on getting a pre-initialized  
>>>> Preprocessor.
>>>> The attached patch modifies PCHReader so that we can use it to  
>>>> load a
>>>> .pch
>>>> file, get the information we need and *afterwards* initialize a
>>>> Preprocessor
>>>> with that info.
>>>
>>> Why do we want to do this?
>>
>> Argiris is working on building some infrastructure around the PCH  
>> format.
>>  Instead of just using the PCH writer for PCH, we'd like to use it  
>> for
>> general AST serialization/deserialization.  To do something like  
>> "load an
>> ast and send it to codegen", you really just want to use whatever  
>> settings
>> the AST was serialized with.  Seem reasonable?
>
> Ah, okay, that makes sense.  Although, what specific uses do you have
> in mind?  I can only think of a couple off the top of my head: a
> dist-cc-like thing and an inter-procedural analysis tool.

Another use of "load an AST and send it to codegen" is implement  
implicit template instantiation via prelinking. In this scheme,  
function templates are not implicitly instantiated in .o files.  
Instead, when the linker sees that it needs a symbol that corresponds  
to a template instantiation, it spawns the compiler to perform the  
template instantiation and give it a .o file containing that template  
instantiation.

Prelinking can save a lot of disk I/O and a bunch of computation,  
since many templates end up being instantiated in several different .o  
files. With prelinking, these instantiations only happen once, and we  
only instantiate what the linker actually needs. However, prelinking  
has never been a huge win because "spawning the compiler" meant re- 
parsing all of the source code. With AST files, we only bring in the  
code that we need to perform the template instantiation itself.

</crazy>

	- Doug



More information about the cfe-commits mailing list