Skip to content

Commit 8c7c20f

Browse files
author
Krzysztof Parzyszek
committed
Convert Optional<CodeModel> to std::optional<CodeModel>
1 parent d98c172 commit 8c7c20f

File tree

67 files changed

+280
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+280
-159
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
9393
#include "llvm/Transforms/Utils/SymbolRewriter.h"
9494
#include <memory>
95+
#include <optional>
9596
using namespace clang;
9697
using namespace llvm;
9798

@@ -312,7 +313,7 @@ static CodeGenOpt::Level getCGOptLevel(const CodeGenOptions &CodeGenOpts) {
312313
}
313314
}
314315

315-
static Optional<llvm::CodeModel::Model>
316+
static std::optional<llvm::CodeModel::Model>
316317
getCodeModel(const CodeGenOptions &CodeGenOpts) {
317318
unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.CodeModel)
318319
.Case("tiny", llvm::CodeModel::Tiny)
@@ -324,7 +325,7 @@ getCodeModel(const CodeGenOptions &CodeGenOpts) {
324325
.Default(~0u);
325326
assert(CodeModel != ~0u && "invalid code model!");
326327
if (CodeModel == ~1u)
327-
return None;
328+
return std::nullopt;
328329
return static_cast<llvm::CodeModel::Model>(CodeModel);
329330
}
330331

@@ -572,7 +573,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
572573
return;
573574
}
574575

575-
Optional<llvm::CodeModel::Model> CM = getCodeModel(CodeGenOpts);
576+
std::optional<llvm::CodeModel::Model> CM = getCodeModel(CodeGenOpts);
576577
std::string FeaturesStr =
577578
llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(), ",");
578579
llvm::Reloc::Model RM = CodeGenOpts.RelocationModel;

lld/Common/TargetOptionsCommandFlags.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/ADT/Triple.h"
1111
#include "llvm/CodeGen/CommandFlags.h"
1212
#include "llvm/Target/TargetOptions.h"
13+
#include <optional>
1314

1415
llvm::TargetOptions lld::initTargetOptionsFromCodeGenFlags() {
1516
return llvm::codegen::InitTargetOptionsFromCodeGenFlags(llvm::Triple());
@@ -19,7 +20,7 @@ llvm::Optional<llvm::Reloc::Model> lld::getRelocModelFromCMModel() {
1920
return llvm::codegen::getExplicitRelocModel();
2021
}
2122

22-
llvm::Optional<llvm::CodeModel::Model> lld::getCodeModelFromCMModel() {
23+
std::optional<llvm::CodeModel::Model> lld::getCodeModelFromCMModel() {
2324
return llvm::codegen::getExplicitCodeModel();
2425
}
2526

lld/include/lld/Common/TargetOptionsCommandFlags.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
#include "llvm/ADT/Optional.h"
1717
#include "llvm/Support/CodeGen.h"
1818
#include "llvm/Target/TargetOptions.h"
19+
#include <optional>
1920

2021
namespace lld {
2122
llvm::TargetOptions initTargetOptionsFromCodeGenFlags();
2223
llvm::Optional<llvm::Reloc::Model> getRelocModelFromCMModel();
23-
llvm::Optional<llvm::CodeModel::Model> getCodeModelFromCMModel();
24+
std::optional<llvm::CodeModel::Model> getCodeModelFromCMModel();
2425
std::string getCPUStr();
2526
std::vector<std::string> getMAttrs();
2627
}

llvm/include/llvm/CodeGen/CommandFlags.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/FloatingPointMode.h"
1919
#include "llvm/Support/CodeGen.h"
2020
#include "llvm/Target/TargetOptions.h"
21+
#include <optional>
2122
#include <string>
2223
#include <vector>
2324

@@ -42,7 +43,7 @@ Optional<Reloc::Model> getExplicitRelocModel();
4243
ThreadModel::Model getThreadModel();
4344

4445
CodeModel::Model getCodeModel();
45-
Optional<CodeModel::Model> getExplicitCodeModel();
46+
std::optional<CodeModel::Model> getExplicitCodeModel();
4647

4748
llvm::ExceptionHandling getExceptionModel();
4849

llvm/include/llvm/ExecutionEngine/ExecutionEngine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <functional>
3636
#include <map>
3737
#include <memory>
38+
#include <optional>
3839
#include <string>
3940
#include <vector>
4041

@@ -541,7 +542,7 @@ class EngineBuilder {
541542
std::shared_ptr<LegacyJITSymbolResolver> Resolver;
542543
TargetOptions Options;
543544
Optional<Reloc::Model> RelocModel;
544-
Optional<CodeModel::Model> CMModel;
545+
std::optional<CodeModel::Model> CMModel;
545546
std::string MArch;
546547
std::string MCPU;
547548
SmallVector<std::string, 4> MAttrs;

llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Target/TargetMachine.h"
2222
#include "llvm/Target/TargetOptions.h"
2323
#include <memory>
24+
#include <optional>
2425
#include <string>
2526
#include <vector>
2627

@@ -92,13 +93,13 @@ class JITTargetMachineBuilder {
9293
const Optional<Reloc::Model> &getRelocationModel() const { return RM; }
9394

9495
/// Set the code model.
95-
JITTargetMachineBuilder &setCodeModel(Optional<CodeModel::Model> CM) {
96+
JITTargetMachineBuilder &setCodeModel(std::optional<CodeModel::Model> CM) {
9697
this->CM = std::move(CM);
9798
return *this;
9899
}
99100

100101
/// Get the code model.
101-
const Optional<CodeModel::Model> &getCodeModel() const { return CM; }
102+
const std::optional<CodeModel::Model> &getCodeModel() const { return CM; }
102103

103104
/// Set the LLVM CodeGen optimization level.
104105
JITTargetMachineBuilder &setCodeGenOptLevel(CodeGenOpt::Level OptLevel) {
@@ -151,7 +152,7 @@ class JITTargetMachineBuilder {
151152
SubtargetFeatures Features;
152153
TargetOptions Options;
153154
Optional<Reloc::Model> RM;
154-
Optional<CodeModel::Model> CM;
155+
std::optional<CodeModel::Model> CM;
155156
CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
156157
};
157158

llvm/include/llvm/IR/Module.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <cstdint>
3737
#include <iterator>
3838
#include <memory>
39+
#include <optional>
3940
#include <string>
4041
#include <vector>
4142

@@ -863,7 +864,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
863864
/// @{
864865

865866
/// Returns the code model (tiny, small, kernel, medium or large model)
866-
Optional<CodeModel::Model> getCodeModel() const;
867+
std::optional<CodeModel::Model> getCodeModel() const;
867868

868869
/// Set the code model (tiny, small, kernel, medium or large)
869870
void setCodeModel(CodeModel::Model CL);

llvm/include/llvm/LTO/Config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Target/TargetOptions.h"
2626

2727
#include <functional>
28+
#include <optional>
2829

2930
namespace llvm {
3031

@@ -52,7 +53,7 @@ struct Config {
5253
/// For adding passes that run right before codegen.
5354
std::function<void(legacy::PassManager &)> PreCodeGenPassesHook;
5455
Optional<Reloc::Model> RelocModel = Reloc::PIC_;
55-
Optional<CodeModel::Model> CodeModel = std::nullopt;
56+
std::optional<CodeModel::Model> CodeModel = std::nullopt;
5657
CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
5758
CodeGenFileType CGFileType = CGFT_ObjectFile;
5859
unsigned OptLevel = 2;

llvm/include/llvm/MC/TargetRegistry.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <cstddef>
3232
#include <iterator>
3333
#include <memory>
34+
#include <optional>
3435
#include <string>
3536

3637
namespace llvm {
@@ -167,7 +168,7 @@ class Target {
167168
using TargetMachineCtorTy = TargetMachine
168169
*(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
169170
const TargetOptions &Options, Optional<Reloc::Model> RM,
170-
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT);
171+
std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT);
171172
// If it weren't for layering issues (this header is in llvm/Support, but
172173
// depends on MC?) this should take the Streamer by value rather than rvalue
173174
// reference.
@@ -481,7 +482,7 @@ class Target {
481482
TargetMachine *
482483
createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
483484
const TargetOptions &Options, Optional<Reloc::Model> RM,
484-
Optional<CodeModel::Model> CM = std::nullopt,
485+
std::optional<CodeModel::Model> CM = std::nullopt,
485486
CodeGenOpt::Level OL = CodeGenOpt::Default,
486487
bool JIT = false) const {
487488
if (!TargetMachineCtorFn)
@@ -1358,10 +1359,12 @@ template <class TargetMachineImpl> struct RegisterTargetMachine {
13581359
}
13591360

13601361
private:
1361-
static TargetMachine *
1362-
Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1363-
const TargetOptions &Options, Optional<Reloc::Model> RM,
1364-
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT) {
1362+
static TargetMachine *Allocator(const Target &T, const Triple &TT,
1363+
StringRef CPU, StringRef FS,
1364+
const TargetOptions &Options,
1365+
Optional<Reloc::Model> RM,
1366+
std::optional<CodeModel::Model> CM,
1367+
CodeGenOpt::Level OL, bool JIT) {
13651368
return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
13661369
}
13671370
};

llvm/include/llvm/Target/CodeGenCWrappers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#include "llvm/ADT/Optional.h"
2020
#include "llvm/Support/CodeGen.h"
2121
#include "llvm/Support/ErrorHandling.h"
22+
#include <optional>
2223

2324
namespace llvm {
2425

25-
inline Optional<CodeModel::Model> unwrap(LLVMCodeModel Model, bool &JIT) {
26+
inline std::optional<CodeModel::Model> unwrap(LLVMCodeModel Model, bool &JIT) {
2627
JIT = false;
2728
switch (Model) {
2829
case LLVMCodeModelJITDefault:

0 commit comments

Comments
 (0)