[llvm-dev] TableGen - cryptic error messages (~feature request)

RCU via llvm-dev llvm-dev at lists.llvm.org
Sat Mar 5 09:30:45 PST 2016


   Hello.
     Sorry for the late reply.
     I'm still writing on llvm-dev (not on llvm-commit as suggested - hope it's not 
against the rules).

     The error described below (<<Assertion `Matches.size() == 1 && "Had duplicate keys to 
match on"' failed.>>) is given when running the command:
       $LLVM_BUILD_PATH/bin/llvm-tblgen -gen-asm-matcher -I $LLVM_SRC_PATH/llvm/include 
Connex.td >ConnexGenAsmMatcher.inc

     This error message lacks any valuable info to help debugging the problem. To help me 
find the problem I edited the file $LLVM_SRC_PATH/llvm/lib/TableGen/StringMatcher.cpp and 
patched it with:
         --- Orig/StringMatcher.cpp	2015-11-17 10:59:07.000000000 +0200
         +++ StringMatcher.cpp	2016-03-05 19:00:29.760320952 +0200
         @@ -49,8 +49,22 @@
            // If we have verified that the entire string matches, we're done: output the
            // matching code.
            if (CharNo == Matches[0]->first.size()) {
         +
         +    printf("Alex: Matches.size() = %ld\n", Matches.size());
         +    if (1) { //Matches.size() != 1) {
         +        printf("CharNo = %d\n", CharNo);
         +        printf("Matches.size() = %ld\n", Matches.size());
         +
         +        printf("Matches =\n");
         +        for ( auto LI =
         +          Matches.begin(), E = Matches.end(); LI != E; ++LI) {
         +            printf("    %s [SEPARATE] %s\n", (*(*LI)).first.c_str(), 
(*(*LI)).second.c_str());
         +          }
         +        printf("END\n");
         +    }
         +
              assert(Matches.size() == 1 && "Had duplicate keys to match on");
         -
         +
              // If the to-execute code has \n's in it, indent each subsequent line.
              StringRef Code = Matches[0]->second;

     Then, I built tblgen (make tblgen) and ran the tblgen command again and got on the 
stdout this time, before the assertion failure these lines:
        CharNo = 2
        Matches.size() = 3
        Matches =
             f0 [SEPARATE] return 1;
             f0 [SEPARATE] return 33;
             f0 [SEPARATE] return 129;
         END

     So, the assertion fails because there are more than 1 object (register, instruction, 
etc) with the ASM name f0.
     From this info, we quickly pinpoint the error in my .td files: it is about the fact I 
defined 3 groups of registers with the same ASM name. See the ConnexInstrInfo.td file 
attached and compare it with ConnexInstrInfo_CORRECTED.td in the same archive. The exact 
code with the problem is (note the "f"#I string that is the same in all 3 definitions):
   foreach I = 0-31 in
   def F#I : FPR<I, "f"#I>, DwarfRegNum<[!add(I, 32)]>;

   // Higher half of 64-bit FP registers.
   foreach I = 0-31 in
   def F_HI#I : FPR<I, "f"#I>, DwarfRegNum<[!add(I, 32)]>;

   /// Mips Double point precision FPU Registers in MFP64 mode.
   foreach I = 0-31 in
   def D#I#_64 : AFPR64<I, "f"#I, [!cast<FPR>("F"#I), !cast<FPR>("F_HI"#I)]>,
                 DwarfRegNum<[!add(I, 32)]>;


   Best regards,
     Alex



On 1/7/2016 9:22 PM, James Grosbach wrote:
>
>> On Jan 7, 2016, at 9:50 AM, David Blaikie via llvm-dev <llvm-dev at lists.llvm.org
>> <mailto:llvm-dev at lists.llvm.org>> wrote:
>>
>>
>>
>> On Tue, Dec 29, 2015 at 2:54 PM, RCU via llvm-dev<llvm-dev at lists.llvm.org
>> <mailto:llvm-dev at lists.llvm.org>>wrote:
>>
>>     Hello.
>>     I started implementing a back end in LLVM (and I'm writing some hints I consider
>>     useful athttps://sites.google.com/site/alexsusu/home/backend-llvm).
>>     Unfortunately, I hit quite a few times very cryptic error messages when compiling
>>     with TableGen, which required a few good hours of debugging the TableGen program.
>>
>>     The most cryptic error message was when compiling with TableGen, with the option
>>     -gen-asm-matcher . Here I got the following error message:
>>     llvm-tblgen: ~/llvm/lib/TableGen/StringMatcher.cpp:52: bool
>>     llvm::StringMatcher::EmitStringMatcherForChar(const std::vector<const
>>     std::pair<std::basic_string<char>, std::basic_string<char> >*>&, unsigned int,
>>     unsigned int) const: Assertion `Matches.size() == 1 && "Had duplicate keys to match
>>     on"' failed.
>>     [...]
>>     Stack dump:
>>     0.      Program arguments: ~/llvm/build3/bin/llvm-tblgen -gen-asm-matcher -I
>>     ~/llvm/include Connex.td
>>     ./run_tblgen.sh: line 13: 27011 Aborted                 (core dumped)
>>     ~/llvm/build3/bin/llvm-tblgen -gen-asm-matcher -I ~/llvm/include Connex.td >
>>     ConnexGenAsmMatcher.inc
>>
>>     It took me quite a few hours to find the source of the error, namely the fact I had
>>     defined two registers with the SAME ASM name (string) - so the disassembly (ASM
>>     matcher) info had conflicts. I actually sped up my debugging by editing the file
>>     ~/llvm/lib/TableGen/StringMatcher.cpp and adding in StringMatcher::
>>     EmitStringMatcherForChar() some printing that explained more clearly why the error
>>     happens.
>>
>>     Therefore I have this IMPORTANT question: would you feel it is useful to make
>>     TableGen give more detailed error messages? I personally recommend this.
>>
>>
>> Seems reasonable to add some extra text to the assertion (and possibly use better error
>> handling - not sure if tblgen aspires to be assertion-free on unbounded table inputs,
>> but it probably should be... ). Perhaps you could send a patch to llvm-commits to
>> discuss the specifics there?
>
> It definitely aspires to, yeah. An assert() for a user error is not a great experience.
> Patches making that aspiration a bit closer to the reality are very welcome.
>
> -jim
>
>>
>> - Dave
>>
>>
>>
>>     Thank you,
>>     Alex
>>     _______________________________________________
>>     LLVM Developers mailing list
>>     llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
>>     http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TableGen_seg_faults_due_to_same_ASM_names_in_FPR_and_AFPR64_registers.zip
Type: application/x-zip-compressed
Size: 8765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160305/89cc4dd4/attachment.bin>


More information about the llvm-dev mailing list