0

LLVM contains an alias analysis named "type based alias analysis"(pass source code on github), which utilizes the !tbaa metadata embedded with the instruction. The metadata information is like:

!1 = metadata !{metadata !2, metadata !2, i64 0}
!2 = metadata !{metadata !"int", metadata !3, i64 0}
!3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
!4 = metadata !{metadata !"Simple C/C++ TBAA"}

It seems that it requires the frontend like clang to generate the metadata information.

Compiling source code file without passing any optimization arguments(or -O0) cannot generate the above metadata. And till now I only find that I have to pass at least -O1 to clang to get these; the problem is that I don't expect other optimizations/transformations(e.g., instcombine) to happen(the passes used by clang -O1 is similar to the results presented by this answer).

Is there any way to achieve this goal?

Community
  • 1
  • 1
Hongxu Chen
  • 5,240
  • 2
  • 45
  • 85

2 Answers2

2

The answer is a bit out of date. I believe -disable-llvm-optzns is deprecated/removed. You can do this with the driver using something like this:

clang -O2 -Xclang -disable-llvm-passes -S -emit-llvm

1

I don't suggest it for production use, but you can do something like this:

clang -cc1 -O1 -no-struct-path-tbaa -disable-llvm-optzns foo.cpp -emit-llvm -o -

to take a look at the TBAA metadata (remove the -no-struct-path-tbaa if you want to look at that as well).

Otherwise you could modify clang pretty easily to always turn on TBAA metadata.

echristo
  • 1,687
  • 10
  • 8
  • Thanks, it works smoothly. I just wanna some experiments on LLVM TBAA for C and don't expect for production use, so that's enough for me. BTW, may I know your opinion on implementation of current LLVM type-based alias analysis? – Hongxu Chen Jan 07 '15 at 01:55
  • 1
    It's fine, the struct path stuff is a little interesting. It's not state of the art, but it's OK. – echristo Jan 07 '15 at 21:30