blob: e11effc4b13aebf95782722a7630a313673bfb7d [file] [log] [blame]
Misha Brukman6d7aad12003-11-06 18:06:13 +00001//===- StackSlots.cpp - Specialize LLVM code for target machine ----------===//
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"
Chris Lattner5a977d42002-12-28 20:42:56 +000020#include "llvm/CodeGen/MachineFunctionInfo.h"
Misha Brukman6d7aad12003-11-06 18:06:13 +000021#include "llvm/CodeGen/MachineFunctionPass.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000022
Brian Gaeked0fde302003-11-11 22:41:34 +000023namespace llvm {
24
Chris Lattner5a977d42002-12-28 20:42:56 +000025namespace {
Chris Lattner3501fea2003-01-14 22:00:31 +000026 class StackSlots : public MachineFunctionPass {
Chris Lattner5a977d42002-12-28 20:42:56 +000027 const TargetMachine &Target;
28 public:
29 StackSlots(const TargetMachine &T) : Target(T) {}
30
31 const char *getPassName() const {
32 return "Stack Slot Insertion for profiling code";
33 }
34
35 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36 AU.setPreservesCFG();
37 }
38
Chris Lattner3501fea2003-01-14 22:00:31 +000039 bool runOnMachineFunction(MachineFunction &MF) {
Chris Lattner5a977d42002-12-28 20:42:56 +000040 const Type *PtrInt = PointerType::get(Type::IntTy);
41 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
42
43 Value *V = Constant::getNullValue(Type::IntTy);
Chris Lattner3501fea2003-01-14 22:00:31 +000044 MF.getInfo()->allocateLocalVar(V, 2*Size);
Chris Lattner5a977d42002-12-28 20:42:56 +000045 return true;
46 }
47 };
48}
Anand Shukla33db9ba2002-09-21 04:58:26 +000049
Chris Lattner54b866b2002-10-23 01:12:01 +000050Pass *createStackSlotsPass(const TargetMachine &Target) {
51 return new StackSlots(Target);
Anand Shukla33db9ba2002-09-21 04:58:26 +000052}
Brian Gaeked0fde302003-11-11 22:41:34 +000053
54} // End llvm namespace