blob: 44103a614be97bbcda17822a7dac8863c32d337c [file] [log] [blame]
Anand Shukla33db9ba2002-09-21 04:58:26 +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
Chris Lattner48e60792003-08-13 02:38:16 +000016#include "SparcInternals.h"
Chris Lattner54b866b2002-10-23 01:12:01 +000017#include "llvm/Constant.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000018#include "llvm/Function.h"
19#include "llvm/DerivedTypes.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattner5a977d42002-12-28 20:42:56 +000021#include "llvm/CodeGen/MachineFunctionInfo.h"
Anand Shukla33db9ba2002-09-21 04:58:26 +000022
Chris Lattner5a977d42002-12-28 20:42:56 +000023namespace {
Chris Lattner3501fea2003-01-14 22:00:31 +000024 class StackSlots : public MachineFunctionPass {
Chris Lattner5a977d42002-12-28 20:42:56 +000025 const TargetMachine &Target;
26 public:
27 StackSlots(const TargetMachine &T) : Target(T) {}
28
29 const char *getPassName() const {
30 return "Stack Slot Insertion for profiling code";
31 }
32
33 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
34 AU.setPreservesCFG();
35 }
36
Chris Lattner3501fea2003-01-14 22:00:31 +000037 bool runOnMachineFunction(MachineFunction &MF) {
Chris Lattner5a977d42002-12-28 20:42:56 +000038 const Type *PtrInt = PointerType::get(Type::IntTy);
39 unsigned Size = Target.getTargetData().getTypeSize(PtrInt);
40
41 Value *V = Constant::getNullValue(Type::IntTy);
Chris Lattner3501fea2003-01-14 22:00:31 +000042 MF.getInfo()->allocateLocalVar(V, 2*Size);
Chris Lattner5a977d42002-12-28 20:42:56 +000043 return true;
44 }
45 };
46}
Anand Shukla33db9ba2002-09-21 04:58:26 +000047
Chris Lattner54b866b2002-10-23 01:12:01 +000048Pass *createStackSlotsPass(const TargetMachine &Target) {
49 return new StackSlots(Target);
Anand Shukla33db9ba2002-09-21 04:58:26 +000050}