Commit 8f1077cb authored by Kevin Modzelewski's avatar Kevin Modzelewski

Pretty-print things inside invokes

Maybe this was the issue I was running into earlier
parent a9832bf5
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Cloning.h"
#include "codegen/codegen.h" #include "codegen/codegen.h"
...@@ -205,9 +206,40 @@ public: ...@@ -205,9 +206,40 @@ public:
} }
}; };
template <typename I> void remapPatchpoint(I* ii) {
int pp_id = -1;
for (int i = 0; i < ii->getNumArgOperands(); i++) {
llvm::Value* op = ii->getArgOperand(i);
if (i == 0) {
llvm::ConstantInt* l_pp_id = llvm::cast<llvm::ConstantInt>(op);
pp_id = l_pp_id->getSExtValue();
} else if (i == 2) {
assert(pp_id != -1);
void* addr = PatchpointInfo::getSlowpathAddr(pp_id);
bool lookup_success = true;
std::string name;
if (addr == (void*)None) {
name = "None";
} else {
name = g.func_addr_registry.getFuncNameAtAddress(addr, true, &lookup_success);
}
if (!lookup_success) {
llvm::Constant* int_val = llvm::ConstantInt::get(g.i64, reinterpret_cast<uintptr_t>(addr), false);
llvm::Constant* ptr_val = llvm::ConstantExpr::getIntToPtr(int_val, g.i8_ptr);
ii->setArgOperand(i, ptr_val);
continue;
} else {
ii->setArgOperand(i, ii->getParent()->getParent()->getParent()->getOrInsertGlobal(name, g.i8));
}
}
}
}
void dumpPrettyIR(llvm::Function* f) { void dumpPrettyIR(llvm::Function* f) {
//f->getParent()->dump(); // f->getParent()->dump();
//return; // return;
std::unique_ptr<llvm::Module> tmp_module(llvm::CloneModule(f->getParent())); std::unique_ptr<llvm::Module> tmp_module(llvm::CloneModule(f->getParent()));
// std::unique_ptr<llvm::Module> tmp_module(new llvm::Module("tmp", g.context)); // std::unique_ptr<llvm::Module> tmp_module(new llvm::Module("tmp", g.context));
...@@ -228,35 +260,11 @@ void dumpPrettyIR(llvm::Function* f) { ...@@ -228,35 +260,11 @@ void dumpPrettyIR(llvm::Function* f) {
if (ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_i64 if (ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_i64
|| ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_void || ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_void
|| ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_double) { || ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_double) {
int pp_id = -1; remapPatchpoint(ii);
for (int i = 0; i < ii->getNumArgOperands(); i++) { }
llvm::Value* op = ii->getArgOperand(i); } else if (llvm::InvokeInst* ii = llvm::dyn_cast<llvm::InvokeInst>(&*it)) {
if (i == 0) { if (ii->getCalledFunction()->isIntrinsic()) {
llvm::ConstantInt* l_pp_id = llvm::cast<llvm::ConstantInt>(op); remapPatchpoint(ii);
pp_id = l_pp_id->getSExtValue();
} else if (i == 2) {
assert(pp_id != -1);
void* addr = PatchpointInfo::getSlowpathAddr(pp_id);
bool lookup_success = true;
std::string name;
if (addr == (void*)None) {
name = "None";
} else {
name = g.func_addr_registry.getFuncNameAtAddress(addr, true, &lookup_success);
}
if (!lookup_success) {
llvm::Constant* int_val
= llvm::ConstantInt::get(g.i64, reinterpret_cast<uintptr_t>(addr), false);
llvm::Constant* ptr_val = llvm::ConstantExpr::getIntToPtr(int_val, g.i8_ptr);
ii->setArgOperand(i, ptr_val);
continue;
} else {
ii->setArgOperand(i, tmp_module->getOrInsertGlobal(name, g.i8));
}
}
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment