Rearrange code, indent for the namespace, add the createMachineFunctionPrinterPass
[oota-llvm.git] / include / llvm / CodeGen / MachineFunction.h
index 0e0aa51036744e38522a9410ba401be72b5a150c..4f255598d385e76cbdd838e19d54f75d15b1491f 100644 (file)
@@ -1,8 +1,17 @@
 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
 // 
-// Collect native machine code information for a method.  This allows
-// target-specific information about the generated code to be stored with each
-// method.
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+// 
+// Collect native machine code for a function.  This class contains a list of
+// MachineBasicBlock instances that make up the current compiled function.
+//
+// This class also contains pointers to various classes which hold
+// target-specific information about the generated code.
 //   
 //===----------------------------------------------------------------------===//
 
 #define LLVM_CODEGEN_MACHINEFUNCTION_H
 
 #include "llvm/CodeGen/MachineBasicBlock.h"
-#include "llvm/CodeGen/SSARegMap.h"
-#include "llvm/Annotation.h"
-#include "Support/HashExtras.h"
-#include "Support/hash_set"
+#include "Support/Annotation.h"
 #include "Support/ilist"
 
-class Value;
+namespace llvm {
+
 class Function;
-class Constant;
-class Type;
 class TargetMachine;
-class Pass;
-
-Pass *createMachineCodeConstructionPass(TargetMachine &Target);
-Pass *createMachineCodeDestructionPass();
-Pass *createMachineFunctionPrinterPass();
+class SSARegMap;
+class MachineFunctionInfo;
+class MachineFrameInfo;
+class MachineConstantPool;
 
 class MachineFunction : private Annotation {
   const Function *Fn;
@@ -34,25 +38,21 @@ class MachineFunction : private Annotation {
   // List of machine basic blocks in function
   iplist<MachineBasicBlock> BasicBlocks;
 
-  // FIXME: State should be held elsewhere...
-  hash_set<const Constant*> constantsForConstPool;
-  hash_map<const Value*, int> offsets;
-  unsigned     staticStackSize;
-  unsigned     automaticVarsSize;
-  unsigned     regSpillsSize;
-  unsigned     maxOptionalArgsSize;
-  unsigned     maxOptionalNumArgs;
-  unsigned     currentTmpValuesSize;
-  unsigned     maxTmpValuesSize;
-  bool          compiledAsLeaf;
-  bool          spillsAreaFrozen;
-  bool          automaticVarsAreaFrozen;
-
   // Keeping track of mapping from SSA values to registers
   SSARegMap *SSARegMapping;
-  
+
+  // Used to keep track of frame and constant area information for sparc be
+  MachineFunctionInfo *MFInfo;
+
+  // Keep track of objects allocated on the stack.
+  MachineFrameInfo *FrameInfo;
+
+  // Keep track of constants which are spilled to memory
+  MachineConstantPool *ConstantPool;
+
 public:
-  MachineFunction(const Function *Fn, const TargetMachine& target);
+  MachineFunction(const Function *Fn, const TargetMachine &TM);
+  ~MachineFunction();
 
   /// getFunction - Return the LLVM function that this machine code represents
   ///
@@ -62,6 +62,28 @@ public:
   ///
   const TargetMachine &getTarget() const { return Target; }
 
+  /// SSARegMap Interface... Keep track of information about each SSA virtual
+  /// register, such as which register class it belongs to.
+  ///
+  SSARegMap *getSSARegMap() const { return SSARegMapping; }
+  void clearSSARegMap();
+
+  /// getFrameInfo - Return the frame info object for the current function.
+  /// This object contains information about objects allocated on the stack
+  /// frame of the current function in an abstract way.
+  ///
+  MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
+
+  /// getConstantPool - Return the constant pool object for the current
+  /// function.
+  MachineConstantPool *getConstantPool() const { return ConstantPool; }
+
+  /// MachineFunctionInfo - Keep track of various per-function pieces of
+  /// information for the sparc backend.
+  ///
+  MachineFunctionInfo *getInfo() const { return MFInfo; }
+
+
   /// print - Print out the MachineFunction in a format suitable for debugging
   /// to the specified stream.
   ///
@@ -71,11 +93,6 @@ public:
   ///
   void dump() const;
 
-  /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
-  /// staticStackSize fields...
-  ///
-  void CalculateArgSize();
-
   // The next three methods are used to construct, destruct, and retrieve the
   // MachineFunction object for the given method.
   //
@@ -83,25 +100,11 @@ public:
   // get()       -- Returns a handle to the object.
   //                This should not be called before "construct()"
   //                for a given Method.
-  // destruct()  -- Destroy the MachineFunction object
   // 
-  static MachineFunction& construct(const Function *Fn,
-                                    const TargetMachine &target);
+  static MachineFunction& construct(const Function *F, const TargetMachine &TM);
   static void destruct(const Function *F);
   static MachineFunction& get(const Function *F);
 
-  // Getting and storing SSARegMap information
-  const TargetRegisterClass* getRegClass(unsigned Reg) { 
-    return SSARegMapping->getRegClass(Reg);
-  }
-  void addRegMap(unsigned Reg, const TargetRegisterClass *RegClass) {
-    SSARegMapping->addRegMap(Reg, RegClass);
-  }
-  void clearSSARegMap() { 
-    delete SSARegMapping;
-    SSARegMapping = NULL;
-  }
-
   // Provide accessors for the MachineBasicBlock list...
   typedef iplist<MachineBasicBlock> BasicBlockListType;
   typedef BasicBlockListType::iterator iterator;
@@ -132,80 +135,8 @@ public:
         MachineBasicBlock &front()       { return BasicBlocks.front(); }
   const MachineBasicBlock & back() const { return BasicBlocks.back(); }
         MachineBasicBlock & back()       { return BasicBlocks.back(); }
-
-  //===--------------------------------------------------------------------===//
-  //
-  // FIXME: Most of the following state should be moved out to passes that use
-  // it, instead of being put here.
-  //
-
-  //
-  // 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;}
-  inline unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
-  inline const hash_set<const Constant*>&
-                  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; }
-  
-  int             computeOffsetforLocalVar (const TargetMachine& target,
-                                            const Value*  local,
-                                            unsigned int& getPaddedSize,
-                                            unsigned int  sizeToUse = 0);
-  int             allocateLocalVar         (const TargetMachine& target,
-                                            const Value* local,
-                                            unsigned int sizeToUse = 0);
-  
-  int             allocateSpilledValue     (const TargetMachine& target,
-                                            const Type* type);
-  
-  int             pushTempValue            (const TargetMachine& target,
-                                            unsigned int size);
-  
-  void            popAllTempValues         (const TargetMachine& target);
-  
-  void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
-  void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
-  
-  int             getOffset                (const Value* val) const;
-  
-  // int          getOffsetFromFP       (const Value* val) const;
-  
-private:
-  inline void     incrementAutomaticVarsSize(int incr) {
-    automaticVarsSize+= incr;
-    staticStackSize += incr;
-  }
-  inline void     incrementRegSpillsSize(int incr) {
-    regSpillsSize+= incr;
-    staticStackSize += incr;
-  }
-  inline void     incrementTmpAreaSize(int incr) {
-    currentTmpValuesSize += incr;
-    if (maxTmpValuesSize < currentTmpValuesSize)
-      {
-        staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
-        maxTmpValuesSize = currentTmpValuesSize;
-      }
-  }
-  inline void     resetTmpAreaSize() {
-    currentTmpValuesSize = 0;
-  }
-  int             allocateOptionalArg      (const TargetMachine& target,
-                                            const Type* type);
 };
 
+} // End llvm namespace
+
 #endif