//
//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "sample-profile"
-
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
using namespace llvm;
+#define DEBUG_TYPE "sample-profile"
+
// Command line option to specify the file to read samples from. This is
// mainly used for debugging.
static cl::opt<std::string> SampleProfileFile(
class SampleFunctionProfile {
public:
SampleFunctionProfile()
- : TotalSamples(0), TotalHeadSamples(0), HeaderLineno(0), DT(0), PDT(0),
- LI(0), Ctx(0) {}
+ : TotalSamples(0), TotalHeadSamples(0), HeaderLineno(0), DT(nullptr),
+ PDT(nullptr), LI(nullptr), Ctx(nullptr) {}
unsigned getFunctionLoc(Function &F);
bool emitAnnotations(Function &F, DominatorTree *DomTree,
return Profiles[F.getName()];
}
- /// \brief Report a parse error message and stop compilation.
+ /// \brief Report a parse error message.
void reportParseError(int64_t LineNumber, Twine Msg) const {
DiagnosticInfoSampleProfile Diag(Filename.data(), LineNumber, Msg);
M.getContext().diagnose(Diag);
/// \brief Name of the profile file to load.
StringRef Filename;
- /// \brief Flag indicating whether the profile input loaded succesfully.
+ /// \brief Flag indicating whether the profile input loaded successfully.
bool ProfileIsValid;
};
}
// Read the profile of each function. Since each function may be
// mentioned more than once, and we are collecting flat profiles,
// accumulate samples as we parse them.
- Regex HeadRE("^([^:]+):([0-9]+):([0-9]+)$");
+ Regex HeadRE("^([^0-9].*):([0-9]+):([0-9]+)$");
Regex LineSample("^([0-9]+)\\.?([0-9]+)?: ([0-9]+)(.*)$");
while (!LineIt.is_at_eof()) {
- // Read the header of each function. The function header should
- // have this format:
+ // Read the header of each function.
//
- // function_name:total_samples:total_head_samples
+ // Note that for function identifiers we are actually expecting
+ // mangled names, but we may not always get them. This happens when
+ // the compiler decides not to emit the function (e.g., it was inlined
+ // and removed). In this case, the binary will not have the linkage
+ // name for the function, so the profiler will emit the function's
+ // unmangled name, which may contain characters like ':' and '>' in its
+ // name (member functions, templates, etc).
//
- // See above for an explanation of each field.
+ // The only requirement we place on the identifier, then, is that it
+ // should not begin with a number.
SmallVector<StringRef, 3> Matches;
if (!HeadRE.match(*LineIt, &Matches)) {
reportParseError(LineIt.line_number(),