[llvm-commits] [patch] Implement a pass to instrument function entry and exit
Chris Lattner
clattner at apple.com
Sat Jun 12 21:51:54 PDT 2010
On Jun 5, 2010, at 6:38 PM, Nelson Elhage wrote:
> This patch adds a pass that adds calls to instrument function exit and
> entry, in a way compatible with GCC's -finstrument-functions flag.
>
> Options are also provided to selectively exclude certain functions from
> instrumenting, analogous to those provided by GCC.
>
> If this patch is not totally off-base, I'm planning to also implement
> and send along a function attribute to disable instrumenting on specific
> functions, and frontend support in clang.
Nice, adding -finstrument-functions support would be great.
Meta comment: please include your patch as an attachment. If you're using Thunderbird, please follow these instructions:
http://llvm.org/docs/DeveloperPolicy.html#patches
This makes it easier to apply.
> +//===----------------------------------------------------------------------===//
> +//
> +// This pass inserts instrumentation calls for entry and exit to
> +// functions. After function entry and before exit, calls are inserted
> +// to the following instrumentation functions:
> +//
> +// void __cyg_profile_func_enter (void *this_fn,
> +// void *call_site);
> +// void __cyg_profile_func_exit (void *this_fn,
> +// void *call_site);
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#define DEBUG_TYPE "instrument-functions"
> +#include "llvm/CodeGen/Passes.h"
This should be added to the scalar passes.
> +namespace {
> + class CommaSeparatedStringParser :
> + public cl::basic_parser<std::vector<std::string> > {
> + public:
> + // parse - Return true on error.
> + bool parse(cl::Option &O, StringRef ArgName, StringRef ArgValue,
> + std::vector<std::string> &Val);
> + };
Instead of handling this with command line options, how about adding a function attribute? That way the frontend can slap it on functions where it makes sense and manage the no_instrument_function attribute.
However, backing up a little bit, I'm not sure I understand this from the GCC man page:
"This instrumentation is also done for functions expanded inline in other functions."
Does that mean that *all* source-level function (that don't have the no_instrument_function attribute) get instrumented, even if they get inlined etc?
If so, then I think this entire thing can be handled in the Clang IR generation routines, not needing LLVM IR attributes and not needing an LLVM IR pass.
What do you think?
-Chris
More information about the llvm-commits
mailing list