[llvm-commits] [poolalloc] r133650 - in /poolalloc/trunk: lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Wed Jun 22 14:17:19 PDT 2011
Author: aggarwa4
Date: Wed Jun 22 16:17:19 2011
New Revision: 133650
URL: http://llvm.org/viewvc/llvm-project?rev=133650&view=rev
Log:
Create a separate TypeTagTy, to make it more flexible.
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=133650&r1=133649&r2=133650&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Wed Jun 22 16:17:19 2011
@@ -60,6 +60,10 @@
static const Type *Int32Ty = 0;
static const Type *Int64Ty = 0;
static const PointerType *VoidPtrTy = 0;
+
+static const Type *TypeTagTy = 0;
+static const Type *TypeTagPtrTy = 0;
+
static Constant *One = 0;
static Constant *Zero = 0;
static Constant *RegisterArgv;
@@ -112,11 +116,11 @@
}
Constant *TypeChecks::getTypeMarkerConstant(Value * V) {
- return ConstantInt::get(Int8Ty, getTypeMarker(V));
+ return ConstantInt::get(TypeTagTy, getTypeMarker(V));
}
Constant *TypeChecks::getTypeMarkerConstant(const Type *T) {
- return ConstantInt::get(Int8Ty, getTypeMarker(T));
+ return ConstantInt::get(TypeTagTy, getTypeMarker(T));
}
bool TypeChecks::runOnModule(Module &M) {
@@ -131,6 +135,10 @@
Int32Ty = IntegerType::getInt32Ty(M.getContext());
Int64Ty = IntegerType::getInt64Ty(M.getContext());
VoidPtrTy = PointerType::getUnqual(Int8Ty);
+
+ TypeTagTy = Int8Ty;
+ TypeTagPtrTy = PointerType::getUnqual(TypeTagTy);
+
One = ConstantInt::get(Int64Ty, 1);
Zero = ConstantInt::get(Int64Ty, 0);
@@ -146,7 +154,7 @@
trackGlobal = M.getOrInsertFunction("trackGlobal",
VoidTy,
VoidPtrTy,/*ptr*/
- Int8Ty,/*type*/
+ TypeTagTy,/*type*/
Int64Ty,/*size*/
Int32Ty,/*tag*/
NULL);
@@ -172,7 +180,7 @@
trackStoreInst = M.getOrInsertFunction("trackStoreInst",
VoidTy,
VoidPtrTy,/*ptr*/
- Int8Ty,/*type*/
+ TypeTagTy,/*type*/
Int64Ty,/*size*/
Int32Ty,/*tag*/
NULL);
@@ -180,20 +188,20 @@
VoidTy,
VoidPtrTy, /*ptr*/
Int64Ty, /*size*/
- VoidPtrTy, /*dest for type tag*/
+ TypeTagPtrTy, /*dest for type tag*/
NULL);
checkTypeInst = M.getOrInsertFunction("checkType",
VoidTy,
- Int8Ty,/*type*/
+ TypeTagTy,/*type*/
Int64Ty,/*size*/
- VoidPtrTy,
+ TypeTagPtrTy,/*ptr to metadata*/
VoidPtrTy,/*ptr*/
Int32Ty,/*tag*/
NULL);
setTypeInfo = M.getOrInsertFunction("setTypeInfo",
VoidTy,
VoidPtrTy,/*dest ptr*/
- VoidPtrTy,/*metadata*/
+ TypeTagPtrTy,/*metadata*/
Int64Ty,/*size*/
Int32Ty,/*tag*/
NULL);
@@ -213,7 +221,7 @@
VoidTy,
VoidPtrTy,/*va_list ptr*/
Int64Ty,/*total num of elements in va_list */
- VoidPtrTy,/*ptr to metadta*/
+ TypeTagPtrTy,/*ptr to metadta*/
Int32Ty,/*tag*/
NULL);
copyVAInfo = M.getOrInsertFunction("copyVAInfo",
@@ -225,7 +233,7 @@
checkVAArg = M.getOrInsertFunction("checkVAArgType",
VoidTy,
VoidPtrTy,/*va_list ptr*/
- Int8Ty,/*type*/
+ TypeTagTy,/*type*/
Int32Ty,/*tag*/
NULL);
@@ -527,7 +535,7 @@
unsigned int NumArgs = CI->getNumOperands() - 1;
inst_iterator InsPt = inst_begin(CI->getParent()->getParent());
Value *NumArgsVal = ConstantInt::get(Int32Ty, NumArgs);
- AllocaInst *AI = new AllocaInst(Int8Ty, NumArgsVal, "", &*InsPt);
+ AllocaInst *AI = new AllocaInst(TypeTagTy, NumArgsVal, "", &*InsPt);
// set the metadata for the varargs in AI
for(i = 1; i <CI->getNumOperands(); i++) {
Value *Idx[2];
@@ -599,7 +607,7 @@
// 1. Create the new argument types vector
std::vector<const Type*> TP;
TP.push_back(Int64Ty); // for count
- TP.push_back(VoidPtrTy); // for MD
+ TP.push_back(TypeTagPtrTy); // for MD
for(Function::arg_iterator I = F.arg_begin(); I !=F.arg_end(); ++I) {
TP.push_back(I->getType());
}
@@ -719,7 +727,7 @@
unsigned int i;
unsigned int NumArgs = II->getNumOperands() - 3;
Value *NumArgsVal = ConstantInt::get(Int32Ty, NumArgs);
- AllocaInst *AI = new AllocaInst(Int8Ty, NumArgsVal, "", &*InsPt);
+ AllocaInst *AI = new AllocaInst(TypeTagTy, NumArgsVal, "", &*InsPt);
// set the metadata for the varargs in AI
for(i = 3; i <II->getNumOperands(); i++) {
Value *Idx[2];
@@ -755,7 +763,7 @@
unsigned int i;
unsigned int NumArgs = CI->getNumOperands() - 1;
Value *NumArgsVal = ConstantInt::get(Int32Ty, NumArgs);
- AllocaInst *AI = new AllocaInst(Int8Ty, NumArgsVal, "", &*InsPt);
+ AllocaInst *AI = new AllocaInst(TypeTagTy, NumArgsVal, "", &*InsPt);
// set the metadata for the varargs in AI
for(i = 1; i <CI->getNumOperands(); i++) {
Value *Idx[2];
@@ -1122,30 +1130,30 @@
return true;
}
- bool TypeChecks::visitMain(Module &M, Function &MainFunc) {
- if(MainFunc.arg_size() < 2)
- // No need to register
- return false;
-
- Function::arg_iterator AI = MainFunc.arg_begin();
- Value *Argc = AI;
- Value *Argv = ++AI;
-
- Instruction *InsertPt = MainFunc.front().begin();
- std::vector<Value *> fargs;
- fargs.push_back (Argc);
- fargs.push_back (Argv);
- CallInst::Create (RegisterArgv, fargs.begin(), fargs.end(), "", InsertPt);
+bool TypeChecks::visitMain(Module &M, Function &MainFunc) {
+ if(MainFunc.arg_size() < 2)
+ // No need to register
+ return false;
- if(MainFunc.arg_size() < 3)
- return true;
+ Function::arg_iterator AI = MainFunc.arg_begin();
+ Value *Argc = AI;
+ Value *Argv = ++AI;
+
+ Instruction *InsertPt = MainFunc.front().begin();
+ std::vector<Value *> fargs;
+ fargs.push_back (Argc);
+ fargs.push_back (Argv);
+ CallInst::Create (RegisterArgv, fargs.begin(), fargs.end(), "", InsertPt);
- Value *Envp = ++AI;
- std::vector<Value*> Args;
- Args.push_back(Envp);
- CallInst::Create(RegisterEnvp, Args.begin(), Args.end(), "", InsertPt);
+ if(MainFunc.arg_size() < 3)
return true;
- }
+
+ Value *Envp = ++AI;
+ std::vector<Value*> Args;
+ Args.push_back(Envp);
+ CallInst::Create(RegisterEnvp, Args.begin(), Args.end(), "", InsertPt);
+ return true;
+}
bool TypeChecks::visitGlobal(Module &M, GlobalVariable &GV,
Constant *C, Instruction &I, SmallVector<Value *,8> Indices) {
@@ -1240,17 +1248,17 @@
}
return true;
}
-bool TypeChecks::visitVAArgInst(Module &M, VAArgInst &VI) {
- if(!VI.getParent()->getParent()->hasInternalLinkage())
+ bool TypeChecks::visitVAArgInst(Module &M, VAArgInst &VI) {
+ if(!VI.getParent()->getParent()->hasInternalLinkage())
+ return false;
+ CastInst *BCI = BitCastInst::CreatePointerCast(VI.getOperand(0), VoidPtrTy, "", &VI);
+ std::vector<Value *>Args;
+ Args.push_back(BCI);
+ Args.push_back(getTypeMarkerConstant(&VI));
+ Args.push_back(getTagCounter());
+ CallInst::Create(checkVAArg, Args.begin(), Args.end(), "", &VI);
return false;
- CastInst *BCI = BitCastInst::CreatePointerCast(VI.getOperand(0), VoidPtrTy, "", &VI);
- std::vector<Value *>Args;
- Args.push_back(BCI);
- Args.push_back(getTypeMarkerConstant(&VI));
- Args.push_back(getTagCounter());
- CallInst::Create(checkVAArg, Args.begin(), Args.end(), "", &VI);
- return false;
-}
+ }
// Insert code to initialize meta data to bottom
// Insert code to set objects to 0
@@ -1630,7 +1638,7 @@
const FunctionType *FOldType = cast<FunctionType>((cast<PointerType>(OrigType))->getElementType());
std::vector<const Type*>TP;
TP.push_back(Int64Ty);
- TP.push_back(VoidPtrTy);
+ TP.push_back(TypeTagPtrTy);
for(llvm::FunctionType::param_iterator ArgI = FOldType->param_begin(); ArgI != FOldType->param_end(); ++ArgI)
TP.push_back(*ArgI);
@@ -1640,14 +1648,11 @@
inst_iterator InsPt = inst_begin(I->getParent()->getParent());
-
-
-
if(isa<CallInst>(I)) {
unsigned int NumArgs = I->getNumOperands() - 1;
Value *NumArgsVal = ConstantInt::get(Int32Ty, NumArgs);
- AllocaInst *AI = new AllocaInst(Int8Ty, NumArgsVal, "", &*InsPt);
+ AllocaInst *AI = new AllocaInst(TypeTagTy, NumArgsVal, "", &*InsPt);
for(unsigned int i = 1; i < I->getNumOperands(); i++) {
Value *Idx[2];
Idx[0] = ConstantInt::get(Int32Ty, i-1);
@@ -1675,7 +1680,7 @@
unsigned int NumArgs = I->getNumOperands() - 3;
Value *NumArgsVal = ConstantInt::get(Int32Ty, NumArgs);
- AllocaInst *AI = new AllocaInst(Int8Ty, NumArgsVal, "", &*InsPt);
+ AllocaInst *AI = new AllocaInst(TypeTagTy, NumArgsVal, "", &*InsPt);
for(unsigned int i = 3; i < I->getNumOperands(); i++) {
Value *Idx[2];
Idx[0] = ConstantInt::get(Int32Ty, i-3);
@@ -1746,7 +1751,7 @@
CastInst *BCI = BitCastInst::CreatePointerCast(LI.getPointerOperand(), VoidPtrTy, "", &LI);
Value *Size = ConstantInt::get(Int32Ty, getSize(LI.getType()));
- AllocaInst *AI = new AllocaInst(Int8Ty, Size, "", &*InsPt);
+ AllocaInst *AI = new AllocaInst(TypeTagTy, Size, "", &*InsPt);
CastInst *BCI_MD = BitCastInst::CreatePointerCast(AI, VoidPtrTy, "", &*InsPt);
std::vector<Value *>Args1;
@@ -1801,7 +1806,6 @@
getTypeCall->eraseFromParent();
}
-
// Create the call to the runtime check and place it before the load instruction.
numLoadChecks++;
return true;
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp?rev=133650&r1=133649&r2=133650&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.cpp Wed Jun 22 16:17:19 2011
@@ -25,7 +25,7 @@
* For now, run a version of the tool without the base fixed, and
* choose address.
*/
-#define BASE ((uint8_t *)(0x2aaaab88c000))
+#define BASE ((TypeTagTy *)(0x2aaaab88c000))
/*
* Do some macro magic to get mmap macros defined properly on all platforms.
*/
@@ -33,17 +33,19 @@
# define MAP_ANONYMOUS MAP_ANON
#endif /* defined(MAP_ANON) && !defined(MAP_ANONYMOUS) */
+typedef uint8_t TypeTagTy ;
+
struct va_info {
uint64_t numElements;
uint64_t counter;
- uint8_t *metadata;
+ TypeTagTy *metadata;
};
// Map to store info about va lists
std::map<void *, struct va_info> VA_InfoMap;
// Pointer to the shadow_memory
-uint8_t * const shadow_begin = BASE;
+TypeTagTy * const shadow_begin = BASE;
// Map from type numbers to type names.
extern char* typeNames[];
@@ -53,22 +55,22 @@
void shadowInit();
void trackArgvType(int argc, char **argv) ;
void trackEnvpType(char **envp) ;
- void trackGlobal(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) ;
+ void trackGlobal(void *ptr, TypeTagTy typeNumber, uint64_t size, uint32_t tag) ;
void trackArray(void *ptr, uint64_t size, uint64_t count, uint32_t tag) ;
- void trackStoreInst(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) ;
+ void trackStoreInst(void *ptr, TypeTagTy typeNumber, uint64_t size, uint32_t tag) ;
void trackStringInput(void *ptr, uint32_t tag) ;
- void compareTypes(uint8_t typeNumberSrc, uint8_t typeNumberDest, uint32_t tag) ;
+ void compareTypes(TypeTagTy typeNumberSrc, TypeTagTy typeNumberDest, uint32_t tag) ;
void compareNumber(uint64_t NumArgsPassed, uint64_t ArgAccessed, uint32_t tag);
void compareTypeAndNumber(uint64_t NumArgsPassed, uint64_t ArgAccessed, uint8_t TypeAccessed, void *MD, uint32_t tag) ;
- void checkVAArgType(void *va_list, uint8_t TypeAccessed, uint32_t tag) ;
- void getTypeTag(void *ptr, uint64_t size, uint8_t *dest) ;
- void checkType(uint8_t typeNumber, uint64_t size, uint8_t *metadata, void *ptr, uint32_t tag);
+ void checkVAArgType(void *va_list, TypeTagTy TypeAccessed, uint32_t tag) ;
+ void getTypeTag(void *ptr, uint64_t size, TypeTagTy *dest) ;
+ void checkType(TypeTagTy typeNumber, uint64_t size, TypeTagTy *metadata, void *ptr, uint32_t tag);
void trackInitInst(void *ptr, uint64_t size, uint32_t tag) ;
void trackUnInitInst(void *ptr, uint64_t size, uint32_t tag) ;
void copyTypeInfo(void *dstptr, void *srcptr, uint64_t size, uint32_t tag) ;
void setTypeInfo(void *dstptr, void *metadata, uint64_t size, uint32_t tag) ;
- void setVAInfo(void *va_list, uint64_t totalCount, uint8_t *metadata_ptr) ;
- void copyVAInfo(void *va_list_dst, uint8_t *va_list_src) ;
+ void setVAInfo(void *va_list, uint64_t totalCount, TypeTagTy *metadata_ptr) ;
+ void copyVAInfo(void *va_list_dst, void *va_list_src) ;
void trackctype(void *ptr, uint32_t tag) ;
void trackctype_32(void *ptr, uint32_t tag) ;
void trackStrncpyInst(void *dst, void *src, uint64_t size, uint32_t tag) ;
@@ -131,7 +133,7 @@
/**
* Record the global type and address in the shadow memory.
*/
-void trackGlobal(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
+void trackGlobal(void *ptr, TypeTagTy typeNumber, uint64_t size, uint32_t tag) {
uintptr_t p = maskAddress(ptr);
shadow_begin[p] = typeNumber;
memset(&shadow_begin[p + 1], 0, size - 1);
@@ -157,7 +159,7 @@
/**
* Record the stored type and address in the shadow memory.
*/
-void trackStoreInst(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
+void trackStoreInst(void *ptr, TypeTagTy typeNumber, uint64_t size, uint32_t tag) {
uintptr_t p = maskAddress(ptr);
shadow_begin[p] = typeNumber;
memset(&shadow_begin[p + 1], 0, size - 1);
@@ -177,7 +179,7 @@
/**
* Check that the two types match
*/
-void compareTypes(uint8_t typeNumberSrc, uint8_t typeNumberDest, uint32_t tag) {
+void compareTypes(TypeTagTy typeNumberSrc, TypeTagTy typeNumberDest, uint32_t tag) {
if(typeNumberSrc != typeNumberDest) {
printf("Type mismatch(%u): expecting %s, found %s! \n", tag, typeNames[typeNumberDest], typeNames[typeNumberSrc]);
}
@@ -197,7 +199,7 @@
* Check that no. of arguments is less than passed
* Check that the type being accessed is correct
*/
-void checkVAArgType(void *va_list, uint8_t TypeAccessed, uint32_t tag) {
+void checkVAArgType(void *va_list, TypeTagTy TypeAccessed, uint32_t tag) {
va_info v = VA_InfoMap[va_list];
compareNumber(v.numElements, v.counter, tag);
compareTypes(TypeAccessed, v.metadata[v.counter], tag);
@@ -209,7 +211,7 @@
* For loads, return the metadata(for size bytes) stored at the ptr
* Store it in dest
*/
-void getTypeTag(void *ptr, uint64_t size, uint8_t *dest) {
+void getTypeTag(void *ptr, uint64_t size, TypeTagTy *dest) {
uintptr_t p = maskAddress(ptr);
assert(p + size < SIZE);
@@ -221,7 +223,7 @@
* ptr and tag are for debugging
*/
void __attribute__((always_inline))
-checkType(uint8_t typeNumber, uint64_t size, uint8_t *metadata, void *ptr, uint32_t tag) {
+checkType(TypeTagTy typeNumber, uint64_t size, TypeTagTy *metadata, void *ptr, uint32_t tag) {
/* Check if this an initialized but untyped memory.*/
if (typeNumber != metadata[0]) {
if (metadata[0] != 0xFF) {
@@ -295,7 +297,7 @@
/**
* Initialize the metadata for a given VAList
*/
-void setVAInfo(void *va_list, uint64_t totalCount, uint8_t *metadata_ptr, uint32_t tag) {
+void setVAInfo(void *va_list, uint64_t totalCount, TypeTagTy *metadata_ptr, uint32_t tag) {
struct va_info v = {totalCount, 0, metadata_ptr};
VA_InfoMap[va_list] = v;
}
@@ -303,7 +305,7 @@
/**
* Copy va list metadata from one list to the other.
*/
-void copyVAInfo(void *va_list_dst, uint8_t *va_list_src, uint32_t tag) {
+void copyVAInfo(void *va_list_dst, void *va_list_src, uint32_t tag) {
VA_InfoMap[va_list_dst] = VA_InfoMap[va_list_src];
}
More information about the llvm-commits
mailing list