LLVM 24.0.0git
CommandFlags.h
Go to the documentation of this file.
1//===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains codegen-specific flags that are shared between different
10// command line tools. The tools "llc" and "opt" both use this file to prevent
11// flag duplication.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_COMMANDFLAGS_H
16#define LLVM_CODEGEN_COMMANDFLAGS_H
17
18#include "llvm/ADT/ArrayRef.h"
22#include <optional>
23#include <string>
24#include <vector>
25
26namespace llvm {
27
28class Module;
29class AttrBuilder;
30class Function;
31class Triple;
32class TargetMachine;
33
34namespace cl {
35class LibraryOptions;
36}
37
38namespace codegen {
39
41
43
45
46LLVM_ABI std::vector<std::string> getMAttrs(const cl::LibraryOptionsContext &C);
47
48LLVM_ABI std::optional<Reloc::Model>
50
51LLVM_ABI std::optional<CodeModel::Model>
53
54LLVM_ABI std::optional<uint64_t>
56
57LLVM_ABI std::optional<CodeGenFileType>
59
61
64
65LLVM_ABI std::optional<bool>
67
68LLVM_ABI std::optional<bool>
70
71LLVM_ABI std::optional<bool>
73
75
77
78/// The options that a tool reading getTargetOptions passes to
79/// cl::parseCommandLineOptions.
81
82/// Common utility function tightly tied to the options listed here. Initializes
83/// a TargetOptions object with CodeGen options and returns it.
84/// \p TheTriple is used to determine the default value for options if
85/// options are not explicitly specified. If those triple dependant options
86/// value do not have effect for your component, a default Triple() could be
87/// passed in.
90 const llvm::Triple &TheTriple);
91
93
95
97
98LLVM_ABI std::vector<std::string>
100
101LLVM_ABI void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val);
102
103/// Set function attributes of function \p F based on CPU, TuneCPU, Features,
104/// and command line flags.
106 StringRef Features, StringRef TuneCPU = "");
107
108/// Set function attributes of functions in Module M based on CPU,
109/// TuneCPU, Features, and command line flags.
111 StringRef Features, StringRef TuneCPU = "");
112
113/// Creates a TargetMachine instance with the options defined on the command
114/// line. This can be used for tools that do not need further customization of
115/// the TargetOptions.
117 const cl::LibraryOptionsContext &LibraryOptions, const Triple &TargetTriple,
119
120/// Conditionally enables the collection of LLVM statistics during the tool run,
121/// based on the value of the flag. Must be called before the tool run to
122/// actually collect data.
124
125/// Conditionally saves the collected LLVM statistics to the received output
126/// file, based on the value of the flag. Should be called after the tool run,
127/// and must follow a call to `maybeEnableStatistics()` to actually have data to
128/// write.
131
132} // namespace codegen
133} // namespace llvm
134
135#endif // LLVM_CODEGEN_COMMANDFLAGS_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define F(x, y, z)
Definition MD5.cpp:54
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Tagged union holding either a T or a Error.
Definition Error.h:485
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The options of a library that declares them in TableGen rather than as cl::opt (see llvm/Option/Libra...
This namespace contains all of the command line option processing machinery.
LLVM_ABI std::string getMArch(const cl::LibraryOptionsContext &C)
LLVM_ABI SaveStatsMode getSaveStats(const cl::LibraryOptionsContext &C)
LLVM_ABI std::string getMTune(const cl::LibraryOptionsContext &C)
LLVM_ABI void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
LLVM_ABI std::vector< std::string > getMAttrs(const cl::LibraryOptionsContext &C)
LLVM_ABI Expected< std::unique_ptr< TargetMachine > > createTargetMachineForTriple(const cl::LibraryOptionsContext &LibraryOptions, const Triple &TargetTriple, CodeGenOptLevel OptLevel=CodeGenOptLevel::Default)
Creates a TargetMachine instance with the options defined on the command line.
LLVM_ABI std::optional< Reloc::Model > getExplicitRelocModel(const cl::LibraryOptionsContext &C)
LLVM_ABI void setFunctionAttributes(Function &F, StringRef CPU, StringRef Features, StringRef TuneCPU="")
Set function attributes of function F based on CPU, TuneCPU, Features, and command line flags.
LLVM_ABI ArrayRef< const cl::LibraryOptions * > getToolOptions()
The options that a tool reading getTargetOptions passes to cl::parseCommandLineOptions.
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
LLVM_ABI std::string getFeaturesStr(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< bool > getExplicitFunctionSections(const cl::LibraryOptionsContext &C)
LLVM_ABI std::vector< std::string > getFeatureList(const cl::LibraryOptionsContext &C)
LLVM_ABI CodeGenFileType getFileType(const cl::LibraryOptionsContext &C)
LLVM_ABI std::string getCPUStr(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< CodeModel::Model > getExplicitCodeModel(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< bool > getExplicitDataSections(const cl::LibraryOptionsContext &C)
LLVM_ABI int maybeSaveStatistics(const cl::LibraryOptionsContext &C, StringRef OutputFilename, StringRef ToolName)
Conditionally saves the collected LLVM statistics to the received output file, based on the value of ...
LLVM_ABI std::optional< CodeGenFileType > getExplicitFileType(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< uint64_t > getExplicitLargeDataThreshold(const cl::LibraryOptionsContext &C)
LLVM_ABI std::string getTuneCPUStr(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< bool > getExplicitEmulatedTLS(const cl::LibraryOptionsContext &C)
LLVM_ABI llvm::FloatABI::ABIType getFloatABIForCalls(const cl::LibraryOptionsContext &C)
LLVM_ABI void maybeEnableStatistics(const cl::LibraryOptionsContext &C)
Conditionally enables the collection of LLVM statistics during the tool run, based on the value of th...
LLVM_ABI std::string getMCPU(const cl::LibraryOptionsContext &C)
This is an optimization pass for GlobalISel generic memory operations.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:309
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:283