33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ // Modifications (c) Copyright 2025 Advanced Micro Devices, Inc. or its
7+ // affiliates
68//
79// ===----------------------------------------------------------------------===//
810//
@@ -1077,10 +1079,14 @@ PDLByteCode::PDLByteCode(
10771079 generator.generate (module );
10781080
10791081 // Initialize the external functions.
1080- for (auto &it : constraintFns)
1082+ for (auto &it : constraintFns) {
10811083 constraintFunctions.push_back (std::move (it.second ));
1082- for (auto &it : rewriteFns)
1084+ constraintFunctionNames.push_back (it.first ().str ());
1085+ }
1086+ for (auto &it : rewriteFns) {
10831087 rewriteFunctions.push_back (std::move (it.second ));
1088+ rewriteFunctionNames.push_back (it.first ().str ());
1089+ }
10841090}
10851091
10861092// / Initialize the given state such that it can be used to execute the current
@@ -1137,7 +1143,9 @@ class ByteCodeExecutor {
11371143 ArrayRef<PatternBenefit> currentPatternBenefits,
11381144 ArrayRef<PDLByteCodePattern> patterns,
11391145 ArrayRef<PDLConstraintFunction> constraintFunctions,
1140- ArrayRef<PDLRewriteFunction> rewriteFunctions)
1146+ ArrayRef<PDLRewriteFunction> rewriteFunctions,
1147+ ArrayRef<std::string> constraintFunctionNames,
1148+ ArrayRef<std::string> rewriteFunctionNames)
11411149 : curCodeIt(curCodeIt), memory(memory), opRangeMemory(opRangeMemory),
11421150 typeRangeMemory (typeRangeMemory),
11431151 allocatedTypeRangeMemory(allocatedTypeRangeMemory),
@@ -1146,7 +1154,9 @@ class ByteCodeExecutor {
11461154 loopIndex(loopIndex), uniquedMemory(uniquedMemory), code(code),
11471155 currentPatternBenefits(currentPatternBenefits), patterns(patterns),
11481156 constraintFunctions(constraintFunctions),
1149- rewriteFunctions(rewriteFunctions) {}
1157+ rewriteFunctions(rewriteFunctions),
1158+ constraintFunctionNames(constraintFunctionNames),
1159+ rewriteFunctionNames(rewriteFunctionNames) {}
11501160
11511161 // / Start executing the code at the current bytecode index. `matches` is an
11521162 // / optional field provided when this function is executed in a matching
@@ -1431,12 +1441,16 @@ class ByteCodeExecutor {
14311441 ArrayRef<PDLByteCodePattern> patterns;
14321442 ArrayRef<PDLConstraintFunction> constraintFunctions;
14331443 ArrayRef<PDLRewriteFunction> rewriteFunctions;
1444+ ArrayRef<std::string> constraintFunctionNames;
1445+ ArrayRef<std::string> rewriteFunctionNames;
14341446};
14351447} // namespace
14361448
14371449void ByteCodeExecutor::executeApplyConstraint (PatternRewriter &rewriter) {
1438- LLVM_DEBUG (llvm::dbgs () << " Executing ApplyConstraint: \n " );
1450+ LLVM_DEBUG (llvm::dbgs () << " Executing ApplyConstraint " );
14391451 ByteCodeField fun_idx = read ();
1452+ LLVM_DEBUG (llvm::dbgs () << constraintFunctionNames[fun_idx] << " :\n " );
1453+
14401454 SmallVector<PDLValue, 16 > args;
14411455 readList<PDLValue>(args);
14421456
@@ -1477,8 +1491,12 @@ void ByteCodeExecutor::executeApplyConstraint(PatternRewriter &rewriter) {
14771491}
14781492
14791493LogicalResult ByteCodeExecutor::executeApplyRewrite (PatternRewriter &rewriter) {
1480- LLVM_DEBUG (llvm::dbgs () << " Executing ApplyRewrite:\n " );
1481- const PDLRewriteFunction &rewriteFn = rewriteFunctions[read ()];
1494+ LLVM_DEBUG (llvm::dbgs () << " Executing ApplyRewrite " );
1495+
1496+ ByteCodeField fun_idx = read ();
1497+ LLVM_DEBUG (llvm::dbgs () << rewriteFunctionNames[fun_idx] << " :\n " );
1498+ const PDLRewriteFunction &rewriteFn = rewriteFunctions[fun_idx];
1499+
14821500 SmallVector<PDLValue, 16 > args;
14831501 readList<PDLValue>(args);
14841502
@@ -2356,7 +2374,8 @@ void PDLByteCode::match(Operation *op, PatternRewriter &rewriter,
23562374 state.typeRangeMemory , state.allocatedTypeRangeMemory ,
23572375 state.valueRangeMemory , state.allocatedValueRangeMemory , state.loopIndex ,
23582376 uniquedData, matcherByteCode, state.currentPatternBenefits , patterns,
2359- constraintFunctions, rewriteFunctions);
2377+ constraintFunctions, rewriteFunctions, constraintFunctionNames,
2378+ rewriteFunctionNames);
23602379 LogicalResult executeResult = executor.execute (rewriter, &matches);
23612380 (void )executeResult;
23622381 assert (succeeded (executeResult) && " unexpected matcher execution failure" );
@@ -2385,7 +2404,8 @@ LogicalResult PDLByteCode::rewrite(PatternRewriter &rewriter,
23852404 state.allocatedTypeRangeMemory , state.valueRangeMemory ,
23862405 state.allocatedValueRangeMemory , state.loopIndex , uniquedData,
23872406 rewriterByteCode, state.currentPatternBenefits , patterns,
2388- constraintFunctions, rewriteFunctions);
2407+ constraintFunctions, rewriteFunctions, constraintFunctionNames,
2408+ rewriteFunctionNames);
23892409 LogicalResult result =
23902410 executor.execute (rewriter, /* matches=*/ nullptr , match.location );
23912411
0 commit comments