How to increase clang parsing performance using PCH or PTH?

扶醉桌前 提交于 2019-12-08 02:25:24

问题


I'm using Clang C API for parsing and getting diagnostics. I've noticed that i'm using the same bundle of headers all the time, so i've decided to try to use PCH or PTH to increase performance.

But i'm getting diagnostics that neither PCH nor PTH were used while clang_parseTranslationUnit:

  • argument unused during compilation: '-emit-pth'
  • /tmp/system/include/libcxx/iostream.pth: 'linker' input unused
  • argument unused during compilation: '-emit-pch'
  • /tmp/system/include/libcxx/iostream.pch: 'linker' input unused

I'm surprised that PCH and PTH were not used while parsing, so how can i use PCH or PTH or any other approach to increase parsing performance?

PS.

PTH was generated using clang++ -x c++-header iostream -emit-pth -o iostream.pth, PCH in similar way

Update 1:

I've found PCH usage example:

// This will load all the symbols from 'IndexTest.c', excluding symbols
// from 'IndexTest.pch'.
char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 0, 0);

The problem is that now i'm getting another diagnostics warning:

'-pch=/system/include/libcxx/iostream.pch' file not found

Looks like command-line arguments were parsed incorrectly.. What am i doing wrong?


回答1:


One needs to include -Xclang before each argument:

char *args[] = { "-Xclang", "-include-pch", "-Xclang", "IndexTest.pch" };

See https://reviews.llvm.org/diffusion/L/browse/cfe/trunk/test/Index/c-index-pch.c for inspiration.



来源:https://stackoverflow.com/questions/26830997/how-to-increase-clang-parsing-performance-using-pch-or-pth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!