Add an "alignment" field to the MachineFunction object. It makes more sense to

have the alignment be calculated up front, and have the back-ends obey whatever
alignment is decided upon.

This allows for future work that would allow for precise no-op placement and the
like.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74564 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2009-06-30 22:38:32 +00:00
parent 73b8f16b36
commit 20c568f366
35 changed files with 122 additions and 36 deletions

View File

@ -111,6 +111,9 @@ class MachineFunction : private Annotation {
// Tracks debug locations.
DebugLocTracker DebugLocInfo;
// The alignment of the function.
unsigned Alignment;
public:
MachineFunction(const Function *Fn, const TargetMachine &TM);
~MachineFunction();
@ -148,6 +151,14 @@ public:
MachineConstantPool *getConstantPool() { return ConstantPool; }
const MachineConstantPool *getConstantPool() const { return ConstantPool; }
/// getAlignment - Return the alignment of the function.
///
unsigned getAlignment() const { return Alignment; }
/// setAlignment - Set the alignment of the function.
///
void setAlignment(unsigned A) { Alignment = A; }
/// MachineFunctionInfo - Keep track of various per-function pieces of
/// information for backends that would like to do so.
///

View File

@ -736,6 +736,9 @@ public:
/// PIC relocation models.
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
/// getFunctionAlignment - Return the alignment of this function.
virtual unsigned getFunctionAlignment(const Function *) const = 0;
//===--------------------------------------------------------------------===//
// TargetLowering Optimization Methods
//

View File

@ -14,6 +14,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Config/config.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
@ -22,15 +26,12 @@
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Config/config.h"
#include <fstream>
#include <sstream>
using namespace llvm;
@ -124,6 +125,7 @@ MachineFunction::MachineFunction(const Function *F,
MachineFrameInfo(*TM.getFrameInfo());
ConstantPool = new (Allocator.Allocate<MachineConstantPool>())
MachineConstantPool(TM.getTargetData());
Alignment = TM.getTargetLowering()->getFunctionAlignment(F);
// Set up jump table.
const TargetData &TD = *TM.getTargetData();

View File

@ -455,6 +455,11 @@ const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
}
}
/// getFunctionAlignment - Return the alignment of this function.
unsigned ARMTargetLowering::getFunctionAlignment(const Function *F) const {
return getTargetMachine().getSubtarget<ARMSubtarget>().isThumb() ? 1 : 2;
}
//===----------------------------------------------------------------------===//
// Lowering Code
//===----------------------------------------------------------------------===//

View File

@ -197,6 +197,9 @@ namespace llvm {
return Subtarget;
}
/// getFunctionAlignment - Return the alignment of this function.
virtual unsigned getFunctionAlignment(const Function *F) const;
private:
/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
/// make the right decision when generating code for different targets.

View File

@ -235,15 +235,16 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printVisibility(CurrentFnName, F->getVisibility());
if (AFI->isThumbFunction()) {
EmitAlignment(1, F, AFI->getAlign());
EmitAlignment(MF.getAlignment(), F, AFI->getAlign());
O << "\t.code\t16\n";
O << "\t.thumb_func";
if (Subtarget->isTargetDarwin())
O << "\t" << CurrentFnName;
O << "\n";
InCPMode = false;
} else
EmitAlignment(2, F);
} else {
EmitAlignment(MF.getAlignment(), F);
}
O << CurrentFnName << ":\n";
// Emit pre-function debug information.

View File

@ -181,6 +181,11 @@ const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
}
}
/// getFunctionAlignment - Return the function alignment.
unsigned AlphaTargetLowering::getFunctionAlignment(const Function *F) const {
return 4;
}
static SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
MVT PtrVT = Op.getValueType();
JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);

View File

@ -103,6 +103,9 @@ namespace llvm {
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *F) const;
private:
// Helpers for custom lowering.
void LowerVAARG(SDNode *N, SDValue &Chain, SDValue &DataPtr,

View File

@ -155,7 +155,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
const Function *F = MF.getFunction();
SwitchToSection(TAI->SectionForGlobal(F));
EmitAlignment(4, F);
EmitAlignment(MF.getAlignment(), F);
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.

View File

@ -433,7 +433,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
const Function *F = MF.getFunction();
SwitchToSection(TAI->SectionForGlobal(F));
EmitAlignment(3, F);
EmitAlignment(MF.getAlignment(), F);
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");

View File

@ -481,6 +481,11 @@ SPUTargetLowering::getTargetNodeName(unsigned Opcode) const
return ((i != node_names.end()) ? i->second : 0);
}
/// getFunctionAlignment - Return the function alignment.
unsigned SPUTargetLowering::getFunctionAlignment(const Function *) const {
return 3;
}
//===----------------------------------------------------------------------===//
// Return the Cell SPU's SETCC result type
//===----------------------------------------------------------------------===//

View File

@ -148,6 +148,9 @@ namespace llvm {
virtual bool isLegalAddressImmediate(GlobalValue *) const;
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *F) const;
};
}

View File

@ -137,7 +137,7 @@ bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
SwitchToSection(TAI->SectionForGlobal(F));
// Print out labels for the function.
EmitAlignment(5);
EmitAlignment(MF.getAlignment());
O << "\t.global\t" << CurrentFnName << '\n';
printVisibility(CurrentFnName, F->getVisibility());

View File

@ -148,6 +148,11 @@ MVT IA64TargetLowering::getSetCCResultType(MVT VT) const {
return MVT::i1;
}
/// getFunctionAlignment - Return the function alignment.
unsigned IA64TargetLowering::getFunctionAlignment(const Function *) const {
return 5;
}
void IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG,
SmallVectorImpl<SDValue> &ArgValues,
DebugLoc dl) {

View File

@ -70,6 +70,8 @@ namespace llvm {
/// (currently, only "ret void")
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *F) const;
};
}

View File

@ -97,10 +97,7 @@ void MSP430AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
SwitchToSection(TAI->SectionForGlobal(F));
unsigned FnAlign = 4;
if (F->hasFnAttr(Attribute::OptimizeForSize))
FnAlign = 1;
unsigned FnAlign = MF.getAlignment();
EmitAlignment(FnAlign, F);
switch (F->getLinkage()) {

View File

@ -127,6 +127,11 @@ SDValue MSP430TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
}
}
/// getFunctionAlignment - Return the alignment of this function.
unsigned MSP430TargetLowering::getFunctionAlignment(const Function *F) const {
return F->hasFnAttr(Attribute::OptimizeForSize) ? 1 : 4;
}
//===----------------------------------------------------------------------===//
// Calling Convention Implementation
//===----------------------------------------------------------------------===//

View File

@ -74,6 +74,9 @@ namespace llvm {
/// DAG node.
virtual const char *getTargetNodeName(unsigned Opcode) const;
/// getFunctionAlignment - Return the alignment of this function.
virtual unsigned getFunctionAlignment(const Function *F) const;
SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
SDValue LowerRET(SDValue Op, SelectionDAG &DAG);

View File

@ -230,7 +230,7 @@ emitFunctionStart(MachineFunction &MF)
SwitchToSection(TAI->SectionForGlobal(F));
// 2 bits aligned
EmitAlignment(2, F);
EmitAlignment(MF.getAlignment(), F);
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.ent\t" << CurrentFnName << '\n';

View File

@ -154,11 +154,14 @@ MipsTargetLowering(MipsTargetMachine &TM): TargetLowering(TM)
computeRegisterProperties();
}
MVT MipsTargetLowering::getSetCCResultType(MVT VT) const {
return MVT::i32;
}
/// getFunctionAlignment - Return the function alignment.
unsigned MipsTargetLowering::getFunctionAlignment(const Function *) const {
return 2;
}
SDValue MipsTargetLowering::
LowerOperation(SDValue Op, SelectionDAG &DAG)

View File

@ -84,6 +84,8 @@ namespace llvm {
/// getSetCCResultType - get the ISD::SETCC result ValueType
MVT getSetCCResultType(MVT VT) const;
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *F) const;
private:
// Subtarget Info
const MipsSubtarget *Subtarget;

View File

@ -145,6 +145,11 @@ namespace llvm {
unsigned GetTmpSize() { return TmpSize; }
void SetTmpSize(unsigned Size) { TmpSize = Size; }
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *) const {
// FIXME: The function never seems to be aligned.
return 1;
}
private:
// If the Node is a BUILD_PAIR representing a direct Address,
// then this function will return true.

View File

@ -596,7 +596,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printVisibility(CurrentFnName, F->getVisibility());
EmitAlignment(2, F);
EmitAlignment(MF.getAlignment(), F);
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
@ -773,7 +773,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printVisibility(CurrentFnName, F->getVisibility());
EmitAlignment(F->hasFnAttr(Attribute::OptimizeForSize) ? 2 : 4, F);
EmitAlignment(MF.getAlignment(), F);
O << CurrentFnName << ":\n";
// Emit pre-function debug information.

View File

@ -428,11 +428,17 @@ const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
}
}
MVT PPCTargetLowering::getSetCCResultType(MVT VT) const {
return MVT::i32;
}
/// getFunctionAlignment - Return the function alignment.
unsigned PPCTargetLowering::getFunctionAlignment(const Function *F) const {
if (getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin())
return F->hasFnAttr(Attribute::OptimizeForSize) ? 2 : 4;
else
return 2;
}
//===----------------------------------------------------------------------===//
// Node matching predicates, for use by the tblgen matching code.

View File

@ -337,6 +337,9 @@ namespace llvm {
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *F) const;
private:
SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;

View File

@ -109,7 +109,7 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out the label for the function.
const Function *F = MF.getFunction();
SwitchToSection(TAI->SectionForGlobal(F));
EmitAlignment(4, F);
EmitAlignment(MF.getAlignment(), F);
O << "\t.globl\t" << CurrentFnName << '\n';
printVisibility(CurrentFnName, F->getVisibility());

View File

@ -1047,3 +1047,8 @@ SparcTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
// The Sparc target isn't yet aware of offsets.
return false;
}
/// getFunctionAlignment - Return the function alignment.
unsigned SparcTargetLowering::getFunctionAlignment(const Function *) const {
return 4;
}

View File

@ -73,6 +73,9 @@ namespace llvm {
MVT VT) const;
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
/// getFunctionAlignment - Return the function alignment.
virtual unsigned getFunctionAlignment(const Function *F) const;
};
} // end namespace llvm

View File

@ -154,21 +154,13 @@ void X86ATTAsmPrinter::decorateName(std::string &Name,
}
}
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
unsigned FnAlign = MF.getAlignment();
const Function *F = MF.getFunction();
decorateName(CurrentFnName, F);
SwitchToSection(TAI->SectionForGlobal(F));
// FIXME: A function's alignment should be part of MachineFunction. There
// shouldn't be a policy decision here.
unsigned FnAlign = 4;
if (F->hasFnAttr(Attribute::OptimizeForSize))
FnAlign = 1;
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.

View File

@ -132,6 +132,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out labels for the function.
const Function *F = MF.getFunction();
unsigned CC = F->getCallingConv();
unsigned FnAlign = MF.getAlignment();
// Populate function information map. Actually, We don't want to populate
// non-stdcall or non-fastcall functions' information right now.
@ -141,10 +142,6 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
decorateName(CurrentFnName, F);
SwitchToTextSection("_text", F);
unsigned FnAlign = 4;
if (F->hasFnAttr(Attribute::OptimizeForSize))
FnAlign = 1;
switch (F->getLinkage()) {
default: assert(0 && "Unsupported linkage type!");
case Function::PrivateLinkage:

View File

@ -1027,6 +1027,11 @@ SDValue X86TargetLowering::getPICJumpTableRelocBase(SDValue Table,
return Table;
}
/// getFunctionAlignment - Return the alignment of this function.
unsigned X86TargetLowering::getFunctionAlignment(const Function *F) const {
return F->hasFnAttr(Attribute::OptimizeForSize) ? 1 : 4;
}
//===----------------------------------------------------------------------===//
// Return Value Calling Convention Implementation
//===----------------------------------------------------------------------===//

View File

@ -380,7 +380,7 @@ namespace llvm {
MVT getOptimalMemOpType(uint64_t Size, unsigned Align,
bool isSrcConst, bool isSrcStr,
SelectionDAG &DAG) const;
/// LowerOperation - Provide custom lowering hooks for some operations.
///
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
@ -533,7 +533,10 @@ namespace llvm {
, SmallSet<Instruction*, 8> &
#endif
);
/// getFunctionAlignment - Return the alignment of this function.
virtual unsigned getFunctionAlignment(const Function *F) const;
private:
/// Subtarget - Keep a pointer to the X86Subtarget around so that we can
/// make the right decision when generating code for different targets.

View File

@ -277,7 +277,7 @@ emitFunctionStart(MachineFunction &MF)
break;
}
// (1 << 1) byte aligned
EmitAlignment(1, F, 1);
EmitAlignment(MF.getAlignment(), F, 1);
if (TAI->hasDotTypeDotSizeDirective()) {
O << "\t.type " << CurrentFnName << ",@function\n";
}

View File

@ -187,6 +187,12 @@ void XCoreTargetLowering::ReplaceNodeResults(SDNode *N,
}
}
/// getFunctionAlignment - Return the alignment of this function.
unsigned XCoreTargetLowering::
getFunctionAlignment(const Function *) const {
return 1;
}
//===----------------------------------------------------------------------===//
// Misc Lower Operation implementation
//===----------------------------------------------------------------------===//

View File

@ -84,6 +84,9 @@ namespace llvm {
virtual bool isLegalAddressingMode(const AddrMode &AM,
const Type *Ty) const;
/// getFunctionAlignment - Return the alignment of this function.
virtual unsigned getFunctionAlignment(const Function *F) const;
private:
const XCoreTargetMachine &TM;
const XCoreSubtarget &Subtarget;