Added function computeOffsetforLocalVar to check how big the

offset-from-FP will be before allocating space for a local variable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1905 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve 2002-03-18 03:36:30 +00:00
parent c356e565a6
commit 89e2da034a

View File

@ -29,8 +29,9 @@ static AnnotationID MCFM_AID(
// This should not be called before "construct()" // This should not be called before "construct()"
// for a given Method. // for a given Method.
// //
MachineCodeForMethod &MachineCodeForMethod::construct(const Method *M, MachineCodeForMethod&
const TargetMachine &Tar){ MachineCodeForMethod::construct(const Method *M, const TargetMachine &Tar)
{
assert(M->getAnnotation(MCFM_AID) == 0 && assert(M->getAnnotation(MCFM_AID) == 0 &&
"Object already exists for this method!"); "Object already exists for this method!");
MachineCodeForMethod* mcInfo = new MachineCodeForMethod(M, Tar); MachineCodeForMethod* mcInfo = new MachineCodeForMethod(M, Tar);
@ -38,13 +39,16 @@ MachineCodeForMethod &MachineCodeForMethod::construct(const Method *M,
return *mcInfo; return *mcInfo;
} }
void MachineCodeForMethod::destruct(const Method *M) { void
MachineCodeForMethod::destruct(const Method *M)
{
bool Deleted = M->deleteAnnotation(MCFM_AID); bool Deleted = M->deleteAnnotation(MCFM_AID);
assert(Deleted && "Machine code did not exist for method!"); assert(Deleted && "Machine code did not exist for method!");
} }
MachineCodeForMethod&
MachineCodeForMethod &MachineCodeForMethod::get(const Method* method) { MachineCodeForMethod::get(const Method* method)
{
MachineCodeForMethod* mc = (MachineCodeForMethod*) MachineCodeForMethod* mc = (MachineCodeForMethod*)
method->getAnnotation(MCFM_AID); method->getAnnotation(MCFM_AID);
assert(mc && "Call construct() method first to allocate the object"); assert(mc && "Call construct() method first to allocate the object");
@ -59,34 +63,37 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Method* method)
unsigned int maxSize = 0; unsigned int maxSize = 0;
for (Method::const_iterator MI=method->begin(), ME=method->end(); for (Method::const_iterator MI=method->begin(), ME=method->end();
MI != ME; ++MI) { MI != ME; ++MI)
const BasicBlock *BB = *MI; {
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) const BasicBlock *BB = *MI;
if (CallInst *callInst = dyn_cast<CallInst>(*I)) { for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
unsigned int numOperands = callInst->getNumOperands() - 1; if (CallInst *callInst = dyn_cast<CallInst>(*I))
int numExtra = (int) numOperands - frameInfo.getNumFixedOutgoingArgs();
if (numExtra <= 0)
continue;
unsigned int sizeForThisCall;
if (frameInfo.argsOnStackHaveFixedSize())
{ {
int argSize = frameInfo.getSizeOfEachArgOnStack(); unsigned int numOperands = callInst->getNumOperands() - 1;
sizeForThisCall = numExtra * (unsigned) argSize; int numExtra = (int) numOperands - frameInfo.getNumFixedOutgoingArgs();
} if (numExtra <= 0)
else continue;
{
assert(0 && "UNTESTED CODE: Size per stack argument is not fixed on this architecture: use actual arg sizes to compute MaxOptionalArgsSize"); unsigned int sizeForThisCall;
sizeForThisCall = 0; if (frameInfo.argsOnStackHaveFixedSize())
for (unsigned i=0; i < numOperands; ++i) {
sizeForThisCall += target.findOptimalStorageSize(callInst-> int argSize = frameInfo.getSizeOfEachArgOnStack();
getOperand(i)->getType()); sizeForThisCall = numExtra * (unsigned) argSize;
} }
else
{
assert(0 && "UNTESTED CODE: Size per stack argument is not fixed on this architecture: use actual arg sizes to compute MaxOptionalArgsSize");
sizeForThisCall = 0;
for (unsigned i=0; i < numOperands; ++i)
sizeForThisCall += target.findOptimalStorageSize(callInst->
getOperand(i)->getType());
}
if (maxSize < sizeForThisCall)
maxSize = sizeForThisCall;
}
}
if (maxSize < sizeForThisCall)
maxSize = sizeForThisCall;
}
}
return maxSize; return maxSize;
} }
@ -120,8 +127,41 @@ MachineCodeForMethod::MachineCodeForMethod(const Method* _M,
currentTmpValuesSize(0) currentTmpValuesSize(0)
{ {
maxOptionalArgsSize = ComputeMaxOptionalArgsSize(target, method); maxOptionalArgsSize = ComputeMaxOptionalArgsSize(target, method);
staticStackSize = maxOptionalArgsSize + staticStackSize = maxOptionalArgsSize
target.getFrameInfo().getMinStackFrameSize(); + target.getFrameInfo().getMinStackFrameSize();
}
int
MachineCodeForMethod::computeOffsetforLocalVar(const TargetMachine& target,
const Value* val,
unsigned int size)
{
bool growUp;
int firstOffset =target.getFrameInfo().getFirstAutomaticVarOffset(*this,
growUp);
unsigned char align;
if (size == 0)
{
size = target.findOptimalStorageSize(val->getType());
// align = target.DataLayout.getTypeAlignment(val->getType());
}
align = SizeToAlignment(size, target);
int offset = getAutomaticVarsSize();
if (! growUp)
offset += size;
if (unsigned int mod = offset % align)
{
offset += align - mod;
size += align - mod;
}
offset = growUp? firstOffset + offset
: firstOffset - offset;
return offset;
} }
int int
@ -134,33 +174,8 @@ MachineCodeForMethod::allocateLocalVar(const TargetMachine& target,
int offset = getOffset(val); int offset = getOffset(val);
if (offset == INVALID_FRAME_OFFSET) if (offset == INVALID_FRAME_OFFSET)
{ {
bool growUp; offset = this->computeOffsetforLocalVar(target, val, size);
int firstOffset =target.getFrameInfo().getFirstAutomaticVarOffset(*this,
growUp);
unsigned char align;
if (size == 0)
{
size = target.findOptimalStorageSize(val->getType());
// align = target.DataLayout.getTypeAlignment(val->getType());
}
align = SizeToAlignment(size, target);
offset = getAutomaticVarsSize();
if (! growUp)
offset += size;
if (unsigned int mod = offset % align)
{
offset += align - mod;
size += align - mod;
}
offset = growUp? firstOffset + offset
: firstOffset - offset;
offsets[val] = offset; offsets[val] = offset;
incrementAutomaticVarsSize(size); incrementAutomaticVarsSize(size);
} }
return offset; return offset;