Debian Codegraph @

clang_delta/CopyPropagation.h

raw symbols SCIP
1 //===----------------------------------------------------------------------===//
2 //
3 // Copyright (c) 2012, 2014 The University of Utah
4 // All rights reserved.
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See the file COPYING for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef COPY_PROPAGATION_H
12 #define COPY_PROPAGATION_H
13
14 #include <string>
15 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "Transformation.h"
18
19 namespace clang {
20 class DeclGroupRef;
21 class ASTContext;
22 class Expr;
23 class VarDecl;
24 class MemberExpr;
25 class ArraySubscriptExpr;
26 }
27
28 class CopyPropCollectionVisitor;
29
30 class CopyPropagation : public Transformation {
31 friend class CopyPropCollectionVisitor;
32
33 public:
34
35 CopyPropagation(const char *TransName, const char *Desc)
36 : Transformation(TransName, Desc),
37 CollectionVisitor(NULL),
38 TheCopyExpr(NULL)
39 { }
40
41 ~CopyPropagation(void);
42
43 private:
44
45 typedef llvm::DenseMap<const clang::VarDecl *, const clang::Expr *>
46 VarToExprMap;
47
48 typedef llvm::DenseMap<const clang::MemberExpr *, const clang::Expr *>
49 MemberExprToExprMap;
50
51 typedef llvm::DenseMap<const clang::ArraySubscriptExpr *,
52 const clang::Expr *> ArraySubToExprMap;
53
54 typedef llvm::SmallPtrSet<const clang::Expr *, 20> ExprSet;
55
56 typedef llvm::DenseMap<const clang::Expr *, ExprSet *>
57 ExprToExprsMap;
58
59 virtual void Initialize(clang::ASTContext &context);
60
61 virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
62
63 virtual void HandleTranslationUnit(clang::ASTContext &Ctx);
64
65 bool isValidExpr(const clang::Expr *E);
66
67 bool isValidLhs(const clang::Expr *Lhs);
68
69 void updateExpr(const clang::Expr *E, const clang::Expr *CopyE);
70
71 void invalidateExpr(const clang::Expr *E);
72
73 void addOneDominatedExpr(const clang::Expr *CopyE,
74 const clang::Expr *DominatedE);
75
76 const clang::VarDecl *getCanonicalRefVarDecl(const clang::Expr *E);
77
78 bool isRefToTheSameVar(const clang::Expr *CopyE,
79 const clang::Expr *DominatedE);
80
81 bool hasSameStringRep(const clang::Expr *CopyE,
82 const clang::Expr *DominatedE);
83
84 void doCopyPropagation(void);
85
86 bool isConstantExpr(const clang::Expr *Exp);
87
88 // A mapping from a var to its value at the current processing point
89 VarToExprMap VarToExpr;
90
91 // A mapping from a member expr to its value at the current processing point
92 MemberExprToExprMap MemberExprToExpr;
93
94 // A mapping from a arraysubscript expr to its value at
95 // the current processing point
96 ArraySubToExprMap ArraySubToExpr;
97
98 // Only hold visited MemberExpr and ArraySubscriptExpr.
99 // Used for distinguishing a valid Member/ArraySubscript expr
100 // and a Member/ArraySubscript expr which will get a copy from its
101 // corresponding initializer. The advantage is that we don't have to
102 // set up initial value for all the fields of a var which has an aggregate
103 // type. We only need to retrieve the initial value of a field on demand.
104 // We don't need to do this for VarDecl because we can directly get its
105 // initial value.
106 ExprSet VisitedMEAndASE;
107
108 // A mapping from an Expr to its dominating Exprs
109 ExprToExprsMap DominatedMap;
110
111 CopyPropCollectionVisitor *CollectionVisitor;
112
113 const clang::Expr *TheCopyExpr;
114
115 // Unimplemented
116 CopyPropagation(void);
117
118 CopyPropagation(const CopyPropagation &);
119
120 void operator=(const CopyPropagation &);
121 };
122 #endif