This is an archive of the discontinued LLVM Phabricator instance.

[LLVM] Change isa<> to a variadic function template
ClosedPublic

Authored by jurahul on Jun 2 2020, 5:43 PM.

Details

Summary

Change isa<> to a variadic function template, so that it can be used to test against one of multiple types as follows:

isa<Type0, Type1, Type2>(Val)

Diff Detail

Event Timeline

jurahul created this revision.Jun 2 2020, 5:43 PM
Herald added a project: Restricted Project. · View Herald Transcript
jurahul retitled this revision from Modify HasParent trait to allow one of several op's as a parent to [MLIR] Modify HasParent trait to allow one of several op's as a parent.Jun 2 2020, 5:47 PM

Thanks, added a couple of comments.

mlir/include/mlir/IR/OpDefinition.h
1151 ↗(On Diff #268025)

Can you add this to llvm/Support/Casting.h? This is something I've been meaning to do for a while.

1182 ↗(On Diff #268025)

nit: to be one of

1183 ↗(On Diff #268025)

Can you just use a fold expression instead?

I would expect one of the following to work:

diag << llvm::makeArrayRef({ParentOpTypes::getOperationName()...});

llvm::interleaveComma(llvm::makeArrayRef({ParentOpTypes::getOperationName()...}), diag);
mehdi_amini added inline comments.Jun 2 2020, 9:13 PM
mlir/include/mlir/IR/OpDefinition.h
1183 ↗(On Diff #268025)

Wow! I thought we needed C++17 for such folding...

jurahul updated this revision to Diff 268250.Jun 3 2020, 10:21 AM

Address River's comments

Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2020, 10:21 AM
jurahul updated this revision to Diff 268315.Jun 3 2020, 3:02 PM

Attempt to fix SCEV build failure on Windows.

jurahul updated this revision to Diff 268322.Jun 3 2020, 3:50 PM

Another attempt to address Windows build failures.

jurahul updated this revision to Diff 268344.Jun 3 2020, 6:13 PM

Another fix for Windows build (really need to setup a Windows build :( )

@rriddle and others, I have extended the isa<> function to be a variadic template, but that is causing a ripple effect of several places breaking where isa<> is used as a predicate and instantiate using something like:

if (SCEVExprContains(T, isa<SCEVUnknown, const SCEV *>))

with the new isa<> definition, such code does not work as is and needs to updated. I am working on fixing all references, but I am wondering if this will cause churn in out-of-tree code that uses LLVM as well. I cannot call the new functions is_one_of as there already exists a struct of this type with a different meaning. Another option is to name it isa_one_of but that does not read well I think. Do you agree with extending isa<> as in this change? If so, I can continue patching the remaining places (once I setup a windows build).

jurahul updated this revision to Diff 268618.Jun 4 2020, 4:16 PM

Fix Clang build failure

Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 4:16 PM
jurahul updated this revision to Diff 268903.Jun 5 2020, 11:48 AM

Fix Clang build failure

jurahul updated this revision to Diff 268905.Jun 5 2020, 11:55 AM

fix MLIR test failure due to change in error message. Reinstate the old message for a single parent case

This is ready for review. The 2 Clang hip related failure are not caused by this change, and the offending change has been reverted now (http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20200601/323475.html)

jurahul updated this revision to Diff 268929.Jun 5 2020, 1:45 PM

Remove {} in ScalarEvolution.cpp to match existing style

jurahul marked 3 inline comments as done.Jun 5 2020, 3:17 PM
jpienaar added inline comments.Jun 8 2020, 11:25 AM
llvm/include/llvm/Support/Casting.h
147

I'm worried that folks may not notice this change based on the change description (e.g., the change sounds MLIR specific), could you make this a separate change? (just focused on isa changes)

jurahul added inline comments.Jun 8 2020, 11:42 AM
llvm/include/llvm/Support/Casting.h
147

I did think of doing that. I agree that we should split the isa<> into its own change.

jurahul updated this revision to Diff 269870.Jun 10 2020, 8:58 AM

Split isa<> changes into its own change

jurahul retitled this revision from [MLIR] Modify HasParent trait to allow one of several op's as a parent to [LLVM] Change isa<> to a variadic function template.Jun 10 2020, 9:01 AM
jurahul edited the summary of this revision. (Show Details)
rriddle accepted this revision.Jun 10 2020, 11:14 AM
rriddle marked an inline comment as done.

I have run into the desire to have this on many occasions, so LGTM for me.

clang/include/clang/AST/DeclBase.h
521

nit: We could also update this to use llvm::erase_if, but fine to leave as is.

llvm/include/llvm/Support/Casting.h
136

nit: arguments

147

nit: I would remove the enable_if and just add an additional type to the template.

template<typename First, typename Second, ...>
... isa(const Y &val) {
  return isa<First>(Val) || isa<Second, Rest...>(Val);
}
This revision is now accepted and ready to land.Jun 10 2020, 11:14 AM
jurahul updated this revision to Diff 270015.Jun 10 2020, 5:51 PM
jurahul edited the summary of this revision. (Show Details)

Address review comments

jurahul marked 4 inline comments as done.Jun 10 2020, 5:54 PM

Do you need someone to land this for you?

Yes, I'd appreciate if someone can land this change.

This revision was automatically updated to reflect the committed changes.