blob: eff679cb4eaab36d6e4be487e709bf64c56131e6 [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 Lattner48e60792003-08-13 02:38:16 +00009#include "SparcInternals.h"
Chris Lattner54b866b2002-10-23 01:12:01 +000010#include "llvm/Constant.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000011#include "llvm/Function.h"
12#include "llvm/DerivedTypes.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000013#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattner5a977d42002-12-28 20:42:56 +000014#include "llvm/CodeGen/MachineFunctionInfo.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000015
Chris Lattner5a977d42002-12-28 20:42:56 +000016namespace {
Chris Lattner3501fea2003-01-14 22:00:31 +000017 class StackSlots : public MachineFunctionPass {
Chris Lattner5a977d42002-12-28 20:42:56 +000018 const TargetMachine &Target;
19 public:
20 StackSlots(const TargetMachine &T) : Target(T) {}
21
22 const char *getPassName() const {
23 return "Stack Slot Insertion for profiling code";
24 }
25
26 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
27 AU.setPreservesCFG();
28 }
29
Chris Lattner3501fea2003-01-14 22:00:31 +000030 bool runOnMachineFunction(MachineFunction &MF) {
Chris Lattner5a977d42002-12-28 20:42:56 +000031 const Type *PtrInt = PointerType::get(Type::IntTy);
32 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
33
34 Value *V = Constant::getNullValue(Type::IntTy);
Chris Lattner3501fea2003-01-14 22:00:31 +000035 MF.getInfo()->allocateLocalVar(V, 2*Size);
Chris Lattner5a977d42002-12-28 20:42:56 +000036 return true;
37 }
38 };
39}
Anand Shukla33db9ba2002-09-21 04:58:26 +000040
Chris Lattner54b866b2002-10-23 01:12:01 +000041Pass *createStackSlotsPass(const TargetMachine &Target) {
42 return new StackSlots(Target);
Anand Shukla33db9ba2002-09-21 04:58:26 +000043}