|
21 | 21 | #include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
22 | 22 | #include "llvm/IR/LegacyPassManager.h"
|
23 | 23 | #include "llvm/MC/MCInstrInfo.h"
|
| 24 | +#include "llvm/Support/Alignment.h" |
24 | 25 | #include "llvm/Support/MemoryBuffer.h"
|
25 | 26 |
|
26 | 27 | namespace llvm {
|
27 | 28 | namespace exegesis {
|
28 | 29 |
|
29 | 30 | static constexpr const char ModuleID[] = "ExegesisInfoTest";
|
30 | 31 | static constexpr const char FunctionID[] = "foo";
|
| 32 | +static const Align kFunctionAlignment(4096); |
31 | 33 |
|
32 | 34 | // Fills the given basic block with register setup code, and returns true if
|
33 | 35 | // all registers could be setup correctly.
|
@@ -169,13 +171,13 @@ void assembleToStream(const ExegesisTarget &ET,
|
169 | 171 | ArrayRef<unsigned> LiveIns,
|
170 | 172 | ArrayRef<RegisterValue> RegisterInitialValues,
|
171 | 173 | const FillFunction &Fill, raw_pwrite_stream &AsmStream) {
|
172 |
| - std::unique_ptr<LLVMContext> Context = std::make_unique<LLVMContext>(); |
| 174 | + auto Context = std::make_unique<LLVMContext>(); |
173 | 175 | std::unique_ptr<Module> Module =
|
174 | 176 | 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()); |
177 | 178 | MachineFunction &MF = createVoidVoidPtrMachineFunction(
|
178 | 179 | FunctionID, Module.get(), &MMIWP.get()->getMMI());
|
| 180 | + MF.ensureAlignment(kFunctionAlignment); |
179 | 181 |
|
180 | 182 | // We need to instruct the passes that we're done with SSA and virtual
|
181 | 183 | // registers.
|
@@ -305,9 +307,11 @@ ExecutableFunction::ExecutableFunction(
|
305 | 307 | // executable page.
|
306 | 308 | ExecEngine->addObjectFile(std::move(ObjectFileHolder));
|
307 | 309 | // 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); |
311 | 315 | }
|
312 | 316 |
|
313 | 317 | } // namespace exegesis
|
|
0 commit comments