mirror of https://github.com/microsoft/clang.git
[analyzer] Generate and use stable identifiers for LocationContext
Those are not created in the allocator. Since they are created fairly rarely, a counter overhead should not affect the memory consumption. Differential Revision: https://reviews.llvm.org/D51827 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342314 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7d1cca4458
commit
ab961c560a
|
@ -227,17 +227,23 @@ private:
|
||||||
AnalysisDeclContext *Ctx;
|
AnalysisDeclContext *Ctx;
|
||||||
|
|
||||||
const LocationContext *Parent;
|
const LocationContext *Parent;
|
||||||
|
int64_t ID;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LocationContext(ContextKind k, AnalysisDeclContext *ctx,
|
LocationContext(ContextKind k, AnalysisDeclContext *ctx,
|
||||||
const LocationContext *parent)
|
const LocationContext *parent,
|
||||||
: Kind(k), Ctx(ctx), Parent(parent) {}
|
int64_t ID)
|
||||||
|
: Kind(k), Ctx(ctx), Parent(parent), ID(ID) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~LocationContext();
|
virtual ~LocationContext();
|
||||||
|
|
||||||
ContextKind getKind() const { return Kind; }
|
ContextKind getKind() const { return Kind; }
|
||||||
|
|
||||||
|
int64_t getID() const {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
AnalysisDeclContext *getAnalysisDeclContext() const { return Ctx; }
|
AnalysisDeclContext *getAnalysisDeclContext() const { return Ctx; }
|
||||||
|
|
||||||
const LocationContext *getParent() const { return Parent; }
|
const LocationContext *getParent() const { return Parent; }
|
||||||
|
@ -297,8 +303,9 @@ class StackFrameContext : public LocationContext {
|
||||||
|
|
||||||
StackFrameContext(AnalysisDeclContext *ctx, const LocationContext *parent,
|
StackFrameContext(AnalysisDeclContext *ctx, const LocationContext *parent,
|
||||||
const Stmt *s, const CFGBlock *blk,
|
const Stmt *s, const CFGBlock *blk,
|
||||||
unsigned idx)
|
unsigned idx,
|
||||||
: LocationContext(StackFrame, ctx, parent), CallSite(s),
|
int64_t ID)
|
||||||
|
: LocationContext(StackFrame, ctx, parent, ID), CallSite(s),
|
||||||
Block(blk), Index(idx) {}
|
Block(blk), Index(idx) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -334,8 +341,8 @@ class ScopeContext : public LocationContext {
|
||||||
const Stmt *Enter;
|
const Stmt *Enter;
|
||||||
|
|
||||||
ScopeContext(AnalysisDeclContext *ctx, const LocationContext *parent,
|
ScopeContext(AnalysisDeclContext *ctx, const LocationContext *parent,
|
||||||
const Stmt *s)
|
const Stmt *s, int64_t ID)
|
||||||
: LocationContext(Scope, ctx, parent), Enter(s) {}
|
: LocationContext(Scope, ctx, parent, ID), Enter(s) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~ScopeContext() override = default;
|
~ScopeContext() override = default;
|
||||||
|
@ -361,9 +368,10 @@ class BlockInvocationContext : public LocationContext {
|
||||||
const void *ContextData;
|
const void *ContextData;
|
||||||
|
|
||||||
BlockInvocationContext(AnalysisDeclContext *ctx,
|
BlockInvocationContext(AnalysisDeclContext *ctx,
|
||||||
const LocationContext *parent,
|
const LocationContext *parent, const BlockDecl *bd,
|
||||||
const BlockDecl *bd, const void *contextData)
|
const void *contextData, int64_t ID)
|
||||||
: LocationContext(Block, ctx, parent), BD(bd), ContextData(contextData) {}
|
: LocationContext(Block, ctx, parent, ID), BD(bd),
|
||||||
|
ContextData(contextData) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~BlockInvocationContext() override = default;
|
~BlockInvocationContext() override = default;
|
||||||
|
@ -389,6 +397,9 @@ public:
|
||||||
class LocationContextManager {
|
class LocationContextManager {
|
||||||
llvm::FoldingSet<LocationContext> Contexts;
|
llvm::FoldingSet<LocationContext> Contexts;
|
||||||
|
|
||||||
|
/// ID used for generating a new location context.
|
||||||
|
int64_t NewID = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~LocationContextManager();
|
~LocationContextManager();
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ LocationContextManager::getLocationContext(AnalysisDeclContext *ctx,
|
||||||
LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
|
LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
|
||||||
|
|
||||||
if (!L) {
|
if (!L) {
|
||||||
L = new LOC(ctx, parent, d);
|
L = new LOC(ctx, parent, d, ++NewID);
|
||||||
Contexts.InsertNode(L, InsertPos);
|
Contexts.InsertNode(L, InsertPos);
|
||||||
}
|
}
|
||||||
return L;
|
return L;
|
||||||
|
@ -402,7 +402,7 @@ LocationContextManager::getStackFrame(AnalysisDeclContext *ctx,
|
||||||
auto *L =
|
auto *L =
|
||||||
cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
|
cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
|
||||||
if (!L) {
|
if (!L) {
|
||||||
L = new StackFrameContext(ctx, parent, s, blk, idx);
|
L = new StackFrameContext(ctx, parent, s, blk, idx, ++NewID);
|
||||||
Contexts.InsertNode(L, InsertPos);
|
Contexts.InsertNode(L, InsertPos);
|
||||||
}
|
}
|
||||||
return L;
|
return L;
|
||||||
|
@ -427,7 +427,7 @@ LocationContextManager::getBlockInvocationContext(AnalysisDeclContext *ctx,
|
||||||
cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
|
cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
|
||||||
InsertPos));
|
InsertPos));
|
||||||
if (!L) {
|
if (!L) {
|
||||||
L = new BlockInvocationContext(ctx, parent, BD, ContextData);
|
L = new BlockInvocationContext(ctx, parent, BD, ContextData, ++NewID);
|
||||||
Contexts.InsertNode(L, InsertPos);
|
Contexts.InsertNode(L, InsertPos);
|
||||||
}
|
}
|
||||||
return L;
|
return L;
|
||||||
|
|
|
@ -235,8 +235,8 @@ void Environment::print(raw_ostream &Out, const char *NL,
|
||||||
const Stmt *S = I.first.getStmt();
|
const Stmt *S = I.first.getStmt();
|
||||||
assert(S != nullptr && "Expected non-null Stmt");
|
assert(S != nullptr && "Expected non-null Stmt");
|
||||||
|
|
||||||
Out << "(LC" << (const void *)LC << ", S" << S->getID(Context) << " <"
|
Out << "(LC " << LC->getID() << " <" << (const void *)LC << ">, S "
|
||||||
<< (const void *)S << "> ) ";
|
<< S->getID(Context) << " <" << (const void *)S << ">) ";
|
||||||
S->printPretty(Out, /*Helper=*/nullptr, PP);
|
S->printPretty(Out, /*Helper=*/nullptr, PP);
|
||||||
Out << " : " << I.second << NL;
|
Out << " : " << I.second << NL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue