Skip to content

Commit

Permalink
migrate remaining 'iu' names to 'rex'
Browse files Browse the repository at this point in the history
Signed-off-by: Jinghao Jia <[email protected]>
  • Loading branch information
jinghao-jia authored and chinrw committed Aug 24, 2024
1 parent 2f02f76 commit c1f45aa
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/AsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class AsmPrinter : public MachineFunctionPass {
/// Emits the PC sections collected from instructions.
void emitPCSections(const MachineFunction &MF);

void checkStackUsageIU(const MachineFunction &MF) const;
void checkStackUsageRex(const MachineFunction &MF) const;

/// Get the CFISection type for a function.
CFISection getFunctionCFISectionType(const Function &F) const;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Target/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ namespace llvm {
unsigned XCOFFReadOnlyPointers : 1;

/// Inner-unikernel flag
unsigned IUEnabled : 1;
unsigned RexEnabled : 1;

/// Name of the stack usage file (i.e., .su file) if user passes
/// -fstack-usage. If empty, it can be implied that -fstack-usage is not
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ static bool needFuncLabels(const MachineFunction &MF) {
classifyEHPersonality(MF.getFunction().getPersonalityFn()));
}

void AsmPrinter::checkStackUsageIU(const MachineFunction &MF) const {
void AsmPrinter::checkStackUsageRex(const MachineFunction &MF) const {
unsigned Limit = 0x1000;
const MachineFrameInfo &FrameInfo = MF.getFrameInfo();

Expand All @@ -1685,7 +1685,7 @@ void AsmPrinter::checkStackUsageIU(const MachineFunction &MF) const {
raw_string_ostream OS(ErrMsg);
OS << "Stack usage exceeded limit of 4096 bytes"
<< " for function " << MF.getName()
<< " in inner-unikernel module "
<< " in Rex module "
<< MF.getFunction().getParent()->getName();
}
report_fatal_error(StringRef(ErrMsg));
Expand All @@ -1695,7 +1695,7 @@ void AsmPrinter::checkStackUsageIU(const MachineFunction &MF) const {
raw_string_ostream OS(ErrMsg);
OS << "Stack contains variable sized objects"
<< " for function " << MF.getName()
<< " in inner-unikernel module "
<< " in Rex module "
<< MF.getFunction().getParent()->getName();
}
report_fatal_error(StringRef(ErrMsg));
Expand Down Expand Up @@ -2033,8 +2033,8 @@ void AsmPrinter::emitFunctionBody() {
emitStackUsage(*MF);

// Check the stack usage for inner-unikernel programs
if (MF->getTarget().Options.IUEnabled)
checkStackUsageIU(*MF);
if (MF->getTarget().Options.RexEnabled)
checkStackUsageRex(*MF);

emitPatchableFunctionEntries();

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ set(sources
GISel/X86InstructionSelector.cpp
GISel/X86LegalizerInfo.cpp
GISel/X86RegisterBankInfo.cpp
X86IUFrameSize.cpp
X86RexFrameSize.cpp
)

add_llvm_target(X86CodeGen ${sources}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ FunctionPass *createX86LoadValueInjectionRetHardeningPass();
FunctionPass *createX86SpeculativeLoadHardeningPass();
FunctionPass *createX86SpeculativeExecutionSideEffectSuppression();
FunctionPass *createX86ArgumentStackSlotPass();
ModulePass *createX86IUFrameSizePass();
ModulePass *createX86RexFrameSizePass();

void initializeCompressEVEXPassPass(PassRegistry &);
void initializeFPSPass(PassRegistry &);
Expand Down Expand Up @@ -201,7 +201,7 @@ void initializeX86ReturnThunksPass(PassRegistry &);
void initializeX86SpeculativeExecutionSideEffectSuppressionPass(PassRegistry &);
void initializeX86SpeculativeLoadHardeningPassPass(PassRegistry &);
void initializeX86TileConfigPass(PassRegistry &);
void initializeX86IUFrameSizePassPass(PassRegistry &);
void initializeX86RexFrameSizePassPass(PassRegistry &);

namespace X86AS {
enum : unsigned {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

using namespace llvm;

#define X86IUFrameSizePassName "X86 frame buffer size check"
#define X86RexFrameSizePassName "X86 frame buffer size check"
#define PASS_KEY "x86-frame-buffer-size"
#define DEBUG_TYPE PASS_KEY

namespace {

class X86IUFrameSizePassMF {
class X86RexFrameSizePassMF {
public:
X86IUFrameSizePassMF(const Module *M, const MachineModuleInfo *MMI)
X86RexFrameSizePassMF(const Module *M, const MachineModuleInfo *MMI)
: M(M), MMI(MMI) {}
bool run();
void runOnMachineFunction(MachineFunction &MF);
Expand All @@ -45,13 +45,13 @@ class X86IUFrameSizePassMF {
static constexpr uint64_t FrameSizeLimit = (0x1000UL << 2) - 0x1000;
};

class X86IUFrameSizePass : public ModulePass {
class X86RexFrameSizePass : public ModulePass {
public:
static char ID;

X86IUFrameSizePass() : ModulePass(ID) {}
X86RexFrameSizePass() : ModulePass(ID) {}
bool runOnModule(Module &M) override;
StringRef getPassName() const override { return X86IUFrameSizePassName; }
StringRef getPassName() const override { return X86RexFrameSizePassName; }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<MachineModuleInfoWrapperPass>();
AU.setPreservesAll();
Expand All @@ -61,39 +61,39 @@ class X86IUFrameSizePass : public ModulePass {

} // end anonymous namespace

char X86IUFrameSizePass::ID = 0;
char X86RexFrameSizePass::ID = 0;

INITIALIZE_PASS(X86IUFrameSizePass, PASS_KEY, X86IUFrameSizePassName, false,
INITIALIZE_PASS(X86RexFrameSizePass, PASS_KEY, X86RexFrameSizePassName, false,
true)

ModulePass *llvm::createX86IUFrameSizePass() {
return new X86IUFrameSizePass();
ModulePass *llvm::createX86RexFrameSizePass() {
return new X86RexFrameSizePass();
}

bool X86IUFrameSizePass::runOnModule(Module &M) {
bool X86RexFrameSizePass::runOnModule(Module &M) {
const MachineModuleInfo *MMI =
&getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
return X86IUFrameSizePassMF(&M, MMI).run();
return X86RexFrameSizePassMF(&M, MMI).run();
}

bool X86IUFrameSizePassMF::run() {
bool X86RexFrameSizePassMF::run() {

bool Failed = false;

// check for iu-stack iu-indirect-call and recursion
NamedMDNode *IUStackMD = M->getNamedMetadata("iu-stack");
// check for rex-stack rex-indirect-call and recursion
NamedMDNode *RexStackMD = M->getNamedMetadata("rex-stack");

if (IUStackMD) {
for (unsigned I = 0, E = IUStackMD->getNumOperands(); I != E; ++I) {
MDNode *Node = IUStackMD->getOperand(I);
if (RexStackMD) {
for (unsigned I = 0, E = RexStackMD->getNumOperands(); I != E; ++I) {
MDNode *Node = RexStackMD->getOperand(I);
if (MDString *Str = dyn_cast<MDString>(Node->getOperand(0))) {
StringRef Value = Str->getString();

// skip pass with recursion
if (Value == "iu-recursion")
if (Value == "rex-recursion")
Failed |= true;

if (Value == "iu-indirect-call")
if (Value == "rex-indirect-call")
Failed |= true;
}
}
Expand All @@ -104,12 +104,12 @@ bool X86IUFrameSizePassMF::run() {

SmallVector<StringRef, 32> WorkList;

// get the iu-program function name
NamedMDNode *IUProgMD = M->getNamedMetadata("iu-programs");
// get the rex-program function name
NamedMDNode *RexProgMD = M->getNamedMetadata("rex-programs");

if (IUProgMD) {
for (unsigned I = 0, E = IUProgMD->getNumOperands(); I != E; ++I) {
MDNode *Node = IUProgMD->getOperand(I);
if (RexProgMD) {
for (unsigned I = 0, E = RexProgMD->getNumOperands(); I != E; ++I) {
MDNode *Node = RexProgMD->getOperand(I);
if (MDString *Str = dyn_cast<MDString>(Node->getOperand(0))) {

// add entry function to the worklist
Expand Down Expand Up @@ -146,7 +146,7 @@ bool X86IUFrameSizePassMF::run() {
return false;
}

void X86IUFrameSizePassMF::runOnMachineFunction(MachineFunction &MF) {
void X86RexFrameSizePassMF::runOnMachineFunction(MachineFunction &MF) {
uint64_t FrameSize = getFrameSize(MF);
if (FrameSize > FrameSizeLimit) {
std::string ErrMsg;
Expand All @@ -160,7 +160,7 @@ void X86IUFrameSizePassMF::runOnMachineFunction(MachineFunction &MF) {
}
}

uint64_t X86IUFrameSizePassMF::getFrameSize(const MachineFunction &MF) {
uint64_t X86RexFrameSizePassMF::getFrameSize(const MachineFunction &MF) {

using FrameSizeEntry = std::pair<const MachineFunction *, uint64_t>;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86Target() {
initializeX86FlagsCopyLoweringPassPass(PR);
initializeX86LoadValueInjectionLoadHardeningPassPass(PR);
initializeX86LoadValueInjectionRetHardeningPassPass(PR);
initializeX86IUFrameSizePassPass(PR);
initializeX86RexFrameSizePassPass(PR);
initializeX86OptimizeLEAPassPass(PR);
initializeX86PartialReductionPass(PR);
initializePseudoProbeInserterPass(PR);
Expand Down Expand Up @@ -626,7 +626,7 @@ void X86PassConfig::addPreEmitPass2() {

// Insert pseudo probe annotation for callsite profiling
addPass(createPseudoProbeInserter());
addPass(createX86IUFrameSizePass());
addPass(createX86RexFrameSizePass());

// KCFI indirect call checks are lowered to a bundle, and on Darwin platforms,
// also CALL_RVMARKER.
Expand Down
32 changes: 16 additions & 16 deletions llvm/lib/Transforms/Rex/RexInsertEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
// This file implements the entry code insertion pass for Inner-Unikernels
// programs. It generates a new function that calls into the __iu_entry_*()
// programs. It generates a new function that calls into the __rex_entry_*()
// 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
Expand Down Expand Up @@ -62,8 +62,8 @@ 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));
// strlen("rex/") = 4
EntryFn->setSection(ProgObj->getSection().substr(4));
switch (ProgType) {
#define REX_PROG_TYPE_1(ty_enum, ty_name, sec) \
case ty_enum: \
Expand Down Expand Up @@ -159,13 +159,13 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
// Perform stack depth instrumentation
Changed |= instrumentStack(M, C);

NamedMDNode *NamedMD = M.getOrInsertNamedMetadata("iu-programs");
NamedMDNode *NamedMD = M.getOrInsertNamedMetadata("rex-programs");

LLVMContext &Context = M.getContext();

// Traverse all Global variables
for (GlobalVariable &G : M.globals()) {
if (G.hasSection() && G.getSection().starts_with("inner_unikernel")) {
if (G.hasSection() && G.getSection().starts_with("rex")) {
Constant *Init = G.getInitializer();
auto *CS = cast<ConstantStruct>(Init);

Expand All @@ -181,11 +181,11 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
switch (RTTI) {
#define REX_PROG_TYPE_1(ty_enum, ty_name, sec) \
case ty_enum: \
ProgRunName = "__iu_entry_" #ty_name; \
ProgRunName = "__rex_entry_" #ty_name; \
break;
#define REX_PROG_TYPE_2(ty_enum, ty_name, sec1, sec2) \
case ty_enum: \
ProgRunName = "__iu_entry_" #ty_name; \
ProgRunName = "__rex_entry_" #ty_name; \
break;
#include "llvm/Transforms/Rex/RexProgType.def"
#undef REX_PROG_TYPE_1
Expand Down Expand Up @@ -240,7 +240,7 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
// Make sure the timeout handler is always in the final executable
UsedGV.push_back(createTimeoutHandler(M, C));

// Mark the Variables (i.e. inserted functions and iu-prog objects) as
// Mark the Variables (i.e. inserted functions and rex-prog objects) as
// used as these symbols are typically considered as dead code during the
// linking stage if the '--gc-sections' option is supplied to the linker.
// Marking the symbols as used would add the 'SHF_GNU_RETAIN' flag and
Expand Down Expand Up @@ -291,16 +291,16 @@ bool RexEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const {

// Add metadata to backend pass
if (HasIndirect) {
NamedMDNode *NamedMD = M.getOrInsertNamedMetadata("iu-stack");
NamedMDNode *NamedMD = M.getOrInsertNamedMetadata("rex-stack");
LLVMContext &Context = M.getContext();
Metadata *Str = MDString::get(Context, "iu-indirect-call");
Metadata *Str = MDString::get(Context, "rex-indirect-call");
MDNode *Node = MDNode::get(Context, Str);
NamedMD->addOperand(Node);
}

FunctionType *CheckStackTy = FunctionType::get(Type::getVoidTy(C), {}, false);
FunctionCallee CheckStack =
M.getOrInsertFunction("__iu_check_stack", CheckStackTy, getRexFnAttr(C));
M.getOrInsertFunction("__rex_check_stack", CheckStackTy, getRexFnAttr(C));

// Add the stack pointer instrumentation
for (auto *I : WorkList) {
Expand All @@ -317,18 +317,18 @@ Function *RexEntryInsertion::createTimeoutHandler(Module &M,
FunctionType *TimeoutHandlerTy =
FunctionType::get(Type::getVoidTy(C), {}, false);
FunctionCallee TimeoutHandlerInner = M.getOrInsertFunction(
"__iu_handle_timeout", TimeoutHandlerTy, getRexFnAttr(C));
"__rex_handle_timeout", TimeoutHandlerTy, getRexFnAttr(C));

Function *TimeoutHandler = cast<Function>(
M.getOrInsertFunction(M.getName().str() + "_iu_handle_timeout",
M.getOrInsertFunction(M.getName().str() + "_rex_handle_timeout",
TimeoutHandlerTy, getRexFnAttr(C))
.getCallee());

// Construct function body, starting with entry BB
BasicBlock *EntryBB = BasicBlock::Create(C, "start", TimeoutHandler);
IRBuilder<> InstBuilder(EntryBB);

// Construct call to __iu_handle_timeout
// Construct call to __rex_handle_timeout
InstBuilder.CreateCall(TimeoutHandlerInner.getFunctionType(),
TimeoutHandlerInner.getCallee(), {});

Expand All @@ -354,9 +354,9 @@ PreservedAnalyses RexEntryInsertion::run(Module &M, ModuleAnalysisManager &AM) {

if (Recursive) {
errs() << "Found recursive call graph with Module " << M.getName() << "\n";
NamedMDNode *NamedMD = M.getOrInsertNamedMetadata("iu-stack");
NamedMDNode *NamedMD = M.getOrInsertNamedMetadata("rex-stack");
LLVMContext &Context = M.getContext();
Metadata *Str = MDString::get(Context, "iu-recursion");
Metadata *Str = MDString::get(Context, "rex-recursion");
MDNode *Node = MDNode::get(Context, Str);
NamedMD->addOperand(Node);
}
Expand Down
1 change: 0 additions & 1 deletion llvm/utils/gn/secondary/llvm/lib/Target/X86/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ static_library("LLVMX86CodeGen") {
"X86TileConfig.cpp",
"X86VZeroUpper.cpp",
"X86WinEHState.cpp",
"X86IUFrameSize.cpp",
]
}

Expand Down

0 comments on commit c1f45aa

Please sign in to comment.