blob: 4dfd7f77826d76dcb2aa1eeae51ab78443b4fad1 [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 Lattner16c45e92003-12-20 10:20:58 +000016#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattner831fdcf2002-12-25 05:03:22 +000017#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner831fdcf2002-12-25 05:03:22 +000018#include "llvm/CodeGen/SSARegMap.h"
Chris Lattner955fad12002-12-28 20:37:16 +000019#include "llvm/CodeGen/MachineFunctionInfo.h"
Chris Lattnereb24db92002-12-28 21:08:26 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner4d149cd2003-01-13 00:23:03 +000021#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattner16c45e92003-12-20 10:20:58 +000022#include "llvm/CodeGen/Passes.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 Lattner2fbfdcf2002-04-07 20:49:59 +000025#include "llvm/Function.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000026#include "llvm/iOther.h"
Chris Lattner62d6ad22004-06-02 05:56:52 +000027#include "llvm/Type.h"
Tanya Lattner792699c2004-05-24 06:11:51 +000028#include "Support/LeakDetector.h"
29
Chris Lattner07f32d42003-12-20 09:17:07 +000030using namespace llvm;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000031
Chris Lattnere316efc2002-10-29 23:18:43 +000032static AnnotationID MF_AID(
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000033 AnnotationManager::getID("CodeGen::MachineCodeForFunction"));
Chris Lattnerf2868ce2002-02-03 07:54:50 +000034
Chris Lattner227c3d32002-10-28 01:12:41 +000035
Chris Lattner227c3d32002-10-28 01:12:41 +000036namespace {
Chris Lattner16c45e92003-12-20 10:20:58 +000037 struct Printer : public MachineFunctionPass {
Brian Gaeke09caa372004-01-30 21:53:46 +000038 std::ostream *OS;
Chris Lattnerd4baf0f2004-02-01 05:25:07 +000039 const std::string Banner;
Brian Gaeke09caa372004-01-30 21:53:46 +000040
41 Printer (std::ostream *_OS, const std::string &_Banner) :
42 OS (_OS), Banner (_Banner) { }
43
Chris Lattner10491642002-10-30 00:48:05 +000044 const char *getPassName() const { return "MachineFunction Printer"; }
45
46 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
47 AU.setPreservesAll();
48 }
49
Chris Lattner16c45e92003-12-20 10:20:58 +000050 bool runOnMachineFunction(MachineFunction &MF) {
Brian Gaeke09caa372004-01-30 21:53:46 +000051 (*OS) << Banner;
52 MF.print (*OS);
Chris Lattner10491642002-10-30 00:48:05 +000053 return false;
54 }
55 };
Chris Lattner227c3d32002-10-28 01:12:41 +000056}
57
Brian Gaeke09caa372004-01-30 21:53:46 +000058/// Returns a newly-created MachineFunction Printer pass. The default output
59/// stream is std::cerr; the default banner is empty.
60///
61FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS,
62 const std::string &Banner) {
63 return new Printer(OS, Banner);
Chris Lattner10491642002-10-30 00:48:05 +000064}
65
Alkis Evlogimenosc81efdc2004-02-15 00:03:15 +000066namespace {
67 struct Deleter : public MachineFunctionPass {
68 const char *getPassName() const { return "Machine Code Deleter"; }
69
70 bool runOnMachineFunction(MachineFunction &MF) {
71 // Delete the annotation from the function now.
72 MachineFunction::destruct(MF.getFunction());
73 return true;
74 }
75 };
76}
77
78/// MachineCodeDeletion Pass - This pass deletes all of the machine code for
79/// the current function, which should happen after the function has been
80/// emitted to a .s file or to memory.
81FunctionPass *llvm::createMachineCodeDeleter() {
82 return new Deleter();
83}
84
85
86
Chris Lattner227c3d32002-10-28 01:12:41 +000087//===---------------------------------------------------------------------===//
88// MachineFunction implementation
89//===---------------------------------------------------------------------===//
Tanya Lattner792699c2004-05-24 06:11:51 +000090MachineBasicBlock* ilist_traits<MachineBasicBlock>::createNode()
91{
92 MachineBasicBlock* dummy = new MachineBasicBlock();
93 LeakDetector::removeGarbageObject(dummy);
94 return dummy;
95}
96
97void ilist_traits<MachineBasicBlock>::transferNodesFromList(
98 iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
99 ilist_iterator<MachineBasicBlock> first,
100 ilist_iterator<MachineBasicBlock> last)
101{
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000102 if (Parent != toList.Parent)
Tanya Lattner792699c2004-05-24 06:11:51 +0000103 for (; first != last; ++first)
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000104 first->Parent = toList.Parent;
Tanya Lattner792699c2004-05-24 06:11:51 +0000105}
Chris Lattner227c3d32002-10-28 01:12:41 +0000106
Chris Lattner10491642002-10-30 00:48:05 +0000107MachineFunction::MachineFunction(const Function *F,
Chris Lattner955fad12002-12-28 20:37:16 +0000108 const TargetMachine &TM)
Brian Gaeked657c422004-05-12 21:35:23 +0000109 : Annotation(MF_AID), Fn(F), Target(TM), NextMBBNumber(0) {
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();
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000114 BasicBlocks.Parent = this;
Chris Lattner831fdcf2002-12-25 05:03:22 +0000115}
116
117MachineFunction::~MachineFunction() {
118 delete SSARegMapping;
Chris Lattner955fad12002-12-28 20:37:16 +0000119 delete MFInfo;
120 delete FrameInfo;
Chris Lattner4d149cd2003-01-13 00:23:03 +0000121 delete ConstantPool;
Chris Lattner10491642002-10-30 00:48:05 +0000122}
123
124void MachineFunction::dump() const { print(std::cerr); }
125
126void MachineFunction::print(std::ostream &OS) const {
Brian Gaeke47b71642004-03-29 21:58:31 +0000127 OS << "# Machine code for " << Fn->getName () << "():\n";
Chris Lattner955fad12002-12-28 20:37:16 +0000128
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
Brian Gaeke90421cd2004-02-13 04:39:55 +0000135 for (const_iterator BB = begin(); BB != end(); ++BB)
136 BB->print(OS);
Brian Gaeke47b71642004-03-29 21:58:31 +0000137
138 OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
Chris Lattner10491642002-10-30 00:48:05 +0000139}
140
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000141// The next two methods are used to construct and to retrieve
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000142// the MachineCodeForFunction object for the given function.
143// construct() -- Allocates and initializes for a given function and target
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000144// get() -- Returns a handle to the object.
145// This should not be called before "construct()"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000146// for a given Function.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000147//
Misha Brukmanfce11432002-10-28 00:28:31 +0000148MachineFunction&
Chris Lattner335d5c32002-10-28 05:58:46 +0000149MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000150{
Chris Lattnere316efc2002-10-29 23:18:43 +0000151 assert(Fn->getAnnotation(MF_AID) == 0 &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000152 "Object already exists for this function!");
Chris Lattner335d5c32002-10-28 05:58:46 +0000153 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
154 Fn->addAnnotation(mcInfo);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000155 return *mcInfo;
156}
157
Chris Lattner16c45e92003-12-20 10:20:58 +0000158void MachineFunction::destruct(const Function *Fn) {
Chris Lattnere316efc2002-10-29 23:18:43 +0000159 bool Deleted = Fn->deleteAnnotation(MF_AID);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000160 assert(Deleted && "Machine code did not exist for function!");
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000161}
162
Chris Lattner335d5c32002-10-28 05:58:46 +0000163MachineFunction& MachineFunction::get(const Function *F)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000164{
Chris Lattnere316efc2002-10-29 23:18:43 +0000165 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000166 assert(mc && "Call construct() method first to allocate the object");
167 return *mc;
168}
169
Chris Lattner831fdcf2002-12-25 05:03:22 +0000170void MachineFunction::clearSSARegMap() {
171 delete SSARegMapping;
172 SSARegMapping = 0;
173}
174
Chris Lattner955fad12002-12-28 20:37:16 +0000175//===----------------------------------------------------------------------===//
Chris Lattnereb24db92002-12-28 21:08:26 +0000176// MachineFrameInfo implementation
Chris Lattner955fad12002-12-28 20:37:16 +0000177//===----------------------------------------------------------------------===//
178
Chris Lattner4d149cd2003-01-13 00:23:03 +0000179/// CreateStackObject - Create a stack object for a value of the specified type.
180///
181int MachineFrameInfo::CreateStackObject(const Type *Ty, const TargetData &TD) {
182 return CreateStackObject(TD.getTypeSize(Ty), TD.getTypeAlignment(Ty));
183}
184
185int MachineFrameInfo::CreateStackObject(const TargetRegisterClass *RC) {
186 return CreateStackObject(RC->getSize(), RC->getAlignment());
187}
188
189
Chris Lattner9085d8a2003-01-16 18:35:57 +0000190void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000191 int ValOffset = MF.getTarget().getFrameInfo()->getOffsetOfLocalArea();
Chris Lattner9085d8a2003-01-16 18:35:57 +0000192
Chris Lattner955fad12002-12-28 20:37:16 +0000193 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
194 const StackObject &SO = Objects[i];
Chris Lattner4d149cd2003-01-13 00:23:03 +0000195 OS << " <fi #" << (int)(i-NumFixedObjects) << "> is ";
Chris Lattner955fad12002-12-28 20:37:16 +0000196 if (SO.Size == 0)
197 OS << "variable sized";
198 else
199 OS << SO.Size << " byte" << (SO.Size != 1 ? "s" : " ");
200
201 if (i < NumFixedObjects)
202 OS << " fixed";
203 if (i < NumFixedObjects || SO.SPOffset != -1) {
Chris Lattner7f7bbc22004-06-11 06:37:11 +0000204 int Off = SO.SPOffset - ValOffset;
Chris Lattner955fad12002-12-28 20:37:16 +0000205 OS << " at location [SP";
Chris Lattner9085d8a2003-01-16 18:35:57 +0000206 if (Off > 0)
207 OS << "+" << Off;
208 else if (Off < 0)
209 OS << Off;
Chris Lattner955fad12002-12-28 20:37:16 +0000210 OS << "]";
211 }
212 OS << "\n";
213 }
214
215 if (HasVarSizedObjects)
216 OS << " Stack frame contains variable sized objects\n";
217}
218
Chris Lattner9085d8a2003-01-16 18:35:57 +0000219void MachineFrameInfo::dump(const MachineFunction &MF) const {
220 print(MF, std::cerr);
221}
Chris Lattner955fad12002-12-28 20:37:16 +0000222
223
224//===----------------------------------------------------------------------===//
Chris Lattner4d149cd2003-01-13 00:23:03 +0000225// MachineConstantPool implementation
226//===----------------------------------------------------------------------===//
227
228void MachineConstantPool::print(std::ostream &OS) const {
229 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
230 OS << " <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
231}
232
233void MachineConstantPool::dump() const { print(std::cerr); }
234
235//===----------------------------------------------------------------------===//
Chris Lattner955fad12002-12-28 20:37:16 +0000236// MachineFunctionInfo implementation
237//===----------------------------------------------------------------------===//
Chris Lattner831fdcf2002-12-25 05:03:22 +0000238
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000239static unsigned
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000240ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F,
241 unsigned &maxOptionalNumArgs)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000242{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000243 const TargetFrameInfo &frameInfo = *target.getFrameInfo();
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000244
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000245 unsigned maxSize = 0;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000246
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000247 for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB)
248 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Chris Lattner2ee82e02003-04-23 16:36:11 +0000249 if (const CallInst *callInst = dyn_cast<CallInst>(I))
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000250 {
251 unsigned numOperands = callInst->getNumOperands() - 1;
252 int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();
253 if (numExtra <= 0)
254 continue;
255
Chris Lattner955fad12002-12-28 20:37:16 +0000256 unsigned sizeForThisCall;
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000257 if (frameInfo.argsOnStackHaveFixedSize())
258 {
259 int argSize = frameInfo.getSizeOfEachArgOnStack();
260 sizeForThisCall = numExtra * (unsigned) argSize;
261 }
262 else
263 {
264 assert(0 && "UNTESTED CODE: Size per stack argument is not "
265 "fixed on this architecture: use actual arg sizes to "
266 "compute MaxOptionalArgsSize");
267 sizeForThisCall = 0;
268 for (unsigned i = 0; i < numOperands; ++i)
Chris Lattner955fad12002-12-28 20:37:16 +0000269 sizeForThisCall += target.getTargetData().getTypeSize(callInst->
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000270 getOperand(i)->getType());
271 }
272
273 if (maxSize < sizeForThisCall)
274 maxSize = sizeForThisCall;
275
276 if ((int)maxOptionalNumArgs < numExtra)
277 maxOptionalNumArgs = (unsigned) numExtra;
278 }
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000279
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000280 return maxSize;
281}
282
283// Align data larger than one L1 cache line on L1 cache line boundaries.
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000284// Align all smaller data on the next higher 2^x boundary (4, 8, ...),
285// but not higher than the alignment of the largest type we support
286// (currently a double word). -- see class TargetData).
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000287//
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000288// This function is similar to the corresponding function in EmitAssembly.cpp
289// but they are unrelated. This one does not align at more than a
290// double-word boundary whereas that one might.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000291//
Chris Lattner955fad12002-12-28 20:37:16 +0000292inline unsigned
293SizeToAlignment(unsigned size, const TargetMachine& target)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000294{
Brian Gaeke05b15fb2004-03-01 06:43:29 +0000295 const unsigned short cacheLineSize = 16;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000296 if (size > (unsigned) cacheLineSize / 2)
297 return cacheLineSize;
298 else
299 for (unsigned sz=1; /*no condition*/; sz *= 2)
Chris Lattner955fad12002-12-28 20:37:16 +0000300 if (sz >= size || sz >= target.getTargetData().getDoubleAlignment())
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000301 return sz;
302}
303
304
Chris Lattner955fad12002-12-28 20:37:16 +0000305void MachineFunctionInfo::CalculateArgSize() {
306 maxOptionalArgsSize = ComputeMaxOptionalArgsSize(MF.getTarget(),
307 MF.getFunction(),
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000308 maxOptionalNumArgs);
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000309 staticStackSize = maxOptionalArgsSize
Chris Lattner62d6ad22004-06-02 05:56:52 +0000310 + MF.getTarget().getFrameInfo()->getMinStackFrameSize();
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000311}
312
313int
Chris Lattner955fad12002-12-28 20:37:16 +0000314MachineFunctionInfo::computeOffsetforLocalVar(const Value* val,
315 unsigned &getPaddedSize,
316 unsigned sizeToUse)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000317{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000318 if (sizeToUse == 0) {
319 // All integer types smaller than ints promote to 4 byte integers.
320 if (val->getType()->isIntegral() && val->getType()->getPrimitiveSize() < 4)
321 sizeToUse = 4;
322 else
323 sizeToUse = MF.getTarget().getTargetData().getTypeSize(val->getType());
324 }
Chris Lattner955fad12002-12-28 20:37:16 +0000325 unsigned align = SizeToAlignment(sizeToUse, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000326
327 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000328 int firstOffset = MF.getTarget().getFrameInfo()->getFirstAutomaticVarOffset(MF,
329 growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000330 int offset = growUp? firstOffset + getAutomaticVarsSize()
331 : firstOffset - (getAutomaticVarsSize() + sizeToUse);
332
Chris Lattner62d6ad22004-06-02 05:56:52 +0000333 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000334 getPaddedSize = sizeToUse + abs(aligned - offset);
335
336 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000337}
338
Chris Lattner07f32d42003-12-20 09:17:07 +0000339
340int MachineFunctionInfo::allocateLocalVar(const Value* val,
341 unsigned sizeToUse) {
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000342 assert(! automaticVarsAreaFrozen &&
343 "Size of auto vars area has been used to compute an offset so "
344 "no more automatic vars should be allocated!");
345
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000346 // Check if we've allocated a stack slot for this value already
347 //
Chris Lattner07f32d42003-12-20 09:17:07 +0000348 hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
349 if (pair != offsets.end())
350 return pair->second;
351
352 unsigned getPaddedSize;
353 unsigned offset = computeOffsetforLocalVar(val, getPaddedSize, sizeToUse);
354 offsets[val] = offset;
355 incrementAutomaticVarsSize(getPaddedSize);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000356 return offset;
357}
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000358
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000359int
Chris Lattner955fad12002-12-28 20:37:16 +0000360MachineFunctionInfo::allocateSpilledValue(const Type* type)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000361{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000362 assert(! spillsAreaFrozen &&
363 "Size of reg spills area has been used to compute an offset so "
364 "no more register spill slots should be allocated!");
365
Chris Lattner955fad12002-12-28 20:37:16 +0000366 unsigned size = MF.getTarget().getTargetData().getTypeSize(type);
367 unsigned char align = MF.getTarget().getTargetData().getTypeAlignment(type);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000368
369 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000370 int firstOffset = MF.getTarget().getFrameInfo()->getRegSpillAreaOffset(MF, growUp);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000371
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000372 int offset = growUp? firstOffset + getRegSpillsSize()
373 : firstOffset - (getRegSpillsSize() + size);
374
Chris Lattner62d6ad22004-06-02 05:56:52 +0000375 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000376 size += abs(aligned - offset); // include alignment padding in size
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000377
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000378 incrementRegSpillsSize(size); // update size of reg. spills area
379
380 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000381}
382
383int
Chris Lattner955fad12002-12-28 20:37:16 +0000384MachineFunctionInfo::pushTempValue(unsigned size)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000385{
Chris Lattner955fad12002-12-28 20:37:16 +0000386 unsigned align = SizeToAlignment(size, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000387
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000388 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000389 int firstOffset = MF.getTarget().getFrameInfo()->getTmpAreaOffset(MF, growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000390
391 int offset = growUp? firstOffset + currentTmpValuesSize
392 : firstOffset - (currentTmpValuesSize + size);
393
Chris Lattner62d6ad22004-06-02 05:56:52 +0000394 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp,
Chris Lattner955fad12002-12-28 20:37:16 +0000395 align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000396 size += abs(aligned - offset); // include alignment padding in size
397
398 incrementTmpAreaSize(size); // update "current" size of tmp area
399
400 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000401}
402
Chris Lattner955fad12002-12-28 20:37:16 +0000403void MachineFunctionInfo::popAllTempValues() {
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000404 resetTmpAreaSize(); // clear tmp area to reuse
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000405}
406