【问题标题】:When and where did the LLVM IR Instruction set it's parent BasicBlock?LLVM IR 指令何时何地设置它的父 BasicBlock?
【发布时间】:2018-04-26 05:59:46
【问题描述】:

当我使用方法将指令插入 BasicBlock 时

BasicBlock::getInstList().push_front(*Instruction); 

但它何时将指令的父级设置为当前的 BasicBlock?

代码如下,运行良好。我只想知道何时何地设置克隆指令的父级。

谢谢。

Instruction *ori_inst = cur_inst->clone();  
//until now, the ori_inst does not have it's parent
CUR_BB->getInstList().push_front(ori_inst); 
//now, the ori_inst has CUR_BB as it's parent, why?

【问题讨论】:

    标签: llvm llvm-ir


    【解决方案1】:

    我认为这是在

    中设置的
    void SymbolTableListTraits<ValueSubClass,ItemParentClass>
          ::addNodeToList(ValueSubClass *V) {
    

    lib/IR/SymbolTableListTraitsImpl.h

    addNodeToListilistinsert方法调用,该方法被push_front调用。因此,每当您将指令添加到基本块中的指令列表时,其父级将自动设置为基本块本身。

    【讨论】:

    • 非常感谢。但是 iplist 是如何调用这个 addNodeToList() 的呢?在“ilist.h”中,它看起来像“void addNodeToList(NodeTy *) {}”,您能告诉我它是如何调用 lib/IR/SymbolTableListTraitsImpl.h 中的那个吗?谢谢
    • @UDNightWish:通过特征机制。如果您在通过代码跟踪它时遇到问题,我建议您在 gdb 的叶子方法中放置一个断点,然后查看堆栈跟踪。
    • 可能是我在理解 C++ 模板代码时遇到了麻烦。感谢您的指导!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    相关资源
    最近更新 更多