1 /**
2  * Copyright (c) Glow Contributors. See CONTRIBUTORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "CommandLine.h"
18 
getLLVMBackendCat()19 llvm::cl::OptionCategory &getLLVMBackendCat() {
20   static llvm::cl::OptionCategory cpuBackendCat("Glow CPU Backend Options");
21   return cpuBackendCat;
22 }
23 
24 llvm::cl::opt<std::string> llvmTarget("target",
25                                       llvm::cl::desc("LLVM target to be used"));
26 
27 llvm::cl::opt<std::string>
28     llvmArch("march", llvm::cl::desc("LLVM architecture to be used"));
29 
30 llvm::cl::opt<std::string> llvmCPU("mcpu",
31                                    llvm::cl::desc("LLVM CPU to be used"));
32 
33 llvm::cl::opt<std::string> llvmABI("mabi",
34                                    llvm::cl::desc("Machine ABI to be used"));
35 
36 llvm::cl::opt<llvm::CodeModel::Model> llvmCodeModel(
37     "code-model",
38     llvm::cl::desc("Specify which code model to use on the target machine"),
39     llvm::cl::values(
40         clEnumValN(llvm::CodeModel::Model::Small, "small", "Small code model"),
41         clEnumValN(llvm::CodeModel::Model::Medium, "medium",
42                    "Medium code model"),
43         clEnumValN(llvm::CodeModel::Model::Large, "large", "Large code model")),
44     llvm::cl::init(llvm::CodeModel::Model::Large),
45     llvm::cl::cat(getLLVMBackendCat()));
46 
47 llvm::cl::opt<llvm::CodeModel::Model> llvmBundleCodeModel(
48     "bundle-code-model",
49     llvm::cl::desc("Specify which code model to use for a bundle"),
50     llvm::cl::values(
51         clEnumValN(llvm::CodeModel::Model::Small, "small", "Small code model"),
52         clEnumValN(llvm::CodeModel::Model::Medium, "medium",
53                    "Medium code model"),
54         clEnumValN(llvm::CodeModel::Model::Large, "large", "Large code model")),
55     llvm::cl::init(llvm::CodeModel::Model::Small),
56     llvm::cl::cat(getLLVMBackendCat()));
57 
58 llvm::cl::opt<llvm::Reloc::Model> llvmRelocModel(
59     "relocation-model",
60     llvm::cl::desc(
61         "Specify which relocation model to use on the target machine"),
62     llvm::cl::values(
63         clEnumValN(llvm::Reloc::Static, "static", "Non-relocatable code"),
64         clEnumValN(llvm::Reloc::PIC_, "pic", "Position independent code")),
65     llvm::cl::init(llvm::Reloc::Static), llvm::cl::cat(getLLVMBackendCat()));
66 
67 llvm::cl::list<std::string>
68     llvmTargetFeatures("target-feature",
69                        llvm::cl::desc("LLVM target/CPU features to be used"),
70                        llvm::cl::CommaSeparated, llvm::cl::ZeroOrMore);
71 
72 llvm::cl::alias llvmMAttr("mattr", llvm::cl::desc("Alias for -target-feature"),
73                           llvm::cl::aliasopt(llvmTargetFeatures));
74 
75 llvm::cl::opt<std::string>
76     llvmCompiler("llvm-compiler",
77                  llvm::cl::desc("External LLVM compiler (e.g. llc) to use for "
78                                 "compiling LLVM bitcode into machine code"));
79 
80 llvm::cl::list<std::string> llvmCompilerOptions(
81     "llvm-compiler-opt",
82     llvm::cl::desc("Options to pass to the external LLVM compiler"),
83     llvm::cl::ZeroOrMore);
84 
85 llvm::cl::opt<llvm::FloatABI::ABIType>
86     floatABI("float-abi", llvm::cl::desc("Option to set float ABI type"),
87              llvm::cl::values(clEnumValN(llvm::FloatABI::Default, "default",
88                                          "Default float ABI type"),
89                               clEnumValN(llvm::FloatABI::Soft, "soft",
90                                          "Soft float ABI (softfp)"),
91                               clEnumValN(llvm::FloatABI::Hard, "hard",
92                                          "Hard float ABI (hardfp)")),
93              llvm::cl::init(llvm::FloatABI::Default));
94 
95 static llvm::cl::OptionCategory bundleSaverCat("Bundle Options");
96 
97 llvm::cl::opt<glow::BundleApiType>
98     bundleAPI("bundle-api", llvm::cl::desc("Specify which bundle API to use."),
99               llvm::cl::Optional,
100               llvm::cl::values(clEnumValN(glow::BundleApiType::Dynamic,
101                                           "dynamic", "Dynamic API"),
102                                clEnumValN(glow::BundleApiType::Static, "static",
103                                           "Static API")),
104               llvm::cl::init(glow::BundleApiType::Static),
105               llvm::cl::cat(bundleSaverCat));
106 
107 llvm::cl::opt<bool> bundleAPIVerbose(
108     "bundle-api-verbose",
109     llvm::cl::desc("Print more details in the bundle API header file"),
110     llvm::cl::init(false), llvm::cl::cat(bundleSaverCat));
111