Repository navigation
Use runCodeGen Abstraction for new LLVM #163672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
boomanaiden154
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
boomanaiden154:rustc-newpm-new-abstraction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,16 @@ | |
| #include "llvm/MC/TargetRegistry.h" | ||
| #include "llvm/Object/ObjectFile.h" | ||
| #include "llvm/Passes/PassBuilder.h" | ||
| #if LLVM_VERSION_GE(24, 0) | ||
| #include "llvm/Passes/RunCodeGen.h" | ||
| #endif | ||
| #include "llvm/Passes/StandardInstrumentations.h" | ||
| #include "llvm/Plugins/PassPlugin.h" | ||
| #include "llvm/Support/CBindingWrapping.h" | ||
| #include "llvm/Support/FileSystem.h" | ||
| #include "llvm/Support/Program.h" | ||
| #include "llvm/Support/TimeProfiler.h" | ||
| #include "llvm/Support/ToolOutputFile.h" | ||
| #include "llvm/Support/VirtualFileSystem.h" | ||
| #include "llvm/Target/TargetMachine.h" | ||
| #include "llvm/TargetParser/Host.h" | ||
|
|
@@ -470,30 +474,6 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMModuleRef M, | |
| const char *Path, const char *DwoPath, | ||
| LLVMRustFileType RustFileType, bool VerifyIR, | ||
| bool DisableSimplifyLibCalls) { | ||
| std::unique_ptr<llvm::legacy::PassManager> PM = | ||
| std::make_unique<llvm::legacy::PassManager>(); | ||
|
|
||
| PM->add(createTargetTransformInfoWrapperPass( | ||
| unwrap(Target)->getTargetIRAnalysis())); | ||
|
|
||
| auto TargetTriple = Triple(unwrap(M)->getTargetTriple()); | ||
| TargetOptions *Options = &unwrap(Target)->Options; | ||
| auto TLII = TargetLibraryInfoImpl(TargetTriple); | ||
| if (DisableSimplifyLibCalls) | ||
| TLII.disableAllFunctions(); | ||
| PM->add(new TargetLibraryInfoWrapperPass(TLII)); | ||
| #if LLVM_VERSION_GE(24, 0) | ||
| // LLVM 24 removed TargetOptions::EABIVersion and ExceptionModel; the EABI | ||
| // version and exception model are now derived from the target triple and | ||
| // module flags respectively instead. | ||
| PM->add(new RuntimeLibraryInfoWrapper(Options->MCOptions.ABIName, | ||
| Options->VecLib)); | ||
| #else | ||
| PM->add(new RuntimeLibraryInfoWrapper( | ||
| TargetTriple, Options->ExceptionModel, Options->FloatABIType, | ||
| Options->EABIVersion, Options->MCOptions.ABIName, Options->VecLib)); | ||
| #endif | ||
|
|
||
| auto FileType = fromRust(RustFileType); | ||
|
|
||
| std::string ErrorInfo; | ||
|
|
@@ -506,29 +486,54 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMModuleRef M, | |
| return LLVMRustResult::Failure; | ||
| } | ||
|
|
||
| // TargetMachine::addPassesToEmitFile stores pointers to the output streams | ||
| // in a couple of places inside of the object. Explicitly delete the PM after | ||
| // we call run() to avoid dangling references. | ||
| std::unique_ptr<llvm::ToolOutputFile> DOS; | ||
| auto BOS = buffer_ostream(OS); | ||
| if (DwoPath) { | ||
| auto DOS = raw_fd_ostream(DwoPath, EC, sys::fs::OF_None); | ||
| EC.clear(); | ||
| if (EC) | ||
| DOS = std::make_unique<llvm::ToolOutputFile>(DwoPath, EC, | ||
| llvm::sys::fs::OF_None); | ||
| if (EC) { | ||
| ErrorInfo = EC.message(); | ||
| DOS.reset(); | ||
| } | ||
| if (ErrorInfo != "") { | ||
| LLVMRustSetLastError(ErrorInfo.c_str()); | ||
| return LLVMRustResult::Failure; | ||
| } | ||
| auto DBOS = buffer_ostream(DOS); | ||
| unwrap(Target)->addPassesToEmitFile(*PM, BOS, &DBOS, FileType, !VerifyIR); | ||
| PM->run(*unwrap(M)); | ||
| PM.reset(); | ||
| } else { | ||
| unwrap(Target)->addPassesToEmitFile(*PM, BOS, nullptr, FileType, !VerifyIR); | ||
| PM->run(*unwrap(M)); | ||
| PM.reset(); | ||
| DOS->keep(); | ||
| } | ||
|
|
||
| #if LLVM_VERSION_GE(24, 0) | ||
| Error CodeGenError = | ||
| runCodeGenPipeline(*unwrap(Target), *unwrap(M), BOS, DOS, FileType, false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs adjustment for llvm/llvm-project#230349. |
||
| !VerifyIR, DisableSimplifyLibCalls); | ||
| #else | ||
| std::unique_ptr<llvm::legacy::PassManager> PM = | ||
| std::make_unique<llvm::legacy::PassManager>(); | ||
|
|
||
| PM->add(createTargetTransformInfoWrapperPass( | ||
| unwrap(Target)->getTargetIRAnalysis())); | ||
|
|
||
| auto TargetTriple = Triple(unwrap(M)->getTargetTriple()); | ||
| TargetOptions *Options = &unwrap(Target)->Options; | ||
| auto TLII = TargetLibraryInfoImpl(TargetTriple); | ||
| if (DisableSimplifyLibCalls) | ||
| TLII.disableAllFunctions(); | ||
| PM->add(new TargetLibraryInfoWrapperPass(TLII)); | ||
| #if LLVM_VERSION_GE(22, 0) | ||
| PM->add(new RuntimeLibraryInfoWrapper( | ||
| TargetTriple, Options->ExceptionModel, Options->FloatABIType, | ||
| Options->EABIVersion, Options->MCOptions.ABIName, Options->VecLib)); | ||
| #endif | ||
|
|
||
| // TargetMachine::addPassesToEmitFile stores pointers to the output streams | ||
| // in a couple of places inside of the object. Explicitly delete the PM after | ||
| // we call run() to avoid dangling references. | ||
| unwrap(Target)->addPassesToEmitFile(*PM, BOS, DOS ? &DOS->os() : nullptr, | ||
| FileType, !VerifyIR); | ||
| PM->run(*unwrap(M)); | ||
| PM.reset(); | ||
| #endif | ||
|
|
||
| return LLVMRustResult::Success; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not sure I understand the unique_ptr here. Can this be just std::optional?