Skip to content

Commit 1fa870b

Browse files
Use None consistently (NFC)
This patch replaces NoneType() and NoneType::None with None in preparation for migration from llvm::Optional to std::optional. In the std::optional world, we are not guranteed to be able to default-construct std::nullopt_t or peek what's inside it, so neither NoneType() nor NoneType::None has a corresponding expression in the std::optional world. Once we consistently use None, we should even be able to replace the contents of llvm/include/llvm/ADT/None.h with something like: using NoneType = std::nullopt_t; inline constexpr std::nullopt_t None = std::nullopt; to ease the migration from llvm::Optional to std::optional. Differential Revision: https://reviews.llvm.org/D138376
1 parent 92bccf5 commit 1fa870b

File tree

21 files changed

+54
-56
lines changed

21 files changed

+54
-56
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class BinaryContext {
323323
if (FileBuildID)
324324
return StringRef(*FileBuildID);
325325

326-
return NoneType();
326+
return None;
327327
}
328328
void setFileBuildID(StringRef ID) { FileBuildID = std::string(ID); }
329329

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ class BinaryFunction {
979979
if (Callback(StringRef(Name)))
980980
return StringRef(Name);
981981

982-
return NoneType();
982+
return None;
983983
}
984984

985985
/// Check if (possibly one out of many) function name matches the given
@@ -1317,7 +1317,7 @@ class BinaryFunction {
13171317
/// Return the name of the section this function originated from.
13181318
Optional<StringRef> getOriginSectionName() const {
13191319
if (!OriginSection)
1320-
return NoneType();
1320+
return None;
13211321
return OriginSection->getName();
13221322
}
13231323

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class MCPlusBuilder {
136136
unsigned Index) const {
137137
const MCInst *AnnotationInst = getAnnotationInst(Inst);
138138
if (!AnnotationInst)
139-
return NoneType();
139+
return None;
140140

141141
for (int I = AnnotationInst->getNumOperands() - 1; I >= 0; --I) {
142142
int64_t ImmValue = AnnotationInst->getOperand(I).getImm();
@@ -145,7 +145,7 @@ class MCPlusBuilder {
145145
}
146146
}
147147

148-
return NoneType();
148+
return None;
149149
}
150150

151151
protected:
@@ -1670,7 +1670,7 @@ class MCPlusBuilder {
16701670
auto AI = AnnotationNameIndexMap.find(Name);
16711671
if (AI != AnnotationNameIndexMap.end())
16721672
return AI->second;
1673-
return NoneType();
1673+
return None;
16741674
}
16751675

16761676
/// Return annotation index matching the \p Name. Create a new index if the

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress,
18981898
}
18991899
}
19001900

1901-
return NoneType();
1901+
return None;
19021902
}
19031903

19041904
ErrorOr<BinarySection &> BinaryContext::getSectionForAddress(uint64_t Address) {

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ bool MCPlusBuilder::isTailCall(const MCInst &Inst) const {
135135

136136
Optional<MCLandingPad> MCPlusBuilder::getEHInfo(const MCInst &Inst) const {
137137
if (!isCall(Inst))
138-
return NoneType();
138+
return None;
139139
Optional<int64_t> LPSym =
140140
getAnnotationOpValue(Inst, MCAnnotation::kEHLandingPad);
141141
if (!LPSym)
142-
return NoneType();
142+
return None;
143143
Optional<int64_t> Action =
144144
getAnnotationOpValue(Inst, MCAnnotation::kEHAction);
145145
if (!Action)
146-
return NoneType();
146+
return None;
147147

148148
return std::make_pair(reinterpret_cast<const MCSymbol *>(*LPSym),
149149
static_cast<uint64_t>(*Action));
@@ -221,7 +221,7 @@ MCPlusBuilder::getConditionalTailCall(const MCInst &Inst) const {
221221
Optional<int64_t> Value =
222222
getAnnotationOpValue(Inst, MCAnnotation::kConditionalTailCall);
223223
if (!Value)
224-
return NoneType();
224+
return None;
225225
return static_cast<uint64_t>(*Value);
226226
}
227227

@@ -243,7 +243,7 @@ bool MCPlusBuilder::unsetConditionalTailCall(MCInst &Inst) {
243243
Optional<uint32_t> MCPlusBuilder::getOffset(const MCInst &Inst) const {
244244
Optional<int64_t> Value = getAnnotationOpValue(Inst, MCAnnotation::kOffset);
245245
if (!Value)
246-
return NoneType();
246+
return None;
247247
return static_cast<uint32_t>(*Value);
248248
}
249249

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress,
263263

264264
auto Iter = Maps.find(FuncAddress);
265265
if (Iter == Maps.end())
266-
return NoneType();
266+
return None;
267267

268268
const MapTy &Map = Iter->second;
269269
auto FromIter = Map.upper_bound(From);

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
943943
SmallVector<std::pair<uint64_t, uint64_t>, 16> Res;
944944

945945
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, &Res))
946-
return NoneType();
946+
return None;
947947

948948
return Res;
949949
}
@@ -1820,13 +1820,13 @@ Optional<int32_t> DataAggregator::parseCommExecEvent() {
18201820
if (LineEnd == StringRef::npos) {
18211821
reportError("expected rest of line");
18221822
Diag << "Found: " << ParsingBuf << "\n";
1823-
return NoneType();
1823+
return None;
18241824
}
18251825
StringRef Line = ParsingBuf.substr(0, LineEnd);
18261826

18271827
size_t Pos = Line.find("PERF_RECORD_COMM exec");
18281828
if (Pos == StringRef::npos)
1829-
return NoneType();
1829+
return None;
18301830
Line = Line.drop_front(Pos);
18311831

18321832
// Line:
@@ -1836,7 +1836,7 @@ Optional<int32_t> DataAggregator::parseCommExecEvent() {
18361836
if (PIDStr.getAsInteger(10, PID)) {
18371837
reportError("expected PID");
18381838
Diag << "Found: " << PIDStr << "in '" << Line << "'\n";
1839-
return NoneType();
1839+
return None;
18401840
}
18411841

18421842
return PID;
@@ -1850,7 +1850,7 @@ Optional<uint64_t> parsePerfTime(const StringRef TimeStr) {
18501850
uint64_t USecTime;
18511851
if (SecTimeStr.getAsInteger(10, SecTime) ||
18521852
USecTimeStr.getAsInteger(10, USecTime))
1853-
return NoneType();
1853+
return None;
18541854
return SecTime * 1000000ULL + USecTime;
18551855
}
18561856
}
@@ -1863,14 +1863,14 @@ Optional<DataAggregator::ForkInfo> DataAggregator::parseForkEvent() {
18631863
if (LineEnd == StringRef::npos) {
18641864
reportError("expected rest of line");
18651865
Diag << "Found: " << ParsingBuf << "\n";
1866-
return NoneType();
1866+
return None;
18671867
}
18681868
StringRef Line = ParsingBuf.substr(0, LineEnd);
18691869

18701870
size_t Pos = Line.find("PERF_RECORD_FORK");
18711871
if (Pos == StringRef::npos) {
18721872
consumeRestOfLine();
1873-
return NoneType();
1873+
return None;
18741874
}
18751875

18761876
ForkInfo FI;
@@ -1889,14 +1889,14 @@ Optional<DataAggregator::ForkInfo> DataAggregator::parseForkEvent() {
18891889
if (ChildPIDStr.getAsInteger(10, FI.ChildPID)) {
18901890
reportError("expected PID");
18911891
Diag << "Found: " << ChildPIDStr << "in '" << Line << "'\n";
1892-
return NoneType();
1892+
return None;
18931893
}
18941894

18951895
const StringRef ParentPIDStr = Line.rsplit('(').second.split(':').first;
18961896
if (ParentPIDStr.getAsInteger(10, FI.ParentPID)) {
18971897
reportError("expected PID");
18981898
Diag << "Found: " << ParentPIDStr << "in '" << Line << "'\n";
1899-
return NoneType();
1899+
return None;
19001900
}
19011901

19021902
consumeRestOfLine();
@@ -2147,17 +2147,17 @@ DataAggregator::parseNameBuildIDPair() {
21472147

21482148
ErrorOr<StringRef> BuildIDStr = parseString(FieldSeparator, true);
21492149
if (std::error_code EC = BuildIDStr.getError())
2150-
return NoneType();
2150+
return None;
21512151

21522152
// If one of the strings is missing, don't issue a parsing error, but still
21532153
// do not return a value.
21542154
consumeAllRemainingFS();
21552155
if (checkNewLine())
2156-
return NoneType();
2156+
return None;
21572157

21582158
ErrorOr<StringRef> NameStr = parseString(FieldSeparator, true);
21592159
if (std::error_code EC = NameStr.getError())
2160-
return NoneType();
2160+
return None;
21612161

21622162
consumeRestOfLine();
21632163
return std::make_pair(NameStr.get(), BuildIDStr.get());
@@ -2205,7 +2205,7 @@ DataAggregator::getFileNameForBuildID(StringRef FileBuildID) {
22052205
if (!FileName.empty())
22062206
return FileName;
22072207

2208-
return NoneType();
2208+
return None;
22092209
}
22102210

22112211
std::error_code

bolt/lib/Profile/DataReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Optional<StringRef> getLTOCommonName(const StringRef Name) {
4949
return Name.substr(0, LTOSuffixPos + 11);
5050
if ((LTOSuffixPos = Name.find(".llvm.")) != StringRef::npos)
5151
return Name.substr(0, LTOSuffixPos + 6);
52-
return NoneType();
52+
return None;
5353
}
5454

5555
namespace {

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ void RewriteInstance::parseBuildID() {
681681

682682
Optional<std::string> RewriteInstance::getPrintableBuildID() const {
683683
if (BuildID.empty())
684-
return NoneType();
684+
return None;
685685

686686
std::string Str;
687687
raw_string_ostream OS(Str);
@@ -4763,7 +4763,7 @@ void RewriteInstance::updateELFSymbolTable(
47634763
assert(SymbolName && "cannot get symbol name");
47644764

47654765
auto updateSymbolValue = [&](const StringRef Name,
4766-
Optional<uint64_t> Value = NoneType()) {
4766+
Optional<uint64_t> Value = None) {
47674767
NewSymbol.st_value = Value ? *Value : getNewValueForSymbol(Name);
47684768
NewSymbol.st_shndx = ELF::SHN_ABS;
47694769
outs() << "BOLT-INFO: setting " << Name << " to 0x"

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ class X86MCPlusBuilder : public MCPlusBuilder {
26002600
if (FKI.Flags & MCFixupKindInfo::FKF_IsPCRel) {
26012601
switch (FKI.TargetSize) {
26022602
default:
2603-
return NoneType();
2603+
return None;
26042604
case 8: RelType = ELF::R_X86_64_PC8; break;
26052605
case 16: RelType = ELF::R_X86_64_PC16; break;
26062606
case 32: RelType = ELF::R_X86_64_PC32; break;
@@ -2609,7 +2609,7 @@ class X86MCPlusBuilder : public MCPlusBuilder {
26092609
} else {
26102610
switch (FKI.TargetSize) {
26112611
default:
2612-
return NoneType();
2612+
return None;
26132613
case 8: RelType = ELF::R_X86_64_8; break;
26142614
case 16: RelType = ELF::R_X86_64_16; break;
26152615
case 32: RelType = ELF::R_X86_64_32; break;

bolt/lib/Utils/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::string getUnescapedName(const StringRef &Name) {
6969
Optional<uint8_t> readDWARFExpressionTargetReg(StringRef ExprBytes) {
7070
uint8_t Opcode = ExprBytes[0];
7171
if (Opcode == dwarf::DW_CFA_def_cfa_expression)
72-
return NoneType();
72+
return None;
7373
assert((Opcode == dwarf::DW_CFA_expression ||
7474
Opcode == dwarf::DW_CFA_val_expression) &&
7575
"invalid DWARF expression CFI");

clang/lib/Driver/ToolChains/HLSL.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ llvm::Optional<std::string> tryParseProfile(StringRef Profile) {
6969
SmallVector<StringRef, 3> Parts;
7070
Profile.split(Parts, "_");
7171
if (Parts.size() != 3)
72-
return NoneType();
72+
return None;
7373

7474
Triple::EnvironmentType Kind =
7575
StringSwitch<Triple::EnvironmentType>(Parts[0])
@@ -84,17 +84,17 @@ llvm::Optional<std::string> tryParseProfile(StringRef Profile) {
8484
.Case("as", Triple::EnvironmentType::Amplification)
8585
.Default(Triple::EnvironmentType::UnknownEnvironment);
8686
if (Kind == Triple::EnvironmentType::UnknownEnvironment)
87-
return NoneType();
87+
return None;
8888

8989
unsigned long long Major = 0;
9090
if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
91-
return NoneType();
91+
return None;
9292

9393
unsigned long long Minor = 0;
9494
if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
9595
Minor = OfflineLibMinor;
9696
else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
97-
return NoneType();
97+
return None;
9898

9999
// dxil-unknown-shadermodel-hull
100100
llvm::Triple T;
@@ -105,7 +105,7 @@ llvm::Optional<std::string> tryParseProfile(StringRef Profile) {
105105
if (isLegalShaderModel(T))
106106
return T.getTriple();
107107
else
108-
return NoneType();
108+
return None;
109109
}
110110

111111
bool isLegalValidatorVersion(StringRef ValVersionStr, const Driver &D) {

lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ getTargetIncludePaths(const llvm::Triple &triple) {
5050
static llvm::Optional<llvm::StringRef>
5151
guessIncludePath(llvm::StringRef path_to_file, llvm::StringRef pattern) {
5252
if (pattern.empty())
53-
return llvm::NoneType();
53+
return llvm::None;
5454
size_t pos = path_to_file.find(pattern);
5555
if (pos == llvm::StringRef::npos)
56-
return llvm::NoneType();
56+
return llvm::None;
5757

5858
return path_to_file.substr(0, pos + pattern.size());
5959
}

llvm/include/llvm/Analysis/InlineAdvisor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class InlineAdvisor {
200200

201201
protected:
202202
InlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
203-
Optional<InlineContext> IC = NoneType::None);
203+
Optional<InlineContext> IC = llvm::None);
204204
virtual std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) = 0;
205205
virtual std::unique_ptr<InlineAdvice> getMandatoryAdvice(CallBase &CB,
206206
bool Advice);

llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ class ARCMDKindCache {
240240
public:
241241
void init(Module *Mod) {
242242
M = Mod;
243-
ImpreciseReleaseMDKind = NoneType::None;
244-
CopyOnEscapeMDKind = NoneType::None;
245-
NoObjCARCExceptionsMDKind = NoneType::None;
243+
ImpreciseReleaseMDKind = llvm::None;
244+
CopyOnEscapeMDKind = llvm::None;
245+
NoObjCARCExceptionsMDKind = llvm::None;
246246
}
247247

248248
unsigned get(ARCMDKindID ID) {

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,8 +3675,7 @@ class DebugVariable {
36753675

36763676
DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
36773677
const DILocation *InlinedAt)
3678-
: Variable(Var),
3679-
Fragment(DIExpr ? DIExpr->getFragmentInfo() : NoneType()),
3678+
: Variable(Var), Fragment(DIExpr ? DIExpr->getFragmentInfo() : None),
36803679
InlinedAt(InlinedAt) {}
36813680

36823681
const DILocalVariable *getVariable() const { return Variable; }
@@ -3707,7 +3706,7 @@ template <> struct DenseMapInfo<DebugVariable> {
37073706

37083707
/// Empty key: no key should be generated that has no DILocalVariable.
37093708
static inline DebugVariable getEmptyKey() {
3710-
return DebugVariable(nullptr, NoneType(), nullptr);
3709+
return DebugVariable(nullptr, None, nullptr);
37113710
}
37123711

37133712
/// Difference in tombstone is that the Optional is meaningful.

llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static bool reduceDbgValsForwardScan(MachineBasicBlock &MBB) {
8989

9090
for (auto &MI : MBB) {
9191
if (MI.isDebugValue()) {
92-
DebugVariable Var(MI.getDebugVariable(), NoneType(),
92+
DebugVariable Var(MI.getDebugVariable(), None,
9393
MI.getDebugLoc()->getInlinedAt());
9494
auto VMI = VariableMap.find(Var);
9595
// Just stop tracking this variable, until we cover DBG_VALUE_LIST.

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
428428
VariableMap;
429429
for (auto &I : *BB) {
430430
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(&I)) {
431-
DebugVariable Key(DVI->getVariable(),
432-
NoneType(),
431+
DebugVariable Key(DVI->getVariable(), None,
433432
DVI->getDebugLoc()->getInlinedAt());
434433
auto VMI = VariableMap.find(Key);
435434
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
@@ -490,7 +489,7 @@ static bool remomveUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
490489
DenseSet<DebugVariable> SeenDefForAggregate;
491490
// Returns the DebugVariable for DVI with no fragment info.
492491
auto GetAggregateVariable = [](DbgValueInst *DVI) {
493-
return DebugVariable(DVI->getVariable(), NoneType(),
492+
return DebugVariable(DVI->getVariable(), None,
494493
DVI->getDebugLoc()->getInlinedAt());
495494
};
496495

llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void DWARFExpressionCopyBytesTest::parseCFIsAndCheckExpression(
159159
return Instr;
160160
}
161161
}
162-
return NoneType();
162+
return None;
163163
};
164164

165165
std::unique_ptr<DWARFContext> Ctx = DWARFContext::create(E);

0 commit comments

Comments
 (0)