Skip to content

Commit

Permalink
Move CodeGenFileType enum to Support/CodeGen.h
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rnk committed Nov 14, 2019
1 parent 4fa44f9 commit 1dfede3
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 47 deletions.
10 changes: 5 additions & 5 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion llvm/examples/Kaleidoscope/Chapter8/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/CodeGen/CommandFlags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/ParallelCG.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/LTO/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -238,7 +238,7 @@ struct LTOCodeGenerator {
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;
Expand Down
9 changes: 9 additions & 0 deletions llvm/include/llvm/Support/CodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 0 additions & 9 deletions llvm/include/llvm/Target/TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,6 @@ class TargetMachine {
/// 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
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/ParallelCG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/TargetMachineC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/gold/gold-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 8 additions & 8 deletions llvm/tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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";

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-exegesis/lib/Assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions polly/lib/CodeGen/PPCGCodeGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down

0 comments on commit 1dfede3

Please sign in to comment.