Added LLVM project notice to the top of every C++ source file.
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9StackSlots.cpp
1 //===- StackSlots.cpp  - Specialize LLVM code for target machine ---------===//
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 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "SparcInternals.h"
17 #include "llvm/Constant.h"
18 #include "llvm/Function.h"
19 #include "llvm/DerivedTypes.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "llvm/CodeGen/MachineFunctionInfo.h"
22
23 namespace {
24   class StackSlots : public MachineFunctionPass {
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     
37     bool runOnMachineFunction(MachineFunction &MF) {
38       const Type *PtrInt = PointerType::get(Type::IntTy);
39       unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
40       
41       Value *V = Constant::getNullValue(Type::IntTy);
42       MF.getInfo()->allocateLocalVar(V, 2*Size);
43       return true;
44     }
45   };
46 }
47
48 Pass *createStackSlotsPass(const TargetMachine &Target) {
49   return new StackSlots(Target);
50 }