blob: 520f1da960963641264e1aec1f004b2455f054b2 [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"
Reid Spencer954da372004-07-04 12:19:56 +000029#include <iostream>
Tanya Lattner792699c2004-05-24 06:11:51 +000030
Chris Lattner07f32d42003-12-20 09:17:07 +000031using namespace llvm;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000032
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
Chris Lattner227c3d32002-10-28 01:12:41 +000037namespace {
Chris Lattner16c45e92003-12-20 10:20:58 +000038 struct Printer : public MachineFunctionPass {
Brian Gaeke09caa372004-01-30 21:53:46 +000039 std::ostream *OS;
Chris Lattnerd4baf0f2004-02-01 05:25:07 +000040 const std::string Banner;
Brian Gaeke09caa372004-01-30 21:53:46 +000041
42 Printer (std::ostream *_OS, const std::string &_Banner) :
43 OS (_OS), Banner (_Banner) { }
44
Chris Lattner10491642002-10-30 00:48:05 +000045 const char *getPassName() const { return "MachineFunction Printer"; }
46
47 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
48 AU.setPreservesAll();
49 }
50
Chris Lattner16c45e92003-12-20 10:20:58 +000051 bool runOnMachineFunction(MachineFunction &MF) {
Brian Gaeke09caa372004-01-30 21:53:46 +000052 (*OS) << Banner;
53 MF.print (*OS);
Chris Lattner10491642002-10-30 00:48:05 +000054 return false;
55 }
56 };
Chris Lattner227c3d32002-10-28 01:12:41 +000057}
58
Brian Gaeke09caa372004-01-30 21:53:46 +000059/// Returns a newly-created MachineFunction Printer pass. The default output
60/// stream is std::cerr; the default banner is empty.
61///
62FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS,
63 const std::string &Banner) {
64 return new Printer(OS, Banner);
Chris Lattner10491642002-10-30 00:48:05 +000065}
66
Alkis Evlogimenosc81efdc2004-02-15 00:03:15 +000067namespace {
68 struct Deleter : public MachineFunctionPass {
69 const char *getPassName() const { return "Machine Code Deleter"; }
70
71 bool runOnMachineFunction(MachineFunction &MF) {
72 // Delete the annotation from the function now.
73 MachineFunction::destruct(MF.getFunction());
74 return true;
75 }
76 };
77}
78
79/// MachineCodeDeletion Pass - This pass deletes all of the machine code for
80/// the current function, which should happen after the function has been
81/// emitted to a .s file or to memory.
82FunctionPass *llvm::createMachineCodeDeleter() {
83 return new Deleter();
84}
85
86
87
Chris Lattner227c3d32002-10-28 01:12:41 +000088//===---------------------------------------------------------------------===//
89// MachineFunction implementation
90//===---------------------------------------------------------------------===//
Tanya Lattner792699c2004-05-24 06:11:51 +000091MachineBasicBlock* ilist_traits<MachineBasicBlock>::createNode()
92{
93 MachineBasicBlock* dummy = new MachineBasicBlock();
94 LeakDetector::removeGarbageObject(dummy);
95 return dummy;
96}
97
98void ilist_traits<MachineBasicBlock>::transferNodesFromList(
99 iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
100 ilist_iterator<MachineBasicBlock> first,
101 ilist_iterator<MachineBasicBlock> last)
102{
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000103 if (Parent != toList.Parent)
Tanya Lattner792699c2004-05-24 06:11:51 +0000104 for (; first != last; ++first)
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000105 first->Parent = toList.Parent;
Tanya Lattner792699c2004-05-24 06:11:51 +0000106}
Chris Lattner227c3d32002-10-28 01:12:41 +0000107
Chris Lattner10491642002-10-30 00:48:05 +0000108MachineFunction::MachineFunction(const Function *F,
Chris Lattner955fad12002-12-28 20:37:16 +0000109 const TargetMachine &TM)
Chris Lattner51289aa2004-07-01 06:02:07 +0000110 : Annotation(MF_AID), Fn(F), Target(TM) {
Misha Brukmanb7825bc2002-11-20 18:55:27 +0000111 SSARegMapping = new SSARegMap();
Chris Lattner955fad12002-12-28 20:37:16 +0000112 MFInfo = new MachineFunctionInfo(*this);
Chris Lattnereb24db92002-12-28 21:08:26 +0000113 FrameInfo = new MachineFrameInfo();
Chris Lattner4d149cd2003-01-13 00:23:03 +0000114 ConstantPool = new MachineConstantPool();
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000115 BasicBlocks.Parent = this;
Chris Lattner831fdcf2002-12-25 05:03:22 +0000116}
117
118MachineFunction::~MachineFunction() {
Chris Lattner4b9a4002004-07-01 06:29:07 +0000119 BasicBlocks.clear();
Chris Lattner831fdcf2002-12-25 05:03:22 +0000120 delete SSARegMapping;
Chris Lattner955fad12002-12-28 20:37:16 +0000121 delete MFInfo;
122 delete FrameInfo;
Chris Lattner4d149cd2003-01-13 00:23:03 +0000123 delete ConstantPool;
Chris Lattner10491642002-10-30 00:48:05 +0000124}
125
126void MachineFunction::dump() const { print(std::cerr); }
127
128void MachineFunction::print(std::ostream &OS) const {
Brian Gaeke47b71642004-03-29 21:58:31 +0000129 OS << "# Machine code for " << Fn->getName () << "():\n";
Chris Lattner955fad12002-12-28 20:37:16 +0000130
131 // Print Frame Information
Chris Lattner9085d8a2003-01-16 18:35:57 +0000132 getFrameInfo()->print(*this, OS);
Chris Lattner4d149cd2003-01-13 00:23:03 +0000133
134 // Print Constant Pool
135 getConstantPool()->print(OS);
Chris Lattner10491642002-10-30 00:48:05 +0000136
Brian Gaeke90421cd2004-02-13 04:39:55 +0000137 for (const_iterator BB = begin(); BB != end(); ++BB)
138 BB->print(OS);
Brian Gaeke47b71642004-03-29 21:58:31 +0000139
140 OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
Chris Lattner10491642002-10-30 00:48:05 +0000141}
142
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000143// The next two methods are used to construct and to retrieve
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000144// the MachineCodeForFunction object for the given function.
145// construct() -- Allocates and initializes for a given function and target
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000146// get() -- Returns a handle to the object.
147// This should not be called before "construct()"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000148// for a given Function.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000149//
Misha Brukmanfce11432002-10-28 00:28:31 +0000150MachineFunction&
Chris Lattner335d5c32002-10-28 05:58:46 +0000151MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000152{
Chris Lattnere316efc2002-10-29 23:18:43 +0000153 assert(Fn->getAnnotation(MF_AID) == 0 &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000154 "Object already exists for this function!");
Chris Lattner335d5c32002-10-28 05:58:46 +0000155 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
156 Fn->addAnnotation(mcInfo);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000157 return *mcInfo;
158}
159
Chris Lattner16c45e92003-12-20 10:20:58 +0000160void MachineFunction::destruct(const Function *Fn) {
Chris Lattnere316efc2002-10-29 23:18:43 +0000161 bool Deleted = Fn->deleteAnnotation(MF_AID);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000162 assert(Deleted && "Machine code did not exist for function!");
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000163}
164
Chris Lattner335d5c32002-10-28 05:58:46 +0000165MachineFunction& MachineFunction::get(const Function *F)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000166{
Chris Lattnere316efc2002-10-29 23:18:43 +0000167 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000168 assert(mc && "Call construct() method first to allocate the object");
169 return *mc;
170}
171
Chris Lattner831fdcf2002-12-25 05:03:22 +0000172void MachineFunction::clearSSARegMap() {
173 delete SSARegMapping;
174 SSARegMapping = 0;
175}
176
Chris Lattner955fad12002-12-28 20:37:16 +0000177//===----------------------------------------------------------------------===//
Chris Lattnereb24db92002-12-28 21:08:26 +0000178// MachineFrameInfo implementation
Chris Lattner955fad12002-12-28 20:37:16 +0000179//===----------------------------------------------------------------------===//
180
Chris Lattner4d149cd2003-01-13 00:23:03 +0000181/// CreateStackObject - Create a stack object for a value of the specified type.
182///
183int MachineFrameInfo::CreateStackObject(const Type *Ty, const TargetData &TD) {
184 return CreateStackObject(TD.getTypeSize(Ty), TD.getTypeAlignment(Ty));
185}
186
187int MachineFrameInfo::CreateStackObject(const TargetRegisterClass *RC) {
188 return CreateStackObject(RC->getSize(), RC->getAlignment());
189}
190
191
Chris Lattner9085d8a2003-01-16 18:35:57 +0000192void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000193 int ValOffset = MF.getTarget().getFrameInfo()->getOffsetOfLocalArea();
Chris Lattner9085d8a2003-01-16 18:35:57 +0000194
Chris Lattner955fad12002-12-28 20:37:16 +0000195 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
196 const StackObject &SO = Objects[i];
Chris Lattner4d149cd2003-01-13 00:23:03 +0000197 OS << " <fi #" << (int)(i-NumFixedObjects) << "> is ";
Chris Lattner955fad12002-12-28 20:37:16 +0000198 if (SO.Size == 0)
199 OS << "variable sized";
200 else
201 OS << SO.Size << " byte" << (SO.Size != 1 ? "s" : " ");
202
203 if (i < NumFixedObjects)
204 OS << " fixed";
205 if (i < NumFixedObjects || SO.SPOffset != -1) {
Chris Lattner7f7bbc22004-06-11 06:37:11 +0000206 int Off = SO.SPOffset - ValOffset;
Chris Lattner955fad12002-12-28 20:37:16 +0000207 OS << " at location [SP";
Chris Lattner9085d8a2003-01-16 18:35:57 +0000208 if (Off > 0)
209 OS << "+" << Off;
210 else if (Off < 0)
211 OS << Off;
Chris Lattner955fad12002-12-28 20:37:16 +0000212 OS << "]";
213 }
214 OS << "\n";
215 }
216
217 if (HasVarSizedObjects)
218 OS << " Stack frame contains variable sized objects\n";
219}
220
Chris Lattner9085d8a2003-01-16 18:35:57 +0000221void MachineFrameInfo::dump(const MachineFunction &MF) const {
222 print(MF, std::cerr);
223}
Chris Lattner955fad12002-12-28 20:37:16 +0000224
225
226//===----------------------------------------------------------------------===//
Chris Lattner4d149cd2003-01-13 00:23:03 +0000227// MachineConstantPool implementation
228//===----------------------------------------------------------------------===//
229
230void MachineConstantPool::print(std::ostream &OS) const {
231 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
232 OS << " <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
233}
234
235void MachineConstantPool::dump() const { print(std::cerr); }
236
237//===----------------------------------------------------------------------===//
Chris Lattner955fad12002-12-28 20:37:16 +0000238// MachineFunctionInfo implementation
239//===----------------------------------------------------------------------===//
Chris Lattner831fdcf2002-12-25 05:03:22 +0000240
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000241static unsigned
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000242ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F,
243 unsigned &maxOptionalNumArgs)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000244{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000245 const TargetFrameInfo &frameInfo = *target.getFrameInfo();
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000246
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000247 unsigned maxSize = 0;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000248
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000249 for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB)
250 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Chris Lattner2ee82e02003-04-23 16:36:11 +0000251 if (const CallInst *callInst = dyn_cast<CallInst>(I))
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000252 {
253 unsigned numOperands = callInst->getNumOperands() - 1;
254 int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();
255 if (numExtra <= 0)
256 continue;
257
Chris Lattner955fad12002-12-28 20:37:16 +0000258 unsigned sizeForThisCall;
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000259 if (frameInfo.argsOnStackHaveFixedSize())
260 {
261 int argSize = frameInfo.getSizeOfEachArgOnStack();
262 sizeForThisCall = numExtra * (unsigned) argSize;
263 }
264 else
265 {
266 assert(0 && "UNTESTED CODE: Size per stack argument is not "
267 "fixed on this architecture: use actual arg sizes to "
268 "compute MaxOptionalArgsSize");
269 sizeForThisCall = 0;
270 for (unsigned i = 0; i < numOperands; ++i)
Chris Lattner955fad12002-12-28 20:37:16 +0000271 sizeForThisCall += target.getTargetData().getTypeSize(callInst->
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000272 getOperand(i)->getType());
273 }
274
275 if (maxSize < sizeForThisCall)
276 maxSize = sizeForThisCall;
277
278 if ((int)maxOptionalNumArgs < numExtra)
279 maxOptionalNumArgs = (unsigned) numExtra;
280 }
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000281
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000282 return maxSize;
283}
284
285// Align data larger than one L1 cache line on L1 cache line boundaries.
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000286// Align all smaller data on the next higher 2^x boundary (4, 8, ...),
287// but not higher than the alignment of the largest type we support
288// (currently a double word). -- see class TargetData).
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000289//
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000290// This function is similar to the corresponding function in EmitAssembly.cpp
291// but they are unrelated. This one does not align at more than a
292// double-word boundary whereas that one might.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000293//
Chris Lattner955fad12002-12-28 20:37:16 +0000294inline unsigned
295SizeToAlignment(unsigned size, const TargetMachine& target)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000296{
Brian Gaeke05b15fb2004-03-01 06:43:29 +0000297 const unsigned short cacheLineSize = 16;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000298 if (size > (unsigned) cacheLineSize / 2)
299 return cacheLineSize;
300 else
301 for (unsigned sz=1; /*no condition*/; sz *= 2)
Chris Lattner955fad12002-12-28 20:37:16 +0000302 if (sz >= size || sz >= target.getTargetData().getDoubleAlignment())
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000303 return sz;
304}
305
306
Chris Lattner955fad12002-12-28 20:37:16 +0000307void MachineFunctionInfo::CalculateArgSize() {
308 maxOptionalArgsSize = ComputeMaxOptionalArgsSize(MF.getTarget(),
309 MF.getFunction(),
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000310 maxOptionalNumArgs);
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000311 staticStackSize = maxOptionalArgsSize
Chris Lattner62d6ad22004-06-02 05:56:52 +0000312 + MF.getTarget().getFrameInfo()->getMinStackFrameSize();
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000313}
314
315int
Chris Lattner955fad12002-12-28 20:37:16 +0000316MachineFunctionInfo::computeOffsetforLocalVar(const Value* val,
317 unsigned &getPaddedSize,
318 unsigned sizeToUse)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000319{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000320 if (sizeToUse == 0) {
321 // All integer types smaller than ints promote to 4 byte integers.
322 if (val->getType()->isIntegral() && val->getType()->getPrimitiveSize() < 4)
323 sizeToUse = 4;
324 else
325 sizeToUse = MF.getTarget().getTargetData().getTypeSize(val->getType());
326 }
Chris Lattner955fad12002-12-28 20:37:16 +0000327 unsigned align = SizeToAlignment(sizeToUse, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000328
329 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000330 int firstOffset = MF.getTarget().getFrameInfo()->getFirstAutomaticVarOffset(MF,
331 growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000332 int offset = growUp? firstOffset + getAutomaticVarsSize()
333 : firstOffset - (getAutomaticVarsSize() + sizeToUse);
334
Chris Lattner62d6ad22004-06-02 05:56:52 +0000335 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000336 getPaddedSize = sizeToUse + abs(aligned - offset);
337
338 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000339}
340
Chris Lattner07f32d42003-12-20 09:17:07 +0000341
342int MachineFunctionInfo::allocateLocalVar(const Value* val,
343 unsigned sizeToUse) {
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000344 assert(! automaticVarsAreaFrozen &&
345 "Size of auto vars area has been used to compute an offset so "
346 "no more automatic vars should be allocated!");
347
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000348 // Check if we've allocated a stack slot for this value already
349 //
Chris Lattner07f32d42003-12-20 09:17:07 +0000350 hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
351 if (pair != offsets.end())
352 return pair->second;
353
354 unsigned getPaddedSize;
355 unsigned offset = computeOffsetforLocalVar(val, getPaddedSize, sizeToUse);
356 offsets[val] = offset;
357 incrementAutomaticVarsSize(getPaddedSize);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000358 return offset;
359}
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000360
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000361int
Chris Lattner955fad12002-12-28 20:37:16 +0000362MachineFunctionInfo::allocateSpilledValue(const Type* type)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000363{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000364 assert(! spillsAreaFrozen &&
365 "Size of reg spills area has been used to compute an offset so "
366 "no more register spill slots should be allocated!");
367
Chris Lattner955fad12002-12-28 20:37:16 +0000368 unsigned size = MF.getTarget().getTargetData().getTypeSize(type);
369 unsigned char align = MF.getTarget().getTargetData().getTypeAlignment(type);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000370
371 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000372 int firstOffset = MF.getTarget().getFrameInfo()->getRegSpillAreaOffset(MF, growUp);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000373
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000374 int offset = growUp? firstOffset + getRegSpillsSize()
375 : firstOffset - (getRegSpillsSize() + size);
376
Chris Lattner62d6ad22004-06-02 05:56:52 +0000377 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000378 size += abs(aligned - offset); // include alignment padding in size
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000379
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000380 incrementRegSpillsSize(size); // update size of reg. spills area
381
382 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000383}
384
385int
Chris Lattner955fad12002-12-28 20:37:16 +0000386MachineFunctionInfo::pushTempValue(unsigned size)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000387{
Chris Lattner955fad12002-12-28 20:37:16 +0000388 unsigned align = SizeToAlignment(size, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000389
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000390 bool growUp;
Chris Lattner62d6ad22004-06-02 05:56:52 +0000391 int firstOffset = MF.getTarget().getFrameInfo()->getTmpAreaOffset(MF, growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000392
393 int offset = growUp? firstOffset + currentTmpValuesSize
394 : firstOffset - (currentTmpValuesSize + size);
395
Chris Lattner62d6ad22004-06-02 05:56:52 +0000396 int aligned = MF.getTarget().getFrameInfo()->adjustAlignment(offset, growUp,
Chris Lattner955fad12002-12-28 20:37:16 +0000397 align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000398 size += abs(aligned - offset); // include alignment padding in size
399
400 incrementTmpAreaSize(size); // update "current" size of tmp area
401
402 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000403}
404
Chris Lattner955fad12002-12-28 20:37:16 +0000405void MachineFunctionInfo::popAllTempValues() {
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000406 resetTmpAreaSize(); // clear tmp area to reuse
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000407}
408