Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Software tracer llvm pass #109

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/include/llvm/Transforms/Yk/SoftwareTracer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LLVM_TRANSFORMS_YK_HELLOWORLD_H
#define LLVM_TRANSFORMS_YK_HELLOWORLD_H

#include "llvm/Pass.h"

namespace llvm {
ModulePass *createSoftwareTracerPass();
} // namespace llvm

#endif
9 changes: 7 additions & 2 deletions llvm/lib/CodeGen/TargetPassConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "llvm/Transforms/Yk/ShadowStack.h"
#include "llvm/Transforms/Yk/Stackmaps.h"
#include "llvm/Transforms/Yk/NoCallsInEntryBlocks.h"
#include "llvm/Transforms/Yk/SoftwareTracer.h"
#include <cassert>
#include <optional>
#include <string>
Expand Down Expand Up @@ -284,8 +285,8 @@ static cl::opt<bool>
cl::desc("Insert stackmaps for JIT deoptimisation"));

static cl::opt<bool>
YkNoCallsInEntryBlocks("yk-no-calls-in-entryblocks", cl::init(false), cl::NotHidden,
cl::desc("Ensure there are no calls in the entryblock."));
YkSoftwareTracer("yk-software-tracer", cl::init(false), cl::NotHidden,
cl::desc("Enables YK Software Tracer capability"));

/// Allow standard passes to be disabled by command line options. This supports
/// simple binary flags that either suppress the pass or do nothing.
Expand Down Expand Up @@ -1166,6 +1167,10 @@ bool TargetPassConfig::addISelPasses() {
addPass(createYkStackmapsPass());
}

if (YkSoftwareTracer) {
addPass(createSoftwareTracerPass());
}

addISelPrepare();
return addCoreISelPasses();
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Yk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_llvm_component_library(LLVMYkPasses
StackMaps.cpp
ShadowStack.cpp
NoCallsInEntryBlocks.cpp
SoftwareTracer.cpp

DEPENDS
intrinsics_gen
Expand Down
52 changes: 52 additions & 0 deletions llvm/lib/Transforms/Yk/SoftwareTracer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "llvm/Transforms/Yk/SoftwareTracer.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"

#define DEBUG_TYPE "yk-software-tracer-pass"

using namespace llvm;

namespace {

struct SoftwareTracerPass : public ModulePass {
static char ID;
Function *externalFunc = NULL;

SoftwareTracerPass() : ModulePass(ID) {}

bool runOnModule(Module &M) override {
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
LLVMContext &Context = M.getContext();
if (externalFunc == NULL) {
FunctionType *FType =
FunctionType::get(Type::getVoidTy(Context), {}, false);
externalFunc = Function::Create(FType, GlobalVariable::ExternalLinkage,
YK_TRACE_FUNCTION, M);
}
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;
++BI) {
// Insert function call instruction
IRBuilder<> builder(Context);
builder.SetInsertPoint(&(*BI));
builder.CreateCall(externalFunc);
}
}
}
return true;
}
};
} // namespace
char SoftwareTracerPass::ID = 0;

ModulePass *llvm::createSoftwareTracerPass() {
return new SoftwareTracerPass();
}