1
Fork 0

Removing LLVM content from CommonMethods -> ConstMethods

This commit is contained in:
Denis Merigoux 2018-09-06 14:44:51 -07:00 committed by Eduard-Mihai Burtescu
parent e224f063e8
commit a1d0d4f943
25 changed files with 55 additions and 124 deletions

View file

@ -18,7 +18,7 @@ use type_::Type;
use type_of::{LayoutLlvmExt, PointerKind};
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TyLayout, Abi as LayoutAbi};
use rustc::ty::{self, Ty};

View file

@ -15,7 +15,7 @@ use builder::Builder;
use value::Value;
use rustc::hir;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use mir::place::PlaceRef;
use mir::operand::OperandValue;

View file

@ -49,7 +49,6 @@ use context::{is_pie_binary, get_reloc_model};
use common;
use jobserver::{Client, Acquired};
use rustc_demangle;
use value::Value;
use std::marker::PhantomData;
use std::any::Any;
@ -428,24 +427,6 @@ impl CodegenContext<'ll> {
}
}
impl CodegenContext<'ll> {
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
common::val_ty(v)
}
fn const_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
common::const_bytes_in_context(llcx, bytes)
}
pub fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
unsafe {
llvm::LLVMPointerType(ty, 0)
}
}
}
pub struct DiagnosticHandlers<'a> {
data: *mut (&'a CodegenContext<'a>, &'a Handler),
llcx: &'a llvm::Context,
@ -907,10 +888,10 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext,
llcx: &llvm::Context,
llmod: &llvm::Module,
bitcode: Option<&[u8]>) {
let llconst = cgcx.const_bytes_in_context(llcx, bitcode.unwrap_or(&[]));
let llconst = common::bytes_in_context(llcx, bitcode.unwrap_or(&[]));
let llglobal = llvm::LLVMAddGlobal(
llmod,
cgcx.val_ty(llconst),
common::val_ty(llconst),
"rustc.embedded.module\0".as_ptr() as *const _,
);
llvm::LLVMSetInitializer(llglobal, llconst);
@ -927,10 +908,10 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext,
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
let llconst = cgcx.const_bytes_in_context(llcx, &[]);
let llconst = common::bytes_in_context(llcx, &[]);
let llglobal = llvm::LLVMAddGlobal(
llmod,
cgcx.val_ty(llconst),
common::val_ty(llconst),
"rustc.embedded.cmdline\0".as_ptr() as *const _,
);
llvm::LLVMSetInitializer(llglobal, llconst);
@ -2598,7 +2579,7 @@ fn create_msvc_imps(cgcx: &CodegenContext, llcx: &llvm::Context, llmod: &llvm::M
"\x01__imp_"
};
unsafe {
let i8p_ty = Type::i8p_llcx(cgcx, llcx);
let i8p_ty = Type::i8p_llcx(llcx);
let globals = base::iter_globals(llmod)
.filter(|&val| {
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage &&

View file

@ -54,7 +54,7 @@ use attributes;
use builder::{Builder, MemFlags};
use callee;
use rustc_mir::monomorphize::item::DefPathBasedNames;
use common::{IntPredicate, RealPredicate};
use common::{self, IntPredicate, RealPredicate};
use consts;
use context::CodegenCx;
use debuginfo;
@ -74,7 +74,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::indexed_vec::Idx;
use interfaces::{BuilderMethods, CommonMethods, CommonWriteMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use std::any::Any;
use std::cmp;
@ -649,12 +649,12 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
DeflateEncoder::new(&mut compressed, Compression::fast())
.write_all(&metadata.raw_data).unwrap();
let llmeta = llvm_module.const_bytes_in_context(metadata_llcx, &compressed);
let llconst = llvm_module.const_struct_in_context(metadata_llcx, &[llmeta], false);
let llmeta = common::bytes_in_context(metadata_llcx, &compressed);
let llconst = common::struct_in_context(metadata_llcx, &[llmeta], false);
let name = exported_symbols::metadata_symbol_name(tcx);
let buf = CString::new(name).unwrap();
let llglobal = unsafe {
llvm::LLVMAddGlobal(metadata_llmod, llvm_module.val_ty(llconst), buf.as_ptr())
llvm::LLVMAddGlobal(metadata_llmod, common::val_ty(llconst), buf.as_ptr())
};
unsafe {
llvm::LLVMSetInitializer(llglobal, llconst);

View file

@ -19,7 +19,7 @@ use rustc::ty::TyCtxt;
use rustc::ty::layout::{Align, Size};
use rustc::session::{config, Session};
use rustc_data_structures::small_c_str::SmallCStr;
use interfaces::{BuilderMethods, Backend, CommonMethods, CommonWriteMethods, TypeMethods};
use interfaces::{BuilderMethods, Backend, ConstMethods, TypeMethods};
use syntax;
use std::borrow::Cow;

View file

@ -22,7 +22,7 @@ use llvm;
use monomorphize::Instance;
use type_of::LayoutLlvmExt;
use value::Value;
use interfaces::CommonWriteMethods;
use interfaces::TypeMethods;
use rustc::hir::def_id::DefId;
use rustc::ty::{self, TypeFoldable};

View file

@ -24,7 +24,7 @@ use declare;
use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;
use interfaces::{Backend, CommonMethods, CommonWriteMethods, TypeMethods};
use interfaces::{Backend, ConstMethods, TypeMethods};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::layout::{HasDataLayout, LayoutOf};
@ -201,7 +201,7 @@ impl Backend for CodegenCx<'ll, 'tcx> {
type Context = &'ll llvm::Context;
}
impl<'ll, 'tcx: 'll> CommonMethods for CodegenCx<'ll, 'tcx> {
impl<'ll, 'tcx: 'll> ConstMethods for CodegenCx<'ll, 'tcx> {
// LLVM constant constructors.
fn const_null(&self, t: &'ll Type) -> &'ll Value {
@ -319,7 +319,7 @@ impl<'ll, 'tcx: 'll> CommonMethods for CodegenCx<'ll, 'tcx> {
elts: &[&'ll Value],
packed: bool
) -> &'ll Value {
&self.const_struct_in_context(&self.llcx, elts, packed)
struct_in_context(&self.llcx, elts, packed)
}
fn const_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
@ -335,7 +335,7 @@ impl<'ll, 'tcx: 'll> CommonMethods for CodegenCx<'ll, 'tcx> {
}
fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
&self.const_bytes_in_context(&self.llcx, bytes)
bytes_in_context(&self.llcx, bytes)
}
fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {
@ -406,14 +406,14 @@ pub fn val_ty(v: &'ll Value) -> &'ll Type {
}
}
pub fn const_bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
pub fn bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
unsafe {
let ptr = bytes.as_ptr() as *const c_char;
return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
}
}
pub fn const_struct_in_context(
pub fn struct_in_context(
llcx: &'a llvm::Context,
elts: &[&'a Value],
packed: bool,
@ -425,26 +425,6 @@ pub fn const_struct_in_context(
}
}
impl<'ll, 'tcx: 'll> CommonWriteMethods for CodegenCx<'ll, 'tcx> {
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
val_ty(v)
}
fn const_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
const_bytes_in_context(llcx, bytes)
}
fn const_struct_in_context(
&self,
llcx: &'a llvm::Context,
elts: &[&'a Value],
packed: bool,
) -> &'a Value {
const_struct_in_context(llcx, elts, packed)
}
}
#[inline]
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
((hi as u128) << 64) | (lo as u128)

View file

@ -24,7 +24,7 @@ use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;
use rustc::ty::{self, Ty};
use interfaces::{CommonWriteMethods, TypeMethods};
use interfaces::TypeMethods;
use rustc::ty::layout::{Align, LayoutOf};

View file

@ -17,7 +17,7 @@ use builder::Builder;
use declare;
use rustc::session::config::DebugInfo;
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use syntax::attr;

View file

@ -18,7 +18,7 @@ use super::namespace::mangled_name_of_instance;
use super::type_names::compute_debuginfo_type_name;
use super::{CrateDebugContext};
use abi;
use interfaces::CommonMethods;
use interfaces::ConstMethods;
use value::Value;
use llvm;

View file

@ -20,7 +20,7 @@ use meth;
use rustc::ty::layout::LayoutOf;
use rustc::ty::{self, Ty};
use value::Value;
use interfaces::{BuilderMethods, CommonMethods};
use interfaces::{BuilderMethods, ConstMethods};
pub fn size_and_align_of_dst(
bx: &Builder<'_, 'll, 'tcx>,

View file

@ -13,7 +13,7 @@ use std::fmt::Debug;
pub trait Backend {
type Value: Debug + PartialEq;
type BasicBlock;
type Type : Debug + PartialEq;
type Type: Debug + PartialEq;
type TypeKind;
type Context;
}

View file

@ -11,7 +11,7 @@
use super::Backend;
use syntax::symbol::LocalInternedString;
pub trait CommonMethods: Backend + CommonWriteMethods {
pub trait ConstMethods: Backend {
// Constant constructors
fn const_null(&self, t: Self::Type) -> Self::Value;
fn const_undef(&self, t: Self::Type) -> Self::Value;
@ -52,14 +52,3 @@ pub trait CommonMethods: Backend + CommonWriteMethods {
fn is_const_integral(&self, v: Self::Value) -> bool;
fn is_const_real(&self, v: Self::Value) -> bool;
}
pub trait CommonWriteMethods: Backend {
fn val_ty(&self, v: Self::Value) -> Self::Type;
fn const_bytes_in_context(&self, llcx: Self::Context, bytes: &[u8]) -> Self::Value;
fn const_struct_in_context(
&self,
llcx: Self::Context,
elts: &[Self::Value],
packed: bool,
) -> Self::Value;
}

View file

@ -10,10 +10,10 @@
mod builder;
mod backend;
mod common;
mod consts;
mod type_;
pub use self::builder::BuilderMethods;
pub use self::backend::Backend;
pub use self::common::{CommonMethods, CommonWriteMethods};
pub use self::consts::ConstMethods;
pub use self::type_::TypeMethods;

View file

@ -10,7 +10,7 @@
use super::backend::Backend;
pub trait TypeMethods : Backend {
pub trait TypeMethods: Backend {
fn type_void(&self) -> Self::Type;
fn type_metadata(&self) -> Self::Type;
fn type_i1(&self) -> Self::Type;
@ -38,4 +38,6 @@ pub trait TypeMethods : Backend {
fn func_params_types(&self, ty: Self::Type) -> Vec<Self::Type>;
fn float_width(&self, ty: Self::Type) -> usize;
fn int_width(&self, ty: Self::Type) -> u64;
fn val_ty(&self, v: Self::Value) -> Self::Type;
}

View file

@ -32,7 +32,7 @@ use syntax::symbol::Symbol;
use builder::Builder;
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use rustc::session::Session;
use syntax_pos::Span;

View file

@ -68,9 +68,6 @@ extern crate tempfile;
extern crate memmap;
use back::bytecode::RLIB_BYTECODE_EXTENSION;
use interfaces::{Backend, CommonWriteMethods};
use value::Value;
use type_::Type;
pub use llvm_util::target_features;
use std::any::Any;
@ -326,14 +323,6 @@ struct ModuleLlvm<'ll> {
phantom: PhantomData<&'ll ()>
}
impl<'ll> Backend for ModuleLlvm<'ll> {
type Value = &'ll Value;
type BasicBlock = &'ll llvm::BasicBlock;
type Type = &'ll Type;
type TypeKind = llvm::TypeKind;
type Context = &'ll llvm::Context;
}
unsafe impl Send for ModuleLlvm<'ll> { }
unsafe impl Sync for ModuleLlvm<'ll> { }
@ -359,25 +348,6 @@ impl ModuleLlvm<'ll> {
}
}
impl CommonWriteMethods for ModuleLlvm<'ll> {
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
common::val_ty(v)
}
fn const_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
common::const_bytes_in_context(llcx, bytes)
}
fn const_struct_in_context(
&self,
llcx: &'a llvm::Context,
elts: &[&'a Value],
packed: bool,
) -> &'a Value {
common::const_struct_in_context(llcx, elts, packed)
}
}
impl Drop for ModuleLlvm<'ll> {
fn drop(&mut self) {
unsafe {

View file

@ -16,7 +16,7 @@ use consts;
use monomorphize;
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use rustc::ty::{self, Ty};
use rustc::ty::layout::HasDataLayout;

View file

@ -26,7 +26,7 @@ use type_of::LayoutLlvmExt;
use type_::Type;
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use syntax::symbol::Symbol;
use syntax_pos::Pos;

View file

@ -25,7 +25,7 @@ use type_::Type;
use syntax::ast::Mutability;
use syntax::source_map::Span;
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use super::super::callee;
use super::FunctionCx;

View file

@ -24,7 +24,7 @@ use debuginfo::{self, declare_local, VariableAccess, VariableKind, FunctionDebug
use monomorphize::Instance;
use abi::{ArgTypeExt, FnType, FnTypeExt, PassMode};
use value::Value;
use interfaces::{BuilderMethods, CommonMethods};
use interfaces::{BuilderMethods, ConstMethods};
use syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
use syntax::symbol::keywords;

View file

@ -20,7 +20,7 @@ use value::Value;
use type_of::LayoutLlvmExt;
use glue;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use std::fmt;

View file

@ -22,7 +22,7 @@ use value::Value;
use glue;
use mir::constant::const_alloc_to_llvm;
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};

View file

@ -26,7 +26,7 @@ use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;
use interfaces::{BuilderMethods, CommonMethods, CommonWriteMethods, TypeMethods};
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};

View file

@ -17,11 +17,12 @@ use llvm::{Bool, False, True, TypeKind};
use context::CodegenCx;
use interfaces::TypeMethods;
use value::Value;
use syntax::ast;
use rustc::ty::layout::{self, Align, Size};
use rustc_data_structures::small_c_str::SmallCStr;
use back::write;
use common;
use std::fmt;
@ -188,9 +189,7 @@ impl TypeMethods for CodegenCx<'ll, 'tcx> {
fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
assert_ne!(self.type_kind(ty), TypeKind::Function,
"don't call ptr_to on function types, use ptr_to_llvm_type on FnType instead");
unsafe {
llvm::LLVMPointerType(ty, 0)
}
ty.ptr_to()
}
fn element_type(&self, ty: &'ll Type) -> &'ll Type {
@ -216,7 +215,7 @@ impl TypeMethods for CodegenCx<'ll, 'tcx> {
}
}
fn float_width(&self, ty : &'ll Type) -> usize {
fn float_width(&self, ty: &'ll Type) -> usize {
match self.type_kind(ty) {
TypeKind::Float => 32,
TypeKind::Double => 64,
@ -232,6 +231,10 @@ impl TypeMethods for CodegenCx<'ll, 'tcx> {
llvm::LLVMGetIntTypeWidth(ty) as u64
}
}
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
common::val_ty(v)
}
}
impl Type {
@ -251,8 +254,14 @@ impl Type {
}
}
pub fn i8p_llcx(cx : &write::CodegenContext<'ll>, llcx: &'ll llvm::Context) -> &'ll Type {
cx.type_ptr_to(Type::i8_llcx(llcx))
pub fn i8p_llcx(llcx: &'ll llvm::Context) -> &'ll Type {
Type::i8_llcx(llcx).ptr_to()
}
fn ptr_to(&self) -> &Type {
unsafe {
llvm::LLVMPointerType(&self, 0)
}
}
}