0

命令をLLVMに置き換える方法を理解しようとしており、元の命令と同じように設定された参照を、作成した新しい命令にリセットできるようにしています(私の人生では、本当に苦労していますLLVM ドキュメントをナビゲートする時間)

私は命令 i を持っていて、それが私が置き換えたいものであることを知っているとしましょう-私はこれをやっています

    BinaryOperator::Create(Instruction::Add, value, operand, "", i);
    i->eraseFromParent();

新しい命令を作成し、それを i の前に配置するには、置き換える命令です。次に、i を削除します。

私の問題は、古い命令がレジスタに設定され、後で %2 がストアに再利用されることです (たとえば、以下のように)。

%2 = mul %0, 2

命令 i を削除する際に、%2 を含む行全体を削除しました。新しい命令が他のレジスタに設定されていると想定しています。どうすればこれを処理できますか? 使用できる ReplaceInstWithInst 呼び出しがあることを見てきましたが、それが問題を解決するかどうか、またはどのように機能するかはわかりません。

4

1 に答える 1

1

There are no registers or variables in the LLVM intermediate language, nor are there any assignments. Confused? I recommend reading more about SSA form.

In particular, I recommend avoiding thinking in names (%something). Names are only useful for the textual representation of the intermediate language (.ll files), they don't have too many uses when you use LLVM APIs directly.

In any case, replaceinstwithinst is a good way to replace one instruction with another. What it actually does is replace all the uses of the old instruction with uses of the new one.

于 2013-04-27T19:56:10.277 に答える