Skip to content

Commit 351e016

Browse files
committed
Rex: directly use attributes from rustc in generated entries
Signed-off-by: Jinghao Jia <[email protected]>
1 parent e84e135 commit 351e016

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

llvm/include/llvm/Transforms/Rex/RexInsertEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RexEntryInsertion : public PassInfoMixin<RexEntryInsertion> {
3030
bool runOnModule(Module &M) const;
3131
Function *insertEntry(Module &M, FunctionCallee &ProgRun,
3232
GlobalVariable *ProgObj, Type *CtxPT, StringRef Name,
33-
unsigned ProgType) const;
33+
unsigned ProgType, AttributeList Attrs) const;
3434
AttributeList getRexFnAttr(LLVMContext &C) const;
3535
void markUsedGlobalVariables(Module &M, ArrayRef<Constant *> Vec) const;
3636
void validateAndFinalizeSection(Function *EntryFn, GlobalVariable *ProgObj,

llvm/lib/Transforms/Rex/RexInsertEntry.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- RexInsertEntry.cpp - code to perform entry insertion for Rex programs-===//
1+
//===- RexInsertEntry.cpp - performs entry insertion for Rex programs -----===//
22
//
33
// Part of the Inner-Unikernels project, based on the LLVM project under
44
// the Apache License v2.0 with LLVM Exceptions.
@@ -59,8 +59,8 @@ STATISTIC(NumInserted, "Number of entry function inserted");
5959
/// Validate program sections, the put the function and program object
6060
/// into appropriate sections
6161
void RexEntryInsertion::validateAndFinalizeSection(Function *EntryFn,
62-
GlobalVariable *ProgObj,
63-
unsigned ProgType) const {
62+
GlobalVariable *ProgObj,
63+
unsigned ProgType) const {
6464
// We want to strip the "inner_unikernel/" prefix
6565
// strlen("rex/") = 4
6666
EntryFn->setSection(ProgObj->getSection().substr(4));
@@ -87,9 +87,9 @@ void RexEntryInsertion::validateAndFinalizeSection(Function *EntryFn,
8787

8888
/// Performs the actual insertion of the new function
8989
Function *RexEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun,
90-
GlobalVariable *ProgObj, Type *CtxPT,
91-
StringRef Name,
92-
unsigned ProgType) const {
90+
GlobalVariable *ProgObj, Type *CtxPT,
91+
StringRef Name, unsigned ProgType,
92+
AttributeList Attrs) const {
9393
LLVMContext &C = M.getContext();
9494

9595
// Argument and return type
@@ -98,7 +98,9 @@ Function *RexEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun,
9898

9999
// Declare the function in module
100100
FunctionType *EntryTy = FunctionType::get(EntryRetty, EntryArgTys, false);
101-
FunctionCallee Entry = M.getOrInsertFunction(Name, EntryTy, getRexFnAttr(C));
101+
FunctionCallee Entry = M.getOrInsertFunction(
102+
Name, EntryTy,
103+
AttributeList::get(C, AttributeList::FunctionIndex, Attrs.getFnAttrs()));
102104

103105
// Setup attributes
104106
Function *EntryFn = cast<Function>(Entry.getCallee());
@@ -145,7 +147,8 @@ AttributeList RexEntryInsertion::getRexFnAttr(LLVMContext &C) const {
145147
.addFnAttribute(C, "probe-stack", "__rust_probestack")
146148
.addFnAttribute(C, "target-cpu", "x86-64")
147149
.addFnAttribute(C, "target-features", TargetFeatureSs.str())
148-
.addFnAttribute(C, "tune-cpu", "generic");
150+
.addFnAttribute(C, "tune-cpu", "generic")
151+
.addFnAttribute(C, "frame-pointer", "all");
149152
return AS;
150153
}
151154

@@ -209,8 +212,10 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
209212

210213
FunctionType *ProgRunTy =
211214
FunctionType::get(ProgRunRetty, ProgRunArgTys, false);
212-
FunctionCallee ProgRun =
213-
M.getOrInsertFunction(ProgRunName, ProgRunTy, getRexFnAttr(C));
215+
FunctionCallee ProgRun = M.getOrInsertFunction(
216+
ProgRunName, ProgRunTy,
217+
AttributeList::get(C, AttributeList::FunctionIndex,
218+
Func->getAttributes().getFnAttrs()));
214219

215220
// name: &'a str
216221
Constant *OP2 = CS->getOperand(2);
@@ -229,7 +234,8 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
229234
NamedMD->addOperand(Node);
230235

231236
// Add the function using the extracted information above
232-
Function *EntryFunc = insertEntry(M, ProgRun, &G, CtxPT, ProgName, RTTI);
237+
Function *EntryFunc = insertEntry(M, ProgRun, &G, CtxPT, ProgName, RTTI,
238+
Func->getAttributes());
233239
UsedGV.push_back(EntryFunc);
234240

235241
// Transformation made
@@ -312,7 +318,7 @@ bool RexEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const {
312318
}
313319

314320
Function *RexEntryInsertion::createTimeoutHandler(Module &M,
315-
LLVMContext &C) const {
321+
LLVMContext &C) const {
316322
// Rust uses void return type for noreturn (i.e. the "!" return type)
317323
FunctionType *TimeoutHandlerTy =
318324
FunctionType::get(Type::getVoidTy(C), {}, false);

0 commit comments

Comments
 (0)