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/Target/MachineInstrInfo.h"
12 #include "llvm/Constant.h"
13 #include "llvm/Function.h"
14 #include "llvm/DerivedTypes.h"
15 #include "llvm/Pass.h"
16 #include "llvm/CodeGen/MachineFunction.h"
18 class StackSlots : public FunctionPass {
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 runOnFunction(Function &F) {
32 const Type *PtrInt = PointerType::get(Type::IntTy);
33 unsigned Size = Target.DataLayout.getTypeSize(PtrInt);
35 MachineFunction &mcInfo = MachineFunction::get(&F);
36 Value *V = Constant::getNullValue(Type::IntTy);
37 mcInfo.allocateLocalVar(Target, V, 2*Size);
42 Pass *createStackSlotsPass(const TargetMachine &Target) {
43 return new StackSlots(Target);