1
- // ===- IUInsertEntry .cpp - code to perform entry insertion for IU programs-===//
1
+ // ===- RexInsertEntry .cpp - code to perform entry insertion for Rex programs-===//
2
2
//
3
3
// Part of the Inner-Unikernels project, based on the LLVM project under
4
4
// the Apache License v2.0 with LLVM Exceptions.
8
8
// ===----------------------------------------------------------------------===//
9
9
// This file implements the entry code insertion pass for Inner-Unikernels
10
10
// programs. It generates a new function that calls into the __iu_entry_*()
11
- // functions in the kernel runtime crate for each global IU program
11
+ // functions in the kernel runtime crate for each global Rex program
12
12
// objects. The pass then sets the entry functions as "used" to prevent
13
13
// link-time stripping using @llvm.used, which will automatically set the
14
14
// "SHF_GNU_RETAIN" flag for these symbols.
15
15
//
16
16
// ===----------------------------------------------------------------------===//
17
17
18
- #include " llvm/Transforms/InnerUnikernels/IUInsertEntry .h"
18
+ #include " llvm/Transforms/Rex/RexInsertEntry .h"
19
19
#include " llvm/ADT/ArrayRef.h"
20
20
#include " llvm/ADT/SCCIterator.h"
21
21
#include " llvm/ADT/SmallVector.h"
52
52
53
53
using namespace llvm ;
54
54
55
- #define DEBUG_TYPE " iu -entry-insertion"
55
+ #define DEBUG_TYPE " rex -entry-insertion"
56
56
57
57
STATISTIC (NumInserted, " Number of entry function inserted" );
58
58
59
59
// / Validate program sections, the put the function and program object
60
60
// / into appropriate sections
61
- void IUEntryInsertion ::validateAndFinalizeSection (Function *EntryFn,
61
+ void RexEntryInsertion ::validateAndFinalizeSection (Function *EntryFn,
62
62
GlobalVariable *ProgObj,
63
63
unsigned ProgType) const {
64
64
// We want to strip the "inner_unikernel/" prefix
65
65
// strlen("inner_unikernel/") + 1 = 16
66
66
EntryFn->setSection (ProgObj->getSection ().substr (16 ));
67
67
switch (ProgType) {
68
- #define IU_PROG_TYPE_1 (ty_enum, ty_name, sec ) \
68
+ #define REX_PROG_TYPE_1 (ty_enum, ty_name, sec ) \
69
69
case ty_enum: \
70
70
ProgObj->setSection (" obj" #ty_name); \
71
71
assert (EntryFn->getSection ().starts_with (sec) && " invalid section name" ); \
72
72
break ;
73
- #define IU_PROG_TYPE_2 (ty_enum, ty_name, sec1, sec2 ) \
73
+ #define REX_PROG_TYPE_2 (ty_enum, ty_name, sec1, sec2 ) \
74
74
case ty_enum: \
75
75
ProgObj->setSection (" obj" #ty_name); \
76
76
assert ((EntryFn->getSection ().starts_with (sec1) || \
77
77
EntryFn->getSection ().starts_with (sec2)) && \
78
78
" invalid section name" ); \
79
79
break ;
80
- #include " llvm/Transforms/InnerUnikernels/IUProgType .def"
81
- #undef IU_PROG_TYPE_1
82
- #undef IU_PROG_TYPE_2
80
+ #include " llvm/Transforms/Rex/RexProgType .def"
81
+ #undef REX_PROG_TYPE_1
82
+ #undef REX_PROG_TYPE_2
83
83
default :
84
84
llvm_unreachable (" Unknown prog type" );
85
85
}
86
86
}
87
87
88
88
// / Performs the actual insertion of the new function
89
- Function *IUEntryInsertion ::insertEntry (Module &M, FunctionCallee &ProgRun,
89
+ Function *RexEntryInsertion ::insertEntry (Module &M, FunctionCallee &ProgRun,
90
90
GlobalVariable *ProgObj, Type *CtxPT,
91
91
StringRef Name,
92
92
unsigned ProgType) const {
@@ -98,7 +98,7 @@ Function *IUEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun,
98
98
99
99
// Declare the function in module
100
100
FunctionType *EntryTy = FunctionType::get (EntryRetty, EntryArgTys, false );
101
- FunctionCallee Entry = M.getOrInsertFunction (Name, EntryTy, getIUFnAttr (C));
101
+ FunctionCallee Entry = M.getOrInsertFunction (Name, EntryTy, getRexFnAttr (C));
102
102
103
103
// Setup attributes
104
104
Function *EntryFn = cast<Function>(Entry.getCallee ());
@@ -126,8 +126,8 @@ Function *IUEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun,
126
126
return EntryFn;
127
127
}
128
128
129
- // / Sets all the needed attribute for the Rust IU programs
130
- AttributeList IUEntryInsertion::getIUFnAttr (LLVMContext &C) const {
129
+ // / Sets all the needed attribute for the Rust Rex programs
130
+ AttributeList RexEntryInsertion::getRexFnAttr (LLVMContext &C) const {
131
131
132
132
// SIMD extensions are not allowed in the kernel
133
133
std::stringstream TargetFeatureSs;
@@ -151,7 +151,7 @@ AttributeList IUEntryInsertion::getIUFnAttr(LLVMContext &C) const {
151
151
152
152
// / Entry point of the pass, it looks at all the global variables to identify
153
153
// / the inner-unikernel program variables
154
- bool IUEntryInsertion ::runOnModule (Module &M) const {
154
+ bool RexEntryInsertion ::runOnModule (Module &M) const {
155
155
bool Changed = false ; // Whether transformation is actually made
156
156
LLVMContext &C = M.getContext ();
157
157
SmallVector<GlobalValue *, 8 > UsedGV;
@@ -179,17 +179,17 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
179
179
180
180
std::string ProgRunName;
181
181
switch (RTTI) {
182
- #define IU_PROG_TYPE_1 (ty_enum, ty_name, sec ) \
182
+ #define REX_PROG_TYPE_1 (ty_enum, ty_name, sec ) \
183
183
case ty_enum: \
184
184
ProgRunName = " __iu_entry_" #ty_name; \
185
185
break ;
186
- #define IU_PROG_TYPE_2 (ty_enum, ty_name, sec1, sec2 ) \
186
+ #define REX_PROG_TYPE_2 (ty_enum, ty_name, sec1, sec2 ) \
187
187
case ty_enum: \
188
188
ProgRunName = " __iu_entry_" #ty_name; \
189
189
break ;
190
- #include " llvm/Transforms/InnerUnikernels/IUProgType .def"
191
- #undef IU_PROG_TYPE_1
192
- #undef IU_PROG_TYPE_2
190
+ #include " llvm/Transforms/Rex/RexProgType .def"
191
+ #undef REX_PROG_TYPE_1
192
+ #undef REX_PROG_TYPE_2
193
193
default :
194
194
errs () << " Unknown RTTI " << RTTI << " \n " ;
195
195
}
@@ -210,7 +210,7 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
210
210
FunctionType *ProgRunTy =
211
211
FunctionType::get (ProgRunRetty, ProgRunArgTys, false );
212
212
FunctionCallee ProgRun =
213
- M.getOrInsertFunction (ProgRunName, ProgRunTy, getIUFnAttr (C));
213
+ M.getOrInsertFunction (ProgRunName, ProgRunTy, getRexFnAttr (C));
214
214
215
215
// name: &'a str
216
216
Constant *OP2 = CS->getOperand (2 );
@@ -253,15 +253,15 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
253
253
return Changed;
254
254
}
255
255
256
- bool IUEntryInsertion ::instrumentStack (Module &M, LLVMContext &C) const {
256
+ bool RexEntryInsertion ::instrumentStack (Module &M, LLVMContext &C) const {
257
257
SmallVector<Instruction *, 32 > WorkList;
258
258
bool HasIndirect = false ;
259
259
260
260
// Find all calls to other functions
261
261
for (auto &F : M) {
262
262
std::string Demangled;
263
263
nonMicrosoftDemangle (F.getName ().data (), Demangled);
264
- if (StringRef (Demangled).starts_with (StringRef (" inner_unikernel_rt ::" )))
264
+ if (StringRef (Demangled).starts_with (StringRef (" rex ::" )))
265
265
continue ;
266
266
for (auto &I : instructions (F)) {
267
267
if (auto *CI = dyn_cast<CallBase>(&I)) {
@@ -285,7 +285,7 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const {
285
285
return false ;
286
286
287
287
// No need to instrument if there is no indirect call and no recursion
288
- // will calculate the frame size in backend pass IUFrameSizePass
288
+ // will calculate the frame size in backend pass RexFrameSizePass
289
289
if (!HasIndirect && !Recursive)
290
290
return false ;
291
291
@@ -300,7 +300,7 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const {
300
300
301
301
FunctionType *CheckStackTy = FunctionType::get (Type::getVoidTy (C), {}, false );
302
302
FunctionCallee CheckStack =
303
- M.getOrInsertFunction (" __iu_check_stack" , CheckStackTy, getIUFnAttr (C));
303
+ M.getOrInsertFunction (" __iu_check_stack" , CheckStackTy, getRexFnAttr (C));
304
304
305
305
// Add the stack pointer instrumentation
306
306
for (auto *I : WorkList) {
@@ -311,17 +311,17 @@ bool IUEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const {
311
311
return true ;
312
312
}
313
313
314
- Function *IUEntryInsertion ::createTimeoutHandler (Module &M,
314
+ Function *RexEntryInsertion ::createTimeoutHandler (Module &M,
315
315
LLVMContext &C) const {
316
316
// Rust uses void return type for noreturn (i.e. the "!" return type)
317
317
FunctionType *TimeoutHandlerTy =
318
318
FunctionType::get (Type::getVoidTy (C), {}, false );
319
319
FunctionCallee TimeoutHandlerInner = M.getOrInsertFunction (
320
- " __iu_handle_timeout" , TimeoutHandlerTy, getIUFnAttr (C));
320
+ " __iu_handle_timeout" , TimeoutHandlerTy, getRexFnAttr (C));
321
321
322
322
Function *TimeoutHandler = cast<Function>(
323
323
M.getOrInsertFunction (M.getName ().str () + " _iu_handle_timeout" ,
324
- TimeoutHandlerTy, getIUFnAttr (C))
324
+ TimeoutHandlerTy, getRexFnAttr (C))
325
325
.getCallee ());
326
326
327
327
// Construct function body, starting with entry BB
@@ -338,7 +338,7 @@ Function *IUEntryInsertion::createTimeoutHandler(Module &M,
338
338
}
339
339
340
340
// / Wrapper for the new pass manager
341
- PreservedAnalyses IUEntryInsertion ::run (Module &M, ModuleAnalysisManager &AM) {
341
+ PreservedAnalyses RexEntryInsertion ::run (Module &M, ModuleAnalysisManager &AM) {
342
342
// Run entry insertion pass
343
343
Recursive = false ;
344
344
CallGraph &CG = AM.getResult <CallGraphAnalysis>(M);
0 commit comments