From 580631a73a71ff621c71618b16e9644b30a9d3c9 Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Sun, 20 Apr 2008 23:39:44 +0000 Subject: [PATCH] Be pessimistic in computing the buffer size when aligning. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50008 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp | 3 ++- lib/ExecutionEngine/JIT/JITEmitter.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp b/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp index b5a07377734..b73b0bd76c3 100644 --- a/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp @@ -664,7 +664,8 @@ unsigned JITDwarfEmitter::GetDwarfTableSizeInBytes(MachineFunction& F, /// the new value. static unsigned RoundUpToAlign(unsigned FinalSize, unsigned Alignment) { if (Alignment == 0) Alignment = 1; - return (FinalSize + Alignment - 1) & ~(Alignment - 1); + // Since we do not know where the buffer will be allocated, be pessimistic. + return FinalSize + Alignment; } unsigned diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 7492982cf47..f0857c100ef 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -623,9 +623,10 @@ static unsigned GetJumpTableSizeInBytes(MachineJumpTableInfo *MJTI) { return NumEntries * EntrySize; } -static void AddAlignment(uintptr_t& Size, unsigned Alignment) { +static uintptr_t RoundUpToAlign(uintptr_t Size, unsigned Alignment) { if (Alignment == 0) Alignment = 1; - Size = (Size + Alignment - 1) & (Alignment - 1); + // Since we do not know where the buffer will be allocated, be pessimistic. + return Size + Alignment; } void JITEmitter::startFunction(MachineFunction &F) { @@ -636,22 +637,24 @@ void JITEmitter::startFunction(MachineFunction &F) { MachineConstantPool *MCP = F.getConstantPool(); // Ensure the constant pool/jump table info is at least 4-byte aligned. - AddAlignment(ActualSize, 16); + ActualSize = RoundUpToAlign(ActualSize, 16); // Add the alignment of the constant pool - AddAlignment(ActualSize, 1 << MCP->getConstantPoolAlignment()); + ActualSize = RoundUpToAlign(ActualSize, + 1 << MCP->getConstantPoolAlignment()); // Add the constant pool size ActualSize += GetConstantPoolSizeInBytes(MCP); // Add the aligment of the jump table info - AddAlignment(ActualSize, MJTI->getAlignment()); + ActualSize = RoundUpToAlign(ActualSize, MJTI->getAlignment()); // Add the jump table size ActualSize += GetJumpTableSizeInBytes(MJTI); // Add the alignment for the function - AddAlignment(ActualSize, std::max(F.getFunction()->getAlignment(), 8U)); + ActualSize = RoundUpToAlign(ActualSize, + std::max(F.getFunction()->getAlignment(), 8U)); // Add the function size ActualSize += TII->GetFunctionSizeInBytes(F); -- 2.34.1