[PATCH] D23734: Add -fprofile-dir= to clang.

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 21:12:57 PDT 2016


compnerd added inline comments.

================
Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:447
@@ -432,3 +446,3 @@
         return Filename.str();
       }
     }
----------------
A quick pass over this yielded something like:

    if (N->getNumOperands() != 2 && N->getNumOperands() != 3)
      continue;

    bool HasProfileDir = N->getNumOperands() == 3;
    unsigned Offset = HasProfileDir ? 1 : 0;

    auto *NotesFile = dyn_cast<MDString>(N->getOperand(Offset + 0));
    auto *CovFile = dyn_cast<MDString>(N->getOperand(Offset + 0));
    auto *CompileUnit = dyn_cast<MDNode>(N->getOperand(Offset + 1));

    if ((!HasProfileDir || !NotesFile) || !CovFile || !CompileUnit)
      continue;

    if (CompileUnit == CU) {
      bool GCNO = OutputType == GCovFileType::GCNO;
      if (HasProfileDir) {
        return GCNO ? NotesFile->getString() : CovFile->getString();
      } else {
        SmallString<128> FileName = CovFile->getString();
        sys::path::replace_extension(FileName, GCNO ? "gcno" : "gcda");
        return FileName.str();
      }
    }

It does reduce a bit of the duplication, and still accounts for the string duplication that you were pointing out.  I think it makes it slightly easier to read due to the variable de-duplication (at the slight cost of an extra pointer on the stack and an extra lookup).


https://reviews.llvm.org/D23734





More information about the cfe-commits mailing list