diff options
author | Nate Begeman <natebegeman@mac.com> | 2007-02-07 05:47:16 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2007-02-07 05:47:16 +0000 |
commit | c2b2d6a7c9c76693a45f316ca1f167dd185b33e4 (patch) | |
tree | d183ee362e42958355ed15780dbb8f611f6b1541 | |
parent | 58f84d4b2ddee76d594a1cdfeffaea6417ed0a20 (diff) | |
download | external_llvm-c2b2d6a7c9c76693a45f316ca1f167dd185b33e4.zip external_llvm-c2b2d6a7c9c76693a45f316ca1f167dd185b33e4.tar.gz external_llvm-c2b2d6a7c9c76693a45f316ca1f167dd185b33e4.tar.bz2 |
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
-rw-r--r-- | lib/CodeGen/MachOWriter.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp index d595852..e6cfeda 100644 --- a/lib/CodeGen/MachOWriter.cpp +++ b/lib/CodeGen/MachOWriter.cpp @@ -84,8 +84,8 @@ namespace llvm { 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 @@ namespace llvm { /// 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 @@ void MachOCodeEmitter::startFunction(MachineFunction &F) { /// 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 @@ bool MachOCodeEmitter::finishFunction(MachineFunction &F) { // 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 |