Projects
Eulaceura:Factory
pin-server
_service:obs_scm:0008-Pin-server-Refactoring-DE...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0008-Pin-server-Refactoring-DEMOs-into-PluginOpt-classes.patch of Package pin-server
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 08/23] [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.33.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2