Brian Gaeke | 3ca4fcc | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 1 | //===- SparcV9StackSlots.cpp - Add empty stack slots to functions ---------===// |
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 | |
Brian Gaeke | 150666f | 2004-02-25 19:08:12 +0000 | [diff] [blame] | 16 | #include "SparcV9Internals.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/DerivedTypes.h" |
Misha Brukman | 6d7aad1 | 2003-11-06 18:06:13 +0000 | [diff] [blame] | 19 | #include "llvm/Function.h" |
Misha Brukman | 6d7aad1 | 2003-11-06 18:06:13 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Chris Lattner | 85015a0 | 2004-08-16 21:55:02 +0000 | [diff] [blame] | 21 | #include "MachineFunctionInfo.h" |
| 22 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 24 | namespace { |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 25 | class StackSlots : public MachineFunctionPass { |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 26 | const TargetMachine &Target; |
| 27 | public: |
| 28 | StackSlots(const TargetMachine &T) : Target(T) {} |
| 29 | |
| 30 | const char *getPassName() const { |
| 31 | return "Stack Slot Insertion for profiling code"; |
| 32 | } |
| 33 | |
| 34 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 35 | AU.setPreservesCFG(); |
| 36 | } |
| 37 | |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 38 | bool runOnMachineFunction(MachineFunction &MF) { |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 39 | const Type *PtrInt = PointerType::get(Type::IntTy); |
| 40 | unsigned Size = Target.getTargetData().getTypeSize(PtrInt); |
| 41 | |
| 42 | Value *V = Constant::getNullValue(Type::IntTy); |
Chris Lattner | a1e51ff | 2004-08-18 18:13:37 +0000 | [diff] [blame^] | 43 | MF.getInfo<SparcV9FunctionInfo>()->allocateLocalVar(V, 2*Size); |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame] | 44 | return true; |
| 45 | } |
| 46 | }; |
| 47 | } |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 85015a0 | 2004-08-16 21:55:02 +0000 | [diff] [blame] | 49 | Pass *llvm::createStackSlotsPass(const TargetMachine &Target) { |
Chris Lattner | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 50 | return new StackSlots(Target); |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 51 | } |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 52 | |