blob: f9b8bbbd12fe6c3f98415b2be434f1ee492a3c1f [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)
Chris Lattner51289aa2004-07-01 06:02:07 +0000109 : 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();
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000114 BasicBlocks.Parent = this;
Chris Lattner831fdcf2002-12-25 05:03:22 +0000115}
116
117MachineFunction::~MachineFunction() {
Chris Lattner4b9a4002004-07-01 06:29:07 +0000118 BasicBlocks.clear();
Chris Lattner831fdcf2002-12-25 05:03:22 +0000119 delete SSARegMapping;
Chris Lattner955fad12002-12-28 20:37:16 +0000120 delete MFInfo;
121 delete FrameInfo;
Chris Lattner4d149cd2003-01-13 00:23:03 +0000122 delete ConstantPool;
Chris Lattner10491642002-10-30 00:48:05 +0000123}
124
125void MachineFunction::dump() const { print(std::cerr); }
126
127void MachineFunction::print(std::ostream &OS) const {
Brian Gaeke47b71642004-03-29 21:58:31 +0000128 OS << "# Machine code for " << Fn->getName () << "():\n";
Chris Lattner955fad12002-12-28 20:37:16 +0000129
130 // Print Frame Information
Chris Lattner9085d8a2003-01-16 18:35:57 +0000131 getFrameInfo()->print(*this, OS);
Chris Lattner4d149cd2003-01-13 00:23:03 +0000132
133 // Print Constant Pool
134 getConstantPool()->print(OS);
Chris Lattner10491642002-10-30 00:48:05 +0000135
Brian Gaeke90421cd2004-02-13 04:39:55 +0000136 for (const_iterator BB = begin(); BB != end(); ++BB)
137 BB->print(OS);
Brian Gaeke47b71642004-03-29 21:58:31 +0000138
139 OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
Chris Lattner10491642002-10-30 00:48:05 +0000140}
141
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000142// The next two methods are used to construct and to retrieve
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000143// the MachineCodeForFunction object for the given function.
144// construct() -- Allocates and initializes for a given function and target
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000145// get() -- Returns a handle to the object.
146// This should not be called before "construct()"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000147// for a given Function.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000148//
Misha Brukmanfce11432002-10-28 00:28:31 +0000149MachineFunction&
Chris Lattner335d5c32002-10-28 05:58:46 +0000150MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000151{
Chris Lattnere316efc2002-10-29 23:18:43 +0000152 assert(Fn->getAnnotation(MF_AID) == 0 &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000153 "Object already exists for this function!");
Chris Lattner335d5c32002-10-28 05:58:46 +0000154 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
155 Fn->addAnnotation(mcInfo);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000156 return *mcInfo;
157}
158
Chris Lattner16c45e92003-12-20 10:20:58 +0000159void MachineFunction::destruct(const Function *Fn) {
Chris Lattnere316efc2002-10-29 23:18:43 +0000160 bool Deleted = Fn->deleteAnnotation(MF_AID);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000161 assert(Deleted && "Machine code did not exist for function!");
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000162}
163
Chris Lattner335d5c32002-10-28 05:58:46 +0000164MachineFunction& MachineFunction::get(const Function *F)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000165{
Chris Lattnere316efc2002-10-29 23:18:43 +0000166 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000167 assert(mc && "Call construct() method first to allocate the object");
168 return *mc;
169}
170
Chris Lattner831fdcf2002-12-25 05:03:22 +0000171void MachineFunction::clearSSARegMap() {
172 delete SSARegMapping;
173 SSARegMapping = 0;
174}
175
Chris Lattner955fad12002-12-28 20:37:16 +0000176//===----------------------------------------------------------------------===//
Chris Lattnereb24db92002-12-28 21:08:26 +0000177// MachineFrameInfo implementation
Chris Lattner955fad12002-12-28 20:37:16 +0000178//===----------------------------------------------------------------------===//
179
Chris Lattner4d149cd2003-01-13 00:23:03 +0000180/// CreateStackObject - Create a stack object for a value of the specified type.
181///
182int MachineFrameInfo::CreateStackObject(const Type *Ty, const TargetData &TD) {
183 return CreateStackObject(TD.getTypeSize(Ty), TD.getTypeAlignment(Ty));
184}
185
186int MachineFrameInfo::CreateStackObject(const TargetRegisterClass *RC) {
187 return CreateStackObject(RC->getSize(), RC->getAlignment());
188}
189
190
Chris Lattner9085d8a2003-01-16 18:35:57 +0000191void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000192 int ValOffset = MF.getTarget().getFrameInfo()->getOffsetOfLocalArea();
Chris Lattner9085d8a2003-01-16 18:35:57 +0000193
Chris Lattner955fad12002-12-28 20:37:16 +0000194 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
195 const StackObject &SO = Objects[i];
Chris Lattner4d149cd2003-01-13 00:23:03 +0000196 OS << " <fi #" << (int)(i-NumFixedObjects) << "> is ";
Chris Lattner955fad12002-12-28 20:37:16 +0000197 if (SO.Size == 0)
198 OS << "variable sized";
199 else
200 OS << SO.Size << " byte" << (SO.Size != 1 ? "s" : " ");
201
202 if (i < NumFixedObjects)
203 OS << " fixed";
204 if (i < NumFixedObjects || SO.SPOffset != -1) {
Chris Lattner7f7bbc22004-06-11 06:37:11 +0000205 int Off = SO.SPOffset - ValOffset;
Chris Lattner955fad12002-12-28 20:37:16 +0000206 OS << " at location [SP";
Chris Lattner9085d8a2003-01-16 18:35:57 +0000207 if (Off > 0)
208 OS << "+" << Off;
209 else if (Off < 0)
210 OS << Off;
Chris Lattner955fad12002-12-28 20:37:16 +0000211 OS << "]";
212 }
213 OS << "\n";
214 }
215
216 if (HasVarSizedObjects)
217 OS << " Stack frame contains variable sized objects\n";
218}
219
Chris Lattner9085d8a2003-01-16 18:35:57 +0000220void MachineFrameInfo::dump(const MachineFunction &MF) const {
221 print(MF, std::cerr);
222}
Chris Lattner955fad12002-12-28 20:37:16 +0000223
224
225//===----------------------------------------------------------------------===//
Chris Lattner4d149cd2003-01-13 00:23:03 +0000226// MachineConstantPool implementation
227//===----------------------------------------------------------------------===//
228
229void MachineConstantPool::print(std::ostream &OS) const {
230 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
231 OS << " <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
232}
233
234void MachineConstantPool::dump() const { print(std::cerr); }
235
236//===----------------------------------------------------------------------===//
Chris Lattner955fad12002-12-28 20:37:16 +0000237// MachineFunctionInfo implementation
238//===----------------------------------------------------------------------===//
Chris Lattner831fdcf2002-12-25 05:03:22 +0000239
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000240static unsigned
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000241ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F,
242 unsigned &maxOptionalNumArgs)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000243{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000244 const TargetFrameInfo &frameInfo = *target.getFrameInfo();
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000245
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000246 unsigned maxSize = 0;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000247
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000248 for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB)
249 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Chris Lattner2ee82e02003-04-23 16:36:11 +0000250 if (const CallInst *callInst = dyn_cast<CallInst>(I))
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000251 {
252 unsigned numOperands = callInst->getNumOperands() - 1;
253 int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();
254 if (numExtra <= 0)
255 continue;
256
Chris Lattner955fad12002-12-28 20:37:16 +0000257 unsigned sizeForThisCall;
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000258 if (frameInfo.argsOnStackHaveFixedSize())
259 {
260 int argSize = frameInfo.getSizeOfEachArgOnStack();
261 sizeForThisCall = numExtra * (unsigned) argSize;
262 }
263 else
264 {
265 assert(0 && "UNTESTED CODE: Size per stack argument is not "
266 "fixed on this architecture: use actual arg sizes to "
267 "compute MaxOptionalArgsSize");
268 sizeForThisCall = 0;
269 for (unsigned i = 0; i < numOperands; ++i)
Chris Lattner955fad12002-12-28 20:37:16 +0000270 sizeForThisCall += target.getTargetData().getTypeSize(callInst->
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000271 getOperand(i)->getType());
272 }
273
274 if (maxSize < sizeForThisCall)
275 maxSize = sizeForThisCall;
276
277 if ((int)maxOptionalNumArgs < numExtra)
278 maxOptionalNumArgs = (unsigned) numExtra;
279 }
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000280
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000281 return maxSize;
282}
283
284// Align data larger than one L1 cache line on L1 cache line boundaries.
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000285// Align all smaller data on the next higher 2^x boundary (4, 8, ...),
286// but not higher than the alignment of the largest type we support
287// (currently a double word). -- see class TargetData).
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000288//
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000289// This function is similar to the corresponding function in EmitAssembly.cpp
290// but they are unrelated. This one does not align at more than a
291// double-word boundary whereas that one might.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000292//
Chris Lattner955fad12002-12-28 20:37:16 +0000293inline unsigned
294SizeToAlignment(unsigned size, const TargetMachine& target)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000295{
Brian Gaeke05b15fb2004-03-01 06:43:29 +0000296 const unsigned short cacheLineSize = 16;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000297 if (size > (unsigned) cacheLineSize / 2)
298 return cacheLineSize;
299 else
300 for (unsigned sz=1; /*no condition*/; sz *= 2)
Chris Lattner955fad12002-12-28 20:37:16 +0000301 if (sz >= size || sz >= target.getTargetData().getDoubleAlignment())
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000302 return sz;
303}
304
305
Chris Lattner955fad12002-12-28 20:37:16 +0000306void MachineFunctionInfo::CalculateArgSize() {
307 maxOptionalArgsSize = ComputeMaxOptionalArgsSize(MF.getTarget(),
308 MF.getFunction(),
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000309 maxOptionalNumArgs);
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000310 staticStackSize = maxOptionalArgsSize
Chris Lattner62d6ad22004-06-02 05:56:52 +0000311 + MF.getTarget().getFrameInfo()->getMinStackFrameSize();
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000312}
313
314int
Chris Lattner955fad12002-12-28 20:37:16 +0000315MachineFunctionInfo::computeOffsetforLocalVar(const Value* val,
316 unsigned &getPaddedSize,
317 unsigned sizeToUse)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000318{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000319 if (sizeToUse == 0) {
320 // All integer types smaller than ints promote to 4 byte integers.
321 if (val->getType()->isIntegral() && val->getType()->getPrimitiveSize() < 4)
322 sizeToUse = 4;
323 else
324 sizeToUse = MF.getTarget().getTargetData().getTypeSize(val->getType());
325 }
Chris Lattner955fad12002-12-28 20:37:16 +0000326 unsigned align = SizeToAlignment(sizeToUse, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000327
328 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000329 int firstOffset = MF.getTarget().getFrameInfo()->getFirstAutomaticVarOffset(MF,
330 growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000331 int offset = growUp? firstOffset + getAutomaticVarsSize()
332 : firstOffset - (getAutomaticVarsSize() + sizeToUse);
333
Chris Lattner62d6ad22004-06-02 05:56:52 +0000334 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000335 getPaddedSize = sizeToUse + abs(aligned - offset);
336
337 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000338}
339
Chris Lattner07f32d42003-12-20 09:17:07 +0000340
341int MachineFunctionInfo::allocateLocalVar(const Value* val,
342 unsigned sizeToUse) {
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000343 assert(! automaticVarsAreaFrozen &&
344 "Size of auto vars area has been used to compute an offset so "
345 "no more automatic vars should be allocated!");
346
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000347 // Check if we've allocated a stack slot for this value already
348 //
Chris Lattner07f32d42003-12-20 09:17:07 +0000349 hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
350 if (pair != offsets.end())
351 return pair->second;
352
353 unsigned getPaddedSize;
354 unsigned offset = computeOffsetforLocalVar(val, getPaddedSize, sizeToUse);
355 offsets[val] = offset;
356 incrementAutomaticVarsSize(getPaddedSize);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000357 return offset;
358}
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000359
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000360int
Chris Lattner955fad12002-12-28 20:37:16 +0000361MachineFunctionInfo::allocateSpilledValue(const Type* type)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000362{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000363 assert(! spillsAreaFrozen &&
364 "Size of reg spills area has been used to compute an offset so "
365 "no more register spill slots should be allocated!");
366
Chris Lattner955fad12002-12-28 20:37:16 +0000367 unsigned size = MF.getTarget().getTargetData().getTypeSize(type);
368 unsigned char align = MF.getTarget().getTargetData().getTypeAlignment(type);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000369
370 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000371 int firstOffset = MF.getTarget().getFrameInfo()->getRegSpillAreaOffset(MF, growUp);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000372
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000373 int offset = growUp? firstOffset + getRegSpillsSize()
374 : firstOffset - (getRegSpillsSize() + size);
375
Chris Lattner62d6ad22004-06-02 05:56:52 +0000376 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000377 size += abs(aligned - offset); // include alignment padding in size
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000378
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000379 incrementRegSpillsSize(size); // update size of reg. spills area
380
381 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000382}
383
384int
Chris Lattner955fad12002-12-28 20:37:16 +0000385MachineFunctionInfo::pushTempValue(unsigned size)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000386{
Chris Lattner955fad12002-12-28 20:37:16 +0000387 unsigned align = SizeToAlignment(size, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000388
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000389 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000390 int firstOffset = MF.getTarget().getFrameInfo()->getTmpAreaOffset(MF, growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000391
392 int offset = growUp? firstOffset + currentTmpValuesSize
393 : firstOffset - (currentTmpValuesSize + size);
394
Chris Lattner62d6ad22004-06-02 05:56:52 +0000395 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp,
Chris Lattner955fad12002-12-28 20:37:16 +0000396 align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000397 size += abs(aligned - offset); // include alignment padding in size
398
399 incrementTmpAreaSize(size); // update "current" size of tmp area
400
401 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000402}
403
Chris Lattner955fad12002-12-28 20:37:16 +0000404void MachineFunctionInfo::popAllTempValues() {
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000405 resetTmpAreaSize(); // clear tmp area to reuse
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000406}
407