Merge commit '1411a98352
' into sync_cg_clif-2021-12-31
This commit is contained in:
commit
b799d6e0a5
18 changed files with 245 additions and 209 deletions
|
@ -18,30 +18,30 @@ use crate::type_of::LayoutGccExt;
|
|||
|
||||
// Rust asm! and GCC Extended Asm semantics differ substantially.
|
||||
//
|
||||
// 1. Rust asm operands go along as one list of operands. Operands themselves indicate
|
||||
// if they're "in" or "out". "In" and "out" operands can interleave. One operand can be
|
||||
// 1. Rust asm operands go along as one list of operands. Operands themselves indicate
|
||||
// if they're "in" or "out". "In" and "out" operands can interleave. One operand can be
|
||||
// both "in" and "out" (`inout(reg)`).
|
||||
//
|
||||
// GCC asm has two different lists for "in" and "out" operands. In terms of gccjit,
|
||||
// this means that all "out" operands must go before "in" operands. "In" and "out" operands
|
||||
// GCC asm has two different lists for "in" and "out" operands. In terms of gccjit,
|
||||
// this means that all "out" operands must go before "in" operands. "In" and "out" operands
|
||||
// cannot interleave.
|
||||
//
|
||||
// 2. Operand lists in both Rust and GCC are indexed. Index starts from 0. Indexes are important
|
||||
// 2. Operand lists in both Rust and GCC are indexed. Index starts from 0. Indexes are important
|
||||
// because the asm template refers to operands by index.
|
||||
//
|
||||
// Mapping from Rust to GCC index would be 1-1 if it wasn't for...
|
||||
//
|
||||
// 3. Clobbers. GCC has a separate list of clobbers, and clobbers don't have indexes.
|
||||
// Contrary, Rust expresses clobbers through "out" operands that aren't tied to
|
||||
// 3. Clobbers. GCC has a separate list of clobbers, and clobbers don't have indexes.
|
||||
// Contrary, Rust expresses clobbers through "out" operands that aren't tied to
|
||||
// a variable (`_`), and such "clobbers" do have index.
|
||||
//
|
||||
// 4. Furthermore, GCC Extended Asm does not support explicit register constraints
|
||||
// (like `out("eax")`) directly, offering so-called "local register variables"
|
||||
// as a workaround. These variables need to be declared and initialized *before*
|
||||
// the Extended Asm block but *after* normal local variables
|
||||
// 4. Furthermore, GCC Extended Asm does not support explicit register constraints
|
||||
// (like `out("eax")`) directly, offering so-called "local register variables"
|
||||
// as a workaround. These variables need to be declared and initialized *before*
|
||||
// the Extended Asm block but *after* normal local variables
|
||||
// (see comment in `codegen_inline_asm` for explanation).
|
||||
//
|
||||
// With that in mind, let's see how we translate Rust syntax to GCC
|
||||
// With that in mind, let's see how we translate Rust syntax to GCC
|
||||
// (from now on, `CC` stands for "constraint code"):
|
||||
//
|
||||
// * `out(reg_class) var` -> translated to output operand: `"=CC"(var)`
|
||||
|
@ -52,18 +52,17 @@ use crate::type_of::LayoutGccExt;
|
|||
//
|
||||
// * `out("explicit register") _` -> not translated to any operands, register is simply added to clobbers list
|
||||
//
|
||||
// * `inout(reg_class) in_var => out_var` -> translated to two operands:
|
||||
// * `inout(reg_class) in_var => out_var` -> translated to two operands:
|
||||
// output: `"=CC"(in_var)`
|
||||
// input: `"num"(out_var)` where num is the GCC index
|
||||
// input: `"num"(out_var)` where num is the GCC index
|
||||
// of the corresponding output operand
|
||||
//
|
||||
// * `inout(reg_class) in_var => _` -> same as `inout(reg_class) in_var => tmp`,
|
||||
// * `inout(reg_class) in_var => _` -> same as `inout(reg_class) in_var => tmp`,
|
||||
// where "tmp" is a temporary unused variable
|
||||
//
|
||||
// * `out/in/inout("explicit register") var` -> translated to one or two operands as described above
|
||||
// with `"r"(var)` constraint,
|
||||
// * `out/in/inout("explicit register") var` -> translated to one or two operands as described above
|
||||
// with `"r"(var)` constraint,
|
||||
// and one register variable assigned to the desired register.
|
||||
//
|
||||
|
||||
const ATT_SYNTAX_INS: &str = ".att_syntax noprefix\n\t";
|
||||
const INTEL_SYNTAX_INS: &str = "\n\t.intel_syntax noprefix";
|
||||
|
@ -131,7 +130,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
let att_dialect = is_x86 && options.contains(InlineAsmOptions::ATT_SYNTAX);
|
||||
let intel_dialect = is_x86 && !options.contains(InlineAsmOptions::ATT_SYNTAX);
|
||||
|
||||
// GCC index of an output operand equals its position in the array
|
||||
// GCC index of an output operand equals its position in the array
|
||||
let mut outputs = vec![];
|
||||
|
||||
// GCC index of an input operand equals its position in the array
|
||||
|
@ -145,9 +144,9 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
let mut constants_len = 0;
|
||||
|
||||
// There are rules we must adhere to if we want GCC to do the right thing:
|
||||
//
|
||||
//
|
||||
// * Every local variable that the asm block uses as an output must be declared *before*
|
||||
// the asm block.
|
||||
// the asm block.
|
||||
// * There must be no instructions whatsoever between the register variables and the asm.
|
||||
//
|
||||
// Therefore, the backend must generate the instructions strictly in this order:
|
||||
|
@ -159,7 +158,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
// We also must make sure that no input operands are emitted before output operands.
|
||||
//
|
||||
// This is why we work in passes, first emitting local vars, then local register vars.
|
||||
// Also, we don't emit any asm operands immediately; we save them to
|
||||
// Also, we don't emit any asm operands immediately; we save them to
|
||||
// the one of the buffers to be emitted later.
|
||||
|
||||
// 1. Normal variables (and saving operands to buffers).
|
||||
|
@ -172,7 +171,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
(Constraint(constraint), Some(place)) => (constraint, place.layout.gcc_type(self.cx, false)),
|
||||
// When `reg` is a class and not an explicit register but the out place is not specified,
|
||||
// we need to create an unused output variable to assign the output to. This var
|
||||
// needs to be of a type that's "compatible" with the register class, but specific type
|
||||
// needs to be of a type that's "compatible" with the register class, but specific type
|
||||
// doesn't matter.
|
||||
(Constraint(constraint), None) => (constraint, dummy_output_type(self.cx, reg.reg_class())),
|
||||
(Register(_), Some(_)) => {
|
||||
|
@ -200,7 +199,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
|
||||
let tmp_var = self.current_func().new_local(None, ty, "output_register");
|
||||
outputs.push(AsmOutOperand {
|
||||
constraint,
|
||||
constraint,
|
||||
rust_idx,
|
||||
late,
|
||||
readwrite: false,
|
||||
|
@ -211,12 +210,12 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
|
||||
InlineAsmOperandRef::In { reg, value } => {
|
||||
if let ConstraintOrRegister::Constraint(constraint) = reg_to_gcc(reg) {
|
||||
inputs.push(AsmInOperand {
|
||||
constraint: Cow::Borrowed(constraint),
|
||||
rust_idx,
|
||||
inputs.push(AsmInOperand {
|
||||
constraint: Cow::Borrowed(constraint),
|
||||
rust_idx,
|
||||
val: value.immediate()
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// left for the next pass
|
||||
continue
|
||||
|
@ -226,7 +225,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
InlineAsmOperandRef::InOut { reg, late, in_value, out_place } => {
|
||||
let constraint = if let ConstraintOrRegister::Constraint(constraint) = reg_to_gcc(reg) {
|
||||
constraint
|
||||
}
|
||||
}
|
||||
else {
|
||||
// left for the next pass
|
||||
continue
|
||||
|
@ -235,22 +234,22 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
// Rustc frontend guarantees that input and output types are "compatible",
|
||||
// so we can just use input var's type for the output variable.
|
||||
//
|
||||
// This decision is also backed by the fact that LLVM needs in and out
|
||||
// values to be of *exactly the same type*, not just "compatible".
|
||||
// This decision is also backed by the fact that LLVM needs in and out
|
||||
// values to be of *exactly the same type*, not just "compatible".
|
||||
// I'm not sure if GCC is so picky too, but better safe than sorry.
|
||||
let ty = in_value.layout.gcc_type(self.cx, false);
|
||||
let tmp_var = self.current_func().new_local(None, ty, "output_register");
|
||||
|
||||
// If the out_place is None (i.e `inout(reg) _` syntax was used), we translate
|
||||
// it to one "readwrite (+) output variable", otherwise we translate it to two
|
||||
// it to one "readwrite (+) output variable", otherwise we translate it to two
|
||||
// "out and tied in" vars as described above.
|
||||
let readwrite = out_place.is_none();
|
||||
outputs.push(AsmOutOperand {
|
||||
constraint,
|
||||
constraint,
|
||||
rust_idx,
|
||||
late,
|
||||
readwrite,
|
||||
tmp_var,
|
||||
tmp_var,
|
||||
out_place,
|
||||
});
|
||||
|
||||
|
@ -259,8 +258,8 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
let constraint = Cow::Owned(out_gcc_idx.to_string());
|
||||
|
||||
inputs.push(AsmInOperand {
|
||||
constraint,
|
||||
rust_idx,
|
||||
constraint,
|
||||
rust_idx,
|
||||
val: in_value.immediate()
|
||||
});
|
||||
}
|
||||
|
@ -287,7 +286,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
if let ConstraintOrRegister::Register(reg_name) = reg_to_gcc(reg) {
|
||||
let out_place = if let Some(place) = place {
|
||||
place
|
||||
}
|
||||
}
|
||||
else {
|
||||
// processed in the previous pass
|
||||
continue
|
||||
|
@ -298,7 +297,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
tmp_var.set_register_name(reg_name);
|
||||
|
||||
outputs.push(AsmOutOperand {
|
||||
constraint: "r".into(),
|
||||
constraint: "r".into(),
|
||||
rust_idx,
|
||||
late,
|
||||
readwrite: false,
|
||||
|
@ -318,9 +317,9 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
reg_var.set_register_name(reg_name);
|
||||
self.llbb().add_assignment(None, reg_var, value.immediate());
|
||||
|
||||
inputs.push(AsmInOperand {
|
||||
constraint: "r".into(),
|
||||
rust_idx,
|
||||
inputs.push(AsmInOperand {
|
||||
constraint: "r".into(),
|
||||
rust_idx,
|
||||
val: reg_var.to_rvalue()
|
||||
});
|
||||
}
|
||||
|
@ -331,31 +330,23 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
// `inout("explicit register") in_var => out_var`
|
||||
InlineAsmOperandRef::InOut { reg, late, in_value, out_place } => {
|
||||
if let ConstraintOrRegister::Register(reg_name) = reg_to_gcc(reg) {
|
||||
let out_place = if let Some(place) = out_place {
|
||||
place
|
||||
}
|
||||
else {
|
||||
// processed in the previous pass
|
||||
continue
|
||||
};
|
||||
|
||||
// See explanation in the first pass.
|
||||
let ty = in_value.layout.gcc_type(self.cx, false);
|
||||
let tmp_var = self.current_func().new_local(None, ty, "output_register");
|
||||
tmp_var.set_register_name(reg_name);
|
||||
|
||||
outputs.push(AsmOutOperand {
|
||||
constraint: "r".into(),
|
||||
constraint: "r".into(),
|
||||
rust_idx,
|
||||
late,
|
||||
readwrite: false,
|
||||
tmp_var,
|
||||
out_place: Some(out_place)
|
||||
out_place,
|
||||
});
|
||||
|
||||
let constraint = Cow::Owned((outputs.len() - 1).to_string());
|
||||
inputs.push(AsmInOperand {
|
||||
constraint,
|
||||
inputs.push(AsmInOperand {
|
||||
constraint,
|
||||
rust_idx,
|
||||
val: in_value.immediate()
|
||||
});
|
||||
|
@ -364,8 +355,8 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
// processed in the previous pass
|
||||
}
|
||||
|
||||
InlineAsmOperandRef::Const { .. }
|
||||
| InlineAsmOperandRef::SymFn { .. }
|
||||
InlineAsmOperandRef::Const { .. }
|
||||
| InlineAsmOperandRef::SymFn { .. }
|
||||
| InlineAsmOperandRef::SymStatic { .. } => {
|
||||
// processed in the previous pass
|
||||
}
|
||||
|
@ -460,7 +451,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
if !intel_dialect {
|
||||
template_str.push_str(INTEL_SYNTAX_INS);
|
||||
}
|
||||
|
||||
|
||||
// 4. Generate Extended Asm block
|
||||
|
||||
let block = self.llbb();
|
||||
|
@ -479,7 +470,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
}
|
||||
|
||||
if !options.contains(InlineAsmOptions::PRESERVES_FLAGS) {
|
||||
// TODO(@Commeownist): I'm not 100% sure this one clobber is sufficient
|
||||
// TODO(@Commeownist): I'm not 100% sure this one clobber is sufficient
|
||||
// on all architectures. For instance, what about FP stack?
|
||||
extended_asm.add_clobber("cc");
|
||||
}
|
||||
|
@ -498,10 +489,10 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
self.call(self.type_void(), builtin_unreachable, &[], None);
|
||||
}
|
||||
|
||||
// Write results to outputs.
|
||||
// Write results to outputs.
|
||||
//
|
||||
// We need to do this because:
|
||||
// 1. Turning `PlaceRef` into `RValue` is error-prone and has nasty edge cases
|
||||
// 1. Turning `PlaceRef` into `RValue` is error-prone and has nasty edge cases
|
||||
// (especially with current `rustc_backend_ssa` API).
|
||||
// 2. Not every output operand has an `out_place`, and it's required by `add_output_operand`.
|
||||
//
|
||||
|
@ -509,7 +500,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
// generates `out_place = tmp_var;` assignments if out_place exists.
|
||||
for op in &outputs {
|
||||
if let Some(place) = op.out_place {
|
||||
OperandValue::Immediate(op.tmp_var.to_rvalue()).store(self, place);
|
||||
OperandValue::Immediate(op.tmp_var.to_rvalue()).store(self, place);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::{env, fs};
|
||||
|
||||
use gccjit::OutputKind;
|
||||
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
|
||||
|
@ -42,17 +42,17 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
|
|||
let _timer = cgcx
|
||||
.prof
|
||||
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &*module.name);
|
||||
match &*module.name {
|
||||
"std_example.7rcbfp3g-cgu.15" => {
|
||||
println!("Dumping reproducer {}", module.name);
|
||||
let _ = fs::create_dir("/tmp/reproducers");
|
||||
// FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
|
||||
// transmuting an rvalue to an lvalue.
|
||||
// Segfault is actually in gcc::jit::reproducer::get_identifier_as_lvalue
|
||||
context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
|
||||
println!("Dumped reproducer {}", module.name);
|
||||
},
|
||||
_ => (),
|
||||
if env::var("CG_GCCJIT_DUMP_MODULE_NAMES").as_deref() == Ok("1") {
|
||||
println!("Module {}", module.name);
|
||||
}
|
||||
if env::var("CG_GCCJIT_DUMP_MODULE").as_deref() == Ok(&module.name) {
|
||||
println!("Dumping reproducer {}", module.name);
|
||||
let _ = fs::create_dir("/tmp/reproducers");
|
||||
// FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
|
||||
// transmuting an rvalue to an lvalue.
|
||||
// Segfault is actually in gcc::jit::reproducer::get_identifier_as_lvalue
|
||||
context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
|
||||
println!("Dumped reproducer {}", module.name);
|
||||
}
|
||||
context.compile_to_file(OutputKind::ObjectFile, obj_out.to_str().expect("path to str"));
|
||||
}
|
||||
|
|
|
@ -81,7 +81,10 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
|
|||
for arg in &tcx.sess.opts.cg.llvm_args {
|
||||
context.add_command_line_option(arg);
|
||||
}
|
||||
// NOTE: an optimization (https://github.com/rust-lang/rustc_codegen_gcc/issues/53).
|
||||
context.add_command_line_option("-fno-semantic-interposition");
|
||||
// NOTE: Rust relies on LLVM not doing TBAA (https://github.com/rust-lang/unsafe-code-guidelines/issues/292).
|
||||
context.add_command_line_option("-fno-strict-aliasing");
|
||||
if env::var("CG_GCCJIT_DUMP_CODE").as_deref() == Ok("1") {
|
||||
context.set_dump_code_on_compile(true);
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
fn check_ptr_call<'b>(&mut self, _typ: &str, func_ptr: RValue<'gcc>, args: &'b [RValue<'gcc>]) -> Cow<'b, [RValue<'gcc>]> {
|
||||
let mut all_args_match = true;
|
||||
let mut param_types = vec![];
|
||||
let gcc_func = func_ptr.get_type().is_function_ptr_type().expect("function ptr");
|
||||
let gcc_func = func_ptr.get_type().dyncast_function_ptr_type().expect("function ptr");
|
||||
for (index, arg) in args.iter().enumerate().take(gcc_func.get_param_count()) {
|
||||
let param = gcc_func.get_param_type(index);
|
||||
if param != arg.get_type() {
|
||||
|
@ -277,7 +277,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
|
||||
// gccjit requires to use the result of functions, even when it's not used.
|
||||
// That's why we assign the result to a local or call add_eval().
|
||||
let gcc_func = func_ptr.get_type().is_function_ptr_type().expect("function ptr");
|
||||
let gcc_func = func_ptr.get_type().dyncast_function_ptr_type().expect("function ptr");
|
||||
let mut return_type = gcc_func.get_return_type();
|
||||
let current_block = self.current_block.borrow().expect("block");
|
||||
let void_type = self.context.new_type::<()>();
|
||||
|
@ -605,22 +605,17 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
}
|
||||
|
||||
fn and(&mut self, a: RValue<'gcc>, mut b: RValue<'gcc>) -> RValue<'gcc> {
|
||||
// FIXME(antoyo): hack by putting the result in a variable to workaround this bug:
|
||||
// https://gcc.gnu.org/bugzilla//show_bug.cgi?id=95498
|
||||
if a.get_type() != b.get_type() {
|
||||
b = self.context.new_cast(None, b, a.get_type());
|
||||
}
|
||||
let res = self.current_func().new_local(None, b.get_type(), "andResult");
|
||||
self.llbb().add_assignment(None, res, a & b);
|
||||
res.to_rvalue()
|
||||
a & b
|
||||
}
|
||||
|
||||
fn or(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
|
||||
// FIXME(antoyo): hack by putting the result in a variable to workaround this bug:
|
||||
// https://gcc.gnu.org/bugzilla//show_bug.cgi?id=95498
|
||||
let res = self.current_func().new_local(None, b.get_type(), "orResult");
|
||||
self.llbb().add_assignment(None, res, a | b);
|
||||
res.to_rvalue()
|
||||
fn or(&mut self, a: RValue<'gcc>, mut b: RValue<'gcc>) -> RValue<'gcc> {
|
||||
if a.get_type() != b.get_type() {
|
||||
b = self.context.new_cast(None, b, a.get_type());
|
||||
}
|
||||
a | b
|
||||
}
|
||||
|
||||
fn xor(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
|
||||
|
@ -628,8 +623,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
}
|
||||
|
||||
fn neg(&mut self, a: RValue<'gcc>) -> RValue<'gcc> {
|
||||
// TODO(antoyo): use new_unary_op()?
|
||||
self.cx.context.new_rvalue_from_long(a.get_type(), 0) - a
|
||||
self.cx.context.new_unary_op(None, UnaryOp::Minus, a.get_type(), a)
|
||||
}
|
||||
|
||||
fn fneg(&mut self, a: RValue<'gcc>) -> RValue<'gcc> {
|
||||
|
@ -816,7 +810,10 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
let atomic_load = self.context.get_builtin_function(&format!("__atomic_load_{}", size.bytes()));
|
||||
let ordering = self.context.new_rvalue_from_int(self.i32_type, order.to_gcc());
|
||||
|
||||
let volatile_const_void_ptr_type = self.context.new_type::<*mut ()>().make_const().make_volatile();
|
||||
let volatile_const_void_ptr_type = self.context.new_type::<()>()
|
||||
.make_const()
|
||||
.make_volatile()
|
||||
.make_pointer();
|
||||
let ptr = self.context.new_cast(None, ptr, volatile_const_void_ptr_type);
|
||||
self.context.new_call(None, atomic_load, &[ptr, ordering])
|
||||
}
|
||||
|
@ -941,7 +938,9 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
// TODO(antoyo): handle alignment.
|
||||
let atomic_store = self.context.get_builtin_function(&format!("__atomic_store_{}", size.bytes()));
|
||||
let ordering = self.context.new_rvalue_from_int(self.i32_type, order.to_gcc());
|
||||
let volatile_const_void_ptr_type = self.context.new_type::<*mut ()>().make_const().make_volatile();
|
||||
let volatile_const_void_ptr_type = self.context.new_type::<()>()
|
||||
.make_volatile()
|
||||
.make_pointer();
|
||||
let ptr = self.context.new_cast(None, ptr, volatile_const_void_ptr_type);
|
||||
|
||||
// FIXME(antoyo): fix libgccjit to allow comparing an integer type with an aligned integer type because
|
||||
|
@ -981,12 +980,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
assert_eq!(idx as usize as u64, idx);
|
||||
let value = ptr.dereference(None).to_rvalue();
|
||||
|
||||
if value_type.is_array().is_some() {
|
||||
if value_type.dyncast_array().is_some() {
|
||||
let index = self.context.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
|
||||
let element = self.context.new_array_access(None, value, index);
|
||||
element.get_address(None)
|
||||
}
|
||||
else if let Some(vector_type) = value_type.is_vector() {
|
||||
else if let Some(vector_type) = value_type.dyncast_vector() {
|
||||
let array_type = vector_type.get_element_type().make_pointer();
|
||||
let array = self.bitcast(ptr, array_type);
|
||||
let index = self.context.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
|
||||
|
@ -1009,7 +1008,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
|
||||
fn sext(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
||||
// TODO(antoyo): check that it indeed sign extend the value.
|
||||
if dest_ty.is_vector().is_some() {
|
||||
if dest_ty.dyncast_vector().is_some() {
|
||||
// TODO(antoyo): nothing to do as it is only for LLVM?
|
||||
return value;
|
||||
}
|
||||
|
@ -1081,7 +1080,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
let right_type = rhs.get_type();
|
||||
if left_type != right_type {
|
||||
// NOTE: because libgccjit cannot compare function pointers.
|
||||
if left_type.is_function_ptr_type().is_some() && right_type.is_function_ptr_type().is_some() {
|
||||
if left_type.dyncast_function_ptr_type().is_some() && right_type.dyncast_function_ptr_type().is_some() {
|
||||
lhs = self.context.new_cast(None, lhs, self.usize_type.make_pointer());
|
||||
rhs = self.context.new_cast(None, rhs, self.usize_type.make_pointer());
|
||||
}
|
||||
|
@ -1189,12 +1188,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
assert_eq!(idx as usize as u64, idx);
|
||||
let value_type = aggregate_value.get_type();
|
||||
|
||||
if value_type.is_array().is_some() {
|
||||
if value_type.dyncast_array().is_some() {
|
||||
let index = self.context.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
|
||||
let element = self.context.new_array_access(None, aggregate_value, index);
|
||||
element.get_address(None)
|
||||
}
|
||||
else if value_type.is_vector().is_some() {
|
||||
else if value_type.dyncast_vector().is_some() {
|
||||
panic!();
|
||||
}
|
||||
else if let Some(pointer_type) = value_type.get_pointee() {
|
||||
|
@ -1221,11 +1220,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||
let value_type = aggregate_value.get_type();
|
||||
|
||||
let lvalue =
|
||||
if value_type.is_array().is_some() {
|
||||
if value_type.dyncast_array().is_some() {
|
||||
let index = self.context.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
|
||||
self.context.new_array_access(None, aggregate_value, index)
|
||||
}
|
||||
else if value_type.is_vector().is_some() {
|
||||
else if value_type.dyncast_vector().is_some() {
|
||||
panic!();
|
||||
}
|
||||
else if let Some(pointer_type) = value_type.get_pointee() {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use gccjit::LValue;
|
||||
use gccjit::{Block, CType, RValue, Type, ToRValue};
|
||||
|
@ -44,7 +43,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
let string = self.context.new_string_literal(&*string);
|
||||
let sym = self.generate_local_symbol_name("str");
|
||||
let global = self.declare_private_global(&sym, self.val_ty(string));
|
||||
global.global_set_initializer_value(string);
|
||||
global.global_set_initializer_rvalue(string);
|
||||
global
|
||||
// TODO(antoyo): set linkage.
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
|
|||
bytes.iter()
|
||||
.map(|&byte| context.new_rvalue_from_int(byte_type, byte as i32))
|
||||
.collect();
|
||||
context.new_rvalue_from_array(None, typ, &elements)
|
||||
context.new_array_constructor(None, typ, &elements)
|
||||
}
|
||||
|
||||
pub fn type_is_pointer<'gcc>(typ: Type<'gcc>) -> bool {
|
||||
|
@ -120,13 +119,6 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
|||
}
|
||||
|
||||
fn const_uint_big(&self, typ: Type<'gcc>, num: u128) -> RValue<'gcc> {
|
||||
let num64: Result<i64, _> = num.try_into();
|
||||
if let Ok(num) = num64 {
|
||||
// FIXME(antoyo): workaround for a bug where libgccjit is expecting a constant.
|
||||
// The operations >> 64 and | low are making the normal case a non-constant.
|
||||
return self.context.new_rvalue_from_long(typ, num as i64);
|
||||
}
|
||||
|
||||
if num >> 64 != 0 {
|
||||
// FIXME(antoyo): use a new function new_rvalue_from_unsigned_long()?
|
||||
let low = self.context.new_rvalue_from_long(self.u64_type, num as u64 as i64);
|
||||
|
@ -193,7 +185,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
|||
// TODO(antoyo): cache the type? It's anonymous, so probably not.
|
||||
let typ = self.type_struct(&fields, packed);
|
||||
let struct_type = typ.is_struct().expect("struct type");
|
||||
self.context.new_rvalue_from_struct(None, struct_type, values)
|
||||
self.context.new_struct_constructor(None, struct_type.as_type(), None, values)
|
||||
}
|
||||
|
||||
fn const_to_opt_uint(&self, _v: RValue<'gcc>) -> Option<u64> {
|
||||
|
|
|
@ -20,7 +20,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
pub fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> {
|
||||
if value.get_type() == self.bool_type.make_pointer() {
|
||||
if let Some(pointee) = typ.get_pointee() {
|
||||
if pointee.is_vector().is_some() {
|
||||
if pointee.dyncast_vector().is_some() {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
|
||||
impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
|
||||
fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) -> RValue<'gcc> {
|
||||
if let Some(global_value) = self.const_globals.borrow().get(&cv) {
|
||||
// TODO(antoyo): upgrade alignment.
|
||||
return *global_value;
|
||||
// TODO(antoyo): implement a proper rvalue comparison in libgccjit instead of doing the
|
||||
// following:
|
||||
for (value, variable) in &*self.const_globals.borrow() {
|
||||
if format!("{:?}", value) == format!("{:?}", cv) {
|
||||
// TODO(antoyo): upgrade alignment.
|
||||
return *variable;
|
||||
}
|
||||
}
|
||||
let global_value = self.static_addr_of_mut(cv, align, kind);
|
||||
// TODO(antoyo): set global constant.
|
||||
|
@ -77,7 +81,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
|
|||
else {
|
||||
value
|
||||
};
|
||||
global.global_set_initializer_value(value);
|
||||
global.global_set_initializer_rvalue(value);
|
||||
|
||||
// As an optimization, all shared statics which do not have interior
|
||||
// mutability are placed into read-only memory.
|
||||
|
@ -176,7 +180,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
};
|
||||
// FIXME(antoyo): I think the name coming from generate_local_symbol_name() above cannot be used
|
||||
// globally.
|
||||
global.global_set_initializer_value(cv);
|
||||
global.global_set_initializer_rvalue(cv);
|
||||
// TODO(antoyo): set unnamed address.
|
||||
global.get_address(None)
|
||||
}
|
||||
|
@ -371,7 +375,7 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
|
|||
real_name.push_str(&sym);
|
||||
let global2 = cx.define_global(&real_name, llty, is_tls, attrs.link_section);
|
||||
// TODO(antoyo): set linkage.
|
||||
global2.global_set_initializer_value(global1.get_address(None));
|
||||
global2.global_set_initializer_rvalue(global1.get_address(None));
|
||||
// TODO(antoyo): use global_set_initializer() when it will work.
|
||||
global2
|
||||
}
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
|
||||
use gccjit::{
|
||||
Block,
|
||||
Context,
|
||||
CType,
|
||||
Function,
|
||||
FunctionType,
|
||||
LValue,
|
||||
RValue,
|
||||
Struct,
|
||||
Type,
|
||||
};
|
||||
use gccjit::{Block, CType, Context, Function, FunctionType, LValue, RValue, Struct, Type};
|
||||
use rustc_codegen_ssa::base::wants_msvc_seh;
|
||||
use rustc_codegen_ssa::traits::{
|
||||
BackendTypes,
|
||||
|
|
|
@ -526,7 +526,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
|
||||
let value =
|
||||
if result_type.is_signed(self.cx) {
|
||||
self.context.new_bitcast(None, value, typ)
|
||||
self.context.new_cast(None, value, typ)
|
||||
}
|
||||
else {
|
||||
value
|
||||
|
@ -690,7 +690,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
},
|
||||
};
|
||||
|
||||
self.context.new_bitcast(None, result, result_type)
|
||||
self.context.new_cast(None, result, result_type)
|
||||
}
|
||||
|
||||
fn count_leading_zeroes(&self, width: u64, arg: RValue<'gcc>) -> RValue<'gcc> {
|
||||
|
@ -741,6 +741,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let not_low = self.context.new_unary_op(None, UnaryOp::LogicalNegate, self.u64_type, low);
|
||||
let not_low_and_not_high = not_low & not_high;
|
||||
let index = not_high + not_low_and_not_high;
|
||||
// NOTE: the following cast is necessary to avoid a GIMPLE verification failure in
|
||||
// gcc.
|
||||
// TODO(antoyo): do the correct verification in libgccjit to avoid an error at the
|
||||
// compilation stage.
|
||||
let index = self.context.new_cast(None, index, self.i32_type);
|
||||
|
||||
let res = self.context.new_array_access(None, result, index);
|
||||
|
||||
|
@ -764,7 +769,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let arg =
|
||||
if result_type.is_signed(self.cx) {
|
||||
let new_type = result_type.to_unsigned(self.cx);
|
||||
self.context.new_bitcast(None, arg, new_type)
|
||||
self.context.new_cast(None, arg, new_type)
|
||||
}
|
||||
else {
|
||||
arg
|
||||
|
@ -816,10 +821,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let not_high = self.context.new_unary_op(None, UnaryOp::LogicalNegate, self.u64_type, high);
|
||||
let not_low_and_not_high = not_low & not_high;
|
||||
let index = not_low + not_low_and_not_high;
|
||||
// NOTE: the following cast is necessary to avoid a GIMPLE verification failure in
|
||||
// gcc.
|
||||
// TODO(antoyo): do the correct verification in libgccjit to avoid an error at the
|
||||
// compilation stage.
|
||||
let index = self.context.new_cast(None, index, self.i32_type);
|
||||
|
||||
let res = self.context.new_array_access(None, result, index);
|
||||
|
||||
return self.context.new_bitcast(None, res, result_type);
|
||||
return self.context.new_cast(None, res, result_type);
|
||||
}
|
||||
else {
|
||||
unimplemented!("count_trailing_zeroes for {:?}", arg_type);
|
||||
|
@ -833,7 +843,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
arg
|
||||
};
|
||||
let res = self.context.new_call(None, count_trailing_zeroes, &[arg]);
|
||||
self.context.new_bitcast(None, res, result_type)
|
||||
self.context.new_cast(None, res, result_type)
|
||||
}
|
||||
|
||||
fn int_width(&self, typ: Type<'gcc>) -> i64 {
|
||||
|
@ -847,7 +857,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
|
||||
let value =
|
||||
if result_type.is_signed(self.cx) {
|
||||
self.context.new_bitcast(None, value, value_type)
|
||||
self.context.new_cast(None, value, value_type)
|
||||
}
|
||||
else {
|
||||
value
|
||||
|
@ -863,7 +873,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let low = self.context.new_cast(None, value, self.cx.ulonglong_type);
|
||||
let low = self.context.new_call(None, popcount, &[low]);
|
||||
let res = high + low;
|
||||
return self.context.new_bitcast(None, res, result_type);
|
||||
return self.context.new_cast(None, res, result_type);
|
||||
}
|
||||
|
||||
// First step.
|
||||
|
@ -888,7 +898,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let value = left + right;
|
||||
|
||||
if value_type.is_u8(&self.cx) {
|
||||
return self.context.new_bitcast(None, value, result_type);
|
||||
return self.context.new_cast(None, value, result_type);
|
||||
}
|
||||
|
||||
// Fourth step.
|
||||
|
@ -899,7 +909,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let value = left + right;
|
||||
|
||||
if value_type.is_u16(&self.cx) {
|
||||
return self.context.new_bitcast(None, value, result_type);
|
||||
return self.context.new_cast(None, value, result_type);
|
||||
}
|
||||
|
||||
// Fifth step.
|
||||
|
@ -910,7 +920,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let value = left + right;
|
||||
|
||||
if value_type.is_u32(&self.cx) {
|
||||
return self.context.new_bitcast(None, value, result_type);
|
||||
return self.context.new_cast(None, value, result_type);
|
||||
}
|
||||
|
||||
// Sixth step.
|
||||
|
@ -920,7 +930,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||
let right = shifted & mask;
|
||||
let value = left + right;
|
||||
|
||||
self.context.new_bitcast(None, value, result_type)
|
||||
self.context.new_cast(None, value, result_type)
|
||||
}
|
||||
|
||||
// Algorithm from: https://blog.regehr.org/archives/1063
|
||||
|
|
|
@ -91,8 +91,6 @@ impl CodegenBackend for GccCodegenBackend {
|
|||
let target_cpu = target_cpu(tcx.sess);
|
||||
let res = codegen_crate(self.clone(), tcx, target_cpu.to_string(), metadata, need_metadata_module);
|
||||
|
||||
rustc_symbol_mangling::test::report_symbol_names(tcx);
|
||||
|
||||
Box::new(res)
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
|||
if typ.is_integral() {
|
||||
TypeKind::Integer
|
||||
}
|
||||
else if typ.is_vector().is_some() {
|
||||
else if typ.dyncast_vector().is_some() {
|
||||
TypeKind::Vector
|
||||
}
|
||||
else {
|
||||
|
@ -141,10 +141,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
|||
}
|
||||
|
||||
fn element_type(&self, ty: Type<'gcc>) -> Type<'gcc> {
|
||||
if let Some(typ) = ty.is_array() {
|
||||
if let Some(typ) = ty.dyncast_array() {
|
||||
typ
|
||||
}
|
||||
else if let Some(vector_type) = ty.is_vector() {
|
||||
else if let Some(vector_type) = ty.dyncast_vector() {
|
||||
vector_type.get_element_type()
|
||||
}
|
||||
else if let Some(typ) = ty.get_pointee() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue