[Update] Update to v0.4.1

(cherry picked from commit c9d9ea91d0ab8b6c0314646b9681085614841d99)
This commit is contained in:
d00573793 2023-02-26 22:49:00 +08:00 committed by openeuler-sync-bot
parent 12680dd19e
commit 010be2021c
12 changed files with 4 additions and 6732 deletions

View File

@ -1,34 +0,0 @@
From 3bbf6ad7dd4cd77e98aa31f0c6bd41ba321b8290 Mon Sep 17 00:00:00 2001
From: benniaobufeijiushiji <linda7@huawei.com>
Date: Wed, 28 Dec 2022 15:04:28 +0800
Subject: [PATCH 1/9] [Pin-gcc-client] Bugfix for ConstOp Support both signed
const int and unsigned const int
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index a5380a7..3a71ffe 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -812,9 +812,16 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId)
mlir::Value opValue;
switch (TREE_CODE(t)) {
case INTEGER_CST : {
- unsigned HOST_WIDE_INT init = tree_to_uhwi(t);
- // FIXME : AnyAttr!
- mlir::Attribute initAttr = builder.getI64IntegerAttr(init);
+ mlir::Attribute initAttr;
+ if (tree_fits_shwi_p(t)) {
+ signed HOST_WIDE_INT sinit = tree_to_shwi(t);
+ initAttr = builder.getI64IntegerAttr(sinit);
+ } else if (tree_fits_uhwi_p(t)) {
+ unsigned HOST_WIDE_INT uinit = tree_to_uhwi(t);
+ initAttr = builder.getI64IntegerAttr(uinit);
+ } else {
+ abort();
+ }
opValue = builder.create<ConstOp>(
builder.getUnknownLoc(), treeId, IDefineCode::IntCST,
readOnly, initAttr, rPluginType);
--
2.27.0.windows.1

File diff suppressed because it is too large Load Diff

View File

@ -1,839 +0,0 @@
From 1e14f9e453c9504cff141ce9059c0eeb405e73ed Mon Sep 17 00:00:00 2001
From: huitailangzju <804544223@qq.com>
Date: Tue, 7 Feb 2023 19:18:42 +0800
Subject: [PATCH 3/9] [Refactoring] Code refactoring of Communication Subsystem
[2/3]. Add PluginGrpcPort, PluginInputCheck and PluginJson.
diff --git a/lib/PluginClient/PluginGrpcPort.cpp b/lib/PluginClient/PluginGrpcPort.cpp
new file mode 100755
index 0000000..c6b9a1f
--- /dev/null
+++ b/lib/PluginClient/PluginGrpcPort.cpp
@@ -0,0 +1,159 @@
+/* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the implementation of the PluginGrpcPort class.
+ 主要完成功能:查找未使用的端口号,并将端口号写入到共享文件中,通过文件锁控制多进程间访问,并提供
+ DeletePortFromLockFile接口在退出时删除写入的端口号
+*/
+
+#include <fstream>
+#include <cstring>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "PluginClient/PluginLog.h"
+#include "PluginClient/PluginGrpcPort.h"
+
+namespace PinClient {
+int PluginGrpcPort::OpenFile(const char *path)
+{
+ int portFileFd = -1;
+ if (access(path, F_OK) == -1) {
+ mode_t mask = umask(0);
+ mode_t mode = 0666; // 权限是rwrwrw跨进程时其他用户也要可以访问
+ portFileFd = open(path, O_CREAT | O_RDWR, mode);
+ umask(mask);
+ } else {
+ portFileFd = open(path, O_RDWR);
+ }
+
+ if (portFileFd == -1) {
+ LOGE("open file %s fail\n", path);
+ }
+ return portFileFd;
+}
+
+bool PluginGrpcPort::ReadPortsFromLockFile(int fd, string& grpcPorts)
+{
+ if (flock(fd, LOCK_EX) != 0) {
+ return false;
+ }
+
+ int fileLen = lseek(fd, 0, SEEK_END);
+ lseek(fd, 0, SEEK_SET);
+ char *buf = new char[fileLen + 1];
+ if (buf == NULL) {
+ return false;
+ }
+ if (read(fd, buf, fileLen) < 0) {
+ return false;
+ }
+ buf[fileLen] = '\0';
+ grpcPorts = buf;
+ delete[] buf;
+ return true;
+}
+
+bool PluginGrpcPort::FindUnusedPort()
+{
+ unsigned short basePort = GetBasePort();
+ int portFileFd = OpenFile(lockFilePath.c_str());
+ if (portFileFd == -1) {
+ return false;
+ }
+
+ string grpcPorts = "";
+ if (!ReadPortsFromLockFile(portFileFd, grpcPorts)) {
+ close(portFileFd);
+ return false;
+ }
+
+ // 不使用UINT16_MAX端口号端口号为UINT16_MAX时作异常处理
+ while (++basePort < UINT16_MAX) {
+ int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ struct sockaddr_in serverAddr;
+ memset(&serverAddr, 0, sizeof(serverAddr));
+ serverAddr.sin_family = AF_INET;
+ serverAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
+ serverAddr.sin_port = htons(basePort);
+ int ret = connect(sock, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
+ if (sock != -1) {
+ close(sock);
+ }
+ if ((ret == -1) && (errno == ECONNREFUSED)) {
+ string strPort = std::to_string(basePort) + "\n";
+ if (grpcPorts.find(strPort) == grpcPorts.npos) {
+ port = basePort;
+ LOGI("found port:%d\n", port);
+ lseek(portFileFd, 0, SEEK_END);
+ write(portFileFd, strPort.c_str(), strPort.size());
+ break;
+ }
+ }
+ }
+
+ if (basePort == UINT16_MAX) {
+ ftruncate(portFileFd, 0); // 清空锁文件,避免异常未删除释放的端口号,导致无端口使用
+ lseek(portFileFd, 0, SEEK_SET);
+ close(portFileFd); // 关闭文件fd会同时释放文件锁
+ return false;
+ }
+
+ close(portFileFd); // 关闭文件fd会同时释放文件锁
+ return true;
+}
+
+bool PluginGrpcPort::DeletePortFromLockFile()
+{
+ if (port == 0) {
+ return true;
+ }
+ int portFileFd = open(lockFilePath.c_str(), O_RDWR);
+ if (portFileFd == -1) {
+ LOGE("%s open file %s fail\n", __func__, lockFilePath.c_str());
+ return false;
+ }
+ LOGI("delete port:%d\n", port);
+
+ string grpcPorts = "";
+ if (!ReadPortsFromLockFile(portFileFd, grpcPorts)) {
+ close(portFileFd);
+ port = 0;
+ return false;
+ }
+
+ string portStr = std::to_string(port) + "\n";
+ string::size_type pos = grpcPorts.find(portStr);
+ if (pos == string::npos) {
+ close(portFileFd);
+ port = 0;
+ return true;
+ }
+ grpcPorts = grpcPorts.erase(pos, portStr.size());
+
+ ftruncate(portFileFd, 0);
+ lseek(portFileFd, 0, SEEK_SET);
+ write(portFileFd, grpcPorts.c_str(), grpcPorts.size());
+ close(portFileFd);
+ port = 0;
+ return true;
+}
+} // namespace PinClient
diff --git a/lib/PluginClient/PluginInputCheck.cpp b/lib/PluginClient/PluginInputCheck.cpp
new file mode 100755
index 0000000..12cfcdc
--- /dev/null
+++ b/lib/PluginClient/PluginInputCheck.cpp
@@ -0,0 +1,194 @@
+/* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the implementation of the PluginInputCheck class.
+*/
+
+#include <fstream>
+#include "PluginClient/PluginInputCheck.h"
+
+namespace PinClient {
+// 对server可执行文件进行检查,后续可以在此函数中扩展是否可执行,文件权限等检查
+int PluginInputCheck::CheckServerFile()
+{
+ int ret = access(serverPath.c_str(), F_OK);
+ return ret;
+}
+
+// 对sha256文件进行检查,后续可以在此函数中扩展文件权限、是否为空等检查
+int PluginInputCheck::CheckShaFile()
+{
+ int ret = access(shaPath.c_str(), F_OK);
+ return ret;
+}
+
+bool PluginInputCheck::ReadConfigfile(Json::Value& root)
+{
+ Json::Reader reader;
+ std::ifstream ifs(configFilePath.c_str());
+ if (!ifs.is_open()) {
+ LOGW("open %s fail! use default sha256file:%s\n", configFilePath.c_str(), shaPath.c_str());
+ return false;
+ }
+
+ if (!reader.parse(ifs, root)) {
+ printf("parse %s fail! check the file format!\n", configFilePath.c_str());
+ ifs.close();
+ return false;
+ }
+
+ ifs.close();
+ return true;
+}
+
+void PluginInputCheck::SetTimeout(int time)
+{
+ const int timeoutMin = 50;
+ const int timeoutMax = 5000;
+ if ((time >= timeoutMin) && (time <= timeoutMax)) { // 不在50~5000ms范围内使用默认值
+ timeout = time;
+ LOGI("the timeout is:%d\n", timeout);
+ return;
+ }
+ LOGW("SetTimeout:%d,should be 50~5000,use default:%d\n", time, timeout);
+}
+
+int PluginInputCheck::GetInitInfo()
+{
+ Json::Value root;
+ if (!ReadConfigfile(root)) {
+ return -1;
+ }
+
+ if (serverPath == "") {
+ if (root[jsonkey[PATH]].isString()) {
+ serverPath = root[jsonkey[PATH]].asString();
+ } else {
+ LOGW("serverPath in config.json is not string!\n");
+ }
+ }
+ if (CheckServerFile() != 0) {
+ LOGE("serverPath:%s not exist!\n", serverPath.c_str());
+ serverPath = "";
+ return -1;
+ }
+
+ if (root[jsonkey[TIMEOUT]].isInt()) {
+ int timeoutJson = root[jsonkey[TIMEOUT]].asInt();
+ SetTimeout(timeoutJson);
+ }
+
+ if (root[jsonkey[SHA256]].isString()) {
+ shaPath = root[jsonkey[SHA256]].asString();
+ } else {
+ LOGW("sha256file int config.json is not string!\n");
+ }
+
+ if ((shaPath == "") || (CheckShaFile() != 0)) {
+ shaPath = GetServerDir() + shaFile; // sha256文件默认和server在同一目录
+ LOGW("sha256 file not found,use default:%s\n", shaPath.c_str());
+ }
+ return 0;
+}
+
+std::map<string, int> g_keyMap {
+ {"server_path", KEY_SERVER_PATH},
+ {"log_level", KEY_LOG_LEVEL},
+};
+void PluginInputCheck::GetInputArgs(struct plugin_name_args *pluginInfo)
+{
+ Json::Value root;
+ map<string, string> compileArgs;
+
+ for (int i = 0; i < pluginInfo->argc; i++) {
+ string key = pluginInfo->argv[i].key;
+ int keyTag = -1;
+ auto it = g_keyMap.find(key);
+ if (it != g_keyMap.end()) {
+ keyTag = it->second;
+ }
+ switch (keyTag) {
+ case KEY_SERVER_PATH:
+ serverPath = pluginInfo->argv[i].value;
+ if (serverPath != "") {
+ configFilePath = GetServerDir() + "/pin-gcc-client.json"; // 配置文件和server在同一目录
+ shaPath = GetServerDir() + shaFile; // sha256文件默认和server在同一目录
+ }
+ break;
+ case KEY_LOG_LEVEL:
+ logLevel = (LogPriority)atoi(pluginInfo->argv[i].value);
+ SetLogPriority(logLevel);
+ break;
+ default:
+ string value = pluginInfo->argv[i].value;
+ compileArgs[key] = value;
+ root[key] = value;
+ break;
+ }
+ }
+
+ args = root.toStyledString();
+ for (auto it = compileArgs.begin(); it != compileArgs.end(); it++) {
+ CheckSafeCompileFlag(it->first, it->second);
+ }
+}
+
+int PluginInputCheck::CheckSHA256()
+{
+ if (shaPath == "") {
+ LOGE("sha256file Path is NULL!\n");
+ return -1;
+ }
+ int index = shaPath.find_last_of("/");
+ string dir = shaPath.substr(0, index);
+ string filename = shaPath.substr(index+1, -1);
+
+ string cmd = "cd " + dir + " && " + "sha256sum -c " + filename + " --quiet";
+ int ret = system(cmd.c_str());
+ return ret;
+}
+
+void PluginInputCheck::CheckSafeCompileFlag(const string& argName, const string& param)
+{
+ for (auto& compileFlag : safeCompileFlags) {
+ if (param.find(compileFlag) != string::npos) {
+ LOGW("%s:%s have safe compile parameter:%s !!!\n", argName.c_str(), param.c_str(), compileFlag.c_str());
+ }
+ }
+}
+
+PluginInputCheck::PluginInputCheck()
+{
+ shaPath = "";
+ serverPath = "";
+ logLevel = PRIORITY_WARN;
+ timeout = 200; // 默认超时时间200ms
+ SetConfigPath("/usr/local/bin/pin-gcc-client.json");
+ safeCompileFlags.push_back("-z noexecstack");
+ safeCompileFlags.push_back("-fno-stack-protector");
+ safeCompileFlags.push_back("-fstack-protector-all");
+ safeCompileFlags.push_back("-D_FORTIFY_SOURCE");
+ safeCompileFlags.push_back("-fPic");
+ safeCompileFlags.push_back("-fPIE");
+ safeCompileFlags.push_back("-fstack-protector-strong");
+ safeCompileFlags.push_back("-fvisibility");
+ safeCompileFlags.push_back("-ftrapv");
+ safeCompileFlags.push_back("-fstack-check");
+}
+} // namespace PinClient
diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp
new file mode 100755
index 0000000..22cd489
--- /dev/null
+++ b/lib/PluginClient/PluginJson.cpp
@@ -0,0 +1,458 @@
+/* Copyright (c) 2022-2022 Huawei Technologies Co., Ltd.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the implementation of the PluginJson class.
+*/
+
+#include <json/json.h>
+#include "PluginAPI/PluginClientAPI.h"
+#include "PluginClient/PluginLog.h"
+#include "PluginClient/PluginJson.h"
+
+namespace PinClient {
+using std::map;
+using namespace mlir::Plugin;
+using namespace mlir;
+
+static uintptr_t GetID(Json::Value node)
+{
+ string id = node.asString();
+ return atol(id.c_str());
+}
+
+Json::Value PluginJson::TypeJsonSerialize(PluginIR::PluginTypeBase& type)
+{
+ Json::Value root;
+ Json::Value operationObj;
+ Json::Value item;
+
+ uint64_t ReTypeId;
+ uint64_t ReTypeWidth;
+
+ 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 (elemTy.isReadOnlyElem()) {
+ item["elemConst"] = "1";
+ } else {
+ item["elemConst"] = "0";
+ }
+ }
+
+ if (type.getPluginIntOrFloatBitWidth() != 0) {
+ ReTypeWidth = type.getPluginIntOrFloatBitWidth();
+ item["width"] = std::to_string(ReTypeWidth);
+ }
+
+ if (type.isSignedPluginInteger()) {
+ item["signed"] = "1";
+ }
+
+ if (type.isUnsignedPluginInteger()) {
+ item["signed"] = "0";
+ }
+
+ root["type"] = item;
+ return root;
+}
+
+PluginIR::PluginTypeBase PluginJson::TypeJsonDeSerialize(const string& data, mlir::MLIRContext &context)
+{
+ Json::Value root;
+ Json::Reader reader;
+ Json::Value node;
+ reader.parse(data, root);
+
+ PluginIR::PluginTypeBase baseType;
+
+ Json::Value type = root["type"];
+ uint64_t id = GetID(type["id"]);
+ PluginIR::PluginTypeID PluginTypeId = static_cast<PluginIR::PluginTypeID>(id);
+
+ if (type["signed"] && (id >= static_cast<uint64_t>(PluginIR::UIntegerTy1ID)
+ && id <= static_cast<uint64_t>(PluginIR::IntegerTy64ID))) {
+ string s = type["signed"].asString();
+ uint64_t width = GetID(type["width"]);
+ if (s == "1") {
+ baseType = PluginIR::PluginIntegerType::get(&context, width, PluginIR::PluginIntegerType::Signed);
+ } else {
+ baseType = PluginIR::PluginIntegerType::get(&context, width, PluginIR::PluginIntegerType::Unsigned);
+ }
+ } else if (type["width"] && (id == static_cast<uint64_t>(PluginIR::FloatTyID)
+ || id == static_cast<uint64_t>(PluginIR::DoubleTyID))) {
+ uint64_t width = GetID(type["width"]);
+ baseType = PluginIR::PluginFloatType::get(&context, width);
+ } else if (id == static_cast<uint64_t>(PluginIR::PointerTyID)) {
+ mlir::Type elemTy = TypeJsonDeSerialize(type["elementType"].toStyledString(), context);
+ baseType = PluginIR::PluginPointerType::get(&context, elemTy, type["elemConst"].asString() == "1" ? 1 : 0);
+ } else {
+ if (PluginTypeId == PluginIR::VoidTyID) {
+ baseType = PluginIR::PluginVoidType::get(&context);
+ }
+ if (PluginTypeId == PluginIR::BooleanTyID) {
+ baseType = PluginIR::PluginBooleanType::get(&context);
+ }
+ if (PluginTypeId == PluginIR::UndefTyID) {
+ baseType = PluginIR::PluginUndefType::get(&context);
+ }
+ }
+
+ return baseType;
+}
+
+void PluginJson::FunctionOpJsonSerialize(vector<FunctionOp>& data, string& out)
+{
+ Json::Value root;
+ Json::Value operationObj;
+ Json::Value item;
+
+ int i = 0;
+ string operation;
+
+ for (auto& d: data) {
+ item["id"] = std::to_string(d.idAttr().getInt());
+ if (d.declaredInlineAttr().getValue()) {
+ item["attributes"]["declaredInline"] = "1";
+ } else {
+ item["attributes"]["declaredInline"] = "0";
+ }
+ item["attributes"]["funcName"] = d.funcNameAttr().getValue().str().c_str();
+ auto &region = d.getRegion();
+ size_t bbIdx = 0;
+ for (auto &b : region) {
+ string blockStr = "block" + std::to_string(bbIdx++);
+ uint64_t bbAddress = 0;
+ size_t opIdx = 0;
+ for (auto &inst : b) {
+ if (isa<PlaceholderOp>(inst)) {
+ continue;
+ } else if (isa<SSAOp>(inst)) {
+ continue;
+ } else if (isa<MemOp>(inst)) {
+ continue;
+ } else if (isa<ConstOp>(inst)) {
+ continue;
+ }
+ string opStr = "Operation" + std::to_string(opIdx++);
+ item["region"][blockStr]["ops"][opStr] = OperationJsonSerialize(&inst, bbAddress);
+ }
+ assert(bbAddress != 0);
+ item["region"][blockStr]["address"] = std::to_string(bbAddress);
+ }
+ operation = "FunctionOp" + std::to_string(i++);
+ root[operation] = item;
+ item.clear();
+ }
+ out = root.toStyledString();
+}
+
+Json::Value PluginJson::OperationJsonSerialize(mlir::Operation *operation, uint64_t &bbId)
+{
+ Json::Value root;
+ if (AssignOp op = llvm::dyn_cast<AssignOp>(operation)) {
+ root = AssignOpJsonSerialize(op);
+ } else if (CallOp op = llvm::dyn_cast<CallOp>(operation)) {
+ root = CallOpJsonSerialize(op);
+ } else if (CondOp op = llvm::dyn_cast<CondOp>(operation)) {
+ root = CondOpJsonSerialize(op, bbId);
+ } else if (PhiOp op = llvm::dyn_cast<PhiOp>(operation)) {
+ root = PhiOpJsonSerialize(op);
+ } else if (FallThroughOp op = llvm::dyn_cast<FallThroughOp>(operation)) {
+ root = FallThroughOpJsonSerialize(op, bbId);
+ } else if (RetOp op = llvm::dyn_cast<RetOp>(operation)) {
+ root = RetOpJsonSerialize(op, bbId);
+ } else if (BaseOp op = llvm::dyn_cast<BaseOp>(operation)) {
+ root = BaseOpJsonSerialize(op);
+ }
+ root["OperationName"] = operation->getName().getStringRef().str();
+ return root;
+}
+
+Json::Value PluginJson::BaseOpJsonSerialize(BaseOp data)
+{
+ Json::Value root;
+ root["id"] = std::to_string(data.idAttr().getInt());
+ root["opCode"] = data.opCodeAttr().getValue().str().c_str();
+ return root;
+}
+
+Json::Value PluginJson::RetOpJsonSerialize(RetOp data, uint64_t &bbId)
+{
+ Json::Value root;
+ bbId = data.addressAttr().getInt();
+ root["address"] = std::to_string(bbId);
+ return root;
+}
+
+Json::Value PluginJson::FallThroughOpJsonSerialize(FallThroughOp data, uint64_t &bbId)
+{
+ Json::Value root;
+ bbId = data.addressAttr().getInt();
+ root["address"] = std::to_string(bbId);
+ root["destaddr"] = std::to_string(data.destaddrAttr().getInt());
+ return root;
+}
+
+void PluginJson::LocalDeclsJsonSerialize(vector<LocalDeclOp>& decls, string& out)
+{
+ Json::Value root;
+ Json::Value operationObj;
+ Json::Value item;
+ int i = 0;
+ string operation;
+
+ for (auto& decl: decls) {
+ item["id"] = std::to_string(decl.idAttr().getInt());
+ item["attributes"]["symName"] = decl.symNameAttr().getValue().str().c_str();
+ item["attributes"]["typeID"] = decl.typeIDAttr().getInt();
+ item["attributes"]["typeWidth"] = decl.typeWidthAttr().getInt();
+ operation = "localDecl" + std::to_string(i++);
+ root[operation] = item;
+ item.clear();
+ }
+ out = root.toStyledString();
+}
+
+void PluginJson::LoopOpsJsonSerialize(vector<mlir::Plugin::LoopOp>& loops, string& out)
+{
+ Json::Value root;
+ Json::Value operationObj;
+ Json::Value item;
+ int i = 0;
+ string operation;
+
+ for (auto& loop: loops) {
+ item["id"] = std::to_string(loop.idAttr().getInt());
+ item["index"] = std::to_string(loop.indexAttr().getInt());
+ item["attributes"]["innerLoopId"] = std::to_string(loop.innerLoopIdAttr().getInt());
+ item["attributes"]["outerLoopId"] = std::to_string(loop.outerLoopIdAttr().getInt());
+ item["attributes"]["numBlock"] = std::to_string(loop.numBlockAttr().getInt());
+ operation = "loopOp" + std::to_string(i++);
+ root[operation] = item;
+ item.clear();
+ }
+ out = root.toStyledString();
+}
+
+void PluginJson::LoopOpJsonSerialize(mlir::Plugin::LoopOp& loop, string& out)
+{
+ Json::Value root;
+ root["id"] = std::to_string(loop.idAttr().getInt());
+ root["index"] = std::to_string(loop.indexAttr().getInt());
+ root["attributes"]["innerLoopId"] = std::to_string(loop.innerLoopIdAttr().getInt());
+ root["attributes"]["outerLoopId"] = std::to_string(loop.outerLoopIdAttr().getInt());
+ root["attributes"]["numBlock"] = std::to_string(loop.numBlockAttr().getInt());
+ out = root.toStyledString();
+}
+
+void PluginJson::BlocksJsonSerialize(vector<uint64_t>& blocks, string& out)
+{
+ Json::Value root;
+ Json::Value item;
+ int i = 0;
+ string index;
+
+ for (auto& block : blocks) {
+ item["id"] = std::to_string(block);
+ index = "block" + std::to_string(i++);
+ root[index] = item;
+ item.clear();
+ }
+ out = root.toStyledString();
+}
+
+void PluginJson::EdgesJsonSerialize(vector<std::pair<uint64_t, uint64_t> >& edges, string& out)
+{
+ Json::Value root;
+ Json::Value item;
+ int i = 0;
+ string index;
+
+ for (auto& edge : edges) {
+ item["src"] = std::to_string(edge.first);
+ item["dest"] = std::to_string(edge.second);
+ index = "edge" + std::to_string(i++);
+ root[index] = item;
+ item.clear();
+ }
+ out = root.toStyledString();
+}
+
+void PluginJson::EdgeJsonSerialize(std::pair<uint64_t, uint64_t>& edge, string& out)
+{
+ Json::Value root;
+ root["src"] = std::to_string(edge.first);
+ root["dest"] = std::to_string(edge.second);
+ out = root.toStyledString();
+}
+
+// void类型的Json序列化
+void PluginJson::NopJsonSerialize(string& out)
+{
+ Json::Value root;
+ out = root.toStyledString();
+}
+
+void PluginJson::GetPhiOpsJsonSerialize(vector<PhiOp> phiOps, string & out)
+{
+ Json::Value root;
+ Json::Value item;
+ int i = 0;
+ string operation;
+ uint64_t placeholder = 0;
+ for (auto phi : phiOps) {
+ item = OperationJsonSerialize(phi.getOperation(), placeholder);
+ operation = "operation" + std::to_string(i++);
+ root[operation] = item;
+ item.clear();
+ }
+ out = root.toStyledString();
+}
+
+Json::Value PluginJson::CallOpJsonSerialize(CallOp& data)
+{
+ Json::Value item;
+ item["id"] = std::to_string(data.idAttr().getInt());
+ item["callee"] = data.callee().str();
+ item["OperationName"] = data.getOperation()->getName().getStringRef().str();
+ size_t opIdx = 0;
+ for (mlir::Value v : data.getArgOperands()) {
+ string input = "input" + std::to_string(opIdx++);
+ item["operands"][input] = ValueJsonSerialize(v);
+ }
+
+ return item;
+}
+
+Json::Value PluginJson::CondOpJsonSerialize(CondOp& data, uint64_t &bbId)
+{
+ Json::Value item;
+ item["id"] = std::to_string(data.idAttr().getInt());
+ item["condCode"] = std::to_string(data.condCodeAttr().getInt());
+ item["lhs"] = ValueJsonSerialize(data.GetLHS());
+ item["rhs"] = ValueJsonSerialize(data.GetRHS());
+ bbId = data.addressAttr().getInt();
+ item["address"] = std::to_string(bbId);
+ item["tbaddr"] = std::to_string(data.tbaddrAttr().getInt());
+ item["fbaddr"] = std::to_string(data.fbaddrAttr().getInt());
+ return item;
+}
+
+Json::Value PluginJson::PhiOpJsonSerialize(PhiOp& data)
+{
+ Json::Value item;
+ item["id"] = std::to_string(data.idAttr().getInt());
+ item["capacity"] = std::to_string(data.capacityAttr().getInt());
+ item["nArgs"] = std::to_string(data.nArgsAttr().getInt());
+ item["OperationName"] = data.getOperation()->getName().getStringRef().str();
+ size_t opIdx = 0;
+ for (mlir::Value v : data.operands()) {
+ string input = "input" + std::to_string(opIdx++);
+ item["operands"][input] = ValueJsonSerialize(v);
+ }
+
+ return item;
+}
+
+Json::Value PluginJson::SSAOpJsonSerialize(SSAOp& data)
+{
+ Json::Value item;
+ item["id"] = std::to_string(data.idAttr().getInt());
+ item["defCode"] = std::to_string(data.defCodeAttr().getInt());
+ item["readOnly"] = std::to_string(data.readOnlyAttr().getValue());
+ item["nameVarId"] = std::to_string(data.nameVarIdAttr().getInt());
+ item["ssaParmDecl"] = std::to_string(data.ssaParmDeclAttr().getInt());
+ item["version"] = std::to_string(data.versionAttr().getInt());
+ item["definingId"] = std::to_string(data.definingIdAttr().getInt());
+ auto retTy = data.getResultType().dyn_cast<PluginIR::PluginTypeBase>();
+ item["retType"] = TypeJsonSerialize(retTy);
+ return item;
+}
+
+Json::Value PluginJson::AssignOpJsonSerialize(AssignOp& data)
+{
+ Json::Value item;
+ item["id"] = std::to_string(data.idAttr().getInt());
+ item["exprCode"] = std::to_string(data.exprCodeAttr().getInt());
+ item["OperationName"] = data.getOperation()->getName().getStringRef().str();
+ size_t opIdx = 0;
+ for (mlir::Value v : data.operands()) {
+ string input = "input" + std::to_string(opIdx++);
+ item["operands"][input] = ValueJsonSerialize(v);
+ }
+
+ return item;
+}
+
+Json::Value PluginJson::ValueJsonSerialize(mlir::Value data)
+{
+ Json::Value root;
+ if (ConstOp cOp = data.getDefiningOp<ConstOp>()) {
+ auto retTy = data.getType().dyn_cast<PluginIR::PluginTypeBase>();
+ root["retType"] = TypeJsonSerialize(retTy);
+ root["id"] = std::to_string(cOp.idAttr().getInt());
+ root["defCode"] = std::to_string(static_cast<int32_t>(IDefineCode::IntCST));
+ root["value"] = std::to_string(cOp.initAttr().cast<mlir::IntegerAttr>().getInt());
+ } else if (MemOp mOp = data.getDefiningOp<MemOp>()) {
+ root = MemOpJsonSerialize(mOp);
+ } else if (SSAOp sOp = data.getDefiningOp<SSAOp>()) {
+ root = SSAOpJsonSerialize(sOp);
+ } else if (PlaceholderOp phOp = data.getDefiningOp<PlaceholderOp>()) {
+ root["id"] = std::to_string(phOp.idAttr().getInt());
+ root["defCode"] = std::to_string(phOp.defCodeAttr().getInt());
+ auto retTy = phOp.getResultType().dyn_cast<PluginIR::PluginTypeBase>();
+ root["retType"] = TypeJsonSerialize(retTy);
+ } else {
+ LOGE("ERROR: Can't Serialize!");
+ }
+ return root;
+}
+
+Json::Value PluginJson::MemOpJsonSerialize(MemOp& data)
+{
+ Json::Value root;
+ root["id"] = std::to_string(data.idAttr().getInt());
+ root["defCode"] = std::to_string(data.defCodeAttr().getInt());
+ root["readOnly"] = std::to_string(data.readOnlyAttr().getValue());
+ mlir::Value base = data.GetBase();
+ mlir::Value offset = data.GetOffset();
+ root["base"] = ValueJsonSerialize(base);
+ root["offset"] = ValueJsonSerialize(offset);
+ auto retTy = data.getResultType().dyn_cast<PluginIR::PluginTypeBase>();
+ root["retType"] = TypeJsonSerialize(retTy);
+ return root;
+}
+
+void PluginJson::IntegerSerialize(int64_t data, string& out)
+{
+ Json::Value root;
+ root["integerData"] = data;
+ out = root.toStyledString();
+}
+
+void PluginJson::StringSerialize(const string& data, string& out)
+{
+ Json::Value root;
+ root["stringData"] = data;
+ out = root.toStyledString();
+}
+} // namespace PinClient
--
2.27.0.windows.1

File diff suppressed because it is too large Load Diff

View File

@ -1,106 +0,0 @@
From c0da500cd20a295521d650cfcdb277b66d18bba5 Mon Sep 17 00:00:00 2001
From: benniaobufeijiushiji <linda7@huawei.com>
Date: Sun, 19 Feb 2023 11:44:30 +0800
Subject: [PATCH 5/9] [Pin-gcc-client] Add DebugOp
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index c48d002..bac84be 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -235,6 +235,16 @@ def BaseOp : Plugin_Op<"statement_base", [NoSideEffect]> {
];
}
+def DebugOp : Plugin_Op<"debug", [NoSideEffect]> {
+ let summary = "DebugOp.";
+ let description = [{TODO}];
+ let arguments = (ins UI64Attr:$id);
+ let results = (outs AnyType);
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id)>
+ ];
+}
+
// Terminators
// Opaque builder used for terminator operations that contain successors.
diff --git a/include/PluginClient/PluginJson.h b/include/PluginClient/PluginJson.h
index 91bd925..a0aac8a 100755
--- a/include/PluginClient/PluginJson.h
+++ b/include/PluginClient/PluginJson.h
@@ -53,6 +53,7 @@ public:
Json::Value PhiOpJsonSerialize(mlir::Plugin::PhiOp& data);
Json::Value AssignOpJsonSerialize(mlir::Plugin::AssignOp& data);
Json::Value BaseOpJsonSerialize(mlir::Plugin::BaseOp data);
+ Json::Value DebugOpJsonSerialize(mlir::Plugin::DebugOp data);
Json::Value FallThroughOpJsonSerialize(mlir::Plugin::FallThroughOp data, uint64_t&);
Json::Value RetOpJsonSerialize(mlir::Plugin::RetOp data, uint64_t&);
Json::Value ValueJsonSerialize(mlir::Value value);
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index 052ebfd..da5f3f3 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -243,6 +243,15 @@ void BaseOp::build(OpBuilder &builder, OperationState &state, uint64_t id, Strin
state.addAttribute("opCode", builder.getStringAttr(opCode));
}
+//===----------------------------------------------------------------------===//
+// DebugOp
+
+void DebugOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+}
+
// ===----------------------------------------------------------------------===//
// FallThroughOp
diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp
index 22cd489..ccadf10 100755
--- a/lib/PluginClient/PluginJson.cpp
+++ b/lib/PluginClient/PluginJson.cpp
@@ -182,6 +182,8 @@ Json::Value PluginJson::OperationJsonSerialize(mlir::Operation *operation, uint6
root = RetOpJsonSerialize(op, bbId);
} else if (BaseOp op = llvm::dyn_cast<BaseOp>(operation)) {
root = BaseOpJsonSerialize(op);
+ } else if (DebugOp op = llvm::dyn_cast<DebugOp>(operation)) {
+ root = DebugOpJsonSerialize(op);
}
root["OperationName"] = operation->getName().getStringRef().str();
return root;
@@ -203,6 +205,13 @@ Json::Value PluginJson::RetOpJsonSerialize(RetOp data, uint64_t &bbId)
return root;
}
+Json::Value PluginJson::DebugOpJsonSerialize(DebugOp data)
+{
+ Json::Value root;
+ root["id"] = std::to_string(data.idAttr().getInt());
+ return root;
+}
+
Json::Value PluginJson::FallThroughOpJsonSerialize(FallThroughOp data, uint64_t &bbId)
{
Json::Value root;
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index b5974aa..2f46f6f 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -579,6 +579,12 @@ Operation *GimpleToPluginOps::BuildOperation(uint64_t id)
ret = condOp.getOperation();
break;
}
+ case GIMPLE_DEBUG: {
+ DebugOp debugOp = builder.create<DebugOp>(
+ builder.getUnknownLoc(), id);
+ ret = debugOp.getOperation();
+ break;
+ }
default: {
BaseOp baseOp = builder.create<BaseOp>(
builder.getUnknownLoc(), id, BaseOp::getOperationName());
--
2.27.0.windows.1

View File

@ -1,38 +0,0 @@
From 3750fd8c57d37a103b698eb7e479a98ccc68bd02 Mon Sep 17 00:00:00 2001
From: benniaobufeijiushiji <linda7@huawei.com>
Date: Sun, 19 Feb 2023 11:48:16 +0800
Subject: [PATCH 6/9] [Pin-gcc-client] Bugfix for ConstOp Support both signed
const int and unsigned const int
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index 2f46f6f..5ecab75 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -840,13 +840,16 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId)
mlir::Value opValue;
switch (TREE_CODE(t)) {
case INTEGER_CST : {
- unsigned HOST_WIDE_INT init = tree_to_uhwi(t);
- // FIXME : AnyAttr!
- mlir::Attribute initAttr = builder.getI64IntegerAttr(init);
- opValue = builder.create<ConstOp>(
- builder.getUnknownLoc(), treeId, IDefineCode::IntCST,
- readOnly, initAttr, rPluginType);
- break;
+ mlir::Attribute initAttr;
+ if (tree_fits_shwi_p(t)) {
+ signed HOST_WIDE_INT sinit = tree_to_shwi(t);
+ initAttr = builder.getI64IntegerAttr(sinit);
+ } else if (tree_fits_uhwi_p(t)) {
+ unsigned HOST_WIDE_INT uinit = tree_to_uhwi(t);
+ initAttr = builder.getI64IntegerAttr(uinit);
+ } else {
+ abort();
+ }
}
case MEM_REF : {
tree operand0 = TREE_OPERAND(t, 0);
--
2.27.0.windows.1

View File

@ -1,131 +0,0 @@
From 9dc1cc4cb0eeb114ac9b5daea3005f2caa1ccf5b Mon Sep 17 00:00:00 2001
From: benniaobufeijiushiji <linda7@huawei.com>
Date: Sun, 19 Feb 2023 14:41:49 +0800
Subject: [PATCH 7/9] [Pin-gcc-client] Add API for LTO judgement
diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h
index 8c47c58..ca74588 100644
--- a/include/PluginAPI/BasicPluginOpsAPI.h
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
@@ -95,6 +95,9 @@ public:
virtual mlir::Value BuildMemRef(PluginTypeBase, uint64_t, uint64_t) = 0;
virtual void RedirectFallthroughTarget(uint64_t, uint64_t) = 0;
virtual void RemoveEdge(uint64_t, uint64_t) = 0;
+
+ virtual bool IsLtoOptimize() = 0;
+ virtual bool IsWholeProgram() = 0;
}; // class BasicPluginOpsAPI
} // namespace PluginAPI
diff --git a/include/PluginAPI/PluginClientAPI.h b/include/PluginAPI/PluginClientAPI.h
index 07d6e52..727d329 100644
--- a/include/PluginAPI/PluginClientAPI.h
+++ b/include/PluginAPI/PluginClientAPI.h
@@ -95,6 +95,9 @@ public:
void RedirectFallthroughTarget(uint64_t, uint64_t) override;
void RemoveEdge(uint64_t, uint64_t) override;
+
+ bool IsLtoOptimize() override;
+ bool IsWholeProgram() override;
private:
PluginIR::GimpleToPluginOps gimpleConversion;
}; // class PluginClientAPI
diff --git a/include/Translate/GimpleToPluginOps.h b/include/Translate/GimpleToPluginOps.h
index 5f8bdf0..2ecf5ac 100644
--- a/include/Translate/GimpleToPluginOps.h
+++ b/include/Translate/GimpleToPluginOps.h
@@ -106,6 +106,10 @@ public:
void RedirectFallthroughTarget(uint64_t, uint64_t);
void RemoveEdge(uint64_t, uint64_t);
+
+ bool IsLtoOptimize();
+ bool IsWholeProgram();
+
private:
GimpleToPluginOps () = delete;
mlir::OpBuilder builder;
diff --git a/lib/PluginAPI/PluginClientAPI.cpp b/lib/PluginAPI/PluginClientAPI.cpp
index 5e454d7..362ede1 100644
--- a/lib/PluginAPI/PluginClientAPI.cpp
+++ b/lib/PluginAPI/PluginClientAPI.cpp
@@ -280,4 +280,14 @@ void PluginClientAPI::RemoveEdge(uint64_t src, uint64_t dest)
return gimpleConversion.RemoveEdge(src, dest);
}
+bool PluginClientAPI::IsLtoOptimize()
+{
+ return gimpleConversion.IsLtoOptimize();
+}
+
+bool PluginClientAPI::IsWholeProgram()
+{
+ return gimpleConversion.IsWholeProgram();
+}
+
} // namespace PluginAPI
\ No newline at end of file
diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp
index 18877c2..81b59c0 100644
--- a/lib/PluginClient/PluginClient.cpp
+++ b/lib/PluginClient/PluginClient.cpp
@@ -820,6 +820,24 @@ void DebugValueResult(PluginClient *client, Json::Value& root, string& result)
client->ReceiveSendMsg("ValueResult", result);
}
+void IsLtoOptimizeResult(PluginClient *client, Json::Value& root, string& result)
+{
+ mlir::MLIRContext context;
+ context.getOrLoadDialect<PluginDialect>();
+ PluginAPI::PluginClientAPI clientAPI(context);
+ bool lto = clientAPI.IsLtoOptimize();
+ client->ReceiveSendMsg("BoolResult", std::to_string(lto));
+}
+
+void IsWholeProgramResult(PluginClient *client, Json::Value& root, string& result)
+{
+ mlir::MLIRContext context;
+ context.getOrLoadDialect<PluginDialect>();
+ PluginAPI::PluginClientAPI clientAPI(context);
+ bool wholePR = clientAPI.IsWholeProgram();
+ client->ReceiveSendMsg("BoolResult", std::to_string(wholePR));
+}
+
typedef std::function<void(PluginClient*, Json::Value&, string&)> GetResultFunc;
std::map<string, GetResultFunc> g_getResultFunc = {
{"GetAllFunc", GetAllFuncResult},
@@ -868,6 +886,8 @@ std::map<string, GetResultFunc> g_getResultFunc = {
{"ConfirmValue", ConfirmValueResult},
{"BuildMemRef", BuildMemRefResult},
{"DebugValue", DebugValueResult},
+ {"IsLtoOptimize",IsLtoOptimizeResult},
+ {"IsWholeProgram",IsWholeProgramResult},
};
void PluginClient::GetIRTransResult(void *gccData, const string& funcName, const string& param)
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index 5ecab75..c4e5611 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -529,6 +529,16 @@ void GimpleToPluginOps::RemoveEdge(uint64_t src, uint64_t dest)
remove_edge(e);
}
+bool GimpleToPluginOps::IsLtoOptimize()
+{
+ return in_lto_p;
+}
+
+bool GimpleToPluginOps::IsWholeProgram()
+{
+ return flag_whole_program;
+}
+
FunctionOp GimpleToPluginOps::BuildFunctionOp(uint64_t functionId)
{
function *fn = reinterpret_cast<function*>(functionId);
--
2.27.0.windows.1

View File

@ -1,115 +0,0 @@
From d8c42ec77001c29291a31484031cb7b5f2b52d48 Mon Sep 17 00:00:00 2001
From: Mingchuan Wu <wumingchuan1992@foxmail.com>
Date: Tue, 21 Feb 2023 16:53:09 +0800
Subject: [PATCH 8/9] [Pin-gcc-client] Fix bug for BuildCallOp. Now we can
convert the function pointer.
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index bac84be..713623c 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -85,12 +85,15 @@ def CallOp : Plugin_Op<"call", [
The arguments list must match the arguments expected by the callee.
}];
let arguments = (ins UI64Attr:$id,
- FlatSymbolRefAttr:$callee,
+ OptionalAttr<FlatSymbolRefAttr>:$callee,
Variadic<AnyType>:$inputs);
let results = (outs Optional<AnyType>:$result);
let builders = [
OpBuilderDAG<(ins "uint64_t":$id, "StringRef":$callee,
- "ArrayRef<Value>":$arguments, "Type":$retType)>
+ "ArrayRef<Value>":$arguments, "Type":$retType)>,
+ OpBuilderDAG<(ins "uint64_t":$id,
+ "ArrayRef<Value>":$arguments,
+ "Type":$retType)>
];
let extraClassDeclaration = [{
Type getResultType() { return this->getOperation()->getResult(0).getType(); }
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index da5f3f3..1ea3b5a 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -146,6 +146,14 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
if (retType != nullptr) state.addTypes(retType);
}
+void CallOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id, ArrayRef<Value> arguments, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addOperands(arguments);
+ if (retType != nullptr) state.addTypes(retType);
+}
+
/// Return the callee of the generic call operation, this is required by the
/// call interface.
CallInterfaceCallable CallOp::getCallableForCallee()
diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp
index ccadf10..966d35e 100755
--- a/lib/PluginClient/PluginJson.cpp
+++ b/lib/PluginClient/PluginJson.cpp
@@ -341,7 +341,10 @@ Json::Value PluginJson::CallOpJsonSerialize(CallOp& data)
{
Json::Value item;
item["id"] = std::to_string(data.idAttr().getInt());
- item["callee"] = data.callee().str();
+ Optional<StringRef> calleeName = data.callee();
+ if (calleeName) {
+ item["callee"] = calleeName->str();
+ }
item["OperationName"] = data.getOperation()->getName().getStringRef().str();
size_t opIdx = 0;
for (mlir::Value v : data.getArgOperands()) {
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index c4e5611..515e5e6 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -645,10 +645,6 @@ uint64_t GimpleToPluginOps::CreateGphiNode(uint64_t argId, uint64_t blockId)
CallOp GimpleToPluginOps::BuildCallOp(uint64_t gcallId)
{
gcall *stmt = reinterpret_cast<gcall*>(gcallId);
- tree fndecl = gimple_call_fndecl(stmt);
- if (fndecl == NULL_TREE || DECL_NAME(fndecl) == NULL_TREE) {
- return nullptr;
- }
llvm::SmallVector<Value, 4> ops;
ops.reserve(gimple_call_num_args(stmt));
for (unsigned i = 0; i < gimple_call_num_args(stmt); i++) {
@@ -658,11 +654,18 @@ CallOp GimpleToPluginOps::BuildCallOp(uint64_t gcallId)
Value arg = TreeToValue(argId);
ops.push_back(arg);
}
- StringRef callName(IDENTIFIER_POINTER(DECL_NAME(fndecl)));
tree returnType = gimple_call_return_type(stmt);
PluginTypeBase rPluginType = typeTranslator.translateType((intptr_t)returnType);
- CallOp ret = builder.create<CallOp>(builder.getUnknownLoc(),
- gcallId, callName, ops, rPluginType);
+ tree fndecl = gimple_call_fndecl(stmt);
+ CallOp ret;
+ if (fndecl == NULL_TREE || DECL_NAME(fndecl) == NULL_TREE) {
+ ret = builder.create<CallOp>(builder.getUnknownLoc(),
+ gcallId, ops, rPluginType);
+ } else {
+ StringRef callName(IDENTIFIER_POINTER(DECL_NAME(fndecl)));
+ ret = builder.create<CallOp>(builder.getUnknownLoc(),
+ gcallId, callName, ops, rPluginType);
+ }
return ret;
}
@@ -860,6 +863,10 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId)
} else {
abort();
}
+ opValue = builder.create<ConstOp>(
+ builder.getUnknownLoc(), treeId, IDefineCode::IntCST,
+ readOnly, initAttr, rPluginType);
+ break;
}
case MEM_REF : {
tree operand0 = TREE_OPERAND(t, 0);
--
2.27.0.windows.1

View File

@ -1,721 +0,0 @@
From 307831e1210fd9aa4453d774308f63812198b555 Mon Sep 17 00:00:00 2001
From: d00573793 <dingguangya1@huawei.com>
Date: Tue, 21 Feb 2023 11:09:39 +0800
Subject: [PATCH 9/9] [Pin-gcc-client] Support functiontype structtype.eg.
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index c48d002..64a0c3d 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -32,15 +32,19 @@ def FunctionOp : Plugin_Op<"function", [NoSideEffect]> {
let arguments = (ins UI64Attr:$id,
StrAttr:$funcName,
- OptionalAttr<BoolAttr>:$declaredInline);
+ OptionalAttr<BoolAttr>:$declaredInline,
+ TypeAttr:$type);
let regions = (region AnyRegion:$bodyRegion);
// Add custom build methods for the operation. These method populates
// the `state` that MLIR uses to create operations, i.e. these are used when
// using `builder.create<Op>(...)`.
let builders = [
- OpBuilderDAG<(ins "uint64_t":$id, "StringRef":$funcName, "bool":$declaredInline)>
+ OpBuilderDAG<(ins "uint64_t":$id, "StringRef":$funcName, "bool":$declaredInline, "Type":$type)>
];
+ let extraClassDeclaration = [{
+ Type getResultType();
+ }];
}
def LocalDeclOp : Plugin_Op<"declaration", [NoSideEffect]> {
diff --git a/include/Dialect/PluginTypes.h b/include/Dialect/PluginTypes.h
index 157b868..da16886 100644
--- a/include/Dialect/PluginTypes.h
+++ b/include/Dialect/PluginTypes.h
@@ -78,6 +78,9 @@ namespace Detail {
struct PluginIntegerTypeStorage;
struct PluginFloatTypeStorage;
struct PluginPointerTypeStorage;
+ struct PluginTypeAndSizeStorage;
+ struct PluginFunctionTypeStorage;
+ struct PluginStructTypeStorage;
}
class PluginIntegerType : public Type::TypeBase<PluginIntegerType, PluginTypeBase, Detail::PluginIntegerTypeStorage> {
@@ -128,6 +131,60 @@ public:
unsigned isReadOnlyElem();
}; // class PluginPointerType
+class PluginArrayType : public Type::TypeBase<PluginArrayType, PluginTypeBase, Detail::PluginTypeAndSizeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static bool isValidElementType(Type type);
+
+ static PluginArrayType get(MLIRContext *context, Type elementType, unsigned numElements);
+
+ Type getElementType();
+
+ unsigned getNumElements();
+}; // class PluginArrayType
+
+class PluginFunctionType : public Type::TypeBase<PluginFunctionType, PluginTypeBase, Detail::PluginFunctionTypeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static bool isValidArgumentType(Type type);
+
+ static bool isValidResultType(Type type);
+
+ static PluginFunctionType get(MLIRContext *context, Type result, ArrayRef<Type> arguments);
+
+ Type getReturnType();
+
+ unsigned getNumParams();
+
+ Type getParamType(unsigned i);
+
+ ArrayRef<Type> getParams();
+}; // class PluginFunctionType
+
+class PluginStructType : public Type::TypeBase<PluginStructType, PluginTypeBase, Detail::PluginStructTypeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static bool isValidElementType(Type type);
+
+ static PluginStructType get(MLIRContext *context, StringRef name, ArrayRef<Type> elements, ArrayRef<StringRef> elemNames);
+
+ StringRef getName();
+
+ ArrayRef<Type> getBody();
+
+ ArrayRef<StringRef> getElementNames();
+
+}; // class PluginStructType
+
class PluginVoidType : public Type::TypeBase<PluginVoidType, PluginTypeBase, TypeStorage> {
public:
using Base::Base;
diff --git a/include/PluginClient/PluginJson.h b/include/PluginClient/PluginJson.h
index 91bd925..3c9fe1f 100755
--- a/include/PluginClient/PluginJson.h
+++ b/include/PluginClient/PluginJson.h
@@ -59,7 +59,7 @@ public:
Json::Value MemOpJsonSerialize(mlir::Plugin::MemOp& data);
Json::Value SSAOpJsonSerialize(mlir::Plugin::SSAOp& data);
/* 将Type类型数据序列化 */
- Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase& type);
+ Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase type);
PluginIR::PluginTypeBase TypeJsonDeSerialize(const string& data, mlir::MLIRContext &context);
/* 将整数型数据序列化 */
void IntegerSerialize(int64_t data, string& out);
diff --git a/lib/Dialect/PluginDialect.cpp b/lib/Dialect/PluginDialect.cpp
index 527c076..69a0aa5 100644
--- a/lib/Dialect/PluginDialect.cpp
+++ b/lib/Dialect/PluginDialect.cpp
@@ -38,6 +38,9 @@ void PluginDialect::initialize()
addTypes<PluginIR::PluginIntegerType,
PluginIR::PluginFloatType,
PluginIR::PluginPointerType,
+ PluginIR::PluginArrayType,
+ PluginIR::PluginFunctionType,
+ PluginIR::PluginStructType,
PluginIR::PluginBooleanType,
PluginIR::PluginVoidType,
PluginIR::PluginUndefType>();
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index 052ebfd..db2574c 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -24,6 +24,7 @@
#include "Dialect/PluginDialect.h"
#include "Dialect/PluginOps.h"
+#include "Dialect/PluginTypes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
@@ -32,13 +33,20 @@
using namespace mlir;
using namespace mlir::Plugin;
-void FunctionOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
- uint64_t id, StringRef funcName, bool declaredInline)
+void FunctionOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id, StringRef funcName, bool declaredInline, Type type)
{
- FunctionOp::build(builder, state,
- builder.getI64IntegerAttr(id),
- builder.getStringAttr(funcName),
- builder.getBoolAttr(declaredInline));
+ state.addRegion();
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("funcName", builder.getStringAttr(funcName));
+ state.addAttribute("declaredInline", builder.getBoolAttr(declaredInline));
+ if (type) state.addAttribute("type", TypeAttr::get(type));
+}
+
+Type FunctionOp::getResultType()
+{
+ PluginIR::PluginFunctionType resultType = type().dyn_cast<PluginIR::PluginFunctionType>();
+ return resultType;
}
void LocalDeclOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
diff --git a/lib/Dialect/PluginTypes.cpp b/lib/Dialect/PluginTypes.cpp
index 396bf0f..329a2b6 100644
--- a/lib/Dialect/PluginTypes.cpp
+++ b/lib/Dialect/PluginTypes.cpp
@@ -98,6 +98,80 @@ namespace Detail {
Type pointee;
unsigned readOnlyPointee;
};
+
+ struct PluginTypeAndSizeStorage : public TypeStorage {
+ using KeyTy = std::tuple<Type, unsigned>;
+
+ PluginTypeAndSizeStorage(const KeyTy &key)
+ : elementType(std::get<0>(key)), numElements(std::get<1>(key)) {}
+
+ static PluginTypeAndSizeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
+ return new (allocator.allocate<PluginTypeAndSizeStorage>())
+ PluginTypeAndSizeStorage(key);
+ }
+
+ bool operator==(const KeyTy &key) const
+ {
+ return std::make_tuple(elementType, numElements) == key;
+ }
+
+ Type elementType;
+ unsigned numElements;
+ };
+
+ struct PluginFunctionTypeStorage : public TypeStorage {
+ using KeyTy = std::tuple<Type, ArrayRef<Type>>;
+
+ PluginFunctionTypeStorage(Type resultType, ArrayRef<Type> argumentTypes)
+ : resultType(resultType), argumentTypes(argumentTypes) {}
+
+ static PluginFunctionTypeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
+ return new (allocator.allocate<PluginFunctionTypeStorage>())
+ PluginFunctionTypeStorage(std::get<0>(key), allocator.copyInto(std::get<1>(key)));
+ }
+
+ static unsigned hashKey(const KeyTy &key) {
+ // LLVM doesn't like hashing bools in tuples.
+ return llvm::hash_combine(std::get<0>(key), std::get<1>(key));
+ }
+
+ bool operator==(const KeyTy &key) const
+ {
+ return std::make_tuple(resultType, argumentTypes) == key;
+ }
+
+ Type resultType;
+ ArrayRef<Type> argumentTypes;
+ };
+
+ struct PluginStructTypeStorage : public TypeStorage {
+ using KeyTy = std::tuple<StringRef, ArrayRef<Type>, ArrayRef<StringRef>>;
+
+ PluginStructTypeStorage(StringRef name, ArrayRef<Type> elements, ArrayRef<StringRef> elemNames)
+ : name(name), elements(elements), elemNames(elemNames) {}
+
+ static PluginStructTypeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
+ return new (allocator.allocate<PluginStructTypeStorage>())
+ PluginStructTypeStorage(std::get<0>(key), allocator.copyInto(std::get<1>(key)), allocator.copyInto(std::get<2>(key)));
+ }
+
+ static unsigned hashKey(const KeyTy &key) {
+ // LLVM doesn't like hashing bools in tuples.
+ return llvm::hash_combine(std::get<0>(key), std::get<1>(key), std::get<2>(key));
+ }
+
+ bool operator==(const KeyTy &key) const
+ {
+ return std::make_tuple(name, elements, elemNames) == key;
+ }
+
+ StringRef name;
+ ArrayRef<Type> elements;
+ ArrayRef<StringRef> elemNames;
+ };
} // namespace Detail
} // namespace PluginIR
@@ -123,6 +197,15 @@ PluginTypeID PluginTypeBase::getPluginTypeID ()
if (auto Ty = dyn_cast<PluginIR::PluginPointerType>()) {
return Ty.getPluginTypeID ();
}
+ if (auto Ty = dyn_cast<PluginIR::PluginArrayType>()) {
+ return Ty.getPluginTypeID ();
+ }
+ if (auto Ty = dyn_cast<PluginIR::PluginFunctionType>()) {
+ return Ty.getPluginTypeID ();
+ }
+ if (auto Ty = dyn_cast<PluginIR::PluginStructType>()) {
+ return Ty.getPluginTypeID ();
+ }
return PluginTypeID::UndefTyID;
}
@@ -295,3 +378,108 @@ PluginPointerType PluginPointerType::get (MLIRContext *context, Type pointee, un
{
return Base::get(context, pointee, readOnlyPointee);
}
+
+
+// ===----------------------------------------------------------------------===//
+// Plugin Array Type
+// ===----------------------------------------------------------------------===//
+
+PluginTypeID PluginArrayType::getPluginTypeID()
+{
+ return PluginTypeID::ArrayTyID;
+}
+
+bool PluginArrayType::isValidElementType(Type type)
+{
+ return !type.isa<PluginVoidType, PluginFunctionType, PluginUndefType>();
+}
+
+PluginArrayType PluginArrayType::get(MLIRContext *context, Type elementType, unsigned numElements)
+{
+ return Base::get(context, elementType, numElements);
+}
+
+Type PluginArrayType::getElementType()
+{
+ return getImpl()->elementType;
+}
+
+unsigned PluginArrayType::getNumElements()
+{
+ return getImpl()->numElements;
+}
+
+// ===----------------------------------------------------------------------===//
+// Plugin Function Type
+// ===----------------------------------------------------------------------===//
+
+PluginTypeID PluginFunctionType::getPluginTypeID()
+{
+ return PluginTypeID::FunctionTyID;
+}
+
+bool PluginFunctionType::isValidArgumentType(Type type)
+{
+ return !type.isa<PluginVoidType, PluginFunctionType>();
+}
+
+bool PluginFunctionType::isValidResultType(Type type) {
+ return !type.isa<PluginFunctionType>();
+}
+
+PluginFunctionType PluginFunctionType::get(MLIRContext *context, Type result, ArrayRef<Type> arguments)
+{
+ return Base::get(context, result, arguments);
+}
+
+Type PluginFunctionType::getReturnType()
+{
+ return getImpl()->resultType;
+}
+
+unsigned PluginFunctionType::getNumParams()
+{
+ return getImpl()->argumentTypes.size();
+}
+
+Type PluginFunctionType::getParamType(unsigned i) {
+ return getImpl()->argumentTypes[i];
+}
+
+ArrayRef<Type> PluginFunctionType::getParams()
+{
+ return getImpl()->argumentTypes;
+}
+
+// ===----------------------------------------------------------------------===//
+// Plugin Struct Type
+// ===----------------------------------------------------------------------===//
+
+PluginTypeID PluginStructType::getPluginTypeID()
+{
+ return PluginTypeID::StructTyID;
+}
+
+bool PluginStructType::isValidElementType(Type type) {
+ return !type.isa<PluginVoidType, PluginFunctionType>();
+}
+
+PluginStructType PluginStructType::get(MLIRContext *context, StringRef name, ArrayRef<Type> elements, ArrayRef<StringRef> elemNames)
+{
+ return Base::get(context, name, elements, elemNames);
+}
+
+StringRef PluginStructType::getName()
+{
+ return getImpl()->name;
+}
+
+ArrayRef<Type> PluginStructType::getBody()
+{
+ return getImpl()->elements;
+}
+
+ArrayRef<StringRef> PluginStructType::getElementNames()
+{
+ return getImpl()->elemNames;
+}
\ No newline at end of file
diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp
index 22cd489..a9db475 100755
--- a/lib/PluginClient/PluginJson.cpp
+++ b/lib/PluginClient/PluginJson.cpp
@@ -20,6 +20,7 @@
This file contains the implementation of the PluginJson class.
*/
+#include <iostream>
#include <json/json.h>
#include "PluginAPI/PluginClientAPI.h"
#include "PluginClient/PluginLog.h"
@@ -36,7 +37,7 @@ static uintptr_t GetID(Json::Value node)
return atol(id.c_str());
}
-Json::Value PluginJson::TypeJsonSerialize(PluginIR::PluginTypeBase& type)
+Json::Value PluginJson::TypeJsonSerialize(PluginIR::PluginTypeBase type)
{
Json::Value root;
Json::Value operationObj;
@@ -48,6 +49,41 @@ Json::Value PluginJson::TypeJsonSerialize(PluginIR::PluginTypeBase& type)
ReTypeId = static_cast<uint64_t>(type.getPluginTypeID());
item["id"] = std::to_string(ReTypeId);
+ if (auto Ty = type.dyn_cast<PluginIR::PluginStructType>()) {
+ std::string tyName = Ty.getName().str();
+ item["structtype"] = tyName;
+ size_t paramIndex = 0;
+ ArrayRef<Type> paramsType = Ty.getBody();
+ for (auto ty :paramsType) {
+ string paramStr = "elemType" + std::to_string(paramIndex++);
+ item["structelemType"][paramStr] = TypeJsonSerialize(ty.dyn_cast<PluginIR::PluginTypeBase>());
+ }
+ paramIndex = 0;
+ ArrayRef<StringRef> paramsNames = Ty.getElementNames();
+ for (auto name :paramsNames) {
+ string paramStr = "elemName" + std::to_string(paramIndex++);
+ item["structelemName"][paramStr] = name.str();
+ }
+ }
+
+ if (auto Ty = type.dyn_cast<PluginIR::PluginFunctionType>()) {
+ auto fnrestype = Ty.getReturnType().dyn_cast<PluginIR::PluginTypeBase>();
+ item["fnreturntype"] = TypeJsonSerialize(fnrestype);
+ size_t paramIndex = 0;
+ ArrayRef<Type> paramsType = Ty.getParams();
+ for (auto ty : Ty.getParams()) {
+ string paramStr = "argType" + std::to_string(paramIndex++);
+ item["fnargsType"][paramStr] = TypeJsonSerialize(ty.dyn_cast<PluginIR::PluginTypeBase>());
+ }
+ }
+
+ if (auto Ty = type.dyn_cast<PluginIR::PluginArrayType>()) {
+ auto elemTy = Ty.getElementType().dyn_cast<PluginIR::PluginTypeBase>();
+ item["elementType"] = TypeJsonSerialize(elemTy);
+ uint64_t elemNum = Ty.getNumElements();
+ item["arraysize"] = std::to_string(elemNum);
+ }
+
if (auto elemTy = type.dyn_cast<PluginIR::PluginPointerType>()) {
auto baseTy = elemTy.getElementType().dyn_cast<PluginIR::PluginTypeBase>();
item["elementType"] = TypeJsonSerialize(baseTy);
@@ -104,7 +140,40 @@ PluginIR::PluginTypeBase PluginJson::TypeJsonDeSerialize(const string& data, mli
} else if (id == static_cast<uint64_t>(PluginIR::PointerTyID)) {
mlir::Type elemTy = TypeJsonDeSerialize(type["elementType"].toStyledString(), context);
baseType = PluginIR::PluginPointerType::get(&context, elemTy, type["elemConst"].asString() == "1" ? 1 : 0);
- } else {
+ } else if (id == static_cast<uint64_t>(PluginIR::ArrayTyID)) {
+ mlir::Type elemTy = TypeJsonDeSerialize(type["elementType"].toStyledString(), context);
+ uint64_t elemNum = GetID(type["arraysize"]);
+ baseType = PluginIR::PluginArrayType::get(&context, elemTy, elemNum);
+ } else if (id == static_cast<uint64_t>(PluginIR::FunctionTyID)) {
+ mlir::Type returnTy = TypeJsonDeSerialize(type["fnreturntype"].toStyledString(), context);
+ llvm::SmallVector<Type> typelist;
+ Json::Value::Members fnTypeNum = type["fnargsType"].getMemberNames();
+ uint64_t argsNum = fnTypeNum.size();
+ for (size_t paramIndex = 0; paramIndex < argsNum; paramIndex++) {
+ string Key = "argType" + std::to_string(paramIndex);
+ mlir::Type paramTy = TypeJsonDeSerialize(type["fnargsType"][Key].toStyledString(), context);
+ typelist.push_back(paramTy);
+ }
+ baseType = PluginIR::PluginFunctionType::get(&context, returnTy, typelist);
+ } else if (id == static_cast<uint64_t>(PluginIR::StructTyID)) {
+ StringRef tyName = type["structtype"].toStyledString();
+ llvm::SmallVector<Type> typelist;
+ Json::Value::Members elemTypeNum = type["structelemType"].getMemberNames();
+ for (size_t paramIndex = 0; paramIndex < elemTypeNum.size(); paramIndex++) {
+ string Key = "elemType" + std::to_string(paramIndex);
+ mlir::Type paramTy = TypeJsonDeSerialize(type["structelemType"][Key].toStyledString(), context);
+ typelist.push_back(paramTy);
+ }
+ llvm::SmallVector<StringRef> names;
+ Json::Value::Members elemNameNum = type["structelemName"].getMemberNames();
+ for (size_t paramIndex = 0; paramIndex < elemTypeNum.size(); paramIndex++) {
+ string Key = "elemName" + std::to_string(paramIndex);
+ StringRef elemName = type["structelemName"][Key].toStyledString();
+ names.push_back(elemName);
+ }
+ baseType = PluginIR::PluginStructType::get(&context, tyName, typelist, names);
+ }
+ else {
if (PluginTypeId == PluginIR::VoidTyID) {
baseType = PluginIR::PluginVoidType::get(&context);
}
@@ -127,7 +196,6 @@ void PluginJson::FunctionOpJsonSerialize(vector<FunctionOp>& data, string& out)
int i = 0;
string operation;
-
for (auto& d: data) {
item["id"] = std::to_string(d.idAttr().getInt());
if (d.declaredInlineAttr().getValue()) {
@@ -136,6 +204,14 @@ void PluginJson::FunctionOpJsonSerialize(vector<FunctionOp>& data, string& out)
item["attributes"]["declaredInline"] = "0";
}
item["attributes"]["funcName"] = d.funcNameAttr().getValue().str().c_str();
+
+ mlir::Type fnty = d.type();
+ if (auto ty = fnty.dyn_cast<PluginIR::PluginFunctionType>()) {
+ if (auto retTy = ty.dyn_cast<PluginIR::PluginTypeBase>()) {
+ item["retType"] = TypeJsonSerialize(retTy);
+ }
+ }
+
auto &region = d.getRegion();
size_t bbIdx = 0;
for (auto &b : region) {
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index b5974aa..3e2321a 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -536,9 +536,12 @@ FunctionOp GimpleToPluginOps::BuildFunctionOp(uint64_t functionId)
bool declaredInline = false;
if (DECL_DECLARED_INLINE_P(fn->decl))
declaredInline = true;
+ tree returnType = TREE_TYPE(fn->decl);
+ PluginTypeBase rPluginType = typeTranslator.translateType((intptr_t)returnType);
auto location = builder.getUnknownLoc();
+ auto Ty = rPluginType.dyn_cast<PluginFunctionType>();
FunctionOp retOp = builder.create<FunctionOp>(location, functionId,
- funcName, declaredInline);
+ funcName, declaredInline, Ty);
auto& fr = retOp.bodyRegion();
if (fn->cfg == nullptr) return retOp;
if (!ProcessBasicBlock((intptr_t)ENTRY_BLOCK_PTR_FOR_FN(fn), fr)) {
diff --git a/lib/Translate/TypeTranslation.cpp b/lib/Translate/TypeTranslation.cpp
index 7c7cff4..ad840f7 100644
--- a/lib/Translate/TypeTranslation.cpp
+++ b/lib/Translate/TypeTranslation.cpp
@@ -45,10 +45,12 @@
#include "ssa.h"
#include "output.h"
#include "langhooks.h"
+#include "print-tree.h"
+#include "stor-layout.h"
-using namespace mlir;
namespace PluginIR {
+using namespace mlir;
namespace Detail {
/* Support for translating Plugin IR types to MLIR Plugin dialect types. */
class TypeFromPluginIRTranslatorImpl {
@@ -77,6 +79,77 @@ private:
return false;
}
+ unsigned getDomainIndex (tree type)
+ {
+ return tree_to_shwi(TYPE_MAX_VALUE(TYPE_DOMAIN(type)))+1;
+ }
+
+ llvm::SmallVector<Type> getArgsType (tree type)
+ {
+ tree parmlist = TYPE_ARG_TYPES (type);
+ tree parmtype;
+ llvm::SmallVector<Type> typelist;
+ for (; parmlist; parmlist = TREE_CHAIN (parmlist))
+ {
+ parmtype = TREE_VALUE (parmlist);
+ typelist.push_back(translatePrimitiveType(parmtype));
+ }
+ return typelist;
+ }
+
+ const char *getTypeName (tree type)
+ {
+ const char *tname = NULL;
+
+ if (type == NULL)
+ {
+ return NULL;
+ }
+
+ if (TYPE_NAME (type) != NULL)
+ {
+ if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
+ {
+ tname = IDENTIFIER_POINTER (TYPE_NAME (type));
+ }
+ else if (DECL_NAME (TYPE_NAME (type)) != NULL)
+ {
+ tname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
+ }
+ }
+ return tname;
+ }
+
+ llvm::SmallVector<Type> getElemType(tree type)
+ {
+ llvm::SmallVector<Type> typelist;
+ tree parmtype;
+ for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
+ {
+ if (TREE_CODE (field) == FIELD_DECL)
+ {
+ parmtype = TREE_TYPE(field);
+ typelist.push_back(translatePrimitiveType(parmtype));
+ }
+ }
+ return typelist;
+ }
+
+ llvm::SmallVector<StringRef> getElemNames(tree type)
+ {
+ llvm::SmallVector<StringRef> names;
+ StringRef name;
+ for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
+ {
+ if (TREE_CODE (field) == FIELD_DECL)
+ {
+ name = IDENTIFIER_POINTER ( DECL_NAME(field));
+ names.push_back(name);
+ }
+ }
+ return names;
+ }
+
/* Translates the given primitive, i.e. non-parametric in MLIR nomenclature,
type. */
PluginTypeBase translatePrimitiveType (tree type)
@@ -93,12 +166,21 @@ private:
if (TREE_CODE(type) == POINTER_TYPE)
return PluginPointerType::get(&context, translatePrimitiveType(TREE_TYPE(type)),
TYPE_READONLY(TREE_TYPE(type)) ? 1 : 0);
+ if (TREE_CODE(type) == ARRAY_TYPE)
+ return PluginArrayType::get(&context,translatePrimitiveType(TREE_TYPE(type)), getDomainIndex(type));
+ if (TREE_CODE(type) == FUNCTION_TYPE) {
+ llvm::SmallVector<Type> argsType = getArgsType(type);
+ return PluginFunctionType::get(&context, translatePrimitiveType(TREE_TYPE(type)),argsType);
+ }
+ if (TREE_CODE(type) == RECORD_TYPE) {
+ return PluginStructType::get(&context, getTypeName(type), getElemType(type), getElemNames(type));
+ }
return PluginUndefType::get(&context);
}
/* The context in which MLIR types are created. */
mlir::MLIRContext &context;
-};
+}; // class TypeFromPluginIRTranslatorImpl
/* Support for translating MLIR Plugin dialect types to Plugin IR types . */
class TypeToPluginIRTranslatorImpl {
@@ -126,6 +208,16 @@ private:
return false;
}
+ auto_vec<tree> getParamsType(PluginFunctionType Ty)
+ {
+ auto_vec<tree> paramTypes;
+ ArrayRef<Type> ArgsTypes = Ty.getParams();
+ for (auto ty :ArgsTypes) {
+ paramTypes.safe_push(translatePrimitiveType(ty.dyn_cast<PluginTypeBase>()));
+ }
+ return paramTypes;
+ }
+
tree translatePrimitiveType(PluginTypeBase type)
{
if (auto Ty = type.dyn_cast<PluginIntegerType>()) {
@@ -179,9 +271,50 @@ private:
TYPE_READONLY(elmTy) = elmConst ? 1 : 0;
return build_pointer_type(elmTy);
}
+ if (auto Ty = type.dyn_cast<PluginArrayType>()) {
+ mlir::Type elmType = Ty.getElementType();
+ auto ty = elmType.dyn_cast<PluginTypeBase>();
+ tree elmTy = translatePrimitiveType(ty);
+ unsigned elmNum = Ty.getNumElements();
+ tree index = build_index_type (size_int (elmNum));
+ return build_array_type(elmTy, index);
+ }
+ if (auto Ty = type.dyn_cast<PluginFunctionType>()) {
+ Type resultType = Ty.getReturnType();
+ tree returnType = translatePrimitiveType(resultType.dyn_cast<PluginTypeBase>());
+ auto_vec<tree> paramTypes = getParamsType(Ty);
+ return build_function_type_array(returnType, paramTypes.length (), paramTypes.address ());
+ }
+ if (auto Ty = type.dyn_cast<PluginStructType>()) {
+ ArrayRef<Type> elemTypes = Ty.getBody();
+ ArrayRef<StringRef> elemNames = Ty.getElementNames();
+ StringRef tyName = Ty.getName();
+ unsigned fieldSize = elemNames.size();
+
+ tree fields[fieldSize];
+ tree ret;
+ unsigned i;
+
+ ret = make_node (RECORD_TYPE);
+ for (i = 0; i < fieldSize; i++)
+ {
+ mlir::Type elemTy = elemTypes[i];
+ auto ty = elemTy.dyn_cast<PluginTypeBase>();
+ tree elmType = translatePrimitiveType(ty);
+ fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, get_identifier (elemNames[i].str().c_str()), elmType);
+ DECL_CONTEXT (fields[i]) = ret;
+ if (i) DECL_CHAIN (fields[i - 1]) = fields[i];
+ }
+ tree typeDecl = build_decl (input_location, TYPE_DECL, get_identifier (tyName.str().c_str()), ret);
+ DECL_ARTIFICIAL (typeDecl) = 1;
+ TYPE_FIELDS (ret) = fields[0];
+ TYPE_NAME (ret) = typeDecl;
+ layout_type (ret);
+ return ret;
+ }
return NULL;
}
-};
+}; // class TypeToPluginIRTranslatorImpl
} // namespace Detail
} // namespace PluginIR
--
2.27.0.windows.1

Binary file not shown.

BIN
pin-gcc-client-0.4.1.tar.gz Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
Name: pin-gcc-client
Version: 0.4.0
Release: 2
Version: 0.4.1
Release: 1
Summary: A Pin (Plug-IN framework) client is implemented based on GCC plugin and can execute the compiler optimization pass in GCC.
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gitee.com/src-openeuler/pin-gcc-client
@ -10,16 +10,6 @@ BuildRequires: gcc gcc-c++ gcc-plugin-devel cmake make pkgconfig grpc grpc-plug
BuildRequires: llvm-mlir llvm-mlir-static llvm-mlir-devel llvm-devel
Requires: gcc grpc protobuf
Patch1: 0001-Pin-gcc-client-Bugfix-for-ConstOp.patch
Patch2: 0002-Refactoring-Code-refactoring-of-Communication-Subsys.patch
Patch3: 0003-Refactoring-Code-refactoring-of-Communication-Subsys.patch
Patch4: 0004-Refactoring-Code-refactoring-of-Communication-Subsys.patch
Patch5: 0005-Pin-gcc-client-Add-DebugOp.patch
Patch6: 0006-Pin-gcc-client-Bugfix-for-ConstOp.patch
Patch7: 0007-Pin-gcc-client-Add-API-for-LTO-judgement.patch
Patch8: 0008-Pin-gcc-client-Fix-bug-for-BuildCallOp.patch
Patch9: 0009-Pin-gcc-client-Support-functiontype-structtype.eg.patch
%description
A Pin (Plug-IN framework) client is implemented based on GCC plugin and can execute the compiler optimization pass in GCC.
@ -29,16 +19,6 @@ A Pin (Plug-IN framework) client is implemented based on GCC plugin and can exec
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
mkdir -p _build
cd _build
%{cmake} .. -DCMAKE_INSTALL_PREFIX=%{_usr} -DCMAKE_INSTALL_LIBDIR=%{_libdir} -DMLIR_DIR=/usr/lib64/cmake/mlir -DLLVM_DIR=/usr/lib64/cmake/llvm
@ -62,11 +42,11 @@ cd _build
%attr(0644,root,root) %{_bindir}/pin-gcc-client.json
%changelog
* Wed Feb 22 2023 dingguangya <dingguangya1@huawei.com> - 0.4.0-2
* Sun Feb 26 2023 dingguangya <dingguangya1@huawei.com> - 0.4.1-1
- Type:Update
- ID:NA
- SUG:NA
- DESC:Sync patch from openEuler/pin-gcc-client
- DESC:Update to v0.4.1
* Tue Dec 20 2022 zhaowenyu <804544223@qq.com> - 0.4.0-1
- Type:Update