[RFC][OpenCL] Using module for OpenCL precompiled header file


I was looking for a way to let Clang use pch of opencl-c.h by default when compiling OpenCL programs. It seems currently Clang lacks a mechanism to build pch as part of Clang building process.

However it seems we may be able to use module (http://clang.llvm.org/docs/Modules.html ) to achieve the same goal of automatically including a precompiled header with improved compilation time.

Here is an excerpt from the above documentation:

The binary representation of modules is automatically generated by the compiler on an as-needed basis. When a module is imported (e.g., by an #include of one of the module's headers), the compiler will spawn a second instance of itself [3]<http://clang.llvm.org/docs/Modules.html#id7>, with a fresh preprocessing context [4]<http://clang.llvm.org/docs/Modules.html#id8>, to parse just the headers in that module. The resulting Abstract Syntax Tree (AST) is then persisted into the binary representation of the module that is then loaded into translation unit where the module import was encountered.

The binary representation of modules is persisted in the module cache. Imports of a module will first query the module cache and, if a binary representation of the required module is already available, will load that representation directly. Thus, a module's headers will only be parsed once per language configuration, rather than once per translation unit that uses the module.

Modules maintain references to each of the headers that were part of the module build. If any of those headers changes, or if any of the modules on which a module depends change, then the module will be (automatically) recompiled. The process should never require any user intervention.
I am thinking probably we could use this for OpenCL.

Any comments? Thanks.


I have an initial implementation at http://reviews.llvm.org/D20444 .

Your feedback is welcome.