I have a pass running on O2 and now want to disable it on Os. One solution is to add a compilation option like the following:
static cl::opt<bool> DisableMyPass("disable-mypass",cl::Hidden,cl::init(false));
and use it with -mllvm disable-mypass=true.
But what I exactly need is by default disabling it when -Os while enabling it when -O2 without any other command line options, and I cannot find out a way to do it.
You should add
// This pass generally increases code size
if (skipFunction(F) || F.optForSize()) {
return false;
}
at start of runOnFunction.
Related
I'm trying to speed up compilation by using ClCache together with Incredibuild.
I've configured ClCache by replacing the cl.exe with the ClCache.exe.
However, when using incredibuild it tries to execute tasks on a helper, but it never uses its output.
I see CL.exe (the renamed clcached.exe) calling Python.exe callin CL_original.exe (the original cl.exe) via procesexplorer on the helper.
Is it possible to view the output of the cl-command executed on an Incredibuild-helper? (This would allow me to further debug the situation)
Did anyone succeed in configuring Clcache to work together with incredibuild?
PS: I also tried to use /MsBuild with a /p:CLToolExe pointing to ClCache, also no success.
I'm trying to write a LLVM function pass to do some instrumentation.
Therefore, I I need to get
filename in which the function is declared
the line numbers (begin and end) of the source file in which the function is decalred.
I already found and tried getMetadata("dbg") but I do not want to use the compiler flag -g.
Is there another way to get these information?
Well... the debug metadata is emitted when debug info generation is enabled. You may want to reduce the amount of debug information generated with -gline-tables-only
I am using MinGW (GCC) as a C++ compiler within my application. I have set it to redirect the output of its command line process to my app. Now, suppose I have the following simple C++ code:
int n = 5;
if (n == 6) cout << "YES";
else cout << "NO";
Is there a way to tell what line(s) of code were actually hit during execution of the application? Is there a command I can send to MinGW (GCC) process which, for the given example, would output 1 and 3, as those were the lines hit. And also, in case of a line inside a "for" loop, to tell how many times that statement was actually hit?
And, if not possible, what would be the best approach to having this information? Developing my own compiler or...? Thanks in advance
EDIT: Can someone provide a snippet of commands (in Windows) to be used in order to create a coverage-enabled GCC exe file?
"Is there a way to tell what line(s) of code were actually hit during execution of the application?"
Yes. It's an intrinsic GCC feature. You'll need to compile and link your code with the --coverage, -lgcov or -fprofile-arcs options set.
The gcov tool can be used to consolidate and interpret the actual informations gathered during program runs, that were instrumented with --coverage.
A very good tool to produce browsable consolidated and fairly visualized covearage information from gcov outputs is lcov.
Since you're using mingw you should be able to use gcov: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
I have just started to work with LLVM. I have wrote my own Hello pass, which worked fine.
Now I want to run opt with the stack protector pass, from StackProtector.cpp, but I am having trouble with that. When I look at the source code, it looks like I should use the flag -stack-protector:
INITIALIZE_PASS(StackProtector, "stack-protector", "Insert stack protectors", false, false)
But this flag is not recognized by opt.
I am not sure which file to "load", as it is not as simple as loading my own LLVMHello.so file and I could not find a StackProtector.so file; I believe this might be the problem.
Edit:
I finally got an answer from LLVMDev. Actually, the pass I wanted to run is performed by llc, not opt. I could not find the option -stack-protector, though, with
llc --help
because this option is hidden. If instead I do
llc --help-hidden
it is shown that the pass is there, and I just need to run
llc -print-before=stack-protector <input>
First you add in your pass :
static RegisterPass<StackProtector> X("StackProtector", "Insert stack protectors", false, false);
Second, in the terminal when you run the pass on a target file, after you run make, you have something like:
//home/YOURNAME/llvm/Release+Asserts/bin/opt -load //home/YOURNAME/llvm/Release+Asserts/lib/StackProtector.so -StackProtector //home/YOURNAME/llvm/tools/clang/woRKSPACE/Test.bc
where Test.bc is your target code. Also, be aware: in your Makefile, don't forget to add LIBRARYNAME = StackProtector.
Also, be aware if the pass in not already registered (if so, you will get a segfault error)
I'm implementing a LLVM pass, and would like to turn some options on or off via the command line, especially I'd like to have a -v verbose mode for my pass.
I couldn't find a mechanism for passing command line flags mentioned in any of the docs, does one exist?
The solution I found is to use LLVM's general CommandLine API: http://llvm.org/docs/CommandLine.html
Works as expected in opt when loading the pass dynamically.
Another useful trick is:
#define DEBUG_TYPE "my-special-name"
...
#include "llvm/Support/Debug.h"
...
Sprinkle a bunch of debug output around:
DEBUG(dbgs() << "Original Frame Size: " << FrameSize << "\n" );
...
DEBUG(Node->dump(CurDAG));
Then, on the command line:
... -debug-only my-special-name ...
will get your output.
If your pass is run with the clang front end, you can use:
... -mllvm -debug-only my-special-name ...
If there is only one option with two possible values, the easiest thing to do is to register the same pass twice under two different names. I don't know of any general solution, especially something that will work with opt.