[llvm-dev] some questions about DAG
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Sat Sep 21 00:19:19 PDT 2019
Hi Jack,
On Sat, 21 Sep 2019 at 07:33, 林政宗 via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> I am reading the code about DAG to DAG Instruction selection when I meet some problems. I am confused about the using of ch, glue.
> when will they be used? And what are they used for?
"Chain" operands, sometimes written "ch" and with type MVT::Other
represent the order nodes need to be evaluated in when it's not given
by normal types and dataflow. It normally happens for nodes that have
side-effects not directly modelled by the type system. For example
load and store nodes have a chain because they affect memory, and
can't be reordered.
"Glue" is even stronger, it's for cases where even normal instructions
would be likely overwrite the desired effects. For example copying
arguments into particular registers before function calls, or a
compare followed by a branch where the flags register would be
clobbered by most arithmetic instructions.
> But how to decide which sdnode is the user of this result? for example, I have the DAG before instruction selection step, the corresponding graph is in attachment:
In general you can't tell. There may be nothing that actually depends
on a store in this graph, or it may be something like a fence, which
nothing can really depend on in a conventional sense.
> Considering t9 already has a i32 sdvalue, why ch is need? Does ch represent for MVT::Other typed sdvalue?
To make sure it happens after the store in t5 and t8, in case they are
to the same area in memory. In fact it looks like it *is* the same
local variable as t5, but that might not be obvious in all cases.
> t22 has 3 results. ch is one of them, but ch is not used by any node. why is it created?
Register copies like that can have ordering requirements. In this case
the glue would probably be sufficient to make things work, but in
general they look very much like loads & stores in affecting a
non-modelled outside resource (the specific register) in a way that it
might not be safe to move around.
I think if a node is specified to have a chain operand, it probably
has to be plumbed into the head & tail.
> what about glue? what is it used for and when is it used?
In this case it's that DivRem sets a specific, fixed, register, and
LLVM needs to get that value into a generic register as soon as
possible, before it gets clobbered by some other instruction, so the
DivRem is glued next to the CopyFromRegister.
> And when the DAG is processed, there is usually a variable chain. what is it used for? and how is it used?
Code generally has to preserve existing chain constraints when it
transforms the DAG. That probably accounts for most "SDValue Chain"
variables you'll see in C++ code.
Occasionally we also need to create new ordering requirements. In that
case you might start at the EntryToken's chain argument and create a
parallel chain.
Cheers.
Tim.
More information about the llvm-dev
mailing list