-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Overhaul the TargetMachine and LLVMTargetMachine Classes #111234
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7841cf4
Refactored LLVMTargetMachine into CodeGenCommonTMImpl, and moved its
matinraayai dd7b8f3
Fixed any files that missed the LLVMTargetMachine migration.
matinraayai cad3040
clang format.
matinraayai 20fd18e
Added missing end of line.
matinraayai 5bda965
More clang format.
matinraayai 138ba34
CodeGen: Renamed CodeGenCommonTMImpl to CodeGenTargetMachineImpl. Lin…
matinraayai fa5a1e5
Clang format.
matinraayai 4182d09
Moved the LLVMTargetMachine::reset() to CodeGenTargetMachineImpl.
matinraayai 050f9d3
Fixed missing CodeGenTargetMachineImpl rename.
matinraayai d266e55
AMDGPUMCResourceInfo.cpp:
matinraayai 921a77d
Merge branch 'main' into merge-tm-llvmtm
matinraayai 2db3e64
Migrated new AArch test to the new TM.
matinraayai 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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//===-- CodeGenTargetMachineImpl.h ------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file This file describes the CodeGenTargetMachineImpl class, which | ||
/// implements a set of functionality used by \c TargetMachine classes in | ||
/// LLVM that make use of the target-independent code generator. | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CODEGEN_CODEGENTARGETMACHINEIMPL_H | ||
#define LLVM_CODEGEN_CODEGENTARGETMACHINEIMPL_H | ||
#include "llvm/Target/TargetMachine.h" | ||
|
||
namespace llvm { | ||
|
||
/// \brief implements a set of functionality in the \c TargetMachine class | ||
/// for targets that make use of the independent code generator (CodeGen) | ||
/// library. Must not be used directly in code unless to inherit its | ||
/// implementation. | ||
class CodeGenTargetMachineImpl : public TargetMachine { | ||
protected: // Can only create subclasses. | ||
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, | ||
const Triple &TT, StringRef CPU, StringRef FS, | ||
const TargetOptions &Options, Reloc::Model RM, | ||
CodeModel::Model CM, CodeGenOptLevel OL); | ||
|
||
void initAsmInfo(); | ||
|
||
/// Reset internal state. | ||
virtual void reset() {}; | ||
|
||
public: | ||
/// Get a TargetTransformInfo implementation for the target. | ||
/// | ||
/// The TTI returned uses the common code generator to answer queries about | ||
/// the IR. | ||
TargetTransformInfo getTargetTransformInfo(const Function &F) const override; | ||
|
||
/// Create a pass configuration object to be used by addPassToEmitX methods | ||
/// for generating a pipeline of CodeGen passes. | ||
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM) override; | ||
|
||
/// Add passes to the specified pass manager to get the specified file | ||
/// emitted. Typically this will involve several steps of code generation. | ||
/// \p MMIWP is an optional parameter that, if set to non-nullptr, | ||
/// will be used to set the MachineModuloInfo for this PM. | ||
bool | ||
addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out, | ||
raw_pwrite_stream *DwoOut, CodeGenFileType FileType, | ||
bool DisableVerify = true, | ||
MachineModuleInfoWrapperPass *MMIWP = nullptr) override; | ||
|
||
/// Add passes to the specified pass manager to get machine code emitted with | ||
/// the MCJIT. This method returns true if machine code is not supported. It | ||
/// fills the MCContext Ctx pointer which can be used to build custom | ||
/// MCStreamer. | ||
bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, | ||
raw_pwrite_stream &Out, | ||
bool DisableVerify = true) override; | ||
|
||
/// Adds an AsmPrinter pass to the pipeline that prints assembly or | ||
/// machine code from the MI representation. | ||
bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out, | ||
raw_pwrite_stream *DwoOut, CodeGenFileType FileType, | ||
MCContext &Context) override; | ||
|
||
Expected<std::unique_ptr<MCStreamer>> | ||
createMCStreamer(raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, | ||
CodeGenFileType FileType, MCContext &Ctx) override; | ||
}; | ||
|
||
/// Helper method for getting the code model, returning Default if | ||
/// CM does not have a value. The tiny and kernel models will produce | ||
/// an error, so targets that support them or require more complex codemodel | ||
/// selection logic should implement and call their own getEffectiveCodeModel. | ||
inline CodeModel::Model | ||
getEffectiveCodeModel(std::optional<CodeModel::Model> CM, | ||
CodeModel::Model Default) { | ||
if (CM) { | ||
// By default, targets do not support the tiny and kernel models. | ||
if (*CM == CodeModel::Tiny) | ||
report_fatal_error("Target does not support the tiny CodeModel", false); | ||
if (*CM == CodeModel::Kernel) | ||
report_fatal_error("Target does not support the kernel CodeModel", false); | ||
return *CM; | ||
} | ||
return Default; | ||
} | ||
|
||
} // namespace llvm | ||
|
||
#endif |
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
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
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
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
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
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
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
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.
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.
I'd expect all of the references in the codegen infrastructure to refer to the codegen dependent subclass
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.
I don't think there's a need anymore. I'm hoping
CodeGenCommonTMImpl
is treated as just a set of function implementation, and there won't be any hard requirement on subclassing it if you want to use the target independent code generator (CodeGen) library.In other words, a Target can just ignore everything in
CodeGenCommonTMImpl
and start from scratch, but still use the CodeGen library.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.
If you're in MachineFunction, you are definitely using CodeGen. So why wouldn't MachineFunction reference the lowest common subclass for codegen?