[llvm] r271822 - [PM] code refactoring /NFC

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 4 22:11:44 PDT 2016


Agreed -- this is actually a good idea -- I got burned by this couple of
times (making the assumption that clang-format-diff will minimize the scope
of format change ..)

David

On Sat, Jun 4, 2016 at 10:08 PM, Chandler Carruth <chandlerc at gmail.com>
wrote:

> In the future, I'd also suggest doing clang-format first, and separately.
>
> On Sat, Jun 4, 2016 at 10:07 PM Xinliang David Li via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> yes.  The change extract the transformation into its own class (to be
>> reusable) and make a new class for the legacy pass as a wrapper to the
>> newly extracted one.  (the larger diff is caused by clang-format).
>>
>> David
>>
>> On Sat, Jun 4, 2016 at 9:40 PM, Chandler Carruth via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>>> On Sat, Jun 4, 2016 at 8:46 PM Xinliang David Li via llvm-commits <
>>> llvm-commits at lists.llvm.org> wrote:
>>>
>>>> Author: davidxl
>>>> Date: Sat Jun  4 22:40:03 2016
>>>> New Revision: 271822
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=271822&view=rev
>>>> Log:
>>>> [PM] code refactoring /NFC
>>>>
>>>
>>> Please write somewhat more detailed commit messages? For example, what
>>> refactoring? To what end? That makes it much easier to do code review.
>>>
>>>
>>>>
>>>> Modified:
>>>>     llvm/trunk/include/llvm/InitializePasses.h
>>>>     llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>>>>     llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
>>>>
>>>> Modified: llvm/trunk/include/llvm/InitializePasses.h
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=271822&r1=271821&r2=271822&view=diff
>>>>
>>>> ==============================================================================
>>>> --- llvm/trunk/include/llvm/InitializePasses.h (original)
>>>> +++ llvm/trunk/include/llvm/InitializePasses.h Sat Jun  4 22:40:03 2016
>>>> @@ -123,7 +123,7 @@ void initializeEarlyIfConverterPass(Pass
>>>>  void initializeEdgeBundlesPass(PassRegistry&);
>>>>  void initializeExpandPostRAPass(PassRegistry&);
>>>>  void initializeAAResultsWrapperPassPass(PassRegistry &);
>>>> -void initializeGCOVProfilerPass(PassRegistry&);
>>>> +void initializeGCOVProfilerLegacyPassPass(PassRegistry&);
>>>>  void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&);
>>>>  void initializePGOInstrumentationUseLegacyPassPass(PassRegistry&);
>>>>  void initializePGOIndirectCallPromotionLegacyPassPass(PassRegistry&);
>>>>
>>>> Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=271822&r1=271821&r2=271822&view=diff
>>>>
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>>>> (original)
>>>> +++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Sat
>>>> Jun  4 22:40:03 2016
>>>> @@ -68,85 +68,95 @@ GCOVOptions GCOVOptions::getDefault() {
>>>>  }
>>>>
>>>>  namespace {
>>>> -  class GCOVFunction;
>>>> +class GCOVFunction;
>>>>
>>>> -  class GCOVProfiler : public ModulePass {
>>>> -  public:
>>>> -    static char ID;
>>>> -    GCOVProfiler() : GCOVProfiler(GCOVOptions::getDefault()) {}
>>>> -    GCOVProfiler(const GCOVOptions &Opts) : ModulePass(ID),
>>>> Options(Opts) {
>>>> -      assert((Options.EmitNotes || Options.EmitData) &&
>>>> -             "GCOVProfiler asked to do nothing?");
>>>> -      ReversedVersion[0] = Options.Version[3];
>>>> -      ReversedVersion[1] = Options.Version[2];
>>>> -      ReversedVersion[2] = Options.Version[1];
>>>> -      ReversedVersion[3] = Options.Version[0];
>>>> -      ReversedVersion[4] = '\0';
>>>> -      initializeGCOVProfilerPass(*PassRegistry::getPassRegistry());
>>>> -    }
>>>> -    const char *getPassName() const override {
>>>> -      return "GCOV Profiler";
>>>> -    }
>>>> -
>>>> -  private:
>>>> -    bool runOnModule(Module &M) override;
>>>> -
>>>> -    // Create the .gcno files for the Module based on DebugInfo.
>>>> -    void emitProfileNotes();
>>>> -
>>>> -    // Modify the program to track transitions along edges and call
>>>> into the
>>>> -    // profiling runtime to emit .gcda files when run.
>>>> -    bool emitProfileArcs();
>>>> -
>>>> -    // Get pointers to the functions in the runtime library.
>>>> -    Constant *getStartFileFunc();
>>>> -    Constant *getIncrementIndirectCounterFunc();
>>>> -    Constant *getEmitFunctionFunc();
>>>> -    Constant *getEmitArcsFunc();
>>>> -    Constant *getSummaryInfoFunc();
>>>> -    Constant *getDeleteWriteoutFunctionListFunc();
>>>> -    Constant *getDeleteFlushFunctionListFunc();
>>>> -    Constant *getEndFileFunc();
>>>> -
>>>> -    // Create or retrieve an i32 state value that is used to represent
>>>> the
>>>> -    // pred block number for certain non-trivial edges.
>>>> -    GlobalVariable *getEdgeStateValue();
>>>> -
>>>> -    // Produce a table of pointers to counters, by predecessor and
>>>> successor
>>>> -    // block number.
>>>> -    GlobalVariable *buildEdgeLookupTable(Function *F,
>>>> -                                         GlobalVariable *Counter,
>>>> -                                         const UniqueVector<BasicBlock
>>>> *>&Preds,
>>>> -                                         const
>>>> UniqueVector<BasicBlock*>&Succs);
>>>> -
>>>> -    // Add the function to write out all our counters to the global
>>>> destructor
>>>> -    // list.
>>>> -    Function *insertCounterWriteout(ArrayRef<std::pair<GlobalVariable*,
>>>> -                                                       MDNode*> >);
>>>> -    Function *insertFlush(ArrayRef<std::pair<GlobalVariable*, MDNode*>
>>>> >);
>>>> -    void insertIndirectCounterIncrement();
>>>> -
>>>> -    std::string mangleName(const DICompileUnit *CU, const char
>>>> *NewStem);
>>>> -
>>>> -    GCOVOptions Options;
>>>> -
>>>> -    // Reversed, NUL-terminated copy of Options.Version.
>>>> -    char ReversedVersion[5];
>>>> -    // Checksum, produced by hash of EdgeDestinations
>>>> -    SmallVector<uint32_t, 4> FileChecksums;
>>>> -
>>>> -    Module *M;
>>>> -    LLVMContext *Ctx;
>>>> -    SmallVector<std::unique_ptr<GCOVFunction>, 16> Funcs;
>>>> -  };
>>>> +class GCOVProfiler {
>>>> +public:
>>>> +  GCOVProfiler() : GCOVProfiler(GCOVOptions::getDefault()) {}
>>>> +  GCOVProfiler(const GCOVOptions &Opts) : Options(Opts) {
>>>> +    assert((Options.EmitNotes || Options.EmitData) &&
>>>> +           "GCOVProfiler asked to do nothing?");
>>>> +    ReversedVersion[0] = Options.Version[3];
>>>> +    ReversedVersion[1] = Options.Version[2];
>>>> +    ReversedVersion[2] = Options.Version[1];
>>>> +    ReversedVersion[3] = Options.Version[0];
>>>> +    ReversedVersion[4] = '\0';
>>>> +  }
>>>> +  bool runOnModule(Module &M);
>>>> +
>>>> +private:
>>>> +  // Create the .gcno files for the Module based on DebugInfo.
>>>> +  void emitProfileNotes();
>>>> +
>>>> +  // Modify the program to track transitions along edges and call into
>>>> the
>>>> +  // profiling runtime to emit .gcda files when run.
>>>> +  bool emitProfileArcs();
>>>> +
>>>> +  // Get pointers to the functions in the runtime library.
>>>> +  Constant *getStartFileFunc();
>>>> +  Constant *getIncrementIndirectCounterFunc();
>>>> +  Constant *getEmitFunctionFunc();
>>>> +  Constant *getEmitArcsFunc();
>>>> +  Constant *getSummaryInfoFunc();
>>>> +  Constant *getDeleteWriteoutFunctionListFunc();
>>>> +  Constant *getDeleteFlushFunctionListFunc();
>>>> +  Constant *getEndFileFunc();
>>>> +
>>>> +  // Create or retrieve an i32 state value that is used to represent
>>>> the
>>>> +  // pred block number for certain non-trivial edges.
>>>> +  GlobalVariable *getEdgeStateValue();
>>>> +
>>>> +  // Produce a table of pointers to counters, by predecessor and
>>>> successor
>>>> +  // block number.
>>>> +  GlobalVariable *buildEdgeLookupTable(Function *F, GlobalVariable
>>>> *Counter,
>>>> +                                       const UniqueVector<BasicBlock
>>>> *> &Preds,
>>>> +                                       const UniqueVector<BasicBlock
>>>> *> &Succs);
>>>> +
>>>> +  // Add the function to write out all our counters to the global
>>>> destructor
>>>> +  // list.
>>>> +  Function *
>>>> +  insertCounterWriteout(ArrayRef<std::pair<GlobalVariable *, MDNode
>>>> *>>);
>>>> +  Function *insertFlush(ArrayRef<std::pair<GlobalVariable *, MDNode
>>>> *>>);
>>>> +  void insertIndirectCounterIncrement();
>>>> +
>>>> +  std::string mangleName(const DICompileUnit *CU, const char *NewStem);
>>>> +
>>>> +  GCOVOptions Options;
>>>> +
>>>> +  // Reversed, NUL-terminated copy of Options.Version.
>>>> +  char ReversedVersion[5];
>>>> +  // Checksum, produced by hash of EdgeDestinations
>>>> +  SmallVector<uint32_t, 4> FileChecksums;
>>>> +
>>>> +  Module *M;
>>>> +  LLVMContext *Ctx;
>>>> +  SmallVector<std::unique_ptr<GCOVFunction>, 16> Funcs;
>>>> +};
>>>> +
>>>> +class GCOVProfilerLegacyPass : public ModulePass {
>>>> +public:
>>>> +  static char ID;
>>>> +  GCOVProfilerLegacyPass()
>>>> +      : GCOVProfilerLegacyPass(GCOVOptions::getDefault()) {}
>>>> +  GCOVProfilerLegacyPass(const GCOVOptions &Opts)
>>>> +      : ModulePass(ID), Profiler(Opts) {
>>>> +
>>>> initializeGCOVProfilerLegacyPassPass(*PassRegistry::getPassRegistry());
>>>> +  }
>>>> +  const char *getPassName() const override { return "GCOV Profiler"; }
>>>> +
>>>> +  bool runOnModule(Module &M) override { return
>>>> Profiler.runOnModule(M); }
>>>> +
>>>> +private:
>>>> +  GCOVProfiler Profiler;
>>>> +};
>>>>  }
>>>>
>>>> -char GCOVProfiler::ID = 0;
>>>> -INITIALIZE_PASS(GCOVProfiler, "insert-gcov-profiling",
>>>> +char GCOVProfilerLegacyPass::ID = 0;
>>>> +INITIALIZE_PASS(GCOVProfilerLegacyPass, "insert-gcov-profiling",
>>>>                  "Insert instrumentation for GCOV profiling", false,
>>>> false)
>>>>
>>>>  ModulePass *llvm::createGCOVProfilerPass(const GCOVOptions &Options) {
>>>> -  return new GCOVProfiler(Options);
>>>> +  return new GCOVProfilerLegacyPass(Options);
>>>>  }
>>>>
>>>>  static StringRef getFunctionName(const DISubprogram *SP) {
>>>>
>>>> Modified: llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp?rev=271822&r1=271821&r2=271822&view=diff
>>>>
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
>>>> (original)
>>>> +++ llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp Sat
>>>> Jun  4 22:40:03 2016
>>>> @@ -59,7 +59,7 @@ void llvm::initializeInstrumentation(Pas
>>>>    initializeAddressSanitizerPass(Registry);
>>>>    initializeAddressSanitizerModulePass(Registry);
>>>>    initializeBoundsCheckingPass(Registry);
>>>> -  initializeGCOVProfilerPass(Registry);
>>>> +  initializeGCOVProfilerLegacyPassPass(Registry);
>>>>    initializePGOInstrumentationGenLegacyPassPass(Registry);
>>>>    initializePGOInstrumentationUseLegacyPassPass(Registry);
>>>>    initializePGOIndirectCallPromotionLegacyPassPass(Registry);
>>>>
>>>>
>>>> _______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160604/13ac7c12/attachment.html>


More information about the llvm-commits mailing list