blob: c7584d2c94d9913343f6a429cd72524f29c9bf5a [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"
16#include "llvm/CodeGen/MachineCodeForMethod.h"
17
Chris Lattner54b866b2002-10-23 01:12:01 +000018class StackSlots : public FunctionPass {
19 const TargetMachine &Target;
Anand Shukla33db9ba2002-09-21 04:58:26 +000020public:
Chris Lattner54b866b2002-10-23 01:12:01 +000021 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 }
Anand Shukla33db9ba2002-09-21 04:58:26 +000030
31 bool runOnFunction(Function &F) {
Chris Lattner54b866b2002-10-23 01:12:01 +000032 const Type *PtrInt = PointerType::get(Type::IntTy);
33 unsigned Size = Target.DataLayout.getTypeSize(PtrInt);
34
Anand Shukla33db9ba2002-09-21 04:58:26 +000035 MachineCodeForMethod &mcInfo = MachineCodeForMethod::get(&F);
Chris Lattner54b866b2002-10-23 01:12:01 +000036 Value *V = Constant::getNullValue(Type::IntTy);
37 mcInfo.allocateLocalVar(Target, V, 2*Size);
Anand Shukla33db9ba2002-09-21 04:58:26 +000038 return true;
39 }
40};
41
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}