blob: 790859bc87a295323537cceab7caac9e68284319 [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
Brian Gaeked0fde302003-11-11 22:41:34 +000031namespace llvm {
32
Chris Lattnerf2868ce2002-02-03 07:54:50 +000033const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max();
34
Chris Lattnere316efc2002-10-29 23:18:43 +000035static AnnotationID MF_AID(
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000036 AnnotationManager::getID("CodeGen::MachineCodeForFunction"));
Chris Lattnerf2868ce2002-02-03 07:54:50 +000037
Chris Lattner227c3d32002-10-28 01:12:41 +000038
39//===---------------------------------------------------------------------===//
40// Code generation/destruction passes
41//===---------------------------------------------------------------------===//
42
43namespace {
44 class ConstructMachineFunction : public FunctionPass {
45 TargetMachine &Target;
46 public:
47 ConstructMachineFunction(TargetMachine &T) : Target(T) {}
48
49 const char *getPassName() const {
50 return "ConstructMachineFunction";
51 }
52
53 bool runOnFunction(Function &F) {
Chris Lattner955fad12002-12-28 20:37:16 +000054 MachineFunction::construct(&F, Target).getInfo()->CalculateArgSize();
Chris Lattner227c3d32002-10-28 01:12:41 +000055 return false;
56 }
57 };
58
59 struct DestroyMachineFunction : public FunctionPass {
60 const char *getPassName() const { return "FreeMachineFunction"; }
61
62 static void freeMachineCode(Instruction &I) {
63 MachineCodeForInstruction::destroy(&I);
64 }
65
66 bool runOnFunction(Function &F) {
67 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
68 for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I)
69 MachineCodeForInstruction::get(I).dropAllReferences();
70
71 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
72 for_each(FI->begin(), FI->end(), freeMachineCode);
73
74 return false;
75 }
76 };
Chris Lattner10491642002-10-30 00:48:05 +000077
78 struct Printer : public FunctionPass {
79 const char *getPassName() const { return "MachineFunction Printer"; }
80
81 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
82 AU.setPreservesAll();
83 }
84
85 bool runOnFunction(Function &F) {
86 MachineFunction::get(&F).dump();
87 return false;
88 }
89 };
Chris Lattner227c3d32002-10-28 01:12:41 +000090}
91
Brian Gaeke19df3872003-08-13 18:18:15 +000092FunctionPass *createMachineCodeConstructionPass(TargetMachine &Target) {
Chris Lattner227c3d32002-10-28 01:12:41 +000093 return new ConstructMachineFunction(Target);
94}
95
Brian Gaeke19df3872003-08-13 18:18:15 +000096FunctionPass *createMachineCodeDestructionPass() {
Chris Lattner227c3d32002-10-28 01:12:41 +000097 return new DestroyMachineFunction();
98}
99
Brian Gaeke19df3872003-08-13 18:18:15 +0000100FunctionPass *createMachineFunctionPrinterPass() {
Chris Lattner10491642002-10-30 00:48:05 +0000101 return new Printer();
102}
103
Chris Lattner227c3d32002-10-28 01:12:41 +0000104
105//===---------------------------------------------------------------------===//
106// MachineFunction implementation
107//===---------------------------------------------------------------------===//
108
Chris Lattner10491642002-10-30 00:48:05 +0000109MachineFunction::MachineFunction(const Function *F,
Chris Lattner955fad12002-12-28 20:37:16 +0000110 const TargetMachine &TM)
111 : Annotation(MF_AID), Fn(F), Target(TM) {
Misha Brukmanb7825bc2002-11-20 18:55:27 +0000112 SSARegMapping = new SSARegMap();
Chris Lattner955fad12002-12-28 20:37:16 +0000113 MFInfo = new MachineFunctionInfo(*this);
Chris Lattnereb24db92002-12-28 21:08:26 +0000114 FrameInfo = new MachineFrameInfo();
Chris Lattner4d149cd2003-01-13 00:23:03 +0000115 ConstantPool = new MachineConstantPool();
Chris Lattner831fdcf2002-12-25 05:03:22 +0000116}
117
118MachineFunction::~MachineFunction() {
119 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 {
Chris Lattner955fad12002-12-28 20:37:16 +0000128 OS << "\n" << *(Value*)Fn->getFunctionType() << " \"" << Fn->getName()
129 << "\"\n";
130
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
137 for (const_iterator BB = begin(); BB != end(); ++BB) {
Chris Lattner9e2dd8f2003-07-26 23:24:56 +0000138 const BasicBlock *LBB = BB->getBasicBlock();
Chris Lattner2109f502002-12-15 20:35:25 +0000139 OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
Chris Lattner10491642002-10-30 00:48:05 +0000140 for (MachineBasicBlock::const_iterator I = BB->begin(); I != BB->end();++I){
141 OS << "\t";
142 (*I)->print(OS, Target);
143 }
144 }
145 OS << "\nEnd function \"" << Fn->getName() << "\"\n\n";
146}
147
148
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000149// The next two methods are used to construct and to retrieve
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000150// the MachineCodeForFunction object for the given function.
151// construct() -- Allocates and initializes for a given function and target
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000152// get() -- Returns a handle to the object.
153// This should not be called before "construct()"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000154// for a given Function.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000155//
Misha Brukmanfce11432002-10-28 00:28:31 +0000156MachineFunction&
Chris Lattner335d5c32002-10-28 05:58:46 +0000157MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000158{
Chris Lattnere316efc2002-10-29 23:18:43 +0000159 assert(Fn->getAnnotation(MF_AID) == 0 &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000160 "Object already exists for this function!");
Chris Lattner335d5c32002-10-28 05:58:46 +0000161 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
162 Fn->addAnnotation(mcInfo);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000163 return *mcInfo;
164}
165
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000166void
Chris Lattner335d5c32002-10-28 05:58:46 +0000167MachineFunction::destruct(const Function *Fn)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000168{
Chris Lattnere316efc2002-10-29 23:18:43 +0000169 bool Deleted = Fn->deleteAnnotation(MF_AID);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000170 assert(Deleted && "Machine code did not exist for function!");
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000171}
172
Chris Lattner335d5c32002-10-28 05:58:46 +0000173MachineFunction& MachineFunction::get(const Function *F)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000174{
Chris Lattnere316efc2002-10-29 23:18:43 +0000175 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000176 assert(mc && "Call construct() method first to allocate the object");
177 return *mc;
178}
179
Chris Lattner831fdcf2002-12-25 05:03:22 +0000180void MachineFunction::clearSSARegMap() {
181 delete SSARegMapping;
182 SSARegMapping = 0;
183}
184
Chris Lattner955fad12002-12-28 20:37:16 +0000185//===----------------------------------------------------------------------===//
Chris Lattnereb24db92002-12-28 21:08:26 +0000186// MachineFrameInfo implementation
Chris Lattner955fad12002-12-28 20:37:16 +0000187//===----------------------------------------------------------------------===//
188
Chris Lattner4d149cd2003-01-13 00:23:03 +0000189/// CreateStackObject - Create a stack object for a value of the specified type.
190///
191int MachineFrameInfo::CreateStackObject(const Type *Ty, const TargetData &TD) {
192 return CreateStackObject(TD.getTypeSize(Ty), TD.getTypeAlignment(Ty));
193}
194
195int MachineFrameInfo::CreateStackObject(const TargetRegisterClass *RC) {
196 return CreateStackObject(RC->getSize(), RC->getAlignment());
197}
198
199
Chris Lattner9085d8a2003-01-16 18:35:57 +0000200void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
201 int ValOffset = MF.getTarget().getFrameInfo().getOffsetOfLocalArea();
202
Chris Lattner955fad12002-12-28 20:37:16 +0000203 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
204 const StackObject &SO = Objects[i];
Chris Lattner4d149cd2003-01-13 00:23:03 +0000205 OS << " <fi #" << (int)(i-NumFixedObjects) << "> is ";
Chris Lattner955fad12002-12-28 20:37:16 +0000206 if (SO.Size == 0)
207 OS << "variable sized";
208 else
209 OS << SO.Size << " byte" << (SO.Size != 1 ? "s" : " ");
210
211 if (i < NumFixedObjects)
212 OS << " fixed";
213 if (i < NumFixedObjects || SO.SPOffset != -1) {
Chris Lattner9085d8a2003-01-16 18:35:57 +0000214 int Off = SO.SPOffset + ValOffset;
Chris Lattner955fad12002-12-28 20:37:16 +0000215 OS << " at location [SP";
Chris Lattner9085d8a2003-01-16 18:35:57 +0000216 if (Off > 0)
217 OS << "+" << Off;
218 else if (Off < 0)
219 OS << Off;
Chris Lattner955fad12002-12-28 20:37:16 +0000220 OS << "]";
221 }
222 OS << "\n";
223 }
224
225 if (HasVarSizedObjects)
226 OS << " Stack frame contains variable sized objects\n";
227}
228
Chris Lattner9085d8a2003-01-16 18:35:57 +0000229void MachineFrameInfo::dump(const MachineFunction &MF) const {
230 print(MF, std::cerr);
231}
Chris Lattner955fad12002-12-28 20:37:16 +0000232
233
234//===----------------------------------------------------------------------===//
Chris Lattner4d149cd2003-01-13 00:23:03 +0000235// MachineConstantPool implementation
236//===----------------------------------------------------------------------===//
237
238void MachineConstantPool::print(std::ostream &OS) const {
239 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
240 OS << " <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
241}
242
243void MachineConstantPool::dump() const { print(std::cerr); }
244
245//===----------------------------------------------------------------------===//
Chris Lattner955fad12002-12-28 20:37:16 +0000246// MachineFunctionInfo implementation
247//===----------------------------------------------------------------------===//
Chris Lattner831fdcf2002-12-25 05:03:22 +0000248
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000249static unsigned
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000250ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F,
251 unsigned &maxOptionalNumArgs)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000252{
Chris Lattner955fad12002-12-28 20:37:16 +0000253 const TargetFrameInfo &frameInfo = target.getFrameInfo();
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000254
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000255 unsigned maxSize = 0;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000256
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000257 for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB)
258 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Chris Lattner2ee82e02003-04-23 16:36:11 +0000259 if (const CallInst *callInst = dyn_cast<CallInst>(I))
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000260 {
261 unsigned numOperands = callInst->getNumOperands() - 1;
262 int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs();
263 if (numExtra <= 0)
264 continue;
265
Chris Lattner955fad12002-12-28 20:37:16 +0000266 unsigned sizeForThisCall;
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000267 if (frameInfo.argsOnStackHaveFixedSize())
268 {
269 int argSize = frameInfo.getSizeOfEachArgOnStack();
270 sizeForThisCall = numExtra * (unsigned) argSize;
271 }
272 else
273 {
274 assert(0 && "UNTESTED CODE: Size per stack argument is not "
275 "fixed on this architecture: use actual arg sizes to "
276 "compute MaxOptionalArgsSize");
277 sizeForThisCall = 0;
278 for (unsigned i = 0; i < numOperands; ++i)
Chris Lattner955fad12002-12-28 20:37:16 +0000279 sizeForThisCall += target.getTargetData().getTypeSize(callInst->
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000280 getOperand(i)->getType());
281 }
282
283 if (maxSize < sizeForThisCall)
284 maxSize = sizeForThisCall;
285
286 if ((int)maxOptionalNumArgs < numExtra)
287 maxOptionalNumArgs = (unsigned) numExtra;
288 }
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000289
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000290 return maxSize;
291}
292
293// Align data larger than one L1 cache line on L1 cache line boundaries.
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000294// Align all smaller data on the next higher 2^x boundary (4, 8, ...),
295// but not higher than the alignment of the largest type we support
296// (currently a double word). -- see class TargetData).
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000297//
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000298// This function is similar to the corresponding function in EmitAssembly.cpp
299// but they are unrelated. This one does not align at more than a
300// double-word boundary whereas that one might.
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000301//
Chris Lattner955fad12002-12-28 20:37:16 +0000302inline unsigned
303SizeToAlignment(unsigned size, const TargetMachine& target)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000304{
305 unsigned short cacheLineSize = target.getCacheInfo().getCacheLineSize(1);
306 if (size > (unsigned) cacheLineSize / 2)
307 return cacheLineSize;
308 else
309 for (unsigned sz=1; /*no condition*/; sz *= 2)
Chris Lattner955fad12002-12-28 20:37:16 +0000310 if (sz >= size || sz >= target.getTargetData().getDoubleAlignment())
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000311 return sz;
312}
313
314
Chris Lattner955fad12002-12-28 20:37:16 +0000315void MachineFunctionInfo::CalculateArgSize() {
316 maxOptionalArgsSize = ComputeMaxOptionalArgsSize(MF.getTarget(),
317 MF.getFunction(),
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000318 maxOptionalNumArgs);
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000319 staticStackSize = maxOptionalArgsSize
Chris Lattner955fad12002-12-28 20:37:16 +0000320 + MF.getTarget().getFrameInfo().getMinStackFrameSize();
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000321}
322
323int
Chris Lattner955fad12002-12-28 20:37:16 +0000324MachineFunctionInfo::computeOffsetforLocalVar(const Value* val,
325 unsigned &getPaddedSize,
326 unsigned sizeToUse)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000327{
Vikram S. Advee4e4d4e2002-03-24 03:39:26 +0000328 if (sizeToUse == 0)
Chris Lattner955fad12002-12-28 20:37:16 +0000329 sizeToUse = MF.getTarget().findOptimalStorageSize(val->getType());
330 unsigned align = SizeToAlignment(sizeToUse, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000331
332 bool growUp;
Chris Lattner955fad12002-12-28 20:37:16 +0000333 int firstOffset = MF.getTarget().getFrameInfo().getFirstAutomaticVarOffset(MF,
334 growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000335 int offset = growUp? firstOffset + getAutomaticVarsSize()
336 : firstOffset - (getAutomaticVarsSize() + sizeToUse);
337
Chris Lattner955fad12002-12-28 20:37:16 +0000338 int aligned = MF.getTarget().getFrameInfo().adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000339 getPaddedSize = sizeToUse + abs(aligned - offset);
340
341 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000342}
343
344int
Chris Lattner955fad12002-12-28 20:37:16 +0000345MachineFunctionInfo::allocateLocalVar(const Value* val,
346 unsigned sizeToUse)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000347{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000348 assert(! automaticVarsAreaFrozen &&
349 "Size of auto vars area has been used to compute an offset so "
350 "no more automatic vars should be allocated!");
351
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000352 // Check if we've allocated a stack slot for this value already
353 //
354 int offset = getOffset(val);
355 if (offset == INVALID_FRAME_OFFSET)
356 {
Chris Lattner955fad12002-12-28 20:37:16 +0000357 unsigned getPaddedSize;
358 offset = computeOffsetforLocalVar(val, getPaddedSize, sizeToUse);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000359 offsets[val] = offset;
Vikram S. Advee4e4d4e2002-03-24 03:39:26 +0000360 incrementAutomaticVarsSize(getPaddedSize);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000361 }
362 return offset;
363}
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000364
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000365int
Chris Lattner955fad12002-12-28 20:37:16 +0000366MachineFunctionInfo::allocateSpilledValue(const Type* type)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000367{
Vikram S. Adve03d33bd2002-04-25 04:30:43 +0000368 assert(! spillsAreaFrozen &&
369 "Size of reg spills area has been used to compute an offset so "
370 "no more register spill slots should be allocated!");
371
Chris Lattner955fad12002-12-28 20:37:16 +0000372 unsigned size = MF.getTarget().getTargetData().getTypeSize(type);
373 unsigned char align = MF.getTarget().getTargetData().getTypeAlignment(type);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000374
375 bool growUp;
Chris Lattner955fad12002-12-28 20:37:16 +0000376 int firstOffset = MF.getTarget().getFrameInfo().getRegSpillAreaOffset(MF, growUp);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000377
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000378 int offset = growUp? firstOffset + getRegSpillsSize()
379 : firstOffset - (getRegSpillsSize() + size);
380
Chris Lattner955fad12002-12-28 20:37:16 +0000381 int aligned = MF.getTarget().getFrameInfo().adjustAlignment(offset, growUp, align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000382 size += abs(aligned - offset); // include alignment padding in size
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000383
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000384 incrementRegSpillsSize(size); // update size of reg. spills area
385
386 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000387}
388
389int
Chris Lattner955fad12002-12-28 20:37:16 +0000390MachineFunctionInfo::pushTempValue(unsigned size)
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000391{
Chris Lattner955fad12002-12-28 20:37:16 +0000392 unsigned align = SizeToAlignment(size, MF.getTarget());
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000393
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000394 bool growUp;
Chris Lattner955fad12002-12-28 20:37:16 +0000395 int firstOffset = MF.getTarget().getFrameInfo().getTmpAreaOffset(MF, growUp);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000396
397 int offset = growUp? firstOffset + currentTmpValuesSize
398 : firstOffset - (currentTmpValuesSize + size);
399
Chris Lattner955fad12002-12-28 20:37:16 +0000400 int aligned = MF.getTarget().getFrameInfo().adjustAlignment(offset, growUp,
401 align);
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000402 size += abs(aligned - offset); // include alignment padding in size
403
404 incrementTmpAreaSize(size); // update "current" size of tmp area
405
406 return aligned;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000407}
408
Chris Lattner955fad12002-12-28 20:37:16 +0000409void MachineFunctionInfo::popAllTempValues() {
Vikram S. Adve1318bed2002-09-16 15:18:16 +0000410 resetTmpAreaSize(); // clear tmp area to reuse
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000411}
412
413int
Chris Lattner955fad12002-12-28 20:37:16 +0000414MachineFunctionInfo::getOffset(const Value* val) const
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000415{
Chris Lattner09ff1122002-07-24 21:21:32 +0000416 hash_map<const Value*, int>::const_iterator pair = offsets.find(val);
Chris Lattner6b944532002-10-28 01:16:38 +0000417 return (pair == offsets.end()) ? INVALID_FRAME_OFFSET : pair->second;
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000418}
Brian Gaeked0fde302003-11-11 22:41:34 +0000419
420} // End llvm namespace