| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 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 |
|
| 89 |
VarToExprMap VarToExpr; |
| 90 |
|
| 91 |
|
| 92 |
MemberExprToExprMap MemberExprToExpr; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
ArraySubToExprMap ArraySubToExpr; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
ExprSet VisitedMEAndASE; |
| 107 |
|
| 108 |
|
| 109 |
ExprToExprsMap DominatedMap; |
| 110 |
|
| 111 |
CopyPropCollectionVisitor *CollectionVisitor; |
| 112 |
|
| 113 |
const clang::Expr *TheCopyExpr; |
| 114 |
|
| 115 |
|
| 116 |
CopyPropagation(void); |
| 117 |
|
| 118 |
CopyPropagation(const CopyPropagation &); |
| 119 |
|
| 120 |
void operator=(const CopyPropagation &); |
| 121 |
}; |
| 122 |
#endif |