[LLVMdev] Tablegen: RegisterInfoEmitter.cpp

Jonas Paulsson jnspaulsson at hotmail.com
Fri Sep 30 08:29:43 PDT 2011


Hi,

I just bumped into a bug in this code. The problem was as follows:

I have defined a set of registers with rather similar names including digits.

The code section at 

RegisterInfoEmitter::run(){
...
 // Process sub-register sets.

runs and fills the RegisterAliases map.

then, 

...
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
    RegNo[Regs[i].TheDef] = i;
    NumAliases += RegisterAliases[Regs[i].TheDef].size();
}

runs. Only, now there are duplicates in the RegisterAliases map for the same Regs[i]-Record.

This lead to duplicate output of the REG_Overlaps lists:

error: redefinition of 'const unsigned int llvm::<unnamed>::a23g_Overlaps []'
/local/scratch/ejonpan/llvm/build/lib/Target/Hubble/HubbleGenRegisterInfo.inc:2700: error: 'const unsigned int llvm::<unnamed>::a23g_Overlaps [4]'
 previously defined here
/local/scratch/ejonpan/llvm/build/lib/Target/Hubble/HubbleGenRegisterInfo.inc:2732: error: redefinition of 'const unsigned int llvm::<unnamed>::a6
7g_Overlaps []'
/local/scratch/ejonpan/llvm/build/lib/Target/Hubble/HubbleGenRegisterInfo.inc:2717: error: 'const unsigned int llvm::<unnamed>::a67g_Overlaps [4]'
 previously defined here

This behaved very oddly, as the error disappeared after changing register names from eg a23g to aa23g.

It was the map ordering operator that was the trouble, it seems, as the problem disappeared when I used std::string::compare() instead for
the RegisterAliases map.

struct LessRecord {
  bool operator()(const Record *Rec1, const Record *Rec2) const {
    return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
  }
};

struct LessRecordRegAliases{
  bool operator()(const Record *Rec1, const Record *Rec2) const {
    return Rec1->getName().compare(Rec2->getName()) < 0;
  }
};

The conclusion is that the StringRef::compare_numeric() is not 
deterministic and should not be used in this context, as the map::operator[] will not find 
the
object, and insert a duplicate in this case. Note that my reg-names included digits and where very similar. 

/Jonas





 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110930/d3b68179/attachment.html>


More information about the llvm-dev mailing list