llvm-6502/lib
Adam Nemet 763d8b2ef7 [TableGen] Fully resolve class-instance values before defs in multiclasses
By class-instance values I mean 'Class<Arg>' in 'Class<Arg>.Field' or in
'Other<Class<Arg>>' (syntactically s SimpleValue).  This is to differentiate
from unnamed/anonymous record definitions (syntactically an ObjectBody) which
are not affected by this change.

Consider the testcase:

    class Struct<int i> {
      int I = !shl(i, 1);
      int J = !shl(I, 1);
    }

    class Class<Struct s> {
        int Class_J = s.J;
    }

    multiclass MultiClass<int i> {
      def Def : Class<Struct<i>>;
    }

    defm Defm : MultiClass<2>;

Before this fix, DefmDef.Class_J yields !shl(I, 1) instead of 8.

This is the sequence of events.  We start with this:

    multiclass MultiClass<int i> {
      def Def : Class<Struct<i>>;
    }

During ParseDef the anonymous object for the class-instance value is created:

    multiclass Multiclass<int i> {
      def anonymous_0 : Struct<i>;

      def Def : Class<NAME#anonymous_0>;
    }

Then class Struct<i> is added to anonymous_0.  Also Class<NAME#anonymous_0> is
added to Def:

    multiclass Multiclass<int i> {
      def anonymous_0 {
        int I = !shl(i, 1);
        int J = !shl(I, 1);
      }

      def Def {
        int Class_J = NAME#anonymous_0.J;
      }
    }

So far so good but then we move on to instantiating this in the defm
by substituting the template arg 'i'.

This is how the anonymous prototype looks after fully instantiating.

    defm Defm = {
      def Defmanonymous_0 {
         int I = 4;
         int J = !shl(I, 1);
      }

Note that we only resolved the reference to the template arg.  The
non-template-arg reference in 'J' has not been resolved yet.

Then we go on to instantiating the Def prototype:

      def DefmDef {
         int Class_J = NAME#anonymous_0.J;
      }

Which is resolved to Defmanonymous_0.J and then to !shl(I, 1).

When we fully resolve each record in a defm, Defmanonymous_0.J does get set
to 8 but that's too late for its use.

The patch adds a new attribute to the Record class that indicates that this
def is actually a class-instance value that may be *used* by other defs in a
multiclass.  (This is unlike regular defs which don't reference each other and
thus can be resolved indepedently.)  They are then fully resolved before the
other defs while the multiclass is instantiated.

I added vg_leak to the new test.  I am not sure if this is necessary but I
don't think I have a way to test it.  I can also check in without the XFAIL
and let the bots test this part.

Also tested that X86.td.expanded and AAarch64.td.expanded were unchange before
and after this change.  (This issue triggering this problem is a WIP patch.)

Part of <rdar://problem/17688758>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217886 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-16 17:14:13 +00:00
..
Analysis InstSimplify: Simplify trivial and/or of icmps 2014-09-15 08:15:28 +00:00
AsmParser Make CallingConv::ID an alias of "unsigned". 2014-09-10 18:00:17 +00:00
Bitcode Use IntrusiveRefCntPtr to manage the lifetime of BitCodeAbbrevs. 2014-09-15 15:44:14 +00:00
CodeGen Fix BasicTTI::getCmpSelInstrCost to deal with illegal vector types 2014-09-16 04:35:50 +00:00
DebugInfo Make DWARFUnitSection final and change base class to non-virtual protected destructor. 2014-09-16 12:58:01 +00:00
ExecutionEngine Spell out a move ctor. Even the 2013 vintage of MSVC cannot synthesize move ctors. 2014-09-16 16:16:39 +00:00
IR Use dyn_cast<> instead of isa<> and cast<> 2014-09-15 17:56:51 +00:00
IRReader Pass a && to getLazyBitcodeModule. 2014-09-03 17:31:46 +00:00
LineEditor
Linker Merge alignment of common GlobalValue. 2014-09-09 17:48:18 +00:00
LTO Add doInitialization/doFinalization to DataLayoutPass. 2014-09-10 21:27:43 +00:00
MC Fix the build for MSVC, it doesn't support extended sizeof 2014-09-15 20:28:38 +00:00
Object [llvm-objdump] for mach-o add -bind, -lazy-bind, and -weak-bind options 2014-09-16 01:41:51 +00:00
Option Add an overload of getLastArgNoClaim taking two OptSpecifiers. 2014-09-12 19:42:53 +00:00
ProfileData llvm-profdata: Avoid undefined behaviour when reading raw profiles 2014-09-12 21:22:55 +00:00
Support Fix memory leak in error paths in YAMLTraits by using unique_ptr 2014-09-15 18:39:24 +00:00
TableGen [TableGen] Fully resolve class-instance values before defs in multiclasses 2014-09-16 17:14:13 +00:00
Target [X86] Improve comment 2014-09-16 17:14:10 +00:00
Transforms Remove dead code in SimplifyCFG 2014-09-15 20:48:13 +00:00
CMakeLists.txt
LLVMBuild.txt
Makefile