Skip to content

Commit d992090

Browse files
Revert "Provide a way of accessing the ThinLTO module import map in rustc."
This reverts commit 9df56ca.
1 parent 5c0110f commit d992090

File tree

3 files changed

+1
-132
lines changed

3 files changed

+1
-132
lines changed

src/librustc_codegen_llvm/back/lto.rs

+1-68
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ use rustc::hir::def_id::LOCAL_CRATE;
2020
use rustc::middle::exported_symbols::SymbolExportLevel;
2121
use rustc::session::config::{self, Lto};
2222
use rustc::util::common::time_ext;
23-
use rustc_data_structures::fx::FxHashMap;
2423
use time_graph::Timeline;
2524
use {ModuleCodegen, ModuleLlvm, ModuleKind, ModuleSource};
2625

2726
use libc;
2827

29-
use std::ffi::{CString, CStr};
28+
use std::ffi::CString;
3029
use std::ptr;
3130
use std::slice;
3231
use std::sync::Arc;
@@ -777,69 +776,3 @@ impl ThinModule {
777776
Ok(module)
778777
}
779778
}
780-
781-
782-
#[derive(Debug)]
783-
pub struct ThinLTOImports {
784-
// key = llvm name of importing module, value = list of modules it imports from
785-
imports: FxHashMap<String, Vec<String>>,
786-
}
787-
788-
impl ThinLTOImports {
789-
790-
/// Load the ThinLTO import map from ThinLTOData.
791-
unsafe fn from_thin_lto_data(data: *const llvm::ThinLTOData) -> ThinLTOImports {
792-
let raw_data: *const llvm::ThinLTOModuleImports =
793-
llvm::LLVMRustGetThinLTOModuleImports(data);
794-
795-
assert!(!raw_data.is_null());
796-
797-
let mut imports = FxHashMap();
798-
let mut module_ptr = raw_data;
799-
let mut module_index = 0;
800-
801-
loop {
802-
let mut entry_ptr: *const llvm::ThinLTOModuleName = *module_ptr;
803-
804-
if entry_ptr.is_null() {
805-
break;
806-
}
807-
808-
let importing_module_name = CStr::from_ptr(*entry_ptr)
809-
.to_str()
810-
.expect("Non-utf8 LLVM module name encountered")
811-
.to_owned();
812-
813-
entry_ptr = entry_ptr.offset(1);
814-
815-
let mut imported_modules = vec![];
816-
817-
loop {
818-
let imported_module_name = *entry_ptr;
819-
820-
if imported_module_name.is_null() {
821-
break
822-
}
823-
824-
let imported_module_name = CStr::from_ptr(imported_module_name)
825-
.to_str()
826-
.expect("Non-utf8 LLVM module name encountered")
827-
.to_owned();
828-
829-
imported_modules.push(imported_module_name);
830-
entry_ptr = entry_ptr.offset(1);
831-
}
832-
833-
imports.insert(importing_module_name, imported_modules);
834-
835-
module_ptr = module_ptr.offset(1);
836-
module_index += 1;
837-
}
838-
839-
assert_eq!(module_index, imports.len());
840-
841-
ThinLTOImports {
842-
imports
843-
}
844-
}
845-
}

src/librustc_llvm/ffi.rs

-8
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,6 @@ pub enum ThinLTOData {}
351351
/// LLVMRustThinLTOBuffer
352352
pub enum ThinLTOBuffer {}
353353

354-
/// LLVMRustThinLTOModuleName
355-
pub type ThinLTOModuleName = *const c_char;
356-
/// LLVMRustThinLTOModuleImports
357-
pub type ThinLTOModuleImports = *const ThinLTOModuleName;
358-
359354
/// LLVMRustThinLTOModule
360355
#[repr(C)]
361356
pub struct ThinLTOModule {
@@ -1784,9 +1779,6 @@ extern "C" {
17841779
Data: *const ThinLTOData,
17851780
Module: ModuleRef,
17861781
) -> bool;
1787-
pub fn LLVMRustGetThinLTOModuleImports(
1788-
Data: *const ThinLTOData,
1789-
) -> *const ThinLTOModuleImports;
17901782
pub fn LLVMRustFreeThinLTOData(Data: *mut ThinLTOData);
17911783
pub fn LLVMRustParseBitcodeForThinLTO(
17921784
Context: ContextRef,

src/rustllvm/PassWrapper.cpp

-56
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,6 @@ LLVMRustPGOAvailable() {
798798
#endif
799799
}
800800

801-
// We encode the ThinLTO module import map as a nested null-terminated list to
802-
// get it into Rust.
803-
typedef const char* LLVMRustThinLTOModuleName;
804-
typedef LLVMRustThinLTOModuleName* LLVMRustThinLTOModuleImports;
805-
806801
#if LLVM_VERSION_GE(4, 0)
807802

808803
// Here you'll find an implementation of ThinLTO as used by the Rust compiler
@@ -1104,52 +1099,6 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
11041099
return true;
11051100
}
11061101

1107-
/// Converts the LLVMRustThinLTOData::ImportLists map into a nested list. The
1108-
/// first level is a null-terminated array with an entry for each module. Each
1109-
/// entry is a pointer that points to a null-termined array of module names. The
1110-
/// first entry is always the name of the *importing* module, the following
1111-
/// entries are the names of the modules it imports from. Each module name is
1112-
/// a regular C string.
1113-
extern "C" LLVMRustThinLTOModuleImports*
1114-
LLVMRustGetThinLTOModuleImports(const LLVMRustThinLTOData *Data) {
1115-
// Allocate number of module +1. This is a null-terminated array.
1116-
LLVMRustThinLTOModuleImports* thinLTOModuleImports =
1117-
new LLVMRustThinLTOModuleImports[Data->ImportLists.size() + 1];
1118-
size_t module_index = 0;
1119-
1120-
for (const auto & module : Data->ImportLists) {
1121-
StringRef module_id = module.getKey();
1122-
const auto& imports = module.getValue();
1123-
1124-
// Allocate number of imported module + 2, one extra for the name of the
1125-
// importing module and another one for null-termination.
1126-
LLVMRustThinLTOModuleImports imports_array =
1127-
new LLVMRustThinLTOModuleName[imports.size() + 2];
1128-
1129-
// The first value is always the name of the *importing* module.
1130-
imports_array[0] = strndup(module_id.data(), module_id.size());
1131-
1132-
size_t imports_array_index = 1;
1133-
for (const auto imported_module_id : imports.keys()) {
1134-
// The following values are the names of the imported modules.
1135-
imports_array[imports_array_index] = strndup(imported_module_id.data(),
1136-
imported_module_id.size());
1137-
imports_array_index += 1;
1138-
}
1139-
1140-
assert(imports_array_index == imports.size() + 1);
1141-
imports_array[imports_array_index] = nullptr;
1142-
1143-
thinLTOModuleImports[module_index] = imports_array;
1144-
module_index += 1;
1145-
}
1146-
1147-
assert(module_index == Data->ImportLists.size());
1148-
thinLTOModuleImports[module_index] = nullptr;
1149-
1150-
return thinLTOModuleImports;
1151-
}
1152-
11531102
// This struct and various functions are sort of a hack right now, but the
11541103
// problem is that we've got in-memory LLVM modules after we generate and
11551104
// optimize all codegen-units for one compilation in rustc. To be compatible
@@ -1331,11 +1280,6 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
13311280
report_fatal_error("ThinLTO not available");
13321281
}
13331282

1334-
extern "C" LLVMRustThinLTOModuleImports
1335-
LLVMRustGetLLVMRustThinLTOModuleImports(const LLVMRustThinLTOData *Data) {
1336-
report_fatal_error("ThinLTO not available");
1337-
}
1338-
13391283
extern "C" void
13401284
LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
13411285
report_fatal_error("ThinLTO not available");

0 commit comments

Comments
 (0)