blob: 90aca0d86456a9519b2bdcb6e9fd71ac25a7800e [file] [log] [blame]
Brian Gaeke3ca4fcc2004-04-25 07:04:49 +00001//===- SparcV9StackSlots.cpp - Add empty stack slots to functions ---------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Anand Shukla33db9ba2002-09-21 04:58:26 +00009//
Chris Lattner54b866b2002-10-23 01:12:01 +000010// This pass adds 2 empty slots at the top of function stack. These two slots
11// are later used during code reoptimization for spilling the register values
12// when rewriting branches.
Anand Shukla33db9ba2002-09-21 04:58:26 +000013//
14//===----------------------------------------------------------------------===//
15
Brian Gaeke150666f2004-02-25 19:08:12 +000016#include "SparcV9Internals.h"
Chris Lattner54b866b2002-10-23 01:12:01 +000017#include "llvm/Constant.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000018#include "llvm/DerivedTypes.h"
Misha Brukman6d7aad12003-11-06 18:06:13 +000019#include "llvm/Function.h"
Misha Brukman6d7aad12003-11-06 18:06:13 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattner85015a02004-08-16 21:55:02 +000021#include "MachineFunctionInfo.h"
22using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000023
Chris Lattner5a977d42002-12-28 20:42:56 +000024namespace {
Chris Lattner3501fea2003-01-14 22:00:31 +000025 class StackSlots : public MachineFunctionPass {
Chris Lattner5a977d42002-12-28 20:42:56 +000026 const TargetMachine &Target;
27 public:
28 StackSlots(const TargetMachine &T) : Target(T) {}
29
30 const char *getPassName() const {
31 return "Stack Slot Insertion for profiling code";
32 }
33
34 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
35 AU.setPreservesCFG();
36 }
37
Chris Lattner3501fea2003-01-14 22:00:31 +000038 bool runOnMachineFunction(MachineFunction &MF) {
Chris Lattner5a977d42002-12-28 20:42:56 +000039 const Type *PtrInt = PointerType::get(Type::IntTy);
40 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
41
42 Value *V = Constant::getNullValue(Type::IntTy);
Chris Lattnera1e51ff2004-08-18 18:13:37 +000043 MF.getInfo<SparcV9FunctionInfo>()->allocateLocalVar(V, 2*Size);
Chris Lattner5a977d42002-12-28 20:42:56 +000044 return true;
45 }
46 };
47}
Anand Shukla33db9ba2002-09-21 04:58:26 +000048
Chris Lattner85015a02004-08-16 21:55:02 +000049Pass *llvm::createStackSlotsPass(const TargetMachine &Target) {
Chris Lattner54b866b2002-10-23 01:12:01 +000050 return new StackSlots(Target);
Anand Shukla33db9ba2002-09-21 04:58:26 +000051}
Brian Gaeked0fde302003-11-11 22:41:34 +000052