!18 [sync] PR-16: [sync] Sync patch from openEuler/pin-server

From: @openeuler-sync-bot 
Reviewed-by: @li-yancheng 
Signed-off-by: @li-yancheng
This commit is contained in:
openeuler-ci-bot 2023-02-27 03:10:26 +00:00 committed by Gitee
commit 9108c8e317
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 7703 additions and 3 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,127 @@
From b14803116c8488a4c765799fd31966991f2031d7 Mon Sep 17 00:00:00 2001
From: benniaobufeijiushiji <linda7@huawei.com>
Date: Sun, 19 Feb 2023 11:43:57 +0800
Subject: [PATCH 4/9] [Pin-server] Add DebugOp
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index 2af4a33..f4062ad 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -82,8 +82,8 @@ def LoopOp : Plugin_Op<"loop", [NoSideEffect]> {
let extraClassDeclaration = [{
mlir::Block* GetHeader();
mlir::Block* GetLatch();
- void SetHeader(mlir::Block*);
- void SetLatch(mlir::Block*);
+ void SetHeader(mlir::Block*);
+ void SetLatch(mlir::Block*);
std::pair<mlir::Block*, mlir::Block*> GetSingleExit();
void Delete();
LoopOp GetInnerLoop();
@@ -247,7 +247,7 @@ def SSAOp : SSA<"SSA"> {
Value Copy();
Value GetCurrentDef();
bool SetCurrentDef(Value def);
- Operation* GetSSADefOperation();
+ Operation* GetSSADefOperation();
}];
}
@@ -274,6 +274,16 @@ def BaseOp : Plugin_Op<"statement_base", [NoSideEffect]> {
];
}
+def DebugOp : Plugin_Op<"debug", [NoSideEffect]> {
+ let summary = "DebugOp.";
+ let description = [{TODO}];
+ let arguments = (ins UI64Attr:$id);
+ let results = (outs AnyType);
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id)>
+ ];
+}
+
// Terminators
// Opaque builder used for terminator operations that contain successors.
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index a0591b5..a49ce16 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -549,6 +549,15 @@ void BaseOp::build(OpBuilder &builder, OperationState &state,
state.addAttribute("opCode", builder.getStringAttr(opCode));
}
+//===----------------------------------------------------------------------===//
+// DebugOp
+
+void DebugOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+}
+
// ===----------------------------------------------------------------------===//
// FallThroughOp
diff --git a/lib/PluginServer/PluginJson.cpp b/lib/PluginServer/PluginJson.cpp
index c399aad..d89945c 100755
--- a/lib/PluginServer/PluginJson.cpp
+++ b/lib/PluginServer/PluginJson.cpp
@@ -196,6 +196,9 @@ bool PluginJson::ProcessBlock(mlir::Block* block, mlir::Region& rg, const Json::
RetOpJsonDeSerialize(opJson.toStyledString());
} else if (opCode == FallThroughOp::getOperationName().str()) {
FallThroughOpJsonDeSerialize(opJson.toStyledString());
+ } else if (opCode == DebugOp::getOperationName().str()) {
+ uint64_t opID = GetID(opJson["id"]);
+ opBuilder->create<DebugOp>(opBuilder->getUnknownLoc(), opID);
} else if (opCode == BaseOp::getOperationName().str()) {
uint64_t opID = GetID(opJson["id"]);
opBuilder->create<BaseOp>(opBuilder->getUnknownLoc(), opID, opCode);
@@ -603,6 +606,10 @@ void PluginJson::OpJsonDeSerialize(
opData.push_back(RetOpJsonDeSerialize(opJson.toStyledString()));
} else if (opCode == FallThroughOp::getOperationName().str()) {
opData.push_back(FallThroughOpJsonDeSerialize(opJson.toStyledString()));
+ } else if (opCode == DebugOp::getOperationName().str()) {
+ uint64_t opID = GetID(opJson["id"]);
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ opBuilder->create<DebugOp>(opBuilder->getUnknownLoc(), opID);
} else if (opCode == BaseOp::getOperationName().str()) {
uint64_t opID = GetID(opJson["id"]);
mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
diff --git a/user.cpp b/user.cpp
index a6fe555..8163cec 100644
--- a/user.cpp
+++ b/user.cpp
@@ -318,7 +318,7 @@ struct originLoopInfo {
Value *limitptr;
Value arr1; /* Array 1 in the old loop. */
Value *arr1ptr;
- Value arr2; /* Array 2 in the old loop. */
+ Value arr2; /* Array 2 in the old loop. */
Value *arr2ptr;
edge entryEdge; /* The edge into the old loop. */
edgePtr entryEdgePtr;
@@ -646,7 +646,7 @@ static bool getIvBase(CondOp cond)
original loop; When prolog_assign is present, make sure loop header is in
simple form; And the interpretation of prolog_assign is as follows:
eg: while (++len != limit)
- ......
+ ......
For such a loop, ++len will be processed before entering header_bb, and the
assign is regarded as the prolog_assign of the loop. */
static bool recordOriginLoopHeader(LoopOp loop)
@@ -665,6 +665,9 @@ static bool recordOriginLoopHeader(LoopOp loop)
continue;
}
+ if (auto debugOp = dyn_cast<DebugOp>(op))
+ continue;
+
if (auto cond = dyn_cast<CondOp>(op)) {
if (!getIvUpperBound(cond)) {
return false;
--
2.27.0.windows.1

View File

@ -0,0 +1,60 @@
From 47f1208aab2acb3e1a8442d830125ad3b54149c5 Mon Sep 17 00:00:00 2001
From: benniaobufeijiushiji <linda7@huawei.com>
Date: Sun, 19 Feb 2023 14:40:09 +0800
Subject: [PATCH 5/9] [Pin-server] Add API for LTO judgement
diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h
index 0ca0ac4..f83b888 100644
--- a/include/PluginAPI/BasicPluginOpsAPI.h
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
@@ -70,6 +70,8 @@ public:
virtual uint32_t AddArgInPhiOp(uint64_t, uint64_t, uint64_t, uint64_t) = 0;
virtual PhiOp CreatePhiOp(uint64_t, uint64_t) = 0;
virtual void DebugValue(uint64_t) = 0;
+ virtual bool IsLtoOptimize() = 0;
+ virtual bool IsWholeProgram() = 0;
virtual mlir::Value GetCurrentDefFromSSA(uint64_t) = 0;
virtual bool SetCurrentDefInSSA(uint64_t, uint64_t) = 0;
diff --git a/include/PluginAPI/PluginServerAPI.h b/include/PluginAPI/PluginServerAPI.h
index 0655d80..b2f8fbf 100644
--- a/include/PluginAPI/PluginServerAPI.h
+++ b/include/PluginAPI/PluginServerAPI.h
@@ -74,6 +74,8 @@ public:
/* Plugin API for ConstOp. */
mlir::Value CreateConstOp(mlir::Attribute, mlir::Type) override;
void DebugValue(uint64_t) override;
+ bool IsLtoOptimize() override;
+ bool IsWholeProgram() override;
mlir::Value GetCurrentDefFromSSA(uint64_t) override;
bool SetCurrentDefInSSA(uint64_t, uint64_t) override;
diff --git a/lib/PluginAPI/PluginServerAPI.cpp b/lib/PluginAPI/PluginServerAPI.cpp
index 523e08d..f81a3ad 100644
--- a/lib/PluginAPI/PluginServerAPI.cpp
+++ b/lib/PluginAPI/PluginServerAPI.cpp
@@ -587,4 +587,20 @@ void PluginServerAPI::DebugValue(uint64_t valId)
PluginServer::GetInstance()->RemoteCallClientWithAPI(funName, params);
}
+bool PluginServerAPI::IsLtoOptimize()
+{
+ Json::Value root;
+ string funName = __func__;
+ string params = root.toStyledString();
+ return PluginServer::GetInstance()->GetBoolResult(funName, params);
+}
+
+bool PluginServerAPI::IsWholeProgram()
+{
+ Json::Value root;
+ string funName = __func__;
+ string params = root.toStyledString();
+ return PluginServer::GetInstance()->GetBoolResult(funName, params);
+}
+
} // namespace Plugin_IR
--
2.27.0.windows.1

View File

@ -0,0 +1,105 @@
From 5be0d63fe19decadaebb012efeb03b75aa868228 Mon Sep 17 00:00:00 2001
From: Mingchuan Wu <wumingchuan1992@foxmail.com>
Date: Tue, 21 Feb 2023 16:52:39 +0800
Subject: [PATCH 6/9] [Pin-server] Fix bug for BuildCallOp. Now we can convert
the function pointer.
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index f4062ad..3a88846 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -107,11 +107,13 @@ def CallOp : Plugin_Op<"call", [
The arguments list must match the arguments expected by the callee.
}];
let arguments = (ins UI64Attr:$id,
- FlatSymbolRefAttr:$callee,
+ OptionalAttr<FlatSymbolRefAttr>:$callee,
Variadic<AnyType>:$inputs);
let builders = [
OpBuilderDAG<(ins "int64_t":$id, "StringRef":$callee,
"ArrayRef<Value>":$arguments)>,
+ OpBuilderDAG<(ins "int64_t":$id,
+ "ArrayRef<Value>":$arguments)>,
// Only for server.
OpBuilderDAG<(ins "Value":$func,
"ArrayRef<Value>":$arguments, "Block *":$block)>,
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index a49ce16..a30e9ed 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -357,6 +357,13 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
state.addAttribute("callee", builder.getSymbolRefAttr(callee));
}
+void CallOp::build(OpBuilder &builder, OperationState &state,
+ int64_t id, ArrayRef<Value> arguments)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addOperands(arguments);
+}
+
/// Return the callee of the generic call operation, this is required by the
/// call interface.
CallInterfaceCallable CallOp::getCallableForCallee()
diff --git a/lib/PluginServer/PluginJson.cpp b/lib/PluginServer/PluginJson.cpp
index d89945c..7bbf681 100755
--- a/lib/PluginServer/PluginJson.cpp
+++ b/lib/PluginServer/PluginJson.cpp
@@ -467,10 +467,16 @@ mlir::Operation *PluginJson::CallOpJsonDeSerialize(const string& data)
ops.push_back(opValue);
}
int64_t id = GetID(node["id"]);
- mlir::StringRef callName(node["callee"].asString());
mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
- CallOp op = opBuilder->create<CallOp>(opBuilder->getUnknownLoc(),
- id, callName, ops);
+ Json::Value calleeJson = node["callee"];
+ CallOp op;
+ if (calleeJson.isNull()) {
+ op = opBuilder->create<CallOp>(opBuilder->getUnknownLoc(), id, ops);
+ } else {
+ mlir::StringRef callName(calleeJson.asString());
+ op = opBuilder->create<CallOp>(opBuilder->getUnknownLoc(),
+ id, callName, ops);
+ }
return op.getOperation();
}
diff --git a/lib/PluginServer/PluginServer.cpp b/lib/PluginServer/PluginServer.cpp
index 05d0d3d..d2a1736 100644
--- a/lib/PluginServer/PluginServer.cpp
+++ b/lib/PluginServer/PluginServer.cpp
@@ -50,7 +50,7 @@ bool PluginServer::RegisterOpt(std::shared_ptr<PluginOptBase> optBase)
string name = "funcname" + std::to_string((uintptr_t)optBase.get());
userOpts[inject].push_back(RecordedOpt(name, optBase));
this->context = optBase->GetContext();
- mlir::OpBuilder opBuilder_temp = mlir::OpBuilder(context);
+ static mlir::OpBuilder opBuilder_temp = mlir::OpBuilder(context);
opBuilder = &opBuilder_temp;
return true;
}
@@ -305,7 +305,7 @@ void PluginServer::RunServer()
ServerSemPost(port);
RegisterCallbacks();
- printf("RunServer: RegisterCallbacks Done.\n");
+ log->LOGI("RunServer: RegisterCallbacks Done.\n");
pluginCom.Run();
}
} // namespace PinServer
diff --git a/lib/PluginServer/main.cpp b/lib/PluginServer/main.cpp
index fac574e..333d55e 100644
--- a/lib/PluginServer/main.cpp
+++ b/lib/PluginServer/main.cpp
@@ -29,7 +29,6 @@ int main(int argc, char** argv)
printf("param num:%d, should be:%d\n", argc, argcNum);
return -1;
}
- printf("main arg: %s, %s\n", argv[0], argv[1]);
std::string port = argv[0];
LogPriority priority = (LogPriority)atoi(argv[1]);
PluginServer server(priority, port);
--
2.27.0.windows.1

View File

@ -0,0 +1,93 @@
From 1f800efcb93e2868f609c70584966b706ba13031 Mon Sep 17 00:00:00 2001
From: Mingchuan Wu <wumingchuan1992@foxmail.com>
Date: Tue, 21 Feb 2023 17:37:23 +0800
Subject: [PATCH 7/9] [Pin-server] Refactoring array-widen-compare into a
class.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a784df..4b2ab67 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -82,7 +82,7 @@ target_link_libraries(plg_grpc_proto
add_subdirectory(include)
add_subdirectory(lib)
-add_library(pin_user SHARED "user.cpp")
+add_library(pin_user SHARED "user/ArrayWidenPass.cpp")
target_link_libraries(pin_user
MLIRServerAPI
)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 7b0c8c4..6bc2859 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -5,9 +5,9 @@ add_mlir_library(MLIRServerAPI
DEPENDS
MLIRPluginOpsIncGen
- MLIRPlugin
+ MLIRPluginServer
LINK_LIBS PUBLIC
MLIRIR
- MLIRPlugin
+ MLIRPluginServer
)
\ No newline at end of file
diff --git a/lib/Dialect/CMakeLists.txt b/lib/Dialect/CMakeLists.txt
index ca912e9..8627cdd 100644
--- a/lib/Dialect/CMakeLists.txt
+++ b/lib/Dialect/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_mlir_dialect_library(MLIRPlugin
+add_mlir_dialect_library(MLIRPluginServer
PluginTypes.cpp
PluginDialect.cpp
PluginOps.cpp
diff --git a/user.cpp b/user/ArrayWidenPass.cpp
similarity index 100%
rename from user.cpp
rename to user/ArrayWidenPass.cpp
diff --git a/user/user.cpp b/user/user.cpp
new file mode 100644
index 0000000..bee70bb
--- /dev/null
+++ b/user/user.cpp
@@ -0,0 +1,33 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the implementation of the User Init.
+*/
+
+#include "PluginAPI/PluginServerAPI.h"
+#include "user/ArrayWidenPass.h"
+#include "user/InlineFunctionPass.h"
+#include "user/LocalVarSummeryPass.h"
+
+void RegisterCallbacks(void)
+{
+ PinServer::PluginServer *pluginServer = PinServer::PluginServer::GetInstance();
+ pluginServer->RegisterOpt(std::make_shared<PluginOpt::InlineFunctionPass>(PluginOpt::HANDLE_BEFORE_IPA));
+ pluginServer->RegisterOpt(std::make_shared<PluginOpt::LocalVarSummeryPass>(PluginOpt::HANDLE_AFTER_IPA));
+ PluginOpt::ManagerSetup setupData(PluginOpt::PASS_PHIOPT, 1, PluginOpt::PASS_INSERT_AFTER);
+ pluginServer->RegisterPassManagerOpt(setupData, std::make_shared<PluginOpt::ArrayWidenPass>());
+}
--
2.27.0.windows.1

View File

@ -0,0 +1,442 @@
From 2942cf7b6cdbea40735d5574e21d34d9f665a1fd Mon Sep 17 00:00:00 2001
From: Mingchuan Wu <wumingchuan1992@foxmail.com>
Date: Tue, 21 Feb 2023 17:45:30 +0800
Subject: [PATCH 8/9] [Pin-server] Refactoring DEMOs into PluginOpt classes.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4b2ab67..1cfb776 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -82,7 +82,12 @@ target_link_libraries(plg_grpc_proto
add_subdirectory(include)
add_subdirectory(lib)
-add_library(pin_user SHARED "user/ArrayWidenPass.cpp")
+add_library(pin_user SHARED
+ "user/ArrayWidenPass.cpp"
+ "user/InlineFunctionPass.cpp"
+ "user/LocalVarSummeryPass.cpp"
+ "user/user.cpp")
+
target_link_libraries(pin_user
MLIRServerAPI
)
diff --git a/include/user/ArrayWidenPass.h b/include/user/ArrayWidenPass.h
new file mode 100755
index 0000000..38c692d
--- /dev/null
+++ b/include/user/ArrayWidenPass.h
@@ -0,0 +1,45 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the ArrayWidenPass class.
+*/
+
+#ifndef ARRAYWIDEN_PASS_H
+#define ARRAYWIDEN_PASS_H
+
+#include "PluginServer/PluginOptBase.h"
+
+namespace PluginOpt {
+class ArrayWidenPass : public PluginOptBase {
+public:
+ ArrayWidenPass() : PluginOptBase(HANDLE_MANAGER_SETUP)
+ {
+ }
+ bool Gate()
+ {
+ return true;
+ }
+ int DoOptimize()
+ {
+ uint64_t *fun = (uint64_t *)GetFuncAddr();
+ return DoOptimize(fun);
+ }
+ int DoOptimize(uint64_t *fun);
+};
+}
+
+#endif
diff --git a/include/user/InlineFunctionPass.h b/include/user/InlineFunctionPass.h
new file mode 100755
index 0000000..b2dad9f
--- /dev/null
+++ b/include/user/InlineFunctionPass.h
@@ -0,0 +1,40 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the InlineFunctionPass class.
+*/
+
+#ifndef INLINEFUNCTION_PASS_H
+#define INLINEFUNCTION_PASS_H
+
+#include "PluginServer/PluginOptBase.h"
+
+namespace PluginOpt {
+class InlineFunctionPass : public PluginOptBase {
+public:
+ InlineFunctionPass(InjectPoint inject) : PluginOptBase(inject)
+ {
+ }
+ bool Gate()
+ {
+ return true;
+ }
+ int DoOptimize();
+};
+}
+
+#endif
diff --git a/include/user/LocalVarSummeryPass.h b/include/user/LocalVarSummeryPass.h
new file mode 100755
index 0000000..760cb25
--- /dev/null
+++ b/include/user/LocalVarSummeryPass.h
@@ -0,0 +1,40 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the declaration of the LocalVarSummeryPass pass.
+*/
+
+#ifndef LOCALVAR_SUMMERY_H
+#define LOCALVAR_SUMMERY_H
+
+#include "PluginServer/PluginOptBase.h"
+
+namespace PluginOpt {
+class LocalVarSummeryPass : public PluginOptBase {
+public:
+ LocalVarSummeryPass(InjectPoint inject) : PluginOptBase(inject)
+ {
+ }
+ bool Gate()
+ {
+ return true;
+ }
+ int DoOptimize();
+};
+}
+
+#endif
diff --git a/user/ArrayWidenPass.cpp b/user/ArrayWidenPass.cpp
index 8163cec..162fdc9 100644
--- a/user/ArrayWidenPass.cpp
+++ b/user/ArrayWidenPass.cpp
@@ -15,7 +15,7 @@
Author: Mingchuan Wu and Yancheng Li
Create: 2022-08-18
Description:
- This file contains the implementation of the User Init.
+ This file contains the implementation of the ArrayWidenPass class.
*/
#include <iostream>
@@ -27,7 +27,7 @@
#include "PluginAPI/PluginServerAPI.h"
#include "PluginServer/PluginLog.h"
#include "PluginAPI/ControlFlowAPI.h"
-#include "PluginServer/PluginOptBase.h"
+#include "user/ArrayWidenPass.h"
namespace PluginOpt {
using std::string;
@@ -318,7 +318,7 @@ struct originLoopInfo {
Value *limitptr;
Value arr1; /* Array 1 in the old loop. */
Value *arr1ptr;
- Value arr2; /* Array 2 in the old loop. */
+ Value arr2; /* Array 2 in the old loop. */
Value *arr2ptr;
edge entryEdge; /* The edge into the old loop. */
edgePtr entryEdgePtr;
@@ -438,7 +438,7 @@ static bool checkCondOp(Operation *op)
/* Record the exit information in the original loop including exit edge,
exit bb block, exit condition stmt,
- eg: exitEX originLoop.exitBBX condOpX. */
+ eg: exit_eX origin_exit_bbX cond_stmtX. */
static bool recordOriginLoopExitInfo(LoopOp loop)
{
@@ -510,7 +510,7 @@ static edge getLoopPreheaderEdge(LoopOp loop)
return e;
}
-/* Returns true if t is SSAOp and user variable exists. */
+/* Returns true if t is SSA_NAME and user variable exists. */
static bool isSSANameVar(Value v)
{
@@ -525,7 +525,7 @@ static bool isSSANameVar(Value v)
return false;
}
-/* Returns true if t1 and t2 are SSAOp and belong to the same variable. */
+/* Returns true if t1 and t2 are SSA_NAME and belong to the same variable. */
static bool isSameSSANameVar(Value v1, Value v2)
{
@@ -565,9 +565,9 @@ static bool getIvUpperBound(CondOp cond)
return false;
}
-/* Returns true only when the expression on the rhs code of stmt is PLUS,
- rhs1 is SSAOp with the same var as originLoop base, and rhs2 is
- ConstOp. */
+/* Returns true only when the expression on the rhs code of stmt is PLUS_EXPR,
+ rhs1 is SSA_NAME with the same var as originLoop base, and rhs2 is
+ INTEGER_CST. */
static bool checkUpdateStmt(Operation *op)
{
if (!op || !isa<AssignOp>(op)) {
@@ -646,7 +646,7 @@ static bool getIvBase(CondOp cond)
original loop; When prolog_assign is present, make sure loop header is in
simple form; And the interpretation of prolog_assign is as follows:
eg: while (++len != limit)
- ......
+ ......
For such a loop, ++len will be processed before entering header_bb, and the
assign is regarded as the prolog_assign of the loop. */
static bool recordOriginLoopHeader(LoopOp loop)
@@ -665,9 +665,6 @@ static bool recordOriginLoopHeader(LoopOp loop)
continue;
}
- if (auto debugOp = dyn_cast<DebugOp>(op))
- continue;
-
if (auto cond = dyn_cast<CondOp>(op)) {
if (!getIvUpperBound(cond)) {
return false;
@@ -711,8 +708,8 @@ static bool recordOriginLoopLatch(LoopOp loop)
return false;
}
-/* Returns true when the define STMT corresponding to arg0 of the MemOp
- satisfies the PtrPlus type. */
+/* Returns true when the DEF_STMT corresponding to arg0 of the mem_ref tree
+ satisfies the POINTER_PLUS_EXPR type. */
static bool checkBodyMemRef(Value memRef)
{
if (getValueDefCode(memRef) != IDefineCode::MemRef) {
@@ -771,7 +768,7 @@ static bool checkBodyPointerPlus(Operation *op, Value &tmpIndex)
}
/* Record the array comparison information in the original loop, while ensuring
- that there are only statements related to cont stmt in the loop body. */
+ that there are only statements related to cont_stmt in the loop body. */
static bool recordOriginLoopBody(LoopOp loop)
{
Block *body = originLoop.condOp2->getBlock();
@@ -1559,33 +1556,9 @@ static void ProcessArrayWiden(void)
}
}
-class ArrayWidenPass : public PluginOptBase {
-public:
- ArrayWidenPass() : PluginOptBase(HANDLE_MANAGER_SETUP)
- {
- }
- bool Gate()
- {
- return true;
- }
- int DoOptimize()
- {
- uint64_t *fun = (uint64_t *)GetFuncAddr();
- return DoOptimize(fun);
- }
- int DoOptimize(uint64_t *fun);
-};
-
int ArrayWidenPass::DoOptimize(uint64_t *fun)
{
ProcessArrayWiden();
return 0;
}
}
-
-void RegisterCallbacks(void)
-{
- PinServer::PluginServer *pluginServer = PinServer::PluginServer::GetInstance();
- PluginOpt::ManagerSetup setupData(PluginOpt::PASS_PHIOPT, 1, PluginOpt::PASS_INSERT_AFTER);
- pluginServer->RegisterPassManagerOpt(setupData, std::make_shared<PluginOpt::ArrayWidenPass>());
-}
diff --git a/user/InlineFunctionPass.cpp b/user/InlineFunctionPass.cpp
new file mode 100755
index 0000000..d982d44
--- /dev/null
+++ b/user/InlineFunctionPass.cpp
@@ -0,0 +1,44 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the implementation of the inlineFunctionPass class.
+*/
+
+#include "PluginAPI/PluginServerAPI.h"
+#include "user/InlineFunctionPass.h"
+
+namespace PluginOpt {
+using namespace PluginAPI;
+
+static void UserOptimizeFunc(void)
+{
+ PluginServerAPI pluginAPI;
+ vector<FunctionOp> allFunction = pluginAPI.GetAllFunc();
+ int count = 0;
+ for (size_t i = 0; i < allFunction.size(); i++) {
+ if (allFunction[i].declaredInlineAttr().getValue())
+ count++;
+ }
+ printf("declaredInline have %d functions were declared.\n", count);
+}
+
+int InlineFunctionPass::DoOptimize()
+{
+ UserOptimizeFunc();
+ return 0;
+}
+}
diff --git a/user/LocalVarSummeryPass.cpp b/user/LocalVarSummeryPass.cpp
new file mode 100755
index 0000000..4fc4985
--- /dev/null
+++ b/user/LocalVarSummeryPass.cpp
@@ -0,0 +1,57 @@
+/* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+
+ Author: Mingchuan Wu and Yancheng Li
+ Create: 2022-08-18
+ Description:
+ This file contains the implementation of the LocalVarSummeryPass pass.
+*/
+
+#include "PluginAPI/ControlFlowAPI.h"
+#include "PluginAPI/PluginServerAPI.h"
+#include "user/LocalVarSummeryPass.h"
+
+namespace PluginOpt {
+using namespace PluginAPI;
+
+static void LocalVarSummery(void)
+{
+ PluginServerAPI pluginAPI;
+ vector<mlir::Plugin::FunctionOp> allFunction = pluginAPI.GetAllFunc();
+ map<string, string> args = PluginServer::GetInstance()->GetArgs();
+ for (size_t i = 0; i < allFunction.size(); i++) {
+ uint64_t funcID = allFunction[i].idAttr().getValue().getZExtValue();
+ printf("In the %ldth function:\n", i);
+ vector<mlir::Plugin::LocalDeclOp> decls = pluginAPI.GetDecls(funcID);
+ int64_t typeFilter = -1u;
+ if (args.find("type_code") != args.end()) {
+ typeFilter = (int64_t)pluginAPI.GetTypeCodeFromString(args["type_code"]);
+ }
+ for (size_t j = 0; j < decls.size(); j++) {
+ auto decl = decls[j];
+ string name = decl.symNameAttr().getValue().str();
+ int64_t declTypeID = decl.typeIDAttr().getValue().getZExtValue();
+ if (declTypeID == typeFilter) {
+ printf("\tFind %ldth target type %s\n", j, name.c_str());
+ }
+ }
+ }
+}
+
+int LocalVarSummeryPass::DoOptimize()
+{
+ LocalVarSummery();
+ return 0;
+}
+}
diff --git a/user/user.cpp b/user/user.cpp
index bee70bb..16f0687 100644
--- a/user/user.cpp
+++ b/user/user.cpp
@@ -27,7 +27,7 @@ void RegisterCallbacks(void)
{
PinServer::PluginServer *pluginServer = PinServer::PluginServer::GetInstance();
pluginServer->RegisterOpt(std::make_shared<PluginOpt::InlineFunctionPass>(PluginOpt::HANDLE_BEFORE_IPA));
- pluginServer->RegisterOpt(std::make_shared<PluginOpt::LocalVarSummeryPass>(PluginOpt::HANDLE_AFTER_IPA));
- PluginOpt::ManagerSetup setupData(PluginOpt::PASS_PHIOPT, 1, PluginOpt::PASS_INSERT_AFTER);
- pluginServer->RegisterPassManagerOpt(setupData, std::make_shared<PluginOpt::ArrayWidenPass>());
+ pluginServer->RegisterOpt(std::make_shared<PluginOpt::LocalVarSummeryPass>(PluginOpt::HANDLE_BEFORE_IPA));
+ // PluginOpt::ManagerSetup setupData(PluginOpt::PASS_PHIOPT, 1, PluginOpt::PASS_INSERT_AFTER);
+ // pluginServer->RegisterPassManagerOpt(setupData, std::make_shared<PluginOpt::ArrayWidenPass>());
}
--
2.27.0.windows.1

View File

@ -0,0 +1,566 @@
From e2a6f729f4ce40542fccec997529b43d25a6d5ae Mon Sep 17 00:00:00 2001
From: d00573793 <dingguangya1@huawei.com>
Date: Tue, 21 Feb 2023 21:53:44 +0800
Subject: [PATCH 9/9] [Pin-server] Support functiontype structtype.eg.
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index 3a88846..1083141 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -30,7 +30,8 @@ def FunctionOp : Plugin_Op<"function", [NoSideEffect]> {
let arguments = (ins UI64Attr:$id,
StrAttr:$funcName,
- OptionalAttr<BoolAttr>:$declaredInline);
+ OptionalAttr<BoolAttr>:$declaredInline,
+ TypeAttr:$type);
let regions = (region AnyRegion:$bodyRegion);
// Add custom build methods for the operation. These method populates
@@ -39,13 +40,15 @@ def FunctionOp : Plugin_Op<"function", [NoSideEffect]> {
let builders = [
OpBuilderDAG<(ins "uint64_t":$id,
"StringRef":$funcName,
- "bool":$declaredInline)>
+ "bool":$declaredInline,
+ "Type":$type)>
];
let extraClassDeclaration = [{
std::vector<LoopOp> GetAllLoops();
LoopOp AllocateNewLoop();
bool IsDomInfoAvailable();
+ Type getResultType();
}];
}
diff --git a/include/Dialect/PluginTypes.h b/include/Dialect/PluginTypes.h
index 7fb1ff9..3f7f14b 100644
--- a/include/Dialect/PluginTypes.h
+++ b/include/Dialect/PluginTypes.h
@@ -78,6 +78,9 @@ namespace detail {
struct PluginIntegerTypeStorage;
struct PluginFloatTypeStorage;
struct PluginPointerTypeStorage;
+ struct PluginTypeAndSizeStorage;
+ struct PluginFunctionTypeStorage;
+ struct PluginStructTypeStorage;
}
class PluginIntegerType : public Type::TypeBase<PluginIntegerType, PluginTypeBase, detail::PluginIntegerTypeStorage> {
@@ -128,6 +131,61 @@ public:
unsigned isReadOnlyElem();
}; // class PluginPointerType
+class PluginArrayType : public Type::TypeBase<PluginArrayType, PluginTypeBase, detail::PluginTypeAndSizeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static bool isValidElementType(Type type);
+
+ static PluginArrayType get(MLIRContext *context, Type elementType, unsigned numElements);
+
+ Type getElementType();
+
+ unsigned getNumElements();
+}; // class PluginArrayType
+
+class PluginFunctionType : public Type::TypeBase<PluginFunctionType, PluginTypeBase, detail::PluginFunctionTypeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static bool isValidArgumentType(Type type);
+
+ static bool isValidResultType(Type type);
+
+ static PluginFunctionType get(MLIRContext *context, Type result, ArrayRef<Type> arguments);
+
+ Type getReturnType();
+
+ unsigned getNumParams();
+
+ Type getParamType(unsigned i);
+
+ ArrayRef<Type> getParams();
+
+}; // class PluginFunctionType
+
+class PluginStructType : public Type::TypeBase<PluginStructType, PluginTypeBase, detail::PluginStructTypeStorage> {
+public:
+ using Base::Base;
+
+ PluginTypeID getPluginTypeID ();
+
+ static bool isValidElementType(Type type);
+
+ static PluginStructType get(MLIRContext *context, std::string name, ArrayRef<Type> elements, ArrayRef<std::string> elemNames);
+
+ std::string getName();
+
+ ArrayRef<Type> getBody();
+
+ ArrayRef<std::string> getElementNames();
+
+}; // class PluginStructType
+
class PluginVoidType : public Type::TypeBase<PluginVoidType, PluginTypeBase, TypeStorage> {
public:
using Base::Base;
diff --git a/include/PluginServer/PluginJson.h b/include/PluginServer/PluginJson.h
index 6f46187..fd2f05b 100755
--- a/include/PluginServer/PluginJson.h
+++ b/include/PluginServer/PluginJson.h
@@ -59,7 +59,7 @@ public:
/* 将json格式数据解析成map<string, string>格式 */
void GetAttributes(Json::Value node, map<string, string>& attributes);
mlir::Value ValueJsonDeSerialize(Json::Value valueJson);
- Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase& type);
+ Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase type);
mlir::Value MemRefDeSerialize(const string& data);
bool ProcessBlock(mlir::Block*, mlir::Region&, const Json::Value&);
};
diff --git a/lib/Dialect/PluginDialect.cpp b/lib/Dialect/PluginDialect.cpp
index 95b38cf..ba8e4fe 100644
--- a/lib/Dialect/PluginDialect.cpp
+++ b/lib/Dialect/PluginDialect.cpp
@@ -37,6 +37,9 @@ void PluginDialect::initialize()
PluginIR::PluginIntegerType,
PluginIR::PluginFloatType,
PluginIR::PluginPointerType,
+ PluginIR::PluginArrayType,
+ PluginIR::PluginFunctionType,
+ PluginIR::PluginStructType,
PluginIR::PluginBooleanType,
PluginIR::PluginVoidType,
PluginIR::PluginUndefType>();
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index a30e9ed..1c4fb2d 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -64,12 +64,19 @@ static uint64_t getBlockAddress(mlir::Block* b)
}
void FunctionOp::build(OpBuilder &builder, OperationState &state,
- uint64_t id, StringRef funcName, bool declaredInline)
+ uint64_t id, StringRef funcName, bool declaredInline, Type type)
{
- FunctionOp::build(builder, state,
- builder.getI64IntegerAttr(id),
- builder.getStringAttr(funcName),
- builder.getBoolAttr(declaredInline));
+ state.addRegion();
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("funcName", builder.getStringAttr(funcName));
+ state.addAttribute("declaredInline", builder.getBoolAttr(declaredInline));
+ if (type) state.addAttribute("type", TypeAttr::get(type));
+}
+
+Type FunctionOp::getResultType()
+{
+ PluginIR::PluginFunctionType resultType = type().dyn_cast<PluginIR::PluginFunctionType>();
+ return resultType;
}
vector<LoopOp> FunctionOp::GetAllLoops()
diff --git a/lib/Dialect/PluginTypes.cpp b/lib/Dialect/PluginTypes.cpp
index c0a58c2..337fc49 100644
--- a/lib/Dialect/PluginTypes.cpp
+++ b/lib/Dialect/PluginTypes.cpp
@@ -97,6 +97,80 @@ namespace detail {
Type pointee;
unsigned readOnlyPointee;
};
+
+ struct PluginTypeAndSizeStorage : public TypeStorage {
+ using KeyTy = std::tuple<Type, unsigned>;
+
+ PluginTypeAndSizeStorage(const KeyTy &key)
+ : elementType(std::get<0>(key)), numElements(std::get<1>(key)) {}
+
+ static PluginTypeAndSizeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
+ return new (allocator.allocate<PluginTypeAndSizeStorage>())
+ PluginTypeAndSizeStorage(key);
+ }
+
+ bool operator==(const KeyTy &key) const
+ {
+ return std::make_tuple(elementType, numElements) == key;
+ }
+
+ Type elementType;
+ unsigned numElements;
+ };
+
+ struct PluginFunctionTypeStorage : public TypeStorage {
+ using KeyTy = std::tuple<Type, ArrayRef<Type>>;
+
+ PluginFunctionTypeStorage(Type resultType, ArrayRef<Type> argumentTypes)
+ : resultType(resultType), argumentTypes(argumentTypes) {}
+
+ static PluginFunctionTypeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
+ return new (allocator.allocate<PluginFunctionTypeStorage>())
+ PluginFunctionTypeStorage(std::get<0>(key), allocator.copyInto(std::get<1>(key)));
+ }
+
+ static unsigned hashKey(const KeyTy &key) {
+ // LLVM doesn't like hashing bools in tuples.
+ return llvm::hash_combine(std::get<0>(key), std::get<1>(key));
+ }
+
+ bool operator==(const KeyTy &key) const
+ {
+ return std::make_tuple(resultType, argumentTypes) == key;
+ }
+
+ Type resultType;
+ ArrayRef<Type> argumentTypes;
+ };
+
+ struct PluginStructTypeStorage : public TypeStorage {
+ using KeyTy = std::tuple<std::string, ArrayRef<Type>, ArrayRef<std::string>>;
+
+ PluginStructTypeStorage(std::string name, ArrayRef<Type> elements, ArrayRef<std::string> elemNames)
+ : name(name), elements(elements), elemNames(elemNames) {}
+
+ static PluginStructTypeStorage *construct(TypeStorageAllocator &allocator, KeyTy key)
+ {
+ return new (allocator.allocate<PluginStructTypeStorage>())
+ PluginStructTypeStorage(std::get<0>(key), allocator.copyInto(std::get<1>(key)), allocator.copyInto(std::get<2>(key)));
+ }
+
+ static unsigned hashKey(const KeyTy &key) {
+ // LLVM doesn't like hashing bools in tuples.
+ return llvm::hash_combine(std::get<0>(key), std::get<1>(key), std::get<2>(key));
+ }
+
+ bool operator==(const KeyTy &key) const
+ {
+ return std::make_tuple(name, elements, elemNames) == key;
+ }
+
+ std::string name;
+ ArrayRef<Type> elements;
+ ArrayRef<std::string> elemNames;
+ };
}
}
@@ -122,6 +196,15 @@ PluginTypeID PluginTypeBase::getPluginTypeID ()
if (auto Ty = dyn_cast<PluginIR::PluginPointerType>()) {
return Ty.getPluginTypeID ();
}
+ if (auto Ty = dyn_cast<PluginIR::PluginArrayType>()) {
+ return Ty.getPluginTypeID ();
+ }
+ if (auto Ty = dyn_cast<PluginIR::PluginFunctionType>()) {
+ return Ty.getPluginTypeID ();
+ }
+ if (auto Ty = dyn_cast<PluginIR::PluginStructType>()) {
+ return Ty.getPluginTypeID ();
+ }
return PluginTypeID::UndefTyID;
}
@@ -292,4 +375,108 @@ unsigned PluginPointerType::isReadOnlyElem()
PluginPointerType PluginPointerType::get (MLIRContext *context, Type pointee, unsigned readOnlyPointee)
{
return Base::get(context, pointee, readOnlyPointee);
+}
+
+// ===----------------------------------------------------------------------===//
+// Plugin Array Type
+// ===----------------------------------------------------------------------===//
+
+PluginTypeID PluginArrayType::getPluginTypeID()
+{
+ return PluginTypeID::ArrayTyID;
+}
+
+bool PluginArrayType::isValidElementType(Type type)
+{
+ return !type.isa<PluginVoidType, PluginFunctionType, PluginUndefType>();
+}
+
+PluginArrayType PluginArrayType::get(MLIRContext *context, Type elementType, unsigned numElements)
+{
+ return Base::get(context, elementType, numElements);
+}
+
+Type PluginArrayType::getElementType()
+{
+ return getImpl()->elementType;
+}
+
+unsigned PluginArrayType::getNumElements()
+{
+ return getImpl()->numElements;
+}
+
+// ===----------------------------------------------------------------------===//
+// Plugin Function Type
+// ===----------------------------------------------------------------------===//
+
+PluginTypeID PluginFunctionType::getPluginTypeID()
+{
+ return PluginTypeID::FunctionTyID;
+}
+
+bool PluginFunctionType::isValidArgumentType(Type type)
+{
+ return !type.isa<PluginVoidType, PluginFunctionType>();
+}
+
+bool PluginFunctionType::isValidResultType(Type type) {
+ return !type.isa<PluginFunctionType>();
+}
+
+PluginFunctionType PluginFunctionType::get(MLIRContext *context, Type result, ArrayRef<Type> arguments)
+{
+ return Base::get(context, result, arguments);
+}
+
+Type PluginFunctionType::getReturnType()
+{
+ return getImpl()->resultType;
+}
+
+unsigned PluginFunctionType::getNumParams()
+{
+ return getImpl()->argumentTypes.size();
+}
+
+Type PluginFunctionType::getParamType(unsigned i) {
+ return getImpl()->argumentTypes[i];
+}
+
+ArrayRef<Type> PluginFunctionType::getParams()
+{
+ return getImpl()->argumentTypes;
+}
+
+// ===----------------------------------------------------------------------===//
+// Plugin Struct Type
+// ===----------------------------------------------------------------------===//
+
+PluginTypeID PluginStructType::getPluginTypeID()
+{
+ return PluginTypeID::StructTyID;
+}
+
+bool PluginStructType::isValidElementType(Type type) {
+ return !type.isa<PluginVoidType, PluginFunctionType>();
+}
+
+PluginStructType PluginStructType::get(MLIRContext *context, std::string name, ArrayRef<Type> elements, ArrayRef<std::string> elemNames)
+{
+ return Base::get(context, name, elements, elemNames);
+}
+
+std::string PluginStructType::getName()
+{
+ return getImpl()->name;
+}
+
+ArrayRef<Type> PluginStructType::getBody()
+{
+ return getImpl()->elements;
+}
+
+ArrayRef<std::string> PluginStructType::getElementNames()
+{
+ return getImpl()->elemNames;
}
\ No newline at end of file
diff --git a/lib/PluginAPI/PluginServerAPI.cpp b/lib/PluginAPI/PluginServerAPI.cpp
index f81a3ad..e3435b0 100644
--- a/lib/PluginAPI/PluginServerAPI.cpp
+++ b/lib/PluginAPI/PluginServerAPI.cpp
@@ -343,6 +343,14 @@ PluginIR::PluginTypeID PluginServerAPI::GetTypeCodeFromString(string type)
return PluginIR::PluginTypeID::FloatTyID;
} else if (type == "DoubleTy") {
return PluginIR::PluginTypeID::DoubleTyID;
+ } else if (type == "PointerTy") {
+ return PluginIR::PluginTypeID::PointerTyID;
+ } else if (type == "ArrayTy") {
+ return PluginIR::PluginTypeID::ArrayTyID;
+ } else if (type == "FunctionTy") {
+ return PluginIR::PluginTypeID::FunctionTyID;
+ } else if (type == "StructTy") {
+ return PluginIR::PluginTypeID::StructTyID;
}
return PluginIR::PluginTypeID::UndefTyID;
diff --git a/lib/PluginServer/PluginJson.cpp b/lib/PluginServer/PluginJson.cpp
index 7bbf681..e1beddf 100755
--- a/lib/PluginServer/PluginJson.cpp
+++ b/lib/PluginServer/PluginJson.cpp
@@ -23,6 +23,7 @@
namespace PinJson {
using namespace PinServer;
+using namespace mlir;
using namespace mlir::Plugin;
static uintptr_t GetID(Json::Value node)
@@ -41,7 +42,7 @@ static void JsonGetAttributes(Json::Value node, map<string, string>& attributes)
}
}
-Json::Value PluginJson::TypeJsonSerialize (PluginIR::PluginTypeBase& type)
+Json::Value PluginJson::TypeJsonSerialize (PluginIR::PluginTypeBase type)
{
Json::Value root;
Json::Value operationObj;
@@ -53,6 +54,41 @@ Json::Value PluginJson::TypeJsonSerialize (PluginIR::PluginTypeBase& type)
ReTypeId = static_cast<uint64_t>(type.getPluginTypeID());
item["id"] = std::to_string(ReTypeId);
+ if (auto Ty = type.dyn_cast<PluginIR::PluginStructType>()) {
+ std::string tyName = Ty.getName();
+ item["structtype"] = tyName;
+ size_t paramIndex = 0;
+ ArrayRef<Type> paramsType = Ty.getBody();
+ for (auto ty :paramsType) {
+ std::string paramStr = "elemType" + std::to_string(paramIndex++);
+ item["structelemType"][paramStr] = TypeJsonSerialize(ty.dyn_cast<PluginIR::PluginTypeBase>());
+ }
+ paramIndex = 0;
+ ArrayRef<std::string> paramsNames = Ty.getElementNames();
+ for (auto name :paramsNames) {
+ std::string paramStr = "elemName" + std::to_string(paramIndex++);
+ item["structelemName"][paramStr] = name;
+ }
+ }
+
+ if (auto Ty = type.dyn_cast<PluginIR::PluginFunctionType>()) {
+ auto fnrestype = Ty.getReturnType().dyn_cast<PluginIR::PluginTypeBase>();
+ item["fnreturntype"] = TypeJsonSerialize(fnrestype);
+ size_t paramIndex = 0;
+ ArrayRef<Type> paramsType = Ty.getParams();
+ for (auto ty : Ty.getParams()) {
+ string paramStr = "argType" + std::to_string(paramIndex++);
+ item["fnargsType"][paramStr] = TypeJsonSerialize(ty.dyn_cast<PluginIR::PluginTypeBase>());
+ }
+ }
+
+ if (auto Ty = type.dyn_cast<PluginIR::PluginArrayType>()) {
+ auto elemTy = Ty.getElementType().dyn_cast<PluginIR::PluginTypeBase>();
+ item["elementType"] = TypeJsonSerialize(elemTy);
+ uint64_t elemNum = Ty.getNumElements();
+ item["arraysize"] = std::to_string(elemNum);
+ }
+
if (auto elemTy = type.dyn_cast<PluginIR::PluginPointerType>()) {
auto baseTy = elemTy.getElementType().dyn_cast<PluginIR::PluginTypeBase>();
item["elementType"] = TypeJsonSerialize(baseTy);
@@ -247,8 +283,9 @@ void PluginJson::FuncOpJsonDeSerialize(
bool declaredInline = false;
if (funcAttributes["declaredInline"] == "1") declaredInline = true;
auto location = opBuilder.getUnknownLoc();
+ PluginIR::PluginTypeBase retType = TypeJsonDeSerialize(node["retType"].toStyledString());
FunctionOp fOp = opBuilder.create<FunctionOp>(
- location, id, funcAttributes["funcName"], declaredInline);
+ location, id, funcAttributes["funcName"], declaredInline, retType);
mlir::Region &bodyRegion = fOp.bodyRegion();
Json::Value regionJson = node["region"];
Json::Value::Members bbMember = regionJson.getMemberNames();
@@ -302,7 +339,40 @@ PluginIR::PluginTypeBase PluginJson::TypeJsonDeSerialize(const string& data)
mlir::Type elemTy = TypeJsonDeSerialize(type["elementType"].toStyledString());
baseType = PluginIR::PluginPointerType::get(
PluginServer::GetInstance()->GetContext(), elemTy, type["elemConst"].asString() == "1" ? 1 : 0);
- } else {
+ } else if (id == static_cast<uint64_t>(PluginIR::ArrayTyID)) {
+ mlir::Type elemTy = TypeJsonDeSerialize(type["elementType"].toStyledString());
+ uint64_t elemNum = GetID(type["arraysize"]);
+ baseType = PluginIR::PluginArrayType::get(PluginServer::GetInstance()->GetContext(), elemTy, elemNum);
+ } else if (id == static_cast<uint64_t>(PluginIR::FunctionTyID)) {
+ mlir::Type returnTy = TypeJsonDeSerialize(type["fnreturntype"].toStyledString());
+ llvm::SmallVector<Type> typelist;
+ Json::Value::Members fnTypeNum = type["fnargsType"].getMemberNames();
+ uint64_t argsNum = fnTypeNum.size();
+ for (size_t paramIndex = 0; paramIndex < argsNum; paramIndex++) {
+ string Key = "argType" + std::to_string(paramIndex);
+ mlir::Type paramTy = TypeJsonDeSerialize(type["fnargsType"][Key].toStyledString());
+ typelist.push_back(paramTy);
+ }
+ baseType = PluginIR::PluginFunctionType::get(PluginServer::GetInstance()->GetContext(), returnTy, typelist);
+ } else if (id == static_cast<uint64_t>(PluginIR::StructTyID)) {
+ std::string tyName = type["structtype"].asString();
+ llvm::SmallVector<Type> typelist;
+ Json::Value::Members elemTypeNum = type["structelemType"].getMemberNames();
+ for (size_t paramIndex = 0; paramIndex < elemTypeNum.size(); paramIndex++) {
+ string Key = "elemType" + std::to_string(paramIndex);
+ mlir::Type paramTy = TypeJsonDeSerialize(type["structelemType"][Key].toStyledString());
+ typelist.push_back(paramTy);
+ }
+ llvm::SmallVector<std::string> names;
+ Json::Value::Members elemNameNum = type["structelemName"].getMemberNames();
+ for (size_t paramIndex = 0; paramIndex < elemTypeNum.size(); paramIndex++) {
+ std::string Key = "elemName" + std::to_string(paramIndex);
+ std::string elemName = type["structelemName"][Key].asString();
+ names.push_back(elemName);
+ }
+ baseType = PluginIR::PluginStructType::get(PluginServer::GetInstance()->GetContext(), tyName, typelist, names);
+ }
+ else {
if (PluginTypeId == PluginIR::VoidTyID) {
baseType = PluginIR::PluginVoidType::get(PluginServer::GetInstance()->GetContext());
}
diff --git a/user/LocalVarSummeryPass.cpp b/user/LocalVarSummeryPass.cpp
index 4fc4985..2e157e3 100755
--- a/user/LocalVarSummeryPass.cpp
+++ b/user/LocalVarSummeryPass.cpp
@@ -23,6 +23,10 @@
#include "user/LocalVarSummeryPass.h"
namespace PluginOpt {
+using std::string;
+using std::vector;
+using std::cout;
+using namespace mlir;
using namespace PluginAPI;
static void LocalVarSummery(void)
@@ -38,6 +42,32 @@ static void LocalVarSummery(void)
if (args.find("type_code") != args.end()) {
typeFilter = (int64_t)pluginAPI.GetTypeCodeFromString(args["type_code"]);
}
+ mlir::Plugin::FunctionOp funcOp = allFunction[i];
+ printf("func name is :%s\n", funcOp.funcNameAttr().getValue().str().c_str());
+ mlir::Type dgyty = funcOp.type();
+ if (auto ty = dgyty.dyn_cast<PluginIR::PluginFunctionType>()) {
+ if(auto stTy = ty.getReturnType().dyn_cast<PluginIR::PluginStructType>()) {
+ printf("func return type is PluginStructType\n");
+ std::string tyName = stTy.getName();
+ printf(" struct name is : %s\n", tyName.c_str());
+
+ llvm::ArrayRef<mlir::Type> paramsType = stTy.getBody();
+ for (auto tty :paramsType) {
+ printf("\n struct arg id : %d\n", tty.dyn_cast<PluginIR::PluginTypeBase>().getPluginTypeID());
+ }
+ llvm::ArrayRef<std::string> paramsNames = stTy.getElementNames();
+ for (auto name :paramsNames) {
+ std::string pName = name;
+ printf("\n struct argname is : %s\n", pName.c_str());
+ }
+ }
+ size_t paramIndex = 0;
+ llvm::ArrayRef<mlir::Type> paramsType = ty.getParams();
+ for (auto ty : ty.getParams()) {
+ printf("\n Param index : %d\n", paramIndex++);
+ printf("\n Param type id : %d\n", ty.dyn_cast<PluginIR::PluginTypeBase>().getPluginTypeID());
+ }
+ }
for (size_t j = 0; j < decls.size(); j++) {
auto decl = decls[j];
string name = decl.symNameAttr().getValue().str();
--
2.27.0.windows.1

View File

@ -1,6 +1,6 @@
Name: pin-server
Version: 0.4.0
Release: 1
Release: 2
Summary: Pin (Plug-IN framework) server provides plugin APIs for compiler optimization developers to develop optimization pass.
License: Apache 2.0
URL: https://gitee.com/openeuler/pin-server
@ -10,6 +10,16 @@ BuildRequires: gcc gcc-c++ cmake make pkgconfig grpc grpc-plugins grpc-devel pr
BuildRequires: llvm-mlir llvm-mlir-static llvm-mlir-devel llvm-devel
Requires: grpc protobuf
Patch1: 0001-Refactoring-Code-refactoring-of-Communication-Subsys.patch
Patch2: 0002-Refactoring-Code-refactoring-of-Communication-Subsys.patch
Patch3: 0003-Refactoring-Code-refactoring-of-Communication-Subsys.patch
Patch4: 0004-Pin-server-Add-DebugOp.patch
Patch5: 0005-Pin-server-Add-API-for-LTO-judgement.patch
Patch6: 0006-Pin-server-Fix-bug-for-BuildCallOp.patch
Patch7: 0007-Pin-server-Refactoring-array-widen-compare-into-a-cl.patch
Patch8: 0008-Pin-server-Refactoring-DEMOs-into-PluginOpt-classes.patch
Patch9: 0009-Pin-server-Support-functiontype-structtype.eg.patch
%description
Pin (Plug-IN framework) server provides plugin APIs for compiler optimization developers to develop optimization pass.
@ -27,6 +37,16 @@ A demo for pin-server
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
mkdir -p _build
cd _build
%{cmake} .. -DCMAKE_INSTALL_PREFIX=%{_usr} -DCMAKE_INSTALL_LIBDIR=%{_libdir} -DMLIR_DIR=/usr/lib64/cmake/mlir -DLLVM_DIR=/usr/lib64/cmake/llvm
@ -45,13 +65,19 @@ cd _build
%files demo
%attr(0755,root,root) %{_libdir}/libpin_user.so
%attr(0755,root,root) %{_libdir}/libMLIRPlugin.so
%attr(0755,root,root) %{_libdir}/libMLIRPlugin.so.12
%attr(0755,root,root) %{_libdir}/libMLIRPluginServer.so
%attr(0755,root,root) %{_libdir}/libMLIRPluginServer.so.12
%attr(0755,root,root) %{_libdir}/libMLIRServerAPI.so
%attr(0755,root,root) %{_libdir}/libMLIRServerAPI.so.12
%attr(0644,root,root) %{_libdir}/libpin_user.sha256
%changelog
* Wed Feb 22 2023 dingguangya <dingguangya1@huawei.com> - 0.4.0-2
- Type:Update
- ID:NA
- SUG:NA
- DESC:Sync patch from openEuler/pin-server
* Tue Dec 20 2022 zhaowenyu <804544223@qq.com> - 0.4.0-1
- Type:Update
- ID:NA