代码拉取完成,页面将自动刷新
From bf910a189fdbf1be97dbbb2fa8e4b7d14163d002 Mon Sep 17 00:00:00 2001
From: d00573793 <dingguangya1@huawei.com>
Date: Fri, 3 Mar 2023 10:52:13 +0800
Subject: [PATCH 20/23] [Pin-server] Add CGnodeOp
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index 93ba116..9554067 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -22,6 +22,34 @@ include "PluginDialect.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/CallInterfaces.td"
+def CGnodeOp : Plugin_Op<"callgraphnode", [NoSideEffect]> {
+ let summary = "callgraph node operation";
+ let description = [{
+ TODO.
+ }];
+
+ let arguments = (ins UI64Attr:$id,
+ StrAttr:$symbolName,
+ OptionalAttr<BoolAttr>:$definition,
+ UI32Attr:$order);
+ 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":$symbolName,
+ "bool":$definition,
+ "uint32_t":$order)>
+ ];
+
+ let extraClassDeclaration = [{
+ // Value GetDecl();
+ bool IsRealSymbol();
+ }];
+}
+
def FunctionOp : Plugin_Op<"function", [NoSideEffect]> {
let summary = "function with a region";
let description = [{
diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h
index 923dd44..e8c0a50 100644
--- a/include/PluginAPI/BasicPluginOpsAPI.h
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
@@ -45,6 +45,10 @@ public:
virtual int GetDeclSourceLine(int64_t) = 0;
virtual int GetDeclSourceColumn(int64_t) = 0;
+ // CGnodeOp
+ virtual vector<CGnodeOp> GetAllCGnode() = 0;
+ virtual CGnodeOp GetCGnodeOpById(uint64_t) = 0;
+
virtual vector<FunctionOp> GetAllFunc() = 0;
virtual FunctionOp GetFunctionOpById(uint64_t) = 0;
virtual vector<LocalDeclOp> GetDecls(uint64_t) = 0;
diff --git a/include/PluginAPI/PluginServerAPI.h b/include/PluginAPI/PluginServerAPI.h
index 3da28f5..71b59b0 100644
--- a/include/PluginAPI/PluginServerAPI.h
+++ b/include/PluginAPI/PluginServerAPI.h
@@ -36,6 +36,12 @@ public:
PluginServerAPI () = default;
~PluginServerAPI () = default;
+ // CGnodeOp
+ vector<CGnodeOp> GetAllCGnode() override;
+ CGnodeOp GetCGnodeOpById(uint64_t) override;
+ // mlir::Value GetDeclFromCGnode(uint64_t);
+ bool IsRealSymbolOfCGnode(uint64_t);
+
vector<FunctionOp> GetAllFunc() override;
FunctionOp GetFunctionOpById(uint64_t);
vector<LocalDeclOp> GetDecls(uint64_t) override;
diff --git a/include/PluginServer/PluginCom.h b/include/PluginServer/PluginCom.h
index 6535362..d507b6f 100755
--- a/include/PluginServer/PluginCom.h
+++ b/include/PluginServer/PluginCom.h
@@ -57,6 +57,7 @@ public:
string GetStringDataResult(void);
vector<mlir::Plugin::FunctionOp> GetFunctionOpResult(void);
vector<mlir::Plugin::LocalDeclOp> GetLocalDeclResult(void);
+ mlir::Plugin::CGnodeOp GetCGnodeOpResult(void);
mlir::Plugin::LoopOp LoopOpResult(void);
vector<mlir::Plugin::LoopOp> LoopOpsResult(void);
vector<std::pair<mlir::Block*, mlir::Block*> > EdgesResult(void);
@@ -73,6 +74,7 @@ private:
PluginJson json;
int64_t integerResult;
string stringResult;
+ mlir::Plugin::CGnodeOp cgnode;
vector<mlir::Plugin::FunctionOp> funcOpData;
vector<mlir::Plugin::LocalDeclOp> decls;
vector<mlir::Plugin::LoopOp> loops;
diff --git a/include/PluginServer/PluginJson.h b/include/PluginServer/PluginJson.h
index 8e00afa..eddbb2a 100755
--- a/include/PluginServer/PluginJson.h
+++ b/include/PluginServer/PluginJson.h
@@ -33,6 +33,9 @@ using std::vector;
namespace PinJson {
class PluginJson {
public:
+ // CGnodeOp
+ mlir::Plugin::CGnodeOp CGnodeOpJsonDeSerialize(const string& data);
+
void FuncOpJsonDeSerialize(const string&, vector<mlir::Plugin::FunctionOp>&);
void LocalDeclOpJsonDeSerialize(const string&,
vector<mlir::Plugin::LocalDeclOp>&);
diff --git a/include/PluginServer/PluginServer.h b/include/PluginServer/PluginServer.h
index b651140..d993505 100644
--- a/include/PluginServer/PluginServer.h
+++ b/include/PluginServer/PluginServer.h
@@ -163,6 +163,11 @@ public:
RemoteCallClientWithAPI(funName, params);
return pluginCom.GetLocalDeclResult();
}
+ mlir::Plugin::CGnodeOp GetCGnodeOpResult(const string& funName, const string& params)
+ {
+ RemoteCallClientWithAPI(funName, params);
+ return pluginCom.GetCGnodeOpResult();
+ }
mlir::Plugin::LoopOp LoopOpResult(const string& funName, const string& params)
{
RemoteCallClientWithAPI(funName, params);
diff --git a/include/user/StructReorder.h b/include/user/StructReorder.h
index 1d05e56..3938121 100644
--- a/include/user/StructReorder.h
+++ b/include/user/StructReorder.h
@@ -23,6 +23,7 @@
#include "PluginServer/PluginOptBase.h"
+
namespace PluginOpt {
class StructReorderPass : public PluginOptBase {
public:
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index ab0e3ce..928dc53 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -87,6 +87,36 @@ static uint64_t getBlockAddress(mlir::Block* b)
}
}
+// ===----------------------------------------------------------------------===//
+// CGnodeOp
+
+void CGnodeOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id, StringRef symbolName, bool definition,
+ uint32_t order)
+{
+ state.addRegion();
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("symbolName", builder.getStringAttr(symbolName));
+ state.addAttribute("definition", builder.getBoolAttr(definition));
+ state.addAttribute("order", builder.getI32IntegerAttr(order));
+}
+
+// Value CGnodeOp::GetDecl()
+// {
+// PluginAPI::PluginServerAPI pluginAPI;
+// uint64_t nodeId = idAttr().getInt();
+// return pluginAPI.GetDeclFromCGnode(nodeId);
+// }
+
+bool CGnodeOp::IsRealSymbol()
+{
+ PluginAPI::PluginServerAPI pluginAPI;
+ uint64_t nodeId = idAttr().getInt();
+ return pluginAPI.IsRealSymbolOfCGnode(nodeId);
+}
+
+// ===----------------------------------------------------------------------===//
+
void FunctionOp::build(OpBuilder &builder, OperationState &state,
uint64_t id, StringRef funcName, bool declaredInline, Type type)
{
diff --git a/lib/PluginAPI/PluginServerAPI.cpp b/lib/PluginAPI/PluginServerAPI.cpp
index ff9c90e..5297357 100644
--- a/lib/PluginAPI/PluginServerAPI.cpp
+++ b/lib/PluginAPI/PluginServerAPI.cpp
@@ -171,6 +171,42 @@ mlir::Value PluginServerAPI::CreateSSAOp(mlir::Type t)
return PluginServer::GetInstance()->GetValueResult(funName, params);
}
+// CGnodeOp ===============
+
+vector<CGnodeOp> PluginServerAPI::GetAllCGnode()
+{
+ Json::Value root;
+ string funName = "GetCGnodeIDs";
+ string params = root.toStyledString();
+ vector<CGnodeOp> res;
+ vector<uint64_t> ids = PluginServer::GetInstance()->GetIdsResult(funName, params);
+ for (auto id : ids) {
+ res.push_back(GetCGnodeOpById(id));
+ }
+ return res;
+}
+
+CGnodeOp PluginServerAPI::GetCGnodeOpById(uint64_t id)
+{
+ Json::Value root;
+ string funName = __func__;
+ root["id"] = std::to_string(id);
+ string params = root.toStyledString();
+ CGnodeOp cgnodeop = PluginServer::GetInstance()->GetCGnodeOpResult(funName, params);
+ return cgnodeop;
+}
+
+bool PluginServerAPI::IsRealSymbolOfCGnode(uint64_t id)
+{
+ Json::Value root;
+ string funName = __func__;
+ root["id"] = std::to_string(id);
+ string params = root.toStyledString();
+ return PluginServer::GetInstance()->GetBoolResult(funName, params);
+}
+
+// ========================
+
vector<FunctionOp> PluginServerAPI::GetAllFunc()
{
Json::Value root;
diff --git a/lib/PluginServer/PluginCom.cpp b/lib/PluginServer/PluginCom.cpp
index ab171c7..ddf0605 100755
--- a/lib/PluginServer/PluginCom.cpp
+++ b/lib/PluginServer/PluginCom.cpp
@@ -59,6 +59,12 @@ vector<mlir::Plugin::LocalDeclOp> PluginCom::GetLocalDeclResult(void)
return retOps;
}
+mlir::Plugin::CGnodeOp PluginCom::GetCGnodeOpResult(void)
+{
+ mlir::Plugin::CGnodeOp retop = cgnode;
+ return retop;
+}
+
vector<mlir::Plugin::LoopOp> PluginCom::LoopOpsResult(void)
{
vector<mlir::Plugin::LoopOp> retLoops = loops;
@@ -125,6 +131,8 @@ void PluginCom::JsonDeSerialize(const string& key, const string& data)
{
if (key == "FuncOpResult") {
json.FuncOpJsonDeSerialize(data, this->funcOpData);
+ } else if (key == "CGnodeOpResult") {
+ this->cgnode = json.CGnodeOpJsonDeSerialize(data);
} else if (key == "LocalDeclOpResult") {
json.LocalDeclOpJsonDeSerialize(data, this->decls);
} else if (key == "LoopOpResult") {
diff --git a/lib/PluginServer/PluginJson.cpp b/lib/PluginServer/PluginJson.cpp
index 14a6ef4..ba2136b 100755
--- a/lib/PluginServer/PluginJson.cpp
+++ b/lib/PluginServer/PluginJson.cpp
@@ -328,6 +328,25 @@ void PluginJson::StringDeSerialize(const string& data, string& result)
result = root["stringData"].asString();
}
+CGnodeOp PluginJson::CGnodeOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ fprintf(stderr, "dgy server cgnode json %s\n", root.toStyledString().c_str());
+
+ mlir::OpBuilder builder(PluginServer::GetInstance()->GetContext());
+ uint64_t id = GetID(root["id"]);
+ Json::Value attributes = root["attributes"];
+ uint32_t order = GetID(attributes["order"]);
+ map<string, string> nodeAttributes;
+ JsonGetAttributes(attributes, nodeAttributes);
+ bool definition = false;
+ if (nodeAttributes["definition"] == "1") definition = true;
+ auto location = builder.getUnknownLoc();
+ return builder.create<CGnodeOp>(location, id, nodeAttributes["symbolName"], definition, order);
+}
+
void PluginJson::FuncOpJsonDeSerialize(
const string& data, vector<mlir::Plugin::FunctionOp>& funcOpData)
{
diff --git a/user/StructReorder.cpp b/user/StructReorder.cpp
index bdc7abb..a23d256 100644
--- a/user/StructReorder.cpp
+++ b/user/StructReorder.cpp
@@ -47,8 +47,33 @@ std::map<uint64_t, std::string> opNameMap;
static void ProcessStructReorder(uint64_t *fun)
{
- std::cout << "Running first pass, structreoder\n";
+ fprintf(stderr, "Running first pass, structreoder\n");
+ PluginServerAPI pluginAPI;
+ vector<CGnodeOp> allnodes = pluginAPI.GetAllCGnode();
+ fprintf(stderr, "allnodes size is %d\n", allnodes.size());
+ for (auto &nodeOp : allnodes) {
+ context = nodeOp.getOperation()->getContext();
+ mlir::OpBuilder opBuilder_temp = mlir::OpBuilder(context);
+ opBuilder = &opBuilder_temp;
+ string name = nodeOp.symbolNameAttr().getValue().str();
+ fprintf(stderr, "Now process symbol : %s \n", name.c_str());
+ uint32_t order = nodeOp.orderAttr().getInt();
+ fprintf(stderr, "Now process order : %d \n", order);
+ if (nodeOp.IsRealSymbol())
+ fprintf(stderr, "Now process IsRealSymbol \n");
+ }
+
+ vector<FunctionOp> allFunction = pluginAPI.GetAllFunc();
+ fprintf(stderr, "allfun size is %d\n", allFunction.size());
+ for (auto &funcOp : allFunction) {
+ context = funcOp.getOperation()->getContext();
+ mlir::OpBuilder opBuilder_temp = mlir::OpBuilder(context);
+ opBuilder = &opBuilder_temp;
+ string name = funcOp.funcNameAttr().getValue().str();
+ fprintf(stderr, "Now process func : %s \n", name.c_str());
+ }
+
}
int StructReorderPass::DoOptimize(uint64_t *fun)
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。