writing an alias analysis pass?

Hi,

I’m attempting to do some alias analysis & other memory inspection. I’ve written a pointless AliasAnalysis pass (that says everything must alias) to attempt to verify that my pass is getting picked up & run by opt.

I run opt with: opt -load ~/Applications/llvm/lib/MustAA.so -must-aa -aa-eval -debug < trace0.ll

I see my pass being initialized, but never being called (I see only may alias results).

Any ideas as to what to do to debug this? Or what I’m missing? I’ve read through http://llvm.org/docs/AliasAnalysis.html and don’t see anything that I’m missing.

Thanks,
Matthew

P.S. Here’s the full source code of my pass:

#define DEBUG_TYPE “must-aa”
#include “llvm/Pass.h”
#include “llvm/Analysis/AliasAnalysis.h”
#include “llvm/Support/raw_ostream.h”
#include “llvm/Support/Debug.h”
using namespace llvm;

namespace {
struct EverythingMustAlias : public ImmutablePass, public AliasAnalysis {
static char ID;
EverythingMustAlias() : ImmutablePass(ID) {}

virtual void initializePass() {
DEBUG(dbgs() << “Initializing everything-must-alias\n”);
InitializeAliasAnalysis(this);
}

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AliasAnalysis::getAnalysisUsage(AU);
AU.setPreservesAll();
}

virtual AliasResult alias(const Location &LocA, const Location &LocB) {
DEBUG(dbgs() << “Everything must alias!\n”);
return AliasAnalysis::MustAlias;
}
};
}

namespace llvm {
void initializeEverythingMustAliasPass(PassRegistry &Registry);
}

char EverythingMustAlias::ID = 0;
static RegisterPass A(“must-aa”, “Everything must alias”);
INITIALIZE_AG_PASS(EverythingMustAlias, AliasAnalysis, “must-aa”,
“Everything must alias”, false, true, false)

Matthew O'Connor wrote:

Hi,

I'm attempting to do some alias analysis & other memory inspection. I've
written a pointless AliasAnalysis pass (that says everything must alias)
to attempt to verify that my pass is getting picked up & run by opt.

I run opt with: opt -load ~/Applications/llvm/lib/MustAA.so -must-aa
-aa-eval -debug < trace0.ll

I see my pass being initialized, but never being called (I see only may
alias results).

Any ideas as to what to do to debug this? Or what I'm missing? I've read
through LLVM Alias Analysis Infrastructure — LLVM 18.0.0git documentation and don't see anything
that I'm missing.

Thanks,
Matthew

P.S. Here's the full source code of my pass:

#define DEBUG_TYPE "must-aa"
#include "llvm/Pass.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h"
using namespace llvm;

namespace {
struct EverythingMustAlias : public ImmutablePass, public AliasAnalysis {

Because you have multiple inheritance on a Pass, you'll need this:

     /// getAdjustedAnalysisPointer - This method is used when a pass implements
     /// an analysis interface through multiple inheritance. If needed, it
     /// should override this to adjust the this pointer as needed for the
     /// specified pass info.
     void *getAdjustedAnalysisPointer(const void *ID) override {
       if (ID == &AliasAnalysis::ID)
         return (AliasAnalysis*)this;
       return this;
     }

There may be another issue beyond that, I haven't tried it.

Nick

Matthew O'Connor wrote:

Hi,

I'm attempting to do some alias analysis & other memory inspection. I've
written a pointless AliasAnalysis pass (that says everything must alias)
to attempt to verify that my pass is getting picked up & run by opt.

I run opt with: opt -load ~/Applications/llvm/lib/MustAA.so -must-aa
-aa-eval -debug < trace0.ll

I see my pass being initialized, but never being called (I see only may
alias results).

Any ideas as to what to do to debug this? Or what I'm missing? I've read
through LLVM Alias Analysis Infrastructure — LLVM 18.0.0git documentation and don't see anything
that I'm missing.

Thanks,
Matthew

P.S. Here's the full source code of my pass:

#define DEBUG_TYPE "must-aa"
#include "llvm/Pass.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h"
using namespace llvm;

namespace {
struct EverythingMustAlias : public ImmutablePass, public AliasAnalysis {

Because you have multiple inheritance on a Pass, you'll need this:

    /// getAdjustedAnalysisPointer - This method is used when a pass
implements
    /// an analysis interface through multiple inheritance. If needed, it
    /// should override this to adjust the this pointer as needed for the
    /// specified pass info.
    void *getAdjustedAnalysisPointer(const void *ID) override {
      if (ID == &AliasAnalysis::ID)
        return (AliasAnalysis*)this;
      return this;
    }

There may be another issue beyond that, I haven't tried it.

Nick

I overrode Pass's member function:
    virtual void *getAdjustedAnalysisPointer(AnalysisID ID);

I'm not seeing getAdjustedAnalysisPointer being called.

Any other ideas?

Hi,

I'm attempting to do some alias analysis & other memory inspection. I've
written a pointless AliasAnalysis pass (that says everything must alias) to
attempt to verify that my pass is getting picked up & run by opt.

I run opt with: opt -load ~/Applications/llvm/lib/MustAA.so -must-aa
-aa-eval -debug < trace0.ll

I see my pass being initialized, but never being called (I see only may
alias results).

Any ideas as to what to do to debug this? Or what I'm missing? I've read
through LLVM Alias Analysis Infrastructure — LLVM 18.0.0git documentation and don't see anything
that I'm missing.

Thanks,
Matthew

P.S. Here's the full source code of my pass:

#define DEBUG_TYPE "must-aa"
#include "llvm/Pass.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h"
using namespace llvm;

namespace {
struct EverythingMustAlias : public ImmutablePass, public AliasAnalysis {
  static char ID;
  EverythingMustAlias() : ImmutablePass(ID) {}

  virtual void initializePass() {
    DEBUG(dbgs() << "Initializing everything-must-alias\n");
    InitializeAliasAnalysis(this);
  }

  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
    AliasAnalysis::getAnalysisUsage(AU);
    AU.setPreservesAll();
  }

  virtual AliasResult alias(const Location &LocA, const Location &LocB) {
    DEBUG(dbgs() << "Everything must alias!\n");
    return AliasAnalysis::MustAlias;
  }
};
}

namespace llvm {
void initializeEverythingMustAliasPass(PassRegistry &Registry);
}

char EverythingMustAlias::ID = 0;
static RegisterPass<EverythingMustAlias> A("must-aa", "Everything must
alias");

static RegisterPass<EverythingMustAlias> A("must-aa", "Everything must
alias", false, true);

Can you try this?

Hi Matthew,

Did you add your alias analysis pass initializeEverythingMustAliasPass() into llvm::initializeAnalysis(PassRegistry &Registry) {} ?
This will initialize it linked into the Analysis library.

thanks,
chen

Hi Matthew,

Did you add your alias analysis pass initializeEverythingMustAliasPass()
into llvm::initializeAnalysis(PassRegistry &Registry) {} ?
This will initialize it linked into the Analysis library.

thanks,
chen

I want to be able to load my pass from an external library & not have it
compiled into opt.

Hi,

I'm attempting to do some alias analysis & other memory inspection. I've
written a pointless AliasAnalysis pass (that says everything must alias) to
attempt to verify that my pass is getting picked up & run by opt.

I run opt with: opt -load ~/Applications/llvm/lib/MustAA.so -must-aa
-aa-eval -debug < trace0.ll

I see my pass being initialized, but never being called (I see only may
alias results).

Any ideas as to what to do to debug this? Or what I'm missing? I've read
through LLVM Alias Analysis Infrastructure — LLVM 18.0.0git documentation and don't see anything
that I'm missing.

Thanks,
Matthew

P.S. Here's the full source code of my pass:

#define DEBUG_TYPE "must-aa"
#include "llvm/Pass.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h"
using namespace llvm;

namespace {
struct EverythingMustAlias : public ImmutablePass, public AliasAnalysis {
  static char ID;
  EverythingMustAlias() : ImmutablePass(ID) {}

  virtual void initializePass() {
    DEBUG(dbgs() << "Initializing everything-must-alias\n");
    InitializeAliasAnalysis(this);
  }

  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
    AliasAnalysis::getAnalysisUsage(AU);
    AU.setPreservesAll();
  }

  virtual AliasResult alias(const Location &LocA, const Location &LocB) {
    DEBUG(dbgs() << "Everything must alias!\n");
    return AliasAnalysis::MustAlias;
  }
};
}

namespace llvm {
void initializeEverythingMustAliasPass(PassRegistry &Registry);
}

char EverythingMustAlias::ID = 0;
static RegisterPass<EverythingMustAlias> A("must-aa", "Everything must
alias");

static RegisterPass<EverythingMustAlias> A("must-aa", "Everything must
alias", false, true);

Can you try this?

I changed "static RegisterPass<EverythingMustAlias> A("must-aa",
"Everything must alias");"
to
"static RegisterPass<

A("must-aa", "Everything must alias", false, true);"

and am seeing the same behavior.

INITIALIZE_AG_PASS(EverythingMustAlias, AliasAnalysis, "must-aa",

INITIALIZE_AG_PASS defines initialization functions, but it does not actually call them. Try this instead:

static RegisterPass<EverythingMustAlias> X("must-aa", "Everything must alias", false, true);
static RegisterAnalysisGroup<AliasAnalysis> Y(X);

I suppose INITIALIZE_AG_PASS is only required if the pass is directly linked into LLVM so it won't be initialized too early (before the rest of LLVM has been initialized). This isn't an issue for plugins, so static initialization works just fine there. But that's just my guess. :wink:

Regards,
Tobias

I want to be able to load my pass from an external library & not have it

compiled into opt.

INITIALIZE_AG_PASS defines initialization functions, but it does not
actually call them. Try this instead:

static RegisterPass<EverythingMustAlias> X("must-aa", "Everything must
alias", false, true);
static RegisterAnalysisGroup<AliasAnalysis> Y(X);

I suppose INITIALIZE_AG_PASS is only required if the pass is directly
linked into LLVM so it won't be initialized too early (before the rest of
LLVM has been initialized). This isn't an issue for plugins, so static
initialization works just fine there. But that's just my guess. :wink:

That did it. Thanks. :slight_smile:

Regards,

Hi Matthew

I'm stuck on the exact same spot.

Did you ever find any solution to this issue?

Best, Cyrill

Hi Matthew

I'm stuck on the exact same spot.

Did you ever find any solution to this issue?

Best, Cyrill

Never mind.

Didn't see that the LLVMdev thread went on in another month.

Sorry for bothering.

Best, Cyrill