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 | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 9 | #include "llvm/CodeGen/StackSlots.h" |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 10 | #include "llvm/Target/TargetMachine.h" |
| 11 | #include "llvm/Target/MachineInstrInfo.h" |
Chris Lattner | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 12 | #include "llvm/Constant.h" |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 13 | #include "llvm/Function.h" |
| 14 | #include "llvm/DerivedTypes.h" |
| 15 | #include "llvm/Pass.h" |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame^] | 17 | #include "llvm/CodeGen/MachineFunctionInfo.h" |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 18 | |
Chris Lattner | 5a977d4 | 2002-12-28 20:42:56 +0000 | [diff] [blame^] | 19 | namespace { |
| 20 | class StackSlots : public FunctionPass { |
| 21 | const TargetMachine &Target; |
| 22 | public: |
| 23 | StackSlots(const TargetMachine &T) : Target(T) {} |
| 24 | |
| 25 | const char *getPassName() const { |
| 26 | return "Stack Slot Insertion for profiling code"; |
| 27 | } |
| 28 | |
| 29 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 30 | AU.setPreservesCFG(); |
| 31 | } |
| 32 | |
| 33 | bool runOnFunction(Function &F) { |
| 34 | const Type *PtrInt = PointerType::get(Type::IntTy); |
| 35 | unsigned Size = Target.getTargetData().getTypeSize(PtrInt); |
| 36 | |
| 37 | Value *V = Constant::getNullValue(Type::IntTy); |
| 38 | MachineFunction::get(&F).getInfo()->allocateLocalVar(V, 2*Size); |
| 39 | return true; |
| 40 | } |
| 41 | }; |
| 42 | } |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 54b866b | 2002-10-23 01:12:01 +0000 | [diff] [blame] | 44 | Pass *createStackSlotsPass(const TargetMachine &Target) { |
| 45 | return new StackSlots(Target); |
Anand Shukla | 33db9ba | 2002-09-21 04:58:26 +0000 | [diff] [blame] | 46 | } |