================ @@ -0,0 +1,194 @@ +//===--- DirectToIndirectFCR.cpp - RISC-V specific pass -------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/Constants.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Value.h" +#include "llvm/InitializePasses.h" +#include "llvm/Support/Casting.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" + +#include "Plugins/Architecture/RISCV/DirectToIndirectFCR.h" + +#include "lldb/Core/Architecture.h" +#include "lldb/Core/Module.h" +#include "lldb/Symbol/Symtab.h" +#include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include <optional> + +using namespace llvm; +using namespace lldb_private; + +namespace { +std::string GetValueTypeStr(const llvm::Type *value_ty) { + assert(value_ty); + std::string str_type; + llvm::raw_string_ostream rso(str_type); + value_ty->print(rso); + return rso.str(); +} + +template <typename... Args> void LogMessage(const char *msg, Args &&...args) { + Log *log = GetLog(LLDBLog::Expressions); + LLDB_LOG(log, msg, std::forward<Args>(args)...); +} +} // namespace + +bool DirectToIndirectFCR::canBeReplaced(const llvm::CallInst *ci) { + assert(ci); + auto *return_value_ty = ci->getType(); + if (!(return_value_ty->isIntegerTy() || return_value_ty->isVoidTy())) { + LogMessage("DirectToIndirectFCR: function {0} has unsupported " + "return type ({1})\n", + ci->getCalledFunction()->getName(), + GetValueTypeStr(return_value_ty)); + return false; + } + + const auto *arg = llvm::find_if_not(ci->args(), [](const auto &arg) { + const auto *type = arg->getType(); + return type->isIntegerTy(); + }); + + if (arg != ci->arg_end()) { + LogMessage("DirectToIndirectFCR: argument {0} of {1} function " + "has unsupported type ({2})\n", + (*arg)->getName(), ci->getCalledFunction()->getName(), + GetValueTypeStr((*arg)->getType())); + return false; + } + return true; +} + +std::vector<llvm::Value *> +DirectToIndirectFCR::getFunctionArgsAsValues(const llvm::CallInst *ci) { + assert(ci); + std::vector<llvm::Value *> args{}; + llvm::transform(ci->args(), std::back_inserter(args), + [](const auto &arg) { return arg.get(); }); + return args; +} + +std::optional<lldb::addr_t> +DirectToIndirectFCR::getFunctionAddress(const llvm::CallInst *ci) const { + auto *target = m_exe_ctx.GetTargetPtr(); + const auto &lldb_module_sp = target->GetExecutableModule(); + const auto &symtab = lldb_module_sp->GetSymtab(); + const llvm::StringRef name = ci->getCalledFunction()->getName(); + + // eSymbolTypeCode: we try to find function + // eDebugNo: not a debug symbol + // eVisibilityExtern: function from extern module ---------------- JDevlieghere wrote:
Either make these named constant variables or use inline comment in the function call (e.g, `/*argument_name=*/value`) https://github.com/llvm/llvm-project/pull/99336 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits