@@ -310,39 +310,34 @@ private List<Metadata> parseMetadataAttachment(List<MetadataAttachmentContext> m
310310 }
311311
312312 final List <Metadata > metadata = new ArrayList <>();
313- //FIXME: This code only looks for DILocation metadata,
314- // and it only extracts the information needed to construct SourceLocation metadata
315313 for (MetadataAttachmentContext metadataCtx : metadataAttachmentContexts ) {
316314 MdNode mdNode = (MdNode ) metadataCtx .accept (this );
317315 assert mdNode instanceof MdReference ;
318316 mdNode = metadataSymbolTable .get (((MdReference ) mdNode ).mdName ());
319317
320318 final String metaDatatype = metadataCtx .MetadataName ().toString ();
321-
322319 if (metaDatatype .equals ("!tbaa" )) {
323- // We assume a tbaa access tag
324- assert mdNode instanceof MdTuple ;
325- final MdTuple accessNode = (MdTuple ) mdNode ;
326- final List <MdNode > children = accessNode .mdFields ();
327-
328- final TBAA .Type base = tbaaBuilder .getTBAATypeFromNode (children .get (0 ));
329- final TBAA .Type access = tbaaBuilder .getTBAATypeFromNode (children .get (1 ));
330- final int offset = ((MdGenericValue <IntLiteral >)children .get (2 )).value ().getValueAsInt ();
331- // final int isConstant = ((MdGenericValue<IntLiteral>)children.get(3)).value().getValueAsInt();
332-
333- metadata .add (new TBAA .AccessTag (base , access , offset ));
334- }
335-
336- if (mdNode instanceof SpecialMdTupleNode diLocationNode && diLocationNode .nodeType () == SpecialMdTupleNode .Type .DILocation ) {
337- SpecialMdTupleNode scope = diLocationNode ;
338- while (scope .getField ("scope" ).isPresent ()) {
339- scope = (SpecialMdTupleNode ) metadataSymbolTable .get (scope .<MdReference >getField ("scope" ).orElseThrow ().mdName ());
320+ // TBAA
321+ metadata .add (tbaaBuilder .getTBAAAccessFromNode (mdNode ));
322+ } else if (metaDatatype .equals ("!dbg" )) {
323+ //FIXME: This code only looks for DILocation metadata
324+ // and it only extracts the information needed to construct SourceLocation metadata
325+ if (mdNode instanceof SpecialMdTupleNode diLocationNode && diLocationNode .nodeType () == SpecialMdTupleNode .Type .DILocation ) {
326+ SpecialMdTupleNode scope = diLocationNode ;
327+ while (scope .getField ("scope" ).isPresent ()) {
328+ scope = (SpecialMdTupleNode ) metadataSymbolTable .get (scope .<MdReference >getField ("scope" ).orElseThrow ().mdName ());
329+ }
330+ assert scope .nodeType () == SpecialMdTupleNode .Type .DIFile ;
331+ final String filename = scope .<MdGenericValue <String >>getField ("filename" ).orElseThrow ().value ();
332+ final String directory = scope .<MdGenericValue <String >>getField ("directory" ).orElseThrow ().value ();
333+ final int lineNumber = diLocationNode .<MdGenericValue <BigInteger >>getField ("line" ).orElseThrow ().value ().intValue ();
334+ metadata .add (new SourceLocation ((directory + "/" + filename ).intern (), lineNumber ));
335+ }
336+ } else {
337+ if (logger .isDebugEnabled ()) {
338+ final String optional = !metaDatatype .equals ("!llvm.loop" ) ? " Potential for optimization?" : "" ;
339+ logger .debug ("Skipped parsing of {} metadata.{}" , metaDatatype , optional );
340340 }
341- assert scope .nodeType () == SpecialMdTupleNode .Type .DIFile ;
342- final String filename = scope .<MdGenericValue <String >>getField ("filename" ).orElseThrow ().value ();
343- final String directory = scope .<MdGenericValue <String >>getField ("directory" ).orElseThrow ().value ();
344- final int lineNumber = diLocationNode .<MdGenericValue <BigInteger >>getField ("line" ).orElseThrow ().value ().intValue ();
345- metadata .add (new SourceLocation ((directory + "/" + filename ).intern (), lineNumber ));
346341 }
347342 }
348343
@@ -1487,6 +1482,27 @@ public <T extends MdNode> Optional<T> getField(String fieldName) {
14871482
14881483 private class TBAABuilder {
14891484 private final Map <MdNode , TBAA .Type > md2tbaaMap = new HashMap <>();
1485+ private final Map <MdNode , TBAA .AccessTag > md2accessMap = new HashMap <>();
1486+
1487+ private TBAA .AccessTag getTBAAAccessFromNode (MdNode node ) {
1488+ if (node instanceof MdReference ref ) {
1489+ node = metadataSymbolTable .get (ref .mdName ());
1490+ }
1491+ assert node instanceof MdTuple ;
1492+ final MdTuple accessNode = (MdTuple ) node ;
1493+
1494+ if (!md2accessMap .containsKey (accessNode )) {
1495+ // We assume a tbaa access tag
1496+ final List <MdNode > children = accessNode .mdFields ();
1497+ final TBAA .Type base = tbaaBuilder .getTBAATypeFromNode (children .get (0 ));
1498+ final TBAA .Type access = tbaaBuilder .getTBAATypeFromNode (children .get (1 ));
1499+ final int offset = ((MdGenericValue <IntLiteral >) children .get (2 )).value ().getValueAsInt ();
1500+ // final int isConstant = ((MdGenericValue<IntLiteral>)children.get(3)).value().getValueAsInt();
1501+ md2accessMap .put (node , new TBAA .AccessTag (base , access , offset ));
1502+ }
1503+
1504+ return md2accessMap .get (node );
1505+ }
14901506
14911507 private TBAA .Type getTBAATypeFromNode (MdNode node ) {
14921508 if (node instanceof MdReference ref ) {
0 commit comments