[cfe-commits] r90506 - in /cfe/trunk: include/clang/Analysis/PathSensitive/AnalysisContext.h lib/Analysis/AnalysisContext.cpp
Ted Kremenek
kremenek at apple.com
Thu Dec 3 16:50:10 PST 2009
Author: kremenek
Date: Thu Dec 3 18:50:10 2009
New Revision: 90506
URL: http://llvm.org/viewvc/llvm-project?rev=90506&view=rev
Log:
Refactor FoldingSet profiling code for LocationContexts, and add a new BlockInvocationContext to represent the invocation of a block.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
cfe/trunk/lib/Analysis/AnalysisContext.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h?rev=90506&r1=90505&r2=90506&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h Thu Dec 3 18:50:10 2009
@@ -78,7 +78,7 @@
class LocationContext : public llvm::FoldingSetNode {
public:
- enum ContextKind { StackFrame, Scope };
+ enum ContextKind { StackFrame, Scope, Block };
private:
ContextKind Kind;
@@ -123,11 +123,17 @@
AnalysisContext *ctx, const LocationContext *parent);
static bool classof(const LocationContext*) { return true; }
+
+protected:
+ static void ProfileCommon(llvm::FoldingSetNodeID &ID,
+ ContextKind ck,
+ AnalysisContext *ctx,
+ const LocationContext *parent,
+ const void* data);
};
class StackFrameContext : public LocationContext {
const Stmt *CallSite;
-
public:
StackFrameContext(AnalysisContext *ctx, const LocationContext *parent,
const Stmt *s)
@@ -138,12 +144,12 @@
Stmt const *getCallSite() const { return CallSite; }
- virtual void Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, getAnalysisContext(), getParent(), CallSite);
- }
-
+ void Profile(llvm::FoldingSetNodeID &ID);
+
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
- const LocationContext *parent, const Stmt *s);
+ const LocationContext *parent, const Stmt *s) {
+ ProfileCommon(ID, StackFrame, ctx, parent, s);
+ }
static bool classof(const LocationContext* Ctx) {
return Ctx->getKind() == StackFrame;
@@ -152,7 +158,6 @@
class ScopeContext : public LocationContext {
const Stmt *Enter;
-
public:
ScopeContext(AnalysisContext *ctx, const LocationContext *parent,
const Stmt *s)
@@ -160,18 +165,41 @@
virtual ~ScopeContext() {}
- virtual void Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, getAnalysisContext(), getParent(), Enter);
- }
+ void Profile(llvm::FoldingSetNodeID &ID);
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
- const LocationContext *parent, const Stmt *s);
+ const LocationContext *parent, const Stmt *s) {
+ ProfileCommon(ID, Scope, ctx, parent, s);
+ }
static bool classof(const LocationContext* Ctx) {
return Ctx->getKind() == Scope;
}
};
+class BlockInvocationContext : public LocationContext {
+ const BlockDecl *BD;
+public:
+ BlockInvocationContext(const BlockDecl *bd, AnalysisContext *ctx,
+ const LocationContext *parent = 0)
+ : LocationContext(Block, ctx, parent), BD(bd) {}
+
+ ~BlockInvocationContext() {}
+
+ const BlockDecl *getBlockDecl() const { return BD; }
+
+ void Profile(llvm::FoldingSetNodeID &ID);
+
+ static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
+ const LocationContext *parent, const BlockDecl *bd) {
+ ProfileCommon(ID, Block, ctx, parent, bd);
+ }
+
+ static bool classof(const LocationContext* Ctx) {
+ return Ctx->getKind() == Block;
+ }
+};
+
class LocationContextManager {
llvm::FoldingSet<LocationContext> Contexts;
Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=90506&r1=90505&r2=90506&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Thu Dec 3 18:50:10 2009
@@ -80,6 +80,10 @@
return AC;
}
+//===----------------------------------------------------------------------===//
+// FoldingSet profiling.
+//===----------------------------------------------------------------------===//
+
void LocationContext::Profile(llvm::FoldingSetNodeID &ID, ContextKind k,
AnalysisContext *ctx,
const LocationContext *parent) {
@@ -88,18 +92,31 @@
ID.AddPointer(parent);
}
-void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID,AnalysisContext *ctx,
- const LocationContext *parent, const Stmt *s) {
- LocationContext::Profile(ID, StackFrame, ctx, parent);
- ID.AddPointer(s);
+void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
+ ContextKind ck,
+ AnalysisContext *ctx,
+ const LocationContext *parent,
+ const void* data) {
+ LocationContext::Profile(ID, ck, ctx, parent);
+ ID.AddPointer(data);
}
-void ScopeContext::Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
- const LocationContext *parent, const Stmt *s) {
- LocationContext::Profile(ID, Scope, ctx, parent);
- ID.AddPointer(s);
+void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getAnalysisContext(), getParent(), CallSite);
}
+void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getAnalysisContext(), getParent(), Enter);
+}
+
+void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getAnalysisContext(), getParent(), BD);
+}
+
+//===----------------------------------------------------------------------===//
+// Cleanup.
+//===----------------------------------------------------------------------===//
+
LocationContextManager::~LocationContextManager() {
clear();
}
More information about the cfe-commits
mailing list