Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/passes/Commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ CommandLineOptions::CommandLineOptions() {
};
}

llvm::Optional<typeart::config::OptionValue> CommandLineOptions::getValue(std::string_view opt_path) const {
std::optional<typeart::config::OptionValue> CommandLineOptions::getValue(std::string_view opt_path) const {
auto key = llvm::StringRef(opt_path.data());
if (mapping_.count(key) != 0U) {
return mapping_.lookup(key);
}
return llvm::None;
return {};
}

[[maybe_unused]] bool CommandLineOptions::valueSpecified(std::string_view opt_path) const {
Expand Down
2 changes: 1 addition & 1 deletion lib/passes/Commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CommandLineOptions final : public config::Configuration {

public:
CommandLineOptions();
[[nodiscard]] llvm::Optional<config::OptionValue> getValue(std::string_view opt_path) const override;
[[nodiscard]] std::optional<config::OptionValue> getValue(std::string_view opt_path) const override;
[[maybe_unused]] [[nodiscard]] bool valueSpecified(std::string_view opt_path) const;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/passes/TypeARTConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TypeARTConfiguration::TypeARTConfiguration(std::unique_ptr<file::FileOptions> co
: configuration_options_(std::move(config_options)), commandline_options_(std::move(commandline_options)) {
}

llvm::Optional<OptionValue> TypeARTConfiguration::getValue(std::string_view opt_path) const {
std::optional<OptionValue> TypeARTConfiguration::getValue(std::string_view opt_path) const {
const bool use_cl = prioritize_commandline && commandline_options_->valueSpecified(opt_path);
if (use_cl) {
LOG_DEBUG("Take CL arg for " << opt_path.data())
Expand Down
2 changes: 1 addition & 1 deletion lib/passes/TypeARTConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TypeARTConfiguration final : public Configuration {
TypeARTConfiguration(std::unique_ptr<file::FileOptions> config_options,
std::unique_ptr<cl::CommandLineOptions> commandline_options);
void prioritizeCommandline(bool do_prioritize);
[[nodiscard]] llvm::Optional<OptionValue> getValue(std::string_view opt_path) const override;
[[nodiscard]] std::optional<OptionValue> getValue(std::string_view opt_path) const override;
[[nodiscard]] OptionValue getValueOr(std::string_view opt_path, OptionValue alt) const override;
[[nodiscard]] OptionValue operator[](std::string_view opt_path) const override;
void emitTypeartFileConfiguration(llvm::raw_ostream& out_stream);
Expand Down
7 changes: 4 additions & 3 deletions lib/passes/TypeARTPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <cassert>
#include <cstddef>
#include <optional>
#include <sstream>
#include <string>
#include <utility>
Expand Down Expand Up @@ -72,7 +73,7 @@ ALWAYS_ENABLED_STATISTIC(NumInstrumentedGlobal, "Number of instrumented globals"

namespace typeart::pass {

llvm::Optional<std::string> get_configuration_file_path() {
std::optional<std::string> get_configuration_file_path() {
if (!cl_typeart_configuration_file.empty()) {
LOG_DEBUG("Using cl::opt for config file " << cl_typeart_configuration_file.getValue());
return cl_typeart_configuration_file.getValue();
Expand All @@ -83,7 +84,7 @@ llvm::Optional<std::string> get_configuration_file_path() {
return std::string{config_file};
}
LOG_INFO("No configuration file set.")
return llvm::None;
return {};
}

// Used by LLVM pass manager to identify passes in memory
Expand All @@ -109,7 +110,7 @@ bool TypeArtPass::doInitialization(Module& m) {
if (!config_file_path) {
pass_config = std::make_unique<config::cl::CommandLineOptions>();
} else {
auto typeart_config = config::make_typeart_configuration({config_file_path.getValue()});
auto typeart_config = config::make_typeart_configuration({config_file_path.value()});
if (typeart_config) {
{
std::string typeart_conf_str;
Expand Down
19 changes: 10 additions & 9 deletions lib/passes/analysis/MemOpData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#ifndef TYPEART_MEMOPDATA_H
#define TYPEART_MEMOPDATA_H

#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"

#include <optional>

namespace llvm {
class CallBase;
class BitCastInst;
Expand Down Expand Up @@ -45,28 +46,28 @@ enum class MemOpKind : uint8_t {
};

struct MemOps {
inline llvm::Optional<MemOpKind> kind(llvm::StringRef function) const {
inline std::optional<MemOpKind> kind(llvm::StringRef function) const {
if (auto alloc = allocKind(function)) {
return alloc;
}
if (auto dealloc = deallocKind(function)) {
return dealloc;
}
return llvm::None;
return {};
}

inline llvm::Optional<MemOpKind> allocKind(llvm::StringRef function) const {
inline std::optional<MemOpKind> allocKind(llvm::StringRef function) const {
if (auto it = alloc_map.find(function); it != std::end(alloc_map)) {
return {(*it).second};
}
return llvm::None;
return {};
}

inline llvm::Optional<MemOpKind> deallocKind(llvm::StringRef function) const {
inline std::optional<MemOpKind> deallocKind(llvm::StringRef function) const {
if (auto it = dealloc_map.find(function); it != std::end(dealloc_map)) {
return {(*it).second};
}
return llvm::None;
return {};
}

const llvm::StringMap<MemOpKind>& allocs() const {
Expand Down Expand Up @@ -129,7 +130,7 @@ struct ArrayCookieData {

struct MallocData {
llvm::CallBase* call{nullptr};
llvm::Optional<ArrayCookieData> array_cookie{llvm::None};
std::optional<ArrayCookieData> array_cookie{};
llvm::BitCastInst* primary{nullptr}; // Non-null if non (void*) cast exists
llvm::SmallPtrSet<llvm::BitCastInst*, 4> bitcasts;
MemOpKind kind;
Expand All @@ -138,7 +139,7 @@ struct MallocData {

struct FreeData {
llvm::CallBase* call{nullptr};
llvm::Optional<llvm::GetElementPtrInst*> array_cookie_gep{llvm::None};
std::optional<llvm::GetElementPtrInst*> array_cookie_gep{};
MemOpKind kind;
bool is_invoke{false};
};
Expand Down
24 changes: 12 additions & 12 deletions lib/passes/analysis/MemOpVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
#include "support/Logger.h"
#include "support/TypeUtil.h"

#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringRef.h"

#if LLVM_VERSION_MAJOR >= 12
#include "llvm/Analysis/ValueTracking.h" // llvm::findAllocaForValue
#else
Expand All @@ -38,6 +37,7 @@
#include "llvm/Support/raw_ostream.h"

#include <cstddef>
#include <optional>

namespace typeart::analysis {

Expand Down Expand Up @@ -82,26 +82,26 @@ void MemOpVisitor::visitCallBase(llvm::CallBase& cb) {
if (!collect_heap) {
return;
}
const auto isInSet = [&](const auto& fMap) -> llvm::Optional<MemOpKind> {
const auto isInSet = [&](const auto& fMap) -> std::optional<MemOpKind> {
const auto* f = cb.getCalledFunction();
if (!f) {
// TODO handle calls through, e.g., function pointers? - seems infeasible
// LOG_INFO("Encountered indirect call, skipping.");
return None;
return {};
}
const auto name = f->getName().str();

const auto res = fMap.find(name);
if (res != fMap.end()) {
return {(*res).second};
}
return None;
return {};
};

if (auto alloc_val = isInSet(mem_operations.allocs())) {
visitMallocLike(cb, alloc_val.getValue());
visitMallocLike(cb, alloc_val.value());
} else if (auto dealloc_val = isInSet(mem_operations.deallocs())) {
visitFreeLike(cb, dealloc_val.getValue());
visitFreeLike(cb, dealloc_val.value());
}
}

Expand Down Expand Up @@ -216,8 +216,8 @@ llvm::Expected<ArrayCookieData> handlePaddedArrayCookie(const MallocGeps& geps,
return {ArrayCookieData{*cookie_store, array_gep}};
}

llvm::Optional<ArrayCookieData> handleArrayCookie(const MallocGeps& geps, MallocBcasts& bcasts,
BitCastInst*& primary_cast) {
std::optional<ArrayCookieData> handleArrayCookie(const MallocGeps& geps, MallocBcasts& bcasts,
BitCastInst*& primary_cast) {
auto exit_on_error = llvm::ExitOnError{"Array Cookie Detection failed!"};
if (geps.size() == 1) {
return exit_on_error(handleUnpaddedArrayCookie(geps, bcasts, primary_cast));
Expand All @@ -232,7 +232,7 @@ llvm::Optional<ArrayCookieData> handleArrayCookie(const MallocGeps& geps, Malloc
LOG_FATAL(err);
exit_on_error({error::make_string_error(err)});
}
return llvm::None;
return {};
}

void MemOpVisitor::visitMallocLike(llvm::CallBase& ci, MemOpKind k) {
Expand All @@ -253,12 +253,12 @@ void MemOpVisitor::visitFreeLike(llvm::CallBase& ci, MemOpKind k) {
if (auto f = ci.getCalledFunction()) {
auto dkind = mem_operations.deallocKind(f->getName());
if (dkind) {
kind = dkind.getValue();
kind = dkind.value();
}
}

auto gep = dyn_cast<GetElementPtrInst>(ci.getArgOperand(0));
auto array_cookie_gep = gep != nullptr ? llvm::Optional<llvm::GetElementPtrInst*>{gep} : llvm::None;
auto array_cookie_gep = gep != nullptr ? std::optional<llvm::GetElementPtrInst*>{gep} : std::nullopt;
frees.emplace_back(FreeData{&ci, array_cookie_gep, kind, isa<InvokeInst>(ci)});
}

Expand Down
15 changes: 7 additions & 8 deletions lib/passes/filter/CGInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "support/Logger.h"
#include "support/Util.h"

#include "llvm/ADT/Optional.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/JSON.h"
Expand Down Expand Up @@ -137,7 +136,7 @@ void JSONCG::construct_call_information(const std::string& entry_caller, const l
const auto hasBody = caller->get("hasBody");
if (hasBody != nullptr) {
assert(hasBody->kind() == llvm::json::Value::Kind::Boolean && "hasBody must be boolean");
hasBodyMap[entry_caller] = hasBody->getAsBoolean().getValue();
hasBodyMap[entry_caller] = *hasBody->getAsBoolean();
}
const auto calls = caller->getArray("callees");
assert(calls != nullptr && "Json callee information is missing");
Expand All @@ -146,9 +145,9 @@ void JSONCG::construct_call_information(const std::string& entry_caller, const l
for (const auto& callee : *calls) {
assert(callee.kind() == llvm::json::Value::Kind::String && "Callees must be strings");
const auto callee_json_string = callee.getAsString();
assert(callee_json_string.hasValue() && "Could not get callee as string");
if (callee_json_string.hasValue()) {
const std::string callee_string = std::string{callee_json_string.getValue()};
assert(callee_json_string && "Could not get callee as string");
if (callee_json_string) {
const std::string callee_string = std::string{*callee_json_string};
directly_called_functions[entry_caller].insert(callee_string);
}
}
Expand All @@ -159,9 +158,9 @@ void JSONCG::construct_call_information(const std::string& entry_caller, const l
for (const auto& function : *overridingFunctions) {
assert(function.kind() == llvm::json::Value::Kind::String && "Function names are always strings");
const auto functionStr = function.getAsString();
assert(functionStr.hasValue() && "Retrieving overriding function as String failed");
if (functionStr.hasValue()) {
const std::string functionName = std::string{functionStr.getValue()};
assert(functionStr && "Retrieving overriding function as String failed");
if (functionStr) {
const std::string functionName = std::string{*functionStr};
virtualTargets[entry_caller].insert(functionName);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/passes/filter/FilterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BaseFilter : public Filter {
continue;
}

llvm::CallSite c(csite.getValue());
llvm::CallSite c(csite.value());
if (fpath.contains(c)) {
// Avoid recursion:
// TODO a continue may be wrong, if the function itself eventually calls "MPI"?
Expand Down Expand Up @@ -151,7 +151,7 @@ class BaseFilter : public Filter {
if (OmpHelper::isOmpExecutor(c)) {
auto outlined = OmpHelper::getMicrotask(c);
if (outlined) {
path2def.push(outlined.getValue());
path2def.push(outlined.value());
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions lib/passes/filter/FilterUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "support/DefUseChain.h"
#include "support/Logger.h"

#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
Expand Down Expand Up @@ -76,7 +74,7 @@ inline std::pair<llvm::Argument*, int> findArg(CallSite c, const Path& p) {
return {nullptr, -1};
}

Value* in = arg.getValue();
Value* in = arg.value();
const auto arg_pos = llvm::find_if(c.args(), [&in](const Use& arg_use) -> bool { return arg_use.get() == in; });

if (arg_pos == c.arg_end()) {
Expand All @@ -90,7 +88,7 @@ inline std::pair<llvm::Argument*, int> findArg(CallSite c, const Path& p) {
if (outlined) {
// Calc the offset of arg in executor to actual arg of the outline function:
auto offset = omp::OmpContext::getArgOffsetToMicrotask(c, arg_num);
Argument* argument = (outlined.getValue()->arg_begin() + offset);
Argument* argument = (outlined.value()->arg_begin() + offset);
return {argument, offset};
}
}
Expand Down
Loading