diff options
| author | Alexis Bourget <alexis.bourget@gmail.com> | 2020-07-19 22:15:44 +0200 | 
|---|---|---|
| committer | Alexis Bourget <alexis.bourget@gmail.com> | 2020-07-19 22:15:44 +0200 | 
| commit | 471dd52d7710dcad5fec0cd731b836b02ba4a8f4 (patch) | |
| tree | 4f7a1b7fcf01c8fb5c255a5af32b3906b44d38fa /src/librustc_codegen_llvm/llvm | |
| parent | e88220f86749d88e53c5dbaa421dcaba1889f86c (diff) | |
| parent | d7f94516345a36ddfcd68cbdf1df835d356795c3 (diff) | |
| download | rust-471dd52d7710dcad5fec0cd731b836b02ba4a8f4.tar.gz rust-471dd52d7710dcad5fec0cd731b836b02ba4a8f4.zip | |
Fix merge conflict with recent PR
Diffstat (limited to 'src/librustc_codegen_llvm/llvm')
| -rw-r--r-- | src/librustc_codegen_llvm/llvm/ffi.rs | 66 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/llvm/mod.rs | 44 | 
2 files changed, 108 insertions, 2 deletions
| diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index 64f5e103f0b..9784beaa079 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1,6 +1,8 @@ #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] +use super::coverageinfo::{SmallVectorCounterExpression, SmallVectorCounterMappingRegion}; + use super::debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DINameSpace, DISPFlags, DIScope, @@ -650,6 +652,16 @@ pub struct Linker<'a>(InvariantOpaque<'a>); pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void); pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint); +pub mod coverageinfo { + use super::InvariantOpaque; + + #[repr(C)] + pub struct SmallVectorCounterExpression<'a>(InvariantOpaque<'a>); + + #[repr(C)] + pub struct SmallVectorCounterMappingRegion<'a>(InvariantOpaque<'a>); +} + pub mod debuginfo { use super::{InvariantOpaque, Metadata}; use bitflags::bitflags; @@ -1365,7 +1377,7 @@ extern "C" { // Miscellaneous instructions pub fn LLVMBuildPhi(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value; - pub fn LLVMRustGetInstrprofIncrementIntrinsic(M: &Module) -> &'a Value; + pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &'a Value; pub fn LLVMRustBuildCall( B: &Builder<'a>, Fn: &'a Value, @@ -1633,6 +1645,58 @@ extern "C" { ConstraintsLen: size_t, ) -> bool; + pub fn LLVMRustCoverageSmallVectorCounterExpressionCreate() + -> &'a mut SmallVectorCounterExpression<'a>; + pub fn LLVMRustCoverageSmallVectorCounterExpressionDispose( + Container: &'a mut SmallVectorCounterExpression<'a>, + ); + pub fn LLVMRustCoverageSmallVectorCounterExpressionAdd( + Container: &mut SmallVectorCounterExpression<'a>, + Kind: rustc_codegen_ssa::coverageinfo::CounterOp, + LeftIndex: c_uint, + RightIndex: c_uint, + ); + + pub fn LLVMRustCoverageSmallVectorCounterMappingRegionCreate() + -> &'a mut SmallVectorCounterMappingRegion<'a>; + pub fn LLVMRustCoverageSmallVectorCounterMappingRegionDispose( + Container: &'a mut SmallVectorCounterMappingRegion<'a>, + ); + pub fn LLVMRustCoverageSmallVectorCounterMappingRegionAdd( + Container: &mut SmallVectorCounterMappingRegion<'a>, + Index: c_uint, + FileID: c_uint, + LineStart: c_uint, + ColumnStart: c_uint, + LineEnd: c_uint, + ColumnEnd: c_uint, + ); + + #[allow(improper_ctypes)] + pub fn LLVMRustCoverageWriteFilenamesSectionToBuffer( + Filenames: *const *const c_char, + FilenamesLen: size_t, + BufferOut: &RustString, + ); + + #[allow(improper_ctypes)] + pub fn LLVMRustCoverageWriteMappingToBuffer( + VirtualFileMappingIDs: *const c_uint, + NumVirtualFileMappingIDs: c_uint, + Expressions: *const SmallVectorCounterExpression<'_>, + MappingRegions: *const SmallVectorCounterMappingRegion<'_>, + BufferOut: &RustString, + ); + + pub fn LLVMRustCoverageComputeHash(Name: *const c_char) -> u64; + + #[allow(improper_ctypes)] + pub fn LLVMRustCoverageWriteSectionNameToString(M: &Module, Str: &RustString); + + #[allow(improper_ctypes)] + pub fn LLVMRustCoverageWriteMappingVarNameToString(Str: &RustString); + + pub fn LLVMRustCoverageMappingVersion() -> u32; pub fn LLVMRustDebugMetadataVersion() -> u32; pub fn LLVMRustVersionMajor() -> u32; pub fn LLVMRustVersionMinor() -> u32; diff --git a/src/librustc_codegen_llvm/llvm/mod.rs b/src/librustc_codegen_llvm/llvm/mod.rs index b7f1e1789c9..c09e3659f80 100644 --- a/src/librustc_codegen_llvm/llvm/mod.rs +++ b/src/librustc_codegen_llvm/llvm/mod.rs @@ -12,7 +12,7 @@ use libc::c_uint; use rustc_data_structures::small_c_str::SmallCStr; use rustc_llvm::RustString; use std::cell::RefCell; -use std::ffi::CStr; +use std::ffi::{CStr, CString}; use std::str::FromStr; use std::string::FromUtf8Error; @@ -189,6 +189,42 @@ pub fn mk_section_iter(llof: &ffi::ObjectFile) -> SectionIter<'_> { unsafe { SectionIter { llsi: LLVMGetSections(llof) } } } +pub fn set_section(llglobal: &Value, section_name: &str) { + let section_name_cstr = CString::new(section_name).expect("unexpected CString error"); + unsafe { + LLVMSetSection(llglobal, section_name_cstr.as_ptr()); + } +} + +pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name: &str) -> &'a Value { + let name_cstr = CString::new(name).expect("unexpected CString error"); + unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) } +} + +pub fn set_initializer(llglobal: &Value, constant_val: &Value) { + unsafe { + LLVMSetInitializer(llglobal, constant_val); + } +} + +pub fn set_global_constant(llglobal: &Value, is_constant: bool) { + unsafe { + LLVMSetGlobalConstant(llglobal, if is_constant { ffi::True } else { ffi::False }); + } +} + +pub fn set_linkage(llglobal: &Value, linkage: Linkage) { + unsafe { + LLVMRustSetLinkage(llglobal, linkage); + } +} + +pub fn set_alignment(llglobal: &Value, bytes: usize) { + unsafe { + ffi::LLVMSetAlignment(llglobal, bytes as c_uint); + } +} + /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun. pub fn get_param(llfn: &Value, index: c_uint) -> &Value { unsafe { @@ -225,6 +261,12 @@ pub fn build_string(f: impl FnOnce(&RustString)) -> Result<String, FromUtf8Error String::from_utf8(sr.bytes.into_inner()) } +pub fn build_byte_buffer(f: impl FnOnce(&RustString)) -> Vec<u8> { + let sr = RustString { bytes: RefCell::new(Vec::new()) }; + f(&sr); + sr.bytes.into_inner() +} + pub fn twine_to_string(tr: &Twine) -> String { unsafe { build_string(|s| LLVMRustWriteTwineToString(tr, s)).expect("got a non-UTF8 Twine from LLVM") | 
