Bump version to 19.1.0 (final)
[llvm-project.git] / bolt / lib / Passes / Hugify.cpp
blob1ac1b08573b86954f01ef3de3a5c4db2f732b984
1 //===--- bolt/Passes/Hugify.cpp -------------------------------------------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "bolt/Passes/Hugify.h"
11 #define DEBUG_TYPE "bolt-hugify"
13 using namespace llvm;
15 namespace llvm {
16 namespace bolt {
18 Error HugePage::runOnFunctions(BinaryContext &BC) {
19 auto *RtLibrary = BC.getRuntimeLibrary();
20 if (!RtLibrary || !BC.isELF() || !BC.StartFunctionAddress) {
21 return Error::success();
24 auto createSimpleFunction =
25 [&](std::string Title, std::vector<MCInst> Instrs) -> BinaryFunction * {
26 BinaryFunction *Func = BC.createInjectedBinaryFunction(Title);
28 std::vector<std::unique_ptr<BinaryBasicBlock>> BBs;
29 BBs.emplace_back(Func->createBasicBlock(nullptr));
30 BBs.back()->addInstructions(Instrs.begin(), Instrs.end());
31 BBs.back()->setCFIState(0);
32 BBs.back()->setOffset(BinaryBasicBlock::INVALID_OFFSET);
34 Func->insertBasicBlocks(nullptr, std::move(BBs),
35 /*UpdateLayout=*/true,
36 /*UpdateCFIState=*/false);
37 Func->updateState(BinaryFunction::State::CFG_Finalized);
38 return Func;
41 const BinaryFunction *const Start =
42 BC.getBinaryFunctionAtAddress(*BC.StartFunctionAddress);
43 assert(Start && "Entry point function not found");
44 const MCSymbol *StartSym = Start->getSymbol();
45 createSimpleFunction("__bolt_hugify_start_program",
46 BC.MIB->createSymbolTrampoline(StartSym, BC.Ctx.get()));
47 return Error::success();
49 } // namespace bolt
50 } // namespace llvm