Move MachineCodeForInstruction.h and MachineFunctionInfo.h into lib/Target/SparcV9
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9StackSlots.cpp
1 //===- SparcV9StackSlots.cpp - Add empty stack slots to functions ---------===//
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 "SparcV9Internals.h"
17 #include "llvm/Constant.h"
18 #include "llvm/DerivedTypes.h"
19 #include "llvm/Function.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "MachineFunctionInfo.h"
22 using namespace llvm;
23
24 namespace {
25   class StackSlots : public MachineFunctionPass {
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     
38     bool runOnMachineFunction(MachineFunction &MF) {
39       const Type *PtrInt = PointerType::get(Type::IntTy);
40       unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
41       
42       Value *V = Constant::getNullValue(Type::IntTy);
43       MF.getInfo()->allocateLocalVar(V, 2*Size);
44       return true;
45     }
46   };
47 }
48
49 Pass *llvm::createStackSlotsPass(const TargetMachine &Target) {
50   return new StackSlots(Target);
51 }
52