[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 10 10:08:02 PDT 2024
================
@@ -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();
----------------
dlav-sc wrote:
Large code model has been merged, so DirectToIndirectFCR pass is deprecated.
https://github.com/llvm/llvm-project/pull/99336
More information about the lldb-commits
mailing list