diff --git a/llvm/include/llvm/Transforms/InnerUnikernels/IUProgType.def b/llvm/include/llvm/Transforms/InnerUnikernels/IUProgType.def deleted file mode 100644 index f0b7da1edceed0..00000000000000 --- a/llvm/include/llvm/Transforms/InnerUnikernels/IUProgType.def +++ /dev/null @@ -1,5 +0,0 @@ -IU_PROG_TYPE_1(BPF_PROG_TYPE_KPROBE, kprobe, "kprobe") -IU_PROG_TYPE_1(BPF_PROG_TYPE_PERF_EVENT, perf_event, "perf_event") -IU_PROG_TYPE_1(BPF_PROG_TYPE_XDP, xdp, "xdp") -IU_PROG_TYPE_2(BPF_PROG_TYPE_SCHED_CLS, sched_cls, "classifier", "tc") -IU_PROG_TYPE_2(BPF_PROG_TYPE_TRACEPOINT, tracepoint, "tracepoint", "tp") diff --git a/llvm/include/llvm/Transforms/InnerUnikernels/IUInsertEntry.h b/llvm/include/llvm/Transforms/Rex/RexInsertEntry.h similarity index 75% rename from llvm/include/llvm/Transforms/InnerUnikernels/IUInsertEntry.h rename to llvm/include/llvm/Transforms/Rex/RexInsertEntry.h index cad22428642ca3..5cd460cd1bc422 100644 --- a/llvm/include/llvm/Transforms/InnerUnikernels/IUInsertEntry.h +++ b/llvm/include/llvm/Transforms/Rex/RexInsertEntry.h @@ -1,4 +1,4 @@ -//===- IUInsertEntry.h - IUEntryInsertion pass ------------------*- C++ -*-===// +//===- RexInsertEntry.h - RexEntryInsertion pass ----------------*- C++ -*-===// // // Part of the Inner-Unikernels project, based on the LLVM project under // the Apache License v2.0 with LLVM Exceptions. @@ -9,13 +9,13 @@ /// \file /// /// This file provides the primary interface to the entry-code-insertion -/// pass for the Inner-Unikernels project. This pass is suitable for use in -/// the new pass manager and it does not support the legacy pass manager. +/// pass for the Rex project. This pass is suitable for use in the new pass +/// managermanager and it does not support the legacy pass manager. /// //===----------------------------------------------------------------------===// -#ifndef LLVM_TRANSFORMS_IUINSERTENTRY_H -#define LLVM_TRANSFORMS_IUINSERTENTRY_H +#ifndef LLVM_TRANSFORMS_REXINSERTENTRY_H +#define LLVM_TRANSFORMS_REXINSERTENTRY_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" @@ -26,17 +26,18 @@ namespace llvm { /// Pass to insert entry points for inner-unikernel programs -class IUEntryInsertion : public PassInfoMixin { +class RexEntryInsertion : public PassInfoMixin { bool runOnModule(Module &M) const; Function *insertEntry(Module &M, FunctionCallee &ProgRun, GlobalVariable *ProgObj, Type *CtxPT, StringRef Name, unsigned ProgType) const; - AttributeList getIUFnAttr(LLVMContext &C) const; + AttributeList getRexFnAttr(LLVMContext &C) const; void markUsedGlobalVariables(Module &M, ArrayRef Vec) const; void validateAndFinalizeSection(Function *EntryFn, GlobalVariable *ProgObj, unsigned ProgType) const; bool instrumentStack(Module &M, LLVMContext &C) const; Function *createTimeoutHandler(Module &M, LLVMContext &C) const; + bool Recursive; public: @@ -45,4 +46,4 @@ class IUEntryInsertion : public PassInfoMixin { } // namespace llvm -#endif /* LLVM_TRANSFORMS_IUINSERTENTRY_H */ +#endif /* LLVM_TRANSFORMS_REXINSERTENTRY_H */ diff --git a/llvm/include/llvm/Transforms/Rex/RexProgType.def b/llvm/include/llvm/Transforms/Rex/RexProgType.def new file mode 100644 index 00000000000000..6fbe7651c102ae --- /dev/null +++ b/llvm/include/llvm/Transforms/Rex/RexProgType.def @@ -0,0 +1,5 @@ +REX_PROG_TYPE_1(BPF_PROG_TYPE_KPROBE, kprobe, "kprobe") +REX_PROG_TYPE_1(BPF_PROG_TYPE_PERF_EVENT, perf_event, "perf_event") +REX_PROG_TYPE_1(BPF_PROG_TYPE_XDP, xdp, "xdp") +REX_PROG_TYPE_2(BPF_PROG_TYPE_SCHED_CLS, sched_cls, "classifier", "tc") +REX_PROG_TYPE_2(BPF_PROG_TYPE_TRACEPOINT, tracepoint, "tracepoint", "tp") diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt index ced12758bc2730..d4531459c51c76 100644 --- a/llvm/lib/Passes/CMakeLists.txt +++ b/llvm/lib/Passes/CMakeLists.txt @@ -22,7 +22,7 @@ add_llvm_component_library(LLVMPasses Coroutines HipStdPar IPO - InnerUnikernels + Rex InstCombine IRPrinter ObjCARC diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 3397a5d57e2534..4d9ffe9df91c9b 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -155,7 +155,6 @@ #include "llvm/Transforms/IPO/StripSymbols.h" #include "llvm/Transforms/IPO/SyntheticCountsPropagation.h" #include "llvm/Transforms/IPO/WholeProgramDevirt.h" -#include "llvm/Transforms/InnerUnikernels/IUInsertEntry.h" #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" @@ -176,6 +175,7 @@ #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" #include "llvm/Transforms/ObjCARC.h" +#include "llvm/Transforms/Rex/RexInsertEntry.h" #include "llvm/Transforms/Scalar/ADCE.h" #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" #include "llvm/Transforms/Scalar/AnnotationRemarks.h" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 026a5373fb4379..ee27e0bbf410c8 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -140,7 +140,7 @@ MODULE_PASS("tsan-module", ModuleThreadSanitizerPass()) MODULE_PASS("verify", VerifierPass()) MODULE_PASS("view-callgraph", CallGraphViewerPass()) MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass()) -MODULE_PASS("iu-entry-insertion", IUEntryInsertion()) +MODULE_PASS("rex-entry-insertion", RexEntryInsertion()) #undef MODULE_PASS #ifndef MODULE_PASS_WITH_PARAMS diff --git a/llvm/lib/Transforms/CMakeLists.txt b/llvm/lib/Transforms/CMakeLists.txt index bf417f01756db6..89f37d379ddd5a 100644 --- a/llvm/lib/Transforms/CMakeLists.txt +++ b/llvm/lib/Transforms/CMakeLists.txt @@ -10,4 +10,4 @@ add_subdirectory(ObjCARC) add_subdirectory(Coroutines) add_subdirectory(CFGuard) add_subdirectory(HipStdPar) -add_subdirectory(InnerUnikernels) +add_subdirectory(Rex) diff --git a/llvm/lib/Transforms/InnerUnikernels/CMakeLists.txt b/llvm/lib/Transforms/Rex/CMakeLists.txt similarity index 56% rename from llvm/lib/Transforms/InnerUnikernels/CMakeLists.txt rename to llvm/lib/Transforms/Rex/CMakeLists.txt index 48a335d53b8dc2..b83e06ccfcfad3 100644 --- a/llvm/lib/Transforms/InnerUnikernels/CMakeLists.txt +++ b/llvm/lib/Transforms/Rex/CMakeLists.txt @@ -1,9 +1,9 @@ -add_llvm_component_library( LLVMInnerUnikernels - IUInsertEntry.cpp +add_llvm_component_library( LLVMRex + RexInsertEntry.cpp ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms - ${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/InnerUnikernels + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/Rex DEPENDS intrinsics_gen diff --git a/llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp b/llvm/lib/Transforms/Rex/RexInsertEntry.cpp similarity index 88% rename from llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp rename to llvm/lib/Transforms/Rex/RexInsertEntry.cpp index 0fe2a9bd5bc25c..c2c3dd68c96abe 100644 --- a/llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp +++ b/llvm/lib/Transforms/Rex/RexInsertEntry.cpp @@ -1,4 +1,4 @@ -//===- IUInsertEntry.cpp - code to perform entry insertion for IU programs-===// +//===- RexInsertEntry.cpp - code to perform entry insertion for Rex programs-===// // // Part of the Inner-Unikernels project, based on the LLVM project under // the Apache License v2.0 with LLVM Exceptions. @@ -8,14 +8,14 @@ //===----------------------------------------------------------------------===// // This file implements the entry code insertion pass for Inner-Unikernels // programs. It generates a new function that calls into the __iu_entry_*() -// functions in the kernel runtime crate for each global IU program +// functions in the kernel runtime crate for each global Rex program // objects. The pass then sets the entry functions as "used" to prevent // link-time stripping using @llvm.used, which will automatically set the // "SHF_GNU_RETAIN" flag for these symbols. // //===----------------------------------------------------------------------===// -#include "llvm/Transforms/InnerUnikernels/IUInsertEntry.h" +#include "llvm/Transforms/Rex/RexInsertEntry.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SCCIterator.h" #include "llvm/ADT/SmallVector.h" @@ -52,41 +52,41 @@ using namespace llvm; -#define DEBUG_TYPE "iu-entry-insertion" +#define DEBUG_TYPE "rex-entry-insertion" STATISTIC(NumInserted, "Number of entry function inserted"); /// Validate program sections, the put the function and program object /// into appropriate sections -void IUEntryInsertion::validateAndFinalizeSection(Function *EntryFn, +void RexEntryInsertion::validateAndFinalizeSection(Function *EntryFn, GlobalVariable *ProgObj, unsigned ProgType) const { // We want to strip the "inner_unikernel/" prefix // strlen("inner_unikernel/") + 1 = 16 EntryFn->setSection(ProgObj->getSection().substr(16)); switch (ProgType) { -#define IU_PROG_TYPE_1(ty_enum, ty_name, sec) \ +#define REX_PROG_TYPE_1(ty_enum, ty_name, sec) \ case ty_enum: \ ProgObj->setSection("obj" #ty_name); \ assert(EntryFn->getSection().starts_with(sec) && "invalid section name"); \ break; -#define IU_PROG_TYPE_2(ty_enum, ty_name, sec1, sec2) \ +#define REX_PROG_TYPE_2(ty_enum, ty_name, sec1, sec2) \ case ty_enum: \ ProgObj->setSection("obj" #ty_name); \ assert((EntryFn->getSection().starts_with(sec1) || \ EntryFn->getSection().starts_with(sec2)) && \ "invalid section name"); \ break; -#include "llvm/Transforms/InnerUnikernels/IUProgType.def" -#undef IU_PROG_TYPE_1 -#undef IU_PROG_TYPE_2 +#include "llvm/Transforms/Rex/RexProgType.def" +#undef REX_PROG_TYPE_1 +#undef REX_PROG_TYPE_2 default: llvm_unreachable("Unknown prog type"); } } /// Performs the actual insertion of the new function -Function *IUEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun, +Function *RexEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun, GlobalVariable *ProgObj, Type *CtxPT, StringRef Name, unsigned ProgType) const { @@ -98,7 +98,7 @@ Function *IUEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun, // Declare the function in module FunctionType *EntryTy = FunctionType::get(EntryRetty, EntryArgTys, false); - FunctionCallee Entry = M.getOrInsertFunction(Name, EntryTy, getIUFnAttr(C)); + FunctionCallee Entry = M.getOrInsertFunction(Name, EntryTy, getRexFnAttr(C)); // Setup attributes Function *EntryFn = cast(Entry.getCallee()); @@ -126,8 +126,8 @@ Function *IUEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun, return EntryFn; } -/// Sets all the needed attribute for the Rust IU programs -AttributeList IUEntryInsertion::getIUFnAttr(LLVMContext &C) const { +/// Sets all the needed attribute for the Rust Rex programs +AttributeList RexEntryInsertion::getRexFnAttr(LLVMContext &C) const { // SIMD extensions are not allowed in the kernel std::stringstream TargetFeatureSs; @@ -151,7 +151,7 @@ AttributeList IUEntryInsertion::getIUFnAttr(LLVMContext &C) const { /// Entry point of the pass, it looks at all the global variables to identify /// the inner-unikernel program variables -bool IUEntryInsertion::runOnModule(Module &M) const { +bool RexEntryInsertion::runOnModule(Module &M) const { bool Changed = false; // Whether transformation is actually made LLVMContext &C = M.getContext(); SmallVector UsedGV; @@ -179,17 +179,17 @@ bool IUEntryInsertion::runOnModule(Module &M) const { std::string ProgRunName; switch (RTTI) { -#define IU_PROG_TYPE_1(ty_enum, ty_name, sec) \ +#define REX_PROG_TYPE_1(ty_enum, ty_name, sec) \ case ty_enum: \ ProgRunName = "__iu_entry_" #ty_name; \ break; -#define IU_PROG_TYPE_2(ty_enum, ty_name, sec1, sec2) \ +#define REX_PROG_TYPE_2(ty_enum, ty_name, sec1, sec2) \ case ty_enum: \ ProgRunName = "__iu_entry_" #ty_name; \ break; -#include "llvm/Transforms/InnerUnikernels/IUProgType.def" -#undef IU_PROG_TYPE_1 -#undef IU_PROG_TYPE_2 +#include "llvm/Transforms/Rex/RexProgType.def" +#undef REX_PROG_TYPE_1 +#undef REX_PROG_TYPE_2 default: errs() << "Unknown RTTI " << RTTI << "\n"; } @@ -210,7 +210,7 @@ bool IUEntryInsertion::runOnModule(Module &M) const { FunctionType *ProgRunTy = FunctionType::get(ProgRunRetty, ProgRunArgTys, false); FunctionCallee ProgRun = - M.getOrInsertFunction(ProgRunName, ProgRunTy, getIUFnAttr(C)); + M.getOrInsertFunction(ProgRunName, ProgRunTy, getRexFnAttr(C)); // name: &'a str Constant *OP2 = CS->getOperand(2); @@ -253,7 +253,7 @@ bool IUEntryInsertion::runOnModule(Module &M) const { return Changed; } -bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const { +bool RexEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const { SmallVector WorkList; bool HasIndirect = false; @@ -261,7 +261,7 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const { for (auto &F : M) { std::string Demangled; nonMicrosoftDemangle(F.getName().data(), Demangled); - if (StringRef(Demangled).starts_with(StringRef("inner_unikernel_rt::"))) + if (StringRef(Demangled).starts_with(StringRef("rex::"))) continue; for (auto &I : instructions(F)) { if (auto *CI = dyn_cast(&I)) { @@ -285,7 +285,7 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const { return false; // No need to instrument if there is no indirect call and no recursion - // will calculate the frame size in backend pass IUFrameSizePass + // will calculate the frame size in backend pass RexFrameSizePass if (!HasIndirect && !Recursive) return false; @@ -300,7 +300,7 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const { FunctionType *CheckStackTy = FunctionType::get(Type::getVoidTy(C), {}, false); FunctionCallee CheckStack = - M.getOrInsertFunction("__iu_check_stack", CheckStackTy, getIUFnAttr(C)); + M.getOrInsertFunction("__iu_check_stack", CheckStackTy, getRexFnAttr(C)); // Add the stack pointer instrumentation for (auto *I : WorkList) { @@ -311,17 +311,17 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const { return true; } -Function *IUEntryInsertion::createTimeoutHandler(Module &M, +Function *RexEntryInsertion::createTimeoutHandler(Module &M, LLVMContext &C) const { // Rust uses void return type for noreturn (i.e. the "!" return type) FunctionType *TimeoutHandlerTy = FunctionType::get(Type::getVoidTy(C), {}, false); FunctionCallee TimeoutHandlerInner = M.getOrInsertFunction( - "__iu_handle_timeout", TimeoutHandlerTy, getIUFnAttr(C)); + "__iu_handle_timeout", TimeoutHandlerTy, getRexFnAttr(C)); Function *TimeoutHandler = cast( M.getOrInsertFunction(M.getName().str() + "_iu_handle_timeout", - TimeoutHandlerTy, getIUFnAttr(C)) + TimeoutHandlerTy, getRexFnAttr(C)) .getCallee()); // Construct function body, starting with entry BB @@ -338,7 +338,7 @@ Function *IUEntryInsertion::createTimeoutHandler(Module &M, } /// Wrapper for the new pass manager -PreservedAnalyses IUEntryInsertion::run(Module &M, ModuleAnalysisManager &AM) { +PreservedAnalyses RexEntryInsertion::run(Module &M, ModuleAnalysisManager &AM) { // Run entry insertion pass Recursive = false; CallGraph &CG = AM.getResult(M);