Skip to content

Commit

Permalink
s/iu/rex/g
Browse files Browse the repository at this point in the history
Signed-off-by: Jinghao Jia <[email protected]>
  • Loading branch information
jinghao-jia committed Jul 11, 2024
1 parent ae09e77 commit 97571c4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 49 deletions.
5 changes: 0 additions & 5 deletions llvm/include/llvm/Transforms/InnerUnikernels/IUProgType.def

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand All @@ -26,17 +26,18 @@
namespace llvm {

/// Pass to insert entry points for inner-unikernel programs
class IUEntryInsertion : public PassInfoMixin<IUEntryInsertion> {
class RexEntryInsertion : public PassInfoMixin<RexEntryInsertion> {
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<Constant *> 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:
Expand All @@ -45,4 +46,4 @@ class IUEntryInsertion : public PassInfoMixin<IUEntryInsertion> {

} // namespace llvm

#endif /* LLVM_TRANSFORMS_IUINSERTENTRY_H */
#endif /* LLVM_TRANSFORMS_REXINSERTENTRY_H */
5 changes: 5 additions & 0 deletions llvm/include/llvm/Transforms/Rex/RexProgType.def
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion llvm/lib/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_llvm_component_library(LLVMPasses
Coroutines
HipStdPar
IPO
InnerUnikernels
Rex
InstCombine
IRPrinter
ObjCARC
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ add_subdirectory(ObjCARC)
add_subdirectory(Coroutines)
add_subdirectory(CFGuard)
add_subdirectory(HipStdPar)
add_subdirectory(InnerUnikernels)
add_subdirectory(Rex)
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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<Function>(Entry.getCallee());
Expand Down Expand Up @@ -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;
Expand All @@ -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<GlobalValue *, 8> UsedGV;
Expand Down Expand Up @@ -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";
}
Expand All @@ -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);
Expand Down Expand Up @@ -253,15 +253,15 @@ 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<Instruction *, 32> WorkList;
bool HasIndirect = false;

// Find all calls to other functions
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<CallBase>(&I)) {
Expand All @@ -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;

Expand All @@ -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) {
Expand All @@ -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<Function>(
M.getOrInsertFunction(M.getName().str() + "_iu_handle_timeout",
TimeoutHandlerTy, getIUFnAttr(C))
TimeoutHandlerTy, getRexFnAttr(C))
.getCallee());

// Construct function body, starting with entry BB
Expand All @@ -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<CallGraphAnalysis>(M);
Expand Down

0 comments on commit 97571c4

Please sign in to comment.