1 //===- StackSlots.cpp - Specialize LLVM code for target machine ---------===//
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.
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/StackSlots.h"
10 #include "llvm/Target/TargetMachine.h"
11 #include "llvm/Constant.h"
12 #include "llvm/Function.h"
13 #include "llvm/DerivedTypes.h"
14 #include "llvm/CodeGen/MachineFunctionPass.h"
15 #include "llvm/CodeGen/MachineFunctionInfo.h"
18 class StackSlots : public MachineFunctionPass {
19 const TargetMachine &Target;
21 StackSlots(const TargetMachine &T) : Target(T) {}
23 const char *getPassName() const {
24 return "Stack Slot Insertion for profiling code";
27 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
31 bool runOnMachineFunction(MachineFunction &MF) {
32 const Type *PtrInt = PointerType::get(Type::IntTy);
33 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
35 Value *V = Constant::getNullValue(Type::IntTy);
36 MF.getInfo()->allocateLocalVar(V, 2*Size);
42 Pass *createStackSlotsPass(const TargetMachine &Target) {
43 return new StackSlots(Target);