Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 1 | //===- StackSlots.cpp - Specialize LLVM code for target machine ---------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame^] | 2 | // |
| 3 | // 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 | //===----------------------------------------------------------------------===// |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 10 | // This pass adds 2 empty slots at the top of function stack. These two slots |
| 11 | // are later used during code reoptimization for spilling the register values |
| 12 | // when rewriting branches. |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chris Lattner | 48e6079 | 2003-08-13 02:38:16 +0000 | [diff] [blame] | 16 | #include "SparcInternals.h" |
Chris Lattner | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 17 | #include "llvm/Constant.h" |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunctionInfo.h" |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 22 | |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 23 | namespace { |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 24 | class StackSlots : public MachineFunctionPass { |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 25 | const TargetMachine &Target; |
| 26 | public: |
| 27 | StackSlots(const TargetMachine &T) : Target(T) {} |
| 28 | |
| 29 | const char *getPassName() const { |
| 30 | return "Stack Slot Insertion for profiling code"; |
| 31 | } |
| 32 | |
| 33 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 34 | AU.setPreservesCFG(); |
| 35 | } |
| 36 | |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 37 | bool runOnMachineFunction(MachineFunction &MF) { |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 38 | const Type *PtrInt = PointerType::get(Type::IntTy); |
| 39 | unsigned Size = Target.getTargetData().getTypeSize(PtrInt); |
| 40 | |
| 41 | Value *V = Constant::getNullValue(Type::IntTy); |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 42 | MF.getInfo()->allocateLocalVar(V, 2*Size); |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 43 | return true; |
| 44 | } |
| 45 | }; |
| 46 | } |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 48 | Pass *createStackSlotsPass(const TargetMachine &Target) { |
| 49 | return new StackSlots(Target); |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 50 | } |