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