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()"
// for a given Method.
//
MachineCodeForMethod &MachineCodeForMethod::construct(const Method *M,
const TargetMachine &Tar){
MachineCodeForMethod&
MachineCodeForMethod::construct(const Method *M, const TargetMachine &Tar)
{
assert(M->getAnnotation(MCFM_AID) == 0 &&
"Object already exists for this method!");
MachineCodeForMethod* mcInfo = new MachineCodeForMethod(M, Tar);
@ -38,13 +39,16 @@ MachineCodeForMethod &MachineCodeForMethod::construct(const Method *M,
return *mcInfo;
}
void MachineCodeForMethod::destruct(const Method *M) {
void
MachineCodeForMethod::destruct(const Method *M)
{
bool Deleted = M->deleteAnnotation(MCFM_AID);
assert(Deleted && "Machine code did not exist for method!");
}
MachineCodeForMethod &MachineCodeForMethod::get(const Method* method) {
MachineCodeForMethod&
MachineCodeForMethod::get(const Method* method)
{
MachineCodeForMethod* mc = (MachineCodeForMethod*)
method->getAnnotation(MCFM_AID);
assert(mc && "Call construct() method first to allocate the object");
@ -59,10 +63,12 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Method* method)
unsigned int maxSize = 0;
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)
if (CallInst *callInst = dyn_cast<CallInst>(*I)) {
if (CallInst *callInst = dyn_cast<CallInst>(*I))
{
unsigned int numOperands = callInst->getNumOperands() - 1;
int numExtra = (int) numOperands - frameInfo.getNumFixedOutgoingArgs();
if (numExtra <= 0)
@ -87,6 +93,7 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Method* method)
maxSize = sizeForThisCall;
}
}
return maxSize;
}
@ -120,19 +127,14 @@ MachineCodeForMethod::MachineCodeForMethod(const Method* _M,
currentTmpValuesSize(0)
{
maxOptionalArgsSize = ComputeMaxOptionalArgsSize(target, method);
staticStackSize = maxOptionalArgsSize +
target.getFrameInfo().getMinStackFrameSize();
staticStackSize = maxOptionalArgsSize
+ target.getFrameInfo().getMinStackFrameSize();
}
int
MachineCodeForMethod::allocateLocalVar(const TargetMachine& target,
MachineCodeForMethod::computeOffsetforLocalVar(const TargetMachine& target,
const Value* val,
unsigned int size)
{
// Check if we've allocated a stack slot for this value already
//
int offset = getOffset(val);
if (offset == INVALID_FRAME_OFFSET)
{
bool growUp;
int firstOffset =target.getFrameInfo().getFirstAutomaticVarOffset(*this,
@ -146,7 +148,7 @@ MachineCodeForMethod::allocateLocalVar(const TargetMachine& target,
align = SizeToAlignment(size, target);
offset = getAutomaticVarsSize();
int offset = getAutomaticVarsSize();
if (! growUp)
offset += size;
@ -159,8 +161,21 @@ MachineCodeForMethod::allocateLocalVar(const TargetMachine& target,
offset = growUp? firstOffset + offset
: firstOffset - offset;
offsets[val] = offset;
return offset;
}
int
MachineCodeForMethod::allocateLocalVar(const TargetMachine& target,
const Value* val,
unsigned int size)
{
// Check if we've allocated a stack slot for this value already
//
int offset = getOffset(val);
if (offset == INVALID_FRAME_OFFSET)
{
offset = this->computeOffsetforLocalVar(target, val, size);
offsets[val] = offset;
incrementAutomaticVarsSize(size);
}
return offset;