diff --git a/0013-pin-gcc-client-Add-DataFlow-APIs.patch b/0013-pin-gcc-client-Add-DataFlow-APIs.patch new file mode 100644 index 0000000000000000000000000000000000000000..7e69481d0c54afe9911d95d91b3455dd51443b43 --- /dev/null +++ b/0013-pin-gcc-client-Add-DataFlow-APIs.patch @@ -0,0 +1,927 @@ +From 6fdbb193b91f3deae430ae6ad0fc17aec40dd720 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=E9=83=91=E6=99=A8=E5=8D=89?= +Date: Fri, 22 Dec 2023 16:06:33 +0800 +Subject: [PATCH 4/5] [pin-gcc-client] Add DataFlow APIs. + +--- + include/PluginAPI/BasicPluginOpsAPI.h | 18 +++ + include/PluginAPI/PluginClientAPI.h | 18 +++ + include/PluginClient/PluginClient.h | 1 + + include/PluginClient/PluginJson.h | 4 +- + include/Translate/GimpleToPluginOps.h | 18 +++ + lib/PluginAPI/PluginClientAPI.cpp | 80 ++++++++++ + lib/PluginClient/PluginClient.cpp | 216 ++++++++++++++++++++++++- + lib/PluginClient/PluginJson.cpp | 32 ++++ + lib/Translate/GimpleToPluginOps.cpp | 217 +++++++++++++++++++++++++- + lib/gccPlugin/gccPlugin.cpp | 5 + + 10 files changed, 602 insertions(+), 7 deletions(-) + +diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h +index 22da8df..647c498 100644 +--- a/include/PluginAPI/BasicPluginOpsAPI.h ++++ b/include/PluginAPI/BasicPluginOpsAPI.h +@@ -100,6 +100,7 @@ public: + virtual vector > GetLoopExits(uint64_t) = 0; + virtual std::pair GetLoopSingleExit(uint64_t) = 0; + virtual LoopOp GetBlockLoopFather(uint64_t) = 0; ++ virtual LoopOp FindCommonLoop(uint64_t, uint64_t) = 0; + virtual PhiOp GetPhiOp(uint64_t) = 0; + virtual CallOp GetCallOp(uint64_t) = 0; + virtual bool SetLhsInCallOp(uint64_t, uint64_t) = 0; +@@ -118,15 +119,32 @@ public: + virtual PhiOp CreatePhiOp(uint64_t, uint64_t) = 0; + virtual bool UpdateSSA() = 0; + virtual vector GetPhiOpsInsideBlock(uint64_t bb) = 0; ++ virtual vector GetOpsInsideBlock(uint64_t bb) = 0; + virtual bool IsDomInfoAvailable() = 0; + virtual mlir::Value GetValue(uint64_t) = 0; + virtual void DebugValue(uint64_t) = 0; ++ virtual void DebugOperation(uint64_t) = 0; ++ virtual void DebugBlock(uint64_t) = 0; + virtual mlir::Value BuildMemRef(PluginTypeBase, uint64_t, uint64_t) = 0; + virtual void RedirectFallthroughTarget(uint64_t, uint64_t) = 0; + virtual void RemoveEdge(uint64_t, uint64_t) = 0; + + virtual bool IsLtoOptimize() = 0; + virtual bool IsWholeProgram() = 0; ++ ++ virtual bool IsVirtualOperand(uint64_t) = 0; ++ ++ virtual void CalDominanceInfo(uint64_t, uint64_t) = 0; ++ virtual vector GetImmUseStmts(uint64_t) = 0; ++ virtual mlir::Value GetGimpleVuse(uint64_t) = 0; ++ virtual mlir::Value GetGimpleVdef(uint64_t) = 0; ++ virtual vector GetSsaUseOperand(uint64_t) = 0; ++ virtual vector GetSsaDefOperand(uint64_t) = 0; ++ virtual vector GetPhiOrStmtUse(uint64_t) = 0; ++ virtual vector GetPhiOrStmtDef(uint64_t) = 0; ++ virtual bool RefsMayAlias(uint64_t, uint64_t, uint64_t) = 0; ++ virtual bool PTIncludesDecl(uint64_t, uint64_t) = 0; ++ virtual bool PTsIntersect(uint64_t, uint64_t) = 0; + }; // class BasicPluginOpsAPI + } // namespace PluginAPI + +diff --git a/include/PluginAPI/PluginClientAPI.h b/include/PluginAPI/PluginClientAPI.h +index 26ef71d..23fa523 100644 +--- a/include/PluginAPI/PluginClientAPI.h ++++ b/include/PluginAPI/PluginClientAPI.h +@@ -92,6 +92,7 @@ public: + vector > GetLoopExits(uint64_t) override; + std::pair GetLoopSingleExit(uint64_t) override; + LoopOp GetBlockLoopFather(uint64_t) override; ++ LoopOp FindCommonLoop(uint64_t, uint64_t) override; + PhiOp GetPhiOp(uint64_t) override; + CallOp GetCallOp(uint64_t) override; + /* Plugin API for CallOp. */ +@@ -110,9 +111,12 @@ public: + mlir::Value CreateConstOp(mlir::Attribute, mlir::Type) override; + bool UpdateSSA() override; + vector GetPhiOpsInsideBlock(uint64_t bb) override; ++ vector GetOpsInsideBlock(uint64_t bb) override; + bool IsDomInfoAvailable() override; + mlir::Value GetValue(uint64_t) override; + void DebugValue(uint64_t) override; ++ void DebugOperation(uint64_t) override; ++ void DebugBlock(uint64_t) override; + mlir::Value BuildMemRef(PluginIR::PluginTypeBase, uint64_t, uint64_t) override; + + mlir::Value GetCurrentDefFromSSA(uint64_t) override; +@@ -128,6 +132,20 @@ public: + + bool IsLtoOptimize() override; + bool IsWholeProgram() override; ++ ++ bool IsVirtualOperand(uint64_t) override; ++ /* Plugin API for Data Flow*/ ++ void CalDominanceInfo(uint64_t, uint64_t) override; ++ virtual vector GetImmUseStmts(uint64_t) override; ++ virtual mlir::Value GetGimpleVuse(uint64_t) override; ++ virtual mlir::Value GetGimpleVdef(uint64_t) override; ++ virtual vector GetSsaUseOperand(uint64_t) override; ++ virtual vector GetSsaDefOperand(uint64_t) override; ++ virtual vector GetPhiOrStmtUse(uint64_t) override; ++ virtual vector GetPhiOrStmtDef(uint64_t) override; ++ virtual bool RefsMayAlias(uint64_t, uint64_t, uint64_t) override; ++ virtual bool PTIncludesDecl(uint64_t, uint64_t) override; ++ virtual bool PTsIntersect(uint64_t, uint64_t) override; + private: + PluginIR::GimpleToPluginOps gimpleConversion; + }; // class PluginClientAPI +diff --git a/include/PluginClient/PluginClient.h b/include/PluginClient/PluginClient.h +index 2b5648c..0b90970 100644 +--- a/include/PluginClient/PluginClient.h ++++ b/include/PluginClient/PluginClient.h +@@ -117,6 +117,7 @@ enum RefPassName { + PASS_PHIOPT, + PASS_SSA, + PASS_LOOP, ++ PASS_LAD, + PASS_MAC, + }; + +diff --git a/include/PluginClient/PluginJson.h b/include/PluginClient/PluginJson.h +index f8df011..a45a9b7 100755 +--- a/include/PluginClient/PluginJson.h ++++ b/include/PluginClient/PluginJson.h +@@ -52,7 +52,9 @@ public: + void FunctionDeclsJsonSerialize(vector& decls, string& out); + void FiledOpsJsonSerialize(vector& decls, string& out); + void GetPhiOpsJsonSerialize(vector phiOps, string& out); +- Json::Value OperationJsonSerialize(mlir::Operation *, uint64_t&); ++ void OpsJsonSerialize(vector>& ops, string& out); ++ void ValuesJsonSerialize(vector& values, string& out); ++ Json::Value OperationJsonSerialize(mlir::Operation*, uint64_t&); + Json::Value CallOpJsonSerialize(mlir::Plugin::CallOp& data); + Json::Value CondOpJsonSerialize(mlir::Plugin::CondOp& data, uint64_t&); + Json::Value PhiOpJsonSerialize(mlir::Plugin::PhiOp& data); +diff --git a/include/Translate/GimpleToPluginOps.h b/include/Translate/GimpleToPluginOps.h +index 1332219..0423f15 100644 +--- a/include/Translate/GimpleToPluginOps.h ++++ b/include/Translate/GimpleToPluginOps.h +@@ -109,6 +109,7 @@ public: + vector > GetLoopExits(uint64_t); + std::pair GetLoopSingleExit(uint64_t); + LoopOp GetBlockLoopFather(uint64_t); ++ LoopOp FindCommonLoop(uint64_t, uint64_t); + CallOp BuildCallOp(uint64_t); + bool SetGimpleCallLHS(uint64_t, uint64_t); + uint32_t AddPhiArg(uint64_t, uint64_t, uint64_t, uint64_t); +@@ -140,9 +141,12 @@ public: + void GetTreeAttr(uint64_t, bool&, PluginTypeBase&); + mlir::Value TreeToValue(uint64_t); + void DebugValue(uint64_t); ++ void DebugOperation(uint64_t); ++ void DebugBlock(uint64_t); + mlir::Value BuildMemRef(PluginIR::PluginTypeBase, uint64_t, uint64_t); + bool UpdateSSA(); + vector GetPhiOpsInsideBlock(uint64_t); ++ vector GetOpsInsideBlock(uint64_t); + bool IsDomInfoAvailable(); + mlir::Value CreateNewDefFor(uint64_t, uint64_t, uint64_t); + bool SetCurrentDefFor(uint64_t, uint64_t); +@@ -156,6 +160,20 @@ public: + bool IsLtoOptimize(); + bool IsWholeProgram(); + ++ bool IsVirtualOperand(uint64_t); ++ ++ void CalDominanceInfo(uint64_t, uint64_t); ++ vector GetImmUseStmts(uint64_t); ++ mlir::Value GetGimpleVuse(uint64_t); ++ mlir::Value GetGimpleVdef(uint64_t); ++ vector GetSsaUseOperand(uint64_t); ++ vector GetSsaDefOperand(uint64_t); ++ vector GetPhiOrStmtUse(uint64_t); ++ vector GetPhiOrStmtDef(uint64_t); ++ bool RefsMayAlias(uint64_t, uint64_t, uint64_t); ++ bool PTIncludesDecl(uint64_t, uint64_t); ++ bool PTsIntersect(uint64_t, uint64_t); ++ + private: + GimpleToPluginOps () = delete; + mlir::OpBuilder builder; +diff --git a/lib/PluginAPI/PluginClientAPI.cpp b/lib/PluginAPI/PluginClientAPI.cpp +index 95e9ab3..b908ba1 100644 +--- a/lib/PluginAPI/PluginClientAPI.cpp ++++ b/lib/PluginAPI/PluginClientAPI.cpp +@@ -274,6 +274,12 @@ LoopOp PluginClientAPI::GetBlockLoopFather(uint64_t blockId) + { + return gimpleConversion.GetBlockLoopFather(blockId); + } ++ ++LoopOp PluginClientAPI::FindCommonLoop(uint64_t opId_1, uint64_t opId_2) ++{ ++ return gimpleConversion.FindCommonLoop(opId_1, opId_2); ++} ++ + PhiOp PluginClientAPI::GetPhiOp(uint64_t id) + { + return gimpleConversion.BuildPhiOp(id); +@@ -345,6 +351,11 @@ vector PluginClientAPI::GetPhiOpsInsideBlock(uint64_t bb) + return gimpleConversion.GetPhiOpsInsideBlock(bb); + } + ++vector PluginClientAPI::GetOpsInsideBlock(uint64_t bb) ++{ ++ return gimpleConversion.GetOpsInsideBlock(bb); ++} ++ + bool PluginClientAPI::IsDomInfoAvailable() + { + return gimpleConversion.IsDomInfoAvailable(); +@@ -380,11 +391,26 @@ mlir::Value PluginClientAPI::GetValue(uint64_t valId) + return gimpleConversion.TreeToValue(valId); + } + ++bool PluginClientAPI::IsVirtualOperand(uint64_t id) ++{ ++ return gimpleConversion.IsVirtualOperand(id); ++} ++ + void PluginClientAPI::DebugValue(uint64_t valId) + { + gimpleConversion.DebugValue(valId); + } + ++void PluginClientAPI::DebugOperation(uint64_t opId) ++{ ++ gimpleConversion.DebugOperation(opId); ++} ++ ++void PluginClientAPI::DebugBlock(uint64_t bb) ++{ ++ gimpleConversion.DebugBlock(bb); ++} ++ + mlir::Value PluginClientAPI::BuildMemRef(PluginIR::PluginTypeBase type, + uint64_t baseId, uint64_t offsetId) + { +@@ -411,4 +437,58 @@ bool PluginClientAPI::IsWholeProgram() + return gimpleConversion.IsWholeProgram(); + } + ++void PluginClientAPI::CalDominanceInfo(uint64_t dir, uint64_t funcID) ++{ ++ return gimpleConversion.CalDominanceInfo(dir, funcID); ++} ++ ++vector PluginClientAPI::GetImmUseStmts(uint64_t varId) ++{ ++ return gimpleConversion.GetImmUseStmts(varId); ++} ++ ++mlir::Value PluginClientAPI::GetGimpleVuse(uint64_t opId) ++{ ++ return gimpleConversion.GetGimpleVuse(opId); ++} ++ ++mlir::Value PluginClientAPI::GetGimpleVdef(uint64_t opId) ++{ ++ return gimpleConversion.GetGimpleVdef(opId); ++} ++ ++vector PluginClientAPI::GetSsaUseOperand(uint64_t opId) ++{ ++ return gimpleConversion.GetSsaUseOperand(opId); ++} ++ ++vector PluginClientAPI::GetSsaDefOperand(uint64_t opId) ++{ ++ return gimpleConversion.GetSsaDefOperand(opId); ++} ++ ++vector PluginClientAPI::GetPhiOrStmtUse(uint64_t opId) ++{ ++ return gimpleConversion.GetPhiOrStmtUse(opId); ++} ++ ++vector PluginClientAPI::GetPhiOrStmtDef(uint64_t opId) ++{ ++ return gimpleConversion.GetPhiOrStmtDef(opId); ++} ++ ++bool PluginClientAPI::RefsMayAlias(uint64_t id1, uint64_t id2, uint64_t flag) ++{ ++ return gimpleConversion.RefsMayAlias(id1, id2, flag); ++} ++ ++bool PluginClientAPI::PTIncludesDecl(uint64_t ptrId, uint64_t declId) ++{ ++ return gimpleConversion.PTIncludesDecl(ptrId, declId); ++} ++ ++bool PluginClientAPI::PTsIntersect(uint64_t ptrId_1, uint64_t ptrId_2) ++{ ++ return gimpleConversion.PTsIntersect(ptrId_1, ptrId_2); ++} + } // namespace PluginAPI +\ No newline at end of file +diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp +index c9f3cb7..fba0de4 100644 +--- a/lib/PluginClient/PluginClient.cpp ++++ b/lib/PluginClient/PluginClient.cpp +@@ -839,6 +839,19 @@ void GetBlockLoopFatherResult(PluginClient *client, Json::Value& root, string& r + client->ReceiveSendMsg("LoopOpResult", result); + } + ++void FindCommonLoopResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ uint64_t loopId_1 = atol(root["loopId_1"].asString().c_str()); ++ uint64_t loopId_2 = atol(root["loopId_2"].asString().c_str()); ++ LoopOp commonLoop = clientAPI.FindCommonLoop(loopId_1, loopId_2); ++ PluginJson json = client->GetJson(); ++ json.LoopOpJsonSerialize(commonLoop, result); ++ client->ReceiveSendMsg("LoopOpResult", result); ++} ++ + void CreateBlockResult(PluginClient *client, Json::Value& root, string& result) + { + /// Json格式 +@@ -942,7 +955,7 @@ void GetPhiOpResult(PluginClient *client, Json::Value& root, string& result) + PhiOp op = clientAPI.GetPhiOp(id); + PluginJson json = client->GetJson(); + Json::Value phiOpResult = json.PhiOpJsonSerialize(op); +- client->ReceiveSendMsg("OpsResult", phiOpResult.toStyledString()); ++ client->ReceiveSendMsg("OpResult", phiOpResult.toStyledString()); + } + + void GetCallOpResult(PluginClient *client, Json::Value& root, string& result) +@@ -954,7 +967,7 @@ void GetCallOpResult(PluginClient *client, Json::Value& root, string& result) + CallOp op = clientAPI.GetCallOp(id); + PluginJson json = client->GetJson(); + Json::Value opResult = json.CallOpJsonSerialize(op); +- client->ReceiveSendMsg("OpsResult", opResult.toStyledString()); ++ client->ReceiveSendMsg("OpResult", opResult.toStyledString()); + } + + void SetLhsInCallOpResult(PluginClient *client, Json::Value& root, string& result) +@@ -1068,7 +1081,7 @@ void CreatePhiOpResult(PluginClient *client, Json::Value& root, string& result) + PhiOp op = clientAPI.CreatePhiOp(argId, blockId); + PluginJson json = client->GetJson(); + Json::Value opResult = json.PhiOpJsonSerialize(op); +- client->ReceiveSendMsg("OpsResult", opResult.toStyledString()); ++ client->ReceiveSendMsg("OpResult", opResult.toStyledString()); + } + + void CreateConstOpResult(PluginClient *client, Json::Value& root, string& result) +@@ -1106,6 +1119,18 @@ void GetAllPhiOpInsideBlockResult(PluginClient *client, Json::Value& root, strin + client->ReceiveSendMsg("GetPhiOps", result); + } + ++void GetAllOpsInsideBlockResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ uint64_t bb = atol(root["bbAddr"].asString().c_str()); ++ vector opsId = clientAPI.GetOpsInsideBlock(bb); ++ PluginJson json = client->GetJson(); ++ json.IDsJsonSerialize(opsId, result); ++ client->ReceiveSendMsg("IdsResult", result); ++} ++ + void IsDomInfoAvailableResult(PluginClient *client, Json::Value& root, string& result) + { + mlir::MLIRContext context; +@@ -1172,6 +1197,136 @@ void CreateNewDefResult(PluginClient *client, Json::Value& root, string& result) + client->ReceiveSendMsg("ValueResult", json.ValueJsonSerialize(ret).toStyledString()); + } + ++void CalDominanceInfoResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ std::string dirIdKey = "dir"; ++ uint64_t dir = atol(root[dirIdKey].asString().c_str()); ++ uint64_t funcId = atol(root["funcId"].asString().c_str()); ++ clientAPI.CalDominanceInfo(dir, funcId); ++ PluginJson json = client->GetJson(); ++ json.NopJsonSerialize(result); ++ client->ReceiveSendMsg("VoidResult", result); ++} ++ ++void GetImmUseStmtsResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t varId = atol(root["varId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ vector opsId = clientAPI.GetImmUseStmts(varId); ++ PluginJson json = client->GetJson(); ++ json.IDsJsonSerialize(opsId, result); ++ client->ReceiveSendMsg("IdsResult", result); ++} ++ ++void GetGimpleVuseResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t opId = atol(root["opId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ mlir::Value vuse = clientAPI.GetGimpleVuse(opId); ++ PluginJson json = client->GetJson(); ++ client->ReceiveSendMsg("ValueResult", json.ValueJsonSerialize(vuse).toStyledString()); ++} ++ ++void GetGimpleVdefResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t opId = atol(root["opId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ mlir::Value vdef = clientAPI.GetGimpleVdef(opId); ++ PluginJson json = client->GetJson(); ++ client->ReceiveSendMsg("ValueResult", json.ValueJsonSerialize(vdef).toStyledString()); ++} ++ ++void GetSsaUseOperandResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t opId = atol(root["opId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ vector ret = clientAPI.GetSsaUseOperand(opId); ++ PluginJson json = client->GetJson(); ++ json.ValuesJsonSerialize(ret, result); ++ client->ReceiveSendMsg("ValuesResult", result); ++} ++ ++void GetSsaDefOperandResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t opId = atol(root["opId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ vector ret = clientAPI.GetSsaDefOperand(opId); ++ PluginJson json = client->GetJson(); ++ json.ValuesJsonSerialize(ret, result); ++ client->ReceiveSendMsg("ValuesResult", result); ++} ++ ++void GetPhiOrStmtUseResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t opId = atol(root["opId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ vector ret = clientAPI.GetPhiOrStmtUse(opId); ++ PluginJson json = client->GetJson(); ++ json.ValuesJsonSerialize(ret, result); ++ client->ReceiveSendMsg("ValuesResult", result); ++} ++ ++void GetPhiOrStmtDefResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t opId = atol(root["opId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ vector ret = clientAPI.GetPhiOrStmtDef(opId); ++ PluginJson json = client->GetJson(); ++ json.ValuesJsonSerialize(ret, result); ++ client->ReceiveSendMsg("ValuesResult", result); ++} ++ ++void RefsMayAliasResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t id1 = atol(root["id1"].asString().c_str()); ++ uint64_t id2 = atol(root["id2"].asString().c_str()); ++ uint64_t flag = atol(root["flag"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ bool ret = clientAPI.RefsMayAlias(id1, id2, flag); ++ client->ReceiveSendMsg("BoolResult", std::to_string(ret)); ++} ++ ++void PTIncludesDeclResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t ptrId = atol(root["ptrId"].asString().c_str()); ++ uint64_t declId = atol(root["declId"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ bool ret = clientAPI.PTIncludesDecl(ptrId, declId); ++ client->ReceiveSendMsg("BoolResult", std::to_string(ret)); ++} ++ ++void PTsIntersectResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t ptrId_1 = atol(root["ptrId_1"].asString().c_str()); ++ uint64_t ptrId_2 = atol(root["ptrId_2"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ bool ret = clientAPI.PTsIntersect(ptrId_1, ptrId_2); ++ client->ReceiveSendMsg("BoolResult", std::to_string(ret)); ++} ++ + void RemoveEdgeResult(PluginClient *client, Json::Value& root, string& result) + { + /// Json格式 +@@ -1235,6 +1390,16 @@ void BuildMemRefResult(PluginClient *client, Json::Value& root, string& result) + client->ReceiveSendMsg("ValueResult", result); + } + ++void IsVirtualOperandResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ uint64_t id = atol(root["id"].asString().c_str()); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ bool ret = clientAPI.IsVirtualOperand(id); ++ client->ReceiveSendMsg("BoolResult", std::to_string(ret)); ++} ++ + void DebugValueResult(PluginClient *client, Json::Value& root, string& result) + { + /// Json格式 +@@ -1252,6 +1417,31 @@ void DebugValueResult(PluginClient *client, Json::Value& root, string& result) + client->ReceiveSendMsg("ValueResult", result); + } + ++void DebugOperationResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ std::string opIdKey = "opId"; ++ uint64_t opId = atol(root[opIdKey].asString().c_str()); ++ clientAPI.DebugOperation(opId); ++ PluginJson json = client->GetJson(); ++ json.NopJsonSerialize(result); ++ client->ReceiveSendMsg("VoidResult", result); ++} ++ ++void DebugBlockResult(PluginClient *client, Json::Value& root, string& result) ++{ ++ mlir::MLIRContext context; ++ context.getOrLoadDialect(); ++ PluginAPI::PluginClientAPI clientAPI(context); ++ uint64_t bb = atol(root["bbAddr"].asString().c_str()); ++ clientAPI.DebugBlock(bb); ++ PluginJson json = client->GetJson(); ++ json.NopJsonSerialize(result); ++ client->ReceiveSendMsg("VoidResult", result); ++} ++ + void IsLtoOptimizeResult(PluginClient *client, Json::Value& root, string& result) + { + mlir::MLIRContext context; +@@ -1314,6 +1504,7 @@ std::map g_getResultFunc = { + {"GetLoopExits", GetLoopExitsResult}, + {"GetLoopSingleExit", GetLoopSingleExitResult}, + {"GetBlockLoopFather", GetBlockLoopFatherResult}, ++ {"FindCommonLoop", FindCommonLoopResult}, + {"CreateBlock", CreateBlockResult}, + {"DeleteBlock", DeleteBlockResult}, + {"SetImmediateDominator", SetImmediateDominatorResult}, +@@ -1332,6 +1523,7 @@ std::map g_getResultFunc = { + {"CreateConstOp", CreateConstOpResult}, + {"UpdateSSA", UpdateSSAResult}, + {"GetAllPhiOpInsideBlock", GetAllPhiOpInsideBlockResult}, ++ {"GetAllOpsInsideBlock", GetAllOpsInsideBlockResult}, + {"IsDomInfoAvailable", IsDomInfoAvailableResult}, + {"GetCurrentDefFromSSA", GetCurrentDefFromSSAResult}, + {"SetCurrentDefInSSA", SetCurrentDefInSSAResult}, +@@ -1341,9 +1533,23 @@ std::map g_getResultFunc = { + {"RemoveEdge", RemoveEdgeResult}, + {"ConfirmValue", ConfirmValueResult}, + {"BuildMemRef", BuildMemRefResult}, ++ {"IsVirtualOperand", IsVirtualOperandResult}, + {"DebugValue", DebugValueResult}, +- {"IsLtoOptimize",IsLtoOptimizeResult}, +- {"IsWholeProgram",IsWholeProgramResult}, ++ {"DebugOperation", DebugOperationResult}, ++ {"DebugBlock", DebugBlockResult}, ++ {"IsLtoOptimize", IsLtoOptimizeResult}, ++ {"IsWholeProgram", IsWholeProgramResult}, ++ {"CalDominanceInfo", CalDominanceInfoResult}, ++ {"GetImmUseStmts", GetImmUseStmtsResult}, ++ {"GetGimpleVuse", GetGimpleVuseResult}, ++ {"GetGimpleVdef", GetGimpleVdefResult}, ++ {"GetSsaUseOperand", GetSsaUseOperandResult}, ++ {"GetSsaDefOperand", GetSsaDefOperandResult}, ++ {"GetPhiOrStmtUse", GetPhiOrStmtUseResult}, ++ {"GetPhiOrStmtDef", GetPhiOrStmtDefResult}, ++ {"RefsMayAlias", RefsMayAliasResult}, ++ {"PTIncludesDecl", PTIncludesDeclResult}, ++ {"PTsIntersect", PTsIntersectResult} + }; + + void PluginClient::GetIRTransResult(void *gccData, const string& funcName, const string& param) +diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp +index 7384a49..70532df 100755 +--- a/lib/PluginClient/PluginJson.cpp ++++ b/lib/PluginClient/PluginJson.cpp +@@ -444,6 +444,38 @@ void PluginJson::LoopOpJsonSerialize(mlir::Plugin::LoopOp& loop, string& out) + out = root.toStyledString(); + } + ++void PluginJson::OpsJsonSerialize(vector>& ops, string& out) ++{ ++ Json::Value root; ++ Json::Value item; ++ int i = 0; ++ string index; ++ ++ for (auto& op : ops) { ++ item = OperationJsonSerialize(op.first, op.second); ++ index = "Op" + std::to_string(i++); ++ root[index] = item; ++ item.clear(); ++ } ++ out = root.toStyledString(); ++} ++ ++void PluginJson::ValuesJsonSerialize(vector& values, string& out) ++{ ++ Json::Value root; ++ Json::Value item; ++ int i = 0; ++ string index; ++ ++ for (auto& v : values) { ++ item = ValueJsonSerialize(v); ++ index = "Value" + std::to_string(i++); ++ root[index] = item; ++ item.clear(); ++ } ++ out = root.toStyledString(); ++} ++ + void PluginJson::IDsJsonSerialize(vector& ids, string& out) + { + Json::Value root; +diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp +index c358d17..342ef3d 100644 +--- a/lib/Translate/GimpleToPluginOps.cpp ++++ b/lib/Translate/GimpleToPluginOps.cpp +@@ -49,6 +49,8 @@ + #include "dominance.h" + #include "print-tree.h" + #include "stor-layout.h" ++#include "ssa-iterators.h" ++#include + + namespace PluginIR { + using namespace mlir::Plugin; +@@ -754,7 +756,7 @@ void GimpleToPluginOps::SetLatch(uint64_t loopID, uint64_t blockID) + vector > GimpleToPluginOps::GetLoopExits(uint64_t loopID) + { + class loop *loop = reinterpret_cast(loopID); +- vec exit_edges = get_loop_exit_edges(loop); ++ auto_vec exit_edges = get_loop_exit_edges(loop); + edge e; + unsigned i = 0; + vector > res; +@@ -789,6 +791,22 @@ LoopOp GimpleToPluginOps::GetBlockLoopFather(uint64_t blockID) + return pluginLoop; + } + ++LoopOp GimpleToPluginOps::FindCommonLoop(uint64_t loopId_1, uint64_t loopId_2) ++{ ++ class loop *loop_s = reinterpret_cast(loopId_1); ++ class loop *loop_d = reinterpret_cast(loopId_2); ++ class loop *loop = find_common_loop(loop_s, loop_d); ++ LoopOp pluginLoop; ++ auto location = builder.getUnknownLoc(); ++ uint64_t id = reinterpret_cast(loop); ++ uint32_t index = (uint32_t)loop->num; ++ uint64_t innerLoopId = reinterpret_cast(reinterpret_cast(loop->inner)); ++ uint64_t outerLoopId = reinterpret_cast(reinterpret_cast(loop_outer(loop))); ++ uint32_t numBlock = loop->num_nodes; ++ pluginLoop = builder.create(location, id, index, innerLoopId, outerLoopId, numBlock); ++ return pluginLoop; ++} ++ + void GimpleToPluginOps::RedirectFallthroughTarget(uint64_t src, uint64_t dest) + { + basic_block srcbb = reinterpret_cast(reinterpret_cast(src)); +@@ -1721,6 +1739,19 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId) + void GimpleToPluginOps::DebugValue(uint64_t valId) + { + tree t = reinterpret_cast(valId); ++ debug_tree(t); ++} ++ ++void GimpleToPluginOps::DebugOperation(uint64_t opId) ++{ ++ gimple *stmt = reinterpret_cast(opId); ++ debug_gimple_stmt(stmt); ++} ++ ++void GimpleToPluginOps::DebugBlock(uint64_t bb) ++{ ++ basic_block BB = reinterpret_cast(bb); ++ debug_bb(BB); + } + + mlir::Value GimpleToPluginOps::BuildMemRef(PluginIR::PluginTypeBase type, uint64_t baseId, uint64_t offsetId) +@@ -1828,6 +1859,27 @@ vector GimpleToPluginOps::GetPhiOpsInsideBlock(uint64_t bb) + return phiOps; + } + ++vector GimpleToPluginOps::GetOpsInsideBlock(uint64_t bb) ++{ ++ basic_block header = reinterpret_cast(bb); ++ vector ops; ++ gimple_stmt_iterator gsi; ++ int i = 0; ++ for (gsi = gsi_start_bb (header); ++ !gsi_end_p (gsi); ++ gsi_next (&gsi)) ++ { ++ gimple *s = gsi_stmt(gsi); ++ if (gimple_code(s) == GIMPLE_DEBUG) continue; ++ uint64_t id = reinterpret_cast(reinterpret_cast(s)); ++ if (gimple_code(s) == GIMPLE_ASSIGN) { ++ BuildAssignOp(id); ++ } ++ ops.push_back(id); ++ } ++ return ops; ++} ++ + bool GimpleToPluginOps::IsDomInfoAvailable() + { + return dom_info_available_p (CDI_DOMINATORS); +@@ -1887,4 +1939,167 @@ Value GimpleToPluginOps::MakeSsaName(mlir::Type type) + return TreeToValue(retId); + } + ++bool GimpleToPluginOps::IsVirtualOperand(uint64_t id) ++{ ++ tree op = reinterpret_cast(id); ++ return virtual_operand_p (op); ++} ++ ++void GimpleToPluginOps::CalDominanceInfo(uint64_t dir, uint64_t funcID) ++{ ++ function *fn = reinterpret_cast(funcID); ++ push_cfun(fn); ++ if (dir == 1) { ++ calculate_dominance_info(CDI_DOMINATORS); ++ } else if (dir == 2) { ++ calculate_dominance_info(CDI_POST_DOMINATORS); ++ } else { ++ abort(); ++ } ++ pop_cfun(); ++} ++ ++vector GimpleToPluginOps::GetImmUseStmts(uint64_t varId) ++{ ++ vector opsId; ++ tree var = reinterpret_cast(varId); ++ imm_use_iterator imm_iter; ++ gimple *stmt; ++ FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var) { ++ uint64_t id = reinterpret_cast(reinterpret_cast(stmt)); ++ opsId.push_back(id); ++ } ++ return opsId; ++} ++ ++ ++mlir::Value GimpleToPluginOps::GetGimpleVuse(uint64_t opId) ++{ ++ gimple *stmt = reinterpret_cast(opId); ++ tree vuse = gimple_vuse(stmt); ++ mlir::Value v = TreeToValue(reinterpret_cast(reinterpret_cast(vuse))); ++ return v; ++} ++ ++mlir::Value GimpleToPluginOps::GetGimpleVdef(uint64_t opId) ++{ ++ gimple *stmt = reinterpret_cast(opId); ++ tree vdef = gimple_vdef(stmt); ++ mlir::Value v = TreeToValue(reinterpret_cast(reinterpret_cast(vdef))); ++ return v; ++} ++ ++vector GimpleToPluginOps::GetSsaUseOperand(uint64_t opId) ++{ ++ vector ret; ++ gimple *stmt = reinterpret_cast(opId); ++ use_operand_p use_p; ++ ssa_op_iter oi; ++ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, oi, SSA_OP_USE) { ++ tree op = USE_FROM_PTR (use_p); ++ if (TREE_CODE (op) != SSA_NAME) { ++ continue; ++ } ++ mlir::Value v = TreeToValue(reinterpret_cast(reinterpret_cast(op))); ++ ret.push_back(v); ++ } ++ return ret; ++} ++ ++vector GimpleToPluginOps::GetSsaDefOperand(uint64_t opId) ++{ ++ vector ret; ++ gimple *stmt = reinterpret_cast(opId); ++ def_operand_p def_p; ++ ssa_op_iter oi; ++ FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, oi, SSA_OP_DEF) { ++ tree op = DEF_FROM_PTR (def_p); ++ if (TREE_CODE (op) != SSA_NAME) { ++ continue; ++ } ++ mlir::Value v = TreeToValue(reinterpret_cast(reinterpret_cast(op))); ++ ret.push_back(v); ++ } ++ return ret; ++} ++ ++vector GimpleToPluginOps::GetPhiOrStmtUse(uint64_t opId) ++{ ++ vector ret; ++ gimple *stmt = reinterpret_cast(opId); ++ use_operand_p use_p; ++ ssa_op_iter oi; ++ FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, oi, SSA_OP_USE) { ++ tree op = USE_FROM_PTR (use_p); ++ mlir::Value v = TreeToValue(reinterpret_cast(reinterpret_cast(op))); ++ ret.push_back(v); ++ } ++ return ret; ++} ++ ++vector GimpleToPluginOps::GetPhiOrStmtDef(uint64_t opId) ++{ ++ vector ret; ++ gimple *stmt = reinterpret_cast(opId); ++ def_operand_p def_p; ++ ssa_op_iter oi; ++ FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, oi, SSA_OP_DEF) { ++ tree op = DEF_FROM_PTR (def_p); ++ mlir::Value v = TreeToValue(reinterpret_cast(reinterpret_cast(op))); ++ ret.push_back(v); ++ } ++ return ret; ++} ++ ++string parser_generic_tree_node(tree node) ++{ ++ FILE *fp = tmpfile(); ++ if(fp==nullptr){ ++ return ""; ++ } ++ pretty_printer buffer; ++ pp_needs_newline(&buffer)=true; ++ buffer.buffer->stream = fp; ++ dump_generic_node(&buffer, node, 0, TDF_SLIM, false); ++ std::string str(pp_formatted_text(&buffer)); ++ pp_newline_and_flush(&buffer); ++ fclose(fp); ++ return str; ++} ++ ++bool GimpleToPluginOps::RefsMayAlias(uint64_t id1, uint64_t id2, uint64_t flag) ++{ ++ tree ref1 = reinterpret_cast(id1); ++ tree ref2 = reinterpret_cast(id2); ++ bool tbaa_p = false; ++ if (flag) tbaa_p = true; ++ return refs_may_alias_p (ref1, ref2, tbaa_p); ++} ++ ++bool GimpleToPluginOps::PTIncludesDecl(uint64_t ptrId, uint64_t declId) ++{ ++ tree ptr = reinterpret_cast(ptrId); ++ tree decl = reinterpret_cast(declId); ++ struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr); ++ if(!pi) return false; ++ if(!decl){ ++ std::cout<<"this decl is invalid!"; ++ return false; ++ } ++ if(is_global_var(decl)){ ++ std::cout<<"decl is global var!"<pt, decl); ++} ++ ++bool GimpleToPluginOps::PTsIntersect(uint64_t ptrId_1, uint64_t ptrId_2) ++{ ++ tree ptr_1 = reinterpret_cast(ptrId_1); ++ tree ptr_2 = reinterpret_cast(ptrId_2); ++ struct ptr_info_def *pi_1 = SSA_NAME_PTR_INFO (ptr_1); ++ struct ptr_info_def *pi_2 = SSA_NAME_PTR_INFO (ptr_2); ++ if(!pi_1 || !pi_2) return false; ++ return pt_solutions_intersect(&pi_1->pt, &pi_2->pt); ++} ++ + } // namespace PluginIR +\ No newline at end of file +diff --git a/lib/gccPlugin/gccPlugin.cpp b/lib/gccPlugin/gccPlugin.cpp +index 1877651..3e10023 100755 +--- a/lib/gccPlugin/gccPlugin.cpp ++++ b/lib/gccPlugin/gccPlugin.cpp +@@ -193,6 +193,7 @@ static std::map g_refPassName { + {PASS_PHIOPT, "phiopt"}, + {PASS_SSA, "ssa"}, + {PASS_LOOP, "loop"}, ++ {PASS_LAD, "laddress"}, + {PASS_MAC, "materialize-all-clones"}, + }; + +@@ -232,6 +233,10 @@ void RegisterPassManagerSetup(unsigned int index, const ManagerSetupData& setupD + passData.type = GIMPLE_PASS; + passInfo.pass = new GimplePass(passData, index); + break; ++ case PASS_LAD: ++ passData.type = GIMPLE_PASS; ++ passInfo.pass = new GimplePass(passData, index); ++ break; + case PASS_MAC: + passData.type = SIMPLE_IPA_PASS; + passInfo.pass = new SimpleIPAPass(passData, index); +-- +2.33.0 + diff --git a/0014-PluginClient-Bugfix-for-semaphore-exception-and-port.patch b/0014-PluginClient-Bugfix-for-semaphore-exception-and-port.patch new file mode 100644 index 0000000000000000000000000000000000000000..4045e30ff8e7cd72e8cefb6a25f6f95d256a316d --- /dev/null +++ b/0014-PluginClient-Bugfix-for-semaphore-exception-and-port.patch @@ -0,0 +1,66 @@ +From 954c37acbb0a9a790d07b567ad99c952e150e6da Mon Sep 17 00:00:00 2001 +From: Mingchuan Wu +Date: Tue, 27 Feb 2024 16:05:13 +0800 +Subject: [PATCH 5/5] [PluginClient] Bugfix for semaphore exception and port + number release. + +--- + lib/PluginClient/PluginClient.cpp | 16 +++++++++++++--- + lib/Translate/GimpleToPluginOps.cpp | 7 ++++++- + 2 files changed, 19 insertions(+), 4 deletions(-) + +diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp +index fba0de4..6bc6401 100644 +--- a/lib/PluginClient/PluginClient.cpp ++++ b/lib/PluginClient/PluginClient.cpp +@@ -1749,7 +1749,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++) { +@@ -1770,8 +1775,13 @@ static bool WaitServer(const string& port) + 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; +diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp +index 342ef3d..76c5e31 100644 +--- a/lib/Translate/GimpleToPluginOps.cpp ++++ b/lib/Translate/GimpleToPluginOps.cpp +@@ -1523,7 +1523,12 @@ 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); + opValue = builder.create( +-- +2.33.0 + diff --git a/0015-MLIR17-Adaptation-to-llvm17-mlir17.patch b/0015-MLIR17-Adaptation-to-llvm17-mlir17.patch new file mode 100644 index 0000000000000000000000000000000000000000..a23783bfe4e1abe0fa619bea180b7e2662fdf116 --- /dev/null +++ b/0015-MLIR17-Adaptation-to-llvm17-mlir17.patch @@ -0,0 +1,1216 @@ +From 862e94cb9cd06370548584a6f0a3a2e07bbc6e11 Mon Sep 17 00:00:00 2001 +From: Mingchuan Wu +Date: Wed, 10 Apr 2024 17:31:27 +0800 +Subject: [PATCH] [MLIR17] Adaptation to llvm17/mlir17. + +--- + include/Dialect/PluginOps.td | 123 ++++++------ + include/Dialect/PluginTypes.h | 2 + + lib/Dialect/PluginOps.cpp | 37 ++-- + lib/PluginClient/PluginJson.cpp | 286 ++++++++++++++-------------- + lib/Translate/GimpleToPluginOps.cpp | 20 +- + 5 files changed, 239 insertions(+), 229 deletions(-) + +diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td +index d9b0893..6ec7961 100644 +--- a/include/Dialect/PluginOps.td ++++ b/include/Dialect/PluginOps.td +@@ -24,7 +24,7 @@ include "PluginDialect.td" + include "mlir/Interfaces/SideEffectInterfaces.td" + include "mlir/Interfaces/CallInterfaces.td" + +-def CGnodeOp : Plugin_Op<"callgraphnode", [NoSideEffect]> { ++def CGnodeOp : Plugin_Op<"callgraphnode", [NoMemoryEffect]> { + let summary = "callgraph node operation"; + let description = [{ + TODO. +@@ -47,7 +47,7 @@ def CGnodeOp : Plugin_Op<"callgraphnode", [NoSideEffect]> { + ]; + } + +-def FunctionOp : Plugin_Op<"function", [NoSideEffect]> { ++def FunctionOp : Plugin_Op<"function", [NoMemoryEffect]> { + let summary = "function with a region"; + let description = [{ + TODO. +@@ -72,7 +72,7 @@ def FunctionOp : Plugin_Op<"function", [NoSideEffect]> { + }]; + } + +-def LocalDeclOp : Plugin_Op<"declaration", [NoSideEffect]> { ++def LocalDeclOp : Plugin_Op<"declaration", [NoMemoryEffect]> { + let summary = "local variable declaration"; + let description = [{TODO}]; + let arguments = (ins OptionalAttr:$id, +@@ -86,7 +86,7 @@ def LocalDeclOp : Plugin_Op<"declaration", [NoSideEffect]> { + ]; + } + +-def LoopOp : Plugin_Op<"loop", [NoSideEffect]> { ++def LoopOp : Plugin_Op<"loop", [NoMemoryEffect]> { + let summary = "loop operation"; + let description = [{ + TODO. +@@ -132,7 +132,7 @@ def CallOp : Plugin_Op<"call", [ + }]; + } + +-def PhiOp : Plugin_Op<"phi", [NoSideEffect]> { ++def PhiOp : Plugin_Op<"phi", [NoMemoryEffect]> { + let summary = "phi op"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, +@@ -150,7 +150,7 @@ def PhiOp : Plugin_Op<"phi", [NoSideEffect]> { + }]; + } + +-def AssignOp : Plugin_Op<"assign", [NoSideEffect]> { ++def AssignOp : Plugin_Op<"assign", [NoMemoryEffect]> { + let summary = "assign op"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, +@@ -169,7 +169,7 @@ def AssignOp : Plugin_Op<"assign", [NoSideEffect]> { + // let printer = [{ return ::print(p, *this); }]; + } + +-def NopOp : Plugin_Op<"nop", [NoSideEffect]> { ++def NopOp : Plugin_Op<"nop", [NoMemoryEffect]> { + let summary = "nop"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id); +@@ -179,7 +179,7 @@ def NopOp : Plugin_Op<"nop", [NoSideEffect]> { + ]; + } + +-def EHElseOp : Plugin_Op<"eh_else", [NoSideEffect]> { ++def EHElseOp : Plugin_Op<"eh_else", [NoMemoryEffect]> { + let summary = "EHElseOP"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, ArrayAttr:$nBody, ArrayAttr:$eBody); +@@ -293,13 +293,13 @@ def DeclBaseOp : DeclBase<"decl"> { + let builders = [ + OpBuilder<(ins "uint64_t":$id, "IDefineCode":$defCode, + "bool":$readOnly, "bool":$addressable, "bool":$used, "int":$uid, "Value":$initial, +- "Value":$name, "Optional":$chain, "Type":$retType)> ++ "Value":$name, "std::optional":$chain, "Type":$retType)> + ]; + let extraClassDeclaration = [{ + Type getResultType() { return this->getOperation()->getResult(0).getType(); } +- Value GetInitial() { return initial(); } +- Value GetName() { return name(); } +- Optional GetChain() { return chain(); } ++ Value GetInitial() { return getInitial(); } ++ Value GetName() { return getName(); } ++ std::optional GetChain() { return getChain(); } + }]; + } + +@@ -308,17 +308,17 @@ def BlockOp : BLOCK<"block"> { + let description = [{TODO}]; + let builders = [ + OpBuilder<(ins "uint64_t":$id, "IDefineCode":$defCode, +- "bool":$readOnly, "Optional":$vars, "Optional":$supercontext, +- "Optional":$subblocks, "Optional":$chain, +- "Optional":$abstract_origin, "Type":$retType)> ++ "bool":$readOnly, "std::optional":$vars, "std::optional":$supercontext, ++ "std::optional":$subblocks, "std::optional":$chain, ++ "std::optional":$abstract_origin, "Type":$retType)> + ]; + let extraClassDeclaration = [{ + Type getResultType() { return this->getOperation()->getResult(0).getType(); } +- Value GetVars() { return vars(); } +- Optional GetSupercontext() { return supercontext(); } +- Value GetSubblocks() { return subblocks(); } +- Value GetChain() { return chain(); } +- Value GetAbstractorigin() { return abstract_origin(); } ++ Value GetVars() { return getVars(); } ++ std::optional GetSupercontext() { return getSupercontext(); } ++ Value GetSubblocks() { return getSubblocks(); } ++ Value GetChain() { return getChain(); } ++ Value GetAbstractorigin() { return getAbstractOrigin(); } + }]; + } + +@@ -342,11 +342,11 @@ def FieldDeclOp : FieldDecl<"field"> { + ]; + let extraClassDeclaration = [{ + Type getResultType() { return this->getOperation()->getResult(0).getType(); } +- Value GetInitial() { return initial(); } +- Value GetName() { return name(); } +- Optional GetChain() { return chain(); } +- Value GetFieldOffset() { return fieldOffset(); } +- Value GetFieldBitOffset() { return fieldBitOffset(); } ++ Value GetInitial() { return getInitial(); } ++ Value GetName() { return getName(); } ++ std::optional GetChain() { return getChain(); } ++ Value GetFieldOffset() { return getFieldOffset(); } ++ Value GetFieldBitOffset() { return getFieldBitOffset(); } + }]; + } + +@@ -359,7 +359,7 @@ def AddressOp : Address<"address"> { + ]; + let extraClassDeclaration = [{ + Type getResultType() { return this->getOperation()->getResult(0).getType(); } +- Value GetOperand() { return operand(); } ++ Value GetOperand() { return getOperand(); } + }]; + } + +@@ -471,7 +471,7 @@ def ArrayOp : ArrayRef<"ArrayRef"> { + }]; + } + +-def BaseOp : Plugin_Op<"statement_base", [NoSideEffect]> { ++def BaseOp : Plugin_Op<"statement_base", [NoMemoryEffect]> { + let summary = "Base operation, just like placeholder for statement."; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, StrAttr:$opCode); +@@ -481,7 +481,7 @@ def BaseOp : Plugin_Op<"statement_base", [NoSideEffect]> { + ]; + } + +-def DebugOp : Plugin_Op<"debug", [NoSideEffect]> { ++def DebugOp : Plugin_Op<"debug", [NoMemoryEffect]> { + let summary = "DebugOp."; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id); +@@ -491,7 +491,7 @@ def DebugOp : Plugin_Op<"debug", [NoSideEffect]> { + ]; + } + +-def AsmOp : Plugin_Op<"asm", [NoSideEffect]> { ++def AsmOp : Plugin_Op<"asm", [NoMemoryEffect]> { + let summary = "asm Op"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, StrAttr:$statement, UI32Attr:$nInputs, UI32Attr:$nOutputs, UI32Attr:$nClobbers, +@@ -503,17 +503,17 @@ def AsmOp : Plugin_Op<"asm", [NoSideEffect]> { + ]; + + let extraClassDeclaration = [{ +- unsigned GetNInputs() { return this->nInputsAttr().getInt(); }; +- unsigned GetNoutputs() { return this->nOutputsAttr().getInt(); }; +- unsigned GetNClobbers() { return this->nClobbersAttr().getInt(); }; ++ unsigned GetNInputs() { return this->getNInputsAttr().getInt(); }; ++ unsigned GetNoutputs() { return this->getNOutputsAttr().getInt(); }; ++ unsigned GetNClobbers() { return this->getNClobbersAttr().getInt(); }; + Value GetInputOp(unsigned index) { return getOperand(index); }; +- Value GetOutputOp(unsigned index) { return getOperand(this->nInputsAttr().getInt() + index); }; ++ Value GetOutputOp(unsigned index) { return getOperand(this->getNInputsAttr().getInt() + index); }; + Value GetCkobberOp(unsigned index) { +- return getOperand(this->nInputsAttr().getInt() + this->nOutputsAttr().getInt() + index); }; ++ return getOperand(this->getNInputsAttr().getInt() + this->getNOutputsAttr().getInt() + index); }; + }]; + } + +-def LabelOp : Plugin_Op<"label", [NoSideEffect]> { ++def LabelOp : Plugin_Op<"label", [NoMemoryEffect]> { + let summary = "Label op."; + let description = [{TODO}]; + let results = (outs AnyType:$result); +@@ -526,7 +526,7 @@ def LabelOp : Plugin_Op<"label", [NoSideEffect]> { + }]; + } + +-def EHMntOp : Plugin_Op<"eh_mnt", [NoSideEffect]> { ++def EHMntOp : Plugin_Op<"eh_mnt", [NoMemoryEffect]> { + let summary = "EH_MUST_NOT_THROW op."; + let description = [{TODO}]; + let results = (outs AnyType:$result); +@@ -535,11 +535,11 @@ def EHMntOp : Plugin_Op<"eh_mnt", [NoSideEffect]> { + OpBuilder<(ins "uint64_t":$id, "Value":$decl)> + ]; + let extraClassDeclaration = [{ +- Value Getfndecl() { return decl(); }; ++ Value Getfndecl() { return getDecl(); }; + }]; + } + +-def BindOp : Plugin_Op<"Bind", [NoSideEffect]> { ++def BindOp : Plugin_Op<"Bind", [NoMemoryEffect]> { + let summary = "BindOp"; + let description = [{TODO}]; + let results = (outs AnyType:$result); +@@ -548,12 +548,12 @@ def BindOp : Plugin_Op<"Bind", [NoSideEffect]> { + OpBuilder<(ins "uint64_t":$id, "Value":$vars, "ArrayRef":$body, "Value":$block)> + ]; + let extraClassDeclaration = [{ +- Value GetVars() { return vars(); }; +- Value GetBlock() { return block(); }; ++ Value GetVars() { return getVars(); }; ++ Value GetBlock() { return getBlock(); }; + }]; + } + +-def TryOp : Plugin_Op<"try", [NoSideEffect]> { ++def TryOp : Plugin_Op<"try", [NoMemoryEffect]> { + let summary = "TryOp"; + let description = [{TODO}]; + let results = (outs AnyType:$result); +@@ -563,7 +563,7 @@ def TryOp : Plugin_Op<"try", [NoSideEffect]> { + ]; + } + +-def CatchOp : Plugin_Op<"catch", [NoSideEffect]> { ++def CatchOp : Plugin_Op<"catch", [NoMemoryEffect]> { + let summary = "CatchOp"; + let description = [{TODO}]; + let results = (outs AnyType:$result); +@@ -572,7 +572,7 @@ def CatchOp : Plugin_Op<"catch", [NoSideEffect]> { + OpBuilder<(ins "uint64_t":$id, "Value":$types, "ArrayRef":$handler)> + ]; + let extraClassDeclaration = [{ +- Value GetTypes() { return types(); }; ++ Value GetTypes() { return getTypes(); }; + }]; + } + // Terminators +@@ -581,30 +581,31 @@ def CatchOp : Plugin_Op<"catch", [NoSideEffect]> { + class Plugin_TerminatorOp traits = []> : + Plugin_Op; + +-def SwitchOp : Plugin_TerminatorOp<"switch", [NoSideEffect]> { ++def SwitchOp : Plugin_TerminatorOp<"switch", [NoMemoryEffect]> { + let summary = "switch op."; + let description = [{TODO}]; + let successors = (successor + AnySuccessor:$defaultDestination, + VariadicSuccessor:$caseDestinations + ); +- let arguments = (ins UI64Attr:$id, AnyType:$index, UI64Attr:$address, AnyType:$defaultLabel, Variadic:$operands, +- UI64Attr:$defaultaddr, ArrayAttr:$caseaddrs); ++ let arguments = (ins UI64Attr:$id, AnyType:$index, UI64Attr:$address, ++ AnyType:$defaultLabel, Variadic:$args, ++ UI64Attr:$defaultaddr, ArrayAttr:$caseaddrs); + let results = (outs AnyType:$result); + let builders = [ + OpBuilder<(ins "uint64_t":$id, "Value":$index, "uint64_t":$address, "Value":$defaultLabel, +- "ArrayRef":$operands, "Block*":$defaultDestination, "uint64_t":$defaultaddr, ++ "ArrayRef":$args, "Block*":$defaultDestination, "uint64_t":$defaultaddr, + "ArrayRef":$caseDestinations, "ArrayRef":$caseaddrs)> + ]; + + let extraClassDeclaration = [{ + unsigned GetNumLabels() { return getNumOperands() - 2; }; +- Block* GetDefautDest() { return defaultDestination();} +- SmallVector GetCaseDest() { return caseDestinations(); }; ++ Block* GetDefautDest() { return getDefaultDestination(); } ++ SmallVector GetCaseDest() { return getCaseDestinations(); }; + }]; + } + +-def FallThroughOp : Plugin_TerminatorOp<"fallthrough", [NoSideEffect]> { ++def FallThroughOp : Plugin_TerminatorOp<"fallthrough", [NoMemoryEffect]> { + let summary = "FallThroughOp"; + let description = [{TODO}]; + let successors = (successor AnySuccessor:$dest); +@@ -616,7 +617,7 @@ def FallThroughOp : Plugin_TerminatorOp<"fallthrough", [NoSideEffect]> { + ]; + } + +-def CondOp : Plugin_TerminatorOp<"condition", [NoSideEffect]> { ++def CondOp : Plugin_TerminatorOp<"condition", [NoMemoryEffect]> { + let summary = "condition op"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, UI64Attr:$address, +@@ -639,7 +640,7 @@ def CondOp : Plugin_TerminatorOp<"condition", [NoSideEffect]> { + } + + // todo: currently RetOp do not have a correct assemblyFormat +-def RetOp : Plugin_TerminatorOp<"ret", [NoSideEffect]> { ++def RetOp : Plugin_TerminatorOp<"ret", [NoMemoryEffect]> { + let summary = "RetOp"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$address); // for bb address +@@ -649,7 +650,7 @@ def RetOp : Plugin_TerminatorOp<"ret", [NoSideEffect]> { + ]; + } + +-def GotoOp : Plugin_TerminatorOp<"goto", [NoSideEffect]> { ++def GotoOp : Plugin_TerminatorOp<"goto", [NoMemoryEffect]> { + let summary = "GotoOp"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, UI64Attr:$address, AnyType:$dest, UI64Attr:$successaddr); +@@ -664,7 +665,7 @@ def GotoOp : Plugin_TerminatorOp<"goto", [NoSideEffect]> { + }]; + } + +-def TransactionOp : Plugin_TerminatorOp<"transaction", [NoSideEffect]> { ++def TransactionOp : Plugin_TerminatorOp<"transaction", [NoMemoryEffect]> { + let summary = "TransactionOp"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, UI64Attr:$address, ArrayAttr:$stmtaddr, AnyType:$labelNorm, +@@ -678,13 +679,13 @@ def TransactionOp : Plugin_TerminatorOp<"transaction", [NoSideEffect]> { + ]; + + let extraClassDeclaration = [{ +- Value GetTransactionNormal() { return labelNorm(); } +- Value GetTransactionUinst() { return labelUninst(); } +- Value GetTransactionOver() { return labelOver(); } ++ Value GetTransactionNormal() { return getLabelNorm(); } ++ Value GetTransactionUinst() { return getLabelUninst(); } ++ Value GetTransactionOver() { return getLabelOver(); } + }]; + } + +-def ResxOp : Plugin_TerminatorOp<"resx", [NoSideEffect]> { ++def ResxOp : Plugin_TerminatorOp<"resx", [NoMemoryEffect]> { + let summary = "ResxOp"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, UI64Attr:$address, UI64Attr:$region); +@@ -693,11 +694,11 @@ def ResxOp : Plugin_TerminatorOp<"resx", [NoSideEffect]> { + OpBuilder<(ins "uint64_t":$id, "uint64_t":$address, "uint64_t":$region)> + ]; + let extraClassDeclaration = [{ +- uint64_t GetTransactionNormal() { return region(); } ++ uint64_t GetTransactionNormal() { return getRegion(); } + }]; + } + +-def EHDispatchOp : Plugin_TerminatorOp<"dispatch", [NoSideEffect]> { ++def EHDispatchOp : Plugin_TerminatorOp<"dispatch", [NoMemoryEffect]> { + let summary = "EHDispatchOp"; + let description = [{TODO}]; + let arguments = (ins UI64Attr:$id, UI64Attr:$address, UI64Attr:$region, ArrayAttr:$ehHandlersaddrs); +@@ -708,7 +709,7 @@ def EHDispatchOp : Plugin_TerminatorOp<"dispatch", [NoSideEffect]> { + "ArrayRef":$ehHandlersaddrs)> + ]; + let extraClassDeclaration = [{ +- uint64_t GetTransactionNormal() { return region(); } ++ uint64_t GetTransactionNormal() { return getRegion(); } + }]; + } + #endif // PLUGIN_OPS_TD +diff --git a/include/Dialect/PluginTypes.h b/include/Dialect/PluginTypes.h +index 3603798..7402c56 100644 +--- a/include/Dialect/PluginTypes.h ++++ b/include/Dialect/PluginTypes.h +@@ -64,6 +64,8 @@ enum PluginTypeID { + class PluginTypeBase : public Type { + public: + using Type::Type; ++ /// FIXME. ++ static bool classof(Type type) { return true; } + + PluginTypeID getPluginTypeID (); + unsigned getPluginIntOrFloatBitWidth (); +diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp +index d4eca75..d4808ef 100644 +--- a/lib/Dialect/PluginOps.cpp ++++ b/lib/Dialect/PluginOps.cpp +@@ -71,7 +71,7 @@ void FunctionOp::build(OpBuilder &builder, OperationState &state, + + Type FunctionOp::getResultType() + { +- PluginIR::PluginFunctionType resultType = type().dyn_cast(); ++ PluginIR::PluginFunctionType resultType = getType().dyn_cast(); + return resultType; + } + +@@ -173,7 +173,7 @@ void PointerOp::build(OpBuilder &builder, OperationState &state, uint64_t id, + + void DeclBaseOp::build(OpBuilder &builder, OperationState &state, uint64_t id, + IDefineCode defCode, bool readOnly, bool addressable, bool used, int32_t uid, Value initial, +- Value name, Optional chain, Type retType) ++ Value name, std::optional chain, Type retType) + { + state.addAttribute("id", builder.getI64IntegerAttr(id)); + state.addAttribute("defCode", +@@ -184,7 +184,7 @@ void DeclBaseOp::build(OpBuilder &builder, OperationState &state, uint64_t id, + state.addAttribute("uid", builder.getI32IntegerAttr(uid)); + state.addOperands(initial); + if(chain) { +- state.addAttribute("chain", builder.getI64IntegerAttr(chain.getValue())); ++ state.addAttribute("chain", builder.getI64IntegerAttr(chain.value())); + } + state.addOperands(name); + state.addTypes(retType); +@@ -194,27 +194,27 @@ void DeclBaseOp::build(OpBuilder &builder, OperationState &state, uint64_t id, + // BlockOp + + void BlockOp::build(OpBuilder &builder, OperationState &state, uint64_t id, +- IDefineCode defCode, bool readOnly, Optional vars, Optional supercontext, +- Optional subblocks, Optional abstract_origin, Optional chain, Type retType) ++ IDefineCode defCode, bool readOnly, std::optional vars, std::optional supercontext, ++ std::optional subblocks, std::optional abstract_origin, std::optional chain, Type retType) + { + state.addAttribute("id", builder.getI64IntegerAttr(id)); + state.addAttribute("defCode", + builder.getI32IntegerAttr(static_cast(defCode))); + state.addAttribute("readOnly", builder.getBoolAttr(readOnly)); + if(vars) { +- state.addOperands(vars.getValue()); ++ state.addOperands(vars.value()); + } + if(supercontext) { +- state.addAttribute("supercontext", builder.getI64IntegerAttr(supercontext.getValue())); ++ state.addAttribute("supercontext", builder.getI64IntegerAttr(supercontext.value())); + } + if(subblocks) { +- state.addOperands(subblocks.getValue()); ++ state.addOperands(subblocks.value()); + } + if(abstract_origin) { +- state.addOperands(abstract_origin.getValue()); ++ state.addOperands(abstract_origin.value()); + } + if(chain) { +- state.addOperands(chain.getValue()); ++ state.addOperands(chain.value()); + } + state.addTypes(retType); + } +@@ -378,11 +378,17 @@ CallInterfaceCallable CallOp::getCallableForCallee() + return (*this)->getAttrOfType("callee"); + } + ++/// Set the callee for the generic call operation, this is required by the call ++/// interface. ++void CallOp::setCalleeFromCallable(CallInterfaceCallable callee) { ++ (*this)->setAttr("callee", callee.get()); ++} ++ + /// Get the argument operands to the called function, this is required by the + /// call interface. + Operation::operand_range CallOp::getArgOperands() + { +- return inputs(); ++ return this->getInputs(); + } + + // ===----------------------------------------------------------------------===// +@@ -448,9 +454,10 @@ void AsmOp::build(OpBuilder &builder, OperationState &state, + + //===----------------------------------------------------------------------===// + // SwitchOp +-void SwitchOp::build(OpBuilder &builder, OperationState &state, +- uint64_t id, Value index, uint64_t address, Value defaultLabel, ArrayRef operands, +- Block* defaultDest, uint64_t defaultaddr, ArrayRef caseDest, ArrayRef caseaddr) ++void SwitchOp::build(OpBuilder &builder, OperationState &state, uint64_t id, ++ Value index, uint64_t address, Value defaultLabel, ++ ArrayRef args, Block* defaultDest, uint64_t defaultaddr, ++ ArrayRef caseDest, ArrayRef caseaddr) + { + state.addAttribute("id", builder.getI64IntegerAttr(id)); + state.addAttribute("address", builder.getI64IntegerAttr(address)); +@@ -462,7 +469,7 @@ void SwitchOp::build(OpBuilder &builder, OperationState &state, + state.addAttribute("caseaddrs", builder.getArrayAttr(attributes)); + state.addOperands(index); + state.addOperands(defaultLabel); +- state.addOperands(operands); ++ state.addOperands(args); + state.addSuccessors(defaultDest); + state.addSuccessors(caseDest); + } +diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp +index 70532df..4e7ec38 100755 +--- a/lib/PluginClient/PluginJson.cpp ++++ b/lib/PluginClient/PluginJson.cpp +@@ -188,14 +188,14 @@ void PluginJson::CGnodeOpJsonSerialize(CGnodeOp& cgnode, string& out) + 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["id"] = std::to_string(cgnode.getIdAttr().getInt()); ++ root["attributes"]["order"] = std::to_string(cgnode.getOrderAttr().getInt()); ++ if (cgnode.getDefinitionAttr().getValue()) { + root["attributes"]["definition"] = "1"; + }else { + root["attributes"]["definition"] = "0"; + } +- root["attributes"]["symbolName"] = cgnode.symbolNameAttr().getValue().str().c_str(); ++ root["attributes"]["symbolName"] = cgnode.getSymbolNameAttr().getValue().str().c_str(); + out = root.toStyledString(); + } + +@@ -208,17 +208,17 @@ void PluginJson::FunctionOpJsonSerialize(vector& data, string& out) + int i = 0; + string operation; + for (auto& d: data) { +- item["id"] = std::to_string(d.idAttr().getInt()); +- if (d.declaredInlineAttr().getValue()) { ++ item["id"] = std::to_string(d.getIdAttr().getInt()); ++ if (d.getDeclaredInlineAttr().getValue()) { + item["attributes"]["declaredInline"] = "1"; + } else { + item["attributes"]["declaredInline"] = "0"; + } +- item["attributes"]["funcName"] = d.funcNameAttr().getValue().str().c_str(); ++ item["attributes"]["funcName"] = d.getFuncNameAttr().getValue().str().c_str(); + +- if (d.validTypeAttr().getValue()) { ++ if (d.getValidTypeAttr().getValue()) { + item["attributes"]["validType"] = "1"; +- mlir::Type fnty = d.type(); ++ mlir::Type fnty = d.getType(); + if (auto ty = fnty.dyn_cast()) { + if (auto retTy = ty.dyn_cast()) { + item["retType"] = TypeJsonSerialize(retTy); +@@ -282,7 +282,7 @@ Json::Value PluginJson::OperationJsonSerialize(mlir::Operation *operation, uint6 + root = AssignOpJsonSerialize(op); + } else if (CallOp op = llvm::dyn_cast(operation)) { + root = CallOpJsonSerialize(op); +- bbId = op.addressAttr().getInt(); ++ bbId = op.getAddressAttr().getInt(); + } else if (CondOp op = llvm::dyn_cast(operation)) { + root = CondOpJsonSerialize(op, bbId); + } else if (PhiOp op = llvm::dyn_cast(operation)) { +@@ -329,15 +329,15 @@ Json::Value PluginJson::OperationJsonSerialize(mlir::Operation *operation, uint6 + Json::Value PluginJson::BaseOpJsonSerialize(BaseOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["opCode"] = data.opCodeAttr().getValue().str().c_str(); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["opCode"] = data.getOpCodeAttr().getValue().str().c_str(); + return root; + } + + Json::Value PluginJson::RetOpJsonSerialize(RetOp data, uint64_t &bbId) + { + Json::Value root; +- bbId = data.addressAttr().getInt(); ++ bbId = data.getAddressAttr().getInt(); + root["address"] = std::to_string(bbId); + return root; + } +@@ -345,16 +345,16 @@ Json::Value PluginJson::RetOpJsonSerialize(RetOp data, uint64_t &bbId) + Json::Value PluginJson::DebugOpJsonSerialize(DebugOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); + return root; + } + + Json::Value PluginJson::FallThroughOpJsonSerialize(FallThroughOp data, uint64_t &bbId) + { + Json::Value root; +- bbId = data.addressAttr().getInt(); ++ bbId = data.getAddressAttr().getInt(); + root["address"] = std::to_string(bbId); +- root["destaddr"] = std::to_string(data.destaddrAttr().getInt()); ++ root["destaddr"] = std::to_string(data.getDestaddrAttr().getInt()); + return root; + } + +@@ -367,10 +367,10 @@ void PluginJson::LocalDeclsJsonSerialize(vector& decls, string& out + string operation; + + for (auto& decl: decls) { +- item["id"] = std::to_string(decl.idAttr().getInt()); +- item["attributes"]["symName"] = decl.symNameAttr().getValue().str().c_str(); +- item["attributes"]["typeID"] = decl.typeIDAttr().getInt(); +- item["attributes"]["typeWidth"] = decl.typeWidthAttr().getInt(); ++ item["id"] = std::to_string(decl.getIdAttr().getInt()); ++ item["attributes"]["symName"] = decl.getSymNameAttr().getValue().str().c_str(); ++ item["attributes"]["typeID"] = decl.getTypeIDAttr().getInt(); ++ item["attributes"]["typeWidth"] = decl.getTypeWidthAttr().getInt(); + operation = "localDecl" + std::to_string(i++); + root[operation] = item; + item.clear(); +@@ -421,11 +421,11 @@ void PluginJson::LoopOpsJsonSerialize(vector& loops, strin + string operation; + + for (auto& loop: loops) { +- item["id"] = std::to_string(loop.idAttr().getInt()); +- item["index"] = std::to_string(loop.indexAttr().getInt()); +- item["attributes"]["innerLoopId"] = std::to_string(loop.innerLoopIdAttr().getInt()); +- item["attributes"]["outerLoopId"] = std::to_string(loop.outerLoopIdAttr().getInt()); +- item["attributes"]["numBlock"] = std::to_string(loop.numBlockAttr().getInt()); ++ item["id"] = std::to_string(loop.getIdAttr().getInt()); ++ item["index"] = std::to_string(loop.getIndexAttr().getInt()); ++ item["attributes"]["innerLoopId"] = std::to_string(loop.getInnerLoopIdAttr().getInt()); ++ item["attributes"]["outerLoopId"] = std::to_string(loop.getOuterLoopIdAttr().getInt()); ++ item["attributes"]["numBlock"] = std::to_string(loop.getNumBlockAttr().getInt()); + operation = "loopOp" + std::to_string(i++); + root[operation] = item; + item.clear(); +@@ -436,11 +436,11 @@ void PluginJson::LoopOpsJsonSerialize(vector& loops, strin + void PluginJson::LoopOpJsonSerialize(mlir::Plugin::LoopOp& loop, string& out) + { + Json::Value root; +- root["id"] = std::to_string(loop.idAttr().getInt()); +- root["index"] = std::to_string(loop.indexAttr().getInt()); +- root["attributes"]["innerLoopId"] = std::to_string(loop.innerLoopIdAttr().getInt()); +- root["attributes"]["outerLoopId"] = std::to_string(loop.outerLoopIdAttr().getInt()); +- root["attributes"]["numBlock"] = std::to_string(loop.numBlockAttr().getInt()); ++ root["id"] = std::to_string(loop.getIdAttr().getInt()); ++ root["index"] = std::to_string(loop.getIndexAttr().getInt()); ++ root["attributes"]["innerLoopId"] = std::to_string(loop.getInnerLoopIdAttr().getInt()); ++ root["attributes"]["outerLoopId"] = std::to_string(loop.getOuterLoopIdAttr().getInt()); ++ root["attributes"]["numBlock"] = std::to_string(loop.getNumBlockAttr().getInt()); + out = root.toStyledString(); + } + +@@ -543,8 +543,8 @@ void PluginJson::GetPhiOpsJsonSerialize(vector phiOps, string & out) + Json::Value PluginJson::CallOpJsonSerialize(CallOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); +- Optional calleeName = data.callee(); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); ++ std::optional calleeName = data.getCallee(); + if (calleeName) { + item["callee"] = calleeName->str(); + } +@@ -561,26 +561,26 @@ Json::Value PluginJson::CallOpJsonSerialize(CallOp& data) + Json::Value PluginJson::CondOpJsonSerialize(CondOp& data, uint64_t &bbId) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); +- item["condCode"] = std::to_string(data.condCodeAttr().getInt()); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); ++ item["condCode"] = std::to_string(data.getCondCodeAttr().getInt()); + item["lhs"] = ValueJsonSerialize(data.GetLHS()); + item["rhs"] = ValueJsonSerialize(data.GetRHS()); +- bbId = data.addressAttr().getInt(); ++ bbId = data.getAddressAttr().getInt(); + item["address"] = std::to_string(bbId); +- item["tbaddr"] = std::to_string(data.tbaddrAttr().getInt()); +- item["fbaddr"] = std::to_string(data.fbaddrAttr().getInt()); ++ item["tbaddr"] = std::to_string(data.getTbaddrAttr().getInt()); ++ item["fbaddr"] = std::to_string(data.getFbaddrAttr().getInt()); + return item; + } + + Json::Value PluginJson::PhiOpJsonSerialize(PhiOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); +- item["capacity"] = std::to_string(data.capacityAttr().getInt()); +- item["nArgs"] = std::to_string(data.nArgsAttr().getInt()); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); ++ item["capacity"] = std::to_string(data.getCapacityAttr().getInt()); ++ item["nArgs"] = std::to_string(data.getNArgsAttr().getInt()); + item["OperationName"] = data.getOperation()->getName().getStringRef().str(); + size_t opIdx = 0; +- for (mlir::Value v : data.operands()) { ++ for (mlir::Value v : data.getOperands()) { + string input = "input" + std::to_string(opIdx++); + item["operands"][input] = ValueJsonSerialize(v); + } +@@ -591,13 +591,13 @@ Json::Value PluginJson::PhiOpJsonSerialize(PhiOp& data) + Json::Value PluginJson::SSAOpJsonSerialize(SSAOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); +- item["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- item["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); +- item["nameVarId"] = std::to_string(data.nameVarIdAttr().getInt()); +- item["ssaParmDecl"] = std::to_string(data.ssaParmDeclAttr().getInt()); +- item["version"] = std::to_string(data.versionAttr().getInt()); +- item["definingId"] = std::to_string(data.definingIdAttr().getInt()); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); ++ item["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ item["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); ++ item["nameVarId"] = std::to_string(data.getNameVarIdAttr().getInt()); ++ item["ssaParmDecl"] = std::to_string(data.getSsaParmDeclAttr().getInt()); ++ item["version"] = std::to_string(data.getVersionAttr().getInt()); ++ item["definingId"] = std::to_string(data.getDefiningIdAttr().getInt()); + auto retTy = data.getResultType().dyn_cast(); + item["retType"] = TypeJsonSerialize(retTy); + return item; +@@ -606,11 +606,11 @@ Json::Value PluginJson::SSAOpJsonSerialize(SSAOp& data) + Json::Value PluginJson::AssignOpJsonSerialize(AssignOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); +- item["exprCode"] = std::to_string(data.exprCodeAttr().getInt()); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); ++ item["exprCode"] = std::to_string(data.getExprCodeAttr().getInt()); + item["OperationName"] = data.getOperation()->getName().getStringRef().str(); + size_t opIdx = 0; +- for (mlir::Value v : data.operands()) { ++ for (mlir::Value v : data.getOperands()) { + string input = "input" + std::to_string(opIdx++); + item["operands"][input] = ValueJsonSerialize(v); + } +@@ -624,9 +624,9 @@ Json::Value PluginJson::ValueJsonSerialize(mlir::Value data) + if (ConstOp cOp = data.getDefiningOp()) { + auto retTy = data.getType().dyn_cast(); + root["retType"] = TypeJsonSerialize(retTy); +- root["id"] = std::to_string(cOp.idAttr().getInt()); ++ root["id"] = std::to_string(cOp.getIdAttr().getInt()); + root["defCode"] = std::to_string(static_cast(IDefineCode::IntCST)); +- root["value"] = std::to_string(cOp.initAttr().cast().getInt()); ++ root["value"] = std::to_string(cOp.getInitAttr().cast().getInt()); + } else if (MemOp mOp = data.getDefiningOp()) { + root = MemOpJsonSerialize(mOp); + } else if (SSAOp sOp = data.getDefiningOp()) { +@@ -652,8 +652,8 @@ Json::Value PluginJson::ValueJsonSerialize(mlir::Value data) + } else if (BlockOp sOp = data.getDefiningOp()) { + root = BlockOpJsonSerialize(sOp); + } else if (PlaceholderOp phOp = data.getDefiningOp()) { +- root["id"] = std::to_string(phOp.idAttr().getInt()); +- root["defCode"] = std::to_string(phOp.defCodeAttr().getInt()); ++ root["id"] = std::to_string(phOp.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(phOp.getDefCodeAttr().getInt()); + auto retTy = phOp.getResultType().dyn_cast(); + root["retType"] = TypeJsonSerialize(retTy); + } else { +@@ -665,9 +665,9 @@ Json::Value PluginJson::ValueJsonSerialize(mlir::Value data) + Json::Value PluginJson::MemOpJsonSerialize(MemOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); + mlir::Value base = data.GetBase(); + mlir::Value offset = data.GetOffset(); + root["base"] = ValueJsonSerialize(base); +@@ -694,13 +694,13 @@ void PluginJson::StringSerialize(const string& data, string& out) + Json::Value PluginJson::AsmOpJsonSerialize(mlir::Plugin::AsmOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["statement"] = data.statementAttr().getValue().str().c_str(); +- root["nInputs"] = std::to_string(data.nInputsAttr().getInt()); +- root["nOutputs"] = std::to_string(data.nOutputsAttr().getInt()); +- root["nClobbers"] = std::to_string(data.nClobbersAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["statement"] = data.getStatementAttr().getValue().str().c_str(); ++ root["nInputs"] = std::to_string(data.getNInputsAttr().getInt()); ++ root["nOutputs"] = std::to_string(data.getNOutputsAttr().getInt()); ++ root["nClobbers"] = std::to_string(data.getNClobbersAttr().getInt()); + size_t opIdx = 0; +- for(mlir::Value v : data.operands()) { ++ for(mlir::Value v : data.getOperands()) { + string index = std::to_string(opIdx++); + root["operands"][index] = ValueJsonSerialize(v); + } +@@ -710,17 +710,17 @@ Json::Value PluginJson::AsmOpJsonSerialize(mlir::Plugin::AsmOp data) + Json::Value PluginJson::SwitchOpJsonSerialize(mlir::Plugin::SwitchOp data, uint64_t &bbId) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- bbId = data.addressAttr().getInt(); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ bbId = data.getAddressAttr().getInt(); + size_t opIdx = 0; +- for(mlir::Value v : data.operands()) { ++ for(mlir::Value v : data.getOperands()) { + string index = std::to_string(opIdx++); + root["operands"][index] = ValueJsonSerialize(v); + } +- root["defaultaddr"] = std::to_string(data.defaultaddrAttr().getInt()); +- root["address"] = std::to_string(data.addressAttr().getInt()); ++ root["defaultaddr"] = std::to_string(data.getDefaultaddrAttr().getInt()); ++ root["address"] = std::to_string(data.getAddressAttr().getInt()); + int index = 0; +- for (auto attr : data.caseaddrsAttr()) { ++ for (auto attr : data.getCaseaddrsAttr()) { + root["case"][index] = std::to_string(attr.dyn_cast().getInt()); + } + return root; +@@ -729,21 +729,21 @@ Json::Value PluginJson::SwitchOpJsonSerialize(mlir::Plugin::SwitchOp data, uint6 + Json::Value PluginJson::ResxOpJsonSerialize(ResxOp data, uint64_t &bbId) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- bbId = data.addressAttr().getInt(); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ bbId = data.getAddressAttr().getInt(); + root["address"] = std::to_string(bbId); +- root["region"] = std::to_string(data.regionAttr().getInt()); ++ root["region"] = std::to_string(data.getRegionAttr().getInt()); + return root; + } + + Json::Value PluginJson::BindOpJsonSerialize(BindOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); + root["vars"] = ValueJsonSerialize(data.GetVars()); + root["block"] = ValueJsonSerialize(data.GetBlock()); + int index = 0; +- for (auto attr : data.bodyAttr()) { ++ for (auto attr : data.getBodyAttr()) { + root["body"][index] = std::to_string(attr.dyn_cast().getInt()); + } + return root; +@@ -752,26 +752,26 @@ Json::Value PluginJson::BindOpJsonSerialize(BindOp data) + Json::Value PluginJson::TryOpJsonSerialize(TryOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); + int index = 0; +- for (auto attr : data.evalAttr()) { ++ for (auto attr : data.getEvalAttr()) { + root["eval"][index] = std::to_string(attr.dyn_cast().getInt()); + } + index = 0; +- for (auto attr : data.cleanupAttr()) { ++ for (auto attr : data.getCleanupAttr()) { + root["cleanup"][index] = std::to_string(attr.dyn_cast().getInt()); + } +- root["kind"] = std::to_string(data.kindAttr().getInt()); ++ root["kind"] = std::to_string(data.getKindAttr().getInt()); + return root; + } + + Json::Value PluginJson::CatchOpJsonSerialize(CatchOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); + root["types"] = ValueJsonSerialize(data.GetTypes()); + int index = 0; +- for (auto attr : data.handlerAttr()) { ++ for (auto attr : data.getHandlerAttr()) { + root["handler"][index] = std::to_string(attr.dyn_cast().getInt()); + } + return root; +@@ -780,12 +780,12 @@ Json::Value PluginJson::CatchOpJsonSerialize(CatchOp data) + Json::Value PluginJson::EHDispatchOpJsonSerialize(EHDispatchOp data, uint64_t &bbId) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- bbId = data.addressAttr().getInt(); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ bbId = data.getAddressAttr().getInt(); + root["address"] = std::to_string(bbId); +- root["region"] = std::to_string(data.regionAttr().getInt()); ++ root["region"] = std::to_string(data.getRegionAttr().getInt()); + int index = 0; +- for (auto attr : data.ehHandlersaddrsAttr()) { ++ for (auto attr : data.getEhHandlersaddrsAttr()) { + root["ehHandlersaddrs"][index] = std::to_string(attr.dyn_cast().getInt()); + } + return root; +@@ -794,37 +794,37 @@ Json::Value PluginJson::EHDispatchOpJsonSerialize(EHDispatchOp data, uint64_t &b + Json::Value PluginJson::GotoOpJsonSerialize(GotoOp data, uint64_t &bbId) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- bbId = data.addressAttr().getInt(); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ bbId = data.getAddressAttr().getInt(); + root["address"] = std::to_string(bbId); + root["dest"] = ValueJsonSerialize(data.GetLabel()); +- root["successaddr"] = std::to_string(data.successaddrAttr().getInt()); ++ root["successaddr"] = std::to_string(data.getSuccessaddrAttr().getInt()); + return root; + } + + Json::Value PluginJson::TransactionOpJsonSerialize(TransactionOp data, uint64_t &bbId) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- bbId = data.addressAttr().getInt(); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ bbId = data.getAddressAttr().getInt(); + root["address"] = std::to_string(bbId); + int index = 0; +- for (auto attr : data.stmtaddrAttr()) { ++ for (auto attr : data.getStmtaddrAttr()) { + root["stmt"][index] = std::to_string(attr.dyn_cast().getInt()); + } + root["labelNorm"] = ValueJsonSerialize(data.GetTransactionNormal()); + root["labelUninst"] = ValueJsonSerialize(data.GetTransactionUinst()); + root["labelOver"] = ValueJsonSerialize(data.GetTransactionOver()); + +- root["fallthroughaddr"] = std::to_string(data.fallthroughaddrAttr().getInt()); +- root["abortaddr"] = std::to_string(data.abortaddrAttr().getInt()); ++ root["fallthroughaddr"] = std::to_string(data.getFallthroughaddrAttr().getInt()); ++ root["abortaddr"] = std::to_string(data.getAbortaddrAttr().getInt()); + return root; + } + + Json::Value PluginJson::LabelOpJsonSerialize(LabelOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); + root["label"] = ValueJsonSerialize(data.GetLabelLabel()); + return root; + } +@@ -832,7 +832,7 @@ Json::Value PluginJson::LabelOpJsonSerialize(LabelOp data) + Json::Value PluginJson::EHMntOpJsonSerialize(EHMntOp data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); + root["decl"] = ValueJsonSerialize(data.Getfndecl()); + return root; + } +@@ -840,21 +840,21 @@ Json::Value PluginJson::EHMntOpJsonSerialize(EHMntOp data) + Json::Value PluginJson::NopOpJsonSerialize(NopOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); + return item; + } + + Json::Value PluginJson::EHElseOpJsonSerialize(EHElseOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); + + int index = 0; +- for (auto attr : data.nBodyAttr()) { ++ for (auto attr : data.getNBodyAttr()) { + item["nbody"][index] = std::to_string(attr.dyn_cast().getInt()); + } + index = 0; +- for (auto attr : data.eBodyAttr()) { ++ for (auto attr : data.getEBodyAttr()) { + item["ebody"][index] = std::to_string(attr.dyn_cast().getInt()); + } + return item; +@@ -863,16 +863,16 @@ Json::Value PluginJson::EHElseOpJsonSerialize(EHElseOp& data) + Json::Value PluginJson::ConstructorOpJsonSerialize(ConstructorOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); +- root["len"] = std::to_string(data.lenAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); ++ root["len"] = std::to_string(data.getLenAttr().getInt()); + int32_t i = 0; +- for (auto idx : data.idx()) { ++ for (auto idx : data.getIdx()) { + root["idx"][i++] = ValueJsonSerialize(idx); + } + i = 0; +- for (auto val : data.val()) { ++ for (auto val : data.getVal()) { + root["val"][i] = ValueJsonSerialize(val); + } + auto retTy = data.getResultType().dyn_cast(); +@@ -883,12 +883,12 @@ Json::Value PluginJson::ConstructorOpJsonSerialize(ConstructorOp& data) + Json::Value PluginJson::ListOpJsonSerialize(ListOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); +- root["hasPurpose"] = std::to_string(data.hasPurposeAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); ++ root["hasPurpose"] = std::to_string(data.getHasPurposeAttr().getValue()); + size_t opIdx = 0; +- for (mlir::Value v : data.operands()) { ++ for (mlir::Value v : data.getOperands()) { + root["operands"][std::to_string(opIdx++)] = ValueJsonSerialize(v); + } + auto retTy = data.getResultType().dyn_cast(); +@@ -899,10 +899,10 @@ Json::Value PluginJson::ListOpJsonSerialize(ListOp& data) + Json::Value PluginJson::StrOpJsonSerialize(StrOp& data) + { + Json::Value item; +- item["id"] = std::to_string(data.idAttr().getInt()); +- item["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- item["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); +- item["str"] = data.strAttr().getValue().str(); ++ item["id"] = std::to_string(data.getIdAttr().getInt()); ++ item["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ item["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); ++ item["str"] = data.getStrAttr().getValue().str(); + auto retTy = data.getType().dyn_cast(); + item["retType"] = TypeJsonSerialize(retTy); + return item; +@@ -911,9 +911,9 @@ Json::Value PluginJson::StrOpJsonSerialize(StrOp& data) + Json::Value PluginJson::ArrayOpJsonSerialize(ArrayOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); + mlir::Value base = data.GetBase(); + mlir::Value offset = data.GetOffset(); + root["base"] = ValueJsonSerialize(base); +@@ -926,9 +926,9 @@ Json::Value PluginJson::ArrayOpJsonSerialize(ArrayOp& data) + Json::Value PluginJson::ComponentOpJsonSerialize(ComponentOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); + mlir::Value component = data.GetComponent(); + mlir::Value field = data.GetField(); + root["component"] = ValueJsonSerialize(component); +@@ -941,16 +941,16 @@ Json::Value PluginJson::ComponentOpJsonSerialize(ComponentOp& data) + Json::Value PluginJson::DeclBaseOpJsonSerialize(DeclBaseOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); +- root["addressable"] = std::to_string(data.addressableAttr().getValue()); +- root["used"] = std::to_string(data.usedAttr().getValue()); +- root["uid"] = std::to_string(data.uidAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); ++ root["addressable"] = std::to_string(data.getAddressableAttr().getValue()); ++ root["used"] = std::to_string(data.getUsedAttr().getValue()); ++ root["uid"] = std::to_string(data.getUidAttr().getInt()); + mlir::Value initial = data.GetInitial(); + mlir::Value name = data.GetName(); + if (data.GetChain()) { +- root["chain"] = std::to_string(data.chain().getValue()); ++ root["chain"] = std::to_string(data.getChain().value()); + } + root["initial"] = ValueJsonSerialize(initial); + root["name"] = ValueJsonSerialize(name); +@@ -962,14 +962,14 @@ Json::Value PluginJson::DeclBaseOpJsonSerialize(DeclBaseOp& data) + Json::Value PluginJson::BlockOpJsonSerialize(BlockOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); + if (data.GetVars()) { + root["vars"] = ValueJsonSerialize(data.GetVars()); + } + if (data.GetSupercontext()) { +- root["supercontext"] = std::to_string(data.GetSupercontext().getValue()); ++ root["supercontext"] = std::to_string(data.GetSupercontext().value()); + } + if (data.GetSubblocks()) { + root["subblocks"] = ValueJsonSerialize(data.GetSubblocks()); +@@ -988,12 +988,12 @@ Json::Value PluginJson::BlockOpJsonSerialize(BlockOp& data) + Json::Value PluginJson::VecOpJsonSerialize(VecOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); +- root["len"] = std::to_string(data.lenAttr().getInt()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); ++ root["len"] = std::to_string(data.getLenAttr().getInt()); + int index = 0; +- for (auto ele : data.elements()) { ++ for (auto ele : data.getElements()) { + root["elements"][index] = ValueJsonSerialize(ele); + } + auto retTy = data.getResultType().dyn_cast(); +@@ -1004,9 +1004,9 @@ Json::Value PluginJson::VecOpJsonSerialize(VecOp& data) + Json::Value PluginJson::FieldDeclOpJsonSerialize(FieldDeclOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); + mlir::Value initial = data.GetInitial(); + mlir::Value name = data.GetName(); + mlir::Value fieldOffset = data.GetFieldOffset(); +@@ -1014,7 +1014,7 @@ Json::Value PluginJson::FieldDeclOpJsonSerialize(FieldDeclOp& data) + root["initial"] = ValueJsonSerialize(initial); + root["name"] = ValueJsonSerialize(name); + if (data.GetChain()) { +- root["chain"] = std::to_string(data.chain().getValue()); ++ root["chain"] = std::to_string(data.getChain().value()); + } + root["fieldOffset"] = ValueJsonSerialize(fieldOffset); + root["fieldBitOffset"] = ValueJsonSerialize(fieldBitOffset); +@@ -1026,9 +1026,9 @@ Json::Value PluginJson::FieldDeclOpJsonSerialize(FieldDeclOp& data) + Json::Value PluginJson::AddressOpJsonSerialize(AddressOp& data) + { + Json::Value root; +- root["id"] = std::to_string(data.idAttr().getInt()); +- root["defCode"] = std::to_string(data.defCodeAttr().getInt()); +- root["readOnly"] = std::to_string(data.readOnlyAttr().getValue()); ++ root["id"] = std::to_string(data.getIdAttr().getInt()); ++ root["defCode"] = std::to_string(data.getDefCodeAttr().getInt()); ++ root["readOnly"] = std::to_string(data.getReadOnlyAttr().getValue()); + mlir::Value operand = data.GetOperand(); + root["operand"] = ValueJsonSerialize(operand); + auto retTy = data.getResultType().dyn_cast(); +diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp +index 76c5e31..f697388 100644 +--- a/lib/Translate/GimpleToPluginOps.cpp ++++ b/lib/Translate/GimpleToPluginOps.cpp +@@ -443,7 +443,7 @@ vector GimpleToPluginOps::GetFuncDecls(uint64_t funcID) + int32_t uid = DECL_UID(var); + mlir::Value initial = TreeToValue((uint64_t)DECL_INITIAL(var)); + mlir::Value name = TreeToValue((uint64_t)DECL_NAME(var)); +- llvm::Optional chain = (uint64_t)DECL_CHAIN(var); ++ std::optional chain = (uint64_t)DECL_CHAIN(var); + bool readOnly = false; + PluginTypeBase rPluginType = PluginUndefType::get(builder.getContext()); + GetTreeAttr(id, readOnly, rPluginType); +@@ -528,7 +528,7 @@ DeclBaseOp GimpleToPluginOps::BuildDecl(IDefineCode code, string name, PluginTyp + int32_t uid = DECL_UID(t); + mlir::Value initial = TreeToValue((uint64_t)DECL_INITIAL(t)); + mlir::Value tname = TreeToValue((uint64_t)DECL_NAME(t)); +- llvm::Optional chain = (uint64_t)DECL_CHAIN(t); ++ std::optional chain = (uint64_t)DECL_CHAIN(t); + bool readOnly = false; + PluginTypeBase rPluginType = PluginUndefType::get(builder.getContext()); + GetTreeAttr(id, readOnly, rPluginType); +@@ -855,7 +855,7 @@ FunctionOp GimpleToPluginOps::BuildFunctionOp(uint64_t functionId) + retOp = builder.create(location, functionId, + funcName, declaredInline, Ty, validType); + } +- auto& fr = retOp.bodyRegion(); ++ auto& fr = retOp.getBodyRegion(); + if (fn->cfg == nullptr) return retOp; + if (!ProcessBasicBlock((intptr_t)ENTRY_BLOCK_PTR_FOR_FN(fn), fr)) { + // handle error +@@ -1628,7 +1628,7 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId) + // postgresql-11.3 ICE + mlir::Value initial = builder.create(builder.getUnknownLoc(), 0, IDefineCode::UNDEF, 0, rPluginType); + mlir::Value name = TreeToValue((uint64_t)DECL_NAME(t)); +- llvm::Optional chain = (uint64_t)DECL_CHAIN(t); ++ std::optional chain = (uint64_t)DECL_CHAIN(t); + GetTreeAttr(treeId, readOnly, rPluginType); + opValue = builder.create( + builder.getUnknownLoc(), treeId, IDefineCode::Decl, readOnly, addressable, used, uid, initial, name, +@@ -1646,7 +1646,7 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId) + int32_t uid = DECL_UID(t); + mlir::Value initial = TreeToValue((uint64_t)DECL_INITIAL(t)); + mlir::Value name = TreeToValue((uint64_t)DECL_NAME(t)); +- llvm::Optional chain = (uint64_t)DECL_CHAIN(t); ++ std::optional chain = (uint64_t)DECL_CHAIN(t); + GetTreeAttr(treeId, readOnly, rPluginType); + opValue = builder.create( + builder.getUnknownLoc(), treeId, IDefineCode::Decl, readOnly, addressable, used, uid, initial, name, +@@ -1712,11 +1712,11 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId) + treeId, IDefineCode::UNDEF, readOnly, rPluginType); + break; + } +- llvm::Optional vars = TreeToValue((uint64_t)BLOCK_VARS(t)); +- llvm::Optional supercontext = (uint64_t)BLOCK_SUPERCONTEXT(t); +- llvm::Optional subblocks = TreeToValue((uint64_t)BLOCK_SUBBLOCKS(t)); +- llvm::Optional chain = TreeToValue((uint64_t)BLOCK_CHAIN(t)); +- llvm::Optional abstract_origin = TreeToValue((uint64_t)BLOCK_ABSTRACT_ORIGIN(t)); ++ std::optional vars = TreeToValue((uint64_t)BLOCK_VARS(t)); ++ std::optional supercontext = (uint64_t)BLOCK_SUPERCONTEXT(t); ++ std::optional subblocks = TreeToValue((uint64_t)BLOCK_SUBBLOCKS(t)); ++ std::optional chain = TreeToValue((uint64_t)BLOCK_CHAIN(t)); ++ std::optional abstract_origin = TreeToValue((uint64_t)BLOCK_ABSTRACT_ORIGIN(t)); + GetTreeAttr(treeId, readOnly, rPluginType); + opValue = builder.create( + builder.getUnknownLoc(), treeId, IDefineCode::BLOCK, readOnly, vars, supercontext, subblocks, +-- +2.33.0 + diff --git a/pin-gcc-client.spec b/pin-gcc-client.spec index dd2ea3ef508df7b957aa8f800198311e33e8360c..f73e6b0a074676d2aa4138a3ee39f552cad5c0d8 100644 --- a/pin-gcc-client.spec +++ b/pin-gcc-client.spec @@ -1,6 +1,6 @@ Name: pin-gcc-client Version: 0.4.1 -Release: 12 +Release: 14 Summary: A Pin (Plug-IN framework) client is implemented based on GCC plugin and can execute the compiler optimization pass in GCC. License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD URL: https://gitee.com/src-openeuler/pin-gcc-client @@ -22,6 +22,9 @@ Patch9: 0009-Pin-gcc-client-Fix-TreeToValue-VAR_DECL-and-ARRAY_TY.patch Patch10: 0010-PluginClient-Fix-the-bug-during-multi-process-compil.patch Patch11: 0011-Pin-gcc-client-Adaptation-to-llvm15-mlir15-only-solv.patch Patch12: 0012-Pin-gcc-client-Adaptation-to-gcc12-only-solves-the-b.patch +Patch13: 0013-pin-gcc-client-Add-DataFlow-APIs.patch +Patch14: 0014-PluginClient-Bugfix-for-semaphore-exception-and-port.patch +Patch15: 0015-MLIR17-Adaptation-to-llvm17-mlir17.patch %description A Pin (Plug-IN framework) client is implemented based on GCC plugin and can execute the compiler optimization pass in GCC. @@ -54,13 +57,25 @@ find %{buildroot} -type f -name "*.so" -exec strip "{}" ";" %license LICENSE %attr(0755,root,root) %{_libdir}/libpin_gcc_client.so %attr(0755,root,root) %{_libdir}/libMLIRClientAPI.so -%attr(0755,root,root) %{_libdir}/libMLIRClientAPI.so.15 +%attr(0755,root,root) %{_libdir}/libMLIRClientAPI.so.17 %attr(0755,root,root) %{_libdir}/libMLIRPlugin.so -%attr(0755,root,root) %{_libdir}/libMLIRPlugin.so.15 +%attr(0755,root,root) %{_libdir}/libMLIRPlugin.so.17 %attr(0644,root,root) %{_bindir}/pin-gcc-client.json %config(noreplace) /etc/ld.so.conf.d/%{name}-%{_arch}.conf %changelog +* Wed Apr 10 2024 wumingchuan - 0.4.1-14 +- Type:Update +- ID:NA +- SUG:NA +- DESC:Adaptation to llvm17/mlir17. + +* Wed Apr 10 2024 wumingchuan - 0.4.1-13 +- Type:Update +- ID:NA +- SUG:NA +- DESC:Sync patch from openEuler/pin-gcc-client + * Tue Aug 22 2023 liyunfei - 0.4.1-12 - Type:FIX - ID:NA