forked from OSchip/llvm-project
Move CodeGenFileType enum to Support/CodeGen.h
Avoids the need to include TargetMachine.h from various places just for an enum. Various other enums live here, such as the optimization level, TLS model, etc. Data suggests that this change probably doesn't matter, but it seems nice to have anyway.
This commit is contained in:
parent
4fa44f989e
commit
1dfede3122
|
@ -407,14 +407,14 @@ getCodeModel(const CodeGenOptions &CodeGenOpts) {
|
|||
return static_cast<llvm::CodeModel::Model>(CodeModel);
|
||||
}
|
||||
|
||||
static TargetMachine::CodeGenFileType getCodeGenFileType(BackendAction Action) {
|
||||
static CodeGenFileType getCodeGenFileType(BackendAction Action) {
|
||||
if (Action == Backend_EmitObj)
|
||||
return TargetMachine::CGFT_ObjectFile;
|
||||
return CGFT_ObjectFile;
|
||||
else if (Action == Backend_EmitMCNull)
|
||||
return TargetMachine::CGFT_Null;
|
||||
return CGFT_Null;
|
||||
else {
|
||||
assert(Action == Backend_EmitAssembly && "Invalid action!");
|
||||
return TargetMachine::CGFT_AssemblyFile;
|
||||
return CGFT_AssemblyFile;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -788,7 +788,7 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
|
|||
|
||||
// Normal mode, emit a .s or .o file by running the code generator. Note,
|
||||
// this also adds codegenerator level optimization passes.
|
||||
TargetMachine::CodeGenFileType CGFT = getCodeGenFileType(Action);
|
||||
CodeGenFileType CGFT = getCodeGenFileType(Action);
|
||||
|
||||
// Add ObjC ARC final-cleanup optimizations. This is done as part of the
|
||||
// "codegen" passes so that it isn't run multiple times when there is
|
||||
|
|
|
@ -157,7 +157,7 @@ pass:
|
|||
.. code-block:: c++
|
||||
|
||||
legacy::PassManager pass;
|
||||
auto FileType = TargetMachine::CGFT_ObjectFile;
|
||||
auto FileType = CGFT_ObjectFile;
|
||||
|
||||
if (TargetMachine->addPassesToEmitFile(pass, dest, nullptr, FileType)) {
|
||||
errs() << "TargetMachine can't emit a file of this type";
|
||||
|
|
|
@ -1253,7 +1253,7 @@ int main() {
|
|||
}
|
||||
|
||||
legacy::PassManager pass;
|
||||
auto FileType = TargetMachine::CGFT_ObjectFile;
|
||||
auto FileType = CGFT_ObjectFile;
|
||||
|
||||
if (TheTargetMachine->addPassesToEmitFile(pass, dest, nullptr, FileType)) {
|
||||
errs() << "TheTargetMachine can't emit a file of this type";
|
||||
|
|
|
@ -102,15 +102,15 @@ static cl::opt<llvm::ExceptionHandling> ExceptionModel(
|
|||
clEnumValN(ExceptionHandling::Wasm, "wasm",
|
||||
"WebAssembly exception handling")));
|
||||
|
||||
static cl::opt<TargetMachine::CodeGenFileType> FileType(
|
||||
"filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
|
||||
static cl::opt<CodeGenFileType> FileType(
|
||||
"filetype", cl::init(CGFT_AssemblyFile),
|
||||
cl::desc(
|
||||
"Choose a file type (not all types are supported by all targets):"),
|
||||
cl::values(clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
|
||||
cl::values(clEnumValN(CGFT_AssemblyFile, "asm",
|
||||
"Emit an assembly ('.s') file"),
|
||||
clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
|
||||
clEnumValN(CGFT_ObjectFile, "obj",
|
||||
"Emit a native object ('.o') file"),
|
||||
clEnumValN(TargetMachine::CGFT_Null, "null",
|
||||
clEnumValN(CGFT_Null, "null",
|
||||
"Emit nothing, for performance testing")));
|
||||
|
||||
static cl::opt<llvm::FramePointer::FP> FramePointerUsage(
|
||||
|
|
|
@ -39,7 +39,7 @@ std::unique_ptr<Module>
|
|||
splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
|
||||
ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
|
||||
const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
|
||||
TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_ObjectFile,
|
||||
CodeGenFileType FileType = CGFT_ObjectFile,
|
||||
bool PreserveLocals = false);
|
||||
|
||||
} // namespace llvm
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#define LLVM_LTO_CONFIG_H
|
||||
|
||||
#include "llvm/IR/DiagnosticInfo.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/Support/CodeGen.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
|
||||
#include <functional>
|
||||
|
@ -41,7 +41,7 @@ struct Config {
|
|||
Optional<Reloc::Model> RelocModel = Reloc::PIC_;
|
||||
Optional<CodeModel::Model> CodeModel = None;
|
||||
CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
|
||||
TargetMachine::CodeGenFileType CGFileType = TargetMachine::CGFT_ObjectFile;
|
||||
CodeGenFileType CGFileType = CGFT_ObjectFile;
|
||||
unsigned OptLevel = 2;
|
||||
bool DisableVerify = false;
|
||||
|
||||
|
|
|
@ -87,8 +87,8 @@ struct LTOCodeGenerator {
|
|||
void setCodePICModel(Optional<Reloc::Model> Model) { RelocModel = Model; }
|
||||
|
||||
/// Set the file type to be emitted (assembly or object code).
|
||||
/// The default is TargetMachine::CGFT_ObjectFile.
|
||||
void setFileType(TargetMachine::CodeGenFileType FT) { FileType = FT; }
|
||||
/// The default is CGFT_ObjectFile.
|
||||
void setFileType(CodeGenFileType FT) { FileType = FT; }
|
||||
|
||||
void setCpu(StringRef MCpu) { this->MCpu = MCpu; }
|
||||
void setAttr(StringRef MAttr) { this->MAttr = MAttr; }
|
||||
|
@ -238,7 +238,7 @@ private:
|
|||
bool ShouldInternalize = EnableLTOInternalization;
|
||||
bool ShouldEmbedUselists = false;
|
||||
bool ShouldRestoreGlobalsLinkage = false;
|
||||
TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_ObjectFile;
|
||||
CodeGenFileType FileType = CGFT_ObjectFile;
|
||||
std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
|
||||
bool Freestanding = false;
|
||||
std::unique_ptr<ToolOutputFile> StatsFile = nullptr;
|
||||
|
|
|
@ -57,6 +57,15 @@ namespace llvm {
|
|||
};
|
||||
}
|
||||
|
||||
/// These enums are meant to be passed into addPassesToEmitFile to indicate
|
||||
/// what type of file to emit, and returned by it to indicate what type of
|
||||
/// file could actually be made.
|
||||
enum CodeGenFileType {
|
||||
CGFT_AssemblyFile,
|
||||
CGFT_ObjectFile,
|
||||
CGFT_Null // Do not emit any output.
|
||||
};
|
||||
|
||||
// Specify effect of frame pointer elimination optimization.
|
||||
namespace FramePointer {
|
||||
enum FP {All, NonLeaf, None};
|
||||
|
|
|
@ -271,15 +271,6 @@ public:
|
|||
/// PassManagerBuilder::addExtension.
|
||||
virtual void adjustPassManager(PassManagerBuilder &) {}
|
||||
|
||||
/// These enums are meant to be passed into addPassesToEmitFile to indicate
|
||||
/// what type of file to emit, and returned by it to indicate what type of
|
||||
/// file could actually be made.
|
||||
enum CodeGenFileType {
|
||||
CGFT_AssemblyFile,
|
||||
CGFT_ObjectFile,
|
||||
CGFT_Null // Do not emit any output.
|
||||
};
|
||||
|
||||
/// Add passes to the specified pass manager to get the specified file
|
||||
/// emitted. Typically this will involve several steps of code generation.
|
||||
/// This method should return true if emission of this file type is not
|
||||
|
|
|
@ -26,7 +26,7 @@ using namespace llvm;
|
|||
|
||||
static void codegen(Module *M, llvm::raw_pwrite_stream &OS,
|
||||
function_ref<std::unique_ptr<TargetMachine>()> TMFactory,
|
||||
TargetMachine::CodeGenFileType FileType) {
|
||||
CodeGenFileType FileType) {
|
||||
std::unique_ptr<TargetMachine> TM = TMFactory();
|
||||
legacy::PassManager CodeGenPasses;
|
||||
if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, FileType))
|
||||
|
@ -38,7 +38,7 @@ std::unique_ptr<Module> llvm::splitCodeGen(
|
|||
std::unique_ptr<Module> M, ArrayRef<llvm::raw_pwrite_stream *> OSs,
|
||||
ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
|
||||
const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
|
||||
TargetMachine::CodeGenFileType FileType, bool PreserveLocals) {
|
||||
CodeGenFileType FileType, bool PreserveLocals) {
|
||||
assert(BCOSs.empty() || BCOSs.size() == OSs.size());
|
||||
|
||||
if (OSs.size() == 1) {
|
||||
|
|
|
@ -259,7 +259,7 @@ bool LTOCodeGenerator::compileOptimizedToFile(const char **Name) {
|
|||
int FD;
|
||||
|
||||
StringRef Extension
|
||||
(FileType == TargetMachine::CGFT_AssemblyFile ? "s" : "o");
|
||||
(FileType == CGFT_AssemblyFile ? "s" : "o");
|
||||
|
||||
std::error_code EC =
|
||||
sys::fs::createTemporaryFile("lto-llvm", Extension, FD, Filename);
|
||||
|
|
|
@ -292,7 +292,7 @@ std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
|
|||
PM.add(createObjCARCContractPass());
|
||||
|
||||
// Setup the codegen now.
|
||||
if (TM.addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_ObjectFile,
|
||||
if (TM.addPassesToEmitFile(PM, OS, nullptr, CGFT_ObjectFile,
|
||||
/* DisableVerify */ true))
|
||||
report_fatal_error("Failed to setup codegen");
|
||||
|
||||
|
|
|
@ -195,13 +195,13 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
|
|||
|
||||
Mod->setDataLayout(TM->createDataLayout());
|
||||
|
||||
TargetMachine::CodeGenFileType ft;
|
||||
CodeGenFileType ft;
|
||||
switch (codegen) {
|
||||
case LLVMAssemblyFile:
|
||||
ft = TargetMachine::CGFT_AssemblyFile;
|
||||
ft = CGFT_AssemblyFile;
|
||||
break;
|
||||
default:
|
||||
ft = TargetMachine::CGFT_ObjectFile;
|
||||
ft = CGFT_ObjectFile;
|
||||
break;
|
||||
}
|
||||
if (TM->addPassesToEmitFile(pass, OS, nullptr, ft)) {
|
||||
|
|
|
@ -899,7 +899,7 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
|
|||
/* UseInputModulePath */ true));
|
||||
break;
|
||||
case options::OT_ASM_ONLY:
|
||||
Conf.CGFileType = TargetMachine::CGFT_AssemblyFile;
|
||||
Conf.CGFileType = CGFT_AssemblyFile;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
|
|||
OutputFilename = IFN;
|
||||
|
||||
switch (FileType) {
|
||||
case TargetMachine::CGFT_AssemblyFile:
|
||||
case CGFT_AssemblyFile:
|
||||
if (TargetName[0] == 'c') {
|
||||
if (TargetName[1] == 0)
|
||||
OutputFilename += ".cbe.c";
|
||||
|
@ -214,13 +214,13 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
|
|||
} else
|
||||
OutputFilename += ".s";
|
||||
break;
|
||||
case TargetMachine::CGFT_ObjectFile:
|
||||
case CGFT_ObjectFile:
|
||||
if (OS == Triple::Win32)
|
||||
OutputFilename += ".obj";
|
||||
else
|
||||
OutputFilename += ".o";
|
||||
break;
|
||||
case TargetMachine::CGFT_Null:
|
||||
case CGFT_Null:
|
||||
OutputFilename += ".null";
|
||||
break;
|
||||
}
|
||||
|
@ -230,10 +230,10 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
|
|||
// Decide if we need "binary" output.
|
||||
bool Binary = false;
|
||||
switch (FileType) {
|
||||
case TargetMachine::CGFT_AssemblyFile:
|
||||
case CGFT_AssemblyFile:
|
||||
break;
|
||||
case TargetMachine::CGFT_ObjectFile:
|
||||
case TargetMachine::CGFT_Null:
|
||||
case CGFT_ObjectFile:
|
||||
case CGFT_Null:
|
||||
Binary = true;
|
||||
break;
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
|||
setFunctionAttributes(CPUStr, FeaturesStr, *M);
|
||||
|
||||
if (RelaxAll.getNumOccurrences() > 0 &&
|
||||
FileType != TargetMachine::CGFT_ObjectFile)
|
||||
FileType != CGFT_ObjectFile)
|
||||
WithColor::warning(errs(), argv[0])
|
||||
<< ": warning: ignoring -mc-relax-all because filetype != obj";
|
||||
|
||||
|
@ -531,7 +531,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
|||
// so we can memcmp the contents in CompileTwice mode
|
||||
SmallVector<char, 0> Buffer;
|
||||
std::unique_ptr<raw_svector_ostream> BOS;
|
||||
if ((FileType != TargetMachine::CGFT_AssemblyFile &&
|
||||
if ((FileType != CGFT_AssemblyFile &&
|
||||
!Out->os().supportsSeeking()) ||
|
||||
CompileTwice) {
|
||||
BOS = std::make_unique<raw_svector_ostream>(Buffer);
|
||||
|
|
|
@ -238,7 +238,7 @@ void assembleToStream(const ExegesisTarget &ET,
|
|||
TPC->setInitialized();
|
||||
|
||||
// AsmPrinter is responsible for generating the assembly into AsmBuffer.
|
||||
if (TM->addAsmPrinter(PM, AsmStream, nullptr, TargetMachine::CGFT_ObjectFile,
|
||||
if (TM->addAsmPrinter(PM, AsmStream, nullptr, CGFT_ObjectFile,
|
||||
MCContext))
|
||||
report_fatal_error("Cannot add AsmPrinter passes");
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|||
TargetLibraryInfoImpl TLII(TM->getTargetTriple());
|
||||
PM.add(new TargetLibraryInfoWrapperPass(TLII));
|
||||
raw_null_ostream OS;
|
||||
TM->addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_Null);
|
||||
TM->addPassesToEmitFile(PM, OS, nullptr, CGFT_Null);
|
||||
PM.run(*M);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -2367,8 +2367,7 @@ std::string GPUNodeBuilder::createKernelASM() {
|
|||
|
||||
PM.add(createTargetTransformInfoWrapperPass(TargetM->getTargetIRAnalysis()));
|
||||
|
||||
if (TargetM->addPassesToEmitFile(PM, ASMStream, nullptr,
|
||||
TargetMachine::CGFT_AssemblyFile,
|
||||
if (TargetM->addPassesToEmitFile(PM, ASMStream, nullptr, CGFT_AssemblyFile,
|
||||
true /* verify */)) {
|
||||
errs() << "The target does not support generation of this file type!\n";
|
||||
return "";
|
||||
|
|
Loading…
Reference in New Issue