[PATCH] instcombine: Only create library call simplifier once

Meador Inge meadori at codesourcery.com
Thu Mar 7 16:39:14 PST 2013


On 03/07/2013 04:34 PM, Michael Ilseman wrote:

> Oh, I see, you're wanting to cache the hash table from the first call.
> Unfortunately, this method seems dangerous and contrary to the design
> of the PassManager. Is there some higher-level structure that it makes
> sense to pin it to? For example, maybe the TargetLibraryInfo, Module,
> LLVMContext, etc would make sense.

Hmmmm.  So in general how to I dynamically create a new object for a pass that
is independent of any function being transformed by a FunctionPass?  The docs
make it sound like this is what 'doInitialization' is for [1].  However, that
doesn't seem to work because I need access to the 'TargetLibraryInfo'.  Also, I
have been steered away from 'doInitialization' in past reviews.

FWIW, the old SimplifyLibCalls pass that I migrated all of this from was
already doing something quite similar:

  class SimplifyLibCalls : public FunctionPass {
    TargetLibraryInfo *TLI;

    StringMap<LibCallOptimization*> Optimizations;
    ...
  }

  bool SimplifyLibCalls::runOnFunction(Function &F) {
    TLI = &getAnalysis<TargetLibraryInfo>();

    if (Optimizations.empty())
      InitOptimizations();

    ...
   }

I guess it shouldn't have been doing that?

[1] http://llvm.org/docs/WritingAnLLVMPass.html#the-doinitialization-module-method

-- 
Meador Inge
CodeSourcery / Mentor Embedded



More information about the llvm-commits mailing list