How correctly remove function from module?
For example:
int f1(int x) {
...
a = f2(smth);
...
}
int f2 (int y) {
...
b = f1(smth);
...
}
I need delete from module both f1 and f2. They haven't uses in other part of
module, but I can't delete them with eraseFromParent, because they are use
each other.
Yours sincerely,
Kadysev Mikhail
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120421/8f492716/attachment.html>
Михаил wrote:> How correctly remove function from module? > For example: > > int f1(int x) { > ... > a = f2(smth); > ... > } > int f2 (int y) { > ... > b = f1(smth); > ... > } > > I need delete from module both f1 and f2. They haven't uses in other > part of module, but I can't delete them with eraseFromParent, because > they are use each other.Call X->replaceAllUsesWith(UndefValue::get(X->getType)) before calling X->eraseFromParent(). Nick
Hi Михаил,
You can also use GVExtractionPass:
if (!strcmp(argv[1], "pass"))
{
PassManager manager;
manager.add(new TargetData(m.get()));
// Delete functions specified in list of functions.
vector<GlobalValue*> functions;
functions.push_back(m.get()->getFunction("f1"));
functions.push_back(m.get()->getFunction("f2"));
manager.add(createGVExtractionPass(functions, true));
// Delete unreachable globals.
manager.add(createGlobalDCEPass());
// Remove dead debug info.
manager.add(createStripDeadDebugInfoPass());
// Remove dead func decls.
manager.add(createStripDeadPrototypesPass());
manager.run(*m.get());
}
if (!strcmp(argv[1], "manual"))
{
Function* f1 = m.get()->getFunction("f1");
Function* f2 = m.get()->getFunction("f2");
f1->replaceAllUsesWith(UndefValue::get((Type*)f1->getType()));
f2->replaceAllUsesWith(UndefValue::get((Type*)f2->getType()));
f1->eraseFromParent();
f2->eraseFromParent();
}
- D.
2012/4/21 Nick Lewycky <nicholas at mxc.ca>:> Михаил wrote:
>> How correctly remove function from module?
>> For example:
>>
>> int f1(int x) {
>> ...
>> a = f2(smth);
>> ...
>> }
>> int f2 (int y) {
>> ...
>> b = f1(smth);
>> ...
>> }
>>
>> I need delete from module both f1 and f2. They haven't uses in
other
>> part of module, but I can't delete them with eraseFromParent,
because
>> they are use each other.
>
> Call X->replaceAllUsesWith(UndefValue::get(X->getType)) before
calling
> X->eraseFromParent().
>
> Nick
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: makefile
Type: application/octet-stream
Size: 388 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120422/f64ca9da/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 98 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120422/f64ca9da/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.ll
Type: application/octet-stream
Size: 1755 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120422/f64ca9da/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transform.cxx
Type: application/octet-stream
Size: 1875 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120422/f64ca9da/attachment-0002.obj>
Thanks, but I replaceAllUsesWith() - works well, but I still get bug in eraseFromParent(): While deleting: i32 (%class.B*, i32)* %_ZN1B1xEi An asserting value handle still pointed to this value! UNREACHABLE executed at /Users/neonomaly/LLVM/LLVM/lib/VMCore/Value.cpp:561! Yours sincerely, Kadysev Mikhail 21.04.2012, в 23:45, Nick Lewycky написал(а):> Михаил wrote: >> How correctly remove function from module? >> For example: >> >> int f1(int x) { >> ... >> a = f2(smth); >> ... >> } >> int f2 (int y) { >> ... >> b = f1(smth); >> ... >> } >> >> I need delete from module both f1 and f2. They haven't uses in other >> part of module, but I can't delete them with eraseFromParent, because >> they are use each other. > > Call X->replaceAllUsesWith(UndefValue::get(X->getType)) before calling X->eraseFromParent(). > > Nick-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120422/a1ef5335/attachment.html>