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 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "codegen/codegen.h"
......@@ -205,29 +206,7 @@ public:
}
};
void dumpPrettyIR(llvm::Function* f) {
//f->getParent()->dump();
//return;
std::unique_ptr<llvm::Module> tmp_module(llvm::CloneModule(f->getParent()));
// std::unique_ptr<llvm::Module> tmp_module(new llvm::Module("tmp", g.context));
llvm::Function* new_f = tmp_module->begin();
llvm::ValueToValueMapTy VMap;
llvm::RemapFlags flags = llvm::RF_None;
llvm::ValueMapTypeRemapper* type_remapper = NULL;
PrettifyingMaterializer materializer(tmp_module.get(), VMap, flags, type_remapper);
for (llvm::Function::iterator I = new_f->begin(), E = new_f->end(); I != E; ++I) {
VMap[I] = I;
}
for (llvm::inst_iterator it = inst_begin(new_f), end = inst_end(new_f); it != end; ++it) {
llvm::RemapInstruction(&*it, VMap, flags, type_remapper, &materializer);
if (llvm::IntrinsicInst* ii = llvm::dyn_cast<llvm::IntrinsicInst>(&*it)) {
if (ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_i64
|| ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_void
|| ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_double) {
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);
......@@ -247,16 +226,45 @@ void dumpPrettyIR(llvm::Function* f) {
}
if (!lookup_success) {
llvm::Constant* int_val
= llvm::ConstantInt::get(g.i64, reinterpret_cast<uintptr_t>(addr), false);
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));
ii->setArgOperand(i, ii->getParent()->getParent()->getParent()->getOrInsertGlobal(name, g.i8));
}
}
}
}
void dumpPrettyIR(llvm::Function* f) {
// f->getParent()->dump();
// return;
std::unique_ptr<llvm::Module> tmp_module(llvm::CloneModule(f->getParent()));
// std::unique_ptr<llvm::Module> tmp_module(new llvm::Module("tmp", g.context));
llvm::Function* new_f = tmp_module->begin();
llvm::ValueToValueMapTy VMap;
llvm::RemapFlags flags = llvm::RF_None;
llvm::ValueMapTypeRemapper* type_remapper = NULL;
PrettifyingMaterializer materializer(tmp_module.get(), VMap, flags, type_remapper);
for (llvm::Function::iterator I = new_f->begin(), E = new_f->end(); I != E; ++I) {
VMap[I] = I;
}
for (llvm::inst_iterator it = inst_begin(new_f), end = inst_end(new_f); it != end; ++it) {
llvm::RemapInstruction(&*it, VMap, flags, type_remapper, &materializer);
if (llvm::IntrinsicInst* ii = llvm::dyn_cast<llvm::IntrinsicInst>(&*it)) {
if (ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_i64
|| ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_void
|| ii->getIntrinsicID() == llvm::Intrinsic::experimental_patchpoint_double) {
remapPatchpoint(ii);
}
} else if (llvm::InvokeInst* ii = llvm::dyn_cast<llvm::InvokeInst>(&*it)) {
if (ii->getCalledFunction()->isIntrinsic()) {
remapPatchpoint(ii);
}
}
}
......
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