File indexing completed on 2026-05-10 08:44:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef LLVM_LTO_LEGACY_LTOCODEGENERATOR_H
0036 #define LLVM_LTO_LEGACY_LTOCODEGENERATOR_H
0037
0038 #include "llvm-c/lto.h"
0039 #include "llvm/ADT/ArrayRef.h"
0040 #include "llvm/ADT/StringMap.h"
0041 #include "llvm/ADT/StringSet.h"
0042 #include "llvm/IR/GlobalValue.h"
0043 #include "llvm/IR/Module.h"
0044 #include "llvm/LTO/Config.h"
0045 #include "llvm/LTO/LTO.h"
0046 #include "llvm/Support/CommandLine.h"
0047 #include "llvm/Support/Error.h"
0048 #include "llvm/Support/ToolOutputFile.h"
0049 #include "llvm/Target/TargetMachine.h"
0050 #include "llvm/Target/TargetOptions.h"
0051 #include <string>
0052 #include <vector>
0053
0054 namespace llvm {
0055 template <typename T> class ArrayRef;
0056 class LLVMContext;
0057 class DiagnosticInfo;
0058 class Linker;
0059 class Mangler;
0060 class MemoryBuffer;
0061 class TargetLibraryInfo;
0062 class TargetMachine;
0063 class raw_ostream;
0064 class raw_pwrite_stream;
0065
0066
0067 extern cl::opt<bool> EnableLTOInternalization;
0068
0069
0070
0071
0072 struct LTOCodeGenerator {
0073 static const char *getVersionString();
0074
0075 LTOCodeGenerator(LLVMContext &Context);
0076 ~LTOCodeGenerator();
0077
0078
0079
0080
0081 bool addModule(struct LTOModule *);
0082
0083
0084
0085
0086 void setModule(std::unique_ptr<LTOModule> M);
0087
0088 void setAsmUndefinedRefs(struct LTOModule *);
0089 void setTargetOptions(const TargetOptions &Options);
0090 void setDebugInfo(lto_debug_model);
0091 void setCodePICModel(std::optional<Reloc::Model> Model) {
0092 Config.RelocModel = Model;
0093 }
0094
0095
0096
0097 void setFileType(CodeGenFileType FT) { Config.CGFileType = FT; }
0098
0099 void setCpu(StringRef MCpu) { Config.CPU = std::string(MCpu); }
0100 void setAttrs(std::vector<std::string> MAttrs) {
0101 Config.MAttrs = std::move(MAttrs);
0102 }
0103 void setOptLevel(unsigned OptLevel);
0104
0105 void setShouldInternalize(bool Value) { ShouldInternalize = Value; }
0106 void setShouldEmbedUselists(bool Value) { ShouldEmbedUselists = Value; }
0107 void setSaveIRBeforeOptPath(std::string Value) {
0108 SaveIRBeforeOptPath = std::move(Value);
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 void setShouldRestoreGlobalsLinkage(bool Value) {
0124 ShouldRestoreGlobalsLinkage = Value;
0125 }
0126
0127 void addMustPreserveSymbol(StringRef Sym) { MustPreserveSymbols.insert(Sym); }
0128
0129
0130
0131
0132
0133
0134
0135 void setCodeGenDebugOptions(ArrayRef<StringRef> Opts);
0136
0137
0138
0139
0140
0141
0142 void parseCodeGenDebugOptions();
0143
0144
0145
0146
0147
0148 bool writeMergedModules(StringRef Path);
0149
0150
0151
0152
0153
0154
0155
0156
0157 bool compile_to_file(const char **Name);
0158
0159
0160
0161
0162
0163
0164
0165 std::unique_ptr<MemoryBuffer> compile();
0166
0167
0168
0169
0170 bool optimize();
0171
0172
0173
0174
0175 std::unique_ptr<MemoryBuffer> compileOptimized();
0176
0177
0178
0179
0180
0181
0182
0183
0184 bool compileOptimized(AddStreamFn AddStream, unsigned ParallelismLevel);
0185
0186
0187
0188 void setFreestanding(bool Enabled) { Config.Freestanding = Enabled; }
0189
0190 void setDisableVerify(bool Value) { Config.DisableVerify = Value; }
0191
0192 void setDebugPassManager(bool Enabled) { Config.DebugPassManager = Enabled; }
0193
0194 void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
0195
0196 LLVMContext &getContext() { return Context; }
0197
0198 void resetMergedModule() { MergedModule.reset(); }
0199 void DiagnosticHandler(const DiagnosticInfo &DI);
0200
0201 private:
0202
0203
0204
0205
0206 void verifyMergedModuleOnce();
0207
0208 bool compileOptimizedToFile(const char **Name);
0209 void restoreLinkageForExternals();
0210 void applyScopeRestrictions();
0211 void preserveDiscardableGVs(
0212 Module &TheModule,
0213 llvm::function_ref<bool(const GlobalValue &)> mustPreserveGV);
0214
0215 bool determineTarget();
0216 std::unique_ptr<TargetMachine> createTargetMachine();
0217
0218 bool useAIXSystemAssembler();
0219 bool runAIXSystemAssembler(SmallString<128> &AssemblyFile);
0220
0221 void emitError(const std::string &ErrMsg);
0222 void emitWarning(const std::string &ErrMsg);
0223
0224 void finishOptimizationRemarks();
0225
0226 LLVMContext &Context;
0227 std::unique_ptr<Module> MergedModule;
0228 std::unique_ptr<Linker> TheLinker;
0229 std::unique_ptr<TargetMachine> TargetMach;
0230 bool EmitDwarfDebugInfo = false;
0231 bool ScopeRestrictionsDone = false;
0232 bool HasVerifiedInput = false;
0233 StringSet<> MustPreserveSymbols;
0234 StringSet<> AsmUndefinedRefs;
0235 StringMap<GlobalValue::LinkageTypes> ExternalSymbols;
0236 std::vector<std::string> CodegenOptions;
0237 std::string FeatureStr;
0238 std::string NativeObjectPath;
0239 const Target *MArch = nullptr;
0240 std::string TripleStr;
0241 lto_diagnostic_handler_t DiagHandler = nullptr;
0242 void *DiagContext = nullptr;
0243 bool ShouldInternalize = EnableLTOInternalization;
0244 bool ShouldEmbedUselists = false;
0245 bool ShouldRestoreGlobalsLinkage = false;
0246 std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
0247 std::unique_ptr<ToolOutputFile> StatsFile = nullptr;
0248 std::string SaveIRBeforeOptPath;
0249
0250 lto::Config Config;
0251 };
0252
0253
0254
0255 void parseCommandLineOptions(std::vector<std::string> &Options);
0256 }
0257 #endif