#include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h"
+#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm-c/Transforms/PassManagerBuilder.h"
#include "llvm/Transforms/Instrumentation.h"
timeTraceProfilerCleanup();
}
-enum class LLVMRustPassKind {
- Other,
- Function,
- Module,
-};
-
-static LLVMRustPassKind toRust(PassKind Kind) {
- switch (Kind) {
- case PT_Function:
- return LLVMRustPassKind::Function;
- case PT_Module:
- return LLVMRustPassKind::Module;
- default:
- return LLVMRustPassKind::Other;
- }
-}
-
extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
#if LLVM_VERSION_LT(15, 0)
StringRef SR(PassName);
#endif
}
-extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
- assert(RustPass);
- Pass *Pass = unwrap(RustPass);
- return toRust(Pass->getPassKind());
-}
-
extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
#if LLVM_VERSION_LT(15, 0)
assert(RustPass);
if (SanitizerOptions->SanitizeAddress) {
OptimizerLastEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
+#if LLVM_VERSION_LT(15, 0)
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
+#endif
#if LLVM_VERSION_GE(14, 0)
AddressSanitizerOptions opts = AddressSanitizerOptions{
/*CompileKernel=*/false,
return true;
}
-extern "C" typedef void (*LLVMRustModuleNameCallback)(void*, // payload
- const char*, // importing module name
- const char*); // imported module name
-
-// Calls `module_name_callback` for each module import done by ThinLTO.
-// The callback is provided with regular null-terminated C strings.
-extern "C" void
-LLVMRustGetThinLTOModules(const LLVMRustThinLTOData *data,
- LLVMRustModuleNameCallback module_name_callback,
- void* callback_payload) {
- for (const auto& importing_module : data->ImportLists) {
- const std::string importing_module_id = importing_module.getKey().str();
- const auto& imports = importing_module.getValue();
- for (const auto& imported_module : imports) {
- const std::string imported_module_id = imported_module.getKey().str();
- module_name_callback(callback_payload,
- importing_module_id.c_str(),
- imported_module_id.c_str());
- }
- }
-}
-
// This struct and various functions are sort of a hack right now, but the
// problem is that we've got in-memory LLVM modules after we generate and
// optimize all codegen-units for one compilation in rustc. To be compatible
};
extern "C" LLVMRustThinLTOBuffer*
-LLVMRustThinLTOBufferCreate(LLVMModuleRef M) {
+LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
auto Ret = std::make_unique<LLVMRustThinLTOBuffer>();
{
raw_string_ostream OS(Ret->data);
{
legacy::PassManager PM;
- PM.add(createWriteThinLTOBitcodePass(OS));
+ if (is_thin) {
+ PM.add(createWriteThinLTOBitcodePass(OS));
+ } else {
+ PM.add(createBitcodeWriterPass(OS));
+ }
PM.run(*unwrap(M));
}
}
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
// the comment in `back/lto.rs` for why this exists.
extern "C" void
-LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
+LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
DICompileUnit **A,
DICompileUnit **B) {
Module *M = unwrap(Mod);
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
// the comment in `back/lto.rs` for why this exists.
extern "C" void
-LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
+LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
Module *M = unwrap(Mod);
// If the original source module didn't have a `DICompileUnit` then try to