diff options
| author | Bob Wilson <bob.wilson@apple.com> | 2014-03-06 06:10:02 +0000 |
|---|---|---|
| committer | Bob Wilson <bob.wilson@apple.com> | 2014-03-06 06:10:02 +0000 |
| commit | 4084bb9da5b07d9a074e1cfec8279daa4d61ab56 (patch) | |
| tree | 2769a146c37d3f535741607a2355d08c501b747c /lib/CodeGen/CodeGenPGO.cpp | |
| parent | 67fafb973cfbd0ac08f3177a344e5cdd4fee4ae6 (diff) | |
| download | clang-4084bb9da5b07d9a074e1cfec8279daa4d61ab56.tar.gz clang-4084bb9da5b07d9a074e1cfec8279daa4d61ab56.tar.bz2 clang-4084bb9da5b07d9a074e1cfec8279daa4d61ab56.tar.xz | |
PGO: add instrumentation for Objective-C methods.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203085 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenPGO.cpp')
| -rw-r--r-- | lib/CodeGen/CodeGenPGO.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 6678c37929..349160ad35 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -49,11 +49,17 @@ PGOProfileData::PGOProfileData(CodeGenModule &CGM, std::string Path) while (CurPtr < BufferEnd) { // Read the function name. const char *FuncStart = CurPtr; - CurPtr = strchr(CurPtr, ' '); + // For Objective-C methods, the name may include whitespace, so search + // backward from the end of the line to find the space that separates the + // name from the number of counters. (This is a temporary hack since we are + // going to completely replace this file format in the near future.) + CurPtr = strchr(CurPtr, '\n'); if (!CurPtr) { ReportBadPGOData(CGM, "pgo data file has malformed function entry"); return; } + while (*--CurPtr != ' ') + ; StringRef FuncName(FuncStart, CurPtr - FuncStart); // Read the number of counters. @@ -129,8 +135,10 @@ bool PGOProfileData::getFunctionCounts(StringRef FuncName, const char *CurPtr = DataBuffer->getBufferStart() + OffsetIter->getValue(); // Skip over the function name. - CurPtr = strchr(CurPtr, ' '); + CurPtr = strchr(CurPtr, '\n'); assert(CurPtr && "pgo-data has corrupted function entry"); + while (*--CurPtr != ' ') + ; // Read the number of counters. char *EndPtr; @@ -303,6 +311,10 @@ namespace { (*CounterMap)[S->getBody()] = NextCounter++; Visit(S->getBody()); } + void VisitObjCMethodDecl(const ObjCMethodDecl *S) { + (*CounterMap)[S->getBody()] = NextCounter++; + Visit(S->getBody()); + } /// Assign a counter to track the block following a label. void VisitLabelStmt(const LabelStmt *S) { (*CounterMap)[S] = NextCounter++; @@ -462,6 +474,13 @@ namespace { Visit(S->getBody()); } + void VisitObjCMethodDecl(const ObjCMethodDecl *S) { + RegionCounter Cnt(PGO, S->getBody()); + Cnt.beginRegion(); + (*CountMap)[S->getBody()] = PGO.getCurrentRegionCount(); + Visit(S->getBody()); + } + void VisitReturnStmt(const ReturnStmt *S) { RecordStmtCount(S); if (S->getRetValue()) @@ -781,6 +800,8 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) { MapRegionCounters Walker(RegionCounterMap); if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) Walker.VisitFunctionDecl(FD); + else if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) + Walker.VisitObjCMethodDecl(MD); NumRegionCounters = Walker.NextCounter; } @@ -789,6 +810,8 @@ void CodeGenPGO::computeRegionCounts(const Decl *D) { ComputeRegionCounts Walker(StmtCountMap, *this); if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) Walker.VisitFunctionDecl(FD); + else if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) + Walker.VisitObjCMethodDecl(MD); } void CodeGenPGO::emitCounterVariables() { |
