[cfe-dev] [RFC] cHash: Integration of AST hashing

Christian Dietrich via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 12 01:10:48 PST 2017


Christian Dietrich <dietrich at sra.uni-hannover.de> writes:

> Sure, this would definitly be a better option. A quick look into the
> RecursiveASTVisitor tells me that there are at least 76 for (...) loops.
> So we have to add them.

Unluckily, there is no general approach to get the number of elements in
an iterator_range, but calling std::distance, however:

  addData(std::distance(S->attrs().begin(), S->attrs.end()));

is kind of ugly, so we better leave that to the implmentor of addData()
by using a template matching iterator_range<> and simply give the child
range to the Collector user:

  addData(S->attrs());

In this case, the user of the collector can do more fancy things on this.

> Perhaps we can combine both, length-indicators and and
> non-small-integers, by using llvm::hash on the <Decl::getKind()> values.
> As the documentation says, we have to spent less than 20 cycles per
> 32-bit value on this. By this, we avoid the magic numbers. I will start
> on doing the changes to incorporate the length fields.

Wait a moment. When thinking of it, the number of children is not a
node-local property, so it should be placed in a different category.
Perhaps, we could do something similar to D40781[1]:

class Collector {
  code Local = [{}];
  code CrossRef = [{}];

  code CHash = !codeconcat(Local, CrossRef);
}

class Decl : Collector {
   code Local = [{
      addData(S->getKind());
   }];

   code CrossRef = [{
      addData(S->attrs());
   }];
}

However, D40782[2] has to land first in LLVM for this, since TableGen
has no !codeconcat command at the moment. So for the moment, I will put
it into Code = [{}];

chris

[1] https://reviews.llvm.org/D40781
[2] https://reviews.llvm.org/D40782
-- 
Christian Dietrich, M.Sc. (Scientific Staff)
Institute for Systems Engineering (Systems and Computerarchitecture)
Leibniz Universität Hannover
Appelstraße 4
30167 Hannover, Germany

Tel:    +49 511 762-19737
Fax:    +49 511 762-19733
eMail:  dietrich at sra.uni-hannover.de
WWW:    https://www.sra.uni-hannover.de


More information about the cfe-dev mailing list