MDL SDK API nvidia_logo_transpbg.gif Up
MDL DAG IR

The MDL DAG IR is an intermediate representation currently used for MDL materials, MDL material instances, and lambda functions (part of materials).

The DAG IR is a directed acyclic dependence graph with exactly one root, representing one MDL expression.

A node A has an edge to a node B, if and only if the computation of A depends on the computation of B, in particular the expression B is an argument of the call A. Hence, edges in the DAG IR are in reverse order compared to data-flow graphs, where the edges would be from the definition to the user. In DAG IR, all edges go from the user to the definition (the source of a value).

Currently, MDL statements cannot be represented in the DAG IR, hence the bodies of MDL functions cannot be represented. This will be changed in the future.

Currently, the DAG IR consists of only four different DAG IR nodes:

  • A DAG_constant represents a single literal value inside the IR. DAG_constants are always leafs inside the DAG.
  • A DAG_call represents the call to a function, operator, or material inside the IR. Its children are the arguments of the call. The edges to the children are attributed by the parameter name and an index. They must always correspond to the parameter order of the called entity.
  • A DAG_parameter represents a parameter of the owning entity. Parameters only have one index attribute that corresponds to the index of the parameter in the DAG IR owner.
  • A DAG_temporary is an optional node in the IR. It can be used to split the DAG into a set of expression trees. If a node has several users, say A<-B and A<-C, the definition node can be replaced by instances of a temporary T, i.e. T'<-B and T''<-C. The nodes T' and T'' use the same temporary index i. The owner of the DAG IR then stores under index i the expression A.

Note that temporary nodes have an expression edge, that points directly to the expression. Hence even with temporaries, an application can either stop at a temporary, getting a tree view, or skip temporaries (by following the expr edge) to see a DAG view.

Every node in a DAG IR is typed (by using an IType).

Note that this representation can be seen as a single static assignment (SSA) representation of an expression. Due to this, powerful optimization can be done on the DAG IR and are automatically enabled during construction, like

  • constant folding
  • common sub-expression evaluation
  • simplification of arithmetic expressions
  • reassociation of sub-expressions

If not explicitly requested via the use_temporaries parameter of IMaterial_instance::initialize(), the DAG backend will not create DAG_temporary nodes. An application should operate on the DAG IR directly to get the most out of this representation.