309 lines
11 KiB
Diff
309 lines
11 KiB
Diff
From 8d80ef3e9d0fc535694cca23d4d29c7d3f9b1e23 Mon Sep 17 00:00:00 2001
|
|
From: d00573793 <dingguangya1@huawei.com>
|
|
Date: Fri, 3 Mar 2023 10:51:04 +0800
|
|
Subject: [PATCH 4/6] [Pin-gcc-client] Add CGnodeOp
|
|
|
|
|
|
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
|
|
index 79d73d0..143a856 100644
|
|
--- a/include/Dialect/PluginOps.td
|
|
+++ b/include/Dialect/PluginOps.td
|
|
@@ -24,6 +24,29 @@ 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)>
|
|
+ ];
|
|
+}
|
|
+
|
|
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 981964b..6e66d08 100644
|
|
--- a/include/PluginAPI/BasicPluginOpsAPI.h
|
|
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
|
|
@@ -49,6 +49,10 @@ public:
|
|
virtual int GetDeclSourceLine(uint64_t gccDataAddr) = 0;
|
|
virtual int GetDeclSourceColumn(uint64_t gccDataAddr) = 0;
|
|
|
|
+ // CGnode
|
|
+ virtual vector<uint64_t> GetCGnodeIDs() = 0;
|
|
+ virtual CGnodeOp GetCGnodeOpById(uint64_t) = 0;
|
|
+
|
|
virtual uint64_t CreateBlock(uint64_t, uint64_t) = 0;
|
|
virtual void DeleteBlock(uint64_t, uint64_t) = 0;
|
|
virtual void SetImmediateDominator(uint64_t, uint64_t, uint64_t) = 0;
|
|
diff --git a/include/PluginAPI/PluginClientAPI.h b/include/PluginAPI/PluginClientAPI.h
|
|
index d69baff..1970f1e 100644
|
|
--- a/include/PluginAPI/PluginClientAPI.h
|
|
+++ b/include/PluginAPI/PluginClientAPI.h
|
|
@@ -45,6 +45,11 @@ public:
|
|
uint64_t GetImmediateDominator(uint64_t, uint64_t) override;
|
|
uint64_t RecomputeDominator(uint64_t, uint64_t) override;
|
|
|
|
+ // CGnode
|
|
+ vector<uint64_t> GetCGnodeIDs() override;
|
|
+ CGnodeOp GetCGnodeOpById(uint64_t) override;
|
|
+ bool IsRealSymbolOfCGnode(uint64_t);
|
|
+
|
|
vector<FunctionOp> GetAllFunc() override;
|
|
vector<uint64_t> GetFunctions() override;
|
|
FunctionOp GetFunctionOpById(uint64_t) override;
|
|
diff --git a/include/PluginClient/PluginJson.h b/include/PluginClient/PluginJson.h
|
|
index d4e48af..3f7813e 100755
|
|
--- a/include/PluginClient/PluginJson.h
|
|
+++ b/include/PluginClient/PluginJson.h
|
|
@@ -37,6 +37,9 @@ using std::vector;
|
|
|
|
class PluginJson {
|
|
public:
|
|
+ // CGnodeOp
|
|
+ void CGnodeOpJsonSerialize(mlir::Plugin::CGnodeOp& cgnode, string& out);
|
|
+
|
|
void OpJsonSerialize(vector<mlir::Plugin::FunctionOp>& data, string& out);
|
|
void LoopOpsJsonSerialize(vector<mlir::Plugin::LoopOp>& loops, string& out);
|
|
void LoopOpJsonSerialize(mlir::Plugin::LoopOp& loop, string& out);
|
|
diff --git a/include/Translate/GimpleToPluginOps.h b/include/Translate/GimpleToPluginOps.h
|
|
index 0928ece..3c7aba2 100644
|
|
--- a/include/Translate/GimpleToPluginOps.h
|
|
+++ b/include/Translate/GimpleToPluginOps.h
|
|
@@ -60,6 +60,13 @@ public:
|
|
void SetImmediateDominator(uint64_t, uint64_t, uint64_t);
|
|
uint64_t GetImmediateDominator(uint64_t, uint64_t);
|
|
uint64_t RecomputeDominator(uint64_t, uint64_t);
|
|
+
|
|
+ // CGnode
|
|
+ vector<uint64_t> GetCGnodeIDs();
|
|
+ mlir::Plugin::CGnodeOp GetCGnodeOpById(uint64_t);
|
|
+ CGnodeOp BuildCGnodeOp(uint64_t);
|
|
+ bool IsRealSymbolOfCGnode(uint64_t);
|
|
+
|
|
vector<mlir::Plugin::FunctionOp> GetAllFunction();
|
|
vector<uint64_t> GetFunctionIDs();
|
|
mlir::Plugin::FunctionOp GetFunctionById(uint64_t);
|
|
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
|
|
index 058a0e6..cf1dbbe 100644
|
|
--- a/lib/Dialect/PluginOps.cpp
|
|
+++ b/lib/Dialect/PluginOps.cpp
|
|
@@ -33,6 +33,21 @@
|
|
using namespace mlir;
|
|
using namespace mlir::Plugin;
|
|
|
|
+// 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));
|
|
+}
|
|
+
|
|
+// ============================
|
|
+
|
|
void FunctionOp::build(OpBuilder &builder, OperationState &state,
|
|
uint64_t id, StringRef funcName, bool declaredInline, Type type)
|
|
{
|
|
diff --git a/lib/PluginAPI/PluginClientAPI.cpp b/lib/PluginAPI/PluginClientAPI.cpp
|
|
index 3623091..5194d29 100644
|
|
--- a/lib/PluginAPI/PluginClientAPI.cpp
|
|
+++ b/lib/PluginAPI/PluginClientAPI.cpp
|
|
@@ -71,6 +71,22 @@ uint64_t PluginClientAPI::RecomputeDominator(uint64_t dir, uint64_t bbAddr)
|
|
return gimpleConversion.RecomputeDominator(dir, bbAddr);
|
|
}
|
|
|
|
+// CGnode
|
|
+vector<uint64_t> PluginClientAPI::GetCGnodeIDs()
|
|
+{
|
|
+ return gimpleConversion.GetCGnodeIDs();
|
|
+}
|
|
+
|
|
+CGnodeOp PluginClientAPI::GetCGnodeOpById(uint64_t id)
|
|
+{
|
|
+ return gimpleConversion.GetCGnodeOpById(id);
|
|
+}
|
|
+
|
|
+bool PluginClientAPI::IsRealSymbolOfCGnode(uint64_t id)
|
|
+{
|
|
+ return gimpleConversion.IsRealSymbolOfCGnode(id);
|
|
+}
|
|
+
|
|
vector<FunctionOp> PluginClientAPI::GetAllFunc()
|
|
{
|
|
return gimpleConversion.GetAllFunction();
|
|
diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp
|
|
index 937f6e1..310366d 100644
|
|
--- a/lib/PluginClient/PluginClient.cpp
|
|
+++ b/lib/PluginClient/PluginClient.cpp
|
|
@@ -95,6 +95,48 @@ void PluginClient::GetGccData(const string& funcName, const string& param, strin
|
|
}
|
|
}
|
|
|
|
+// CGnode ============
|
|
+
|
|
+void GetCGnodeIDsResult(PluginClient *client, Json::Value& root, string& result)
|
|
+{
|
|
+ // Load our Dialect in this MLIR Context.
|
|
+ mlir::MLIRContext context;
|
|
+ context.getOrLoadDialect<PluginDialect>();
|
|
+ PluginAPI::PluginClientAPI clientAPI(context);
|
|
+ vector<uint64_t> ids = clientAPI.GetCGnodeIDs();
|
|
+ PluginJson json = client->GetJson();
|
|
+ json.IDsJsonSerialize(ids, result);
|
|
+ client->ReceiveSendMsg("IdsResult", result);
|
|
+}
|
|
+
|
|
+void GetCGnodeOpByIdResult(PluginClient *client, Json::Value& root, string& result)
|
|
+{
|
|
+ // Load our Dialect in this MLIR Context.
|
|
+ mlir::MLIRContext context;
|
|
+ context.getOrLoadDialect<PluginDialect>();
|
|
+ PluginAPI::PluginClientAPI clientAPI(context);
|
|
+ std::string funcIdKey = "id";
|
|
+ uint64_t cgnodeID = atol(root[funcIdKey].asString().c_str());
|
|
+ CGnodeOp cgnodeOp = clientAPI.GetCGnodeOpById(cgnodeID);
|
|
+ PluginJson json = client->GetJson();
|
|
+ json.CGnodeOpJsonSerialize(cgnodeOp, result);
|
|
+ client->ReceiveSendMsg("CGnodeOpResult", result);
|
|
+}
|
|
+
|
|
+void IsRealSymbolOfCGnodeResult(PluginClient *client, Json::Value& root, string& result)
|
|
+{
|
|
+ // Load our Dialect in this MLIR Context.
|
|
+ mlir::MLIRContext context;
|
|
+ context.getOrLoadDialect<PluginDialect>();
|
|
+ PluginAPI::PluginClientAPI clientAPI(context);
|
|
+ std::string funcIdKey = "id";
|
|
+ uint64_t cgnodeID = atol(root[funcIdKey].asString().c_str());
|
|
+ bool realsymbol = clientAPI.IsRealSymbolOfCGnode(cgnodeID);
|
|
+ client->ReceiveSendMsg("BoolResult", std::to_string(realsymbol));
|
|
+}
|
|
+
|
|
+// ===================
|
|
+
|
|
void GetAllFuncResult(PluginClient *client, Json::Value& root, string& result)
|
|
{
|
|
// Load our Dialect in this MLIR Context.
|
|
@@ -867,6 +909,9 @@ void IsWholeProgramResult(PluginClient *client, Json::Value& root, string& resul
|
|
|
|
typedef std::function<void(PluginClient*, Json::Value&, string&)> GetResultFunc;
|
|
std::map<string, GetResultFunc> g_getResultFunc = {
|
|
+ {"GetCGnodeIDs", GetCGnodeIDsResult},
|
|
+ {"GetCGnodeOpById", GetCGnodeOpByIdResult},
|
|
+ {"IsRealSymbolOfCGnode", IsRealSymbolOfCGnodeResult},
|
|
{"GetAllFunc", GetAllFuncResult},
|
|
{"GetFunctionIDs", GetFunctionIDsResult},
|
|
{"GetFunctionOpById", GetFunctionOpByIdResult},
|
|
diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp
|
|
index 388efc9..40590b2 100755
|
|
--- a/lib/PluginClient/PluginJson.cpp
|
|
+++ b/lib/PluginClient/PluginJson.cpp
|
|
@@ -195,6 +195,24 @@ PluginIR::PluginTypeBase PluginJson::TypeJsonDeSerialize(const string& data, mli
|
|
return baseType;
|
|
}
|
|
|
|
+void PluginJson::CGnodeOpJsonSerialize(CGnodeOp& cgnode, string& out)
|
|
+{
|
|
+ Json::Value root;
|
|
+ Json::Value operationObj;
|
|
+ Json::Value item;
|
|
+
|
|
+ root["id"] = std::to_string(cgnode.idAttr().getInt());
|
|
+ root["attributes"]["order"] = std::to_string(cgnode.orderAttr().getInt());
|
|
+ if (cgnode.definitionAttr().getValue()) {
|
|
+ root["attributes"]["definition"] = "1";
|
|
+ }else {
|
|
+ root["attributes"]["definition"] = "0";
|
|
+ }
|
|
+ root["attributes"]["symbolName"] = cgnode.symbolNameAttr().getValue().str().c_str();
|
|
+ fprintf(stderr, "dgy client cgnode json %s\n", root.toStyledString().c_str());
|
|
+ out = root.toStyledString();
|
|
+}
|
|
+
|
|
void PluginJson::FunctionOpJsonSerialize(vector<FunctionOp>& data, string& out)
|
|
{
|
|
Json::Value root;
|
|
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
|
|
index 0bb4416..230fc1e 100644
|
|
--- a/lib/Translate/GimpleToPluginOps.cpp
|
|
+++ b/lib/Translate/GimpleToPluginOps.cpp
|
|
@@ -313,6 +313,52 @@ uint64_t GimpleToPluginOps::RecomputeDominator(uint64_t dir, uint64_t bbAddr)
|
|
abort();
|
|
}
|
|
|
|
+// CGnode =========
|
|
+
|
|
+CGnodeOp GimpleToPluginOps::BuildCGnodeOp(uint64_t id)
|
|
+{
|
|
+ cgraph_node *node;
|
|
+ node = reinterpret_cast<cgraph_node *>(id);
|
|
+ fprintf(stderr, "dgy client BuildCGnodeOp id : %lld\n", id);
|
|
+ fprintf(stderr, "dgy client BuildCGnodeOp node name is : %s/%d\n", node->name(), node->order);
|
|
+ mlir::StringRef symbolName(node->name());
|
|
+ bool definition = false;
|
|
+ if (node->definition)
|
|
+ definition = true;
|
|
+ uint32_t order = node->order;
|
|
+ auto location = builder.getUnknownLoc();
|
|
+ CGnodeOp retOp = builder.create<CGnodeOp>(location, id, symbolName, definition, order);
|
|
+ return retOp;
|
|
+}
|
|
+
|
|
+vector<uint64_t> GimpleToPluginOps::GetCGnodeIDs()
|
|
+{
|
|
+ cgraph_node *node = NULL;
|
|
+ vector<uint64_t> cgnodeIDs;
|
|
+ FOR_EACH_FUNCTION (node) {
|
|
+ int64_t id = reinterpret_cast<int64_t>(reinterpret_cast<void*>(node));
|
|
+ fprintf(stderr, "dgy client GetCGnodeIDs id : %lld\n", id);
|
|
+ fprintf(stderr, "dgy client GetCGnodeIDs node name is : %s/%d\n", node->name(), node->order);
|
|
+ cgnodeIDs.push_back(id);
|
|
+ }
|
|
+ return cgnodeIDs;
|
|
+}
|
|
+
|
|
+CGnodeOp GimpleToPluginOps::GetCGnodeOpById(uint64_t id)
|
|
+{
|
|
+ CGnodeOp cgOp = BuildCGnodeOp(id);
|
|
+ return cgOp;
|
|
+}
|
|
+
|
|
+bool GimpleToPluginOps::IsRealSymbolOfCGnode(uint64_t id)
|
|
+{
|
|
+ cgraph_node *node;
|
|
+ node = reinterpret_cast<cgraph_node *>(id);
|
|
+ return node->real_symbol_p();
|
|
+}
|
|
+
|
|
+//=================
|
|
+
|
|
vector<FunctionOp> GimpleToPluginOps::GetAllFunction()
|
|
{
|
|
cgraph_node *node = NULL;
|
|
--
|
|
2.33.0
|
|
|