blob: c1eb30a1966aeb7641aa6cf23e8842299047f303 [file] [log] [blame]
Chris Lattner6b944532002-10-28 01:16:38 +00001//===-- MachineFunction.cpp -----------------------------------------------===//
Chris Lattnerf2868ce2002-02-03 07:54:50 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner6b944532002-10-28 01:16:38 +000010// Collect native machine code information for a function. This allows
11// target-specific information about the generated code to be stored with each
12// function.
13//
14//===----------------------------------------------------------------------===//
Chris Lattnerf2868ce2002-02-03 07:54:50 +000015
Chris Lattner6b944532002-10-28 01:16:38 +000016#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner831fdcf2002-12-25 05:03:22 +000017#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner227c3d32002-10-28 01:12:41 +000018#include "llvm/CodeGen/MachineCodeForInstruction.h"
Chris Lattner831fdcf2002-12-25 05:03:22 +000019#include "llvm/CodeGen/SSARegMap.h"
Chris Lattner955fad12002-12-28 20:37:16 +000020#include "llvm/CodeGen/MachineFunctionInfo.h"
Chris Lattnereb24db92002-12-28 21:08:26 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner4d149cd2003-01-13 00:23:03 +000022#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000023#include "llvm/Target/TargetMachine.h"
Chris Lattner8bd66e62002-12-28 21:00:25 +000024#include "llvm/Target/TargetFrameInfo.h"
Chris Lattnerf27eeea2002-12-29 02:50:35 +000025#include "llvm/Target/TargetCacheInfo.h"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000026#include "llvm/Function.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000027#include "llvm/iOther.h"
Chris Lattner227c3d32002-10-28 01:12:41 +000028#include "llvm/Pass.h"
John Criswell7a73b802003-06-30 21:59:07 +000029#include "Config/limits.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000030
31const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max();
32
Chris Lattnere316efc2002-10-29 23:18:43 +000033static AnnotationID MF_AID(
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000034 AnnotationManager::getID("CodeGen::MachineCodeForFunction"));
Chris Lattnerf2868ce2002-02-03 07:54:50 +000035
Chris Lattner227c3d32002-10-28 01:12:41 +000036
37//===---------------------------------------------------------------------===//
38// Code generation/destruction passes
39//===---------------------------------------------------------------------===//
40
41namespace {
42 class ConstructMachineFunction : public FunctionPass {
43 TargetMachine &Target;
44 public:
45 ConstructMachineFunction(TargetMachine &T) : Target(T) {}
46
47 const char *getPassName() const {
48 return "ConstructMachineFunction";
49 }
50
51 bool runOnFunction(Function &F) {
Chris Lattner955fad12002-12-28 20:37:16 +000052 MachineFunction::construct(&F, Target).getInfo()->CalculateArgSize();
Chris Lattner227c3d32002-10-28 01:12:41 +000053 return false;
54 }
55 };
56
57 struct DestroyMachineFunction : public FunctionPass {
58 const char *getPassName() const { return "FreeMachineFunction"; }
59
60 static void freeMachineCode(Instruction &I) {
61 MachineCodeForInstruction::destroy(&I);
62 }
63
64 bool runOnFunction(Function &F) {
65 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
66 for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I)
67 MachineCodeForInstruction::get(I).dropAllReferences();
68
69 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
70 for_each(FI->begin(), FI->end(), freeMachineCode);
71
72 return false;
73 }
74 };
Chris Lattner10491642002-10-30 00:48:05 +000075
76 struct Printer : public FunctionPass {
77 const char *getPassName() const { return "MachineFunction Printer"; }
78
79 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
80 AU.setPreservesAll();
81 }
82
83 bool runOnFunction(Function &F) {
84 MachineFunction::get(&F).dump();
85 return false;
86 }
87 };
Chris Lattner227c3d32002-10-28 01:12:41 +000088}
89
Brian Gaeke19df3872003-08-13 18:18:15 +000090FunctionPass *createMachineCodeConstructionPass(TargetMachine &Target) {
Chris Lattner227c3d32002-10-28 01:12:41 +000091 return new ConstructMachineFunction(Target);
92}
93
Brian Gaeke19df3872003-08-13 18:18:15 +000094FunctionPass *createMachineCodeDestructionPass() {
Chris Lattner227c3d32002-10-28 01:12:41 +000095 return new DestroyMachineFunction();
96}
97
Brian Gaeke19df3872003-08-13 18:18:15 +000098FunctionPass *createMachineFunctionPrinterPass() {
Chris Lattner10491642002-10-30 00:48:05 +000099 return new Printer();
100}
101
Chris Lattner227c3d32002-10-28 01:12:41 +0000102
103//===---------------------------------------------------------------------===//
104// MachineFunction implementation
105//===---------------------------------------------------------------------===//
106
Chris Lattner10491642002-10-30 00:48:05 +0000107MachineFunction::MachineFunction(const Function *F,
Chris Lattner955fad12002-12-28 20:37:16 +0000108 const TargetMachine &TM)
109 : Annotation(MF_AID), Fn(F), Target(TM) {
Misha Brukmanb7825bc2002-11-20 18:55:27 +0000110 SSARegMapping = new SSARegMap();
Chris Lattner955fad12002-12-28 20:37:16 +0000111 MFInfo = new MachineFunctionInfo(*this);
Chris Lattnereb24db92002-12-28 21:08:26 +0000112 FrameInfo = new MachineFrameInfo();
Chris Lattner4d149cd2003-01-13 00:23:03 +0000113 ConstantPool = new MachineConstantPool();
Chris Lattner831fdcf2002-12-25 05:03:22 +0000114}
115
116MachineFunction::~MachineFunction() {
117 delete SSARegMapping;
Chris Lattner955fad12002-12-28 20:37:16 +0000118 delete MFInfo;
119 delete FrameInfo;
Chris Lattner4d149cd2003-01-13 00:23:03 +0000120 delete ConstantPool;
Chris Lattner10491642002-10-30 00:48:05 +0000121}
122
123void MachineFunction::dump() const { print(std::cerr); }
124
125void MachineFunction::print(std::ostream &OS) const {
Chris Lattner955fad12002-12-28 20:37:16 +0000126 OS << "\n" << *(Value*)Fn->getFunctionType() << " \"" << Fn->getName()
127 << "\"\n";
128
129 // Print Frame Information
Chris Lattner9085d8a2003-01-16 18:35:57 +0000130 getFrameInfo()->print(*this, OS);
Chris Lattner4d149cd2003-01-13 00:23:03 +0000131
132 // Print Constant Pool
133 getConstantPool()->print(OS);
Chris Lattner10491642002-10-30 00:48:05 +0000134
135 for (const_iterator BB = begin(); BB != end(); ++BB) {
Chris Lattner9e2dd8f2003-07-26 23:24:56 +0000136 const BasicBlock *LBB = BB->getBasicBlock();
Chris Lattner2109f502002-12-15 20:35:25 +0000137 OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
Chris Lattner10491642002-10-30 00:48:05 +0000138 for (MachineBasicBlock::const_iterator I = BB->begin(); I != BB->end();++I){
139 OS << "\t";
140 (*I)->print(OS, Target);
141 }
142 }
143 OS << "\nEnd function \"" << Fn->getName() << "\"\n\n";
144}
145
146
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000147// The next two methods are used to construct and to retrieve
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000148// the MachineCodeForFunction object for the given function.
149// construct() -- Allocates and initializes for a given function and target
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000150// get() -- Returns a handle to the object.
151// This should not be called before "construct()"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000152// for a given Function.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000153//
Misha Brukmanfce11432002-10-28 00:28:31 +0000154MachineFunction&
Chris Lattner335d5c32002-10-28 05:58:46 +0000155MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000156{
Chris Lattnere316efc2002-10-29 23:18:43 +0000157 assert(Fn->getAnnotation(MF_AID) == 0 &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000158 "Object already exists for this function!");
Chris Lattner335d5c32002-10-28 05:58:46 +0000159 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
160 Fn->addAnnotation(mcInfo);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000161 return *mcInfo;
162}
163
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000164void
Chris Lattner335d5c32002-10-28 05:58:46 +0000165MachineFunction::destruct(const Function *Fn)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000166{
Chris Lattnere316efc2002-10-29 23:18:43 +0000167 bool Deleted = Fn->deleteAnnotation(MF_AID);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000168 assert(Deleted && "Machine code did not exist for function!");
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000169}
170
Chris Lattner335d5c32002-10-28 05:58:46 +0000171MachineFunction& MachineFunction::get(const Function *F)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000172{
Chris Lattnere316efc2002-10-29 23:18:43 +0000173 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000174 assert(mc && "Call construct() method first to allocate the object");
175 return *mc;
176}
177
Chris Lattner831fdcf2002-12-25 05:03:22 +0000178void MachineFunction::clearSSARegMap() {
179 delete SSARegMapping;
180 SSARegMapping = 0;
181}
182
Chris Lattner955fad12002-12-28 20:37:16 +0000183//===----------------------------------------------------------------------===//
Chris Lattnereb24db92002-12-28 21:08:26 +0000184// MachineFrameInfo implementation
Chris Lattner955fad12002-12-28 20:37:16 +0000185//===----------------------------------------------------------------------===//
186
Chris Lattner4d149cd2003-01-13 00:23:03 +0000187/// CreateStackObject - Create a stack object for a value of the specified type.
188///
189int MachineFrameInfo::CreateStackObject(const Type *Ty, const TargetData &TD) {
190 return CreateStackObject(TD.getTypeSize(Ty), TD.getTypeAlignment(Ty));
191}
192
193int MachineFrameInfo::CreateStackObject(const TargetRegisterClass *RC) {
194 return CreateStackObject(RC->getSize(), RC->getAlignment());
195}
196
197
Chris Lattner9085d8a2003-01-16 18:35:57 +0000198void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
199 int ValOffset = MF.getTarget().getFrameInfo().getOffsetOfLocalArea();
200
Chris Lattner955fad12002-12-28 20:37:16 +0000201 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
202 const StackObject &SO = Objects[i];
Chris Lattner4d149cd2003-01-13 00:23:03 +0000203 OS << " <fi #" << (int)(i-NumFixedObjects) << "> is ";
Chris Lattner955fad12002-12-28 20:37:16 +0000204 if (SO.Size == 0)
205 OS << "variable sized";
206 else
207 OS << SO.Size << " byte" << (SO.Size != 1 ? "s" : " ");
208
209 if (i < NumFixedObjects)
210 OS << " fixed";
211 if (i < NumFixedObjects || SO.SPOffset != -1) {
Chris Lattner9085d8a2003-01-16 18:35:57 +0000212 int Off = SO.SPOffset + ValOffset;
Chris Lattner955fad12002-12-28 20:37:16 +0000213 OS << " at location [SP";
Chris Lattner9085d8a2003-01-16 18:35:57 +0000214 if (Off > 0)
215 OS << "+" << Off;
216 else if (Off < 0)
217 OS << Off;
Chris Lattner955fad12002-12-28 20:37:16 +0000218 OS << "]";
219 }
220 OS << "\n";
221 }
222
223 if (HasVarSizedObjects)
224 OS << " Stack frame contains variable sized objects\n";
225}
226
Chris Lattner9085d8a2003-01-16 18:35:57 +0000227void MachineFrameInfo::dump(const MachineFunction &MF) const {
228 print(MF, std::cerr);
229}
Chris Lattner955fad12002-12-28 20:37:16 +0000230
231
232//===----------------------------------------------------------------------===//
Chris Lattner4d149cd2003-01-13 00:23:03 +0000233// MachineConstantPool implementation
234//===----------------------------------------------------------------------===//
235
236void MachineConstantPool::print(std::ostream &OS) const {
237 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
238 OS << " <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
239}
240
241void MachineConstantPool::dump() const { print(std::cerr); }
242
243//===----------------------------------------------------------------------===//
Chris Lattner955fad12002-12-28 20:37:16 +0000244// MachineFunctionInfo implementation
245//===----------------------------------------------------------------------===//
Chris Lattner831fdcf2002-12-25 05:03:22 +0000246
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000247static unsigned
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000248ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F,
249 unsigned &maxOptionalNumArgs)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000250{
Chris Lattner955fad12002-12-28 20:37:16 +0000251 const TargetFrameInfo &frameInfo = target.getFrameInfo();
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000252
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000253 unsigned maxSize = 0;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000254
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000255 for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB)
256 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Chris Lattner2ee82e02003-04-23 16:36:11 +0000257 if (const CallInst *callInst = dyn_cast<CallInst>(I))
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000258 {
259 unsigned numOperands = callInst->getNumOperands() - 1;
260 int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();
261 if (numExtra <= 0)
262 continue;
263
Chris Lattner955fad12002-12-28 20:37:16 +0000264 unsigned sizeForThisCall;
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000265 if (frameInfo.argsOnStackHaveFixedSize())
266 {
267 int argSize = frameInfo.getSizeOfEachArgOnStack();
268 sizeForThisCall = numExtra * (unsigned) argSize;
269 }
270 else
271 {
272 assert(0 && "UNTESTED CODE: Size per stack argument is not "
273 "fixed on this architecture: use actual arg sizes to "
274 "compute MaxOptionalArgsSize");
275 sizeForThisCall = 0;
276 for (unsigned i = 0; i < numOperands; ++i)
Chris Lattner955fad12002-12-28 20:37:16 +0000277 sizeForThisCall += target.getTargetData().getTypeSize(callInst->
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000278 getOperand(i)->getType());
279 }
280
281 if (maxSize < sizeForThisCall)
282 maxSize = sizeForThisCall;
283
284 if ((int)maxOptionalNumArgs < numExtra)
285 maxOptionalNumArgs = (unsigned) numExtra;
286 }
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000287
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000288 return maxSize;
289}
290
291// Align data larger than one L1 cache line on L1 cache line boundaries.
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000292// Align all smaller data on the next higher 2^x boundary (4, 8, ...),
293// but not higher than the alignment of the largest type we support
294// (currently a double word). -- see class TargetData).
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000295//
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000296// This function is similar to the corresponding function in EmitAssembly.cpp
297// but they are unrelated. This one does not align at more than a
298// double-word boundary whereas that one might.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000299//
Chris Lattner955fad12002-12-28 20:37:16 +0000300inline unsigned
301SizeToAlignment(unsigned size, const TargetMachine& target)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000302{
303 unsigned short cacheLineSize = target.getCacheInfo().getCacheLineSize(1);
304 if (size > (unsigned) cacheLineSize / 2)
305 return cacheLineSize;
306 else
307 for (unsigned sz=1; /*no condition*/; sz *= 2)
Chris Lattner955fad12002-12-28 20:37:16 +0000308 if (sz >= size || sz >= target.getTargetData().getDoubleAlignment())
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000309 return sz;
310}
311
312
Chris Lattner955fad12002-12-28 20:37:16 +0000313void MachineFunctionInfo::CalculateArgSize() {
314 maxOptionalArgsSize = ComputeMaxOptionalArgsSize(MF.getTarget(),
315 MF.getFunction(),
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000316 maxOptionalNumArgs);
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000317 staticStackSize = maxOptionalArgsSize
Chris Lattner955fad12002-12-28 20:37:16 +0000318 + MF.getTarget().getFrameInfo().getMinStackFrameSize();
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000319}
320
321int
Chris Lattner955fad12002-12-28 20:37:16 +0000322MachineFunctionInfo::computeOffsetforLocalVar(const Value* val,
323 unsigned &getPaddedSize,
324 unsigned sizeToUse)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000325{
Vikram S. Advee4e4d4e2002-03-24 03:39:26 +0000326 if (sizeToUse == 0)
Chris Lattner955fad12002-12-28 20:37:16 +0000327 sizeToUse = MF.getTarget().findOptimalStorageSize(val->getType());
328 unsigned align = SizeToAlignment(sizeToUse, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000329
330 bool growUp;
Chris Lattner955fad12002-12-28 20:37:16 +0000331 int firstOffset = MF.getTarget().getFrameInfo().getFirstAutomaticVarOffset(MF,
332 growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000333 int offset = growUp? firstOffset + getAutomaticVarsSize()
334 : firstOffset - (getAutomaticVarsSize() + sizeToUse);
335
Chris Lattner955fad12002-12-28 20:37:16 +0000336 int aligned = MF.getTarget().getFrameInfo().adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000337 getPaddedSize = sizeToUse + abs(aligned - offset);
338
339 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000340}
341
342int
Chris Lattner955fad12002-12-28 20:37:16 +0000343MachineFunctionInfo::allocateLocalVar(const Value* val,
344 unsigned sizeToUse)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000345{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000346 assert(! automaticVarsAreaFrozen &&
347 "Size of auto vars area has been used to compute an offset so "
348 "no more automatic vars should be allocated!");
349
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000350 // Check if we've allocated a stack slot for this value already
351 //
352 int offset = getOffset(val);
353 if (offset == INVALID_FRAME_OFFSET)
354 {
Chris Lattner955fad12002-12-28 20:37:16 +0000355 unsigned getPaddedSize;
356 offset = computeOffsetforLocalVar(val, getPaddedSize, sizeToUse);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000357 offsets[val] = offset;
Vikram S. Advee4e4d4e2002-03-24 03:39:26 +0000358 incrementAutomaticVarsSize(getPaddedSize);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000359 }
360 return offset;
361}
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000362
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000363int
Chris Lattner955fad12002-12-28 20:37:16 +0000364MachineFunctionInfo::allocateSpilledValue(const Type* type)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000365{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000366 assert(! spillsAreaFrozen &&
367 "Size of reg spills area has been used to compute an offset so "
368 "no more register spill slots should be allocated!");
369
Chris Lattner955fad12002-12-28 20:37:16 +0000370 unsigned size = MF.getTarget().getTargetData().getTypeSize(type);
371 unsigned char align = MF.getTarget().getTargetData().getTypeAlignment(type);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000372
373 bool growUp;
Chris Lattner955fad12002-12-28 20:37:16 +0000374 int firstOffset = MF.getTarget().getFrameInfo().getRegSpillAreaOffset(MF, growUp);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000375
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000376 int offset = growUp? firstOffset + getRegSpillsSize()
377 : firstOffset - (getRegSpillsSize() + size);
378
Chris Lattner955fad12002-12-28 20:37:16 +0000379 int aligned = MF.getTarget().getFrameInfo().adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000380 size += abs(aligned - offset); // include alignment padding in size
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000381
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000382 incrementRegSpillsSize(size); // update size of reg. spills area
383
384 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000385}
386
387int
Chris Lattner955fad12002-12-28 20:37:16 +0000388MachineFunctionInfo::pushTempValue(unsigned size)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000389{
Chris Lattner955fad12002-12-28 20:37:16 +0000390 unsigned align = SizeToAlignment(size, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000391
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000392 bool growUp;
Chris Lattner955fad12002-12-28 20:37:16 +0000393 int firstOffset = MF.getTarget().getFrameInfo().getTmpAreaOffset(MF, growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000394
395 int offset = growUp? firstOffset + currentTmpValuesSize
396 : firstOffset - (currentTmpValuesSize + size);
397
Chris Lattner955fad12002-12-28 20:37:16 +0000398 int aligned = MF.getTarget().getFrameInfo().adjustAlignment(offset, growUp,
399 align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000400 size += abs(aligned - offset); // include alignment padding in size
401
402 incrementTmpAreaSize(size); // update "current" size of tmp area
403
404 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000405}
406
Chris Lattner955fad12002-12-28 20:37:16 +0000407void MachineFunctionInfo::popAllTempValues() {
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000408 resetTmpAreaSize(); // clear tmp area to reuse
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000409}
410
411int
Chris Lattner955fad12002-12-28 20:37:16 +0000412MachineFunctionInfo::getOffset(const Value* val) const
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000413{
Chris Lattner09ff1122002-07-24 21:21:32 +0000414 hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
Chris Lattner6b944532002-10-28 01:16:38 +0000415 return (pair == offsets.end()) ? INVALID_FRAME_OFFSET : pair->second;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000416}