Skip to content

Commit 542c82e

Browse files
committed
Fix for libgccjit 12
1 parent e3deac5 commit 542c82e

File tree

6 files changed

+79
-61
lines changed

6 files changed

+79
-61
lines changed

Cargo.lock

Lines changed: 15 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ gccjit = { git = "https://github.com/antoyo/gccjit.rs" }
2828
#gccjit = { path = "../gccjit.rs" }
2929

3030
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
31+
# TODO(antoyo): make tempfile optional.
32+
tempfile = "3.7.1"
3133

3234
[dev-dependencies]
3335
lang_tester = "0.3.9"

src/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use std::time::Instant;
66
use gccjit::{
77
Context,
88
FunctionType,
9-
GlobalKind, TargetInfo,
9+
GlobalKind,
1010
};
11+
#[cfg(feature="master")]
12+
use gccjit::TargetInfo;
1113
use rustc_middle::dep_graph;
1214
use rustc_middle::ty::TyCtxt;
1315
#[cfg(feature="master")]
@@ -20,6 +22,8 @@ use rustc_codegen_ssa::traits::DebugInfoMethods;
2022
use rustc_session::config::DebugInfo;
2123
use rustc_span::Symbol;
2224

25+
#[cfg(not(feature="master"))]
26+
use crate::TargetInfo;
2327
use crate::GccContext;
2428
use crate::builder::Builder;
2529
use crate::context::CodegenCx;

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
493493
}
494494

495495
#[cfg(not(feature="master"))]
496-
fn invoke(&mut self, typ: Type<'gcc>, fn_attrs: &CodegenFnAttrs, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
496+
fn invoke(&mut self, typ: Type<'gcc>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
497497
let call_site = self.call(typ, fn_attrs, None, func, args, None);
498498
let condition = self.context.new_rvalue_from_int(self.bool_type, 1);
499499
self.llbb().end_with_conditional(None, condition, then, catch);

src/intrinsic/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use rustc_codegen_ssa::base::wants_msvc_seh;
1010
use rustc_codegen_ssa::common::IntPredicate;
1111
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1212
use rustc_codegen_ssa::mir::place::PlaceRef;
13-
use rustc_codegen_ssa::traits::{ArgAbiMethods, BaseTypeMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods};
13+
use rustc_codegen_ssa::traits::{ArgAbiMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods};
1414
#[cfg(feature="master")]
15-
use rustc_codegen_ssa::traits::MiscMethods;
15+
use rustc_codegen_ssa::traits::{BaseTypeMethods, MiscMethods};
1616
use rustc_codegen_ssa::errors::InvalidMonomorphization;
1717
use rustc_middle::bug;
1818
use rustc_middle::ty::{self, Instance, Ty};

src/lib.rs

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ mod type_of;
6464

6565
use std::any::Any;
6666
use std::sync::Arc;
67+
#[cfg(not(feature="master"))]
68+
use std::sync::atomic::{AtomicBool, Ordering};
6769

6870
use crate::errors::LTONotSupported;
69-
use gccjit::{Context, OptimizationLevel, TargetInfo};
71+
use gccjit::{Context, OptimizationLevel};
72+
#[cfg(feature="master")]
73+
use gccjit::TargetInfo;
74+
#[cfg(not(feature="master"))]
75+
use gccjit::CType;
7076
use rustc_ast::expand::allocator::AllocatorKind;
7177
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
7278
use rustc_codegen_ssa::base::codegen_crate;
@@ -85,6 +91,8 @@ use rustc_session::config::{Lto, OptLevel, OutputFilenames};
8591
use rustc_session::Session;
8692
use rustc_span::Symbol;
8793
use rustc_span::fatal_error::FatalError;
94+
#[cfg(not(feature="master"))]
95+
use tempfile::TempDir;
8896

8997
fluent_messages! { "../messages.ftl" }
9098

@@ -98,6 +106,23 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
98106
}
99107
}
100108

109+
#[cfg(not(feature="master"))]
110+
#[derive(Debug)]
111+
pub struct TargetInfo {
112+
supports_128bit_integers: AtomicBool,
113+
}
114+
115+
#[cfg(not(feature="master"))]
116+
impl TargetInfo {
117+
fn cpu_supports(&self, _feature: &str) -> bool {
118+
false
119+
}
120+
121+
fn supports_128bit_int(&self) -> bool {
122+
self.supports_128bit_integers.load(Ordering::SeqCst)
123+
}
124+
}
125+
101126
#[derive(Clone)]
102127
pub struct GccCodegenBackend {
103128
target_info: Arc<TargetInfo>,
@@ -114,6 +139,18 @@ impl CodegenBackend for GccCodegenBackend {
114139
if sess.lto() != Lto::No {
115140
sess.emit_warning(LTONotSupported {});
116141
}
142+
143+
#[cfg(not(feature="master"))]
144+
{
145+
let temp_dir = TempDir::new().expect("cannot create temporary directory");
146+
let temp_file = temp_dir.into_path().join("result.asm");
147+
let check_context = Context::default();
148+
check_context.set_print_errors_to_stderr(false);
149+
let _int128_ty = check_context.new_c_type(CType::UInt128t);
150+
// NOTE: we cannot just call compile() as this would require other files than libgccjit.so.
151+
check_context.compile_to_file(gccjit::OutputKind::Assembler, temp_file.to_str().expect("path to str"));
152+
self.target_info.supports_128bit_integers.store(check_context.get_last_error() == Ok(None), Ordering::SeqCst);
153+
}
117154
}
118155

119156
fn provide(&self, providers: &mut Providers) {
@@ -266,14 +303,21 @@ impl WriteBackendMethods for GccCodegenBackend {
266303
/// This is the entrypoint for a hot plugged rustc_codegen_gccjit
267304
#[no_mangle]
268305
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
269-
// Get the native arch and check whether the target supports 128-bit integers.
270-
let context = Context::default();
271-
let arch = context.get_target_info().arch().unwrap();
272-
273-
// Get the second TargetInfo with the correct CPU features by setting the arch.
274-
let context = Context::default();
275-
context.add_driver_option(&format!("-march={}", arch.to_str().unwrap()));
276-
let target_info = Arc::new(context.get_target_info());
306+
#[cfg(feature="master")]
307+
let target_info = {
308+
// Get the native arch and check whether the target supports 128-bit integers.
309+
let context = Context::default();
310+
let arch = context.get_target_info().arch().unwrap();
311+
312+
// Get the second TargetInfo with the correct CPU features by setting the arch.
313+
let context = Context::default();
314+
context.add_driver_option(&format!("-march={}", arch.to_str().unwrap()));
315+
Arc::new(context.get_target_info())
316+
};
317+
#[cfg(not(feature="master"))]
318+
let target_info = Arc::new(TargetInfo {
319+
supports_128bit_integers: AtomicBool::new(false),
320+
});
277321

278322
Box::new(GccCodegenBackend {
279323
target_info,
@@ -319,14 +363,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Arc<T
319363
},
320364
)
321365
.filter(|_feature| {
322-
#[cfg(feature="master")]
323-
{
324-
target_info.cpu_supports(_feature)
325-
}
326-
#[cfg(not(feature="master"))]
327-
{
328-
false
329-
}
366+
target_info.cpu_supports(_feature)
330367
/*
331368
adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma,
332369
avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq,

0 commit comments

Comments
 (0)