@@ -168,25 +168,39 @@ def update_intrinsics(llvm_path, llvmint, llvmint2):
168
168
os .path .dirname (os .path .abspath (__file__ )),
169
169
"../src/intrinsic/archs.rs" ,
170
170
)
171
+ # A hashmap of all architectures. This allows us to first match on the architecture, and then on the intrisnics.
172
+ # This speeds up the comparison, and makes our code considerably smaller.
173
+ # Since all intrinsic names start with ".llvm", we skip that prefix.
171
174
print ("Updating content of `{}`..." .format (output_file ))
172
175
with open (output_file , "w" , encoding = "utf8" ) as out :
173
176
out .write ("// File generated by `rustc_codegen_gcc/tools/generate_intrinsics.py`\n " )
174
177
out .write ("// DO NOT EDIT IT!\n " )
175
- out .write ("match name {\n " )
178
+ out .write ("/// Translate a given LLVM intrinsic name to an equivalent GCC one.\n " )
179
+ out .write ("fn map_arch_intrinsic(name:&str)->&str{\n " )
180
+ out .write ('let Some(name) = name.strip_prefix("llvm.") else {unimplemented!("***** unsupported LLVM intrinsic {}", name)};\n ' )
181
+ out .write ('let Some((arch, name)) = name.split_once(\' .\' ) else {unimplemented!("***** unsupported LLVM intrinsic {}", name)};\n ' )
182
+ out .write ("match arch {\n " )
176
183
for arch in archs :
177
184
if len (intrinsics [arch ]) == 0 :
178
185
continue
186
+ out .write ("\" {}\" => {{ #[allow(non_snake_case)] fn {}(name:&str)->&str{{ match name{{" .format (arch ,arch ))
179
187
intrinsics [arch ].sort (key = lambda x : (x [0 ], x [2 ]))
180
188
out .write (' // {}\n ' .format (arch ))
181
189
for entry in intrinsics [arch ]:
190
+ llvm_name = entry [0 ].removeprefix ("llvm." );
191
+ llvm_name = llvm_name .removeprefix (arch );
192
+ llvm_name = llvm_name .removeprefix ("." );
182
193
if entry [2 ] is True : # if it is a duplicate
183
- out .write (' // [DUPLICATE]: "{}" => "{}",\n ' .format (entry [ 0 ] , entry [1 ]))
194
+ out .write (' // [DUPLICATE]: "{}" => "{}",\n ' .format (llvm_name , entry [1 ]))
184
195
elif "_round_mask" in entry [1 ]:
185
- out .write (' // [INVALID CONVERSION]: "{}" => "{}",\n ' .format (entry [ 0 ] , entry [1 ]))
196
+ out .write (' // [INVALID CONVERSION]: "{}" => "{}",\n ' .format (llvm_name , entry [1 ]))
186
197
else :
187
- out .write (' "{}" => "{}",\n ' .format (entry [0 ], entry [1 ]))
198
+ out .write (' "{}" => "{}",\n ' .format (llvm_name , entry [1 ]))
199
+ out .write (' _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n ' )
200
+ out .write ("}} }} {}(name) }}\n ," .format (arch ))
188
201
out .write (' _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n ' )
189
- out .write ("}\n " )
202
+ out .write ("}\n }" )
203
+ subprocess .call (["rustfmt" , output_file ])
190
204
print ("Done!" )
191
205
192
206
0 commit comments