blob: 8f3a507b25eaad208b736ac7431ebbb9149f1d46 [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"
11#include "llvm/Target/MachineInstrInfo.h"
Chris Lattner54b866b2002-10-23 01:12:01 +000012#include "llvm/Constant.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000013#include "llvm/Function.h"
14#include "llvm/DerivedTypes.h"
15#include "llvm/Pass.h"
Misha Brukmanfce11432002-10-28 00:28:31 +000016#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner5a977d42002-12-28 20:42:56 +000017#include "llvm/CodeGen/MachineFunctionInfo.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000018
Chris Lattner5a977d42002-12-28 20:42:56 +000019namespace {
20 class StackSlots : public FunctionPass {
21 const TargetMachine &Target;
22 public:
23 StackSlots(const TargetMachine &T) : Target(T) {}
24
25 const char *getPassName() const {
26 return "Stack Slot Insertion for profiling code";
27 }
28
29 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
30 AU.setPreservesCFG();
31 }
32
33 bool runOnFunction(Function &F) {
34 const Type *PtrInt = PointerType::get(Type::IntTy);
35 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
36
37 Value *V = Constant::getNullValue(Type::IntTy);
38 MachineFunction::get(&F).getInfo()->allocateLocalVar(V, 2*Size);
39 return true;
40 }
41 };
42}
Anand Shukla33db9ba2002-09-21 04:58:26 +000043
Chris Lattner54b866b2002-10-23 01:12:01 +000044Pass *createStackSlotsPass(const TargetMachine &Target) {
45 return new StackSlots(Target);
Anand Shukla33db9ba2002-09-21 04:58:26 +000046}