Spatial
Simple Static Analysis in LLVM
Token.h
Go to the documentation of this file.
1#ifndef TOKEN_H
2#define TOKEN_H
3
4#include "string"
5#include "llvm/ADT/BitVector.h"
6#include "llvm/ADT/StringRef.h"
7#include "llvm/IR/Argument.h"
8#include "llvm/IR/Function.h"
9#include "llvm/IR/Instructions.h"
10#include "llvm/IR/Operator.h"
11#include "llvm/IR/Type.h"
12#include "llvm/IR/Value.h"
13#include "llvm/Support/raw_ostream.h"
14
15namespace spatial {
16
27};
28
29class Token {
30private:
31 llvm::Value *Val;
32 llvm::Type *Ty;
33 llvm::Argument *Arg;
34 // 0 is Value
35 // 1 is Type
36 // 2 is Argument
37 // 3 is Dummy
38 std::string Index;
39 unsigned int Kind;
40 llvm::Function *Func;
41 std::string name;
42 bool IsGlobal;
43
44 void set(llvm::Value *Val, unsigned int Kind, std::string Index,
45 llvm::Function *Func, bool Global = false);
46 void set(llvm::Type *Ty, unsigned int Kind, std::string Index);
47 void set(llvm::Argument *Arg, unsigned int Kind, std::string Index,
48 llvm::Function *Func);
49 void set(std::string S, unsigned int Kind, std::string Index,
50 llvm::Function *Func);
51 llvm::BitVector opTokenTy;
52 unsigned int TyLength;
53
54public:
55 void setIndex(llvm::GetElementPtrInst *GEPInst);
56 void setIndex(llvm::GEPOperator *GEPOp);
57 void setIndex(Token *, std::string);
58 void setIndex(Token *);
59 void resetIndex();
60 void resetIndexToZero();
61 void resetIndexToZero(std::string);
62 std::string getIndex(llvm::GEPOperator *GEPOp);
63
64 Token(llvm::Value *Val, std::string Index = "");
65 Token(llvm::GEPOperator *GOP, llvm::Function *Func, std::string Index = "");
66 Token(llvm::Argument *Arg, std::string Index = "");
67 Token(llvm::Type *Ty, std::string Index = "");
68 Token(std::string S, llvm::Function *Func, std::string Index = "");
69 Token(Token *A);
70 Token();
71
72 llvm::Value *getValue() const;
73 llvm::StringRef getName() const;
74 std::string getMemTypeName() const;
75 std::string getFunctionName() const;
76 std::string getFieldIndex() const;
77
78 friend std::ostream &operator<<(std::ostream &OS, const Token &A);
79
80 bool isMem() const;
81 bool isArg() const;
82 bool isField() const;
83 bool isGlobalVar() const;
84 bool isAllocaOrArgOrGlobal() const;
85 bool sameFunc(llvm::Function *Func) const;
86 bool isBasePointerType() const;
87 bool isValPointerType() const;
88 std::string getHash() const;
89 bool isPointerType() const;
90
91 bool operator<(const Token &TheToken) const;
92 bool operator==(const Token &TheToken) const;
93 void operator=(const Token &TheToken);
94 void setIsGlobal();
95 void setIsArray();
96 bool getIsArray();
97 void setIsAlloca();
98 bool getIsAlloca();
99 void setIsOpBitcast();
100 bool getIsOpBitcast();
101 void setIsPhiGEPOpd();
102 bool getIsPhiGEPOpd();
103 void setIsIcmpGEPOpd();
104 bool getIsIcmpGEPOpd();
105 void setIsOneGEPIndx();
106 bool getIsOneGEPIndx();
107 void setIsFunPtr();
108 bool getIsFunPtr();
109 void setIsFunArg();
110 bool getIsFunArg();
111 void setIsRetGEP();
112 bool getIsRetGEP();
113
114 template <typename GOP> bool isGEPOperandArrayTy(GOP *, int);
115 template <typename GEP> std::vector<int> getGEPArrayIndex(GEP *);
116
117 bool isNullToken();
119 llvm::Type *getTy();
120 void setTy(llvm::Type *);
121 void setFunction(llvm::Function *);
122 llvm::Function *getFunction();
123};
124
125} // namespace spatial
126
127#endif
Definition: Token.h:29
void setIsFunArg()
Definition: Token.cpp:370
llvm::Type * getTy()
Definition: Token.cpp:399
friend std::ostream & operator<<(std::ostream &OS, const Token &A)
Definition: Token.cpp:209
bool getIsFunPtr()
Definition: Token.cpp:368
bool isField() const
isField - Returns true if alias is a field
Definition: Token.cpp:273
void operator=(const Token &TheToken)
Definition: Token.cpp:327
bool isValPointerType() const
Definition: Token.cpp:300
void resetIndex()
resetIndex - Resets the index back to an empty string
Definition: Token.cpp:148
bool getIsPhiGEPOpd()
Definition: Token.cpp:356
void setIndex(llvm::GetElementPtrInst *GEPInst)
setIndex - For a GEP Instruction find the offset and store it
Definition: Token.cpp:127
bool sameFunc(llvm::Function *Func) const
sameFunc = Returns true if the parent function of alias is same as /p Func
Definition: Token.cpp:282
bool isGEPOperandArrayTy(GOP *, int)
Definition: Token.cpp:172
bool isPointerType() const
void setIsIcmpGEPOpd()
Definition: Token.cpp:358
void resetIndexToZero()
resetIndexToZero - Resets the index to string zero for bitcast instr
Definition: Token.cpp:151
std::string getFunctionName() const
getFunctionName - Returns the name of the parent function
Definition: Token.cpp:253
bool operator<(const Token &TheToken) const
Definition: Token.cpp:319
bool getIsIcmpGEPOpd()
Definition: Token.cpp:360
void setIsArray()
Definition: Token.cpp:342
bool operator==(const Token &TheToken) const
Definition: Token.cpp:323
void setIsOpBitcast()
Definition: Token.cpp:350
Token()
Definition: Token.cpp:5
bool getIsFunArg()
Definition: Token.cpp:372
void setIsGlobal()
Definition: Token.cpp:340
void setIsFunPtr()
Definition: Token.cpp:366
void setFunction(llvm::Function *)
Definition: Token.cpp:403
llvm::StringRef getName() const
Definition: Token.cpp:231
std::string getFieldIndex() const
getFieldIndex - Returns index of the field
Definition: Token.cpp:261
void setIsRetGEP()
Definition: Token.cpp:374
void setIsAlloca()
Definition: Token.cpp:346
std::string getHash() const
Definition: Token.cpp:308
bool getIsAlloca()
Definition: Token.cpp:348
bool isBasePointerType() const
isBasePointerType - Returns true if the Token type's base type is a pointer
Definition: Token.cpp:289
llvm::Function * getFunction()
Definition: Token.cpp:405
bool isMem() const
isMem - Returns true if the alias denotes a location in heap
Definition: Token.cpp:264
bool isArg() const
isArg - Returns true if alias is a function argument
Definition: Token.cpp:270
void setIsPhiGEPOpd()
Definition: Token.cpp:354
bool getIsOpBitcast()
Definition: Token.cpp:352
bool isGlobalVar() const
isGlobalVar - Returns true if the alias is global
Definition: Token.cpp:267
bool getIsRetGEP()
Definition: Token.cpp:376
void setIsOneGEPIndx()
Definition: Token.cpp:362
std::vector< int > getGEPArrayIndex(GEP *)
void setTy(llvm::Type *)
Definition: Token.cpp:401
std::string getIndex(llvm::GEPOperator *GEPOp)
getIndex - For a GEP Operator find the offset
Definition: Token.cpp:157
void setNullToken()
bool isAllocaOrArgOrGlobal() const
Definition: Token.cpp:277
std::string getMemTypeName() const
getMemTypeName - Returns the memory type name
Definition: Token.cpp:243
llvm::Value * getValue() const
getValue - Returns the underlying Value* for the alias
Definition: Token.cpp:202
bool getIsOneGEPIndx()
Definition: Token.cpp:364
bool isNullToken()
Definition: Token.cpp:393
bool getIsArray()
Definition: Token.cpp:344
Definition: PointsToBenchmark.cpp:19
opTokenTy
Definition: Token.h:17
@ isFunPtr
Definition: Token.h:24
@ isIcmpGEPOpd
Definition: Token.h:22
@ isRetGEP
Definition: Token.h:26
@ isAlloca
Definition: Token.h:19
@ isArray
Definition: Token.h:18
@ isOneGEPIndx
Definition: Token.h:23
@ isFunArg
Definition: Token.h:25
@ isOpBitcast
Definition: Token.h:20
@ isPhiGEPOpd
Definition: Token.h:21