Skip to content

[analyzer] Improve cache locality by using separate allocators #138295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class CoreEngine {

public:
/// Construct a CoreEngine object to analyze the provided CFG.
CoreEngine(ExprEngine &exprengine,
FunctionSummariesTy *FS,
AnalyzerOptions &Opts);
CoreEngine(ExprEngine &exprengine, FunctionSummariesTy *FS,
AnalyzerOptions &Opts,
llvm::BumpPtrAllocator &BlockCounterFactoryAllocator);

CoreEngine(const CoreEngine &) = delete;
CoreEngine &operator=(const CoreEngine &) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ class ExprEngine {

public:
ExprEngine(cross_tu::CrossTranslationUnitContext &CTU, AnalysisManager &mgr,
SetOfConstDecls *VisitedCalleesIn,
FunctionSummariesTy *FS, InliningModes HowToInlineIn);
SetOfConstDecls *VisitedCalleesIn, FunctionSummariesTy *FS,
InliningModes HowToInlineIn,
std::array<llvm::BumpPtrAllocator, 7> &ProgramStateAllocators,
llvm::BumpPtrAllocator &BlockCounterFactoryAllocator);

virtual ~ExprEngine() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,10 @@ class ProgramStateManager {
std::vector<ProgramState *> freeStates;

public:
ProgramStateManager(ASTContext &Ctx,
StoreManagerCreator CreateStoreManager,
ConstraintManagerCreator CreateConstraintManager,
llvm::BumpPtrAllocator& alloc,
ExprEngine *expreng);
ProgramStateManager(ASTContext &Ctx, StoreManagerCreator CreateStoreManager,
ConstraintManagerCreator CreateConstraintManager,
std::array<llvm::BumpPtrAllocator, 7> &Allocators,
ExprEngine *expreng);

~ProgramStateManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ class SValBuilder {
const unsigned ArrayIndexWidth;

public:
SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
ProgramStateManager &stateMgr);
SValBuilder(llvm::BumpPtrAllocator &BasicValueFactoryAllocator,
llvm::BumpPtrAllocator &SymbolManagerAllocator,
llvm::BumpPtrAllocator &MemRegionManagerAllocator,
ASTContext &context, ProgramStateManager &stateMgr);

virtual ~SValBuilder() = default;

Expand Down Expand Up @@ -409,9 +411,11 @@ class SValBuilder {
const StackFrameContext *SFC);
};

SValBuilder* createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc,
ASTContext &context,
ProgramStateManager &stateMgr);
SValBuilder *
createSimpleSValBuilder(llvm::BumpPtrAllocator &BasicValueFactoryAllocator,
llvm::BumpPtrAllocator &SymbolManagerAllocator,
llvm::BumpPtrAllocator &MemRegionManagerAllocator,
ASTContext &context, ProgramStateManager &stateMgr);

} // namespace ento

Expand Down
5 changes: 3 additions & 2 deletions clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ static std::unique_ptr<WorkList> generateWorkList(AnalyzerOptions &Opts) {
}

CoreEngine::CoreEngine(ExprEngine &exprengine, FunctionSummariesTy *FS,
AnalyzerOptions &Opts)
AnalyzerOptions &Opts,
llvm::BumpPtrAllocator &BlockCounterFactoryAllocator)
: ExprEng(exprengine), WList(generateWorkList(Opts)),
CTUWList(Opts.IsNaiveCTUEnabled ? generateWorkList(Opts) : nullptr),
BCounterFactory(G.getAllocator()), FunctionSummaries(FS) {}
BCounterFactory(BlockCounterFactoryAllocator), FunctionSummaries(FS) {}

void CoreEngine::setBlockCounter(BlockCounter C) {
WList->setBlockCounter(C);
Expand Down
14 changes: 9 additions & 5 deletions clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,18 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(PendingArrayDestruction,

static const char* TagProviderName = "ExprEngine";

ExprEngine::ExprEngine(cross_tu::CrossTranslationUnitContext &CTU,
AnalysisManager &mgr, SetOfConstDecls *VisitedCalleesIn,
FunctionSummariesTy *FS, InliningModes HowToInlineIn)
ExprEngine::ExprEngine(
cross_tu::CrossTranslationUnitContext &CTU, AnalysisManager &mgr,
SetOfConstDecls *VisitedCalleesIn, FunctionSummariesTy *FS,
InliningModes HowToInlineIn,
std::array<llvm::BumpPtrAllocator, 7> &ProgramStateAllocators,
llvm::BumpPtrAllocator &BlockCounterFactoryAllocator)
: CTU(CTU), IsCTUEnabled(mgr.getAnalyzerOptions().IsNaiveCTUEnabled),
AMgr(mgr), AnalysisDeclContexts(mgr.getAnalysisDeclContextManager()),
Engine(*this, FS, mgr.getAnalyzerOptions()), G(Engine.getGraph()),
Engine(*this, FS, mgr.getAnalyzerOptions(), BlockCounterFactoryAllocator),
G(Engine.getGraph()),
StateMgr(getContext(), mgr.getStoreManagerCreator(),
mgr.getConstraintManagerCreator(), G.getAllocator(), this),
mgr.getConstraintManagerCreator(), ProgramStateAllocators, this),
SymMgr(StateMgr.getSymbolManager()), MRMgr(StateMgr.getRegionManager()),
svalBuilder(StateMgr.getSValBuilder()), ObjCNoRet(mgr.getASTContext()),
BR(mgr, *this), VisitedCallees(VisitedCalleesIn),
Expand Down
17 changes: 8 additions & 9 deletions clang/lib/StaticAnalyzer/Core/ProgramState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ int64_t ProgramState::getID() const {
return getStateManager().Alloc.identifyKnownAlignedObject<ProgramState>(this);
}

ProgramStateManager::ProgramStateManager(ASTContext &Ctx,
StoreManagerCreator CreateSMgr,
ConstraintManagerCreator CreateCMgr,
llvm::BumpPtrAllocator &alloc,
ExprEngine *ExprEng)
: Eng(ExprEng), EnvMgr(alloc), GDMFactory(alloc),
svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
ProgramStateManager::ProgramStateManager(
ASTContext &Ctx, StoreManagerCreator CreateSMgr,
ConstraintManagerCreator CreateCMgr,
std::array<llvm::BumpPtrAllocator, 7> &Allocators, ExprEngine *ExprEng)
: Eng(ExprEng), EnvMgr(Allocators[0]), GDMFactory(Allocators[1]),
svalBuilder(createSimpleSValBuilder(Allocators[2], Allocators[3],
Allocators[4], Ctx, *this)),
CallEventMgr(new CallEventManager(Allocators[5])), Alloc(Allocators[6]) {
StoreMgr = (*CreateSMgr)(*this);
ConstraintMgr = (*CreateCMgr)(*this, ExprEng);
}


ProgramStateManager::~ProgramStateManager() {
for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
I!=E; ++I)
Expand Down
12 changes: 7 additions & 5 deletions clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ using namespace ento;

void SValBuilder::anchor() {}

SValBuilder::SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
ProgramStateManager &stateMgr)
: Context(context), BasicVals(context, alloc),
SymMgr(context, BasicVals, alloc), MemMgr(context, alloc),
StateMgr(stateMgr),
SValBuilder::SValBuilder(llvm::BumpPtrAllocator &BasicValueFactoryAllocator,
llvm::BumpPtrAllocator &SymbolManagerAllocator,
llvm::BumpPtrAllocator &MemRegionManagerAllocator,
ASTContext &context, ProgramStateManager &stateMgr)
: Context(context), BasicVals(context, BasicValueFactoryAllocator),
SymMgr(context, BasicVals, SymbolManagerAllocator),
MemMgr(context, MemRegionManagerAllocator), StateMgr(stateMgr),
AnOpts(
stateMgr.getOwningEngine().getAnalysisManager().getAnalyzerOptions()),
ArrayIndexTy(context.LongLongTy),
Expand Down
21 changes: 14 additions & 7 deletions clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ class SimpleSValBuilder : public SValBuilder {
SVal simplifySValOnce(ProgramStateRef State, SVal V);

public:
SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
ProgramStateManager &stateMgr)
: SValBuilder(alloc, context, stateMgr) {}
SimpleSValBuilder(llvm::BumpPtrAllocator &BasicValueFactoryAllocator,
llvm::BumpPtrAllocator &SymbolManagerAllocator,
llvm::BumpPtrAllocator &MemRegionManagerAllocator,
ASTContext &context, ProgramStateManager &stateMgr)
: SValBuilder(BasicValueFactoryAllocator, SymbolManagerAllocator,
MemRegionManagerAllocator, context, stateMgr) {}
~SimpleSValBuilder() override {}

SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op,
Expand Down Expand Up @@ -98,10 +101,14 @@ class SimpleSValBuilder : public SValBuilder {
};
} // end anonymous namespace

SValBuilder *ento::createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc,
ASTContext &context,
ProgramStateManager &stateMgr) {
return new SimpleSValBuilder(alloc, context, stateMgr);
SValBuilder *ento::createSimpleSValBuilder(
llvm::BumpPtrAllocator &BasicValueFactoryAllocator,
llvm::BumpPtrAllocator &SymbolManagerAllocator,
llvm::BumpPtrAllocator &MemRegionManagerAllocator, ASTContext &context,
ProgramStateManager &stateMgr) {
return new SimpleSValBuilder(BasicValueFactoryAllocator,
SymbolManagerAllocator,
MemRegionManagerAllocator, context, stateMgr);
}

// Checks if the negation the value and flipping sign preserve
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
if (!Mgr->getAnalysisDeclContext(D)->getAnalysis<RelaxedLiveVariables>())
return;

ExprEngine Eng(CTU, *Mgr, VisitedCallees, &FunctionSummaries, IMode);
std::array<llvm::BumpPtrAllocator, 7> ProgramStateManagerAllocators;
llvm::BumpPtrAllocator BlockCounterFactoryAllocator;

ExprEngine Eng(CTU, *Mgr, VisitedCallees, &FunctionSummaries, IMode,
ProgramStateManagerAllocators, BlockCounterFactoryAllocator);

// Execute the worklist algorithm.
llvm::TimeRecord ExprEngineStartTime;
Expand Down
Loading