pin-gcc-client/0004-Pin-gcc-client-Support-Plugin-Pointer-type.patch
benniaobufeijiushiji 02a666961a [sync] Sync patch from openeuler/pin-gcc-client
Sync patch from openeuler/pin-gcc-client 2022/12/08

(cherry picked from commit ca424952fd407c6158e330c8e21d67442aec4c16)
2022-12-09 09:52:56 +08:00

185 lines
6.6 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From b8322c7f689c44ac7ca5fb4d407994308f4725ed Mon Sep 17 00:00:00 2001
From: dingguangya <dingguangya1@huawei.com>
Date: Thu, 8 Dec 2022 20:41:09 +0800
Subject: [PATCH 4/4] [Pin-gcc-client] Support Plugin Pointer type
---
include/Dialect/PluginTypes.h | 12 +++++++++
include/PluginClient/PluginClient.h | 2 +-
lib/Dialect/PluginDialect.cpp | 1 +
lib/Dialect/PluginTypes.cpp | 41 +++++++++++++++++++++++++++++
lib/PluginClient/PluginClient.cpp | 9 +++++--
lib/Translate/TypeTranslation.cpp | 2 ++
6 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/include/Dialect/PluginTypes.h b/include/Dialect/PluginTypes.h
index e0ef867..b329caa 100644
--- a/include/Dialect/PluginTypes.h
+++ b/include/Dialect/PluginTypes.h
@@ -80,6 +80,7 @@ private:
namespace detail {
struct PluginIntegerTypeStorage;
struct PluginFloatTypeStorage;
+ struct PluginPointerTypeStorage;
}
class PluginIntegerType : public Type::TypeBase<PluginIntegerType, PluginTypeBase, detail::PluginIntegerTypeStorage> {
@@ -117,6 +118,17 @@ public:
unsigned getWidth() const;
};
+class PluginPointerType : public Type::TypeBase<PluginPointerType, PluginTypeBase, detail::PluginPointerTypeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static PluginPointerType get(MLIRContext *context, Type pointee);
+
+ Type getElementType();
+}; // class PluginPointerType
+
class PluginVoidType : public Type::TypeBase<PluginVoidType, PluginTypeBase, TypeStorage> {
public:
using Base::Base;
diff --git a/include/PluginClient/PluginClient.h b/include/PluginClient/PluginClient.h
index b18ecc0..51e16c9 100644
--- a/include/PluginClient/PluginClient.h
+++ b/include/PluginClient/PluginClient.h
@@ -128,7 +128,7 @@ public:
Json::Value RetOpJsonSerialize(mlir::Plugin::RetOp data, uint64_t&);
Json::Value ValueJsonSerialize(mlir::Value value);
/* 将Type类型数据序列化 */
- void TypeJsonSerialize(PluginIR::PluginTypeBase& type, string& out);
+ Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase& type);
/* 获取gcc插件数据并进行IR转换将转换后的数据序列化返回给server。param函数入参序列化后的数据 */
void IRTransBegin(const string& funname, const string& param);
/* 从配置文件读取初始化信息 */
diff --git a/lib/Dialect/PluginDialect.cpp b/lib/Dialect/PluginDialect.cpp
index a53861e..7071e64 100644
--- a/lib/Dialect/PluginDialect.cpp
+++ b/lib/Dialect/PluginDialect.cpp
@@ -36,6 +36,7 @@ using namespace mlir::Plugin;
void PluginDialect::initialize() {
addTypes<PluginIR::PluginIntegerType,
PluginIR::PluginFloatType,
+ PluginIR::PluginPointerType,
PluginIR::PluginBooleanType,
PluginIR::PluginVoidType,
PluginIR::PluginUndefType>();
diff --git a/lib/Dialect/PluginTypes.cpp b/lib/Dialect/PluginTypes.cpp
index bd5f145..0c0e048 100644
--- a/lib/Dialect/PluginTypes.cpp
+++ b/lib/Dialect/PluginTypes.cpp
@@ -74,6 +74,25 @@ namespace detail {
unsigned width : 30;
};
+
+ struct PluginPointerTypeStorage : public TypeStorage {
+ using KeyTy = Type;
+
+ PluginPointerTypeStorage(const KeyTy &key)
+ : pointee(key) {}
+
+ static PluginPointerTypeStorage *construct(TypeStorageAllocator &allocator,
+ KeyTy key) {
+ return new (allocator.allocate<PluginPointerTypeStorage>())
+ PluginPointerTypeStorage(key);
+ }
+
+ bool operator==(const KeyTy &key) const {
+ return KeyTy(pointee) == key;
+ }
+
+ Type pointee;
+ };
} // namespace detail
} // namespace PluginIR
@@ -96,6 +115,9 @@ PluginTypeID PluginTypeBase::getPluginTypeID ()
if (auto Ty = dyn_cast<PluginIR::PluginVoidType>()) {
return Ty.getPluginTypeID ();
}
+ if (auto Ty = dyn_cast<PluginIR::PluginPointerType>()) {
+ return Ty.getPluginTypeID ();
+ }
return PluginTypeID::UndefTyID;
}
@@ -254,4 +276,23 @@ PluginTypeID PluginVoidType::getPluginTypeID()
PluginTypeID PluginUndefType::getPluginTypeID()
{
return PluginTypeID::UndefTyID;
+}
+
+//===----------------------------------------------------------------------===//
+// Plugin Pointer Type
+//===----------------------------------------------------------------------===//
+
+PluginTypeID PluginPointerType::getPluginTypeID()
+{
+ return PluginTypeID::PointerTyID;
+}
+
+Type PluginPointerType::getElementType()
+{
+ return getImpl()->pointee;
+}
+
+PluginPointerType PluginPointerType::get (MLIRContext *context, Type pointee)
+{
+ return Base::get(context, pointee);
}
\ No newline at end of file
diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp
index e8a7d7d..237eccb 100644
--- a/lib/PluginClient/PluginClient.cpp
+++ b/lib/PluginClient/PluginClient.cpp
@@ -70,7 +70,7 @@ int PluginClient::GetEvent(InjectPoint inject, plugin_event *event)
return -1;
}
-void PluginClient::TypeJsonSerialize (PluginIR::PluginTypeBase& type, string& out)
+Json::Value PluginClient::TypeJsonSerialize (PluginIR::PluginTypeBase& type)
{
Json::Value root;
Json::Value operationObj;
@@ -82,6 +82,11 @@ void PluginClient::TypeJsonSerialize (PluginIR::PluginTypeBase& type, string& ou
ReTypeId = static_cast<uint64_t>(type.getPluginTypeID());
item["id"] = std::to_string(ReTypeId);
+ if (auto elemTy = type.dyn_cast<PluginIR::PluginPointerType>()) {
+ auto baseTy = elemTy.getElementType().dyn_cast<PluginIR::PluginTypeBase>();
+ item["elementType"] = TypeJsonSerialize(baseTy);
+ }
+
if (type.getPluginIntOrFloatBitWidth() != 0) {
ReTypeWidth = type.getPluginIntOrFloatBitWidth();
item["width"] = std::to_string(ReTypeWidth);
@@ -102,7 +107,7 @@ void PluginClient::TypeJsonSerialize (PluginIR::PluginTypeBase& type, string& ou
}
root["type"] = item;
- out = root.toStyledString();
+ return root;
}
void PluginClient::FunctionOpJsonSerialize(vector<FunctionOp>& data, string& out)
diff --git a/lib/Translate/TypeTranslation.cpp b/lib/Translate/TypeTranslation.cpp
index 492a895..4c390fa 100644
--- a/lib/Translate/TypeTranslation.cpp
+++ b/lib/Translate/TypeTranslation.cpp
@@ -95,6 +95,8 @@ private:
return PluginBooleanType::get(&context);
if (TREE_CODE(type) == VOID_TYPE)
return PluginVoidType::get(&context);
+ if (TREE_CODE(type) == POINTER_TYPE)
+ return PluginPointerType::get(&context, translatePrimitiveType(TREE_TYPE(type)));
return PluginUndefType::get(&context);
}
--
2.27.0.windows.1