[mlir] Fix C++ name hiding bug in PDLPatternMatch for Op classes (#195554)
Native constraints with a named operation operand type failed because of
name hiding in `ProcessPDLValue`.
i.e. previously a constraint like:
```
Constraint TestConstraintWithNamedOpOperand(testOp: Op<test.op_a>) [{
return success();
}];
```
would fail with:
```
In file included from /home/jumerckx/llvm-project/mlir/include/mlir/IR/PatternMatch.h:814,
from /home/jumerckx/llvm-project/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h:13,
from /home/jumerckx/llvm-project/mlir/include/mlir/Dialect/Bufferization/IR/Bufferization.h:14,
from /home/jumerckx/llvm-project/mlir/test/lib/Tools/PDLL/../../Dialect/Test/TestDialect.h:21,
from /home/jumerckx/llvm-project/mlir/test/lib/Tools/PDLL/TestPDLL.cpp:9:
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PDLPatternMatch.h.inc: In instantiation of ‘typename FnTraitsT::result_t mlir::detail::pdl_function_builder::processArgsAndInvokeConstraint(PDLFnT&, mlir::PatternRewriter&, llvm::ArrayRef<mlir::PDLValue>, std::index_sequence<InputIndexes ...>) [with PDLFnT = llvm::LogicalResult (* const)(mlir::PatternRewriter&, test::OpA); long unsigned int ...I = {0}; FnTraitsT = llvm::function_traits<llvm::LogicalResult (* const)(mlir::PatternRewriter&, test::OpA), false>; typename FnTraitsT::result_t = llvm::LogicalResult; std::index_sequence<InputIndexes ...> = std::integer_sequence<long unsigned int, 0>]’:
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PDLPatternMatch.h.inc:733:42: required from ‘std::enable_if_t<(! std::is_convertible<ConstraintFnT, std::function<llvm::LogicalResult(mlir::PatternRewriter&, mlir::PDLResultList&, llvm::ArrayRef<mlir::PDLValue>)> >::value), std::function<llvm::LogicalResult(mlir::PatternRewriter&, mlir::PDLResultList&, llvm::ArrayRef<mlir::PDLValue>)> > mlir::detail::pdl_function_builder::buildConstraintFn(ConstraintFnT&&) [with ConstraintFnT = llvm::LogicalResult (&)(mlir::PatternRewriter&, test::OpA); std::enable_if_t<(! std::is_convertible<ConstraintFnT, std::function<llvm::LogicalResult(mlir::PatternRewriter&, mlir::PDLResultList&, llvm::ArrayRef<mlir::PDLValue>)> >::value), std::function<llvm::LogicalResult(mlir::PatternRewriter&, mlir::PDLResultList&, llvm::ArrayRef<mlir::PDLValue>)> > = std::function<llvm::LogicalResult(mlir::PatternRewriter&, mlir::PDLResultList&, llvm::ArrayRef<mlir::PDLValue>)>]’
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PDLPatternMatch.h.inc:868:79: required from ‘void mlir::PDLPatternModule::registerConstraintFunction(llvm::StringRef, ConstraintFnT&&) [with ConstraintFnT = llvm::LogicalResult (&)(mlir::PatternRewriter&, test::OpA)]’
/home/jumerckx/llvm-project/build/tools/mlir/test/lib/Tools/PDLL/TestPDLLPatterns.h.inc:64:31: required from ‘{anonymous}::GeneratedPDLLPattern0::GeneratedPDLLPattern0(mlir::MLIRContext*, ConfigsT&& ...) [with ConfigsT = {}]’
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PatternMatch.h:1017:25: required from ‘std::enable_if_t<std::is_base_of<mlir::PDLPatternModule, T>::value> mlir::RewritePatternSet:addImpl(llvm::ArrayRef<llvm::StringRef>, Args&& ...) [with T = {anonymous}::GeneratedPDLLPattern0; Args = {mlir::MLIRContext*}; std::enable_if_t<std::is_base_of<mlir::PDLPatternModule, T>::value> = void]’
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PatternMatch.h:864:17: required from ‘mlir::RewritePatternSet& mlir::RewritePatternSet::add(ConstructorArg&&, ConstructorArgs&& ...) [with Ts = {{anonymous}::GeneratedPDLLPattern0}; ConstructorArg = mlir::MLIRContext*; ConstructorArgs = {}; <template-parameter-1-4> = void]’
/home/jumerckx/llvm-project/build/tools/mlir/test/lib/Tools/PDLL/TestPDLLPatterns.h.inc:74:38: required from ‘void populateGeneratedPDLLPatterns(mlir::RewritePatternSet&, ConfigsT&& ...) [with ConfigsT = {}]’
/home/jumerckx/llvm-project/mlir/test/lib/Tools/PDLL/TestPDLL.cpp:36:34: required from here
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PDLPatternMatch.h.inc:702:80: error: cannot convert ‘const mlir::PDLValue’ to ‘mlir::Operation*’
702 | (ProcessPDLValue<typename FnTraitsT::template arg_t<I + 1>>::processAsArg(
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
703 | values[I]))...);
| ~~~~~~~~~~~
/home/jumerckx/llvm-project/mlir/include/mlir/IR/PDLPatternMatch.h.inc:522:36: note: initializing argument 1 of ‘static T mlir::detail::pdl_function_builder::ProcessPDLValue<T, typename std::enable_if<std::is_base_of<mlir::OpState, T>::value, void>::type>::processAsArg(mlir::Operation*) [with T = test::OpA]’
522 | static T processAsArg(Operation *value) { return cast<T>(value); }
| ~~~~~~~~~~~^~~~~
```
This pr fixes that.Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.