Commit c6c87982 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix IR-prettifier to correctly remap void patchpoints

parent 6720893e
...@@ -201,21 +201,40 @@ public: ...@@ -201,21 +201,40 @@ public:
return module->getOrInsertGlobal(name, pt->getElementType()); return module->getOrInsertGlobal(name, pt->getElementType());
} }
} }
if (llvm::IntrinsicInst* ii = llvm::dyn_cast<llvm::IntrinsicInst>(v)) { return v;
}
};
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 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; int pp_id = -1;
for (int i = 0; i < ii->getNumArgOperands(); i++) { for (int i = 0; i < ii->getNumArgOperands(); i++) {
llvm::Value* op = ii->getArgOperand(i); llvm::Value* op = ii->getArgOperand(i);
if (i != 2) { if (i == 0) {
if (i == 0) { llvm::ConstantInt* l_pp_id = llvm::cast<llvm::ConstantInt>(op);
llvm::ConstantInt* l_pp_id = llvm::cast<llvm::ConstantInt>(op); pp_id = l_pp_id->getSExtValue();
pp_id = l_pp_id->getSExtValue(); } else if (i == 2) {
}
ii->setArgOperand(i, llvm::MapValue(op, VMap, flags, type_remapper, this));
continue;
} else {
assert(pp_id != -1); assert(pp_id != -1);
void* addr = PatchpointInfo::getSlowpathAddr(pp_id); void* addr = PatchpointInfo::getSlowpathAddr(pp_id);
...@@ -234,35 +253,12 @@ public: ...@@ -234,35 +253,12 @@ public:
ii->setArgOperand(i, ptr_val); ii->setArgOperand(i, ptr_val);
continue; continue;
} else { } else {
ii->setArgOperand(i, module->getOrInsertGlobal(name, g.i8)); ii->setArgOperand(i, tmp_module->getOrInsertGlobal(name, g.i8));
} }
} }
} }
return ii;
} }
} }
return v;
}
};
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);
} }
tmp_module->begin()->dump(); tmp_module->begin()->dump();
// tmp_module->dump(); // tmp_module->dump();
......
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