217 lines
8.2 KiB
Diff
217 lines
8.2 KiB
Diff
From b622cc8d95f4ef8bd417d94974e9ff83104beab9 Mon Sep 17 00:00:00 2001
|
||
From: Mingchuan Wu <wumingchuan1992@foxmail.com>
|
||
Date: Sat, 2 Sep 2023 15:59:19 +0800
|
||
Subject: [PATCH 2/2] [PluginClient] Update transfer command.
|
||
|
||
---
|
||
include/PluginAPI/BasicPluginOpsAPI.h | 1 +
|
||
include/PluginAPI/PluginClientAPI.h | 1 +
|
||
lib/PluginAPI/PluginClientAPI.cpp | 3 ++
|
||
lib/PluginClient/PluginClient.cpp | 78 +++++++++++++++++++++++++--
|
||
lib/Translate/GimpleToPluginOps.cpp | 11 ++--
|
||
5 files changed, 87 insertions(+), 7 deletions(-)
|
||
|
||
diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h
|
||
index 22da8df..37bd73d 100644
|
||
--- a/include/PluginAPI/BasicPluginOpsAPI.h
|
||
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
|
||
@@ -48,6 +48,7 @@ public:
|
||
virtual string FuncName(int64_t gccDataAddr) = 0;
|
||
virtual int GetDeclSourceLine(uint64_t gccDataAddr) = 0;
|
||
virtual int GetDeclSourceColumn(uint64_t gccDataAddr) = 0;
|
||
+ virtual void ShutdownCompile() = 0;
|
||
|
||
// CGnode
|
||
virtual vector<uint64_t> GetCGnodeIDs() = 0;
|
||
diff --git a/include/PluginAPI/PluginClientAPI.h b/include/PluginAPI/PluginClientAPI.h
|
||
index 26ef71d..43e7154 100644
|
||
--- a/include/PluginAPI/PluginClientAPI.h
|
||
+++ b/include/PluginAPI/PluginClientAPI.h
|
||
@@ -38,6 +38,7 @@ public:
|
||
string FuncName(int64_t gccDataAddr) override;
|
||
int GetDeclSourceLine(uint64_t gccDataAddr) override;
|
||
int GetDeclSourceColumn(uint64_t gccDataAddr) override;
|
||
+ void ShutdownCompile() override;
|
||
|
||
uint64_t CreateBlock(uint64_t, uint64_t) override;
|
||
void DeleteBlock(uint64_t, uint64_t) override;
|
||
diff --git a/lib/PluginAPI/PluginClientAPI.cpp b/lib/PluginAPI/PluginClientAPI.cpp
|
||
index 95e9ab3..55f46f7 100644
|
||
--- a/lib/PluginAPI/PluginClientAPI.cpp
|
||
+++ b/lib/PluginAPI/PluginClientAPI.cpp
|
||
@@ -17,6 +17,7 @@
|
||
*/
|
||
|
||
#include "PluginAPI/PluginClientAPI.h"
|
||
+#include <unistd.h>
|
||
|
||
namespace PluginAPI {
|
||
|
||
@@ -92,6 +93,8 @@ vector<FunctionOp> PluginClientAPI::GetAllFunc()
|
||
return gimpleConversion.GetAllFunction();
|
||
}
|
||
|
||
+void PluginClientAPI::ShutdownCompile() { _exit(0); }
|
||
+
|
||
vector<uint64_t> PluginClientAPI::GetFunctions()
|
||
{
|
||
return gimpleConversion.GetFunctionIDs();
|
||
diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp
|
||
index c9f3cb7..cf3036d 100644
|
||
--- a/lib/PluginClient/PluginClient.cpp
|
||
+++ b/lib/PluginClient/PluginClient.cpp
|
||
@@ -25,6 +25,10 @@
|
||
#include "Dialect/PluginTypes.h"
|
||
#include "PluginAPI/PluginClientAPI.h"
|
||
|
||
+#include "gcc-plugin.h"
|
||
+#include "plugin-version.h"
|
||
+#include "toplev.h"
|
||
+#include "opts.h"
|
||
namespace PinClient {
|
||
using namespace mlir::Plugin;
|
||
using namespace mlir;
|
||
@@ -344,6 +348,16 @@ void SetDeclAlignResult(PluginClient *client, Json::Value& root, string& result)
|
||
client->ReceiveSendMsg("VoidResult", result);
|
||
}
|
||
|
||
+void ShutdownCompile(PluginClient *client, Json::Value& root, string& result)
|
||
+{
|
||
+ // Load our Dialect in this MLIR Context.
|
||
+ mlir::MLIRContext context;
|
||
+ context.getOrLoadDialect<PluginDialect>();
|
||
+ PluginAPI::PluginClientAPI clientAPI(context);
|
||
+ clientAPI.ShutdownCompile();
|
||
+ client->ReceiveSendMsg("VoidResult", result);
|
||
+}
|
||
+
|
||
void SetUserAlignResult(PluginClient *client, Json::Value& root, string& result)
|
||
{
|
||
/// Json格式
|
||
@@ -1335,6 +1349,7 @@ std::map<string, GetResultFunc> g_getResultFunc = {
|
||
{"IsDomInfoAvailable", IsDomInfoAvailableResult},
|
||
{"GetCurrentDefFromSSA", GetCurrentDefFromSSAResult},
|
||
{"SetCurrentDefInSSA", SetCurrentDefInSSAResult},
|
||
+ {"ShutdownCompile", ShutdownCompile},
|
||
{"CopySSAOp", CopySSAOpResult},
|
||
{"CreateSSAOp", CreateSSAOpResult},
|
||
{"CreateNewDef", CreateNewDefResult},
|
||
@@ -1543,7 +1558,12 @@ static bool WaitServer(const string& port)
|
||
mode_t mask = umask(0);
|
||
mode_t mode = 0666; // 权限是rwrwrw,跨进程时,其他用户也要可以访问
|
||
string semFile = "wait_server_startup" + port;
|
||
- sem_t *sem = sem_open(semFile.c_str(), O_CREAT, mode, 0);
|
||
+ sem_t *sem = sem_open(semFile.c_str(), O_CREAT | O_EXCL, mode, 0);
|
||
+ // Semaphore exception handling.
|
||
+ if (sem == SEM_FAILED) {
|
||
+ sem_unlink(semFile.c_str());
|
||
+ sem = sem_open(semFile.c_str(), O_CREAT, mode, 0);
|
||
+ }
|
||
umask(mask);
|
||
int i = 0;
|
||
for (; i < cnt; i++) {
|
||
@@ -1561,11 +1581,60 @@ static bool WaitServer(const string& port)
|
||
return true;
|
||
}
|
||
|
||
+bool ExecuteWithCommand(string serverPath, string port, string level)
|
||
+{
|
||
+ string inputFile (main_input_filename);
|
||
+ string cwd = get_current_dir_name();
|
||
+
|
||
+ string outputName="";
|
||
+ for (int i = 0; i< save_decoded_options_count; ++i) {
|
||
+ if (!strcmp(save_decoded_options[i].canonical_option[0],"-o")) {
|
||
+ outputName = save_decoded_options[i].canonical_option[1];
|
||
+ }
|
||
+ }
|
||
+
|
||
+ string common_opt = "";
|
||
+ for (int i = 0; i< save_decoded_options_count; ++i) {
|
||
+ if (!strcmp(save_decoded_options[i].canonical_option[0],"-I") ||
|
||
+ !strcmp(save_decoded_options[i].canonical_option[0],"-D")) {
|
||
+ common_opt.append(save_decoded_options[i].canonical_option[0]);
|
||
+ common_opt.append(save_decoded_options[i].canonical_option[1]);
|
||
+ common_opt.append(" ");
|
||
+ }
|
||
+ if (!strcmp(save_decoded_options[i].canonical_option[0],"-std=gnu90")) {
|
||
+ common_opt.append(" -std=gnu90 ");
|
||
+ }
|
||
+ }
|
||
+
|
||
+ string extra_opt = "";
|
||
+ for (int i = 0; i< save_decoded_options_count; ++i) {
|
||
+ if (strcmp(save_decoded_options[i].canonical_option[0],"-I") &&
|
||
+ strcmp(save_decoded_options[i].canonical_option[0],"-D") &&
|
||
+ strcmp(save_decoded_options[i].canonical_option[0],"-o")) {
|
||
+ extra_opt.append(save_decoded_options[i].canonical_option[0]);
|
||
+ extra_opt.append(" ");
|
||
+ }
|
||
+ }
|
||
+
|
||
+ if (execl(serverPath.c_str(), port.c_str(), level.c_str(),
|
||
+ inputFile.c_str(), cwd.c_str(), common_opt.c_str(), extra_opt.c_str(), outputName.c_str(), NULL) == -1)
|
||
+ {
|
||
+ return true;
|
||
+ }
|
||
+ return false;
|
||
+
|
||
+}
|
||
+
|
||
int PluginClient::ServerStart(pid_t& pid)
|
||
{
|
||
if (!grpcPort.FindUnusedPort()) {
|
||
- LOGE("cannot find port for grpc,port 40001-65535 all used!\n");
|
||
- return -1;
|
||
+ // Rectify the fault that the port number is not released
|
||
+ // because the client is abnormal.
|
||
+ LOGW("cannot find port for grpc, try again!\n");
|
||
+ if (!grpcPort.FindUnusedPort()) {
|
||
+ LOGE("cannot find port for grpc,port 40001-65534 all used!\n");
|
||
+ return -1;
|
||
+ }
|
||
}
|
||
|
||
int ret = 0;
|
||
@@ -1575,7 +1644,8 @@ int PluginClient::ServerStart(pid_t& pid)
|
||
if (pid == 0) {
|
||
LOGI("start plugin server!\n");
|
||
string serverPath = input.GetServerPath();
|
||
- if (execl(serverPath.c_str(), port.c_str(), std::to_string(input.GetLogLevel()).c_str(), NULL) == -1) {
|
||
+ string level = std::to_string(input.GetLogLevel());
|
||
+ if (ExecuteWithCommand(serverPath, port, level)) {
|
||
DeleteGrpcPort();
|
||
LOGE("server start fail! please check serverPath:%s\n", serverPath.c_str());
|
||
ret = -1;
|
||
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
|
||
index 80d4e87..4617c78 100644
|
||
--- a/lib/Translate/GimpleToPluginOps.cpp
|
||
+++ b/lib/Translate/GimpleToPluginOps.cpp
|
||
@@ -1505,9 +1505,14 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId)
|
||
unsigned HOST_WIDE_INT uinit = tree_to_uhwi(t);
|
||
initAttr = builder.getI64IntegerAttr(uinit);
|
||
} else {
|
||
- abort();
|
||
+ wide_int val = wi::to_wide(t);
|
||
+ if (wi::neg_p(val, TYPE_SIGN(TREE_TYPE(t)))) {
|
||
+ val = -val;
|
||
+ }
|
||
+ signed HOST_WIDE_INT init = val.to_shwi();
|
||
+ initAttr = builder.getI64IntegerAttr(init);
|
||
}
|
||
- GetTreeAttr(treeId, readOnly, rPluginType);
|
||
+ GetTreeAttr(treeId, readOnly, rPluginType);
|
||
opValue = builder.create<ConstOp>(
|
||
builder.getUnknownLoc(), treeId, IDefineCode::IntCST,
|
||
readOnly, initAttr, rPluginType);
|
||
@@ -1887,4 +1892,4 @@ Value GimpleToPluginOps::MakeSsaName(mlir::Type type)
|
||
return TreeToValue(retId);
|
||
}
|
||
|
||
-} // namespace PluginIR
|
||
\ No newline at end of file
|
||
+} // namespace PluginIR
|
||
--
|
||
2.33.0
|
||
|