[PATCH] D81045: [MLIR] Modify HasParent trait to allow one of several op's as a parent

2020-06-04 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul updated this revision to Diff 268618.
jurahul added a comment.
Herald added subscribers: cfe-commits, msifontes.
Herald added a project: clang.

Fix Clang build failure


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045

Files:
  clang/include/clang/AST/DeclBase.h
  llvm/include/llvm/Support/Casting.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
  mlir/include/mlir/IR/OpBase.td
  mlir/include/mlir/IR/OpDefinition.h
  mlir/test/IR/traits.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -439,10 +439,18 @@
   let results = (outs AnyTensor);
 }
 
-// There the "HasParent" trait.
-def ParentOp : TEST_Op<"parent">;
+// HasParent trait
+def ParentOp : TEST_Op<"parent"> {
+let regions = (region AnyRegion);
+}
 def ChildOp : TEST_Op<"child", [HasParent<"ParentOp">]>;
 
+// ParentOneOf trait
+def ParentOp1 : TEST_Op<"parent1"> {
+  let regions = (region AnyRegion);
+}
+def ChildWithParentOneOf : TEST_Op<"child_with_parent_one_of",
+[ParentOneOf<["ParentOp", "ParentOp1"]>]>;
 
 def TerminatorOp : TEST_Op<"finish", [Terminator]>;
 def SingleBlockImplicitTerminatorOp : TEST_Op<"SingleBlockImplicitTerminator",
Index: mlir/test/IR/traits.mlir
===
--- mlir/test/IR/traits.mlir
+++ mlir/test/IR/traits.mlir
@@ -173,6 +173,39 @@
   }) : () -> ()
 }
 
+// -
+
+// CHECK: succeededParentOneOf
+func @succeededParentOneOf() {
+  "test.parent"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+// CHECK: succeededParent1OneOf
+func @succeededParent1OneOf() {
+  "test.parent1"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+func @failedParentOneOf_wrong_parent1() {
+  "some.otherop"() ({
+// expected-error@+1 {{'test.child_with_parent_one_of' op expects parent op to be one of 'test.parent, test.parent1'}}
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+}
+
+
 // -
 
 func @failedSingleBlockImplicitTerminator_empty_block() {
Index: mlir/include/mlir/IR/OpDefinition.h
===
--- mlir/include/mlir/IR/OpDefinition.h
+++ mlir/include/mlir/IR/OpDefinition.h
@@ -1139,16 +1139,24 @@
   };
 };
 
-/// This class provides a verifier for ops that are expecting a specific parent.
-template  struct HasParent {
+/// This class provides a verifier for ops that are expecting their parent
+/// to be one of the given parent ops
+template 
+struct HasParent {
   template 
   class Impl : public TraitBase {
   public:
 static LogicalResult verifyTrait(Operation *op) {
-  if (isa(op->getParentOp()))
+  if (llvm::isa(op->getParentOp()))
 return success();
-  return op->emitOpError() << "expects parent op '"
-   << ParentOpType::getOperationName() << "'";
+
+  InFlightDiagnostic diag = op->emitOpError();
+  diag << "expects parent op "
+   << (sizeof...(ParentOpTypes) != 1 ? "to be one of '" : "'");
+  llvm::interleaveComma(
+  llvm::makeArrayRef({ParentOpTypes::getOperationName()...}), diag);
+  diag << "'";
+  return diag;
 }
   };
 };
Index: mlir/include/mlir/IR/OpBase.td
===
--- mlir/include/mlir/IR/OpBase.td
+++ mlir/include/mlir/IR/OpBase.td
@@ -1686,6 +1686,9 @@
 class HasParent
 : ParamNativeOpTrait<"HasParent", op>;
 
+class ParentOneOf ops>
+: ParamNativeOpTrait<"HasParent", StrJoin.result>;
+
 // Op result type is derived from the first attribute. If the attribute is an
 // subclass of `TypeAttrBase`, its value is used, otherwise, the type of the
 // attribute content is used.
Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,9 @@
   if (I != HasRecMap.end())
 return I->second;
 
-

[PATCH] D81045: [MLIR] Modify HasParent trait to allow one of several op's as a parent

2020-06-05 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul updated this revision to Diff 268903.
jurahul added a comment.

Fix Clang build failure


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045

Files:
  clang/include/clang/AST/DeclBase.h
  llvm/include/llvm/Support/Casting.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
  mlir/include/mlir/IR/OpBase.td
  mlir/include/mlir/IR/OpDefinition.h
  mlir/test/IR/traits.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -439,10 +439,18 @@
   let results = (outs AnyTensor);
 }
 
-// There the "HasParent" trait.
-def ParentOp : TEST_Op<"parent">;
+// HasParent trait
+def ParentOp : TEST_Op<"parent"> {
+let regions = (region AnyRegion);
+}
 def ChildOp : TEST_Op<"child", [HasParent<"ParentOp">]>;
 
+// ParentOneOf trait
+def ParentOp1 : TEST_Op<"parent1"> {
+  let regions = (region AnyRegion);
+}
+def ChildWithParentOneOf : TEST_Op<"child_with_parent_one_of",
+[ParentOneOf<["ParentOp", "ParentOp1"]>]>;
 
 def TerminatorOp : TEST_Op<"finish", [Terminator]>;
 def SingleBlockImplicitTerminatorOp : TEST_Op<"SingleBlockImplicitTerminator",
Index: mlir/test/IR/traits.mlir
===
--- mlir/test/IR/traits.mlir
+++ mlir/test/IR/traits.mlir
@@ -173,6 +173,39 @@
   }) : () -> ()
 }
 
+// -
+
+// CHECK: succeededParentOneOf
+func @succeededParentOneOf() {
+  "test.parent"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+// CHECK: succeededParent1OneOf
+func @succeededParent1OneOf() {
+  "test.parent1"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+func @failedParentOneOf_wrong_parent1() {
+  "some.otherop"() ({
+// expected-error@+1 {{'test.child_with_parent_one_of' op expects parent op to be one of 'test.parent, test.parent1'}}
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+}
+
+
 // -
 
 func @failedSingleBlockImplicitTerminator_empty_block() {
Index: mlir/include/mlir/IR/OpDefinition.h
===
--- mlir/include/mlir/IR/OpDefinition.h
+++ mlir/include/mlir/IR/OpDefinition.h
@@ -1139,16 +1139,24 @@
   };
 };
 
-/// This class provides a verifier for ops that are expecting a specific parent.
-template  struct HasParent {
+/// This class provides a verifier for ops that are expecting their parent
+/// to be one of the given parent ops
+template 
+struct HasParent {
   template 
   class Impl : public TraitBase {
   public:
 static LogicalResult verifyTrait(Operation *op) {
-  if (isa(op->getParentOp()))
+  if (llvm::isa(op->getParentOp()))
 return success();
-  return op->emitOpError() << "expects parent op '"
-   << ParentOpType::getOperationName() << "'";
+
+  InFlightDiagnostic diag = op->emitOpError();
+  diag << "expects parent op to be "
+   << (sizeof...(ParentOpTypes) != 1 ? "one of '" : "'");
+  llvm::interleaveComma(
+  llvm::makeArrayRef({ParentOpTypes::getOperationName()...}), diag);
+  diag << "'";
+  return diag;
 }
   };
 };
Index: mlir/include/mlir/IR/OpBase.td
===
--- mlir/include/mlir/IR/OpBase.td
+++ mlir/include/mlir/IR/OpBase.td
@@ -1686,6 +1686,9 @@
 class HasParent
 : ParamNativeOpTrait<"HasParent", op>;
 
+class ParentOneOf ops>
+: ParamNativeOpTrait<"HasParent", StrJoin.result>;
+
 // Op result type is derived from the first attribute. If the attribute is an
 // subclass of `TypeAttrBase`, its value is used, otherwise, the type of the
 // attribute content is used.
Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 
-  bool FoundAddRec = SCEVExprContains(S, isa);
+  bool FoundAddRec =
+  SCEVE

[PATCH] D81045: [MLIR] Modify HasParent trait to allow one of several op's as a parent

2020-06-05 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul updated this revision to Diff 268905.
jurahul added a comment.

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


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045

Files:
  clang/include/clang/AST/DeclBase.h
  llvm/include/llvm/Support/Casting.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
  mlir/include/mlir/IR/OpBase.td
  mlir/include/mlir/IR/OpDefinition.h
  mlir/test/IR/traits.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -439,10 +439,18 @@
   let results = (outs AnyTensor);
 }
 
-// There the "HasParent" trait.
-def ParentOp : TEST_Op<"parent">;
+// HasParent trait
+def ParentOp : TEST_Op<"parent"> {
+let regions = (region AnyRegion);
+}
 def ChildOp : TEST_Op<"child", [HasParent<"ParentOp">]>;
 
+// ParentOneOf trait
+def ParentOp1 : TEST_Op<"parent1"> {
+  let regions = (region AnyRegion);
+}
+def ChildWithParentOneOf : TEST_Op<"child_with_parent_one_of",
+[ParentOneOf<["ParentOp", "ParentOp1"]>]>;
 
 def TerminatorOp : TEST_Op<"finish", [Terminator]>;
 def SingleBlockImplicitTerminatorOp : TEST_Op<"SingleBlockImplicitTerminator",
Index: mlir/test/IR/traits.mlir
===
--- mlir/test/IR/traits.mlir
+++ mlir/test/IR/traits.mlir
@@ -173,6 +173,39 @@
   }) : () -> ()
 }
 
+// -
+
+// CHECK: succeededParentOneOf
+func @succeededParentOneOf() {
+  "test.parent"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+// CHECK: succeededParent1OneOf
+func @succeededParent1OneOf() {
+  "test.parent1"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+func @failedParentOneOf_wrong_parent1() {
+  "some.otherop"() ({
+// expected-error@+1 {{'test.child_with_parent_one_of' op expects parent op to be one of 'test.parent, test.parent1'}}
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+}
+
+
 // -
 
 func @failedSingleBlockImplicitTerminator_empty_block() {
Index: mlir/include/mlir/IR/OpDefinition.h
===
--- mlir/include/mlir/IR/OpDefinition.h
+++ mlir/include/mlir/IR/OpDefinition.h
@@ -1139,16 +1139,24 @@
   };
 };
 
-/// This class provides a verifier for ops that are expecting a specific parent.
-template  struct HasParent {
+/// This class provides a verifier for ops that are expecting their parent
+/// to be one of the given parent ops
+template 
+struct HasParent {
   template 
   class Impl : public TraitBase {
   public:
 static LogicalResult verifyTrait(Operation *op) {
-  if (isa(op->getParentOp()))
+  if (llvm::isa(op->getParentOp()))
 return success();
-  return op->emitOpError() << "expects parent op '"
-   << ParentOpType::getOperationName() << "'";
+
+  InFlightDiagnostic diag = op->emitOpError();
+  diag << "expects parent op "
+   << (sizeof...(ParentOpTypes) != 1 ? "to be one of '" : "'");
+  llvm::interleaveComma(
+  llvm::makeArrayRef({ParentOpTypes::getOperationName()...}), diag);
+  diag << "'";
+  return diag;
 }
   };
 };
Index: mlir/include/mlir/IR/OpBase.td
===
--- mlir/include/mlir/IR/OpBase.td
+++ mlir/include/mlir/IR/OpBase.td
@@ -1686,6 +1686,9 @@
 class HasParent
 : ParamNativeOpTrait<"HasParent", op>;
 
+class ParentOneOf ops>
+: ParamNativeOpTrait<"HasParent", StrJoin.result>;
+
 // Op result type is derived from the first attribute. If the attribute is an
 // subclass of `TypeAttrBase`, its value is used, otherwise, the type of the
 // attribute content is used.
Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 

[PATCH] D81045: [MLIR] Modify HasParent trait to allow one of several op's as a parent

2020-06-05 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul added a comment.

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)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81045: [MLIR] Modify HasParent trait to allow one of several op's as a parent

2020-06-05 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul updated this revision to Diff 268929.
jurahul added a comment.

Remove {} in ScalarEvolution.cpp to match existing style


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045

Files:
  clang/include/clang/AST/DeclBase.h
  llvm/include/llvm/Support/Casting.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
  mlir/include/mlir/IR/OpBase.td
  mlir/include/mlir/IR/OpDefinition.h
  mlir/test/IR/traits.mlir
  mlir/test/lib/Dialect/Test/TestOps.td

Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -439,10 +439,18 @@
   let results = (outs AnyTensor);
 }
 
-// There the "HasParent" trait.
-def ParentOp : TEST_Op<"parent">;
+// HasParent trait
+def ParentOp : TEST_Op<"parent"> {
+let regions = (region AnyRegion);
+}
 def ChildOp : TEST_Op<"child", [HasParent<"ParentOp">]>;
 
+// ParentOneOf trait
+def ParentOp1 : TEST_Op<"parent1"> {
+  let regions = (region AnyRegion);
+}
+def ChildWithParentOneOf : TEST_Op<"child_with_parent_one_of",
+[ParentOneOf<["ParentOp", "ParentOp1"]>]>;
 
 def TerminatorOp : TEST_Op<"finish", [Terminator]>;
 def SingleBlockImplicitTerminatorOp : TEST_Op<"SingleBlockImplicitTerminator",
Index: mlir/test/IR/traits.mlir
===
--- mlir/test/IR/traits.mlir
+++ mlir/test/IR/traits.mlir
@@ -173,6 +173,39 @@
   }) : () -> ()
 }
 
+// -
+
+// CHECK: succeededParentOneOf
+func @succeededParentOneOf() {
+  "test.parent"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+// CHECK: succeededParent1OneOf
+func @succeededParent1OneOf() {
+  "test.parent1"() ({
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+  return
+}
+
+// -
+
+func @failedParentOneOf_wrong_parent1() {
+  "some.otherop"() ({
+// expected-error@+1 {{'test.child_with_parent_one_of' op expects parent op to be one of 'test.parent, test.parent1'}}
+"test.child_with_parent_one_of"() : () -> ()
+"test.finish"() : () -> ()
+   }) : () -> ()
+}
+
+
 // -
 
 func @failedSingleBlockImplicitTerminator_empty_block() {
Index: mlir/include/mlir/IR/OpDefinition.h
===
--- mlir/include/mlir/IR/OpDefinition.h
+++ mlir/include/mlir/IR/OpDefinition.h
@@ -1139,16 +1139,24 @@
   };
 };
 
-/// This class provides a verifier for ops that are expecting a specific parent.
-template  struct HasParent {
+/// This class provides a verifier for ops that are expecting their parent
+/// to be one of the given parent ops
+template 
+struct HasParent {
   template 
   class Impl : public TraitBase {
   public:
 static LogicalResult verifyTrait(Operation *op) {
-  if (isa(op->getParentOp()))
+  if (llvm::isa(op->getParentOp()))
 return success();
-  return op->emitOpError() << "expects parent op '"
-   << ParentOpType::getOperationName() << "'";
+
+  InFlightDiagnostic diag = op->emitOpError();
+  diag << "expects parent op "
+   << (sizeof...(ParentOpTypes) != 1 ? "to be one of '" : "'");
+  llvm::interleaveComma(
+  llvm::makeArrayRef({ParentOpTypes::getOperationName()...}), diag);
+  diag << "'";
+  return diag;
 }
   };
 };
Index: mlir/include/mlir/IR/OpBase.td
===
--- mlir/include/mlir/IR/OpBase.td
+++ mlir/include/mlir/IR/OpBase.td
@@ -1686,6 +1686,9 @@
 class HasParent
 : ParamNativeOpTrait<"HasParent", op>;
 
+class ParentOneOf ops>
+: ParamNativeOpTrait<"HasParent", StrJoin.result>;
+
 // Op result type is derived from the first attribute. If the attribute is an
 // subclass of `TypeAttrBase`, its value is used, otherwise, the type of the
 // attribute content is used.
Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 
-  bool FoundAddRec = SCEVExprContains(S, isa);
+

[PATCH] D81045: [MLIR] Modify HasParent trait to allow one of several op's as a parent

2020-06-08 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul added inline comments.



Comment at: llvm/include/llvm/Support/Casting.h:147
+template 
+LLVM_NODISCARD inline typename std::enable_if::type
+isa(const Y &Val) {

jpienaar wrote:
> 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)
I did think of doing that. I agree that we should split the isa<> into its own 
change. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81045: [LLVM] Change isa<> to a variadic function template

2020-06-10 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul updated this revision to Diff 269870.
jurahul added a comment.

Split isa<> changes into its own change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045

Files:
  clang/include/clang/AST/DeclBase.h
  llvm/include/llvm/Support/Casting.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp


Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 
-  bool FoundAddRec = SCEVExprContains(S, isa);
+  bool FoundAddRec =
+  SCEVExprContains(S, [](const SCEV *S) { return isa(S); 
});
   HasRecMap.insert({S, FoundAddRec});
   return FoundAddRec;
 }
@@ -11201,8 +11202,9 @@
 // Returns true when one of the SCEVs of Terms contains a SCEVUnknown 
parameter.
 static inline bool containsParameters(SmallVectorImpl &Terms) {
   for (const SCEV *T : Terms)
-if (SCEVExprContains(T, isa))
+if (SCEVExprContains(T, [](const SCEV *S) { return isa(S); }))
   return true;
+
   return false;
 }
 
Index: llvm/include/llvm/Support/Casting.h
===
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -132,24 +132,31 @@
   }
 };
 
-// isa - Return true if the parameter to the template is an instance of the
-// template type argument.  Used like this:
+// isa - Return true if the parameter to the template is an instance of one
+// of the template type argument.  Used like this:
 //
 //  if (isa(myVal)) { ... }
+//  if (isa(myVal)) { ... }
 //
 template  LLVM_NODISCARD inline bool isa(const Y &Val) {
   return isa_impl_wrap::SimpleType>::doit(Val);
 }
 
+template 
+LLVM_NODISCARD inline typename std::enable_if::type
+isa(const Y &Val) {
+  return isa(Val) || isa(Val);
+}
+
 // isa_and_nonnull - Functionally identical to isa, except that a null value
 // is accepted.
 //
-template 
+template 
 LLVM_NODISCARD inline bool isa_and_nonnull(const Y &Val) {
   if (!Val)
 return false;
-  return isa(Val);
+  return isa(Val);
 }
 
 
//===--===//
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -518,7 +518,9 @@
 if (!HasAttrs) return;
 
 AttrVec &Vec = getAttrs();
-Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa), 
Vec.end());
+Vec.erase(std::remove_if(Vec.begin(), Vec.end(),
+ [](Attr *A) { return isa(A); }),
+  Vec.end());
 
 if (Vec.empty())
   HasAttrs = false;


Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 
-  bool FoundAddRec = SCEVExprContains(S, isa);
+  bool FoundAddRec =
+  SCEVExprContains(S, [](const SCEV *S) { return isa(S); });
   HasRecMap.insert({S, FoundAddRec});
   return FoundAddRec;
 }
@@ -11201,8 +11202,9 @@
 // Returns true when one of the SCEVs of Terms contains a SCEVUnknown parameter.
 static inline bool containsParameters(SmallVectorImpl &Terms) {
   for (const SCEV *T : Terms)
-if (SCEVExprContains(T, isa))
+if (SCEVExprContains(T, [](const SCEV *S) { return isa(S); }))
   return true;
+
   return false;
 }
 
Index: llvm/include/llvm/Support/Casting.h
===
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -132,24

[PATCH] D81045: [LLVM] Change isa<> to a variadic function template

2020-06-10 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul updated this revision to Diff 270015.
jurahul edited the summary of this revision.
jurahul added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045

Files:
  clang/include/clang/AST/DeclBase.h
  llvm/include/llvm/Support/Casting.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp


Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 
-  bool FoundAddRec = SCEVExprContains(S, isa);
+  bool FoundAddRec =
+  SCEVExprContains(S, [](const SCEV *S) { return isa(S); 
});
   HasRecMap.insert({S, FoundAddRec});
   return FoundAddRec;
 }
@@ -11201,8 +11202,9 @@
 // Returns true when one of the SCEVs of Terms contains a SCEVUnknown 
parameter.
 static inline bool containsParameters(SmallVectorImpl &Terms) {
   for (const SCEV *T : Terms)
-if (SCEVExprContains(T, isa))
+if (SCEVExprContains(T, [](const SCEV *S) { return isa(S); }))
   return true;
+
   return false;
 }
 
Index: llvm/include/llvm/Support/Casting.h
===
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -132,24 +132,30 @@
   }
 };
 
-// isa - Return true if the parameter to the template is an instance of the
-// template type argument.  Used like this:
+// isa - Return true if the parameter to the template is an instance of one
+// of the template type arguments.  Used like this:
 //
 //  if (isa(myVal)) { ... }
+//  if (isa(myVal)) { ... }
 //
 template  LLVM_NODISCARD inline bool isa(const Y &Val) {
   return isa_impl_wrap::SimpleType>::doit(Val);
 }
 
+template 
+LLVM_NODISCARD inline bool isa(const Y &Val) {
+  return isa(Val) || isa(Val);
+}
+
 // isa_and_nonnull - Functionally identical to isa, except that a null value
 // is accepted.
 //
-template 
+template 
 LLVM_NODISCARD inline bool isa_and_nonnull(const Y &Val) {
   if (!Val)
 return false;
-  return isa(Val);
+  return isa(Val);
 }
 
 
//===--===//
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -518,7 +518,7 @@
 if (!HasAttrs) return;
 
 AttrVec &Vec = getAttrs();
-Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa), 
Vec.end());
+llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
 if (Vec.empty())
   HasAttrs = false;


Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
===
--- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@
 auto Defs = findAllDefs(U);
 
 // If the values are all Constants or Arguments, don't bother
-if (llvm::none_of(Defs, isa))
+if (llvm::none_of(Defs, [](Value *V) { return isa(V); }))
   return false;
 
 // Presently, we only know how to handle PHINode, Constant, Arguments and
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@
   if (I != HasRecMap.end())
 return I->second;
 
-  bool FoundAddRec = SCEVExprContains(S, isa);
+  bool FoundAddRec =
+  SCEVExprContains(S, [](const SCEV *S) { return isa(S); });
   HasRecMap.insert({S, FoundAddRec});
   return FoundAddRec;
 }
@@ -11201,8 +11202,9 @@
 // Returns true when one of the SCEVs of Terms contains a SCEVUnknown parameter.
 static inline bool containsParameters(SmallVectorImpl &Terms) {
   for (const SCEV *T : Terms)
-if (SCEVExprContains(T, isa))
+if (SCEVExprContains(T, [](const SCEV *S) { return isa(S); }))
   return true;
+
   return false;
 }
 
Index: llvm/include/llvm/Support/Casting.h
===
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -132,24 +132,30 @@
   }
 };
 
-// isa - Return true if the parameter to the template is a

[PATCH] D81045: [LLVM] Change isa<> to a variadic function template

2020-06-15 Thread Rahul Joshi via Phabricator via cfe-commits
jurahul added a comment.

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


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81045/new/

https://reviews.llvm.org/D81045



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits