| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef SIMPLE_INLINER_H |
| 12 |
#define SIMPLE_INLINER_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
#include <utility> |
| 17 |
#include "llvm/ADT/SmallVector.h" |
| 18 |
#include "llvm/ADT/SmallSet.h" |
| 19 |
#include "llvm/ADT/DenseMap.h" |
| 20 |
#include "Transformation.h" |
| 21 |
|
| 22 |
namespace clang { |
| 23 |
class DeclGroupRef; |
| 24 |
class ASTContext; |
| 25 |
class FunctionDecl; |
| 26 |
class CallExpr; |
| 27 |
class DeclRefExpr; |
| 28 |
class MangleContext; |
| 29 |
class ReturnStmt; |
| 30 |
class Expr; |
| 31 |
class Stmt; |
| 32 |
} |
| 33 |
|
| 34 |
class SimpleInlinerCollectionVisitor; |
| 35 |
class SimpleInlinerFunctionVisitor; |
| 36 |
class SimpleInlinerFunctionStmtVisitor; |
| 37 |
class SimpleInlinerStmtVisitor; |
| 38 |
|
| 39 |
class SimpleInliner : public Transformation { |
| 40 |
friend class SimpleInlinerCollectionVisitor; |
| 41 |
friend class SimpleInlinerFunctionVisitor; |
| 42 |
friend class SimpleInlinerFunctionStmtVisitor; |
| 43 |
friend class SimpleInlinerStmtVisitor; |
| 44 |
|
| 45 |
public: |
| 46 |
|
| 47 |
SimpleInliner(const char *TransName, const char *Desc) |
| 48 |
: Transformation(TransName, Desc), |
| 49 |
CollectionVisitor(NULL), |
| 50 |
FunctionVisitor(NULL), |
| 51 |
FunctionStmtVisitor(NULL), |
| 52 |
StmtVisitor(NULL), |
| 53 |
NameQueryWrap(NULL), |
| 54 |
MangleCtx(NULL), |
| 55 |
TheCallExpr(NULL), |
| 56 |
TheCaller(NULL), |
| 57 |
CurrentFD(NULL), |
| 58 |
TheStmt(NULL), |
| 59 |
SingleMaxNumStmts(25), |
| 60 |
MaxNumStmts(10), |
| 61 |
TmpVarName(""), |
| 62 |
NeedParen(false), |
| 63 |
NamePostfix(0) |
| 64 |
{ } |
| 65 |
|
| 66 |
~SimpleInliner(void); |
| 67 |
|
| 68 |
private: |
| 69 |
|
| 70 |
typedef llvm::SmallVector<clang::ReturnStmt *, 5> ReturnStmtsVector; |
| 71 |
|
| 72 |
typedef llvm::SmallVector<const clang::DeclRefExpr *, 5> ParmRefsVector; |
| 73 |
|
| 74 |
typedef llvm::DenseMap<clang::FunctionDecl *, unsigned int> |
| 75 |
FunctionDeclToNumCallsMap; |
| 76 |
|
| 77 |
typedef llvm::DenseMap<clang::FunctionDecl *, unsigned int> |
| 78 |
FunctionDeclToNumStmtsMap; |
| 79 |
|
| 80 |
virtual void Initialize(clang::ASTContext &context); |
| 81 |
|
| 82 |
virtual bool HandleTopLevelDecl(clang::DeclGroupRef D); |
| 83 |
|
| 84 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 85 |
|
| 86 |
void replaceCallExpr(void); |
| 87 |
|
| 88 |
void doAnalysis(void); |
| 89 |
|
| 90 |
std::string getMangledName(clang::FunctionDecl *FD); |
| 91 |
|
| 92 |
clang::FunctionDecl *getAliaseeFunctionDecl(clang::FunctionDecl *FD); |
| 93 |
|
| 94 |
bool isValidArgExpr(const clang::Expr *E); |
| 95 |
|
| 96 |
bool hasValidArgExprs(const clang::CallExpr *CE); |
| 97 |
|
| 98 |
void createReturnVar(void); |
| 99 |
|
| 100 |
void generateParamStrings(void); |
| 101 |
|
| 102 |
void copyFunctionBody(void); |
| 103 |
|
| 104 |
std::string getNewTmpName(void); |
| 105 |
|
| 106 |
void getValidFunctionDecls(void); |
| 107 |
|
| 108 |
void removeFunctionBody(void); |
| 109 |
|
| 110 |
void sortReturnStmtsByOffs(const char *StartBuf, |
| 111 |
std::vector< std::pair<clang::ReturnStmt *, int> > &SortedReturnStmts); |
| 112 |
|
| 113 |
void insertReturnStmt |
| 114 |
(std::vector< std::pair<clang::ReturnStmt *, int> > &SortedReturnStmts, |
| 115 |
clang::ReturnStmt *RS, int Off); |
| 116 |
|
| 117 |
bool hasNameClash(const std::string &ParmName, const clang::Expr *E); |
| 118 |
|
| 119 |
FunctionDeclToNumCallsMap FunctionDeclNumCalls; |
| 120 |
|
| 121 |
FunctionDeclToNumStmtsMap FunctionDeclNumStmts; |
| 122 |
|
| 123 |
llvm::DenseMap<clang::CallExpr *, clang::FunctionDecl *> CalleeToCallerMap; |
| 124 |
|
| 125 |
llvm::SmallVector<clang::CallExpr *, 10> AllCallExprs; |
| 126 |
|
| 127 |
llvm::SmallSet<clang::FunctionDecl *, 10> ValidFunctionDecls; |
| 128 |
|
| 129 |
llvm::SmallVector<std::string, 10> ParmStrings; |
| 130 |
|
| 131 |
llvm::SmallVector<std::string, 4> ParmsWithNameClash; |
| 132 |
|
| 133 |
std::map<std::string, clang::FunctionDecl *> MangledNameToFuncDeclMap; |
| 134 |
|
| 135 |
ReturnStmtsVector ReturnStmts; |
| 136 |
|
| 137 |
ParmRefsVector ParmRefs; |
| 138 |
|
| 139 |
SimpleInlinerCollectionVisitor *CollectionVisitor; |
| 140 |
|
| 141 |
SimpleInlinerFunctionVisitor *FunctionVisitor; |
| 142 |
|
| 143 |
SimpleInlinerFunctionStmtVisitor *FunctionStmtVisitor; |
| 144 |
|
| 145 |
SimpleInlinerStmtVisitor *StmtVisitor; |
| 146 |
|
| 147 |
TransNameQueryWrap *NameQueryWrap; |
| 148 |
|
| 149 |
clang::MangleContext *MangleCtx; |
| 150 |
|
| 151 |
clang::CallExpr *TheCallExpr; |
| 152 |
|
| 153 |
clang::FunctionDecl *TheCaller; |
| 154 |
|
| 155 |
clang::FunctionDecl *CurrentFD; |
| 156 |
|
| 157 |
clang::Stmt *TheStmt; |
| 158 |
|
| 159 |
|
| 160 |
const unsigned int SingleMaxNumStmts; |
| 161 |
|
| 162 |
|
| 163 |
const unsigned int MaxNumStmts; |
| 164 |
|
| 165 |
std::string TmpVarName; |
| 166 |
|
| 167 |
bool NeedParen; |
| 168 |
|
| 169 |
unsigned int NamePostfix; |
| 170 |
|
| 171 |
|
| 172 |
SimpleInliner(void); |
| 173 |
|
| 174 |
SimpleInliner(const SimpleInliner &); |
| 175 |
|
| 176 |
void operator=(const SimpleInliner &); |
| 177 |
}; |
| 178 |
#endif |