2002-10-28 01:27:51 +00:00
|
|
|
//===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
|
2002-02-03 07:54:50 +00:00
|
|
|
//
|
2002-10-28 00:28:31 +00:00
|
|
|
// Collect native machine code information for a method. This allows
|
|
|
|
// target-specific information about the generated code to be stored with each
|
|
|
|
// method.
|
|
|
|
//
|
2002-02-03 07:54:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-10-28 00:28:31 +00:00
|
|
|
#ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEFUNCTION_H
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2002-10-28 02:01:06 +00:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2002-10-28 05:30:46 +00:00
|
|
|
#include "llvm/Annotation.h"
|
2002-02-03 07:54:50 +00:00
|
|
|
#include "Support/HashExtras.h"
|
2002-10-28 02:08:43 +00:00
|
|
|
#include "Support/hash_set"
|
|
|
|
#include "Support/ilist"
|
|
|
|
|
2002-02-03 07:54:50 +00:00
|
|
|
class Value;
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2002-02-03 07:54:50 +00:00
|
|
|
class Constant;
|
|
|
|
class Type;
|
|
|
|
class TargetMachine;
|
2002-10-28 01:11:58 +00:00
|
|
|
class Pass;
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2002-10-28 01:11:58 +00:00
|
|
|
Pass *createMachineCodeConstructionPass(TargetMachine &Target);
|
|
|
|
Pass *createMachineCodeDestructionPass();
|
2002-02-03 07:54:50 +00:00
|
|
|
|
2002-10-28 00:28:31 +00:00
|
|
|
class MachineFunction : private Annotation {
|
2002-10-28 05:58:46 +00:00
|
|
|
const Function *Fn;
|
|
|
|
const TargetMachine &Target;
|
2002-10-28 02:08:43 +00:00
|
|
|
|
|
|
|
// List of machine basic blocks in function
|
|
|
|
iplist<MachineBasicBlock> BasicBlocks;
|
2002-10-28 01:27:51 +00:00
|
|
|
|
|
|
|
// FIXME: State should be held elsewhere...
|
2002-10-28 02:08:43 +00:00
|
|
|
hash_set<const Constant*> constantsForConstPool;
|
|
|
|
hash_map<const Value*, int> offsets;
|
2002-02-03 07:54:50 +00:00
|
|
|
unsigned staticStackSize;
|
|
|
|
unsigned automaticVarsSize;
|
|
|
|
unsigned regSpillsSize;
|
|
|
|
unsigned maxOptionalArgsSize;
|
2002-04-25 04:47:26 +00:00
|
|
|
unsigned maxOptionalNumArgs;
|
2002-02-03 07:54:50 +00:00
|
|
|
unsigned currentTmpValuesSize;
|
2002-03-31 18:57:49 +00:00
|
|
|
unsigned maxTmpValuesSize;
|
2002-04-25 04:47:26 +00:00
|
|
|
bool compiledAsLeaf;
|
|
|
|
bool spillsAreaFrozen;
|
|
|
|
bool automaticVarsAreaFrozen;
|
2002-02-03 07:54:50 +00:00
|
|
|
|
|
|
|
public:
|
2002-10-28 05:58:46 +00:00
|
|
|
MachineFunction(const Function *Fn, const TargetMachine& target);
|
|
|
|
|
2002-10-29 23:40:30 +00:00
|
|
|
|
|
|
|
/// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
|
|
|
|
/// staticStackSize fields...
|
|
|
|
///
|
|
|
|
void CalculateArgSize();
|
|
|
|
|
2002-10-28 05:58:46 +00:00
|
|
|
/// getFunction - Return the LLVM function that this machine code represents
|
|
|
|
///
|
|
|
|
const Function *getFunction() const { return Fn; }
|
|
|
|
|
|
|
|
/// getTarget - Return the target machine this machine code is compiled with
|
|
|
|
///
|
|
|
|
const TargetMachine &getTarget() const { return Target; }
|
2002-02-03 07:54:50 +00:00
|
|
|
|
|
|
|
// The next two methods are used to construct and to retrieve
|
2002-10-28 00:28:31 +00:00
|
|
|
// the MachineFunction object for the given method.
|
2002-02-03 07:54:50 +00:00
|
|
|
// construct() -- Allocates and initializes for a given method and target
|
|
|
|
// get() -- Returns a handle to the object.
|
|
|
|
// This should not be called before "construct()"
|
|
|
|
// for a given Method.
|
|
|
|
//
|
2002-10-28 05:58:46 +00:00
|
|
|
static MachineFunction& construct(const Function *Fn,
|
|
|
|
const TargetMachine &target);
|
2002-03-23 22:51:58 +00:00
|
|
|
static void destruct(const Function *F);
|
2002-10-28 05:30:46 +00:00
|
|
|
static MachineFunction& get(const Function *F);
|
|
|
|
|
|
|
|
// Provide accessors for the MachineBasicBlock list...
|
|
|
|
typedef iplist<MachineBasicBlock> BasicBlockListType;
|
|
|
|
typedef BasicBlockListType::iterator iterator;
|
|
|
|
typedef BasicBlockListType::const_iterator const_iterator;
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
|
|
|
|
// Provide accessors for basic blocks...
|
|
|
|
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
|
|
|
|
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// BasicBlock iterator forwarding functions
|
|
|
|
//
|
|
|
|
iterator begin() { return BasicBlocks.begin(); }
|
|
|
|
const_iterator begin() const { return BasicBlocks.begin(); }
|
|
|
|
iterator end () { return BasicBlocks.end(); }
|
|
|
|
const_iterator end () const { return BasicBlocks.end(); }
|
|
|
|
|
|
|
|
reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
|
|
|
|
const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
|
|
|
|
reverse_iterator rend () { return BasicBlocks.rend(); }
|
|
|
|
const_reverse_iterator rend () const { return BasicBlocks.rend(); }
|
2002-10-28 01:27:51 +00:00
|
|
|
|
2002-10-28 05:30:46 +00:00
|
|
|
unsigned size() const { return BasicBlocks.size(); }
|
|
|
|
bool empty() const { return BasicBlocks.empty(); }
|
|
|
|
const MachineBasicBlock &front() const { return BasicBlocks.front(); }
|
|
|
|
MachineBasicBlock &front() { return BasicBlocks.front(); }
|
2002-10-28 19:58:38 +00:00
|
|
|
const MachineBasicBlock & back() const { return BasicBlocks.back(); }
|
|
|
|
MachineBasicBlock & back() { return BasicBlocks.back(); }
|
2002-10-28 01:27:51 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// FIXME: Most of the following state should be moved out to passes that use
|
|
|
|
// it, instead of being put here.
|
|
|
|
//
|
|
|
|
|
2002-02-03 07:54:50 +00:00
|
|
|
//
|
|
|
|
// Accessors for global information about generated code for a method.
|
|
|
|
//
|
|
|
|
inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
|
|
|
|
inline unsigned getStaticStackSize() const { return staticStackSize; }
|
|
|
|
inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
|
|
|
|
inline unsigned getRegSpillsSize() const { return regSpillsSize; }
|
|
|
|
inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
|
2002-04-25 04:47:26 +00:00
|
|
|
inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
|
2002-07-24 21:21:33 +00:00
|
|
|
inline const hash_set<const Constant*>&
|
2002-02-03 07:54:50 +00:00
|
|
|
getConstantPoolValues() const {return constantsForConstPool;}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Modifiers used during code generation
|
|
|
|
//
|
|
|
|
void initializeFrameLayout (const TargetMachine& target);
|
|
|
|
|
|
|
|
void addToConstantPool (const Constant* constVal)
|
|
|
|
{ constantsForConstPool.insert(constVal); }
|
|
|
|
|
|
|
|
inline void markAsLeafMethod() { compiledAsLeaf = true; }
|
|
|
|
|
2002-03-18 03:23:29 +00:00
|
|
|
int computeOffsetforLocalVar (const TargetMachine& target,
|
2002-04-25 04:47:26 +00:00
|
|
|
const Value* local,
|
2002-03-24 03:57:38 +00:00
|
|
|
unsigned int& getPaddedSize,
|
|
|
|
unsigned int sizeToUse = 0);
|
2002-02-03 07:54:50 +00:00
|
|
|
int allocateLocalVar (const TargetMachine& target,
|
|
|
|
const Value* local,
|
2002-03-24 03:57:38 +00:00
|
|
|
unsigned int sizeToUse = 0);
|
2002-02-03 07:54:50 +00:00
|
|
|
|
|
|
|
int allocateSpilledValue (const TargetMachine& target,
|
|
|
|
const Type* type);
|
|
|
|
|
|
|
|
int pushTempValue (const TargetMachine& target,
|
|
|
|
unsigned int size);
|
|
|
|
|
|
|
|
void popAllTempValues (const TargetMachine& target);
|
|
|
|
|
2002-04-25 04:47:26 +00:00
|
|
|
void freezeSpillsArea () { spillsAreaFrozen = true; }
|
|
|
|
void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
|
|
|
|
|
2002-02-03 07:54:50 +00:00
|
|
|
int getOffset (const Value* val) const;
|
|
|
|
|
|
|
|
// int getOffsetFromFP (const Value* val) const;
|
|
|
|
|
|
|
|
void dump () const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
inline void incrementAutomaticVarsSize(int incr) {
|
|
|
|
automaticVarsSize+= incr;
|
|
|
|
staticStackSize += incr;
|
|
|
|
}
|
|
|
|
inline void incrementRegSpillsSize(int incr) {
|
|
|
|
regSpillsSize+= incr;
|
|
|
|
staticStackSize += incr;
|
|
|
|
}
|
2002-03-31 18:57:49 +00:00
|
|
|
inline void incrementTmpAreaSize(int incr) {
|
|
|
|
currentTmpValuesSize += incr;
|
|
|
|
if (maxTmpValuesSize < currentTmpValuesSize)
|
|
|
|
{
|
|
|
|
staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
|
|
|
|
maxTmpValuesSize = currentTmpValuesSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline void resetTmpAreaSize() {
|
|
|
|
currentTmpValuesSize = 0;
|
|
|
|
}
|
2002-04-25 04:47:26 +00:00
|
|
|
int allocateOptionalArg (const TargetMachine& target,
|
|
|
|
const Type* type);
|
2002-02-03 07:54:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|