Chris Lattner | 6b94453 | 2002-10-28 01:16:38 +0000 | [diff] [blame] | 1 | //===-- MachineFunction.cpp -----------------------------------------------===// |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 6b94453 | 2002-10-28 01:16:38 +0000 | [diff] [blame] | 3 | // Collect native machine code information for a function. This allows |
| 4 | // target-specific information about the generated code to be stored with each |
| 5 | // function. |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 8 | |
Chris Lattner | 6b94453 | 2002-10-28 01:16:38 +0000 | [diff] [blame] | 9 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 831fdcf | 2002-12-25 05:03:22 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 227c3d3 | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
Chris Lattner | 831fdcf | 2002-12-25 05:03:22 +0000 | [diff] [blame] | 12 | #include "llvm/CodeGen/SSARegMap.h" |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 13 | #include "llvm/Target/TargetMachine.h" |
| 14 | #include "llvm/Target/MachineFrameInfo.h" |
| 15 | #include "llvm/Target/MachineCacheInfo.h" |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 16 | #include "llvm/Function.h" |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 17 | #include "llvm/iOther.h" |
Chris Lattner | 227c3d3 | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 18 | #include "llvm/Pass.h" |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 19 | #include <limits.h> |
| 20 | |
| 21 | const int INVALID_FRAME_OFFSET = INT_MAX; // std::numeric_limits<int>::max(); |
| 22 | |
Chris Lattner | e316efc | 2002-10-29 23:18:43 +0000 | [diff] [blame] | 23 | static AnnotationID MF_AID( |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 24 | AnnotationManager::getID("CodeGen::MachineCodeForFunction")); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 227c3d3 | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 26 | |
| 27 | //===---------------------------------------------------------------------===// |
| 28 | // Code generation/destruction passes |
| 29 | //===---------------------------------------------------------------------===// |
| 30 | |
| 31 | namespace { |
| 32 | class ConstructMachineFunction : public FunctionPass { |
| 33 | TargetMachine &Target; |
| 34 | public: |
| 35 | ConstructMachineFunction(TargetMachine &T) : Target(T) {} |
| 36 | |
| 37 | const char *getPassName() const { |
| 38 | return "ConstructMachineFunction"; |
| 39 | } |
| 40 | |
| 41 | bool runOnFunction(Function &F) { |
Chris Lattner | 8872618 | 2002-10-29 23:40:03 +0000 | [diff] [blame] | 42 | MachineFunction::construct(&F, Target).CalculateArgSize(); |
Chris Lattner | 227c3d3 | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 43 | return false; |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | struct DestroyMachineFunction : public FunctionPass { |
| 48 | const char *getPassName() const { return "FreeMachineFunction"; } |
| 49 | |
| 50 | static void freeMachineCode(Instruction &I) { |
| 51 | MachineCodeForInstruction::destroy(&I); |
| 52 | } |
| 53 | |
| 54 | bool runOnFunction(Function &F) { |
| 55 | for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) |
| 56 | for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I) |
| 57 | MachineCodeForInstruction::get(I).dropAllReferences(); |
| 58 | |
| 59 | for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) |
| 60 | for_each(FI->begin(), FI->end(), freeMachineCode); |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | }; |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 65 | |
| 66 | struct Printer : public FunctionPass { |
| 67 | const char *getPassName() const { return "MachineFunction Printer"; } |
| 68 | |
| 69 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 70 | AU.setPreservesAll(); |
| 71 | } |
| 72 | |
| 73 | bool runOnFunction(Function &F) { |
| 74 | MachineFunction::get(&F).dump(); |
| 75 | return false; |
| 76 | } |
| 77 | }; |
Chris Lattner | 227c3d3 | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | Pass *createMachineCodeConstructionPass(TargetMachine &Target) { |
| 81 | return new ConstructMachineFunction(Target); |
| 82 | } |
| 83 | |
| 84 | Pass *createMachineCodeDestructionPass() { |
| 85 | return new DestroyMachineFunction(); |
| 86 | } |
| 87 | |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 88 | Pass *createMachineFunctionPrinterPass() { |
| 89 | return new Printer(); |
| 90 | } |
| 91 | |
Chris Lattner | 227c3d3 | 2002-10-28 01:12:41 +0000 | [diff] [blame] | 92 | |
| 93 | //===---------------------------------------------------------------------===// |
| 94 | // MachineFunction implementation |
| 95 | //===---------------------------------------------------------------------===// |
| 96 | |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 97 | MachineFunction::MachineFunction(const Function *F, |
| 98 | const TargetMachine& target) |
Chris Lattner | 831fdcf | 2002-12-25 05:03:22 +0000 | [diff] [blame] | 99 | : Annotation(MF_AID), Fn(F), Target(target) { |
Misha Brukman | b7825bc | 2002-11-20 18:55:27 +0000 | [diff] [blame] | 100 | SSARegMapping = new SSARegMap(); |
Chris Lattner | 831fdcf | 2002-12-25 05:03:22 +0000 | [diff] [blame] | 101 | |
| 102 | // FIXME: move state into another class |
| 103 | staticStackSize = automaticVarsSize = regSpillsSize = 0; |
| 104 | maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0; |
| 105 | maxTmpValuesSize = 0; |
| 106 | compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false; |
| 107 | } |
| 108 | |
| 109 | MachineFunction::~MachineFunction() { |
| 110 | delete SSARegMapping; |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void MachineFunction::dump() const { print(std::cerr); } |
| 114 | |
| 115 | void MachineFunction::print(std::ostream &OS) const { |
| 116 | OS << "\n" << *(Value*)Fn->getReturnType() << " \"" << Fn->getName()<< "\"\n"; |
| 117 | |
| 118 | for (const_iterator BB = begin(); BB != end(); ++BB) { |
| 119 | BasicBlock *LBB = BB->getBasicBlock(); |
Chris Lattner | 2109f50 | 2002-12-15 20:35:25 +0000 | [diff] [blame] | 120 | OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n"; |
Chris Lattner | 1049164 | 2002-10-30 00:48:05 +0000 | [diff] [blame] | 121 | for (MachineBasicBlock::const_iterator I = BB->begin(); I != BB->end();++I){ |
| 122 | OS << "\t"; |
| 123 | (*I)->print(OS, Target); |
| 124 | } |
| 125 | } |
| 126 | OS << "\nEnd function \"" << Fn->getName() << "\"\n\n"; |
| 127 | } |
| 128 | |
| 129 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 130 | // The next two methods are used to construct and to retrieve |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 131 | // the MachineCodeForFunction object for the given function. |
| 132 | // construct() -- Allocates and initializes for a given function and target |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 133 | // get() -- Returns a handle to the object. |
| 134 | // This should not be called before "construct()" |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 135 | // for a given Function. |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 136 | // |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 137 | MachineFunction& |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 138 | MachineFunction::construct(const Function *Fn, const TargetMachine &Tar) |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 139 | { |
Chris Lattner | e316efc | 2002-10-29 23:18:43 +0000 | [diff] [blame] | 140 | assert(Fn->getAnnotation(MF_AID) == 0 && |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 141 | "Object already exists for this function!"); |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 142 | MachineFunction* mcInfo = new MachineFunction(Fn, Tar); |
| 143 | Fn->addAnnotation(mcInfo); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 144 | return *mcInfo; |
| 145 | } |
| 146 | |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 147 | void |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 148 | MachineFunction::destruct(const Function *Fn) |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 149 | { |
Chris Lattner | e316efc | 2002-10-29 23:18:43 +0000 | [diff] [blame] | 150 | bool Deleted = Fn->deleteAnnotation(MF_AID); |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 151 | assert(Deleted && "Machine code did not exist for function!"); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 154 | MachineFunction& MachineFunction::get(const Function *F) |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 155 | { |
Chris Lattner | e316efc | 2002-10-29 23:18:43 +0000 | [diff] [blame] | 156 | MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 157 | assert(mc && "Call construct() method first to allocate the object"); |
| 158 | return *mc; |
| 159 | } |
| 160 | |
Chris Lattner | 831fdcf | 2002-12-25 05:03:22 +0000 | [diff] [blame] | 161 | void MachineFunction::clearSSARegMap() { |
| 162 | delete SSARegMapping; |
| 163 | SSARegMapping = 0; |
| 164 | } |
| 165 | |
| 166 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 167 | static unsigned |
Vikram S. Adve | 03d33bd | 2002-04-25 04:30:43 +0000 | [diff] [blame] | 168 | ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F, |
| 169 | unsigned &maxOptionalNumArgs) |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 170 | { |
| 171 | const MachineFrameInfo& frameInfo = target.getFrameInfo(); |
| 172 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 173 | unsigned maxSize = 0; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 174 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 175 | for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB) |
| 176 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
| 177 | if (const CallInst *callInst = dyn_cast<CallInst>(&*I)) |
| 178 | { |
| 179 | unsigned numOperands = callInst->getNumOperands() - 1; |
| 180 | int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs(); |
| 181 | if (numExtra <= 0) |
| 182 | continue; |
| 183 | |
| 184 | unsigned int sizeForThisCall; |
| 185 | if (frameInfo.argsOnStackHaveFixedSize()) |
| 186 | { |
| 187 | int argSize = frameInfo.getSizeOfEachArgOnStack(); |
| 188 | sizeForThisCall = numExtra * (unsigned) argSize; |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | assert(0 && "UNTESTED CODE: Size per stack argument is not " |
| 193 | "fixed on this architecture: use actual arg sizes to " |
| 194 | "compute MaxOptionalArgsSize"); |
| 195 | sizeForThisCall = 0; |
| 196 | for (unsigned i = 0; i < numOperands; ++i) |
Vikram S. Adve | cde3982 | 2002-10-11 16:10:53 +0000 | [diff] [blame] | 197 | sizeForThisCall += target.DataLayout.getTypeSize(callInst-> |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 198 | getOperand(i)->getType()); |
| 199 | } |
| 200 | |
| 201 | if (maxSize < sizeForThisCall) |
| 202 | maxSize = sizeForThisCall; |
| 203 | |
| 204 | if ((int)maxOptionalNumArgs < numExtra) |
| 205 | maxOptionalNumArgs = (unsigned) numExtra; |
| 206 | } |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 207 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 208 | return maxSize; |
| 209 | } |
| 210 | |
| 211 | // Align data larger than one L1 cache line on L1 cache line boundaries. |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 212 | // Align all smaller data on the next higher 2^x boundary (4, 8, ...), |
| 213 | // but not higher than the alignment of the largest type we support |
| 214 | // (currently a double word). -- see class TargetData). |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 215 | // |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 216 | // This function is similar to the corresponding function in EmitAssembly.cpp |
| 217 | // but they are unrelated. This one does not align at more than a |
| 218 | // double-word boundary whereas that one might. |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 219 | // |
| 220 | inline unsigned int |
| 221 | SizeToAlignment(unsigned int size, const TargetMachine& target) |
| 222 | { |
| 223 | unsigned short cacheLineSize = target.getCacheInfo().getCacheLineSize(1); |
| 224 | if (size > (unsigned) cacheLineSize / 2) |
| 225 | return cacheLineSize; |
| 226 | else |
| 227 | for (unsigned sz=1; /*no condition*/; sz *= 2) |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 228 | if (sz >= size || sz >= target.DataLayout.getDoubleAlignment()) |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 229 | return sz; |
| 230 | } |
| 231 | |
| 232 | |
Chris Lattner | 8872618 | 2002-10-29 23:40:03 +0000 | [diff] [blame] | 233 | void MachineFunction::CalculateArgSize() { |
| 234 | maxOptionalArgsSize = ComputeMaxOptionalArgsSize(Target, Fn, |
Vikram S. Adve | 03d33bd | 2002-04-25 04:30:43 +0000 | [diff] [blame] | 235 | maxOptionalNumArgs); |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 236 | staticStackSize = maxOptionalArgsSize |
Chris Lattner | 8872618 | 2002-10-29 23:40:03 +0000 | [diff] [blame] | 237 | + Target.getFrameInfo().getMinStackFrameSize(); |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 241 | MachineFunction::computeOffsetforLocalVar(const TargetMachine& target, |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 242 | const Value* val, |
Vikram S. Adve | e4e4d4e | 2002-03-24 03:39:26 +0000 | [diff] [blame] | 243 | unsigned int& getPaddedSize, |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 244 | unsigned int sizeToUse) |
Vikram S. Adve | 89e2da0 | 2002-03-18 03:36:30 +0000 | [diff] [blame] | 245 | { |
Vikram S. Adve | e4e4d4e | 2002-03-24 03:39:26 +0000 | [diff] [blame] | 246 | if (sizeToUse == 0) |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 247 | sizeToUse = target.findOptimalStorageSize(val->getType()); |
| 248 | unsigned int align = SizeToAlignment(sizeToUse, target); |
| 249 | |
| 250 | bool growUp; |
| 251 | int firstOffset = target.getFrameInfo().getFirstAutomaticVarOffset(*this, |
| 252 | growUp); |
| 253 | int offset = growUp? firstOffset + getAutomaticVarsSize() |
| 254 | : firstOffset - (getAutomaticVarsSize() + sizeToUse); |
| 255 | |
| 256 | int aligned = target.getFrameInfo().adjustAlignment(offset, growUp, align); |
| 257 | getPaddedSize = sizeToUse + abs(aligned - offset); |
| 258 | |
| 259 | return aligned; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 263 | MachineFunction::allocateLocalVar(const TargetMachine& target, |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 264 | const Value* val, |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 265 | unsigned int sizeToUse) |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 266 | { |
Vikram S. Adve | 03d33bd | 2002-04-25 04:30:43 +0000 | [diff] [blame] | 267 | assert(! automaticVarsAreaFrozen && |
| 268 | "Size of auto vars area has been used to compute an offset so " |
| 269 | "no more automatic vars should be allocated!"); |
| 270 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 271 | // Check if we've allocated a stack slot for this value already |
| 272 | // |
| 273 | int offset = getOffset(val); |
| 274 | if (offset == INVALID_FRAME_OFFSET) |
| 275 | { |
Vikram S. Adve | e4e4d4e | 2002-03-24 03:39:26 +0000 | [diff] [blame] | 276 | unsigned int getPaddedSize; |
Chris Lattner | 6b94453 | 2002-10-28 01:16:38 +0000 | [diff] [blame] | 277 | offset = computeOffsetforLocalVar(target, val, getPaddedSize, sizeToUse); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 278 | offsets[val] = offset; |
Vikram S. Adve | e4e4d4e | 2002-03-24 03:39:26 +0000 | [diff] [blame] | 279 | incrementAutomaticVarsSize(getPaddedSize); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 280 | } |
| 281 | return offset; |
| 282 | } |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 283 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 284 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 285 | MachineFunction::allocateSpilledValue(const TargetMachine& target, |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 286 | const Type* type) |
| 287 | { |
Vikram S. Adve | 03d33bd | 2002-04-25 04:30:43 +0000 | [diff] [blame] | 288 | assert(! spillsAreaFrozen && |
| 289 | "Size of reg spills area has been used to compute an offset so " |
| 290 | "no more register spill slots should be allocated!"); |
| 291 | |
Vikram S. Adve | cde3982 | 2002-10-11 16:10:53 +0000 | [diff] [blame] | 292 | unsigned int size = target.DataLayout.getTypeSize(type); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 293 | unsigned char align = target.DataLayout.getTypeAlignment(type); |
| 294 | |
| 295 | bool growUp; |
| 296 | int firstOffset = target.getFrameInfo().getRegSpillAreaOffset(*this, growUp); |
| 297 | |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 298 | int offset = growUp? firstOffset + getRegSpillsSize() |
| 299 | : firstOffset - (getRegSpillsSize() + size); |
| 300 | |
| 301 | int aligned = target.getFrameInfo().adjustAlignment(offset, growUp, align); |
| 302 | size += abs(aligned - offset); // include alignment padding in size |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 303 | |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 304 | incrementRegSpillsSize(size); // update size of reg. spills area |
| 305 | |
| 306 | return aligned; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 310 | MachineFunction::pushTempValue(const TargetMachine& target, |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 311 | unsigned int size) |
| 312 | { |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 313 | unsigned int align = SizeToAlignment(size, target); |
| 314 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 315 | bool growUp; |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 316 | int firstOffset = target.getFrameInfo().getTmpAreaOffset(*this, growUp); |
| 317 | |
| 318 | int offset = growUp? firstOffset + currentTmpValuesSize |
| 319 | : firstOffset - (currentTmpValuesSize + size); |
| 320 | |
| 321 | int aligned = target.getFrameInfo().adjustAlignment(offset, growUp, align); |
| 322 | size += abs(aligned - offset); // include alignment padding in size |
| 323 | |
| 324 | incrementTmpAreaSize(size); // update "current" size of tmp area |
| 325 | |
| 326 | return aligned; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 330 | MachineFunction::popAllTempValues(const TargetMachine& target) |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 331 | { |
Vikram S. Adve | 1318bed | 2002-09-16 15:18:16 +0000 | [diff] [blame] | 332 | resetTmpAreaSize(); // clear tmp area to reuse |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 336 | MachineFunction::getOffset(const Value* val) const |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 337 | { |
Chris Lattner | 09ff112 | 2002-07-24 21:21:32 +0000 | [diff] [blame] | 338 | hash_map<const Value*, int>::const_iterator pair = offsets.find(val); |
Chris Lattner | 6b94453 | 2002-10-28 01:16:38 +0000 | [diff] [blame] | 339 | return (pair == offsets.end()) ? INVALID_FRAME_OFFSET : pair->second; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 340 | } |