blob: 523cb913885e78aa859aef934df92c2362713eda [file] [log] [blame]
Clement Courbet0e69e2d2018-05-17 10:52:18 +00001//===-- Assembler.cpp -------------------------------------------*- C++ -*-===//
Clement Courbetac74acd2018-04-04 11:37:06 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Clement Courbetac74acd2018-04-04 11:37:06 +00006//
7//===----------------------------------------------------------------------===//
8
Clement Courbet0e69e2d2018-05-17 10:52:18 +00009#include "Assembler.h"
10
Clement Courbet9431b722019-09-27 12:56:24 +000011#include "SnippetRepetitor.h"
Clement Courbet6fd00e32018-06-20 11:54:35 +000012#include "Target.h"
Reid Kleckner1d7b4132019-10-19 00:22:07 +000013#include "llvm/Analysis/TargetLibraryInfo.h"
Clement Courbet559d1e32018-05-15 07:40:21 +000014#include "llvm/CodeGen/GlobalISel/CallLowering.h"
15#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "llvm/CodeGen/MachineModuleInfo.h"
18#include "llvm/CodeGen/MachineRegisterInfo.h"
19#include "llvm/CodeGen/TargetInstrInfo.h"
20#include "llvm/CodeGen/TargetPassConfig.h"
Clement Courbet0e69e2d2018-05-17 10:52:18 +000021#include "llvm/CodeGen/TargetSubtargetInfo.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000022#include "llvm/ExecutionEngine/SectionMemoryManager.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000023#include "llvm/IR/LegacyPassManager.h"
Clement Courbet0e69e2d2018-05-17 10:52:18 +000024#include "llvm/MC/MCInstrInfo.h"
Clement Courbet04a9a0e2019-10-09 14:25:08 +000025#include "llvm/Support/Alignment.h"
Clement Courbet0e69e2d2018-05-17 10:52:18 +000026#include "llvm/Support/MemoryBuffer.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000027
Fangrui Song32401af2018-10-22 17:10:47 +000028namespace llvm {
Clement Courbetac74acd2018-04-04 11:37:06 +000029namespace exegesis {
30
31static constexpr const char ModuleID[] = "ExegesisInfoTest";
32static constexpr const char FunctionID[] = "foo";
Clement Courbet04a9a0e2019-10-09 14:25:08 +000033static const Align kFunctionAlignment(4096);
Clement Courbetac74acd2018-04-04 11:37:06 +000034
Clement Courbet9431b722019-09-27 12:56:24 +000035// Fills the given basic block with register setup code, and returns true if
36// all registers could be setup correctly.
Clement Courbet50cdd562019-10-09 11:58:42 +000037static bool generateSnippetSetupCode(
38 const ExegesisTarget &ET, const MCSubtargetInfo *const MSI,
39 ArrayRef<RegisterValue> RegisterInitialValues, BasicBlockFiller &BBF) {
Clement Courbet9431b722019-09-27 12:56:24 +000040 bool IsSnippetSetupComplete = true;
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000041 for (const RegisterValue &RV : RegisterInitialValues) {
Simon Pilgrimf652ef32018-09-18 15:38:16 +000042 // Load a constant in the register.
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000043 const auto SetRegisterCode = ET.setRegTo(*MSI, RV.Register, RV.Value);
44 if (SetRegisterCode.empty())
45 IsSnippetSetupComplete = false;
Clement Courbet9431b722019-09-27 12:56:24 +000046 BBF.addInstructions(SetRegisterCode);
Simon Pilgrimf652ef32018-09-18 15:38:16 +000047 }
Clement Courbet9431b722019-09-27 12:56:24 +000048 return IsSnippetSetupComplete;
Clement Courbeta51efc22018-06-25 13:12:02 +000049}
50
Clement Courbetac74acd2018-04-04 11:37:06 +000051// Small utility function to add named passes.
Clement Courbet50cdd562019-10-09 11:58:42 +000052static bool addPass(PassManagerBase &PM, StringRef PassName,
53 TargetPassConfig &TPC) {
54 const PassRegistry *PR = PassRegistry::getPassRegistry();
55 const PassInfo *PI = PR->getPassInfo(PassName);
Clement Courbetac74acd2018-04-04 11:37:06 +000056 if (!PI) {
Clement Courbet50cdd562019-10-09 11:58:42 +000057 errs() << " run-pass " << PassName << " is not registered.\n";
Clement Courbetac74acd2018-04-04 11:37:06 +000058 return true;
59 }
60
61 if (!PI->getNormalCtor()) {
Clement Courbet50cdd562019-10-09 11:58:42 +000062 errs() << " cannot create pass: " << PI->getPassName() << "\n";
Clement Courbetac74acd2018-04-04 11:37:06 +000063 return true;
64 }
Clement Courbet50cdd562019-10-09 11:58:42 +000065 Pass *P = PI->getNormalCtor()();
Clement Courbetac74acd2018-04-04 11:37:06 +000066 std::string Banner = std::string("After ") + std::string(P->getPassName());
67 PM.add(P);
68 TPC.printAndVerify(Banner);
69
70 return false;
71}
72
Simon Pilgrimaedb5282019-11-09 13:43:09 +000073MachineFunction &createVoidVoidPtrMachineFunction(StringRef FunctionName,
Clement Courbet50cdd562019-10-09 11:58:42 +000074 Module *Module,
75 MachineModuleInfo *MMI) {
76 Type *const ReturnType = Type::getInt32Ty(Module->getContext());
77 Type *const MemParamType = PointerType::get(
78 Type::getInt8Ty(Module->getContext()), 0 /*default address space*/);
79 FunctionType *FunctionType =
80 FunctionType::get(ReturnType, {MemParamType}, false);
81 Function *const F = Function::Create(
Simon Pilgrimaedb5282019-11-09 13:43:09 +000082 FunctionType, GlobalValue::InternalLinkage, FunctionName, Module);
Clement Courbetac74acd2018-04-04 11:37:06 +000083 // Making sure we can create a MachineFunction out of this Function even if it
84 // contains no IR.
85 F->setIsMaterializable(true);
86 return MMI->getOrCreateMachineFunction(*F);
87}
88
Clement Courbet50cdd562019-10-09 11:58:42 +000089BasicBlockFiller::BasicBlockFiller(MachineFunction &MF, MachineBasicBlock *MBB,
90 const MCInstrInfo *MCII)
Clement Courbet9431b722019-09-27 12:56:24 +000091 : MF(MF), MBB(MBB), MCII(MCII) {}
92
Clement Courbet50cdd562019-10-09 11:58:42 +000093void BasicBlockFiller::addInstruction(const MCInst &Inst, const DebugLoc &DL) {
Clement Courbet9431b722019-09-27 12:56:24 +000094 const unsigned Opcode = Inst.getOpcode();
Clement Courbet50cdd562019-10-09 11:58:42 +000095 const MCInstrDesc &MCID = MCII->get(Opcode);
96 MachineInstrBuilder Builder = BuildMI(MBB, DL, MCID);
Clement Courbet9431b722019-09-27 12:56:24 +000097 for (unsigned OpIndex = 0, E = Inst.getNumOperands(); OpIndex < E;
98 ++OpIndex) {
Clement Courbet50cdd562019-10-09 11:58:42 +000099 const MCOperand &Op = Inst.getOperand(OpIndex);
Clement Courbet9431b722019-09-27 12:56:24 +0000100 if (Op.isReg()) {
101 const bool IsDef = OpIndex < MCID.getNumDefs();
102 unsigned Flags = 0;
Clement Courbet50cdd562019-10-09 11:58:42 +0000103 const MCOperandInfo &OpInfo = MCID.operands().begin()[OpIndex];
Clement Courbet9431b722019-09-27 12:56:24 +0000104 if (IsDef && !OpInfo.isOptionalDef())
Clement Courbet50cdd562019-10-09 11:58:42 +0000105 Flags |= RegState::Define;
Clement Courbet9431b722019-09-27 12:56:24 +0000106 Builder.addReg(Op.getReg(), Flags);
107 } else if (Op.isImm()) {
108 Builder.addImm(Op.getImm());
109 } else if (!Op.isValid()) {
110 llvm_unreachable("Operand is not set");
111 } else {
112 llvm_unreachable("Not yet implemented");
Clement Courbetac74acd2018-04-04 11:37:06 +0000113 }
114 }
Clement Courbet9431b722019-09-27 12:56:24 +0000115}
116
Clement Courbet50cdd562019-10-09 11:58:42 +0000117void BasicBlockFiller::addInstructions(ArrayRef<MCInst> Insts,
118 const DebugLoc &DL) {
Clement Courbet9431b722019-09-27 12:56:24 +0000119 for (const MCInst &Inst : Insts)
120 addInstruction(Inst, DL);
121}
122
Clement Courbet50cdd562019-10-09 11:58:42 +0000123void BasicBlockFiller::addReturn(const DebugLoc &DL) {
Clement Courbet559d1e32018-05-15 07:40:21 +0000124 // Insert the return code.
Clement Courbet50cdd562019-10-09 11:58:42 +0000125 const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
Clement Courbet559d1e32018-05-15 07:40:21 +0000126 if (TII->getReturnOpcode() < TII->getNumOpcodes()) {
Clement Courbet50cdd562019-10-09 11:58:42 +0000127 BuildMI(MBB, DL, TII->get(TII->getReturnOpcode()));
Clement Courbet559d1e32018-05-15 07:40:21 +0000128 } else {
Clement Courbet50cdd562019-10-09 11:58:42 +0000129 MachineIRBuilder MIB(MF);
Clement Courbet559d1e32018-05-15 07:40:21 +0000130 MIB.setMBB(*MBB);
John Brawnc616a722018-10-10 13:03:23 +0000131 MF.getSubtarget().getCallLowering()->lowerReturn(MIB, nullptr, {});
Clement Courbet559d1e32018-05-15 07:40:21 +0000132 }
Clement Courbetac74acd2018-04-04 11:37:06 +0000133}
134
Clement Courbet50cdd562019-10-09 11:58:42 +0000135FunctionFiller::FunctionFiller(MachineFunction &MF,
Clement Courbet9431b722019-09-27 12:56:24 +0000136 std::vector<unsigned> RegistersSetUp)
137 : MF(MF), MCII(MF.getTarget().getMCInstrInfo()), Entry(addBasicBlock()),
138 RegistersSetUp(std::move(RegistersSetUp)) {}
139
140BasicBlockFiller FunctionFiller::addBasicBlock() {
Clement Courbet50cdd562019-10-09 11:58:42 +0000141 MachineBasicBlock *MBB = MF.CreateMachineBasicBlock();
Clement Courbet9431b722019-09-27 12:56:24 +0000142 MF.push_back(MBB);
143 return BasicBlockFiller(MF, MBB, MCII);
144}
145
146ArrayRef<unsigned> FunctionFiller::getRegistersSetUp() const {
147 return RegistersSetUp;
148}
149
Clement Courbet50cdd562019-10-09 11:58:42 +0000150static std::unique_ptr<Module>
151createModule(const std::unique_ptr<LLVMContext> &Context, const DataLayout DL) {
152 auto Mod = std::make_unique<Module>(ModuleID, *Context);
153 Mod->setDataLayout(DL);
154 return Mod;
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000155}
156
Clement Courbet50cdd562019-10-09 11:58:42 +0000157BitVector getFunctionReservedRegs(const TargetMachine &TM) {
158 std::unique_ptr<LLVMContext> Context = std::make_unique<LLVMContext>();
159 std::unique_ptr<Module> Module = createModule(Context, TM.createDataLayout());
Matthias Braun3d849f62018-11-05 23:49:13 +0000160 // TODO: This only works for targets implementing LLVMTargetMachine.
Yuanfang Chencc382cf2019-09-30 17:54:50 +0000161 const LLVMTargetMachine &LLVMTM = static_cast<const LLVMTargetMachine &>(TM);
Clement Courbet50cdd562019-10-09 11:58:42 +0000162 std::unique_ptr<MachineModuleInfoWrapperPass> MMIWP =
163 std::make_unique<MachineModuleInfoWrapperPass>(&LLVMTM);
164 MachineFunction &MF = createVoidVoidPtrMachineFunction(
Yuanfang Chencc382cf2019-09-30 17:54:50 +0000165 FunctionID, Module.get(), &MMIWP.get()->getMMI());
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000166 // Saving reserved registers for client.
167 return MF.getSubtarget().getRegisterInfo()->getReservedRegs(MF);
168}
169
Miloš Stojanović79c7d342020-02-19 14:34:12 +0100170Error assembleToStream(const ExegesisTarget &ET,
171 std::unique_ptr<LLVMTargetMachine> TM,
172 ArrayRef<unsigned> LiveIns,
173 ArrayRef<RegisterValue> RegisterInitialValues,
174 const FillFunction &Fill, raw_pwrite_stream &AsmStream) {
Clement Courbet04a9a0e2019-10-09 14:25:08 +0000175 auto Context = std::make_unique<LLVMContext>();
Clement Courbet50cdd562019-10-09 11:58:42 +0000176 std::unique_ptr<Module> Module =
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000177 createModule(Context, TM->createDataLayout());
Clement Courbet04a9a0e2019-10-09 14:25:08 +0000178 auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(TM.get());
Clement Courbet50cdd562019-10-09 11:58:42 +0000179 MachineFunction &MF = createVoidVoidPtrMachineFunction(
Yuanfang Chencc382cf2019-09-30 17:54:50 +0000180 FunctionID, Module.get(), &MMIWP.get()->getMMI());
Clement Courbet04a9a0e2019-10-09 14:25:08 +0000181 MF.ensureAlignment(kFunctionAlignment);
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000182
183 // We need to instruct the passes that we're done with SSA and virtual
184 // registers.
185 auto &Properties = MF.getProperties();
Clement Courbet50cdd562019-10-09 11:58:42 +0000186 Properties.set(MachineFunctionProperties::Property::NoVRegs);
187 Properties.reset(MachineFunctionProperties::Property::IsSSA);
188 Properties.set(MachineFunctionProperties::Property::NoPHIs);
Guillaume Chateletfb943542018-08-01 14:41:45 +0000189
190 for (const unsigned Reg : LiveIns)
191 MF.getRegInfo().addLiveIn(Reg);
192
Clement Courbet9431b722019-09-27 12:56:24 +0000193 std::vector<unsigned> RegistersSetUp;
194 for (const auto &InitValue : RegisterInitialValues) {
195 RegistersSetUp.push_back(InitValue.Register);
196 }
197 FunctionFiller Sink(MF, std::move(RegistersSetUp));
198 auto Entry = Sink.getEntry();
199 for (const unsigned Reg : LiveIns)
200 Entry.MBB->addLiveIn(Reg);
Guillaume Chateletc96a97b2018-09-20 12:22:18 +0000201
Clement Courbet9431b722019-09-27 12:56:24 +0000202 const bool IsSnippetSetupComplete = generateSnippetSetupCode(
203 ET, TM->getMCSubtargetInfo(), RegisterInitialValues, Entry);
Guillaume Chateletc96a97b2018-09-20 12:22:18 +0000204
Clement Courbeta51efc22018-06-25 13:12:02 +0000205 // If the snippet setup is not complete, we disable liveliness tracking. This
206 // means that we won't know what values are in the registers.
207 if (!IsSnippetSetupComplete)
Clement Courbet50cdd562019-10-09 11:58:42 +0000208 Properties.reset(MachineFunctionProperties::Property::TracksLiveness);
Clement Courbeta51efc22018-06-25 13:12:02 +0000209
Clement Courbet9431b722019-09-27 12:56:24 +0000210 Fill(Sink);
211
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000212 // prologue/epilogue pass needs the reserved registers to be frozen, this
213 // is usually done by the SelectionDAGISel pass.
214 MF.getRegInfo().freezeReservedRegs(MF);
215
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000216 // We create the pass manager, run the passes to populate AsmBuffer.
Clement Courbet50cdd562019-10-09 11:58:42 +0000217 MCContext &MCContext = MMIWP->getMMI().getContext();
218 legacy::PassManager PM;
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000219
Clement Courbet50cdd562019-10-09 11:58:42 +0000220 TargetLibraryInfoImpl TLII(Triple(Module->getTargetTriple()));
221 PM.add(new TargetLibraryInfoWrapperPass(TLII));
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000222
Clement Courbet50cdd562019-10-09 11:58:42 +0000223 TargetPassConfig *TPC = TM->createPassConfig(PM);
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000224 PM.add(TPC);
Yuanfang Chencc382cf2019-09-30 17:54:50 +0000225 PM.add(MMIWP.release());
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000226 TPC->printAndVerify("MachineFunctionGenerator::assemble");
Clement Courbet6fd00e32018-06-20 11:54:35 +0000227 // Add target-specific passes.
Clement Courbet4860b982018-06-26 08:49:30 +0000228 ET.addTargetSpecificPasses(PM);
229 TPC->printAndVerify("After ExegesisTarget::addTargetSpecificPasses");
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000230 // Adding the following passes:
Simon Atanasyancf1ba232019-10-11 20:26:08 +0000231 // - postrapseudos: expands pseudo return instructions used on some targets.
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000232 // - machineverifier: checks that the MachineFunction is well formed.
233 // - prologepilog: saves and restore callee saved registers.
Simon Atanasyancf1ba232019-10-11 20:26:08 +0000234 for (const char *PassName :
235 {"postrapseudos", "machineverifier", "prologepilog"})
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000236 if (addPass(PM, PassName, *TPC))
Miloš Stojanović79c7d342020-02-19 14:34:12 +0100237 return make_error<Failure>("Unable to add a mandatory pass");
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000238 TPC->setInitialized();
239
240 // AsmPrinter is responsible for generating the assembly into AsmBuffer.
Miloš Stojanović79c7d342020-02-19 14:34:12 +0100241 if (TM->addAsmPrinter(PM, AsmStream, nullptr, CGFT_ObjectFile, MCContext))
242 return make_error<Failure>("Cannot add AsmPrinter passes");
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000243
244 PM.run(*Module); // Run all the passes
Miloš Stojanović79c7d342020-02-19 14:34:12 +0100245 return Error::success();
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000246}
247
Clement Courbet50cdd562019-10-09 11:58:42 +0000248object::OwningBinary<object::ObjectFile>
249getObjectFromBuffer(StringRef InputData) {
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000250 // Storing the generated assembly into a MemoryBuffer that owns the memory.
Clement Courbet50cdd562019-10-09 11:58:42 +0000251 std::unique_ptr<MemoryBuffer> Buffer =
252 MemoryBuffer::getMemBufferCopy(InputData);
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000253 // Create the ObjectFile from the MemoryBuffer.
Clement Courbet50cdd562019-10-09 11:58:42 +0000254 std::unique_ptr<object::ObjectFile> Obj =
255 cantFail(object::ObjectFile::createObjectFile(Buffer->getMemBufferRef()));
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000256 // Returning both the MemoryBuffer and the ObjectFile.
Clement Courbet50cdd562019-10-09 11:58:42 +0000257 return object::OwningBinary<object::ObjectFile>(std::move(Obj),
258 std::move(Buffer));
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000259}
260
Clement Courbet50cdd562019-10-09 11:58:42 +0000261object::OwningBinary<object::ObjectFile> getObjectFromFile(StringRef Filename) {
262 return cantFail(object::ObjectFile::createObjectFile(Filename));
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000263}
264
Clement Courbetac74acd2018-04-04 11:37:06 +0000265namespace {
266
267// Implementation of this class relies on the fact that a single object with a
268// single function will be loaded into memory.
Clement Courbet50cdd562019-10-09 11:58:42 +0000269class TrackingSectionMemoryManager : public SectionMemoryManager {
Clement Courbetac74acd2018-04-04 11:37:06 +0000270public:
271 explicit TrackingSectionMemoryManager(uintptr_t *CodeSize)
272 : CodeSize(CodeSize) {}
273
274 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
275 unsigned SectionID,
Clement Courbet50cdd562019-10-09 11:58:42 +0000276 StringRef SectionName) override {
Clement Courbetac74acd2018-04-04 11:37:06 +0000277 *CodeSize = Size;
Clement Courbet50cdd562019-10-09 11:58:42 +0000278 return SectionMemoryManager::allocateCodeSection(Size, Alignment, SectionID,
279 SectionName);
Clement Courbetac74acd2018-04-04 11:37:06 +0000280 }
281
282private:
283 uintptr_t *const CodeSize = nullptr;
284};
285
286} // namespace
287
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000288ExecutableFunction::ExecutableFunction(
Clement Courbet50cdd562019-10-09 11:58:42 +0000289 std::unique_ptr<LLVMTargetMachine> TM,
290 object::OwningBinary<object::ObjectFile> &&ObjectFileHolder)
291 : Context(std::make_unique<LLVMContext>()) {
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000292 assert(ObjectFileHolder.getBinary() && "cannot create object file");
Clement Courbetac74acd2018-04-04 11:37:06 +0000293 // Initializing the execution engine.
294 // We need to use the JIT EngineKind to be able to add an object file.
295 LLVMLinkInMCJIT();
296 uintptr_t CodeSize = 0;
297 std::string Error;
298 ExecEngine.reset(
Clement Courbet50cdd562019-10-09 11:58:42 +0000299 EngineBuilder(createModule(Context, TM->createDataLayout()))
Clement Courbetac74acd2018-04-04 11:37:06 +0000300 .setErrorStr(&Error)
Simon Pilgrim01e8c4e2018-04-18 14:22:33 +0000301 .setMCPU(TM->getTargetCPU())
Clement Courbet50cdd562019-10-09 11:58:42 +0000302 .setEngineKind(EngineKind::JIT)
Clement Courbetac74acd2018-04-04 11:37:06 +0000303 .setMCJITMemoryManager(
Jonas Devlieghere0eaee542019-08-15 15:54:37 +0000304 std::make_unique<TrackingSectionMemoryManager>(&CodeSize))
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000305 .create(TM.release()));
Clement Courbetac74acd2018-04-04 11:37:06 +0000306 if (!ExecEngine)
Clement Courbet50cdd562019-10-09 11:58:42 +0000307 report_fatal_error(Error);
Clement Courbetac74acd2018-04-04 11:37:06 +0000308 // Adding the generated object file containing the assembled function.
309 // The ExecutionEngine makes sure the object file is copied into an
310 // executable page.
Clement Courbet0e69e2d2018-05-17 10:52:18 +0000311 ExecEngine->addObjectFile(std::move(ObjectFileHolder));
312 // Fetching function bytes.
Clement Courbet04a9a0e2019-10-09 14:25:08 +0000313 const uint64_t FunctionAddress = ExecEngine->getFunctionAddress(FunctionID);
314 assert(isAligned(kFunctionAlignment, FunctionAddress) &&
315 "function is not properly aligned");
316 FunctionBytes =
317 StringRef(reinterpret_cast<const char *>(FunctionAddress), CodeSize);
Clement Courbetac74acd2018-04-04 11:37:06 +0000318}
319
320} // namespace exegesis
Fangrui Song32401af2018-10-22 17:10:47 +0000321} // namespace llvm