blob: 1ff54b9c12c3a075b9f9f2dcb2d93043ab490fe1 [file] [log] [blame]
Anand Shukla33db9ba2002-09-21 04:58:26 +00001//===- StackSlots.cpp - Specialize LLVM code for target machine ---------===//
2//
Chris Lattner54b866b2002-10-23 01:12:01 +00003// 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 Shukla33db9ba2002-09-21 04:58:26 +00006//
7//===----------------------------------------------------------------------===//
8
Chris Lattner54b866b2002-10-23 01:12:01 +00009#include "llvm/CodeGen/StackSlots.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000010#include "llvm/Target/TargetMachine.h"
Chris Lattner54b866b2002-10-23 01:12:01 +000011#include "llvm/Constant.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000012#include "llvm/Function.h"
13#include "llvm/DerivedTypes.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000014#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattner5a977d42002-12-28 20:42:56 +000015#include "llvm/CodeGen/MachineFunctionInfo.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000016
Chris Lattner5a977d42002-12-28 20:42:56 +000017namespace {
Chris Lattner3501fea2003-01-14 22:00:31 +000018 class StackSlots : public MachineFunctionPass {
Chris Lattner5a977d42002-12-28 20:42:56 +000019 const TargetMachine &Target;
20 public:
21 StackSlots(const TargetMachine &T) : Target(T) {}
22
23 const char *getPassName() const {
24 return "Stack Slot Insertion for profiling code";
25 }
26
27 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
28 AU.setPreservesCFG();
29 }
30
Chris Lattner3501fea2003-01-14 22:00:31 +000031 bool runOnMachineFunction(MachineFunction &MF) {
Chris Lattner5a977d42002-12-28 20:42:56 +000032 const Type *PtrInt = PointerType::get(Type::IntTy);
33 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
34
35 Value *V = Constant::getNullValue(Type::IntTy);
Chris Lattner3501fea2003-01-14 22:00:31 +000036 MF.getInfo()->allocateLocalVar(V, 2*Size);
Chris Lattner5a977d42002-12-28 20:42:56 +000037 return true;
38 }
39 };
40}
Anand Shukla33db9ba2002-09-21 04:58:26 +000041
Chris Lattner54b866b2002-10-23 01:12:01 +000042Pass *createStackSlotsPass(const TargetMachine &Target) {
43 return new StackSlots(Target);
Anand Shukla33db9ba2002-09-21 04:58:26 +000044}