about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-06-18 15:11:44 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-06-18 15:11:44 +0200
commitefb79975f61712b619389999aa89c56f150371f1 (patch)
tree718c279c1bf27d0957e19001a764836cc9c5a99b /tools
parent265f4a7b6356c99de88bc8bb539a44d5277c7f36 (diff)
downloadrust-efb79975f61712b619389999aa89c56f150371f1.tar.gz
rust-efb79975f61712b619389999aa89c56f150371f1.zip
Merge commit 'fda0bb9588912a3e0606e880ca9f6e913cf8a5a4' into subtree-update_cg_gcc_2025-06-18
Diffstat (limited to 'tools')
-rw-r--r--tools/cspell_dicts/rust.txt2
-rw-r--r--tools/cspell_dicts/rustc_codegen_gcc.txt75
-rw-r--r--tools/generate_intrinsics.py26
3 files changed, 97 insertions, 6 deletions
diff --git a/tools/cspell_dicts/rust.txt b/tools/cspell_dicts/rust.txt
new file mode 100644
index 00000000000..379cbd77eef
--- /dev/null
+++ b/tools/cspell_dicts/rust.txt
@@ -0,0 +1,2 @@
+lateout
+repr
diff --git a/tools/cspell_dicts/rustc_codegen_gcc.txt b/tools/cspell_dicts/rustc_codegen_gcc.txt
new file mode 100644
index 00000000000..31023e50ffa
--- /dev/null
+++ b/tools/cspell_dicts/rustc_codegen_gcc.txt
@@ -0,0 +1,75 @@
+aapcs
+addo
+archs
+ashl
+ashr
+cgcx
+clzll
+cmse
+codegened
+csky
+ctlz
+ctpop
+cttz
+ctzll
+flto
+fmaximumf
+fmuladd
+fmuladdf
+fminimumf
+fmul
+fptosi
+fptosui
+fptoui
+fwrapv
+gimple
+hrtb
+immediates
+liblto
+llbb
+llcx
+llextra
+llfn
+lgcc
+llmod
+llresult
+llret
+ltrans
+llty
+llval
+llvals
+loong
+lshr
+masm
+maximumf
+maxnumf
+mavx
+mcmodel
+minimumf
+minnumf
+monomorphization
+monomorphizations
+monomorphized
+monomorphizing
+movnt
+mulo
+nvptx
+pointee
+powitf
+reassoc
+riscv
+rlib
+roundevenf
+rustc
+sitofp
+sizet
+spir
+subo
+sysv
+tbaa
+uitofp
+unord
+uninlined
+utrunc
+xabort
+zext
diff --git a/tools/generate_intrinsics.py b/tools/generate_intrinsics.py
index 181f1e501a4..ed0ebf00719 100644
--- a/tools/generate_intrinsics.py
+++ b/tools/generate_intrinsics.py
@@ -168,25 +168,39 @@ def update_intrinsics(llvm_path, llvmint, llvmint2):
         os.path.dirname(os.path.abspath(__file__)),
         "../src/intrinsic/archs.rs",
     )
+    # A hashmap of all architectures. This allows us to first match on the architecture, and then on the intrinsics.
+    # This speeds up the comparison, and makes our code considerably smaller.
+    # Since all intrinsic names start with "llvm.", we skip that prefix.
     print("Updating content of `{}`...".format(output_file))
     with open(output_file, "w", encoding="utf8") as out:
         out.write("// File generated by `rustc_codegen_gcc/tools/generate_intrinsics.py`\n")
         out.write("// DO NOT EDIT IT!\n")
-        out.write("match name {\n")
+        out.write("/// Translate a given LLVM intrinsic name to an equivalent GCC one.\n")
+        out.write("fn map_arch_intrinsic(name:&str)->&str{\n")
+        out.write('let Some(name) = name.strip_prefix("llvm.") else { unimplemented!("***** unsupported LLVM intrinsic {}", name) };\n')
+        out.write('let Some((arch, name)) = name.split_once(\'.\') else { unimplemented!("***** unsupported LLVM intrinsic {}", name) };\n')
+        out.write("match arch {\n")
         for arch in archs:
             if len(intrinsics[arch]) == 0:
                 continue
+            out.write("\"{}\" => {{ #[allow(non_snake_case)] fn {}(name: &str) -> &str {{ match name {{".format(arch,arch))
             intrinsics[arch].sort(key=lambda x: (x[0], x[2]))
             out.write('    // {}\n'.format(arch))
             for entry in intrinsics[arch]:
+                llvm_name = entry[0].removeprefix("llvm.");
+                llvm_name = llvm_name.removeprefix(arch);
+                llvm_name = llvm_name.removeprefix(".");
                 if entry[2] is True: # if it is a duplicate
-                    out.write('    // [DUPLICATE]: "{}" => "{}",\n'.format(entry[0], entry[1]))
+                    out.write('    // [DUPLICATE]: "{}" => "{}",\n'.format(llvm_name, entry[1]))
                 elif "_round_mask" in entry[1]:
-                    out.write('    // [INVALID CONVERSION]: "{}" => "{}",\n'.format(entry[0], entry[1]))
+                    out.write('    // [INVALID CONVERSION]: "{}" => "{}",\n'.format(llvm_name, entry[1]))
                 else:
-                    out.write('    "{}" => "{}",\n'.format(entry[0], entry[1]))
-        out.write('    _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n')
-        out.write("}\n")
+                    out.write('    "{}" => "{}",\n'.format(llvm_name, entry[1]))
+            out.write('    _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n')
+            out.write("}} }} {}(name) }}\n,".format(arch))
+        out.write('    _ => unimplemented!("***** unsupported LLVM architecture {}", name),\n')
+        out.write("}\n}")
+    subprocess.call(["rustfmt", output_file])
     print("Done!")