Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions clang/lib/DPCT/MigrateScript/MigrateCmakeScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,25 @@ applyCmakeMigrationRules(const clang::tooling::UnifiedPath InRoot,

// cmake systaxes need to be processed by implicit migration rules, as they are
// difficult to be described with yaml based rule syntax.
static const std::vector<std::string> ImplicitMigrationRules = {
static const std::vector<std::string> BuiltinMigrationRules = {
"cmake_minimum_required", "execute_process", "cuda_compile",
"cuda_compile_fatbin"};

static void reserveImplicitMigrationRules() {
for (const auto &Rule : ImplicitMigrationRules) {
MetaRuleObject::PatternRewriter PrePR;
PrePR.BuildScriptSyntax = Rule;
CmakeBuildInRules[PrePR.BuildScriptSyntax] = PrePR;
static void applyBuiltinMigrationRules() {
for (const auto &Rule : BuiltinMigrationRules) {
MetaRuleObject::PatternRewriter BuiltinPR;
BuiltinPR.BuildScriptSyntax = Rule;
BuiltinPR.RuleId = "builtin_rule_" + Rule;

auto &PR = CmakeBuildInRules[Rule];
if (PR.Priority != RulePriority::Takeover) {
PR = BuiltinPR;
} else {
llvm::outs() << "[Warning]: Two migration rules (Rule:"
<< BuiltinPR.RuleId << ", Rule:" << PR.RuleId
<< ") are duplicated, the migration rule (Rule:"
<< BuiltinPR.RuleId << ") is ignored.\n";
}
}
}

Expand All @@ -592,7 +602,7 @@ void doCmakeScriptMigration(const clang::tooling::UnifiedPath &InRoot,
loadBufferFromFile(InRoot, OutRoot, CmakeScriptFileBufferMap);
unifyInputFileFormat(CmakeScriptFileBufferMap, ScriptFileCRLFMap);
convertAllCmakeCommandsToLowerCase();
reserveImplicitMigrationRules();
applyBuiltinMigrationRules();
doCmakeScriptAnalysis();
applyCmakeMigrationRules(InRoot, OutRoot);
storeBufferToFile(CmakeScriptFileBufferMap, ScriptFileCRLFMap);
Expand All @@ -610,7 +620,7 @@ void registerCmakeMigrationRule(MetaRuleObject &R) {
Iter->second.Priority > PR.Priority) {
CmakeBuildInRules[PR.BuildScriptSyntax] = PR;
} else {
llvm::outs() << "[Warnning]: Two migration rules (Rule:" << R.RuleId
llvm::outs() << "[Warning]: Two migration rules (Rule:" << R.RuleId
<< ", Rule:" << Iter->second.RuleId
<< ") are duplicated, the migration rule (Rule:" << R.RuleId
<< ") is ignored.\n";
Expand Down
4 changes: 2 additions & 2 deletions clang/test/dpct/cmake_migration/case_044/ref.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// CHECK: [Warnning]: Two migration rules (Rule:rule_gen_codes_add_link_options_test_dup, Rule:rule_gen_codes_add_link_options) are duplicated, the migration rule (Rule:rule_gen_codes_add_link_options_test_dup) is ignored.
// CHECK: [Warnning]: Two migration rules (Rule:rule_a_new, Rule:rule_a_old) are duplicated, the migration rule (Rule:rule_a_new) is ignored.
// CHECK: [Warning]: Two migration rules (Rule:rule_gen_codes_add_link_options_test_dup, Rule:rule_gen_codes_add_link_options) are duplicated, the migration rule (Rule:rule_gen_codes_add_link_options_test_dup) is ignored.
// CHECK: [Warning]: Two migration rules (Rule:rule_a_new, Rule:rule_a_old) are duplicated, the migration rule (Rule:rule_a_new) is ignored.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: rm -rf %T && mkdir -p %T
// RUN: cd %T
// RUN: cp %S/input.cmake ./input.cmake
// RUN: dpct -in-root ./ -out-root out ./input.cmake --migrate-build-script-only --rule-file=%S/local_replace_implicit_migration_rule.yaml > migration.log 2>&1
// RUN: diff --strip-trailing-cr %S/expected.txt %T/out/input.cmake >> %T/diff.txt

// RUN: cat %S/migration_ref.log > %T/check_migration_check.log
// RUN: cat %T/migration.log >>%T/check_migration_check.log
// RUN: FileCheck --match-full-lines --input-file %T/check_migration_check.log %T/check_migration_check.log
19 changes: 19 additions & 0 deletions clang/test/dpct/cmake_migration/case_068/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## execute_process is commented in the CMakeLists.txt file
set(AOT_GENERATE_COMMAND
${Python3_EXECUTABLE} -m aot_build_utils.generate --path
${GENERATED_SOURCE_DIR} --head_dims ${HEAD_DIMS} --pos_encoding_modes
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
--mask_modes ${MASK_MODES} --enable_f16 ${FLASHINFER_ENABLE_F16}
--enable_bf16 ${FLASHINFER_ENABLE_BF16} --enable_fp8_e4m3
${FLASHINFER_ENABLE_FP8_E4M3} --enable_fp8_e5m2
${FLASHINFER_ENABLE_FP8_E5M2})

set(AOT_GENERATE_DISPATCH_INC_COMMAND
${Python3_EXECUTABLE} -m aot_build_utils.generate_dispatch_inc --path
"${GENERATED_SOURCE_DIR}/dispatch.inc" --head_dims ${HEAD_DIMS}
--head_dims_sm90 ${HEAD_DIMS_SM90} --pos_encoding_modes
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
--mask_modes ${MASK_MODES})

#execute_process(COMMAND ${AOT_GENERATE_COMMAND} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
#execute_process(COMMAND ${AOT_GENERATE_DISPATCH_INC_COMMAND} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
21 changes: 21 additions & 0 deletions clang/test/dpct/cmake_migration/case_068/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## execute_process is commented in the CMakeLists.txt file
set(AOT_GENERATE_COMMAND
${Python3_EXECUTABLE} -m aot_build_utils.generate --path
${GENERATED_SOURCE_DIR} --head_dims ${HEAD_DIMS} --pos_encoding_modes
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
--mask_modes ${MASK_MODES} --enable_f16 ${FLASHINFER_ENABLE_F16}
--enable_bf16 ${FLASHINFER_ENABLE_BF16} --enable_fp8_e4m3
${FLASHINFER_ENABLE_FP8_E4M3} --enable_fp8_e5m2
${FLASHINFER_ENABLE_FP8_E5M2})

set(AOT_GENERATE_DISPATCH_INC_COMMAND
${Python3_EXECUTABLE} -m aot_build_utils.generate_dispatch_inc --path
"${GENERATED_SOURCE_DIR}/dispatch.inc" --head_dims ${HEAD_DIMS}
--head_dims_sm90 ${HEAD_DIMS_SM90} --pos_encoding_modes
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
--mask_modes ${MASK_MODES})

execute_process(COMMAND ${AOT_GENERATE_COMMAND}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
execute_process(COMMAND ${AOT_GENERATE_DISPATCH_INC_COMMAND}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Rule: rule_execute_process
Kind: CMakeRule
Priority: Takeover
CmakeSyntax: execute_process
In: execute_process(${args1} ${args2} ${args3})
Out: "#execute_process(${args1} ${args2} ${args3})"
4 changes: 4 additions & 0 deletions clang/test/dpct/cmake_migration/case_068/migration_ref.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// CHECK: Warning: Only CMake scripts will be migrated as no --migrate-build-script option is provided.
// CHECK: dpct exited with code: 4 (Migration of build script(s) completed.)
// CHECK: [Warning]: Two migration rules (Rule:builtin_rule_execute_process, Rule:rule_execute_process) are duplicated, the migration rule (Rule:builtin_rule_execute_process) is ignored.
// CHECK: Processing: {{(.+)}}input.cmake