llvm.org GIT mirror llvm / 112d959
Document Multidefs Provide documentation for multidefs, explaining in detail how they work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141236 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 8 years ago
1 changed file(s) with 59 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
768768
769769
770770
771

772 A special "multidef" may be used inside a multiclass to generate
773 several defs given a list of values.
774

775
776
777

                  
                
778 class Base<int i> {
779 int value = i;
780 }
781
782 multiclass Multi<list<int> values> {
783 def ONE : Base<values[0]>;
784 def TWO : Base<values[1]>;
785
786 multidef COUNT<values, int v, 2> : Base<:v>;
787 }
788
789 defm List : Multi<[1, 2, 3, 4, 5, 6]<;
790 ...
791
792 // Results
793 def ListCOUNT {
794 int v = ?;
795 int value = v;
796 list Multi::values = [1, 2, 3, 4, 5, 6];
797 }
798 def ListONE {
799 int value = 1;
800 }
801 def ListTWO {
802 int value = 2;
803 }
804 def MD2.ListCOUNT {
805 int value = 3;
806 }
807 def MD3.ListCOUNT {
808 int value = 4;
809 }
810 def MD4.ListCOUNT {
811 int value = 5;
812 }
813 def MD5.ListCOUNT {
814 int value = 6;
815 }
816
817
818
819

820 A multidef takes three "arguments" in the <> notation after the multidef
821 name. The first is a list of items to process. The second is a declaration.
822 This declaration creates a temporary name used as an iterator. It picks up the
823 value of each processed list item as TableGen generates defs from the multidef.
824 This temporary may be named and passed into the multidef body as shown in the
825 example above. This provides a powerful way to generate defs with various
826 values from a single multidef. The final "argument" is an integer value
827 indicating where in the list to begin processing. In the above example we
828 chose to begin list processing with the third item (index 2).
829

771830
772831
773832