Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ccdc271

Browse files
committedJan 3, 2023
[polly] Use std::optional instead of llvm::Optional (NFC)
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
1 parent 1ae6891 commit ccdc271

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed
 

‎polly/include/polly/ScopInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <cassert>
3535
#include <cstddef>
3636
#include <forward_list>
37+
#include <optional>
3738

3839
namespace polly {
3940
using llvm::AnalysisInfoMixin;
@@ -51,7 +52,6 @@ using llvm::LoadInst;
5152
using llvm::make_range;
5253
using llvm::MapVector;
5354
using llvm::MemIntrinsic;
54-
using llvm::Optional;
5555
using llvm::PassInfoMixin;
5656
using llvm::PHINode;
5757
using llvm::RegionNode;
@@ -1662,7 +1662,7 @@ class Scop final {
16621662
Region &R;
16631663

16641664
/// The name of the SCoP (identical to the regions name)
1665-
Optional<std::string> name;
1665+
std::optional<std::string> name;
16661666

16671667
// Access functions of the SCoP.
16681668
//

‎polly/include/polly/Support/ScopHelper.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/IR/IntrinsicInst.h"
1919
#include "llvm/IR/ValueHandle.h"
2020
#include "isl/isl-noexceptions.h"
21+
#include <optional>
2122

2223
namespace llvm {
2324
class LoopInfo;
@@ -522,16 +523,16 @@ bool hasDebugCall(ScopStmt *Stmt);
522523
///
523524
/// Then `nullptr` is set to mark the property is existing, but does not carry
524525
/// any value. If the property does not exist, `None` is returned.
525-
llvm::Optional<llvm::Metadata *> findMetadataOperand(llvm::MDNode *LoopMD,
526-
llvm::StringRef Name);
526+
std::optional<llvm::Metadata *> findMetadataOperand(llvm::MDNode *LoopMD,
527+
llvm::StringRef Name);
527528

528529
/// Find a boolean property value in a LoopID. The value not being defined is
529530
/// interpreted as a false value.
530531
bool getBooleanLoopAttribute(llvm::MDNode *LoopID, llvm::StringRef Name);
531532

532533
/// Find an integers property value in a LoopID.
533-
llvm::Optional<int> getOptionalIntLoopAttribute(llvm::MDNode *LoopID,
534-
llvm::StringRef Name);
534+
std::optional<int> getOptionalIntLoopAttribute(llvm::MDNode *LoopID,
535+
llvm::StringRef Name);
535536

536537
/// Does the loop's LoopID contain a 'llvm.loop.disable_heuristics' property?
537538
///

‎polly/lib/Analysis/ScopPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
2020
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
2121
#include "llvm/Analysis/TargetTransformInfo.h"
22+
#include <optional>
2223

2324
using namespace llvm;
2425
using namespace polly;
@@ -119,7 +120,7 @@ bool ScopAnalysisManagerFunctionProxy::Result::invalidate(
119120
// Even if all analyses were preserved, we still need to run deferred
120121
// invalidation
121122
for (auto &S : *SI) {
122-
Optional<PreservedAnalyses> InnerPA;
123+
std::optional<PreservedAnalyses> InnerPA;
123124
auto *scop = S.second.get();
124125
if (!scop)
125126
continue;

‎polly/lib/Support/ScopHelper.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
2222
#include "llvm/Transforms/Utils/LoopUtils.h"
2323
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
24+
#include <optional>
2425

2526
using namespace llvm;
2627
using namespace polly;
@@ -699,8 +700,8 @@ static MDNode *findNamedMetadataNode(MDNode *LoopMD, StringRef Name) {
699700
return nullptr;
700701
}
701702

702-
static Optional<const MDOperand *> findNamedMetadataArg(MDNode *LoopID,
703-
StringRef Name) {
703+
static std::optional<const MDOperand *> findNamedMetadataArg(MDNode *LoopID,
704+
StringRef Name) {
704705
MDNode *MD = findNamedMetadataNode(LoopID, Name);
705706
if (!MD)
706707
return std::nullopt;
@@ -714,8 +715,8 @@ static Optional<const MDOperand *> findNamedMetadataArg(MDNode *LoopID,
714715
}
715716
}
716717

717-
Optional<Metadata *> polly::findMetadataOperand(MDNode *LoopMD,
718-
StringRef Name) {
718+
std::optional<Metadata *> polly::findMetadataOperand(MDNode *LoopMD,
719+
StringRef Name) {
719720
MDNode *MD = findNamedMetadataNode(LoopMD, Name);
720721
if (!MD)
721722
return std::nullopt;
@@ -729,8 +730,8 @@ Optional<Metadata *> polly::findMetadataOperand(MDNode *LoopMD,
729730
}
730731
}
731732

732-
static Optional<bool> getOptionalBoolLoopAttribute(MDNode *LoopID,
733-
StringRef Name) {
733+
static std::optional<bool> getOptionalBoolLoopAttribute(MDNode *LoopID,
734+
StringRef Name) {
734735
MDNode *MD = findNamedMetadataNode(LoopID, Name);
735736
if (!MD)
736737
return std::nullopt;
@@ -750,8 +751,8 @@ bool polly::getBooleanLoopAttribute(MDNode *LoopID, StringRef Name) {
750751
return getOptionalBoolLoopAttribute(LoopID, Name).value_or(false);
751752
}
752753

753-
llvm::Optional<int> polly::getOptionalIntLoopAttribute(MDNode *LoopID,
754-
StringRef Name) {
754+
std::optional<int> polly::getOptionalIntLoopAttribute(MDNode *LoopID,
755+
StringRef Name) {
755756
const MDOperand *AttrMD =
756757
findNamedMetadataArg(LoopID, Name).value_or(nullptr);
757758
if (!AttrMD)

‎polly/lib/Transform/ManualOptimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include "polly/Options.h"
1616
#include "polly/ScheduleTreeTransform.h"
1717
#include "polly/Support/ScopHelper.h"
18-
#include "llvm/ADT/Optional.h"
1918
#include "llvm/ADT/StringRef.h"
2019
#include "llvm/Analysis/LoopInfo.h"
2120
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
2221
#include "llvm/IR/Metadata.h"
2322
#include "llvm/Transforms/Utils/LoopUtils.h"
23+
#include <optional>
2424

2525
#define DEBUG_TYPE "polly-opt-manual"
2626

@@ -40,7 +40,7 @@ static TransformationMode hasUnrollTransformation(MDNode *LoopID) {
4040
if (getBooleanLoopAttribute(LoopID, "llvm.loop.unroll.disable"))
4141
return TM_SuppressedByUser;
4242

43-
Optional<int> Count =
43+
std::optional<int> Count =
4444
getOptionalIntLoopAttribute(LoopID, "llvm.loop.unroll.count");
4545
if (Count)
4646
return *Count == 1 ? TM_SuppressedByUser : TM_ForcedByUser;

‎polly/lib/Transform/Simplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/Statistic.h"
2121
#include "llvm/InitializePasses.h"
2222
#include "llvm/Support/Debug.h"
23+
#include <optional>
2324

2425
#define DEBUG_TYPE "polly-simplify"
2526

@@ -758,7 +759,7 @@ class SimplifyWrapperPass final : public ScopPass {
758759
public:
759760
static char ID;
760761
int CallNo;
761-
Optional<SimplifyImpl> Impl;
762+
std::optional<SimplifyImpl> Impl;
762763

763764
explicit SimplifyWrapperPass(int CallNo = 0) : ScopPass(ID), CallNo(CallNo) {}
764765

0 commit comments

Comments
 (0)
Please sign in to comment.