Changes in directory llvm/lib/CodeGen:
MachOWriter.cpp updated: 1.22 -> 1.23 --- Log message: 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. --- Diffs of the changes: (+14 -11) MachOWriter.cpp | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-) Index: llvm/lib/CodeGen/MachOWriter.cpp diff -u llvm/lib/CodeGen/MachOWriter.cpp:1.22 llvm/lib/CodeGen/MachOWriter.cpp:1.23 --- llvm/lib/CodeGen/MachOWriter.cpp:1.22 Fri Feb 2 20:39:40 2007 +++ llvm/lib/CodeGen/MachOWriter.cpp Tue Feb 6 23:47:16 2007 @@ -84,8 +84,8 @@ isLittleEndian = TM.getTargetData()->isLittleEndian(); } - virtual void startFunction(MachineFunction &F); - virtual bool finishFunction(MachineFunction &F); + virtual void startFunction(MachineFunction &MF); + virtual bool finishFunction(MachineFunction &MF); virtual void addRelocation(const MachineRelocation &MR) { Relocations.push_back(MR); @@ -130,12 +130,15 @@ /// startFunction - This callback is invoked when a new machine function is /// 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. - // FIXME: MachineFunction or TargetData should probably carry an alignment - // field for functions that we can query here instead of hard coding 4 in both - // the object writer and asm printer. - unsigned Align = 4; + unsigned FnAlign = F->getAlignment(); + unsigned TDAlign = TD->getTypeAlignmentPref(F->getType()); + unsigned Align = Log2_32(std::max(FnAlign, TDAlign)); + assert(!(Align & (Align-1)) && "Alignment is not a power of two!"); // Get the Mach-O Section that this function belongs in. MachOWriter::MachOSection *MOS = MOW.getTextSection(); @@ -172,7 +175,7 @@ /// finishFunction - This callback is invoked after the function is completely /// finished. -bool MachOCodeEmitter::finishFunction(MachineFunction &F) { +bool MachOCodeEmitter::finishFunction(MachineFunction &MF) { // Get the Mach-O Section that this function belongs in. MachOWriter::MachOSection *MOS = MOW.getTextSection(); @@ -180,16 +183,16 @@ // FIXME: it seems like we should call something like AddSymbolToSection // in startFunction rather than changing the section size and symbol n_value // here. - const GlobalValue *FuncV = F.getFunction(); + const GlobalValue *FuncV = MF.getFunction(); MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TM); FnSym.n_value = MOS->size; MOS->size = CurBufferPtr - BufferBegin; // Emit constant pool to appropriate section(s) - emitConstantPool(F.getConstantPool()); + emitConstantPool(MF.getConstantPool()); // Emit jump tables to appropriate section - emitJumpTables(F.getJumpTableInfo()); + emitJumpTables(MF.getJumpTableInfo()); // If we have emitted any relocations to function-specific objects such as // basic blocks, constant pools entries, or jump tables, record their _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits