[llvm-commits] [poolalloc] r128991 - in /poolalloc/trunk: lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.c
Brice Lin
Brice.Lin at gmail.com
Tue Apr 5 23:04:17 PDT 2011
Author: bglin2
Date: Wed Apr 6 01:04:17 2011
New Revision: 128991
URL: http://llvm.org/viewvc/llvm-project?rev=128991&view=rev
Log:
1. Lowered memory usage using 1:1 mapping of data to metadata (from uint32_t to uint8_t).
2. Cleaned up output.
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=128991&r1=128990&r2=128991&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Wed Apr 6 01:04:17 2011
@@ -157,10 +157,10 @@
std::vector<Value *> Args;
Args.push_back(BCI);
- Args.push_back(ConstantInt::get(Int32Ty, UsedTypes[LI.getType()]));
+ Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[LI.getType()]));
// Create the call to the runtime check and place it before the load instruction.
- Constant *F = M.getOrInsertFunction("trackLoadInst", Int32Ty, VoidPtrTy, Int32Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackLoadInst", VoidTy, VoidPtrTy, Int8Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &LI);
return true;
@@ -173,10 +173,10 @@
std::vector<Value *> Args;
Args.push_back(BCI);
- Args.push_back(ConstantInt::get(Int32Ty, UsedTypes[SI.getOperand(0)->getType()])); // SI.getValueOperand()
+ Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[SI.getOperand(0)->getType()])); // SI.getValueOperand()
// Create the call to the runtime check and place it before the store instruction.
- Constant *F = M.getOrInsertFunction("trackStoreInst", Int32Ty, VoidPtrTy, Int32Ty, NULL);
+ Constant *F = M.getOrInsertFunction("trackStoreInst", VoidTy, VoidPtrTy, Int8Ty, NULL);
CallInst::Create(F, Args.begin(), Args.end(), "", &SI);
return true;
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=128991&r1=128990&r2=128991&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Wed Apr 6 01:04:17 2011
@@ -3,18 +3,25 @@
#include <stdio.h>
#include <sys/mman.h>
-#define SIZE ((size_t)(sizeof(unsigned int)) * (size_t)(4294967296))
+#define DEBUG (0)
-unsigned int *shadow_begin;
+#define SIZE ((size_t)(4294967296))
+
+#if 0
+/* 2^47 bits */
+#define SIZE ((size_t)(140737488355328))
+#endif
+
+uint8_t *shadow_begin;
/**
* Initialize the shadow memory which records the 1:1 mapping of addresses to types.
*/
void shadowInit() {
- shadow_begin = (unsigned int *)mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
+ shadow_begin = (uint8_t *)mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
if (shadow_begin == MAP_FAILED) {
- fprintf(stderr, "Failed to map the shadow memory!");
+ fprintf(stderr, "Failed to map the shadow memory!\n");
fflush(stderr);
assert(0 && "MAP_FAILED");
}
@@ -25,36 +32,36 @@
*/
void shadowUnmap() {
if (munmap(shadow_begin, SIZE) == -1) {
- fprintf(stderr, "Failed to unmap the shadow memory!");
+ fprintf(stderr, "Failed to unmap the shadow memory!\n");
fflush(stderr);
}
}
/**
* Check the loaded type against the type recorded in the shadow memory.
- *
- * Note: currently does not handle GEPs.
*/
-int trackLoadInst(void *ptr, unsigned int typeNumber) {
+void trackLoadInst(void *ptr, uint8_t typeNumber) {
uintptr_t p = (uintptr_t)ptr;
p &= 0xFFFFFFFF;
- printf("Load: %p, %p = %u | expecting %u\n", ptr, (void *)p, typeNumber, shadow_begin[p]);
- return 0;
+ if (typeNumber != shadow_begin[p]) {
+ printf("Type mismatch: detecting %u, expecting %u!\n", typeNumber, shadow_begin[p]);
+ }
+
+#if DEBUG
+ printf("Load: %p, %p = %u | expecting %u\n", ptr, (void *)p, typeNumber, shadow_begin[p]);
+#endif
}
/**
* Record the stored type and address in the shadow memory.
- *
- * Note: currently does not handle GEPs.
*/
-int trackStoreInst(void *ptr, unsigned int typeNumber) {
+void trackStoreInst(void *ptr, uint8_t typeNumber) {
uintptr_t p = (uintptr_t)ptr;
p &= 0xFFFFFFFF;
shadow_begin[p] = typeNumber;
-#if 0
+
+#if DEBUG
printf("Store: %p, %p = %u\n", ptr, (void *)p, typeNumber);
#endif
-
- return 0;
}
More information about the llvm-commits
mailing list