Skip to content

Commit 04a9a0e

Browse files
committed
[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
1 parent fcc9c46 commit 04a9a0e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/tools/llvm-exegesis/lib/Assembler.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2222
#include "llvm/IR/LegacyPassManager.h"
2323
#include "llvm/MC/MCInstrInfo.h"
24+
#include "llvm/Support/Alignment.h"
2425
#include "llvm/Support/MemoryBuffer.h"
2526

2627
namespace llvm {
2728
namespace exegesis {
2829

2930
static constexpr const char ModuleID[] = "ExegesisInfoTest";
3031
static constexpr const char FunctionID[] = "foo";
32+
static const Align kFunctionAlignment(4096);
3133

3234
// Fills the given basic block with register setup code, and returns true if
3335
// all registers could be setup correctly.
@@ -169,13 +171,13 @@ void assembleToStream(const ExegesisTarget &ET,
169171
ArrayRef<unsigned> LiveIns,
170172
ArrayRef<RegisterValue> RegisterInitialValues,
171173
const FillFunction &Fill, raw_pwrite_stream &AsmStream) {
172-
std::unique_ptr<LLVMContext> Context = std::make_unique<LLVMContext>();
174+
auto Context = std::make_unique<LLVMContext>();
173175
std::unique_ptr<Module> Module =
174176
createModule(Context, TM->createDataLayout());
175-
std::unique_ptr<MachineModuleInfoWrapperPass> MMIWP =
176-
std::make_unique<MachineModuleInfoWrapperPass>(TM.get());
177+
auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(TM.get());
177178
MachineFunction &MF = createVoidVoidPtrMachineFunction(
178179
FunctionID, Module.get(), &MMIWP.get()->getMMI());
180+
MF.ensureAlignment(kFunctionAlignment);
179181

180182
// We need to instruct the passes that we're done with SSA and virtual
181183
// registers.
@@ -305,9 +307,11 @@ ExecutableFunction::ExecutableFunction(
305307
// executable page.
306308
ExecEngine->addObjectFile(std::move(ObjectFileHolder));
307309
// Fetching function bytes.
308-
FunctionBytes = StringRef(reinterpret_cast<const char *>(
309-
ExecEngine->getFunctionAddress(FunctionID)),
310-
CodeSize);
310+
const uint64_t FunctionAddress = ExecEngine->getFunctionAddress(FunctionID);
311+
assert(isAligned(kFunctionAlignment, FunctionAddress) &&
312+
"function is not properly aligned");
313+
FunctionBytes =
314+
StringRef(reinterpret_cast<const char *>(FunctionAddress), CodeSize);
311315
}
312316

313317
} // namespace exegesis

0 commit comments

Comments
 (0)