В настоящее время я изучаю создание пользовательского бэкэнда для цели. В официальных документах llvm https://llvm.org/docs/WritingAnLLVMBackend.html#basic-steps упоминается, что для понижения Dag нам необходимо модифицировать [Target]ISelDAGToDAG.cpp и [Target]ISelLowering.cpp. Я исследовал несколько целей llvm. Но не в состоянии уловить разницу.
Интересный момент, потому что изучение структуры внутреннего кода не является тривиальным, и каждая цель реализуется в отдельной подпапке в папке Target.
с несколькими файлами .cpp
, .h
и .td
.
Поскольку в предоставленном вами связь упоминается следующее:
"Также напишите код в XXXISelLowering.cpp
, чтобы заменить или удалить операции и типы данных, которые изначально не поддерживаются в SelectionDAG
."
Давайте двигаться вперед. Я бы ответил более крупной картинкой, показывающей основные шаги
до выбор инструкции, начиная с LLVM IR
шаг, который находится в левом верхнем углу, а затем цитирует Начало работы с LLVM
Основные библиотеки:
First, a
SelectionDAGBuilder
instance (seeSelectionDAGISel.cpp
for details) visits every function and creates aSelectionDAG
object for each basic block. During this process, some special IR instructions such ascall
andret
already need targetspecific idioms—for instance, how to pass call arguments and how to return from a function—to be transformed intoSelectionDAG
nodes. To solve this issue, the algorithms in theTargetLowering
class are used for the first time. This class is an abstract interface that each target must implement, but also has plenty of common functionality used throughout all backends.
To implement this abstract interface, each target declares a
TargetLowering
subclass named<Target>TargetLowering
. Each target also overloads methods that implement how a specific target-independent, high-level node should be lowered to a level closer to the one of this machine. As expected, only a small subset of nodes must be lowered in this way, while the majority of the others are matched and replaced at instruction selection. For instance, inSelectionDAG
fromsum. bc
, theX86TargetLowering::LowerReturn()
method (seelib/Target/X86/ X86ISelLowering.cpp
) is used to lower the IRret
instruction. While doing this, it generates theX86ISD::RET_FLAG
node, which copies the function result toEAX
—a target-specific way to handle the function return.
Точно! [Target]ISelDAGToDAG.cpp
для выбора инструкций. Например, если вашей целью является SPARC, вы используете этот Иселдагтодаг.cpp для выбора инструкций.
Спасибо за ответ. «Как и ожидалось, только небольшое подмножество узлов должно быть понижено таким образом, в то время как большинство других сопоставляются и заменяются при выборе инструкции ...», это дает мне много смысла. Затем [Target]ISelDAGToDAG.cpp для выбора инструкции, не так ли?