Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 0 additions & 106 deletions llvm/include/llvm/Transforms/Utils/MyTy.h

This file was deleted.

45 changes: 0 additions & 45 deletions llvm/include/llvm/Transforms/Utils/PointerTypeHelpers.h

This file was deleted.

32 changes: 0 additions & 32 deletions llvm/include/llvm/Transforms/Utils/PointerTypePrinter.h

This file was deleted.

94 changes: 94 additions & 0 deletions llvm/include/llvm/Transforms/Utils/PointerTypeTool/FlowAnalyzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef LLVM_TRANSFORMS_UTILS_POINTERTYPETOOL_FLOWANALYZER_H
#define LLVM_TRANSFORMS_UTILS_POINTERTYPETOOL_FLOWANALYZER_H

#include "llvm/Transforms/Utils/PointerTypeTool/MyTy.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Instructions.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/IR/Constants.h"

namespace llvm {

class FlowAnalyzer {
struct BlockInfo {
DenseMap<Value *, shared_ptr<MyTy>> typeInfo;
SetVector<BasicBlock *> inBlock;
SetVector<BasicBlock *> outBlock;
BasicBlock *block;
};
DenseMap<BasicBlock *, BlockInfo> blockInfo;
DenseMap<Type *, shared_ptr<MyStructTy>> structInfo;
SetVector<BasicBlock *> workList;

shared_ptr<MyTy> toMyTy(Type *ty);
void addBlockEdge(BasicBlock *from, BasicBlock *to);
void meet(BasicBlock *B);
void process(BasicBlock *B);
bool addTypeInfo(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
Value *val, Type *ty);
bool addTypeInfo(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
Value *val, shared_ptr<MyTy> ty);
bool addTypeInfo(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
Value *val1, Value *val2);
bool addTypeInfoByPointee(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
Value *ptr, Type *ty);
bool addTypeInfoByPointee(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
Value *ptr, shared_ptr<MyTy> ty);
bool addTypeInfoByPointee(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
Value *ptr, Value *val);
shared_ptr<MyTy> visitAggType(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
shared_ptr<MyTy> type, Value *val,
SmallVector<Value *> &indices,
unsigned int index, bool &changed);
shared_ptr<MyTy> visitAggPtrType(DenseMap<Value *, shared_ptr<MyTy>> &typeInfo,
shared_ptr<MyTy> type, Value *valPtr,
SmallVector<Value *> &indices,
unsigned int index, bool &changed);

void initWithInst(Instruction *I);
void initWithReturnInst(ReturnInst *RI);
void initWithBranchInst(BranchInst *BI);
void initWithSwitchInst(SwitchInst *SI);
void initWithIndirectBrInst(IndirectBrInst *II);
void initWithInvolkeInst(InvokeInst *II);

void visitFunction(Function &F);
void visitBasicBlock(BasicBlock *B);
bool visitInst(Instruction *I);
bool visitNonExInfoInst(Instruction *I);
bool visitReturnInst(ReturnInst *RI);
bool visitInvokeInst(InvokeInst *II);
bool visitExtractElementInst(ExtractElementInst *EI);
bool visitInsertElementInst(InsertElementInst *II);
bool visitShuffleVectorInst(ShuffleVectorInst *SI);
bool visitExtractValueInst(ExtractValueInst *EI);
bool visitInsertValueInst(InsertValueInst *II);
bool visitAllocaInst(AllocaInst *AI);
bool visitLoadInst(LoadInst *LI);
bool visitStoreInst(StoreInst *SI);
bool visitAtomicCmpXchgInst(AtomicCmpXchgInst *AI);
bool visitAtomicRWMInst(AtomicRMWInst *AI);
bool visitGetElementPtrInst(GetElementPtrInst *GI);
bool visitICmpInst(ICmpInst *II);
bool visitPHINode(PHINode *PN);
bool visitSelectInst(SelectInst *SI);

void printUpdateLog(Value *V, shared_ptr<MyTy> T);
void printPtrUpdateLog(Value *V, shared_ptr<MyTy> T);
void printUpdateLog(Value *V, Type *T);
void printPtrUpdateLog(Value *V, Type *T);
void printUpdateLog(Value *V1, Value *V2);
void printPtrUpdateLog(Value *P, Value *V);

public:
FlowAnalyzer(Module &M);
void visitModule(Module &M);
const DenseMap<Type *, shared_ptr<MyStructTy>> &getStructInfo();
const DenseMap<Value *, shared_ptr<MyTy>> &getTypeInfo(BasicBlock *B);
};

}

#endif
114 changes: 114 additions & 0 deletions llvm/include/llvm/Transforms/Utils/PointerTypeTool/MyTy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#ifndef LLVM_TRANSFORMS_UTILS_POINTERTYPETOOL_MYTY_H
#define LLVM_TRANSFORMS_UTILS_POINTERTYPETOOL_MYTY_H

#include <string>
#include "llvm/IR/Type.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/DenseMap.h"

using std::make_shared;
using std::shared_ptr;
using std::string;

namespace llvm {

class MyTy {
public:
enum MyTypeID { Basic, Pointer, Unknown, Array, Struct, Vector, Void };
MyTy();
virtual string toString();
virtual bool update(shared_ptr<MyTy>);
shared_ptr<MyTy> getPointeeTyAsPtr();
MyTypeID getTypeID() const;
void setTypeID(MyTypeID);
bool isBasic() const;
bool isPointer() const;
bool isVoid() const;
bool isArray() const;
bool isUnknown() const;
bool isStruct() const;
bool isVector() const;
bool compatibleWith(shared_ptr<MyTy>);
static shared_ptr<MyTy> leastCompatibleType(shared_ptr<MyTy>,
shared_ptr<MyTy>);
static shared_ptr<MyTy> getStructLCA(shared_ptr<MyTy>, shared_ptr<MyTy>);
template <typename T, typename U>
static shared_ptr<T> ptr_cast(shared_ptr<U>);
protected:
MyTypeID typeId;
static int floatBitWidth[7];
static shared_ptr<MyTy> basic_with_basic(shared_ptr<MyTy>, shared_ptr<MyTy>);
static shared_ptr<MyTy> ptr_with_array(shared_ptr<MyTy>, shared_ptr<MyTy>);
static shared_ptr<MyTy> int_with_int(Type *, Type *);
static shared_ptr<MyTy> float_with_float(Type *, Type *);
};

class MyVoidTy : public MyTy {
public:
MyVoidTy();
string toString() override;
};

class MyPointerTy : public MyTy {
shared_ptr<MyTy> pointeeTy;

public:
MyPointerTy(shared_ptr<MyTy>);
shared_ptr<MyTy> getPointeeTy();
string toString() override;
bool update(shared_ptr<MyTy>) override;
};

class MyBasicTy : public MyTy {
Type *basicTy;

public:
MyBasicTy(Type *basic);
Type *getBasic();
string toString() override;
};

class MyArrayTy : public MyTy {
int elementCnt;
shared_ptr<MyTy> elementTy;

public:
MyArrayTy(shared_ptr<MyTy> eTy, int eCnt);
shared_ptr<MyTy> getElementTy();
int getElementCnt() const;
string toString() override;
bool update(shared_ptr<MyTy> pointee) override;
};

class MyVectorTy : public MyTy {
int elementCnt;
shared_ptr<MyTy> elementTy;
bool fixed;

public:
MyVectorTy(shared_ptr<MyTy> eTy, int eCnt, bool fixed);
shared_ptr<MyTy> getElementTy();
int getElementCnt() const;
string toString() override;
bool update(shared_ptr<MyTy> pointee) override;
};

class MyStructTy : public MyTy {
SmallVector<shared_ptr<MyTy>> elementTy;
string name;
bool opaque;

public:
MyStructTy(string name, SmallVector<shared_ptr<MyTy>> vec, bool opaque);
shared_ptr<MyTy> getElementTy(int index = 0);
string toString() override;
bool hasName() const;
bool isOpaque() const;
int getElementCnt();
bool update(shared_ptr<MyTy> pointee) override;
bool updateElement(shared_ptr<MyTy> ty, int index = 0);
};

}
#endif
Loading