jit: better module stripping (#2743)

This commit is contained in:
Ivan Butygin 2018-06-10 16:54:42 +03:00 committed by GitHub
parent 86265da6b0
commit 65337ed170
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 0 deletions

View file

@ -169,6 +169,22 @@ void iterateFuncInstructions(llvm::Function &func, F &&handler) {
} // for (auto &&bb : fun)
}
template<typename I>
void stripDeclarations(llvm::iterator_range<I> range) {
for (auto it = range.begin(); it != range.end();) {
auto elem = &(*it);
++it;
if (elem->isDeclaration() && elem->use_empty()) {
elem->eraseFromParent();
}
}
}
void stripModule(llvm::Module &module) {
stripDeclarations(module.functions());
stripDeclarations(module.globals());
}
void fixRtModule(llvm::Module &newModule,
const decltype(IRState::dynamicCompiledFunctions) &funcs) {
std::unordered_map<std::string, std::string> thunkVar2func;
@ -224,6 +240,8 @@ void fixRtModule(llvm::Module &newModule,
}
}
}
stripModule(newModule);
}
void removeFunctionsTargets(IRState *irs, llvm::Module &module) {