Commit Graph

77 Commits

Author SHA1 Message Date
Diego Novillo aa8b1cb8a4 Set function entry counts with -fprofile-instr-use.
This generates function entry counts from instrumentation profiles.

llvm-svn: 238360
2015-05-27 21:58:42 +00:00
David Blaikie 43f9bb7371 API update for streamlining of IRBuilder::CreateCall to just use ArrayRef/initializer_list+braced init
llvm-svn: 237625
2015-05-18 22:14:03 +00:00
Justin Bogner 65512647cc InstrProf: Cede ownership of createProfileWeights to CGF
The fact that PGO has a say in how these branch weights are determined
isn't interesting to most of CodeGen, so it makes more sense for this
API to be accessible via CodeGenFunction rather than CodeGenPGO.

llvm-svn: 236380
2015-05-02 05:00:55 +00:00
Justin Bogner a909abfd29 InstrProf: Use a locally tracked current count in ComputeRegionCounts
No functional change. This just makes it more obvious that the logic
in ComputeRegionCounts only depends on the counter map and local
state.

llvm-svn: 236370
2015-05-02 00:48:27 +00:00
Justin Bogner 07193cc80b InstrProf: Replace the RegionCounter class with a simpler direct approach
This removes the RegionCounter class, which is only used as a helper
in teh ComputeRegionCounts stmt visitor. This class is just an extra
layer of abstraction that makes the code harder to follow at this
point, and removing it makes the logic quite a bit more direct.

llvm-svn: 236364
2015-05-01 23:41:09 +00:00
Justin Bogner 2e5d484597 InstrProf: Fix handling of profile counters in the body of range based for
We were assigning the counter for the body of the loop to the loop
variable initialization for some reason here, but our tests completely
lacked coverage for range-for loops. This fixes that and makes the
logic generally more similar to the logic for a regular for.

llvm-svn: 236277
2015-04-30 22:58:28 +00:00
Justin Bogner f959febf7a InstrProf: Mark code regions after throw expressions as unreachable
We weren't setting regions as being unreachable after C++ throw
expressions, leading to incorrect count propagations.

llvm-svn: 235967
2015-04-28 06:31:55 +00:00
Justin Bogner 66242d6c5e InstrProf: Stop using RegionCounter outside of CodeGenPGO (NFC)
The RegionCounter type does a lot of legwork, but most of it is only
meaningful within the implementation of CodeGenPGO. The uses elsewhere
in CodeGen generally just want to increment or read counters, so do
that directly.

llvm-svn: 235664
2015-04-23 23:06:47 +00:00
Justin Bogner 60d852ba5b InstrProf: Fix a shadowing error that would break length of profile names
We try to use the member variable "FuncName" here, but we've also used
that name as a parameter. This ends with us getting the length of the
function name wrong when we generate the coverage data.

llvm-svn: 235565
2015-04-23 00:31:16 +00:00
Justin Bogner 1c21c28b9e InstrProf: Simplify getStmtCount by using an Optional
llvm-svn: 234750
2015-04-13 12:23:19 +00:00
Justin Bogner e9fe0a298c InstrProf: Make profile variables private to reduce binary size overhead
When we instrument a program for profiling, we copy the linkage of an
instrumented function so that our datastructures merge in the same way
as the function. This avoids redundant copies for things like
linkonce, but ends up emitting names we never need to reference for
normal and internal symbols. Promoting internal and external linkage
to private for these variables reduces the size overhead of profiling
drastically.

llvm-svn: 232799
2015-03-20 06:34:38 +00:00
Justin Bogner e4ca441a65 InstrProf: Run clang-format to fix some strange indentation (NFC)
Somehow this file ended up with a strange hybrid of the old "indent
inside a namespace" style and the new "don't", giving us a wonderful
two-space indent starting halfway through a namespace. Fix it.

llvm-svn: 230244
2015-02-23 19:27:00 +00:00
Justin Bogner 00270df517 InstrProf: Avoid creating profile names for symbols in system headers
We don't emit any coverage mapping for uncovered functions that come
from system headers, but we were creating a GlobalVariable with each
of their names. This is wasteful since the linker will need to dead
strip the unused symbols, and it can lead to issues when merging
coverage with others TUs that do have coverage for those functions.

llvm-svn: 226764
2015-01-22 02:17:23 +00:00
Justin Bogner 203f91e311 InstrProf: Don't emit counter increments in dead code
We were previously emitting counter increments even if we didn't have
an insertion point, which would result in a CallInst with no
parent. This leads to a crash, as in pr22166, if we try to do
GlobalDCE.

llvm-svn: 225495
2015-01-09 01:46:40 +00:00
Justin Bogner 970ac60573 InstrProf: Use LLVM's -instrprof pass for profiling
The logic for lowering profiling counters has been moved to an LLVM
pass. Emit the intrinsics rather than duplicating the whole pass in
clang.

llvm-svn: 223683
2014-12-08 19:04:51 +00:00
Justin Bogner 111c6533c2 InstrProf: Use the same names for variables as we use in the profile
There's no need to use different names for the local variables than we
use in the profile itself, and it's a bit simpler and easier to debug
if we're consistent.

llvm-svn: 223173
2014-12-02 23:15:30 +00:00
Justin Bogner 7f8cf5bff7 InstrProf: Remove some pointless indirection (NFC)
It doesn't make much sense to have std::unique_ptrs of std::string and
std::vector. Avoid some useless indirection by using these types
directly.

llvm-svn: 223166
2014-12-02 22:38:52 +00:00
Justin Bogner e5ee6c58d7 Reapply "InstrProf: Update for the LLVM API change in r218879"
Reapplying now that r218887 is in.

This reverts commit r218882, reapplying r218880.

llvm-svn: 218888
2014-10-02 16:44:01 +00:00
Justin Bogner 1c4fb4600d Revert "InstrProf: Update for the LLVM API change in r218879"
r218879 has been reverted for now, this needs to go to match.

This reverts commit r218880.

llvm-svn: 218882
2014-10-02 16:15:37 +00:00
Justin Bogner 94eabf58bd InstrProf: Update for the LLVM API change in r218879
llvm-svn: 218880
2014-10-02 16:04:18 +00:00
Alex Lorenz 1d45c5bc26 Coverage Mapping: store function's hash in coverage function records.
The profile data format was recently updated and the new indexing api
requires the code coverage tool to know the function's hash as well
as the function's name to get the execution counts for a function.

Differential Revision: http://reviews.llvm.org/D4995

llvm-svn: 216208
2014-08-21 19:25:27 +00:00
Alex Lorenz d42367478d Revert r215365 - Coverage mapping: emit mapping for cxx constructors that use microsoft's ABI
llvm-svn: 215371
2014-08-11 18:21:34 +00:00
Alex Lorenz 975f3fb3e9 Coverage mapping: emit mapping for cxx constructors that use microsoft's ABI
llvm-svn: 215365
2014-08-11 17:45:49 +00:00
Alex Lorenz f2cf38e020 Add a cc1 "dump-coverage-mapping" for testing coverage mapping.
Differential Revision: http://reviews.llvm.org/D4799

llvm-svn: 215258
2014-08-08 23:41:24 +00:00
Alex Lorenz ee02499a8f Add coverage mapping generation.
This patch adds the '-fcoverage-mapping' option which
allows clang to generate the coverage mapping information
that can be used to provide code coverage analysis using
the execution counts obtained from the instrumentation 
based profiling (-fprofile-instr-generate).

llvm-svn: 214752
2014-08-04 18:41:51 +00:00
Justin Bogner 9c6818ef00 InstrProf: Update for LLVM API change
We've added support for a multiple functions with the same name in
LLVM's profile data, so the lookup returning the function hash it
found doesn't make sense anymore. Update to pass in the hash we
expect.

This also adds a test that the version 1 format is still readable,
since the new API is expected to handle that.

llvm-svn: 214586
2014-08-01 22:50:16 +00:00
Justin Bogner 40b8ba1496 CodeGen: Improve warnings about uninstrumented files when profiling
Improve the warning when building with -fprofile-instr-use and a file
appears not to have been profiled at all. This keys on whether a
function is defined in the main file or not to avoid false negatives
when one includes a header with functions that have been profiled.

llvm-svn: 211760
2014-06-26 01:45:07 +00:00
Duncan P. N. Exon Smith 9121220804 InstrProf: Set profile data to visibility hidden
Shared objects are fairly broken for InstrProf right now -- a follow-up
commit in compiler-rt will fix the rest of this.

The main problem here is that at link time, profile data symbols in the
shared object might get used instead of symbols from the main
executable, creating invalid profile data sections.

<rdar://problem/16918688>

llvm-svn: 208939
2014-05-16 01:24:00 +00:00
Justin Bogner 3212b18bbf CodeGen: Avoid instrumenting implicit Decls more effectively
We don't assign counters for implicit Decls, but we were emitting code
to increment the (non-existent) counters and adding empty counter
lists in the output. This fixes the checks in assignRegionCounters and
emitInstrumentationData to do the right thing, and adds an assert for
the pathological case of emitting zero counters.

llvm-svn: 207203
2014-04-25 07:20:05 +00:00
Justin Bogner 8776638235 CodeGen: Remove an unused include
llvm-svn: 206667
2014-04-18 22:31:07 +00:00
Justin Bogner 837a6f6f79 CodeGen: Use LLVM's InstrProfReader in -fprofile-instr-use=
Update clang to use the InstrProfReader from LLVM to read
instrumentation based profile data. This also switches us from the
naive text format to the binary format, since that's what's
implemented in the reader.

llvm-svn: 206658
2014-04-18 21:52:00 +00:00
Justin Bogner fc83c1105c [Cleanup] Remove a trailing whitespace
llvm-svn: 206657
2014-04-18 21:51:09 +00:00
Duncan P. N. Exon Smith 4bc7731a29 InstrProf: Calculate a better function hash
The function hash should change when control flow changes.  This patch
hashes the type of each AST node that affects counters, rather than just
counting how many there are.  These types are combined into a small
enumerator that currently has 16 values.

The new hash algorithm packs the enums for consecutively visited types
into a `uint64_t`.  In order to save space for new types, the types are
assumed to be 6-bit values (instead of 4-bit).  In order to minimize
overhead for functions with little control flow, the `uint64_t` is used
directly as a hash if it never fills up; if it does, it's passed through
an MD5 context.

<rdar://problem/16435801>

llvm-svn: 206397
2014-04-16 16:03:27 +00:00
Justin Bogner e2ef2a09ef CodeGen: Emit warnings for out of date profile data during PGO
This adds a warning that triggers when profile data doesn't match for
the source that's being compiled with -fprofile-instr-use=. This fires
only once per translation unit, as warning on every mismatched
function would be quite noisy.

llvm-svn: 206322
2014-04-15 21:22:35 +00:00
Justin Bogner 3f0c79ce8d CodeGen: Remove a comment that isn't in the right place
This comment also appears elsewhere where it actually makes sense, and
it's just confusing here.

llvm-svn: 206321
2014-04-15 20:37:41 +00:00
Justin Bogner 81ab90f7ed CodeGen: Handle CapturedStmt in instrumentation based profiling
CapturedStmt was being ignored by instrumentation based profiling, and
its counters attributed to the containing function. Instead, we need
to treat this as a top level entity, like we do with blocks.

llvm-svn: 206231
2014-04-15 00:50:54 +00:00
Justin Bogner 191ec63b71 CodeGen: Fix handling of C++11 lambdas in profiling
Until now we were generating duplicate counters for lambdas: one set
in the function where the lambda was declared and another for the
lambda itself. Instead, we should skip over the bodies of lambdas in
their containing contexts.

llvm-svn: 206081
2014-04-11 23:06:35 +00:00
Bob Wilson d893142595 [PGO] Change MapRegionCounters to be a RecursiveASTVisitor.
This avoids the overhead of specifying all the traversal code when using
ConstStmtVisitor and makes it a lot easier to maintain this.

llvm-svn: 206039
2014-04-11 17:16:13 +00:00
Justin Bogner 53c55d993f CodeGen: Handle binary conditional operators in PGO instrumentation
This treats binary conditional operators in the same way as ternary
conditional operators for instrumentation based profiling.

llvm-svn: 206021
2014-04-11 06:10:10 +00:00
Duncan P. N. Exon Smith 3fefedb24c Switch from constexpr to const char *const
Responding to Richard Smith's review of r205037.

llvm-svn: 206008
2014-04-11 00:43:16 +00:00
Duncan P. N. Exon Smith 4a2f5ae8d5 InstrProf: Rename Decl parameters from S to D
No functionality change.

<rdar://problem/16435801>

llvm-svn: 206002
2014-04-10 23:37:36 +00:00
Duncan P. N. Exon Smith e9624291b1 InstrProf: Read unsigned numbers with strtoul and strtoull
Fixes a bug where unsigned numbers are read using strtol and strtoll.

I don't have a testcase because this bug is effectively unobservable
right now.  To expose the problem in the hash, we would need a function
with greater than INT64_MAX counters, which we don't handle anyway.  To
expose the problem in the function count, we'd need a function with
greater than INT32_MAX counters; this is theoretically observable, but
it isn't a practical testcase to check in.

An upcoming commit changes the hash to be non-trivial, so we'll get some
coverage eventually.

<rdar://problem/16435801>

llvm-svn: 206001
2014-04-10 23:37:34 +00:00
Justin Bogner f2ea775ed9 CodeGen: Move PGO initialization into Release()
Emitting the PGO initialization in EmitGlobalFunctionDefinition is
inefficient, since this only has an effect once per module.  We move
this to Release() with the rest of the once-per-module logic.

llvm-svn: 205977
2014-04-10 18:13:13 +00:00
Justin Bogner f3aefca7c1 CodeGen: Don't create branch weight metadata from empty profiles
If all of our weights are zero when calculating branch weights, it
means we haven't profiled the code in question. Avoid creating a
metadata node that says all branches are equally likely in this case.

The test also checks constructs that hit the other createBranchWeights
overload. These were already working.

llvm-svn: 205606
2014-04-04 02:48:51 +00:00
Duncan P. N. Exon Smith 966e320664 Use constexpr again, this time portably
Responding to Justin's review of r205025.

llvm-svn: 205037
2014-03-28 19:27:37 +00:00
Duncan P. N. Exon Smith 3b3edfb16d InstrProf: Fix MSVC after r205023
llvm-svn: 205025
2014-03-28 18:22:26 +00:00
Duncan P. N. Exon Smith d971cd1b18 InstrProf: Emit runtime hook directly in IRGen
-u behaviour is apparently not portable between linkers (see cfe-commits
discussions for r204379 and r205012).  I've moved the logic to IRGen,
where it should have been in the first place.

I don't have a Linux system to test this on, so it's possible this logic
*still* doesn't pull in the instrumented profiling runtime on Linux.

I'm in the process of getting tests going on the compiler-rt side
(llvm-commits "[PATCH] InstrProf: Add initial compiler-rt test").  Once
we have tests for the full flow there, the runtime logic should get a
whole lot less brittle.

<rdar://problem/16458307>

llvm-svn: 205023
2014-03-28 17:53:22 +00:00
Duncan P. N. Exon Smith 1b67cfd40f InstrProf: Use unique_ptr
llvm-svn: 204846
2014-03-26 19:26:05 +00:00
Duncan P. N. Exon Smith 3586be7216 InstrProf: Use references
llvm-svn: 204845
2014-03-26 19:26:02 +00:00
Duncan P. N. Exon Smith 7c41451bc9 PGO: Don't define instrumentation data available_externally
Variables with available_externally linkage can be dropped at will.
This causes link errors, since there are still references to the
instrumentation!  linkonce_odr is almost equivalent, so use that
instead.

As a drive-by fix (I don't have an Elf system, so I'm not sure how to
write a testcase), use linkonce linkage for the instrumentation of
extern_weak functions.

<rdar://problem/15943240>

llvm-svn: 204408
2014-03-20 22:50:08 +00:00