Fix a fixme by correctly calculating preferred alignments for functions,

based on the alignment of the symbol and the target data's preferred align
for that type.

Also, rename some arguments for consistency.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33984 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nate Begeman 2007-02-07 05:47:16 +00:00
parent 58f84d4b2d
commit c2b2d6a7c9

View File

@ -84,8 +84,8 @@ namespace llvm {
isLittleEndian = TM.getTargetData()->isLittleEndian(); isLittleEndian = TM.getTargetData()->isLittleEndian();
} }
virtual void startFunction(MachineFunction &F); virtual void startFunction(MachineFunction &MF);
virtual bool finishFunction(MachineFunction &F); virtual bool finishFunction(MachineFunction &MF);
virtual void addRelocation(const MachineRelocation &MR) { virtual void addRelocation(const MachineRelocation &MR) {
Relocations.push_back(MR); Relocations.push_back(MR);
@ -130,12 +130,15 @@ namespace llvm {
/// startFunction - This callback is invoked when a new machine function is /// startFunction - This callback is invoked when a new machine function is
/// about to be emitted. /// about to be emitted.
void MachOCodeEmitter::startFunction(MachineFunction &F) { void MachOCodeEmitter::startFunction(MachineFunction &MF) {
const TargetData *TD = TM.getTargetData();
const Function *F = MF.getFunction();
// Align the output buffer to the appropriate alignment, power of 2. // Align the output buffer to the appropriate alignment, power of 2.
// FIXME: MachineFunction or TargetData should probably carry an alignment unsigned FnAlign = F->getAlignment();
// field for functions that we can query here instead of hard coding 4 in both unsigned TDAlign = TD->getTypeAlignmentPref(F->getType());
// the object writer and asm printer. unsigned Align = Log2_32(std::max(FnAlign, TDAlign));
unsigned Align = 4; assert(!(Align & (Align-1)) && "Alignment is not a power of two!");
// Get the Mach-O Section that this function belongs in. // Get the Mach-O Section that this function belongs in.
MachOWriter::MachOSection *MOS = MOW.getTextSection(); MachOWriter::MachOSection *MOS = MOW.getTextSection();
@ -172,7 +175,7 @@ void MachOCodeEmitter::startFunction(MachineFunction &F) {
/// finishFunction - This callback is invoked after the function is completely /// finishFunction - This callback is invoked after the function is completely
/// finished. /// finished.
bool MachOCodeEmitter::finishFunction(MachineFunction &F) { bool MachOCodeEmitter::finishFunction(MachineFunction &MF) {
// Get the Mach-O Section that this function belongs in. // Get the Mach-O Section that this function belongs in.
MachOWriter::MachOSection *MOS = MOW.getTextSection(); MachOWriter::MachOSection *MOS = MOW.getTextSection();
@ -180,16 +183,16 @@ bool MachOCodeEmitter::finishFunction(MachineFunction &F) {
// FIXME: it seems like we should call something like AddSymbolToSection // FIXME: it seems like we should call something like AddSymbolToSection
// in startFunction rather than changing the section size and symbol n_value // in startFunction rather than changing the section size and symbol n_value
// here. // here.
const GlobalValue *FuncV = F.getFunction(); const GlobalValue *FuncV = MF.getFunction();
MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TM); MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TM);
FnSym.n_value = MOS->size; FnSym.n_value = MOS->size;
MOS->size = CurBufferPtr - BufferBegin; MOS->size = CurBufferPtr - BufferBegin;
// Emit constant pool to appropriate section(s) // Emit constant pool to appropriate section(s)
emitConstantPool(F.getConstantPool()); emitConstantPool(MF.getConstantPool());
// Emit jump tables to appropriate section // Emit jump tables to appropriate section
emitJumpTables(F.getJumpTableInfo()); emitJumpTables(MF.getJumpTableInfo());
// If we have emitted any relocations to function-specific objects such as // If we have emitted any relocations to function-specific objects such as
// basic blocks, constant pools entries, or jump tables, record their // basic blocks, constant pools entries, or jump tables, record their