mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Added code for pool allocating only the pool-allocatable data structures in the presence of collapsed nodes + a couple of bug fixes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7662 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
69666e552e
commit
8e37bd0330
@ -163,6 +163,9 @@ bool PoolAllocate::run(Module &M) {
|
|||||||
ProcessFunctionBody(*I, FI != FuncMap.end() ? *FI->second : *I);
|
ProcessFunctionBody(*I, FI != FuncMap.end() ? *FI->second : *I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CollapseFlag)
|
||||||
|
std::cerr << "Pool Allocation successful! However all data structures may not be pool allocated\n";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,6 +395,8 @@ Function *PoolAllocate::MakeFunctionClone(Function &F) {
|
|||||||
assert ((FI.ArgNodes.size() == (unsigned) (FI.PoolArgLast -
|
assert ((FI.ArgNodes.size() == (unsigned) (FI.PoolArgLast -
|
||||||
FI.PoolArgFirst)) &&
|
FI.PoolArgFirst)) &&
|
||||||
"Number of ArgNodes equal to the number of pool arguments used by this function");
|
"Number of ArgNodes equal to the number of pool arguments used by this function");
|
||||||
|
|
||||||
|
if (FI.ArgNodes.empty()) return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -412,6 +417,7 @@ Function *PoolAllocate::MakeFunctionClone(Function &F) {
|
|||||||
Function::aiterator NI = New->abegin();
|
Function::aiterator NI = New->abegin();
|
||||||
|
|
||||||
if (FuncECs.findClass(&F)) {
|
if (FuncECs.findClass(&F)) {
|
||||||
|
// If the function belongs to an equivalence class
|
||||||
for (int i = 0; i <= EqClass2LastPoolArg[FuncECs.findClass(&F)]; ++i,
|
for (int i = 0; i <= EqClass2LastPoolArg[FuncECs.findClass(&F)]; ++i,
|
||||||
++NI)
|
++NI)
|
||||||
NI->setName("PDa");
|
NI->setName("PDa");
|
||||||
@ -421,7 +427,6 @@ Function *PoolAllocate::MakeFunctionClone(Function &F) {
|
|||||||
for (int i = 0; i < FI.PoolArgFirst; ++NI, ++i)
|
for (int i = 0; i < FI.PoolArgFirst; ++NI, ++i)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (FI.ArgNodes.size() > 0)
|
|
||||||
for (unsigned i = 0, e = FI.ArgNodes.size(); i != e; ++i, ++NI)
|
for (unsigned i = 0, e = FI.ArgNodes.size(); i != e; ++i, ++NI)
|
||||||
PoolDescriptors.insert(std::make_pair(FI.ArgNodes[i], NI));
|
PoolDescriptors.insert(std::make_pair(FI.ArgNodes[i], NI));
|
||||||
|
|
||||||
@ -430,6 +435,7 @@ Function *PoolAllocate::MakeFunctionClone(Function &F) {
|
|||||||
for (int i = 0; i <= EqClass2LastPoolArg[FuncECs.findClass(&F)]; ++i, ++NI)
|
for (int i = 0; i <= EqClass2LastPoolArg[FuncECs.findClass(&F)]; ++i, ++NI)
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
|
// If the function does not belong to an equivalence class
|
||||||
if (FI.ArgNodes.size())
|
if (FI.ArgNodes.size())
|
||||||
for (unsigned i = 0, e = FI.ArgNodes.size(); i != e; ++i, ++NI) {
|
for (unsigned i = 0, e = FI.ArgNodes.size(); i != e; ++i, ++NI) {
|
||||||
NI->setName("PDa"); // Add pd entry
|
NI->setName("PDa"); // Add pd entry
|
||||||
@ -536,7 +542,8 @@ void PoolAllocate::CreatePools(Function &F,
|
|||||||
if (Node->getType() != Type::VoidTy)
|
if (Node->getType() != Type::VoidTy)
|
||||||
ElSize = ConstantUInt::get(Type::UIntTy, TD.getTypeSize(Node->getType()));
|
ElSize = ConstantUInt::get(Type::UIntTy, TD.getTypeSize(Node->getType()));
|
||||||
else {
|
else {
|
||||||
std::cerr << "Potential node collapsing in " << F.getName() << "\n";
|
DEBUG(std::cerr << "Potential node collapsing in " << F.getName()
|
||||||
|
<< ". All Data Structures may not be pool allocated\n");
|
||||||
ElSize = ConstantUInt::get(Type::UIntTy, 0);
|
ElSize = ConstantUInt::get(Type::UIntTy, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,11 +612,36 @@ namespace {
|
|||||||
return G.getScalarMap()[V];
|
return G.getScalarMap()[V];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DSNodeHandle& getTDDSNodeHFor(Value *V) {
|
||||||
|
if (!FI.NewToOldValueMap.empty()) {
|
||||||
|
// If the NewToOldValueMap is in effect, use it.
|
||||||
|
std::map<Value*,const Value*>::iterator I = FI.NewToOldValueMap.find(V);
|
||||||
|
if (I != FI.NewToOldValueMap.end())
|
||||||
|
V = (Value*)I->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TDG.getScalarMap()[V];
|
||||||
|
}
|
||||||
|
|
||||||
Value *getPoolHandle(Value *V) {
|
Value *getPoolHandle(Value *V) {
|
||||||
DSNode *Node = getDSNodeHFor(V).getNode();
|
DSNode *Node = getDSNodeHFor(V).getNode();
|
||||||
// Get the pool handle for this DSNode...
|
// Get the pool handle for this DSNode...
|
||||||
std::map<DSNode*, Value*>::iterator I = FI.PoolDescriptors.find(Node);
|
std::map<DSNode*, Value*>::iterator I = FI.PoolDescriptors.find(Node);
|
||||||
return I != FI.PoolDescriptors.end() ? I->second : 0;
|
|
||||||
|
if (I != FI.PoolDescriptors.end()) {
|
||||||
|
// Check that the node pointed to by V in the TD DS graph is not
|
||||||
|
// collapsed
|
||||||
|
DSNode *TDNode = getTDDSNodeHFor(V).getNode();
|
||||||
|
if (TDNode->getType() != Type::VoidTy)
|
||||||
|
return I->second;
|
||||||
|
else {
|
||||||
|
PAInfo.CollapseFlag = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFuncPtr(Value *V);
|
bool isFuncPtr(Value *V);
|
||||||
@ -765,6 +797,8 @@ void FuncTransform::visitPHINode(PHINode &PI) {
|
|||||||
void FuncTransform::visitMallocInst(MallocInst &MI) {
|
void FuncTransform::visitMallocInst(MallocInst &MI) {
|
||||||
// Get the pool handle for the node that this contributes to...
|
// Get the pool handle for the node that this contributes to...
|
||||||
Value *PH = getPoolHandle(&MI);
|
Value *PH = getPoolHandle(&MI);
|
||||||
|
|
||||||
|
// NB: PH is zero even if the node is collapsed
|
||||||
if (PH == 0) return;
|
if (PH == 0) return;
|
||||||
|
|
||||||
// Insert a call to poolalloc
|
// Insert a call to poolalloc
|
||||||
@ -878,7 +912,7 @@ static void CalcNodeMapping(DSNodeHandle& Caller, DSNodeHandle& Callee,
|
|||||||
|
|
||||||
if (numCallerLinks > 0) {
|
if (numCallerLinks > 0) {
|
||||||
if (numCallerLinks < numCalleeLinks) {
|
if (numCallerLinks < numCalleeLinks) {
|
||||||
std::cerr << "Potential node collapsing in caller\n";
|
DEBUG(std::cerr << "Potential node collapsing in caller\n");
|
||||||
for (unsigned i = 0, e = numCalleeLinks; i != e; ++i)
|
for (unsigned i = 0, e = numCalleeLinks; i != e; ++i)
|
||||||
CalcNodeMapping(CallerNode->getLink(((i%numCallerLinks) << DS::PointerShift) + CallerOffset), CalleeNode->getLink((i << DS::PointerShift) + CalleeOffset), NodeMapping);
|
CalcNodeMapping(CallerNode->getLink(((i%numCallerLinks) << DS::PointerShift) + CallerOffset), CalleeNode->getLink((i << DS::PointerShift) + CalleeOffset), NodeMapping);
|
||||||
} else {
|
} else {
|
||||||
@ -886,8 +920,8 @@ static void CalcNodeMapping(DSNodeHandle& Caller, DSNodeHandle& Callee,
|
|||||||
CalcNodeMapping(CallerNode->getLink((i << DS::PointerShift) + CallerOffset), CalleeNode->getLink((i << DS::PointerShift) + CalleeOffset), NodeMapping);
|
CalcNodeMapping(CallerNode->getLink((i << DS::PointerShift) + CallerOffset), CalleeNode->getLink((i << DS::PointerShift) + CalleeOffset), NodeMapping);
|
||||||
}
|
}
|
||||||
} else if (numCalleeLinks > 0) {
|
} else if (numCalleeLinks > 0) {
|
||||||
std::cerr <<
|
DEBUG(std::cerr <<
|
||||||
"Caller has unexpanded node, due to indirect call perhaps!\n";
|
"Caller has unexpanded node, due to indirect call perhaps!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1112,8 +1146,8 @@ void FuncTransform::visitCallInst(CallInst &CI) {
|
|||||||
Function *FuncClass = PAInfo.FuncECs.findClass(CF);
|
Function *FuncClass = PAInfo.FuncECs.findClass(CF);
|
||||||
|
|
||||||
if (PAInfo.EqClass2LastPoolArg.count(FuncClass))
|
if (PAInfo.EqClass2LastPoolArg.count(FuncClass))
|
||||||
for (unsigned i = CFI->PoolArgLast;
|
for (int i = CFI->PoolArgLast;
|
||||||
i <= PAInfo.EqClass2LastPoolArg.count(FuncClass); ++i)
|
i <= PAInfo.EqClass2LastPoolArg[FuncClass]; ++i)
|
||||||
Args.push_back(Constant::getNullValue(PoolDescPtr));
|
Args.push_back(Constant::getNullValue(PoolDescPtr));
|
||||||
|
|
||||||
// Add the rest of the arguments...
|
// Add the rest of the arguments...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user