This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add `const` qualifiers to `AffineMap` methods
ClosedPublic

Authored by vinograd47 on Feb 4 2021, 6:08 AM.

Details

Summary

The AffineMap class follows the same semantic as Type and Attribute.
It is immutable object, so it make sence to mark its methods as const.
Also part of its API is already marked as const, this change just make the API consistent.

Diff Detail

Event Timeline

vinograd47 created this revision.Feb 4 2021, 6:08 AM
vinograd47 requested review of this revision.Feb 4 2021, 6:08 AM
ftynse added a comment.Feb 4 2021, 6:16 AM

https://mlir.llvm.org/docs/Rationale/UsageOfConst/

AffineMaps are wrappers around a pointer and are passed by-value (I systematically complain about const AffineMap &), so we don't care about const for them.

@ftynse Here is the code snippet, which doesn't work for me:

if (memref.getAffineMaps().front().isPermutation()) {...}

The MemRefType::getAffineMaps returns ArrayRef, which returns const references to its elements. Also some of the methods in AffineMap already marked as const. The change just makes its API consistent.

I've seen this article about const correctness, but as I understood, it applies to Operations, not to Types and Attributes, which are immutable by their nature. And it seems that AffineMap also follows this immutable immortal singleton model as Types and Attributes. Am I wrong?

ftynse accepted this revision.Feb 4 2021, 6:39 AM

Type analogy makes sense. Please put it in the commit description.

This revision is now accepted and ready to land.Feb 4 2021, 6:39 AM
vinograd47 edited the summary of this revision. (Show Details)

@ftynse Done

bondhugula accepted this revision.Feb 5 2021, 3:02 AM
This revision was automatically updated to reflect the committed changes.