-//===-- CodeGen/FunctionFrameInfo.h - Abstract Stack Frame Rep --*- C++ -*-===//
-//
-// The FunctionFrameInfo class represents an abstract stack frame until
+//===-- CodeGen/MachineFrameInfo.h - Abstract Stack Frame Rep. --*- C++ -*-===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// The MachineFrameInfo class represents an abstract stack frame until
// prolog/epilog code is inserted. This class is key to allowing stack frame
// representation optimizations, such as frame pointer elimination. It also
// allows more mundane (but still important) optimizations, such as reordering
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CODEGEN_FUNCTIONFRAMEINFO_H
-#define LLVM_CODEGEN_FUNCTIONFRAMEINFO_H
+#ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
+#define LLVM_CODEGEN_MACHINEFRAMEINFO_H
+
+#include <vector>
-class FunctionFrameInfo {
+namespace llvm {
+class TargetData;
+class TargetRegisterClass;
+class Type;
+class MachineDebugInfo;
+class MachineFunction;
+
+class MachineFrameInfo {
// StackObject - Represent a single object allocated on the stack.
struct StackObject {
/// to be allocated on entry to the function.
///
unsigned StackSize;
+
+ /// MaxAlignment - The prolog/epilog code inserter may process objects
+ /// that require greater alignment than the default alignment the target
+ /// provides. To handle this, MaxAlignment is set to the maximum alignment
+ /// needed by the objects on the current frame. If this is greater than the
+ /// native alignment maintained by the compiler, dynamic alignment code will
+ /// be needed.
+ ///
+ unsigned MaxAlignment;
/// HasCalls - Set to true if this function has any function calls. This is
/// only valid during and after prolog/epilog code insertion.
/// insertion.
///
unsigned MaxCallFrameSize;
+
+ /// DebugInfo - This field is set (via setMachineDebugInfo) by a debug info
+ /// consumer (ex. DwarfWriter) to indicate that frame layout information
+ /// should be acquired. Typically, it's the responsibility of the target's
+ /// MRegisterInfo prologue/epilogue emitting code to inform MachineDebugInfo
+ /// of frame layouts.
+ MachineDebugInfo *DebugInfo;
+
public:
- FunctionFrameInfo() {
- NumFixedObjects = StackSize = 0;
+ MachineFrameInfo() {
+ NumFixedObjects = StackSize = MaxAlignment = 0;
HasVarSizedObjects = false;
HasCalls = false;
MaxCallFrameSize = 0;
+ DebugInfo = 0;
}
/// hasStackObjects - Return true if there are any stack objects in this
///
void setStackSize(unsigned Size) { StackSize = Size; }
+ /// getMaxAlignment - Return the alignment in bytes that this function must be
+ /// aligned to, which is greater than the default stack alignment provided by
+ /// the target.
+ ///
+ unsigned getMaxAlignment() const { return MaxAlignment; }
+
+ /// setMaxAlignment - Set the preferred alignment.
+ ///
+ void setMaxAlignment(unsigned Align) { MaxAlignment = Align; }
+
/// hasCalls - Return true if the current function has no function calls.
/// This is only valid during or after prolog/epilog code emission.
///
bool hasCalls() const { return HasCalls; }
void setHasCalls(bool V) { HasCalls = V; }
-
+
/// getMaxCallFrameSize - Return the maximum size of a call frame that must be
/// allocated for an outgoing function call. This is only available if
/// CallFrameSetup/Destroy pseudo instructions are used by the target, and
Objects.insert(Objects.begin(), StackObject(Size, 1, SPOffset));
return -++NumFixedObjects;
}
-
+
/// CreateStackObject - Create a new statically sized stack object, returning
/// a postive identifier to represent it.
///
int CreateStackObject(unsigned Size, unsigned Alignment) {
+ // Keep track of the maximum alignment.
+ if (MaxAlignment < Alignment) MaxAlignment = Alignment;
+
assert(Size != 0 && "Cannot allocate zero size stack objects!");
Objects.push_back(StackObject(Size, Alignment, -1));
return Objects.size()-NumFixedObjects-1;
}
- /// CreateVariableSizedObject - Notify the FunctionFrameInfo object that a
+ /// CreateVariableSizedObject - Notify the MachineFrameInfo object that a
/// variable sized object has been created. This must be created whenever a
/// variable sized object is created, whether or not the index returned is
/// actually used.
///
int CreateVariableSizedObject() {
HasVarSizedObjects = true;
+ if (MaxAlignment < 1) MaxAlignment = 1;
Objects.push_back(StackObject(0, 1, -1));
return Objects.size()-NumFixedObjects-1;
}
+ /// getMachineDebugInfo - Used by a prologue/epilogue emitter (MRegisterInfo)
+ /// to provide frame layout information.
+ MachineDebugInfo *getMachineDebugInfo() const { return DebugInfo; }
+
+ /// setMachineDebugInfo - Used by a debug consumer (DwarfWriter) to indicate
+ /// that frame layout information should be gathered.
+ void setMachineDebugInfo(MachineDebugInfo *DI) { DebugInfo = DI; }
+
/// print - Used by the MachineFunction printer to print information about
/// stack objects. Implemented in MachineFunction.cpp
///
- void print(std::ostream &OS) const;
+ void print(const MachineFunction &MF, std::ostream &OS) const;
- /// dump - Call print(std::cerr) to be called from the debugger.
- void dump() const;
+ /// dump - Call print(MF, std::cerr) to be called from the debugger.
+ void dump(const MachineFunction &MF) const;
};
+} // End llvm namespace
+
#endif