pin-server/0003-Refactoring-Code-refactoring-of-Communication-Subsys.patch
2023-03-07 11:41:20 +08:00

1716 lines
65 KiB
Diff
Raw Permalink 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 d395986acddf59c379a107fbe6d1b69c74ff2d3b Mon Sep 17 00:00:00 2001
From: wangding16 <wangding16@huawei.com>
Date: Wed, 8 Feb 2023 15:16:49 +0800
Subject: [PATCH 03/23] [Refactoring] Code refactoring of Communication
Subsystem [3/3]. Code refactoring of Communication subsystem.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1373e8..3a784df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -92,6 +92,9 @@ add_custom_command(TARGET pin_user COMMAND sha256sum libpin_user.so > libpin_use
add_executable(pin_server
"lib/PluginServer/PluginServer.cpp"
"lib/PluginAPI/ControlFlowAPI.cpp"
+ "lib/PluginServer/PluginGrpc.cpp"
+ "lib/PluginServer/PluginJson.cpp"
+ "lib/PluginServer/PluginCom.cpp"
"lib/PluginServer/PluginLog.cpp"
"lib/PluginServer/main.cpp")
target_link_libraries(pin_server
diff --git a/README.md b/README.md
index f948f51..3513a24 100644
--- a/README.md
+++ b/README.md
@@ -6,10 +6,8 @@ Pin (Plug-IN framework) server provides plugin APIs for compiler optimization de
#### 软件架构
Pin(Plug-IN framework, 插件框架)为生态伙伴提供基于插件IR的编译器优化开发能力允许开发者使用插件API开发编译器优化pass并以插件形式向主流编译器如GCC提供优化能力。
-本框架采用插件服务端组件(Pin-Server)和插件客户端模块(Pin-gcc-client)组成代理模式。
+本框架采用插件服务端组件(Pin-Server)和插件客户端模块组成代理模式。
Pin-Server为开发者提供插件API进行编译器优化pass的开发。
-Pin-gcc-client基于GCC插件实现可以在GCC场景执行优化pass。
-
#### 安装教程
diff --git a/include/Dialect/PluginDialect.h b/include/Dialect/PluginDialect.h
index 0affbc2..65e03c0 100644
--- a/include/Dialect/PluginDialect.h
+++ b/include/Dialect/PluginDialect.h
@@ -13,11 +13,11 @@
under the License.
*/
-//===----------------------------------------------------------------------===//
-//
+// ===----------------------------------------------------------------------===//
+//
// This is the header file for the Plugin dialect.
//
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
#ifndef PLUGIN_DIALECT_H
#define PLUGIN_DIALECT_H
diff --git a/include/Dialect/PluginOps.h b/include/Dialect/PluginOps.h
index 8bab877..3c7bd64 100644
--- a/include/Dialect/PluginOps.h
+++ b/include/Dialect/PluginOps.h
@@ -14,11 +14,11 @@
*/
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
//
-// This is the header file for operations in Plugin dialect.
+// This is the header file for operations in Plugin dialect.
//
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
#ifndef Plugin_OPS_H
#define Plugin_OPS_H
diff --git a/include/Dialect/PluginTypes.h b/include/Dialect/PluginTypes.h
index 0b1f4f4..7fb1ff9 100644
--- a/include/Dialect/PluginTypes.h
+++ b/include/Dialect/PluginTypes.h
@@ -131,25 +131,19 @@ public:
class PluginVoidType : public Type::TypeBase<PluginVoidType, PluginTypeBase, TypeStorage> {
public:
using Base::Base;
-
PluginTypeID getPluginTypeID ();
-
}; // class PluginVoidType
class PluginUndefType : public Type::TypeBase<PluginUndefType, PluginTypeBase, TypeStorage> {
public:
using Base::Base;
-
PluginTypeID getPluginTypeID ();
-
}; // class PluginUndefType
class PluginBooleanType : public Type::TypeBase<PluginBooleanType, PluginTypeBase, TypeStorage> {
public:
using Base::Base;
-
PluginTypeID getPluginTypeID ();
-
}; // class PluginBooleanType
} // namespace PluginIR
diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h
index 68abaef..0ca0ac4 100644
--- a/include/PluginAPI/BasicPluginOpsAPI.h
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
@@ -37,6 +37,14 @@ public:
BasicPluginOpsAPI() = default;
virtual ~BasicPluginOpsAPI() = default;
+ virtual int64_t GetInjectDataAddress() = 0;
+ virtual string GetDeclSourceFile(int64_t) = 0;
+ virtual string VariableName(int64_t) = 0;
+ virtual string FuncName(int64_t) = 0;
+ virtual string GetIncludeFile() = 0;
+ virtual int GetDeclSourceLine(int64_t) = 0;
+ virtual int GetDeclSourceColumn(int64_t) = 0;
+
virtual vector<FunctionOp> GetAllFunc() = 0;
virtual vector<LocalDeclOp> GetDecls(uint64_t) = 0;
virtual LoopOp AllocateNewLoop(uint64_t) = 0;
@@ -74,4 +82,4 @@ public:
}; // class BasicPluginOpsAPI
} // namespace PluginAPI
-#endif // BASIC_PLUGIN_OPS_FRAMEWORK_API_H
\ No newline at end of file
+#endif // BASIC_PLUGIN_OPS_FRAMEWORK_API_H
diff --git a/include/PluginAPI/PluginServerAPI.h b/include/PluginAPI/PluginServerAPI.h
index 360ffbd..0655d80 100644
--- a/include/PluginAPI/PluginServerAPI.h
+++ b/include/PluginAPI/PluginServerAPI.h
@@ -52,8 +52,8 @@ public:
vector<pair<mlir::Block*, mlir::Block*> > GetLoopExitEdges(uint64_t loopID);
mlir::Block* GetHeader(uint64_t loopID);
mlir::Block* GetLatch(uint64_t loopID);
- void SetHeader(uint64_t loopID, uint64_t blockID);
- void SetLatch(uint64_t loopID, uint64_t blockID);
+ void SetHeader(uint64_t loopID, uint64_t blockID);
+ void SetLatch(uint64_t loopID, uint64_t blockID);
vector<mlir::Block*> GetLoopBody(uint64_t loopID);
LoopOp GetBlockLoopFather(uint64_t blockID);
mlir::Block* FindBlock(uint64_t);
@@ -73,7 +73,7 @@ public:
PhiOp CreatePhiOp(uint64_t, uint64_t) override;
/* Plugin API for ConstOp. */
mlir::Value CreateConstOp(mlir::Attribute, mlir::Type) override;
- void DebugValue(uint64_t) override;
+ void DebugValue(uint64_t) override;
mlir::Value GetCurrentDefFromSSA(uint64_t) override;
bool SetCurrentDefInSSA(uint64_t, uint64_t) override;
@@ -84,16 +84,15 @@ public:
bool RedirectFallthroughTarget(FallThroughOp&, uint64_t, uint64_t) override;
mlir::Operation* GetSSADefOperation(uint64_t) override;
void InsertCreatedBlock(uint64_t id, mlir::Block* block);
- void WaitClientResult(const string& funName, const string& params);
+ int64_t GetInjectDataAddress() override; // 获取注入点返回数据的地址
+ string GetDeclSourceFile(int64_t) override;
+ string VariableName(int64_t) override;
+ string FuncName(int64_t) override;
+ string GetIncludeFile() override;
+ int GetDeclSourceLine(int64_t) override;
+ int GetDeclSourceColumn(int64_t) override;
private:
- vector<FunctionOp> GetFunctionOpResult(const string& funName, const string& params);
- vector<LocalDeclOp> GetDeclOperationResult(const string& funName, const string& params);
- LoopOp GetLoopResult(const string&funName, const string& params);
- vector<LoopOp> GetLoopsResult(const string& funName, const string& params);
- bool GetBoolResult(const string& funName, const string& params);
- pair<mlir::Block*, mlir::Block*> EdgeResult(const string& funName, const string& params);
- vector<pair<mlir::Block*, mlir::Block*> > EdgesResult(const string& funName, const string& params);
mlir::Block* BlockResult(const string& funName, const string& params);
vector<mlir::Block*> BlocksResult(const string& funName, const string& params);
bool GetDomInfoAvaiResult(const string& funName);
diff --git a/include/PluginServer/ManagerSetup.h b/include/PluginServer/ManagerSetup.h
new file mode 100755
index 0000000..27ba930
--- /dev/null
+++ b/include/PluginServer/ManagerSetup.h
@@ -0,0 +1,67 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the ManagerSetup class.
+ 主要完成功能提供managerSetup注册方法
+*/
+
+#ifndef MANAGER_SETUP_H
+#define MANAGER_SETUP_H
+
+namespace PluginOpt {
+enum RefPassName {
+ PASS_CFG,
+ PASS_PHIOPT,
+ PASS_SSA,
+ PASS_LOOP,
+};
+
+enum PassPosition {
+ PASS_INSERT_AFTER,
+ PASS_INSERT_BEFORE,
+ PASS_REPLACE,
+};
+
+class ManagerSetup {
+public:
+ ManagerSetup(RefPassName name, int num, PassPosition position)
+ {
+ refPassName = name;
+ passNum = num;
+ passPosition = position;
+ }
+ RefPassName GetPassName()
+ {
+ return refPassName;
+ }
+ int GetPassNum()
+ {
+ return passNum;
+ }
+ PassPosition GetPassPosition()
+ {
+ return passPosition;
+ }
+
+private:
+ RefPassName refPassName;
+ int passNum; // 指定passName的第几次执行作为参考点
+ PassPosition passPosition; // 指定pass是添加在参考点之前还是之后
+};
+} // namespace PinOpt
+
+#endif
\ No newline at end of file
diff --git a/include/PluginServer/PluginCom.h b/include/PluginServer/PluginCom.h
new file mode 100755
index 0000000..6535362
--- /dev/null
+++ b/include/PluginServer/PluginCom.h
@@ -0,0 +1,90 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the PluginCom class.
+ 主要完成功能和client之间通信、数据解析、数据反序列化
+*/
+
+#ifndef PLUGIN_COM_H
+#define PLUGIN_COM_H
+
+#include "Dialect/PluginOps.h"
+#include "Dialect/PluginTypes.h"
+#include "PluginServer/PluginJson.h"
+#include "PluginServer/PluginGrpc.h"
+
+namespace PinCom {
+using PinGrpc::PluginGrpc;
+using PinJson::PluginJson;
+using std::vector;
+using std::string;
+
+class PluginCom {
+public:
+ bool RegisterServer(const string& port)
+ {
+ return pluginGrpc.RegisterServer(port);
+ }
+ void Run()
+ {
+ pluginGrpc.Run();
+ }
+ void ShutDown()
+ {
+ pluginGrpc.ShutDown();
+ }
+ void ServerSend(const string& key, const string& value)
+ {
+ pluginGrpc.ServerSend(key, value);
+ }
+ /* json反序列化根据key值分别调用Operation/Decl/Type反序列化接口函数 */
+ void JsonDeSerialize(const string& key, const string& data);
+ int64_t GetIntegerDataResult(void);
+ string GetStringDataResult(void);
+ vector<mlir::Plugin::FunctionOp> GetFunctionOpResult(void);
+ vector<mlir::Plugin::LocalDeclOp> GetLocalDeclResult(void);
+ mlir::Plugin::LoopOp LoopOpResult(void);
+ vector<mlir::Plugin::LoopOp> LoopOpsResult(void);
+ vector<std::pair<mlir::Block*, mlir::Block*> > EdgesResult(void);
+ std::pair<mlir::Block*, mlir::Block*> EdgeResult(void);
+ vector<mlir::Operation *> GetOpResult(void);
+ bool GetBoolResult(void);
+ uint64_t GetIdResult(void);
+ vector<uint64_t> GetIdsResult(void);
+ mlir::Value GetValueResult(void);
+ vector<mlir::Plugin::PhiOp> GetPhiOpsResult(void);
+
+private:
+ PluginGrpc pluginGrpc;
+ PluginJson json;
+ int64_t integerResult;
+ string stringResult;
+ vector<mlir::Plugin::FunctionOp> funcOpData;
+ vector<mlir::Plugin::LocalDeclOp> decls;
+ vector<mlir::Plugin::LoopOp> loops;
+ mlir::Plugin::LoopOp loop;
+ vector<std::pair<mlir::Block*, mlir::Block*> > edges;
+ std::pair<mlir::Block*, mlir::Block*> edge;
+ vector<mlir::Operation *> opData;
+ bool boolResult;
+ uint64_t idResult;
+ vector<uint64_t> idsResult;
+ mlir::Value valueResult;
+};
+} // namespace PinCom
+
+#endif
\ No newline at end of file
diff --git a/include/PluginServer/PluginGrpc.h b/include/PluginServer/PluginGrpc.h
new file mode 100755
index 0000000..9d30dce
--- /dev/null
+++ b/include/PluginServer/PluginGrpc.h
@@ -0,0 +1,65 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the GrpcService class.
+ 主要完成功能完成grpc server服务的注册提供server和client之间grpc收发接口
+*/
+
+#ifndef PLUGIN_GRPC_H
+#define PLUGIN_GRPC_H
+
+#include <grpcpp/grpcpp.h>
+#include "plugin.grpc.pb.h"
+
+namespace PinGrpc {
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::ServerReaderWriter;
+using grpc::Status;
+
+using plugin::PluginService;
+using plugin::ClientMsg;
+using plugin::ServerMsg;
+using std::string;
+
+class PluginGrpc final : public PluginService::Service {
+public:
+ PluginGrpc()
+ {
+ shutdown = false;
+ }
+ /* 定义的grpc服务端和客户端通信的接口函数 */
+ Status ReceiveSendMsg(ServerContext* context, ServerReaderWriter<ServerMsg, ClientMsg>* stream) override;
+ /* 服务端发送数据给client接口 */
+ void ServerSend(const string& key, const string& value);
+ bool RegisterServer(const string& port);
+ void Run();
+ void ShutDown()
+ {
+ shutdown = true;
+ }
+
+private:
+ void ServerMonitorThread(); // 监听线程,shutdown为true时,grpc server退出
+ bool shutdown; // 是否关闭grpc server
+ ServerReaderWriter<ServerMsg, ClientMsg> *grpcStream; // 保存server和client通信的grpc stream指针
+ std::unique_ptr<Server> grpcServer;
+};
+} // namespace PinGrpc
+
+#endif
diff --git a/include/PluginServer/PluginJson.h b/include/PluginServer/PluginJson.h
new file mode 100755
index 0000000..6f46187
--- /dev/null
+++ b/include/PluginServer/PluginJson.h
@@ -0,0 +1,68 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the PluginJson class.
+ 主要完成功能:将序列化数据进行反序列化
+*/
+
+#ifndef PLUGIN_JSON_H
+#define PLUGIN_JSON_H
+
+#include <json/json.h>
+#include "Dialect/PluginOps.h"
+#include "Dialect/PluginTypes.h"
+
+using std::string;
+using std::map;
+using std::vector;
+
+namespace PinJson {
+class PluginJson {
+public:
+ void FuncOpJsonDeSerialize(const string&, vector<mlir::Plugin::FunctionOp>&);
+ void LocalDeclOpJsonDeSerialize(const string&,
+ vector<mlir::Plugin::LocalDeclOp>&);
+ void LoopOpsJsonDeSerialize(const string&, vector<mlir::Plugin::LoopOp>&);
+ void EdgesJsonDeSerialize(const string&,
+ vector<std::pair<mlir::Block*, mlir::Block*>>&);
+ void EdgeJsonDeSerialize(const string&, std::pair<mlir::Block*, mlir::Block*>&);
+ void IdsJsonDeSerialize(const string&, vector<uint64_t>&);
+ mlir::Operation *CallOpJsonDeSerialize(const string&);
+ mlir::Operation *CondOpJsonDeSerialize(const string&);
+ mlir::Operation *RetOpJsonDeSerialize(const string&);
+ mlir::Operation *FallThroughOpJsonDeSerialize(const string&);
+ mlir::Operation *PhiOpJsonDeSerialize(const string&);
+ mlir::Operation *AssignOpJsonDeSerialize(const string&);
+ void GetPhiOpsJsonDeSerialize(const string&, vector<mlir::Operation *>&);
+ mlir::Value SSAOpJsonDeSerialize(const string& data);
+ mlir::Plugin::LoopOp LoopOpJsonDeSerialize(const string& data);
+ PluginIR::PluginTypeBase TypeJsonDeSerialize(const string& data);
+ void OpJsonDeSerialize(const string&, vector<mlir::Operation *>&);
+ /* 将整形数据反序列化 */
+ void IntegerDeSerialize(const string& data, int64_t& result);
+ /* 将字符串数据反序列化 */
+ void StringDeSerialize(const string& data, string& result);
+ /* 将json格式数据解析成map<string, string>格式 */
+ void GetAttributes(Json::Value node, map<string, string>& attributes);
+ mlir::Value ValueJsonDeSerialize(Json::Value valueJson);
+ Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase& type);
+ mlir::Value MemRefDeSerialize(const string& data);
+ bool ProcessBlock(mlir::Block*, mlir::Region&, const Json::Value&);
+};
+} // namespace PinJson
+
+#endif
diff --git a/include/user/user.h b/include/user/user.h
new file mode 100755
index 0000000..1fb7a30
--- /dev/null
+++ b/include/user/user.h
@@ -0,0 +1,27 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the User Init.
+*/
+
+#ifndef PLUGIN_USER_H
+#define PLUGIN_USER_H
+
+/* 将注册点及用户函数注册给server, server初始化时调用 */
+void RegisterCallbacks(void);
+
+#endif
diff --git a/lib/Dialect/PluginDialect.cpp b/lib/Dialect/PluginDialect.cpp
index 001fdab..95b38cf 100644
--- a/lib/Dialect/PluginDialect.cpp
+++ b/lib/Dialect/PluginDialect.cpp
@@ -14,11 +14,11 @@
*/
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
//
// This file defines Plugin dialect.
//
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
#include "Dialect/PluginDialect.h"
#include "Dialect/PluginOps.h"
@@ -27,21 +27,22 @@
using namespace mlir;
using namespace mlir::Plugin;
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin dialect.
-//===----------------------------------------------------------------------===//
-
-void PluginDialect::initialize() {
- addTypes<
- PluginIR::PluginIntegerType,
- PluginIR::PluginFloatType,
- PluginIR::PluginPointerType,
- PluginIR::PluginBooleanType,
- PluginIR::PluginVoidType,
- PluginIR::PluginUndefType>();
-
- addOperations<
+// ===----------------------------------------------------------------------===//
+
+void PluginDialect::initialize()
+{
+ addTypes<
+ PluginIR::PluginIntegerType,
+ PluginIR::PluginFloatType,
+ PluginIR::PluginPointerType,
+ PluginIR::PluginBooleanType,
+ PluginIR::PluginVoidType,
+ PluginIR::PluginUndefType>();
+
+ addOperations<
#define GET_OP_LIST
#include "Dialect/PluginOps.cpp.inc"
- >();
+ >();
}
\ No newline at end of file
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index 4d8974a..a0591b5 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -14,11 +14,11 @@
*/
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
//
// This file defines operations in the Plugin dialect.
//
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
#include "PluginAPI/PluginServerAPI.h"
#include "PluginAPI/ControlFlowAPI.h"
@@ -105,7 +105,8 @@ void LocalDeclOp::build(OpBuilder &builder, OperationState &state,
void LoopOp::build(mlir::OpBuilder &builder, mlir::OperationState &state,
uint64_t id, uint32_t index, uint64_t innerLoopId,
- uint64_t outerLoopId, uint32_t numBlock) {
+ uint64_t outerLoopId, uint32_t numBlock)
+{
LoopOp::build(builder, state,
builder.getI64IntegerAttr(id),
builder.getI32IntegerAttr(index),
@@ -219,7 +220,7 @@ void LoopOp::AddBlock(mlir::Block* block)
pluginAPI.AddBlockToLoop(blockId, loopId);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// PlaceholderOp
void PlaceholderOp::build(OpBuilder &builder, OperationState &state,
@@ -233,7 +234,7 @@ void PlaceholderOp::build(OpBuilder &builder, OperationState &state,
state.addTypes(retType);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// MemOp
void MemOp::build(OpBuilder &builder, OperationState &state,
@@ -248,7 +249,7 @@ void MemOp::build(OpBuilder &builder, OperationState &state,
if (retType) state.addTypes(retType);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// SSAOp
void SSAOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
@@ -270,23 +271,23 @@ void SSAOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
Value SSAOp::MakeSSA(OpBuilder &builder, Type t)
{
PluginAPI::PluginServerAPI pluginAPI;
- PinServer::PluginServer::GetInstance()->SetOpBuilder(builder);
+ PinServer::PluginServer::GetInstance()->SetOpBuilder(&builder);
return pluginAPI.CreateSSAOp(t);
}
Value SSAOp::Copy()
{
PluginAPI::PluginServerAPI pluginAPI;
- OpBuilder builder(this->getOperation());
- PinServer::PluginServer::GetInstance()->SetOpBuilder(builder);
+ static OpBuilder builder(this->getOperation());
+ PinServer::PluginServer::GetInstance()->SetOpBuilder(&builder);
return pluginAPI.CopySSAOp(this->idAttr().getInt());
}
Value SSAOp::GetCurrentDef()
{
PluginAPI::PluginServerAPI pluginAPI;
- OpBuilder builder(this->getOperation());
- PinServer::PluginServer::GetInstance()->SetOpBuilder(builder);
+ static OpBuilder builder(this->getOperation());
+ PinServer::PluginServer::GetInstance()->SetOpBuilder(&builder);
return pluginAPI.GetCurrentDefFromSSA(this->idAttr().getInt());
}
@@ -307,7 +308,7 @@ Operation* SSAOp::GetSSADefOperation()
return pluginAPI.GetSSADefOperation(definingId);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// ConstOp
void ConstOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
@@ -325,11 +326,11 @@ void ConstOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
Value ConstOp::CreateConst(OpBuilder &builder, Attribute value, Type retType)
{
PluginAPI::PluginServerAPI pluginAPI;
- PinServer::PluginServer::GetInstance()->SetOpBuilder(builder);
+ PinServer::PluginServer::GetInstance()->SetOpBuilder(&builder);
return pluginAPI.CreateConstOp(value, retType);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// PointerOp
void PointerOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
@@ -344,7 +345,7 @@ void PointerOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
state.addAttribute("pointeeReadOnly", builder.getBoolAttr(pointeeReadOnly));
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// CallOp
void CallOp::build(OpBuilder &builder, OperationState &state,
@@ -414,13 +415,14 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
state.addAttribute("callee", builder.getSymbolRefAttr("ctzll"));
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// CondOp
void CondOp::build(OpBuilder &builder, OperationState &state,
uint64_t id, uint64_t address, IComparisonCode condCode,
Value lhs, Value rhs, Block* tb, Block* fb, uint64_t tbaddr,
- uint64_t fbaddr, Value trueLabel, Value falseLabel) {
+ uint64_t fbaddr, Value trueLabel, Value falseLabel)
+{
state.addAttribute("id", builder.getI64IntegerAttr(id));
state.addAttribute("address", builder.getI64IntegerAttr(address));
state.addAttribute("tbaddr", builder.getI64IntegerAttr(tbaddr));
@@ -449,19 +451,18 @@ void CondOp::build(OpBuilder &builder, OperationState &state,
state.addAttribute("id", builder.getI64IntegerAttr(id));
state.addOperands({lhs, rhs});
state.addAttribute("condCode",
- builder.getI32IntegerAttr(static_cast<int32_t>(condCode)));
+ builder.getI32IntegerAttr(static_cast<int32_t>(condCode)));
state.addSuccessors(tb);
state.addSuccessors(fb);
state.addAttribute("tbaddr", builder.getI64IntegerAttr(tbaddr));
state.addAttribute("fbaddr", builder.getI64IntegerAttr(fbaddr));
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// PhiOp
void PhiOp::build(OpBuilder &builder, OperationState &state,
- ArrayRef<Value> operands, uint64_t id,
- uint32_t capacity, uint32_t nArgs)
+ ArrayRef<Value> operands, uint64_t id, uint32_t capacity, uint32_t nArgs)
{
state.addAttribute("id", builder.getI64IntegerAttr(id));
state.addAttribute("capacity", builder.getI32IntegerAttr(capacity));
@@ -472,8 +473,8 @@ void PhiOp::build(OpBuilder &builder, OperationState &state,
Value PhiOp::GetResult()
{
PluginAPI::PluginServerAPI pluginAPI;
- OpBuilder builder(this->getOperation());
- PinServer::PluginServer::GetInstance()->SetOpBuilder(builder);
+ static OpBuilder builder(this->getOperation());
+ PinServer::PluginServer::GetInstance()->SetOpBuilder(&builder);
return pluginAPI.GetResultFromPhi(this->idAttr().getInt());
}
@@ -507,7 +508,7 @@ Value PhiOp::GetArgDef(int i)
}
return getOperand(i);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// AssignOp
void AssignOp::build(OpBuilder &builder, OperationState &state,
@@ -538,7 +539,7 @@ void AssignOp::build(OpBuilder &builder, OperationState &state,
state.addOperands(operands);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// BaseOp
void BaseOp::build(OpBuilder &builder, OperationState &state,
@@ -548,7 +549,7 @@ void BaseOp::build(OpBuilder &builder, OperationState &state,
state.addAttribute("opCode", builder.getStringAttr(opCode));
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// FallThroughOp
void FallThroughOp::build(OpBuilder &builder, OperationState &state,
@@ -572,7 +573,7 @@ void FallThroughOp::build(OpBuilder &builder, OperationState &state,
state.addSuccessors(dest);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// RetOp
void RetOp::build(OpBuilder &builder, OperationState &state, uint64_t address)
@@ -580,9 +581,9 @@ void RetOp::build(OpBuilder &builder, OperationState &state, uint64_t address)
state.addAttribute("address", builder.getI64IntegerAttr(address));
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// TableGen'd op method definitions
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
#define GET_OP_CLASSES
#include "Dialect/PluginOps.cpp.inc"
\ No newline at end of file
diff --git a/lib/Dialect/PluginTypes.cpp b/lib/Dialect/PluginTypes.cpp
index c33d9e0..c0a58c2 100644
--- a/lib/Dialect/PluginTypes.cpp
+++ b/lib/Dialect/PluginTypes.cpp
@@ -36,16 +36,19 @@ namespace detail {
/// The hash key used for uniquing.
using KeyTy = std::pair<unsigned, PluginIntegerType::SignednessSemantics>;
- static llvm::hash_code hashKey(const KeyTy &key) {
+ static llvm::hash_code hashKey(const KeyTy &key)
+ {
return llvm::hash_value(key);
}
- bool operator==(const KeyTy &key) const {
+ bool operator==(const KeyTy &key) const
+ {
return KeyTy(width, signedness) == key;
}
static PluginIntegerTypeStorage *construct(TypeStorageAllocator &allocator,
- KeyTy key) {
+ KeyTy key)
+ {
return new (allocator.allocate<PluginIntegerTypeStorage>())
PluginIntegerTypeStorage(key.first, key.second);
}
@@ -60,12 +63,13 @@ namespace detail {
/// The hash key used for uniquing.
using KeyTy = unsigned;
- bool operator==(const KeyTy &key) const {
+ bool operator==(const KeyTy &key) const
+ {
return KeyTy(width) == key;
}
- static PluginFloatTypeStorage *construct(TypeStorageAllocator &allocator,
- KeyTy key) {
+ static PluginFloatTypeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
return new (allocator.allocate<PluginFloatTypeStorage>())
PluginFloatTypeStorage(key);
}
@@ -79,13 +83,14 @@ namespace detail {
PluginPointerTypeStorage(const KeyTy &key)
: pointee(std::get<0>(key)), readOnlyPointee(std::get<1>(key)) {}
- static PluginPointerTypeStorage *construct(TypeStorageAllocator &allocator,
- KeyTy key) {
+ static PluginPointerTypeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
return new (allocator.allocate<PluginPointerTypeStorage>())
PluginPointerTypeStorage(key);
}
- bool operator==(const KeyTy &key) const {
+ bool operator==(const KeyTy &key) const
+ {
return std::make_tuple(pointee, readOnlyPointee) == key;
}
@@ -96,9 +101,9 @@ namespace detail {
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin TypeBase
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
PluginTypeID PluginTypeBase::getPluginTypeID ()
{
@@ -117,7 +122,7 @@ PluginTypeID PluginTypeBase::getPluginTypeID ()
if (auto Ty = dyn_cast<PluginIR::PluginPointerType>()) {
return Ty.getPluginTypeID ();
}
- return PluginTypeID::UndefTyID;
+ return PluginTypeID::UndefTyID;
}
unsigned PluginTypeBase::getPluginIntOrFloatBitWidth ()
@@ -157,9 +162,9 @@ unsigned PluginTypeBase::getTypeSize ()
return size;
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin Integer Type
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
unsigned PluginIntegerType::getWidth() const
{
@@ -173,10 +178,8 @@ PluginIntegerType::SignednessSemantics PluginIntegerType::getSignedness() const
PluginTypeID PluginIntegerType::getPluginTypeID()
{
- if (isSigned())
- {
- switch (getWidth())
- {
+ if (isSigned()) {
+ switch (getWidth()) {
case 1:
return PluginTypeID::IntegerTy1ID;
case 8:
@@ -191,10 +194,8 @@ PluginTypeID PluginIntegerType::getPluginTypeID()
return PluginTypeID::UndefTyID;
}
}
- if (isUnsigned())
- {
- switch (getWidth())
- {
+ if (isUnsigned()) {
+ switch (getWidth()) {
case 1:
return PluginTypeID::UIntegerTy1ID;
case 8:
@@ -212,15 +213,15 @@ PluginTypeID PluginIntegerType::getPluginTypeID()
return PluginTypeID::UndefTyID;
}
-PluginIntegerType PluginIntegerType::get (MLIRContext *context, unsigned width, PluginIntegerType::SignednessSemantics signedness)
+PluginIntegerType PluginIntegerType::get (MLIRContext *context, unsigned width,
+ PluginIntegerType::SignednessSemantics signedness)
{
return Base::get(context, width, signedness);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin Float Type
-//===----------------------------------------------------------------------===//
-
+// ===----------------------------------------------------------------------===//
unsigned PluginFloatType::getWidth () const
{
return getImpl()->width;
@@ -228,10 +229,12 @@ unsigned PluginFloatType::getWidth () const
PluginTypeID PluginFloatType::getPluginTypeID()
{
- if (getWidth() == 32)
+ if (getWidth() == 32) {
return PluginTypeID::FloatTyID;
- if (getWidth() == 64)
+ }
+ if (getWidth() == 64) {
return PluginTypeID::DoubleTyID;
+ }
return PluginTypeID::UndefTyID;
}
@@ -240,36 +243,36 @@ PluginFloatType PluginFloatType::get (MLIRContext *context, unsigned width)
return Base::get(context, width);
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin Boolean Type
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
PluginTypeID PluginBooleanType::getPluginTypeID()
{
return PluginTypeID::BooleanTyID;
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin Void Type
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
PluginTypeID PluginVoidType::getPluginTypeID()
{
return PluginTypeID::VoidTyID;
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin Undef Type
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
PluginTypeID PluginUndefType::getPluginTypeID()
{
return PluginTypeID::UndefTyID;
}
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
// Plugin Pointer Type
-//===----------------------------------------------------------------------===//
+// ===----------------------------------------------------------------------===//
PluginTypeID PluginPointerType::getPluginTypeID()
{
diff --git a/lib/PluginAPI/ControlFlowAPI.cpp b/lib/PluginAPI/ControlFlowAPI.cpp
index b598f57..92c0dd3 100644
--- a/lib/PluginAPI/ControlFlowAPI.cpp
+++ b/lib/PluginAPI/ControlFlowAPI.cpp
@@ -15,7 +15,6 @@
*/
#include "PluginAPI/ControlFlowAPI.h"
-#include "PluginServer/PluginLog.h"
namespace PluginAPI {
using namespace PinServer;
@@ -60,20 +59,18 @@ bool ControlFlowAPI::UpdateSSA(void)
bool ControlFlowAPI::GetUpdateOperationResult(const string &funName)
{
Json::Value root;
- pluginAPI.WaitClientResult(funName, root.toStyledString());
- return PluginServer::GetInstance()->GetBoolResult();
+ return PluginServer::GetInstance()->GetBoolResult(funName, root.toStyledString());
}
vector<PhiOp> ControlFlowAPI::GetPhiOperationResult(const string &funName, const string& params)
{
- pluginAPI.WaitClientResult(funName, params);;
- vector<PhiOp> retOps = PluginServer::GetInstance()->GetPhiOpsResult();
+ vector<PhiOp> retOps = PluginServer::GetInstance()->GetPhiOpsResult(funName, params);
return retOps;
}
void ControlFlowAPI::GetDominatorSetOperationResult(const string &funName, const string& params)
{
- pluginAPI.WaitClientResult(funName, params);;
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
return;
}
@@ -97,12 +94,11 @@ uint64_t ControlFlowAPI::CreateBlock(mlir::Block* b, uint64_t funcAddr, uint64_t
root["funcaddr"] = std::to_string(funcAddr);
root["bbaddr"] = std::to_string(bbAddr);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);;
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
return PluginServer::GetInstance()->GetBlockResult(b);
}
-void ControlFlowAPI::DeleteBlock(mlir::Block* b, uint64_t funcAddr,
- uint64_t bbAddr)
+void ControlFlowAPI::DeleteBlock(mlir::Block* b, uint64_t funcAddr, uint64_t bbAddr)
{
Json::Value root;
string funName = __func__;
@@ -111,14 +107,12 @@ void ControlFlowAPI::DeleteBlock(mlir::Block* b, uint64_t funcAddr,
root["funcaddr"] = std::to_string(funcAddr);
root["bbaddr"] = std::to_string(bbAddr);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);;
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
PluginServer::GetInstance()->EraseBlock(b);
- // b->erase();
}
/* dir: 1 or 2 */
-void ControlFlowAPI::SetImmediateDominator(uint64_t dir, uint64_t bbAddr,
- uint64_t domiAddr)
+void ControlFlowAPI::SetImmediateDominator(uint64_t dir, uint64_t bbAddr, uint64_t domiAddr)
{
Json::Value root;
string funName = __func__;
@@ -128,7 +122,7 @@ void ControlFlowAPI::SetImmediateDominator(uint64_t dir, uint64_t bbAddr,
root["bbaddr"] = std::to_string(bbAddr);
root["domiaddr"] = std::to_string(domiAddr);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);;
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
/* dir: 1 or 2 */
@@ -140,8 +134,7 @@ uint64_t ControlFlowAPI::GetImmediateDominator(uint64_t dir, uint64_t bbAddr)
root["dir"] = std::to_string(dir);
root["bbaddr"] = std::to_string(bbAddr);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);;
- return PluginServer::GetInstance()->GetIdResult();
+ return PluginServer::GetInstance()->GetIdResult(funName, params);
}
/* dir: 1 or 2 */
@@ -153,8 +146,7 @@ uint64_t ControlFlowAPI::RecomputeDominator(uint64_t dir, uint64_t bbAddr)
root["dir"] = std::to_string(dir);
root["bbaddr"] = std::to_string(bbAddr);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);;
- return PluginServer::GetInstance()->GetIdResult();
+ return PluginServer::GetInstance()->GetIdResult(funName, params);
}
mlir::Value ControlFlowAPI::CreateNewDef(mlir::Value oldValue,
@@ -170,8 +162,7 @@ mlir::Value ControlFlowAPI::CreateNewDef(mlir::Value oldValue,
uint64_t defId = 0;
root["defId"] = std::to_string(defId);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
void ControlFlowAPI::CreateFallthroughOp(
@@ -182,7 +173,7 @@ void ControlFlowAPI::CreateFallthroughOp(
root["address"] = std::to_string(address);
root["destaddr"] = std::to_string(destaddr);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
void ControlFlowAPI::RemoveEdge(uint64_t src, uint64_t dest)
@@ -192,7 +183,7 @@ void ControlFlowAPI::RemoveEdge(uint64_t src, uint64_t dest)
root["src"] = std::to_string(src);
root["dest"] = std::to_string(dest);
string params = root.toStyledString();
- pluginAPI.WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
} // namespace PluginAPI
diff --git a/lib/PluginAPI/PluginServerAPI.cpp b/lib/PluginAPI/PluginServerAPI.cpp
index 5ab27d7..523e08d 100644
--- a/lib/PluginAPI/PluginServerAPI.cpp
+++ b/lib/PluginAPI/PluginServerAPI.cpp
@@ -18,24 +18,27 @@
*/
#include "PluginAPI/PluginServerAPI.h"
-#include "PluginServer/PluginLog.h"
+#include "PluginServer/PluginJson.h"
namespace PluginAPI {
using namespace PinServer;
using namespace mlir::Plugin;
-int CheckAttribute(string &attribute)
+static bool CheckAttribute(string &attribute)
{
- /* if (attribute == "") {
+ if (attribute == "NULL") {
printf("param attribute is NULL,check fail!\n");
- return -1;
- } */
- return 0;
+ return false;
+ }
+ return true;
}
-int CheckID(uintptr_t id)
+static bool CheckID(uintptr_t id)
{
- return 0;
+ if (id == 0) {
+ return false;
+ }
+ return true;
}
static uint64_t GetValueId(mlir::Value v)
@@ -52,21 +55,60 @@ static uint64_t GetValueId(mlir::Value v)
}
return 0;
}
+int64_t PluginServerAPI::GetInjectDataAddress()
+{
+ string funName = __func__;
+ string params = "";
-void PluginServerAPI::WaitClientResult(const string& funName, const string& params)
+ return PluginServer::GetInstance()->GetIntegerDataResult(funName, params);
+}
+
+string PluginServerAPI::GetDeclSourceFile(int64_t clientDataAddr)
{
- PluginServer *server = PluginServer::GetInstance();
- server->SetApiFuncName(funName);
- server->SetApiFuncParams(params);
- server->SetUserFunState(STATE_BEGIN);
- server->SemPost();
- while (1) {
- server->ClientReturnSemWait();
- if (server->GetUserFunState() == STATE_RETURN) { // wait client result
- server->SetUserFunState(STATE_WAIT_BEGIN);
- break;
- }
- }
+ string funName = __func__;
+ string params = std::to_string(clientDataAddr);
+
+ return PluginServer::GetInstance()->GetStringDataResult(funName, params);
+}
+
+string PluginServerAPI::VariableName(int64_t clientDataAddr)
+{
+ string funName = __func__;
+ string params = std::to_string(clientDataAddr);
+
+ return PluginServer::GetInstance()->GetStringDataResult(funName, params);
+}
+
+string PluginServerAPI::FuncName(int64_t clientDataAddr)
+{
+ string funName = __func__;
+ string params = std::to_string(clientDataAddr);
+
+ return PluginServer::GetInstance()->GetStringDataResult(funName, params);
+}
+
+string PluginServerAPI::GetIncludeFile()
+{
+ string funName = __func__;
+ string params = "";
+
+ return PluginServer::GetInstance()->GetStringDataResult(funName, params);
+}
+
+int PluginServerAPI::GetDeclSourceLine(int64_t clientDataAddr)
+{
+ string funName = __func__;
+ string params = std::to_string(clientDataAddr);
+
+ return PluginServer::GetInstance()->GetIntegerDataResult(funName, params);
+}
+
+int PluginServerAPI::GetDeclSourceColumn(int64_t clientDataAddr)
+{
+ string funName = __func__;
+ string params = std::to_string(clientDataAddr);
+
+ return PluginServer::GetInstance()->GetIntegerDataResult(funName, params);
}
bool PluginServerAPI::SetCurrentDefInSSA(uint64_t varId, uint64_t defId)
@@ -76,8 +118,7 @@ bool PluginServerAPI::SetCurrentDefInSSA(uint64_t varId, uint64_t defId)
root["varId"] = std::to_string(varId);
root["defId"] = std::to_string(defId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetBoolResult();
+ return PluginServer::GetInstance()->GetBoolResult(funName, params);
}
mlir::Value PluginServerAPI::GetCurrentDefFromSSA(uint64_t varId)
@@ -86,8 +127,7 @@ mlir::Value PluginServerAPI::GetCurrentDefFromSSA(uint64_t varId)
string funName = __func__;
root["varId"] = std::to_string(varId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
mlir::Value PluginServerAPI::CopySSAOp(uint64_t id)
@@ -96,8 +136,7 @@ mlir::Value PluginServerAPI::CopySSAOp(uint64_t id)
string funName = __func__;
root["id"] = std::to_string(id);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
mlir::Value PluginServerAPI::CreateSSAOp(mlir::Type t)
@@ -105,17 +144,10 @@ mlir::Value PluginServerAPI::CreateSSAOp(mlir::Type t)
Json::Value root;
string funName = __func__;
auto baseTy = t.dyn_cast<PluginIR::PluginTypeBase>();
- root = PluginServer::GetInstance()->TypeJsonSerialize(baseTy);
+ PinJson::PluginJson json;
+ root = json.TypeJsonSerialize(baseTy);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
-}
-
-vector<FunctionOp> PluginServerAPI::GetFunctionOpResult(const string& funName, const string& params)
-{
- WaitClientResult(funName, params);
- vector<FunctionOp> retOps = PluginServer::GetInstance()->GetFunctionOpResult();
- return retOps;
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
vector<FunctionOp> PluginServerAPI::GetAllFunc()
@@ -124,7 +156,7 @@ vector<FunctionOp> PluginServerAPI::GetAllFunc()
string funName = __func__;
string params = root.toStyledString();
- return GetFunctionOpResult(funName, params);
+ return PluginServer::GetInstance()->GetFunctionOpResult(funName, params);
}
PhiOp PluginServerAPI::GetPhiOp(uint64_t id)
@@ -133,8 +165,7 @@ PhiOp PluginServerAPI::GetPhiOp(uint64_t id)
string funName = __func__;
root["id"] = std::to_string(id);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- vector<mlir::Operation*> opRet = PluginServer::GetInstance()->GetOpResult();
+ vector<mlir::Operation*> opRet = PluginServer::GetInstance()->GetOpResult(funName, params);
return llvm::dyn_cast<PhiOp>(opRet[0]);
}
@@ -144,8 +175,7 @@ CallOp PluginServerAPI::GetCallOp(uint64_t id)
string funName = __func__;
root["id"] = std::to_string(id);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- vector<mlir::Operation*> opRet = PluginServer::GetInstance()->GetOpResult();
+ vector<mlir::Operation*> opRet = PluginServer::GetInstance()->GetOpResult(funName, params);
return llvm::dyn_cast<CallOp>(opRet[0]);
}
@@ -156,14 +186,10 @@ bool PluginServerAPI::SetLhsInCallOp(uint64_t callId, uint64_t lhsId)
root["callId"] = std::to_string(callId);
root["lhsId"] = std::to_string(lhsId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetBoolResult();
+ return PluginServer::GetInstance()->GetBoolResult(funName, params);
}
-uint32_t PluginServerAPI::AddArgInPhiOp(uint64_t phiId,
- uint64_t argId,
- uint64_t predId,
- uint64_t succId)
+uint32_t PluginServerAPI::AddArgInPhiOp(uint64_t phiId, uint64_t argId, uint64_t predId, uint64_t succId)
{
Json::Value root;
string funName = __func__;
@@ -172,8 +198,7 @@ uint32_t PluginServerAPI::AddArgInPhiOp(uint64_t phiId,
root["predId"] = std::to_string(predId);
root["succId"] = std::to_string(succId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetIdResult();
+ return PluginServer::GetInstance()->GetIdResult(funName, params);
}
uint64_t PluginServerAPI::CreateCondOp(uint64_t blockId, IComparisonCode iCode,
@@ -189,8 +214,7 @@ uint64_t PluginServerAPI::CreateCondOp(uint64_t blockId, IComparisonCode iCode,
root["tbaddr"] = std::to_string(tbaddr);
root["fbaddr"] = std::to_string(fbaddr);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetIdResult();
+ return PluginServer::GetInstance()->GetIdResult(funName, params);
}
uint64_t PluginServerAPI::CreateAssignOp(uint64_t blockId, IExprCode iCode, vector<uint64_t> &argIds)
@@ -207,8 +231,7 @@ uint64_t PluginServerAPI::CreateAssignOp(uint64_t blockId, IExprCode iCode, vect
}
root["argIds"] = item;
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetIdResult();
+ return PluginServer::GetInstance()->GetIdResult(funName, params);
}
uint64_t PluginServerAPI::CreateCallOp(uint64_t blockId, uint64_t funcId,
@@ -226,8 +249,7 @@ uint64_t PluginServerAPI::CreateCallOp(uint64_t blockId, uint64_t funcId,
}
root["argIds"] = item;
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetIdResult();
+ return PluginServer::GetInstance()->GetIdResult(funName, params);
}
mlir::Value PluginServerAPI::CreateConstOp(mlir::Attribute attr, mlir::Type type)
@@ -235,15 +257,15 @@ mlir::Value PluginServerAPI::CreateConstOp(mlir::Attribute attr, mlir::Type type
Json::Value root;
string funName = __func__;
auto baseTy = type.dyn_cast<PluginIR::PluginTypeBase>();
- root = PluginServer::GetInstance()->TypeJsonSerialize(baseTy);
+ PinJson::PluginJson json;
+ root = json.TypeJsonSerialize(baseTy);
string valueStr;
if (type.isa<PluginIR::PluginIntegerType>()) {
valueStr = std::to_string(attr.cast<mlir::IntegerAttr>().getInt());
}
root["value"] = valueStr;
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
mlir::Value PluginServerAPI::GetResultFromPhi(uint64_t phiId)
@@ -252,8 +274,7 @@ mlir::Value PluginServerAPI::GetResultFromPhi(uint64_t phiId)
string funName = __func__;
root["id"] = std::to_string(phiId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
PhiOp PluginServerAPI::CreatePhiOp(uint64_t argId, uint64_t blockId)
@@ -263,8 +284,7 @@ PhiOp PluginServerAPI::CreatePhiOp(uint64_t argId, uint64_t blockId)
root["blockId"] = std::to_string(blockId);
root["argId"] = std::to_string(argId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- vector<mlir::Operation*> opRet = PluginServer::GetInstance()->GetOpResult();
+ vector<mlir::Operation*> opRet = PluginServer::GetInstance()->GetOpResult(funName, params);
return llvm::dyn_cast<PhiOp>(opRet[0]);
}
@@ -275,8 +295,7 @@ mlir::Value PluginServerAPI::ConfirmValue(mlir::Value v)
uint64_t valId = GetValueId(v);
root["valId"] = std::to_string(valId);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
mlir::Value PluginServerAPI::BuildMemRef(PluginIR::PluginTypeBase type,
@@ -288,55 +307,47 @@ mlir::Value PluginServerAPI::BuildMemRef(PluginIR::PluginTypeBase type,
uint64_t offsetId = GetValueId(offset);
root["baseId"] = baseId;
root["offsetId"] = offsetId;
- root["type"] = PluginServer::GetInstance()->TypeJsonSerialize(type);
+ PinJson::PluginJson json;
+ root["type"] = json.TypeJsonSerialize(type);
string params = root.toStyledString();
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetValueResult();
+ return PluginServer::GetInstance()->GetValueResult(funName, params);
}
PluginIR::PluginTypeID PluginServerAPI::GetTypeCodeFromString(string type)
{
if (type == "VoidTy") {
return PluginIR::PluginTypeID::VoidTyID;
- }else if (type == "UIntegerTy1") {
+ } else if (type == "UIntegerTy1") {
return PluginIR::PluginTypeID::UIntegerTy1ID;
- }else if (type == "UIntegerTy8") {
+ } else if (type == "UIntegerTy8") {
return PluginIR::PluginTypeID::UIntegerTy8ID;
- }else if (type == "UIntegerTy16") {
+ } else if (type == "UIntegerTy16") {
return PluginIR::PluginTypeID::UIntegerTy16ID;
- }else if (type == "UIntegerTy32") {
+ } else if (type == "UIntegerTy32") {
return PluginIR::PluginTypeID::UIntegerTy32ID;
- }else if (type == "UIntegerTy64") {
+ } else if (type == "UIntegerTy64") {
return PluginIR::PluginTypeID::UIntegerTy64ID;
- }else if (type == "IntegerTy1") {
+ } else if (type == "IntegerTy1") {
return PluginIR::PluginTypeID::IntegerTy1ID;
- }else if (type == "IntegerTy8") {
+ } else if (type == "IntegerTy8") {
return PluginIR::PluginTypeID::IntegerTy8ID;
- }else if (type == "IntegerTy16") {
+ } else if (type == "IntegerTy16") {
return PluginIR::PluginTypeID::IntegerTy16ID;
- }else if (type == "IntegerTy32") {
+ } else if (type == "IntegerTy32") {
return PluginIR::PluginTypeID::IntegerTy32ID;
- }else if (type == "IntegerTy64") {
+ } else if (type == "IntegerTy64") {
return PluginIR::PluginTypeID::IntegerTy64ID;
- }else if (type == "BooleanTy") {
+ } else if (type == "BooleanTy") {
return PluginIR::PluginTypeID::BooleanTyID;
- }else if (type == "FloatTy") {
+ } else if (type == "FloatTy") {
return PluginIR::PluginTypeID::FloatTyID;
- }else if (type == "DoubleTy") {
+ } else if (type == "DoubleTy") {
return PluginIR::PluginTypeID::DoubleTyID;
}
return PluginIR::PluginTypeID::UndefTyID;
}
-vector<LocalDeclOp> PluginServerAPI::GetDeclOperationResult(const string&funName,
- const string& params)
-{
- WaitClientResult(funName, params);
- vector<LocalDeclOp> retDecls = PluginServer::GetInstance()->GetLocalDeclResult();
- return retDecls;
-}
-
vector<LocalDeclOp> PluginServerAPI::GetDecls(uint64_t funcID)
{
Json::Value root;
@@ -344,48 +355,12 @@ vector<LocalDeclOp> PluginServerAPI::GetDecls(uint64_t funcID)
root["funcId"] = std::to_string(funcID);
string params = root.toStyledString();
- return GetDeclOperationResult(funName, params);
-}
-
-vector<LoopOp> PluginServerAPI::GetLoopsResult(const string& funName,
- const string& params)
-{
- WaitClientResult(funName, params);
- vector<LoopOp> loops = PluginServer::GetInstance()->LoopOpsResult();
- return loops;
-}
-
-LoopOp PluginServerAPI::GetLoopResult(const string& funName, const string& params)
-{
- WaitClientResult(funName, params);
- LoopOp loop = PluginServer::GetInstance()->LoopOpResult();
- return loop;
-}
-
-bool PluginServerAPI::GetBoolResult(const string& funName, const string& params)
-{
- WaitClientResult(funName, params);
- return PluginServer::GetInstance()->GetBoolResult();
-}
-
-pair<mlir::Block*, mlir::Block*> PluginServerAPI::EdgeResult(const string& funName, const string& params)
-{
- WaitClientResult(funName, params);
- pair<mlir::Block*, mlir::Block*> e = PluginServer::GetInstance()->EdgeResult();
- return e;
-}
-
-vector<pair<mlir::Block*, mlir::Block*> > PluginServerAPI::EdgesResult(const string& funName, const string& params)
-{
- WaitClientResult(funName, params);
- vector<pair<mlir::Block*, mlir::Block*> > retEdges = PluginServer::GetInstance()->EdgesResult();
- return retEdges;
+ return PluginServer::GetInstance()->GetLocalDeclResult(funName, params);
}
mlir::Block* PluginServerAPI::BlockResult(const string& funName, const string& params)
{
- WaitClientResult(funName, params);
- uint64_t blockId = PluginServer::GetInstance()->GetIdResult();
+ uint64_t blockId = PluginServer::GetInstance()->GetIdResult(funName, params);
return PluginServer::GetInstance()->FindBlock(blockId);
}
@@ -393,9 +368,8 @@ vector<mlir::Block*> PluginServerAPI::BlocksResult(const string& funName, const
{
vector<mlir::Block*> res;
PluginServer *server = PluginServer::GetInstance();
- WaitClientResult(funName, params);
- vector<uint64_t> blockIds = server->GetIdsResult();
- for(auto b : blockIds) {
+ vector<uint64_t> blockIds = server->GetIdsResult(funName, params);
+ for (auto b : blockIds) {
res.push_back(server->FindBlock(b));
}
return res;
@@ -408,7 +382,7 @@ vector<LoopOp> PluginServerAPI::GetLoopsFromFunc(uint64_t funcID)
root["funcId"] = std::to_string(funcID);
string params = root.toStyledString();
- return GetLoopsResult(funName, params);
+ return PluginServer::GetInstance()->LoopOpsResult(funName, params);
}
bool PluginServerAPI::IsDomInfoAvailable()
@@ -421,8 +395,7 @@ bool PluginServerAPI::IsDomInfoAvailable()
bool PluginServerAPI::GetDomInfoAvaiResult(const string& funName)
{
Json::Value root;
- WaitClientResult(funName, root.toStyledString());
- return PluginServer::GetInstance()->GetBoolResult();
+ return PluginServer::GetInstance()->GetBoolResult(funName, root.toStyledString());
}
LoopOp PluginServerAPI::AllocateNewLoop(uint64_t funcID)
@@ -432,7 +405,7 @@ LoopOp PluginServerAPI::AllocateNewLoop(uint64_t funcID)
root["funcId"] = std::to_string(funcID);
string params = root.toStyledString();
- return GetLoopResult(funName, params);
+ return PluginServer::GetInstance()->LoopOpResult(funName, params);
}
LoopOp PluginServerAPI::GetLoopById(uint64_t loopID)
@@ -442,7 +415,7 @@ LoopOp PluginServerAPI::GetLoopById(uint64_t loopID)
root["loopId"] = std::to_string(loopID);
string params = root.toStyledString();
- return GetLoopResult(funName, params);
+ return PluginServer::GetInstance()->LoopOpResult(funName, params);
}
void PluginServerAPI::DeleteLoop(uint64_t loopID)
@@ -451,7 +424,7 @@ void PluginServerAPI::DeleteLoop(uint64_t loopID)
string funName("DeleteLoop");
root["loopId"] = std::to_string(loopID);
string params = root.toStyledString();
- WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
void PluginServerAPI::AddLoop(uint64_t loopID, uint64_t outerID, uint64_t funcID)
@@ -462,7 +435,7 @@ void PluginServerAPI::AddLoop(uint64_t loopID, uint64_t outerID, uint64_t funcID
root["outerId"] = outerID;
root["funcId"] = funcID;
string params = root.toStyledString();
- WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
void PluginServerAPI::AddBlockToLoop(uint64_t blockID, uint64_t loopID)
@@ -472,7 +445,7 @@ void PluginServerAPI::AddBlockToLoop(uint64_t blockID, uint64_t loopID)
root["blockId"] = blockID;
root["loopId"] = loopID;
string params = root.toStyledString();
- WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
bool PluginServerAPI::IsBlockInLoop(uint64_t loopID, uint64_t blockID)
@@ -483,7 +456,7 @@ bool PluginServerAPI::IsBlockInLoop(uint64_t loopID, uint64_t blockID)
root["blockId"] = std::to_string(blockID);
string params = root.toStyledString();
- return GetBoolResult(funName, params);
+ return PluginServer::GetInstance()->GetBoolResult(funName, params);
}
mlir::Block* PluginServerAPI::GetHeader(uint64_t loopID)
@@ -513,8 +486,7 @@ void PluginServerAPI::SetHeader(uint64_t loopID, uint64_t blockID)
root["loopId"] = std::to_string(loopID);
root["blockId"] = std::to_string(blockID);
string params = root.toStyledString();
-
- WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
void PluginServerAPI::SetLatch(uint64_t loopID, uint64_t blockID)
@@ -524,8 +496,7 @@ void PluginServerAPI::SetLatch(uint64_t loopID, uint64_t blockID)
root["loopId"] = std::to_string(loopID);
root["blockId"] = std::to_string(blockID);
string params = root.toStyledString();
-
- WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
pair<mlir::Block*, mlir::Block*> PluginServerAPI::LoopSingleExit(uint64_t loopID)
@@ -534,8 +505,7 @@ pair<mlir::Block*, mlir::Block*> PluginServerAPI::LoopSingleExit(uint64_t loopID
string funName("GetLoopSingleExit");
root["loopId"] = std::to_string(loopID);
string params = root.toStyledString();
-
- return EdgeResult(funName, params);
+ return PluginServer::GetInstance()->EdgeResult(funName, params);
}
vector<pair<mlir::Block*, mlir::Block*> > PluginServerAPI::GetLoopExitEdges(uint64_t loopID)
@@ -544,8 +514,7 @@ vector<pair<mlir::Block*, mlir::Block*> > PluginServerAPI::GetLoopExitEdges(uint
string funName("GetLoopExits");
root["loopId"] = std::to_string(loopID);
string params = root.toStyledString();
-
- return EdgesResult(funName, params);
+ return PluginServer::GetInstance()->EdgesResult(funName, params);
}
vector<mlir::Block*> PluginServerAPI::GetLoopBody(uint64_t loopID)
@@ -554,7 +523,6 @@ vector<mlir::Block*> PluginServerAPI::GetLoopBody(uint64_t loopID)
string funName("GetBlocksInLoop");
root["loopId"] = std::to_string(loopID);
string params = root.toStyledString();
-
return BlocksResult(funName, params);
}
@@ -564,8 +532,7 @@ LoopOp PluginServerAPI::GetBlockLoopFather(uint64_t blockID)
string funName("GetBlockLoopFather");
root["blockId"] = std::to_string(blockID);
string params = root.toStyledString();
-
- return GetLoopResult(funName, params);
+ return PluginServer::GetInstance()->LoopOpResult(funName, params);
}
mlir::Block* PluginServerAPI::FindBlock(uint64_t b)
@@ -594,8 +561,8 @@ bool PluginServerAPI::RedirectFallthroughTarget(FallThroughOp& fop,
root["src"] = src;
root["dest"] = dest;
string params = root.toStyledString();
- WaitClientResult(funName, params);
- //update server
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
+ // update server
PluginServer *server = PluginServer::GetInstance();
fop->setSuccessor(server->FindBlock(dest), 0);
return true;
@@ -617,7 +584,7 @@ void PluginServerAPI::DebugValue(uint64_t valId)
string funName = __func__;
root["valId"] = valId;
string params = root.toStyledString();
- WaitClientResult(funName, params);
+ PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
} // namespace Plugin_IR
--
2.33.0