2002-09-21 04:58:26 +00:00
|
|
|
//===- StackSlots.cpp - Specialize LLVM code for target machine ---------===//
|
|
|
|
//
|
2002-10-23 01:12:01 +00:00
|
|
|
// This pass adds 2 empty slots at the top of function stack. These two slots
|
|
|
|
// are later used during code reoptimization for spilling the register values
|
|
|
|
// when rewriting branches.
|
2002-09-21 04:58:26 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-10-23 01:12:01 +00:00
|
|
|
#include "llvm/CodeGen/StackSlots.h"
|
2002-09-21 04:58:26 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/MachineInstrInfo.h"
|
2002-10-23 01:12:01 +00:00
|
|
|
#include "llvm/Constant.h"
|
2002-09-21 04:58:26 +00:00
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/CodeGen/MachineCodeForMethod.h"
|
|
|
|
|
2002-10-23 01:12:01 +00:00
|
|
|
class StackSlots : public FunctionPass {
|
|
|
|
const TargetMachine &Target;
|
|
|
|
public:
|
|
|
|
StackSlots (const TargetMachine &T) : Target(T) {}
|
2002-09-21 04:58:26 +00:00
|
|
|
|
2002-10-23 01:12:01 +00:00
|
|
|
const char *getPassName() const {
|
|
|
|
return "Stack Slot Insertion for profiling code";
|
|
|
|
}
|
2002-09-21 04:58:26 +00:00
|
|
|
|
2002-10-23 01:12:01 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
}
|
2002-09-21 04:58:26 +00:00
|
|
|
|
|
|
|
bool runOnFunction(Function &F) {
|
2002-10-23 01:12:01 +00:00
|
|
|
const Type *PtrInt = PointerType::get(Type::IntTy);
|
|
|
|
unsigned Size = Target.DataLayout.getTypeSize(PtrInt);
|
|
|
|
|
2002-09-21 04:58:26 +00:00
|
|
|
MachineCodeForMethod &mcInfo = MachineCodeForMethod::get(&F);
|
2002-10-23 01:12:01 +00:00
|
|
|
Value *V = Constant::getNullValue(Type::IntTy);
|
|
|
|
mcInfo.allocateLocalVar(Target, V, 2*Size);
|
2002-09-21 04:58:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-10-23 01:12:01 +00:00
|
|
|
Pass *createStackSlotsPass(const TargetMachine &Target) {
|
|
|
|
return new StackSlots(Target);
|
2002-09-21 04:58:26 +00:00
|
|
|
}
|