From 04a9a0eb0dd459ee209d001eaaaf6c9a73b76869 Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Wed, 9 Oct 2019 14:25:08 +0000 Subject: [PATCH] [llvm-exegesis] Ensure that ExecutableFunction are aligned. Summary: Experiments show that this is the alignment we get (for ELF+Linux), but let's ensure that we have it. Reviewers: gchatelet Subscribers: tschuett, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68703 llvm-svn: 374170 --- llvm/tools/llvm-exegesis/lib/Assembler.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp index c19cac8..4067098 100644 --- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp +++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp @@ -21,6 +21,7 @@ #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/Support/Alignment.h" #include "llvm/Support/MemoryBuffer.h" namespace llvm { @@ -28,6 +29,7 @@ namespace exegesis { static constexpr const char ModuleID[] = "ExegesisInfoTest"; static constexpr const char FunctionID[] = "foo"; +static const Align kFunctionAlignment(4096); // Fills the given basic block with register setup code, and returns true if // all registers could be setup correctly. @@ -169,13 +171,13 @@ void assembleToStream(const ExegesisTarget &ET, ArrayRef LiveIns, ArrayRef RegisterInitialValues, const FillFunction &Fill, raw_pwrite_stream &AsmStream) { - std::unique_ptr Context = std::make_unique(); + auto Context = std::make_unique(); std::unique_ptr Module = createModule(Context, TM->createDataLayout()); - std::unique_ptr MMIWP = - std::make_unique(TM.get()); + auto MMIWP = std::make_unique(TM.get()); MachineFunction &MF = createVoidVoidPtrMachineFunction( FunctionID, Module.get(), &MMIWP.get()->getMMI()); + MF.ensureAlignment(kFunctionAlignment); // We need to instruct the passes that we're done with SSA and virtual // registers. @@ -305,9 +307,11 @@ ExecutableFunction::ExecutableFunction( // executable page. ExecEngine->addObjectFile(std::move(ObjectFileHolder)); // Fetching function bytes. - FunctionBytes = StringRef(reinterpret_cast( - ExecEngine->getFunctionAddress(FunctionID)), - CodeSize); + const uint64_t FunctionAddress = ExecEngine->getFunctionAddress(FunctionID); + assert(isAligned(kFunctionAlignment, FunctionAddress) && + "function is not properly aligned"); + FunctionBytes = + StringRef(reinterpret_cast(FunctionAddress), CodeSize); } } // namespace exegesis -- 2.7.4