[llvm-commits] [poolalloc] r72345 - in /poolalloc/trunk: include/poolalloc/PoolAllocate.h lib/PoolAllocate/PASimple.cpp
Haohui Mai
mai4 at uiuc.edu
Sat May 23 14:44:50 PDT 2009
Author: mai4
Date: Sat May 23 16:44:44 2009
New Revision: 72345
URL: http://llvm.org/viewvc/llvm-project?rev=72345&view=rev
Log:
1. Rename the global pool to poolalloc.GlobalPool
2. Do not take the responbility to insert initialization calls in main() function. Instead, create a function poolalloc.init(), and let the client handles it. The client might either put it into the global constructor list or insert it into the main() function, just as it did before. This patch enables poolallocation to support memory allocation in static global constructors.
Modified:
poolalloc/trunk/include/poolalloc/PoolAllocate.h
poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=72345&r1=72344&r2=72345&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Sat May 23 16:44:44 2009
@@ -439,7 +439,7 @@
void getAnalysisUsage(AnalysisUsage &AU) const;
bool runOnModule(Module &M);
GlobalVariable *CreateGlobalPool(unsigned RecSize, unsigned Align,
- Instruction *IPHint, Module& M);
+ Module& M);
void ProcessFunctionBodySimple(Function& F, TargetData & TD);
Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=72345&r1=72344&r2=72345&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Sat May 23 16:44:44 2009
@@ -132,12 +132,14 @@
//
// Create the global pool.
//
- TheGlobalPool = CreateGlobalPool(32, 1, MainFunc->getEntryBlock().begin(), M);
+ TheGlobalPool = CreateGlobalPool(32, 1, M);
//
// Now that all call targets are available, rewrite the function bodies of the
// clones.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
+ std::string name = I->getName();
+ if (name == "poolalloc.init") continue;
if (!(I->isDeclaration()))
ProcessFunctionBodySimple(*I, TD);
}
@@ -349,29 +351,23 @@
GlobalVariable *
PoolAllocateSimple::CreateGlobalPool (unsigned RecSize,
unsigned Align,
- Instruction *IPHint,
Module& M) {
GlobalVariable *GV =
new GlobalVariable(getPoolType(), false, GlobalValue::InternalLinkage,
- Constant::getNullValue(getPoolType()), "GlobalPool",
+ Constant::getNullValue(getPoolType()), "poolalloc.GlobalPool",
&M);
- Function *MainFunc = (M.getFunction("main") ? M.getFunction("main")
- : M.getFunction("MAIN__"));
- assert(MainFunc && "No main in program??");
-
- BasicBlock::iterator InsertPt;
- if (IPHint)
- InsertPt = IPHint;
- else {
- InsertPt = MainFunc->getEntryBlock().begin();
- while (isa<AllocaInst>(InsertPt)) ++InsertPt;
- }
+ Function *InitFunc = Function::Create
+ (FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false),
+ GlobalValue::InternalLinkage, "poolalloc.init", &M);
+ BasicBlock * BB = BasicBlock::Create("entry", InitFunc);
Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize);
Value *AlignV = ConstantInt::get(Type::Int32Ty, Align);
Value* Opts[3] = {GV, ElSize, AlignV};
- CallInst::Create(PoolInit, Opts, Opts + 3, "", InsertPt);
+ CallInst::Create(PoolInit, Opts, Opts + 3, "", BB);
+
+ ReturnInst::Create(BB);
return GV;
}
More information about the llvm-commits
mailing list