AArch64/ARM64: port more tests
[oota-llvm.git] / lib / Transforms / Scalar / SampleProfile.cpp
index e8adc64eeeedf26b92993217d99a39ec2327d588..2f03edda18abd741313828c4c04a7caf39ecf0e8 100644 (file)
@@ -22,8 +22,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "sample-profile"
-
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -54,6 +52,8 @@
 
 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(
@@ -94,7 +94,7 @@ template <> struct DenseMapInfo<InstructionLocation> {
                                DiscriminatorInfo::getTombstoneKey());
   }
   static inline unsigned getHashValue(InstructionLocation Val) {
-    return DenseMapInfo<std::pair<int, unsigned> >::getHashValue(
+    return DenseMapInfo<std::pair<int, unsigned>>::getHashValue(
         std::pair<int, unsigned>(Val.LineOffset, Val.Discriminator));
   }
   static inline bool isEqual(InstructionLocation LHS, InstructionLocation RHS) {
@@ -110,7 +110,7 @@ typedef DenseMap<BasicBlock *, unsigned> BlockWeightMap;
 typedef DenseMap<BasicBlock *, BasicBlock *> EquivalenceClassMap;
 typedef std::pair<BasicBlock *, BasicBlock *> Edge;
 typedef DenseMap<Edge, unsigned> EdgeWeightMap;
-typedef DenseMap<BasicBlock *, SmallVector<BasicBlock *, 8> > BlockEdgeMap;
+typedef DenseMap<BasicBlock *, SmallVector<BasicBlock *, 8>> BlockEdgeMap;
 
 /// \brief Representation of the runtime profile for a function.
 ///
@@ -251,7 +251,7 @@ public:
     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);
@@ -315,7 +315,7 @@ protected:
   /// \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;
 };
 }
@@ -454,8 +454,7 @@ bool SampleModuleProfile::loadText() {
   error_code EC = MemoryBuffer::getFile(Filename, Buffer);
   if (EC) {
     std::string Msg(EC.message());
-    DiagnosticInfoSampleProfile Diag(Filename.data(), Msg);
-    M.getContext().diagnose(Diag);
+    M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg));
     return false;
   }
   line_iterator LineIt(*Buffer, '#');
@@ -463,15 +462,21 @@ bool SampleModuleProfile::loadText() {
   // 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(),
@@ -973,9 +978,8 @@ unsigned SampleFunctionProfile::getFunctionLoc(Function &F) {
     }
   }
 
-  DiagnosticInfoSampleProfile Diag("No debug information found in function " +
-                                   F.getName());
-  F.getContext().diagnose(Diag);
+  F.getContext().diagnose(DiagnosticInfoSampleProfile(
+      "No debug information found in function " + F.getName()));
   return 0;
 }