2596 lines
92 KiB
Diff
2596 lines
92 KiB
Diff
From c1301cbec8465ef4c9c4df597ee46774b6da5715 Mon Sep 17 00:00:00 2001
|
||
From: wangding16 <wangding16@huawei.com>
|
||
Date: Wed, 8 Feb 2023 15:13:54 +0800
|
||
Subject: [PATCH 02/23] [Refactoring] Code refactoring of Communication
|
||
Subsystem [2/3]. Code refactoring of PluginServer.
|
||
|
||
|
||
diff --git a/include/PluginServer/PluginLog.h b/include/PluginServer/PluginLog.h
|
||
index 716e08a..ece7067 100644
|
||
--- a/include/PluginServer/PluginLog.h
|
||
+++ b/include/PluginServer/PluginLog.h
|
||
@@ -16,13 +16,18 @@
|
||
Create: 2022-08-18
|
||
Description:
|
||
This file contains the declaration of the Plugin_Log class.
|
||
+ 主要完成功能:提供LOGE、LOGW、LOGI、LOGD四个log保存接口,并提供SetLogPriority接口
|
||
+ 设置log级别
|
||
*/
|
||
|
||
#ifndef PLUGIN_LOG_H
|
||
#define PLUGIN_LOG_H
|
||
|
||
-namespace PinServer {
|
||
-#define LOG_FILE_SIZE (10 * 1024 * 1024)
|
||
+#include <string>
|
||
+#include <memory>
|
||
+
|
||
+namespace PinLog {
|
||
+using std::string;
|
||
|
||
enum LogPriority : uint8_t {
|
||
PRIORITY_ERROR = 0,
|
||
@@ -30,14 +35,38 @@ enum LogPriority : uint8_t {
|
||
PRIORITY_INFO,
|
||
PRIORITY_DEBUG
|
||
};
|
||
-void LogPrint(LogPriority priority, const char *tag, const char *fmt, ...);
|
||
-void CloseLog(void);
|
||
-bool SetLogPriority(LogPriority priority);
|
||
-
|
||
-#define LOGE(...) LogPrint(PRIORITY_ERROR, "ERROR:", __VA_ARGS__)
|
||
-#define LOGW(...) LogPrint(PRIORITY_WARN, "WARN:", __VA_ARGS__)
|
||
-#define LOGI(...) LogPrint(PRIORITY_INFO, "", __VA_ARGS__)
|
||
-#define LOGD(...) LogPrint(PRIORITY_DEBUG, "DEBUG:", __VA_ARGS__)
|
||
-} // namespace PinServer
|
||
+
|
||
+constexpr int LOG_BUF_SIZE = 102400;
|
||
+constexpr int BASE_DATE = 1900;
|
||
+class PluginLog {
|
||
+public:
|
||
+ PluginLog();
|
||
+ ~PluginLog()
|
||
+ {
|
||
+ CloseLog();
|
||
+ }
|
||
+ void CloseLog();
|
||
+ bool SetPriority(LogPriority pri);
|
||
+ void SetFileSize(unsigned int size)
|
||
+ {
|
||
+ logFileSize = size;
|
||
+ }
|
||
+ void LOGE(const char *fmt, ...);
|
||
+ void LOGW(const char *fmt, ...);
|
||
+ void LOGI(const char *fmt, ...);
|
||
+ void LOGD(const char *fmt, ...);
|
||
+ static PluginLog *GetInstance();
|
||
+
|
||
+private:
|
||
+ void LogPrint(LogPriority priority, const char *tag, const char *fmt);
|
||
+ void LogWrite(const char *tag, const char *msg);
|
||
+ void LogWriteFile(const string& data);
|
||
+ void GetLogFileName(string& fileName);
|
||
+ LogPriority priority;
|
||
+ unsigned int logFileSize;
|
||
+ std::shared_ptr<std::fstream> logFs;
|
||
+ char logBuf[LOG_BUF_SIZE];
|
||
+};
|
||
+} // namespace PinLog
|
||
|
||
#endif
|
||
diff --git a/include/PluginServer/PluginOptBase.h b/include/PluginServer/PluginOptBase.h
|
||
new file mode 100755
|
||
index 0000000..474d072
|
||
--- /dev/null
|
||
+++ b/include/PluginServer/PluginOptBase.h
|
||
@@ -0,0 +1,82 @@
|
||
+/* 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 PluginOptBase class.
|
||
+ 主要完成功能:提供优化基类,gate为进入条件,DoOptimize为执行函数,RegisterCallbacks为注册函数
|
||
+*/
|
||
+
|
||
+#ifndef PLUGIN_OPTBASE_H
|
||
+#define PLUGIN_OPTBASE_H
|
||
+
|
||
+#include "PluginServer/ManagerSetup.h"
|
||
+#include "Dialect/PluginDialect.h"
|
||
+#include "Dialect/PluginOps.h"
|
||
+#include "mlir/IR/MLIRContext.h"
|
||
+#include "mlir/IR/Builders.h"
|
||
+
|
||
+namespace PluginOpt {
|
||
+enum InjectPoint : uint8_t {
|
||
+ HANDLE_PARSE_TYPE = 0,
|
||
+ HANDLE_PARSE_DECL,
|
||
+ HANDLE_PRAGMAS,
|
||
+ HANDLE_PARSE_FUNCTION,
|
||
+ HANDLE_BEFORE_IPA,
|
||
+ HANDLE_AFTER_IPA,
|
||
+ HANDLE_BEFORE_EVERY_PASS,
|
||
+ HANDLE_AFTER_EVERY_PASS,
|
||
+ HANDLE_BEFORE_ALL_PASS,
|
||
+ HANDLE_AFTER_ALL_PASS,
|
||
+ HANDLE_COMPILE_END,
|
||
+ HANDLE_MANAGER_SETUP,
|
||
+ HANDLE_INCLUDE_FILE,
|
||
+ HANDLE_MAX,
|
||
+};
|
||
+
|
||
+class PluginOptBase {
|
||
+public:
|
||
+ PluginOptBase(InjectPoint inject)
|
||
+ {
|
||
+ this->inject = inject;
|
||
+ context.getOrLoadDialect<mlir::Plugin::PluginDialect>();
|
||
+ }
|
||
+ virtual ~PluginOptBase() = default;
|
||
+ virtual bool Gate() = 0;
|
||
+ virtual int DoOptimize() = 0;
|
||
+ InjectPoint GetInject()
|
||
+ {
|
||
+ return inject;
|
||
+ }
|
||
+ void SetFuncAddr(uint64_t add)
|
||
+ {
|
||
+ func = add;
|
||
+ }
|
||
+ uint64_t GetFuncAddr(void)
|
||
+ {
|
||
+ return func;
|
||
+ }
|
||
+ mlir::MLIRContext *GetContext()
|
||
+ {
|
||
+ return &(this->context);
|
||
+ }
|
||
+
|
||
+private:
|
||
+ mlir::MLIRContext context;
|
||
+ InjectPoint inject;
|
||
+ uint64_t func; // 保存managerSetup fun参数指针
|
||
+};
|
||
+} // namespace PluginOpt
|
||
+#endif
|
||
diff --git a/include/PluginServer/PluginServer.h b/include/PluginServer/PluginServer.h
|
||
index ba659be..b651140 100644
|
||
--- a/include/PluginServer/PluginServer.h
|
||
+++ b/include/PluginServer/PluginServer.h
|
||
@@ -16,6 +16,8 @@
|
||
Create: 2022-08-18
|
||
Description:
|
||
This file contains the declaration of the PluginServer class.
|
||
+ 主要完成功能:完成和server之间grpc数据解析,提供接口函数获取client数据,提供注册
|
||
+ 函数完成用户事件注册,并在对应事件触发时回调用户函数
|
||
*/
|
||
|
||
#ifndef PLUGIN_SERVER_H
|
||
@@ -30,22 +32,25 @@
|
||
|
||
#include <json/json.h>
|
||
#include <grpcpp/grpcpp.h>
|
||
-#include "Dialect/PluginOps.h"
|
||
#include "plugin.grpc.pb.h"
|
||
+#include "Dialect/PluginOps.h"
|
||
#include "mlir/IR/MLIRContext.h"
|
||
#include "mlir/IR/Builders.h"
|
||
#include "Dialect/PluginTypes.h"
|
||
|
||
-namespace PinServer {
|
||
-using grpc::Server;
|
||
-using grpc::ServerBuilder;
|
||
-using grpc::ServerContext;
|
||
-using grpc::ServerReaderWriter;
|
||
-using grpc::Status;
|
||
+#include "PluginServer/PluginLog.h"
|
||
+#include "PluginServer/PluginCom.h"
|
||
+#include "PluginServer/PluginOptBase.h"
|
||
|
||
-using plugin::PluginService;
|
||
+namespace PinServer {
|
||
+using PinLog::PluginLog;
|
||
+using PinLog::LogPriority;
|
||
+using PinCom::PluginCom;
|
||
using plugin::ClientMsg;
|
||
using plugin::ServerMsg;
|
||
+using PluginOpt::InjectPoint;
|
||
+using PluginOpt::ManagerSetup;
|
||
+using PluginOpt::PluginOptBase;
|
||
|
||
using std::vector;
|
||
using std::string;
|
||
@@ -60,250 +65,211 @@ typedef enum {
|
||
STATE_TIMEOUT,
|
||
} UserFunStateEnum;
|
||
|
||
-typedef std::function<void(void)> UserFunc;
|
||
-enum InjectPoint : uint8_t {
|
||
- HANDLE_PARSE_TYPE = 0,
|
||
- HANDLE_PARSE_DECL,
|
||
- HANDLE_PRAGMAS,
|
||
- HANDLE_PARSE_FUNCTION,
|
||
- HANDLE_BEFORE_IPA,
|
||
- HANDLE_AFTER_IPA,
|
||
- HANDLE_BEFORE_EVERY_PASS,
|
||
- HANDLE_AFTER_EVERY_PASS,
|
||
- HANDLE_BEFORE_ALL_PASS,
|
||
- HANDLE_AFTER_ALL_PASS,
|
||
- HANDLE_COMPILE_END,
|
||
- HANDLE_MANAGER_SETUP,
|
||
- HANDLE_MAX,
|
||
-};
|
||
-
|
||
-// 参考点名称
|
||
-enum RefPassName {
|
||
- PASS_CFG,
|
||
- PASS_PHIOPT,
|
||
- PASS_SSA,
|
||
- PASS_LOOP,
|
||
-};
|
||
-
|
||
-enum PassPosition {
|
||
- PASS_INSERT_AFTER,
|
||
- PASS_INSERT_BEFORE,
|
||
- PASS_REPLACE,
|
||
-};
|
||
-
|
||
-struct ManagerSetupData {
|
||
- RefPassName refPassName;
|
||
- int passNum; // 指定passName的第几次执行作为参考点
|
||
- PassPosition passPosition; // 指定pass是添加在参考点之前还是之后
|
||
-};
|
||
-
|
||
-class RecordedUserFunc {
|
||
+class RecordedOpt {
|
||
public:
|
||
- RecordedUserFunc () = default;
|
||
- ~RecordedUserFunc () = default;
|
||
- RecordedUserFunc (const string& name, UserFunc func)
|
||
+ RecordedOpt() = default;
|
||
+ ~RecordedOpt() = default;
|
||
+ RecordedOpt(const string& name, std::shared_ptr<PluginOptBase> opt)
|
||
{
|
||
this->name = name;
|
||
- this->func = func;
|
||
+ this->opt = opt;
|
||
}
|
||
- string GetName(void)
|
||
+ RecordedOpt(const string& name, const string& param, std::shared_ptr<PluginOptBase> opt)
|
||
+ {
|
||
+ this->name = name;
|
||
+ this->param = param;
|
||
+ this->opt = opt;
|
||
+ }
|
||
+ string GetName()
|
||
{
|
||
return name;
|
||
}
|
||
- UserFunc GetFunc(void)
|
||
+ string GetParam()
|
||
{
|
||
- return func;
|
||
+ return param;
|
||
+ }
|
||
+ std::shared_ptr<PluginOptBase> GetOpt()
|
||
+ {
|
||
+ return opt;
|
||
}
|
||
private:
|
||
string name;
|
||
- UserFunc func;
|
||
+ string param;
|
||
+ std::shared_ptr<PluginOptBase> opt;
|
||
};
|
||
|
||
-class PluginServer final : public PluginService::Service {
|
||
+class PluginServer {
|
||
public:
|
||
- PluginServer() : opBuilder(&context){}
|
||
- /* 定义的grpc服务端和客户端通信的接口函数 */
|
||
- Status ReceiveSendMsg(ServerContext* context, ServerReaderWriter<ServerMsg, ClientMsg>* stream) override;
|
||
- /* 服务端发送数据给client接口 */
|
||
- void ServerSend(ServerReaderWriter<ServerMsg, ClientMsg>* stream, const string& key, const string& value);
|
||
+ PluginServer(LogPriority priority, const string& port)
|
||
+ {
|
||
+ userFunState = STATE_WAIT_BEGIN;
|
||
+ sem_init(&clientWaitSem, 0, 0);
|
||
+ sem_init(&clientReturnSem, 0, 0);
|
||
+ log = PluginLog::GetInstance();
|
||
+ log->SetPriority(priority);
|
||
+ this->port = port;
|
||
+ pluginServerPtr = this;
|
||
+ }
|
||
+ ~PluginServer()
|
||
+ {
|
||
+ sem_destroy(&clientWaitSem);
|
||
+ sem_destroy(&clientReturnSem);
|
||
+ log->LOGI("server ppid:%d quit!\n", getppid());
|
||
+ }
|
||
/* 处理从client接收到的消息 */
|
||
- int ClientMsgProc(ServerReaderWriter<ServerMsg, ClientMsg>* stream, const string& attribute, const string& value);
|
||
- /* 获取server对象实例,有且只有一个实例对象 */
|
||
- static PluginServer *GetInstance(void);
|
||
- vector<mlir::Plugin::FunctionOp> GetFunctionOpResult(void);
|
||
- vector<mlir::Plugin::LocalDeclOp> GetLocalDeclResult(void);
|
||
- mlir::Plugin::LoopOp LoopOpResult(void);
|
||
- vector<mlir::Plugin::LoopOp> LoopOpsResult(void);
|
||
- vector<std::pair<mlir::Block*, mlir::Block*> > EdgesResult(void);
|
||
- std::pair<mlir::Block*, mlir::Block*> EdgeResult(void);
|
||
- vector<mlir::Operation *> GetOpResult(void);
|
||
- bool GetBoolResult(void);
|
||
- void EraseBlock(mlir::Block*);
|
||
- uint64_t GetBlockResult(mlir::Block*);
|
||
- uint64_t GetIdResult(void);
|
||
- vector<uint64_t> GetIdsResult(void);
|
||
- mlir::Value GetValueResult(void);
|
||
- vector<mlir::Plugin::PhiOp> GetPhiOpsResult(void);
|
||
- mlir::Block* FindBlock(uint64_t);
|
||
- uint64_t FindBasicBlock(mlir::Block*);
|
||
- bool InsertValue(uint64_t, mlir::Value);
|
||
- mlir::Operation* FindDefOperation(uint64_t);
|
||
- void InsertCreatedBlock(uint64_t, mlir::Block*);
|
||
+ int ClientMsgProc(const string& attribute, const string& value);
|
||
+ mlir::MLIRContext *GetContext()
|
||
+ {
|
||
+ return this->context;
|
||
+ }
|
||
+ void SetOpBuilder(mlir::OpBuilder *builder)
|
||
+ {
|
||
+ this->opBuilder = builder;
|
||
+ }
|
||
+ mlir::OpBuilder *GetOpBuilder()
|
||
+ {
|
||
+ return this->opBuilder;
|
||
+ }
|
||
/* 回调函数接口,用于向server注册用户需要执行的函数 */
|
||
- int RegisterUserFunc(InjectPoint inject, UserFunc func);
|
||
- int RegisterPassManagerSetup(InjectPoint inject, const ManagerSetupData& passData, UserFunc func);
|
||
- /* 执行用户注册的回调函数,根据value查找对应的函数,value格式 InjectPoint:funName */
|
||
- void ExecFunc(const string& value);
|
||
- /* 将注册点和函数名发到客户端, stream为grpc当前数据流指针 */
|
||
- void SendRegisteredUserFunc(ServerReaderWriter<ServerMsg, ClientMsg>* stream);
|
||
- bool GetShutdownFlag(void)
|
||
+ bool RegisterOpt(std::shared_ptr<PluginOptBase> optBase);
|
||
+ bool RegisterPassManagerOpt(ManagerSetup& passData, std::shared_ptr<PluginOptBase> optBase);
|
||
+ map<string, string>& GetArgs()
|
||
{
|
||
- return shutdown;
|
||
+ return args;
|
||
}
|
||
- void SetShutdownFlag(bool flag)
|
||
+ /* 执行用户注册的回调函数,根据value查找对应的函数,value格式 InjectPoint:funName */
|
||
+ void ExecFunc(const string& value);
|
||
+ void RunServer();
|
||
+ /* 获取server对象实例,有且只有一个实例对象 */
|
||
+ static PluginServer *GetInstance(void);
|
||
+
|
||
+ int64_t GetIntegerDataResult(const string& funName, const string& params)
|
||
{
|
||
- shutdown = flag;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetIntegerDataResult();
|
||
}
|
||
- void SetApiFuncName(const string& name)
|
||
+ string GetStringDataResult(const string& funName, const string& params)
|
||
{
|
||
- apiFuncName = name;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetStringDataResult();
|
||
}
|
||
- void SetApiFuncParams(const string& params)
|
||
+ vector<mlir::Plugin::FunctionOp> GetFunctionOpResult(const string& funName, const string& params)
|
||
{
|
||
- apiFuncParams = params;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetFunctionOpResult();
|
||
}
|
||
- string &GetApiFuncName(void)
|
||
+ vector<mlir::Plugin::LocalDeclOp> GetLocalDeclResult(const string& funName, const string& params)
|
||
{
|
||
- return apiFuncName;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetLocalDeclResult();
|
||
}
|
||
- string &GetApiFuncParams(void)
|
||
+ mlir::Plugin::LoopOp LoopOpResult(const string& funName, const string& params)
|
||
{
|
||
- return apiFuncParams;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.LoopOpResult();
|
||
}
|
||
- void SetUserFunState(UserFunStateEnum state)
|
||
+ vector<mlir::Plugin::LoopOp> LoopOpsResult(const string& funName, const string& params)
|
||
{
|
||
- userFunState = state;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.LoopOpsResult();
|
||
}
|
||
- UserFunStateEnum GetUserFunState(void)
|
||
+ vector<std::pair<mlir::Block*, mlir::Block*> > EdgesResult(const string& funName, const string& params)
|
||
{
|
||
- return userFunState;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.EdgesResult();
|
||
}
|
||
- void SetTimeout(int time)
|
||
+ std::pair<mlir::Block*, mlir::Block*> EdgeResult(const string& funName, const string& params)
|
||
{
|
||
- timeout = time;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.EdgeResult();
|
||
}
|
||
- void FuncOpJsonDeSerialize(const string& data);
|
||
- Json::Value TypeJsonSerialize(PluginIR::PluginTypeBase& type);
|
||
- PluginIR::PluginTypeBase TypeJsonDeSerialize(const string& data);
|
||
- void LocalDeclOpJsonDeSerialize(const string& data);
|
||
- void LoopOpsJsonDeSerialize(const string& data);
|
||
- void LoopOpJsonDeSerialize(const string& data);
|
||
- void EdgesJsonDeSerialize(const string& data);
|
||
- void EdgeJsonDeSerialize(const string& data);
|
||
- void IdsJsonDeSerialize(const string& data);
|
||
- void CallOpJsonDeSerialize(const string& data);
|
||
- void CondOpJsonDeSerialize(const string& data);
|
||
- void RetOpJsonDeSerialize(const string& data);
|
||
- mlir::Value SSAOpJsonDeSerialize(const string& data);
|
||
- void FallThroughOpJsonDeSerialize(const string& data);
|
||
- void PhiOpJsonDeSerialize(const string& data);
|
||
- void AssignOpJsonDeSerialize(const string& data);
|
||
- void GetPhiOpsJsonDeSerialize(const string& data);
|
||
- void OpJsonDeSerialize(const string& data);
|
||
- mlir::Value ValueJsonDeSerialize(Json::Value valueJson);
|
||
- mlir::Value MemRefDeSerialize(const string& data);
|
||
- /* json反序列化,根据key值分别调用Operation/Decl/Type反序列化接口函数 */
|
||
- void JsonDeSerialize(const string& key, const string& data);
|
||
- /* 解析客户端发送过来的-fplugin-arg参数,并保存在私有变量args中 */
|
||
- void ParseArgv(const string& data);
|
||
- void TimerInit(void); // 超时定时器初始化
|
||
- void TimerStart(int interval); // 启动定时器,interval为0表示关闭定时器
|
||
- map<string, string>& GetArgs(void)
|
||
+ vector<mlir::Operation *> GetOpResult(const string& funName, const string& params)
|
||
{
|
||
- return args;
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetOpResult();
|
||
}
|
||
- /* 将json格式数据解析成map<string, string>格式 */
|
||
- void JsonGetAttributes(Json::Value node, map<string, string>& attributes);
|
||
- void SemInit(void)
|
||
+ bool GetBoolResult(const string& funName, const string& params)
|
||
{
|
||
- sem_init(&sem[0], 0, 0);
|
||
- sem_init(&sem[1], 0, 0);
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetBoolResult();
|
||
}
|
||
- void SemPost(void) // 开始执行用户函数或者用户函数结束触发该信号量
|
||
+ uint64_t GetIdResult(const string& funName, const string& params)
|
||
{
|
||
- sem_post(&sem[0]);
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetIdResult();
|
||
}
|
||
- void SemWait(void)
|
||
+ vector<uint64_t> GetIdsResult(const string& funName, const string& params)
|
||
{
|
||
- sem_wait(&sem[0]);
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetIdsResult();
|
||
}
|
||
- void ClientReturnSemPost(void) // client返回数据后触发该信号量
|
||
+ mlir::Value GetValueResult(const string& funName, const string& params)
|
||
{
|
||
- sem_post(&sem[1]);
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetValueResult();
|
||
}
|
||
- void ClientReturnSemWait(void)
|
||
+ vector<mlir::Plugin::PhiOp> GetPhiOpsResult(const string& funName, const string& params)
|
||
{
|
||
- sem_wait(&sem[1]);
|
||
+ RemoteCallClientWithAPI(funName, params);
|
||
+ return pluginCom.GetPhiOpsResult();
|
||
}
|
||
- void SemDestroy(void)
|
||
+
|
||
+ uint64_t GetBlockResult(mlir::Block*);
|
||
+ void EraseBlock(mlir::Block*);
|
||
+ mlir::Block* FindBlock(uint64_t);
|
||
+ void InsertCreatedBlock(uint64_t, mlir::Block*);
|
||
+ bool HaveBlock(uint64_t id)
|
||
{
|
||
- sem_destroy(&sem[0]);
|
||
- sem_destroy(&sem[1]);
|
||
+ return this->blockMaps.find(id) != this->blockMaps.end();
|
||
}
|
||
|
||
- void SetOpBuilder(mlir::OpBuilder builder) { this->opBuilder = builder; }
|
||
void ClearMaps()
|
||
{
|
||
valueMaps.clear();
|
||
blockMaps.clear();
|
||
basicblockMaps.clear();
|
||
defOpMaps.clear();
|
||
- idsResult.clear();
|
||
- opData.clear();
|
||
- edges.clear();
|
||
- loops.clear();
|
||
- decls.clear();
|
||
- funcOpData.clear();
|
||
- opBuilder = mlir::OpBuilder(&context);
|
||
}
|
||
|
||
+ uint64_t FindBasicBlock(mlir::Block*);
|
||
+ bool InsertValue(uint64_t, mlir::Value);
|
||
+ bool HaveValue(uint64_t);
|
||
+ mlir::Value GetValue(uint64_t);
|
||
+ mlir::Operation* FindDefOperation(uint64_t);
|
||
+ bool InsertDefOperation(uint64_t, mlir::Operation*);
|
||
+ void RemoteCallClientWithAPI(const string& api, const string& params);
|
||
+
|
||
private:
|
||
- bool shutdown; // 是否关闭server
|
||
/* 用户函数执行状态,client返回结果后为STATE_RETURN,开始执行下一个函数 */
|
||
volatile UserFunStateEnum userFunState;
|
||
- mlir::MLIRContext context;
|
||
- mlir::OpBuilder opBuilder;
|
||
- vector<mlir::Plugin::FunctionOp> funcOpData;
|
||
- PluginIR::PluginTypeBase pluginType;
|
||
- vector<mlir::Plugin::LocalDeclOp> decls;
|
||
- vector<mlir::Plugin::LoopOp> loops;
|
||
- mlir::Plugin::LoopOp loop;
|
||
- vector<std::pair<mlir::Block*, mlir::Block*> > edges;
|
||
- std::pair<mlir::Block*, mlir::Block*> edge;
|
||
- vector<mlir::Operation *> opData;
|
||
- bool boolResult;
|
||
- uint64_t idResult;
|
||
- vector<uint64_t> idsResult;
|
||
- mlir::Value valueResult;
|
||
+ mlir::MLIRContext *context;
|
||
+ mlir::OpBuilder* opBuilder = nullptr;
|
||
+
|
||
/* 保存用户注册的回调函数,它们将在注入点事件触发后调用 */
|
||
- map<InjectPoint, vector<RecordedUserFunc>> userFunc;
|
||
+ map<InjectPoint, vector<RecordedOpt>> userOpts;
|
||
string apiFuncName; // 保存用户调用PluginAPI的函数名
|
||
string apiFuncParams; // 保存用户调用PluginAPI函数的参数
|
||
- int timeout;
|
||
- timer_t timerId;
|
||
- map<string, string> args; // 保存gcc编译时用户传入参数
|
||
- sem_t sem[2];
|
||
+ string port; // server使用的端口号
|
||
+ map<string, string> args; // 保存client编译时用户传入参数
|
||
+ sem_t clientWaitSem; // 等待client结果信号量
|
||
+ sem_t clientReturnSem; // client返回结果信号量
|
||
+ PluginCom pluginCom;
|
||
+ PluginLog *log;
|
||
|
||
std::map<uint64_t, mlir::Value> valueMaps;
|
||
// process Block.
|
||
std::map<uint64_t, mlir::Block*> blockMaps;
|
||
std::map<mlir::Block*, uint64_t> basicblockMaps;
|
||
std::map<uint64_t, mlir::Operation*> defOpMaps;
|
||
- bool ProcessBlock(mlir::Block*, mlir::Region&, const Json::Value&);
|
||
|
||
+ /* 解析客户端发送过来的-fplugin-arg参数,并保存在私有变量args中 */
|
||
+ void ParseArgv(const string& data);
|
||
+ void ServerSemPost(const string& port); // server服务起来后通知client
|
||
+ /* 将注册点和函数名发到客户端, stream为grpc当前数据流指针 */
|
||
+ void SendRegisteredUserOpts();
|
||
+ void ExecCallbacks(const string& name);
|
||
+ static PluginServer *pluginServerPtr;
|
||
}; // class PluginServer
|
||
-
|
||
-void RunServer(int timeout, string& port);
|
||
} // namespace PinServer
|
||
|
||
#endif
|
||
diff --git a/lib/PluginServer/PluginCom.cpp b/lib/PluginServer/PluginCom.cpp
|
||
new file mode 100755
|
||
index 0000000..ab171c7
|
||
--- /dev/null
|
||
+++ b/lib/PluginServer/PluginCom.cpp
|
||
@@ -0,0 +1,164 @@
|
||
+/* 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 PluginCom class.
|
||
+ 主要完成功能:和client之间通信、数据解析、数据反序列化
|
||
+*/
|
||
+
|
||
+#include "PluginServer/PluginCom.h"
|
||
+#include "PluginServer/PluginLog.h"
|
||
+
|
||
+namespace PinCom {
|
||
+int64_t PluginCom::GetIntegerDataResult(void)
|
||
+{
|
||
+ int64_t result = integerResult;
|
||
+ integerResult = 0; // clear
|
||
+ return result;
|
||
+}
|
||
+
|
||
+string PluginCom::GetStringDataResult(void)
|
||
+{
|
||
+ string result = stringResult;
|
||
+ stringResult.clear(); // clear
|
||
+ return result;
|
||
+}
|
||
+
|
||
+vector<mlir::Plugin::FunctionOp> PluginCom::GetFunctionOpResult(void)
|
||
+{
|
||
+ vector<mlir::Plugin::FunctionOp> retOps = this->funcOpData;
|
||
+ this->funcOpData.clear();
|
||
+ this->opData.clear();
|
||
+ return retOps;
|
||
+}
|
||
+
|
||
+vector<mlir::Operation *> PluginCom::GetOpResult(void)
|
||
+{
|
||
+ vector<mlir::Operation *> retOps = opData;
|
||
+ opData.clear();
|
||
+ return retOps;
|
||
+}
|
||
+
|
||
+vector<mlir::Plugin::LocalDeclOp> PluginCom::GetLocalDeclResult(void)
|
||
+{
|
||
+ vector<mlir::Plugin::LocalDeclOp> retOps = decls;
|
||
+ decls.clear();
|
||
+ return retOps;
|
||
+}
|
||
+
|
||
+vector<mlir::Plugin::LoopOp> PluginCom::LoopOpsResult(void)
|
||
+{
|
||
+ vector<mlir::Plugin::LoopOp> retLoops = loops;
|
||
+ loops.clear();
|
||
+ return retLoops;
|
||
+}
|
||
+
|
||
+mlir::Plugin::LoopOp PluginCom::LoopOpResult(void)
|
||
+{
|
||
+ mlir::Plugin::LoopOp retLoop = loop;
|
||
+ return retLoop;
|
||
+}
|
||
+
|
||
+std::pair<mlir::Block*, mlir::Block*> PluginCom::EdgeResult()
|
||
+{
|
||
+ std::pair<mlir::Block*, mlir::Block*> e;
|
||
+ e.first = edge.first;
|
||
+ e.second = edge.second;
|
||
+ return e;
|
||
+}
|
||
+
|
||
+vector<std::pair<mlir::Block*, mlir::Block*> > PluginCom::EdgesResult()
|
||
+{
|
||
+ vector<std::pair<mlir::Block*, mlir::Block*> > retEdges;
|
||
+ retEdges = edges;
|
||
+ edges.clear();
|
||
+ return retEdges;
|
||
+}
|
||
+
|
||
+bool PluginCom::GetBoolResult()
|
||
+{
|
||
+ return this->boolResult;
|
||
+}
|
||
+
|
||
+uint64_t PluginCom::GetIdResult()
|
||
+{
|
||
+ return this->idResult;
|
||
+}
|
||
+
|
||
+vector<uint64_t> PluginCom::GetIdsResult()
|
||
+{
|
||
+ vector<uint64_t> retIds = idsResult;
|
||
+ idsResult.clear();
|
||
+ return retIds;
|
||
+}
|
||
+
|
||
+mlir::Value PluginCom::GetValueResult()
|
||
+{
|
||
+ return this->valueResult;
|
||
+}
|
||
+
|
||
+vector<mlir::Plugin::PhiOp> PluginCom::GetPhiOpsResult()
|
||
+{
|
||
+ vector<mlir::Plugin::PhiOp> retOps;
|
||
+ for (auto item : opData) {
|
||
+ mlir::Plugin::PhiOp p = llvm::dyn_cast<mlir::Plugin::PhiOp>(item);
|
||
+ retOps.push_back(p);
|
||
+ }
|
||
+ opData.clear();
|
||
+ return retOps;
|
||
+}
|
||
+
|
||
+void PluginCom::JsonDeSerialize(const string& key, const string& data)
|
||
+{
|
||
+ if (key == "FuncOpResult") {
|
||
+ json.FuncOpJsonDeSerialize(data, this->funcOpData);
|
||
+ } else if (key == "LocalDeclOpResult") {
|
||
+ json.LocalDeclOpJsonDeSerialize(data, this->decls);
|
||
+ } else if (key == "LoopOpResult") {
|
||
+ this->loop = json.LoopOpJsonDeSerialize (data);
|
||
+ } else if (key == "LoopOpsResult") {
|
||
+ json.LoopOpsJsonDeSerialize (data, this->loops);
|
||
+ } else if (key == "BoolResult") {
|
||
+ this->boolResult = (bool)atol(data.c_str());
|
||
+ } else if (key == "VoidResult") {
|
||
+ ;
|
||
+ } else if (key == "EdgeResult") {
|
||
+ json.EdgeJsonDeSerialize(data, this->edge);
|
||
+ } else if (key == "EdgesResult") {
|
||
+ json.EdgesJsonDeSerialize(data, this->edges);
|
||
+ } else if (key == "IdsResult") {
|
||
+ json.IdsJsonDeSerialize(data, this->idsResult);
|
||
+ } else if (key == "IdResult") {
|
||
+ this->idResult = atol(data.c_str());
|
||
+ } else if (key == "OpsResult") {
|
||
+ json.OpJsonDeSerialize(data.c_str(), this->opData);
|
||
+ } else if (key == "ValueResult") {
|
||
+ Json::Value node;
|
||
+ Json::Reader reader;
|
||
+ reader.parse(data, node);
|
||
+ this->valueResult = json.ValueJsonDeSerialize(node);
|
||
+ } else if (key == "GetPhiOps") {
|
||
+ json.GetPhiOpsJsonDeSerialize(data, this->opData);
|
||
+ } else if (key == "IntegerResult") {
|
||
+ json.IntegerDeSerialize(data, integerResult);
|
||
+ } else if (key == "StringResult") {
|
||
+ json.StringDeSerialize(data, stringResult);
|
||
+ } else {
|
||
+ PinLog::PluginLog::GetInstance()->LOGE("not Json,key:%s,value:%s\n", key.c_str(), data.c_str());
|
||
+ }
|
||
+}
|
||
+} // namespace PinCom
|
||
+
|
||
diff --git a/lib/PluginServer/PluginGrpc.cpp b/lib/PluginServer/PluginGrpc.cpp
|
||
new file mode 100755
|
||
index 0000000..659b3ef
|
||
--- /dev/null
|
||
+++ b/lib/PluginServer/PluginGrpc.cpp
|
||
@@ -0,0 +1,82 @@
|
||
+/* 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 PluginGrpc class.
|
||
+ 主要完成功能:完成grpc server服务的注册,提供server和client之间grpc收发接口
|
||
+*/
|
||
+
|
||
+#include <thread>
|
||
+#include "PluginServer/PluginServer.h"
|
||
+
|
||
+namespace PinGrpc {
|
||
+void PluginGrpc::ServerSend(const string& key, const string& value)
|
||
+{
|
||
+ ServerMsg serverMsg;
|
||
+ serverMsg.set_attribute(key);
|
||
+ serverMsg.set_value(value);
|
||
+ grpcStream->Write(serverMsg);
|
||
+}
|
||
+
|
||
+Status PluginGrpc::ReceiveSendMsg(ServerContext* context, ServerReaderWriter<ServerMsg, ClientMsg>* stream)
|
||
+{
|
||
+ ClientMsg clientMsg;
|
||
+ grpcStream = stream;
|
||
+
|
||
+ while (stream->Read(&clientMsg)) {
|
||
+ PinServer::PluginServer::GetInstance()->ClientMsgProc(clientMsg.attribute(), clientMsg.value());
|
||
+ }
|
||
+ return Status::OK;
|
||
+}
|
||
+
|
||
+void PluginGrpc::ServerMonitorThread()
|
||
+{
|
||
+ int delay = 100000; // 100ms
|
||
+ pid_t initPid = 1;
|
||
+ while (1) {
|
||
+ if (shutdown || (getppid() == initPid)) {
|
||
+ grpcServer->Shutdown();
|
||
+ break;
|
||
+ }
|
||
+ usleep(delay);
|
||
+ }
|
||
+}
|
||
+
|
||
+bool PluginGrpc::RegisterServer(const string& port)
|
||
+{
|
||
+ string serverAddress = "0.0.0.0:" + port;
|
||
+ ServerBuilder builder;
|
||
+ int serverPort = 0;
|
||
+ // Listen on the given address without any authentication mechanism.
|
||
+ builder.AddListeningPort(serverAddress, grpc::InsecureServerCredentials(), &serverPort);
|
||
+ builder.RegisterService(this);
|
||
+ grpcServer = std::unique_ptr<Server>(builder.BuildAndStart());
|
||
+ if (serverPort != atoi(port.c_str())) {
|
||
+ return false;
|
||
+ }
|
||
+ return true;
|
||
+}
|
||
+
|
||
+void PluginGrpc::Run()
|
||
+{
|
||
+ std::thread serverExtiThread(&PluginGrpc::ServerMonitorThread, this);
|
||
+ serverExtiThread.join();
|
||
+
|
||
+ // Wait for the server to shutdown. Note that some other thread must be
|
||
+ // responsible for shutting down the server for this call to ever return.
|
||
+ grpcServer->Wait();
|
||
+}
|
||
+} // namespace PinGrpc
|
||
diff --git a/lib/PluginServer/main.cpp b/lib/PluginServer/main.cpp
|
||
index 5ec007b..fac574e 100644
|
||
--- a/lib/PluginServer/main.cpp
|
||
+++ b/lib/PluginServer/main.cpp
|
||
@@ -19,15 +19,20 @@
|
||
*/
|
||
|
||
#include "PluginServer/PluginServer.h"
|
||
-#include "PluginServer/PluginLog.h"
|
||
+
|
||
+using namespace PinServer;
|
||
|
||
int main(int argc, char** argv)
|
||
{
|
||
- int timeout = atoi(argv[0]);
|
||
- std::string port = argv[1];
|
||
- PinServer::LogPriority priority = (PinServer::LogPriority)atoi(argv[2]);
|
||
- PinServer::SetLogPriority(priority);
|
||
- PinServer::RunServer(timeout, port);
|
||
- PinServer::CloseLog();
|
||
+ const int argcNum = 2; // 参数只有2个,argv[0]:port argv[1]:log级别
|
||
+ if (argc != argcNum) {
|
||
+ 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);
|
||
+ server.RunServer();
|
||
return 0;
|
||
}
|
||
\ No newline at end of file
|
||
diff --git a/user.cpp b/user.cpp
|
||
index cdb0b99..a6fe555 100644
|
||
--- a/user.cpp
|
||
+++ b/user.cpp
|
||
@@ -27,7 +27,9 @@
|
||
#include "PluginAPI/PluginServerAPI.h"
|
||
#include "PluginServer/PluginLog.h"
|
||
#include "PluginAPI/ControlFlowAPI.h"
|
||
+#include "PluginServer/PluginOptBase.h"
|
||
|
||
+namespace PluginOpt {
|
||
using std::string;
|
||
using std::vector;
|
||
using std::cout;
|
||
@@ -83,15 +85,13 @@ static void PassManagerSetupFunc(void)
|
||
printf("PassManagerSetupFunc in\n");
|
||
}
|
||
|
||
-enum EDGE_FLAG
|
||
-{
|
||
+enum EDGE_FLAG {
|
||
EDGE_FALLTHRU,
|
||
EDGE_TRUE_VALUE,
|
||
EDGE_FALSE_VALUE
|
||
};
|
||
|
||
-struct edgeDef
|
||
-{
|
||
+struct edgeDef {
|
||
Block *src;
|
||
Block *dest;
|
||
unsigned destIdx;
|
||
@@ -100,84 +100,74 @@ struct edgeDef
|
||
typedef struct edgeDef edge;
|
||
typedef struct edgeDef *edgePtr;
|
||
|
||
-static vector<Block *>
|
||
-getPredecessors (Block *bb)
|
||
+static vector<Block *> getPredecessors(Block *bb)
|
||
{
|
||
vector<Block *> preds;
|
||
- for (auto it = bb->pred_begin(); it != bb->pred_end(); ++it)
|
||
- {
|
||
+ for (auto it = bb->pred_begin(); it != bb->pred_end(); ++it) {
|
||
Block *pred = *it;
|
||
preds.push_back(pred);
|
||
}
|
||
return preds;
|
||
}
|
||
|
||
-static unsigned
|
||
-getNumPredecessor (Block *bb)
|
||
+static unsigned getNumPredecessor(Block *bb)
|
||
{
|
||
vector<Block *> preds = getPredecessors(bb);
|
||
return preds.size();
|
||
}
|
||
|
||
-static unsigned
|
||
-getIndexPredecessor (Block *bb, Block *pred)
|
||
+static unsigned getIndexPredecessor(Block *bb, Block *pred)
|
||
{
|
||
unsigned i;
|
||
vector<Block *> preds = getPredecessors(bb);
|
||
- for (i = 0; i < getNumPredecessor(bb); i++)
|
||
- {
|
||
- if (preds[i] == pred)
|
||
- break;
|
||
+ for (i = 0; i < getNumPredecessor(bb); i++) {
|
||
+ if (preds[i] == pred) {
|
||
+ break;
|
||
+ }
|
||
}
|
||
return i;
|
||
}
|
||
|
||
-static enum EDGE_FLAG
|
||
-getEdgeFlag (Block *src, Block *dest)
|
||
+static enum EDGE_FLAG GetEdgeFlag(Block *src, Block *dest)
|
||
{
|
||
Operation *op = src->getTerminator();
|
||
enum EDGE_FLAG flag;
|
||
- if (isa<FallThroughOp>(op))
|
||
- {
|
||
+ if (isa<FallThroughOp>(op)) {
|
||
flag = EDGE_FALLTHRU;
|
||
}
|
||
- if (isa<CondOp>(op))
|
||
- {
|
||
- if (op->getSuccessor(0) == dest)
|
||
+ if (isa<CondOp>(op)) {
|
||
+ if (op->getSuccessor(0) == dest) {
|
||
flag = EDGE_TRUE_VALUE;
|
||
- else
|
||
+ } else {
|
||
flag = EDGE_FALSE_VALUE;
|
||
+ }
|
||
}
|
||
return flag;
|
||
}
|
||
|
||
|
||
-static vector<edge>
|
||
-getPredEdges (Block *bb)
|
||
+static vector<edge> GetPredEdges(Block *bb)
|
||
{
|
||
unsigned i = 0;
|
||
vector<edge> edges;
|
||
- for (auto it = bb->pred_begin(); it != bb->pred_end(); ++it)
|
||
- {
|
||
+ for (auto it = bb->pred_begin(); it != bb->pred_end(); ++it) {
|
||
Block *pred = *it;
|
||
edge e;
|
||
e.src = pred;
|
||
e.dest = bb;
|
||
e.destIdx = i;
|
||
- e.flag = getEdgeFlag(bb, pred);
|
||
+ e.flag = GetEdgeFlag(bb, pred);
|
||
edges.push_back(e);
|
||
i++;
|
||
}
|
||
return edges;
|
||
}
|
||
|
||
-static edge
|
||
-getEdge (Block *src, Block *dest)
|
||
+static edge GetEdge(Block *src, Block *dest)
|
||
{
|
||
- vector<edge> edges = getPredEdges (dest);
|
||
+ vector<edge> edges = GetPredEdges(dest);
|
||
edge e;
|
||
- for (auto elm : edges)
|
||
- {
|
||
+ for (auto elm : edges) {
|
||
if (elm.src == src) {
|
||
e = elm;
|
||
break;
|
||
@@ -186,24 +176,21 @@ getEdge (Block *src, Block *dest)
|
||
return e;
|
||
}
|
||
|
||
-static unsigned
|
||
-getEdgeDestIdx (Block *src, Block *dest)
|
||
+static unsigned GetEdgeDestIdx(Block *src, Block *dest)
|
||
{
|
||
- edge e = getEdge(src, dest);
|
||
+ edge e = GetEdge(src, dest);
|
||
return e.destIdx;
|
||
}
|
||
|
||
-static bool
|
||
-isEqualEdge (edge e1, edge e2)
|
||
+static bool IsEqualEdge(edge e1, edge e2)
|
||
{
|
||
- if (e1.src == e2.src && e1.dest == e2.dest && e1.destIdx == e2.destIdx
|
||
- && e1.flag == e2.flag)
|
||
+ if (e1.src == e2.src && e1.dest == e2.dest && e1.destIdx == e2.destIdx && e1.flag == e2.flag) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
-static IDefineCode
|
||
-getValueDefCode (Value v)
|
||
+static IDefineCode getValueDefCode(Value v)
|
||
{
|
||
IDefineCode rescode;
|
||
if (auto ssaop = dyn_cast<SSAOp>(v.getDefiningOp())) {
|
||
@@ -212,16 +199,14 @@ getValueDefCode (Value v)
|
||
rescode = memop.defCode().getValue();
|
||
} else if (auto constop = dyn_cast<ConstOp>(v.getDefiningOp())) {
|
||
rescode = constop.defCode().getValue();
|
||
- }else {
|
||
+ } else {
|
||
auto holderop = dyn_cast<PlaceholderOp>(v.getDefiningOp());
|
||
rescode = holderop.defCode().getValue();
|
||
}
|
||
- // assert(rescode == IDefineCode::UNDEF);
|
||
return rescode;
|
||
}
|
||
|
||
-static uint64_t
|
||
-getValueId (Value v)
|
||
+static uint64_t getValueId(Value v)
|
||
{
|
||
uint64_t resid;
|
||
if (auto ssaop = dyn_cast<SSAOp>(v.getDefiningOp())) {
|
||
@@ -230,15 +215,14 @@ getValueId (Value v)
|
||
resid = memop.id();
|
||
} else if (auto constop = dyn_cast<ConstOp>(v.getDefiningOp())) {
|
||
resid = constop.id();
|
||
- }else {
|
||
+ } else {
|
||
auto holderop = dyn_cast<PlaceholderOp>(v.getDefiningOp());
|
||
resid = holderop.id();
|
||
}
|
||
return resid;
|
||
}
|
||
|
||
-static PluginIR::PluginTypeBase
|
||
-getPluginTypeofValue (Value v)
|
||
+static PluginIR::PluginTypeBase getPluginTypeofValue(Value v)
|
||
{
|
||
PluginIR::PluginTypeBase type;
|
||
if (auto ssaop = dyn_cast<SSAOp>(v.getDefiningOp())) {
|
||
@@ -247,15 +231,14 @@ getPluginTypeofValue (Value v)
|
||
type = memop.getResultType().dyn_cast<PluginIR::PluginTypeBase>();
|
||
} else if (auto constop = dyn_cast<ConstOp>(v.getDefiningOp())) {
|
||
type = constop.getResultType().dyn_cast<PluginIR::PluginTypeBase>();
|
||
- }else {
|
||
+ } else {
|
||
auto holderop = dyn_cast<PlaceholderOp>(v.getDefiningOp());
|
||
type = holderop.getResultType().dyn_cast<PluginIR::PluginTypeBase>();
|
||
}
|
||
return type;
|
||
}
|
||
|
||
-static bool
|
||
-isValueExist (Value v)
|
||
+static bool isValueExist(Value v)
|
||
{
|
||
uint64_t vid = getValueId(v);
|
||
if (vid != 0) {
|
||
@@ -264,60 +247,58 @@ isValueExist (Value v)
|
||
return false;
|
||
}
|
||
|
||
-static bool
|
||
-isEqualValue (Value v1, Value v2)
|
||
+static bool isEqualValue(Value v1, Value v2)
|
||
{
|
||
uint64_t v1id = getValueId(v1);
|
||
uint64_t v2id = getValueId(v2);
|
||
- if (v1id != 0 && v2id != 0 && v1id == v2id)
|
||
+ if (v1id != 0 && v2id != 0 && v1id == v2id) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
-static bool
|
||
-isSingleRhsAssignOp (Operation *op)
|
||
+static bool isSingleRhsAssignOp(Operation *op)
|
||
{
|
||
- if (!isa<AssignOp>(op))
|
||
+ if (!isa<AssignOp>(op)) {
|
||
return false;
|
||
- if (op->getNumOperands() == 2)
|
||
+ }
|
||
+ if (op->getNumOperands() == 2) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
-static bool
|
||
-isBinaryRhsAssignOp (Operation *op)
|
||
+static bool isBinaryRhsAssignOp(Operation *op)
|
||
{
|
||
- if (!isa<AssignOp>(op))
|
||
+ if (!isa<AssignOp>(op)) {
|
||
return false;
|
||
- if (op->getNumOperands() == 3)
|
||
+ }
|
||
+ if (op->getNumOperands() == 3) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
-static IDefineCode
|
||
-getSingleRhsAssignOpCode (Operation *op)
|
||
+static IDefineCode getSingleRhsAssignOpCode(Operation *op)
|
||
{
|
||
auto assignOp = dyn_cast<AssignOp>(op);
|
||
Value v = assignOp.GetRHS1();
|
||
return getValueDefCode(v);
|
||
}
|
||
|
||
-static IExprCode
|
||
-getBinaryRhsAssignOpCode (Operation *op)
|
||
+static IExprCode getBinaryRhsAssignOpCode(Operation *op)
|
||
{
|
||
auto assignOp = dyn_cast<AssignOp>(op);
|
||
return assignOp.exprCode();
|
||
}
|
||
|
||
-static int64_t
|
||
-getRealValueIntCST (Value v)
|
||
+static int64_t getRealValueIntCST(Value v)
|
||
{
|
||
auto constOp = dyn_cast<ConstOp>(v.getDefiningOp());
|
||
return constOp.initAttr().cast<mlir::IntegerAttr>().getInt();
|
||
}
|
||
|
||
-static Operation *
|
||
-getSSADefStmtofValue (Value v)
|
||
+static Operation *getSSADefStmtofValue(Value v)
|
||
{
|
||
if (!isa<SSAOp>(v.getDefiningOp())) {
|
||
return NULL;
|
||
@@ -330,17 +311,16 @@ getSSADefStmtofValue (Value v)
|
||
return op;
|
||
}
|
||
|
||
-struct originLoopInfo
|
||
-{
|
||
- Value base; /* The initial index of the array in the old loop. */
|
||
+struct originLoopInfo {
|
||
+ Value base; /* The initial index of the array in the old loop. */
|
||
Value *baseptr;
|
||
- Value limit; /* The limit index of the array in the old loop. */
|
||
+ Value limit; /* The limit index of the array in the old loop. */
|
||
Value *limitptr;
|
||
- Value arr1; /* Array 1 in the old loop. */
|
||
+ 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. */
|
||
+ edge entryEdge; /* The edge into the old loop. */
|
||
edgePtr entryEdgePtr;
|
||
Block *exitBB1;
|
||
Block *exitBB2;
|
||
@@ -352,10 +332,9 @@ struct originLoopInfo
|
||
Operation *condOp2;
|
||
Operation *updateStmt;
|
||
bool existPrologAssgin;
|
||
- /* Whether the marker has an initial value assigned
|
||
- to the array index. */
|
||
+ /* Whether the marker has an initial value assigned to the array index. */
|
||
uint64_t step;
|
||
- /* The growth step of the loop induction variable. */
|
||
+ /* The growth step of the loop induction variable. */
|
||
};
|
||
|
||
typedef struct originLoopInfo originLoopInfo;
|
||
@@ -363,32 +342,31 @@ typedef struct originLoopInfo originLoopInfo;
|
||
static originLoopInfo originLoop;
|
||
|
||
/* Return true if the loop has precisely one backedge. */
|
||
-
|
||
-static bool
|
||
-isLoopSingleBackedge (LoopOp loop)
|
||
+static bool isLoopSingleBackedge(LoopOp loop)
|
||
{
|
||
Block *latch = loop.GetLatch();
|
||
unsigned numSucc = latch->getNumSuccessors();
|
||
- if (numSucc != 1)
|
||
+ if (numSucc != 1) {
|
||
return false;
|
||
+ }
|
||
|
||
Block *header = loop.GetHeader();
|
||
Block *latchSuccBB = latch->getSuccessor(numSucc-1);
|
||
|
||
- if (latchSuccBB != header)
|
||
+ if (latchSuccBB != header) {
|
||
return false;
|
||
+ }
|
||
|
||
return true;
|
||
}
|
||
|
||
/* Return true if the loop has precisely one preheader BB. */
|
||
-
|
||
-static bool
|
||
-isLoopSinglePreheaderBB (LoopOp loop)
|
||
+static bool isLoopSinglePreheaderBB(LoopOp loop)
|
||
{
|
||
Block *header = loop.GetHeader();
|
||
- if (getNumPredecessor(header) != 2)
|
||
+ if (getNumPredecessor(header) != 2) {
|
||
return false;
|
||
+ }
|
||
|
||
vector<Block *> preds = getPredecessors(header);
|
||
Block *headerPred1 = preds[0];
|
||
@@ -396,39 +374,37 @@ isLoopSinglePreheaderBB (LoopOp loop)
|
||
|
||
Block *latch = loop.GetLatch();
|
||
if ((headerPred1 == latch && !loop.IsLoopFather(headerPred2))
|
||
- || (headerPred2 == latch && !loop.IsLoopFather(headerPred1)))
|
||
+ || (headerPred2 == latch && !loop.IsLoopFather(headerPred1))) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
/* Initialize the originLoop structure. */
|
||
-static void
|
||
-initOriginLoopStructure ()
|
||
+static void InitOriginLoopStructure()
|
||
{
|
||
- originLoop.baseptr = nullptr;
|
||
- originLoop.limitptr = nullptr;
|
||
- originLoop.arr1ptr = nullptr;
|
||
- originLoop.arr2ptr = nullptr;
|
||
- originLoop.exitE1Ptr = nullptr;
|
||
- originLoop.exitE2Ptr = nullptr;
|
||
- originLoop.exitBB1 = nullptr;
|
||
- originLoop.exitBB2 =nullptr;
|
||
- originLoop.entryEdgePtr = nullptr;
|
||
- originLoop.condOp1 = nullptr;
|
||
- originLoop.condOp2 = nullptr;
|
||
- originLoop.updateStmt = nullptr;
|
||
- originLoop.existPrologAssgin = false;
|
||
- originLoop.step = 0;
|
||
+ originLoop.baseptr = nullptr;
|
||
+ originLoop.limitptr = nullptr;
|
||
+ originLoop.arr1ptr = nullptr;
|
||
+ originLoop.arr2ptr = nullptr;
|
||
+ originLoop.exitE1Ptr = nullptr;
|
||
+ originLoop.exitE2Ptr = nullptr;
|
||
+ originLoop.exitBB1 = nullptr;
|
||
+ originLoop.exitBB2 =nullptr;
|
||
+ originLoop.entryEdgePtr = nullptr;
|
||
+ originLoop.condOp1 = nullptr;
|
||
+ originLoop.condOp2 = nullptr;
|
||
+ originLoop.updateStmt = nullptr;
|
||
+ originLoop.existPrologAssgin = false;
|
||
+ originLoop.step = 0;
|
||
}
|
||
|
||
-static vector<edge>
|
||
-getLoopExitEdges (LoopOp loop)
|
||
+static vector<edge> getLoopExitEdges(LoopOp loop)
|
||
{
|
||
vector<std::pair<Block *, Block *>> bbPairInfo = loop.GetExitEdges();
|
||
vector<edge> edges;
|
||
for (auto elm : bbPairInfo) {
|
||
- edge e;
|
||
- e = getEdge(elm.first, elm.second);
|
||
+ edge e = GetEdge(elm.first, elm.second);
|
||
edges.push_back(e);
|
||
}
|
||
return edges;
|
||
@@ -436,51 +412,53 @@ getLoopExitEdges (LoopOp loop)
|
||
|
||
/* Make sure the exit condition stmt satisfies a specific form. */
|
||
|
||
-static bool
|
||
-checkCondOp (Operation *op)
|
||
+static bool checkCondOp(Operation *op)
|
||
{
|
||
- if (!op)
|
||
+ if (!op) {
|
||
return false;
|
||
- if (!isa<CondOp>(op))
|
||
+ }
|
||
+ if (!isa<CondOp>(op)) {
|
||
return false;
|
||
+ }
|
||
|
||
auto cond = dyn_cast<CondOp>(op);
|
||
|
||
- if (cond.condCode() != IComparisonCode::ne
|
||
- && cond.condCode() != IComparisonCode::eq)
|
||
+ if (cond.condCode() != IComparisonCode::ne && cond.condCode() != IComparisonCode::eq) {
|
||
return false;
|
||
+ }
|
||
|
||
Value lhs = cond.GetLHS();
|
||
Value rhs = cond.GetRHS();
|
||
-
|
||
- if (getValueDefCode(lhs) != IDefineCode::SSA
|
||
- || getValueDefCode(rhs) != IDefineCode::SSA)
|
||
+ if (getValueDefCode(lhs) != IDefineCode::SSA || getValueDefCode(rhs) != IDefineCode::SSA) {
|
||
return false;
|
||
+ }
|
||
|
||
- return true;
|
||
+ return true;
|
||
}
|
||
|
||
/* Record the exit information in the original loop including exit edge,
|
||
exit bb block, exit condition stmt,
|
||
- eg: exit_eX origin_exit_bbX cond_stmtX. */
|
||
+ eg: exitEX originLoop.exitBBX condOpX. */
|
||
|
||
-static bool
|
||
-recordOriginLoopExitInfo (LoopOp loop)
|
||
+static bool recordOriginLoopExitInfo(LoopOp loop)
|
||
{
|
||
bool found = false;
|
||
Operation *op;
|
||
|
||
if (originLoop.exitE1Ptr != nullptr || originLoop.exitBB1 != nullptr
|
||
|| originLoop.exitE2Ptr != nullptr || originLoop.exitBB2 != nullptr
|
||
- || originLoop.condOp1 != nullptr || originLoop.condOp2 != nullptr)
|
||
+ || originLoop.condOp1 != nullptr || originLoop.condOp2 != nullptr) {
|
||
return false;
|
||
+ }
|
||
|
||
vector<edge> exitEdges = getLoopExitEdges (loop);
|
||
- if (exitEdges.empty())
|
||
+ if (exitEdges.empty()) {
|
||
return false;
|
||
+ }
|
||
|
||
- if (exitEdges.size() != 2)
|
||
+ if (exitEdges.size() != 2) {
|
||
return false;
|
||
+ }
|
||
for (auto e : exitEdges) {
|
||
if (e.src == loop.GetHeader()) {
|
||
originLoop.exitE1 = e;
|
||
@@ -502,21 +480,19 @@ recordOriginLoopExitInfo (LoopOp loop)
|
||
}
|
||
}
|
||
}
|
||
-
|
||
-
|
||
|
||
- if (originLoop.exitE1Ptr != nullptr && originLoop.exitBB1 != nullptr
|
||
+ if (originLoop.exitE1Ptr != nullptr && originLoop.exitBB1 != nullptr
|
||
&& originLoop.exitE2Ptr != nullptr && originLoop.exitBB2 != nullptr
|
||
- && originLoop.condOp1 != nullptr && originLoop.condOp2 != nullptr)
|
||
- found = true;
|
||
+ && originLoop.condOp1 != nullptr && originLoop.condOp2 != nullptr) {
|
||
+ found = true;
|
||
+ }
|
||
|
||
- return found;
|
||
+ return found;
|
||
}
|
||
|
||
/* Get the edge that first entered the loop. */
|
||
|
||
-static edge
|
||
-getLoopPreheaderEdge (LoopOp loop)
|
||
+static edge getLoopPreheaderEdge(LoopOp loop)
|
||
{
|
||
Block *header = loop.GetHeader();
|
||
vector<Block *> preds = getPredecessors(header);
|
||
@@ -529,54 +505,56 @@ getLoopPreheaderEdge (LoopOp loop)
|
||
}
|
||
}
|
||
|
||
- edge e = getEdge(src, header);
|
||
+ edge e = GetEdge(src, header);
|
||
|
||
return e;
|
||
}
|
||
|
||
-/* Returns true if t is SSA_NAME and user variable exists. */
|
||
+/* Returns true if t is SSAOp and user variable exists. */
|
||
|
||
-static bool
|
||
-isSSANameVar (Value v)
|
||
+static bool isSSANameVar(Value v)
|
||
{
|
||
- if (!isValueExist(v) || getValueDefCode(v) != IDefineCode::SSA)
|
||
+ if (!isValueExist(v) || getValueDefCode(v) != IDefineCode::SSA) {
|
||
return false;
|
||
+ }
|
||
auto ssaOp = dyn_cast<SSAOp>(v.getDefiningOp());
|
||
uint64_t varid = ssaOp.nameVarId();
|
||
- if (varid != 0)
|
||
+ if (varid != 0) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
-/* Returns true if t1 and t2 are SSA_NAME and belong to the same variable. */
|
||
+/* Returns true if t1 and t2 are SSAOp and belong to the same variable. */
|
||
|
||
-static bool
|
||
-isSameSSANameVar (Value v1, Value v2)
|
||
+static bool isSameSSANameVar(Value v1, Value v2)
|
||
{
|
||
- if (!isSSANameVar (v1) || !isSSANameVar (v2))
|
||
+ if (!isSSANameVar (v1) || !isSSANameVar (v2)) {
|
||
return false;
|
||
+ }
|
||
auto ssaOp1 = dyn_cast<SSAOp>(v1.getDefiningOp());
|
||
auto ssaOp2 = dyn_cast<SSAOp>(v2.getDefiningOp());
|
||
uint64_t varid1 = ssaOp1.nameVarId();
|
||
uint64_t varid2 = ssaOp2.nameVarId();
|
||
- if (varid1 == varid2)
|
||
+ if (varid1 == varid2) {
|
||
return true;
|
||
+ }
|
||
return false;
|
||
}
|
||
|
||
/* Get origin loop induction variable upper bound. */
|
||
-
|
||
-static bool
|
||
-getIvUpperBound (CondOp cond)
|
||
+static bool getIvUpperBound(CondOp cond)
|
||
{
|
||
- if (originLoop.limitptr != nullptr)
|
||
+ if (originLoop.limitptr != nullptr) {
|
||
return false;
|
||
+ }
|
||
|
||
Value lhs = cond.GetLHS();
|
||
Value rhs = cond.GetRHS();
|
||
-
|
||
- if (!getPluginTypeofValue(lhs).isa<PluginIR::PluginIntegerType>() || !getPluginTypeofValue(rhs).isa<PluginIR::PluginIntegerType>())
|
||
+ if (!getPluginTypeofValue(lhs).isa<PluginIR::PluginIntegerType>()
|
||
+ || !getPluginTypeofValue(rhs).isa<PluginIR::PluginIntegerType>()) {
|
||
return false;
|
||
+ }
|
||
|
||
originLoop.limit = rhs;
|
||
originLoop.limitptr = &originLoop.limit;
|
||
@@ -587,18 +565,16 @@ getIvUpperBound (CondOp cond)
|
||
return false;
|
||
}
|
||
|
||
-/* 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)
|
||
+/* 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. */
|
||
+static bool checkUpdateStmt(Operation *op)
|
||
{
|
||
- if (!op || !isa<AssignOp>(op))
|
||
+ if (!op || !isa<AssignOp>(op)) {
|
||
return false;
|
||
+ }
|
||
auto assignOp = dyn_cast<AssignOp>(op);
|
||
if (assignOp.exprCode() == IExprCode::Plus) {
|
||
-
|
||
Value rhs1 = assignOp.GetRHS1();
|
||
Value rhs2 = assignOp.GetRHS2();
|
||
if (getValueDefCode(rhs1) == IDefineCode::SSA
|
||
@@ -615,42 +591,43 @@ checkUpdateStmt (Operation *op)
|
||
}
|
||
|
||
/* Get origin loop induction variable initial value. */
|
||
-
|
||
-static bool
|
||
-getIvBase (CondOp cond)
|
||
+static bool getIvBase(CondOp cond)
|
||
{
|
||
- if (originLoop.baseptr != nullptr || originLoop.updateStmt != nullptr)
|
||
+ if (originLoop.baseptr != nullptr || originLoop.updateStmt != nullptr) {
|
||
return false;
|
||
+ }
|
||
|
||
Value lhs = cond.GetLHS();
|
||
-
|
||
Block *header = cond.getOperation()->getBlock();
|
||
-
|
||
auto &opList = header->getOperations();
|
||
for (auto it = opList.begin(); it != opList.end(); ++it) {
|
||
Operation *op = &(*it);
|
||
- if (!isa<PhiOp>(op))
|
||
+ if (!isa<PhiOp>(op)) {
|
||
continue;
|
||
+ }
|
||
auto phi = dyn_cast<PhiOp>(op);
|
||
Value result = phi.GetResult();
|
||
- if (!isSameSSANameVar (result, lhs))
|
||
+ if (!isSameSSANameVar (result, lhs)) {
|
||
continue;
|
||
+ }
|
||
Value base = phi.GetArgDef(originLoop.entryEdge.destIdx);
|
||
- if (!isSameSSANameVar (base, lhs))
|
||
+ if (!isSameSSANameVar (base, lhs)) {
|
||
return false;
|
||
+ }
|
||
|
||
originLoop.base = base;
|
||
originLoop.baseptr = &originLoop.base;
|
||
- vector<edge> edges = getPredEdges(header);
|
||
+ vector<edge> edges = GetPredEdges(header);
|
||
for (auto e : edges) {
|
||
-
|
||
- if (!isEqualEdge(e, originLoop.entryEdge)) {
|
||
+ if (!IsEqualEdge(e, originLoop.entryEdge)) {
|
||
Value ivAfter = phi.GetArgDef(e.destIdx);
|
||
- if (!isa<SSAOp>(ivAfter.getDefiningOp()))
|
||
+ if (!isa<SSAOp>(ivAfter.getDefiningOp())) {
|
||
return false;
|
||
+ }
|
||
Operation *op = getSSADefStmtofValue(ivAfter);
|
||
- if (!checkUpdateStmt (op))
|
||
+ if (!checkUpdateStmt (op)) {
|
||
return false;
|
||
+ }
|
||
originLoop.updateStmt = op;
|
||
if (op->getBlock() == header && isEqualValue(ivAfter, lhs)) {
|
||
originLoop.existPrologAssgin = true;
|
||
@@ -672,60 +649,58 @@ getIvBase (CondOp cond)
|
||
......
|
||
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)
|
||
+static bool recordOriginLoopHeader(LoopOp loop)
|
||
{
|
||
Block *header = loop.GetHeader();
|
||
-
|
||
if (originLoop.entryEdgePtr != nullptr || originLoop.baseptr != nullptr
|
||
- || originLoop.updateStmt != nullptr || originLoop.limitptr != nullptr)
|
||
+ || originLoop.updateStmt != nullptr || originLoop.limitptr != nullptr) {
|
||
return false;
|
||
+ }
|
||
originLoop.entryEdge = getLoopPreheaderEdge (loop);
|
||
originLoop.entryEdgePtr = &originLoop.entryEdge;
|
||
auto &opList = header->getOperations();
|
||
for (auto it = opList.rbegin(); it != opList.rend(); ++it) {
|
||
Operation *op = &(*it);
|
||
- if (isa<PhiOp, SSAOp, PlaceholderOp, ConstOp>(op))
|
||
+ if (isa<PhiOp, SSAOp, PlaceholderOp, ConstOp>(op)) {
|
||
continue;
|
||
+ }
|
||
|
||
if (auto cond = dyn_cast<CondOp>(op)) {
|
||
- if (!getIvUpperBound (cond))
|
||
+ if (!getIvUpperBound(cond)) {
|
||
return false;
|
||
- if (!getIvBase (cond))
|
||
+ }
|
||
+ if (!getIvBase(cond)) {
|
||
return false;
|
||
+ }
|
||
} else if (auto assign = dyn_cast<AssignOp>(op)) {
|
||
-
|
||
if (op != originLoop.updateStmt || !originLoop.existPrologAssgin) {
|
||
return false;
|
||
}
|
||
- }
|
||
- else {
|
||
+ } else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
- if (originLoop.entryEdgePtr != nullptr && originLoop.baseptr != nullptr
|
||
+ if (originLoop.entryEdgePtr != nullptr && originLoop.baseptr != nullptr
|
||
&& originLoop.updateStmt != nullptr && originLoop.limitptr != nullptr) {
|
||
return true;
|
||
}
|
||
|
||
- return false;
|
||
+ return false;
|
||
}
|
||
|
||
/* When prolog_assign does not exist, make sure that updateStmt exists in the
|
||
loop latch, and its form is a specific form, eg:
|
||
len_2 = len_1 + 1. */
|
||
-
|
||
-static bool
|
||
-recordOriginLoopLatch (LoopOp loop)
|
||
+static bool recordOriginLoopLatch(LoopOp loop)
|
||
{
|
||
Block *latch = loop.GetLatch();
|
||
Operation *op = latch->getTerminator();
|
||
|
||
if (originLoop.existPrologAssgin) {
|
||
- if (isa<FallThroughOp>(op))
|
||
+ if (isa<FallThroughOp>(op)) {
|
||
return true;
|
||
+ }
|
||
}
|
||
|
||
// Todo: else分支处理别的场景,待添加
|
||
@@ -733,14 +708,13 @@ recordOriginLoopLatch (LoopOp loop)
|
||
return false;
|
||
}
|
||
|
||
-/* 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)
|
||
+/* Returns true when the define STMT corresponding to arg0 of the MemOp
|
||
+ satisfies the PtrPlus type. */
|
||
+static bool checkBodyMemRef(Value memRef)
|
||
{
|
||
- if(getValueDefCode(memRef) != IDefineCode::MemRef)
|
||
+ if (getValueDefCode(memRef) != IDefineCode::MemRef) {
|
||
return false;
|
||
+ }
|
||
|
||
auto memOp = dyn_cast<MemOp>(memRef.getDefiningOp());
|
||
Value realarg0 = memOp.GetBase();
|
||
@@ -748,7 +722,6 @@ checkBodyMemRef (Value memRef)
|
||
PluginServerAPI pluginapi;
|
||
Value arg0 = pluginapi.ConfirmValue(realarg0);
|
||
Value arg1 = pluginapi.ConfirmValue(realarg1);
|
||
-
|
||
if (getPluginTypeofValue(arg0).isa<PluginIR::PluginPointerType>()
|
||
&& getValueDefCode(arg1) == IDefineCode::IntCST
|
||
&& getRealValueIntCST(arg1) == 0) {
|
||
@@ -762,9 +735,7 @@ checkBodyMemRef (Value memRef)
|
||
|
||
/* Returns true if the rh2 of the current stmt comes from the base in the
|
||
original loop. */
|
||
-
|
||
-static bool
|
||
-checkBodyPointerPlus (Operation *op, Value &tmpIndex)
|
||
+static bool checkBodyPointerPlus(Operation *op, Value &tmpIndex)
|
||
{
|
||
auto assignOp = dyn_cast<AssignOp>(op);
|
||
Value rhs1 = assignOp.GetRHS1();
|
||
@@ -775,17 +746,17 @@ checkBodyPointerPlus (Operation *op, Value &tmpIndex)
|
||
if (g && isSingleRhsAssignOp(g) && getBinaryRhsAssignOpCode(g) == IExprCode::Nop) {
|
||
auto nopOp = dyn_cast<AssignOp>(g);
|
||
Value nopRhs = nopOp.GetRHS1();
|
||
-
|
||
if (isSameSSANameVar(nopRhs, originLoop.base)) {
|
||
if (!originLoop.arr1ptr) {
|
||
originLoop.arr1 = rhs1;
|
||
originLoop.arr1ptr = &originLoop.arr1;
|
||
tmpIndex = rhs2;
|
||
- } else if(!originLoop.arr2ptr) {
|
||
- originLoop.arr2 = rhs1;
|
||
- originLoop.arr2ptr = &originLoop.arr2;
|
||
- if (!isEqualValue(tmpIndex, rhs2))
|
||
- return false;
|
||
+ } else if (!originLoop.arr2ptr) {
|
||
+ originLoop.arr2 = rhs1;
|
||
+ originLoop.arr2ptr = &originLoop.arr2;
|
||
+ if (!isEqualValue(tmpIndex, rhs2)) {
|
||
+ return false;
|
||
+ }
|
||
} else {
|
||
return false;
|
||
}
|
||
@@ -796,15 +767,11 @@ checkBodyPointerPlus (Operation *op, Value &tmpIndex)
|
||
return false;
|
||
}
|
||
|
||
-
|
||
/* Record the array comparison information in the original loop, while ensuring
|
||
- that there are only statements related to cont_stmt in the loop body. */
|
||
-
|
||
-static bool
|
||
-recordOriginLoopBody (LoopOp loop)
|
||
+ that there are only statements related to cont stmt in the loop body. */
|
||
+static bool recordOriginLoopBody(LoopOp loop)
|
||
{
|
||
Block *body = originLoop.condOp2->getBlock();
|
||
-
|
||
map<Operation*, bool> visited;
|
||
for (auto &op : *body) {
|
||
visited[&op] = false;
|
||
@@ -813,8 +780,9 @@ recordOriginLoopBody (LoopOp loop)
|
||
Value condLhs = dyn_cast<CondOp>(originLoop.condOp2).GetLHS();
|
||
Value condRhs = dyn_cast<CondOp>(originLoop.condOp2).GetRHS();
|
||
if (!(getPluginTypeofValue(condLhs).isa<PluginIR::PluginIntegerType>())
|
||
- || !(getPluginTypeofValue(condRhs).isa<PluginIR::PluginIntegerType>()))
|
||
+ || !(getPluginTypeofValue(condRhs).isa<PluginIR::PluginIntegerType>())) {
|
||
return false;
|
||
+ }
|
||
|
||
vector<Value> worklist;
|
||
worklist.push_back(condLhs);
|
||
@@ -822,63 +790,68 @@ recordOriginLoopBody (LoopOp loop)
|
||
Value tmpIndex;
|
||
visited[originLoop.condOp2] = true;
|
||
|
||
- while (!worklist.empty())
|
||
- {
|
||
+ while (!worklist.empty()) {
|
||
Value v = worklist.back();
|
||
worklist.pop_back();
|
||
Operation *op = getSSADefStmtofValue(v);
|
||
|
||
- if (!op || op->getBlock() != body || !isa<AssignOp>(op))
|
||
+ if (!op || op->getBlock() != body || !isa<AssignOp>(op)) {
|
||
continue;
|
||
+ }
|
||
visited[op] = true;
|
||
if (isSingleRhsAssignOp(op) && getSingleRhsAssignOpCode(op) == IDefineCode::MemRef) {
|
||
auto assignopmem = dyn_cast<AssignOp>(op);
|
||
Value memRef = assignopmem.GetRHS1();
|
||
- if (!checkBodyMemRef(memRef))
|
||
+ if (!checkBodyMemRef(memRef)) {
|
||
return false;
|
||
+ }
|
||
auto memOp = dyn_cast<MemOp>(memRef.getDefiningOp());
|
||
Value arg0 = memOp.GetBase();
|
||
- worklist.push_back(arg0);//memref arg0
|
||
- }else if (isBinaryRhsAssignOp(op) && getBinaryRhsAssignOpCode(op) == IExprCode::PtrPlus) {
|
||
+ worklist.push_back(arg0); // memref arg0
|
||
+ } else if (isBinaryRhsAssignOp(op) && getBinaryRhsAssignOpCode(op) == IExprCode::PtrPlus) {
|
||
auto assignop2 = dyn_cast<AssignOp>(op);
|
||
Value rhs2 = assignop2.GetRHS2();
|
||
- if (!checkBodyPointerPlus(op, tmpIndex))
|
||
+ if (!checkBodyPointerPlus(op, tmpIndex)) {
|
||
return false;
|
||
+ }
|
||
worklist.push_back(rhs2);
|
||
- }else if (isSingleRhsAssignOp(op) && getBinaryRhsAssignOpCode(op) == IExprCode::Nop){
|
||
+ } else if (isSingleRhsAssignOp(op) && getBinaryRhsAssignOpCode(op) == IExprCode::Nop) {
|
||
auto assignop = dyn_cast<AssignOp>(op);
|
||
Value rhs = assignop.GetRHS1();
|
||
- if (!isSameSSANameVar(rhs, originLoop.base))
|
||
+ if (!isSameSSANameVar(rhs, originLoop.base)) {
|
||
return false;
|
||
+ }
|
||
worklist.push_back(rhs);
|
||
- }else {
|
||
+ } else {
|
||
return false;
|
||
}
|
||
}
|
||
bool allvisited = true;
|
||
- if (allvisited)
|
||
+ if (allvisited) {
|
||
return true;
|
||
+ }
|
||
|
||
return false;
|
||
}
|
||
|
||
/* Returns true only if the exit bb of the original loop is unique and its phi
|
||
node parameter comes from the same variable. */
|
||
-
|
||
-static bool
|
||
-checkExitBB (LoopOp loop)
|
||
+static bool checkExitBB(LoopOp loop)
|
||
{
|
||
- if (originLoop.exitBB1 != originLoop.exitBB2
|
||
- || loop.IsBlockInside (originLoop.exitBB1))
|
||
- return false;
|
||
+ if (originLoop.exitBB1 != originLoop.exitBB2
|
||
+ || loop.IsBlockInside (originLoop.exitBB1)) {
|
||
+ return false;
|
||
+ }
|
||
|
||
for (auto &op : *originLoop.exitBB1) {
|
||
- if (!isa<PhiOp>(op))
|
||
+ if (!isa<PhiOp>(op)) {
|
||
continue;
|
||
+ }
|
||
auto phi = dyn_cast<PhiOp>(op);
|
||
Value result = phi.GetResult();
|
||
- if (!isSameSSANameVar(result, originLoop.base))
|
||
+ if (!isSameSSANameVar(result, originLoop.base)) {
|
||
continue;
|
||
+ }
|
||
if (phi.nArgs() == 2) {
|
||
Value arg0 = phi.GetArgDef(0);
|
||
Value arg1 = phi.GetArgDef(1);
|
||
@@ -892,131 +865,122 @@ checkExitBB (LoopOp loop)
|
||
|
||
/* Make sure that the recorded originLoop information meets the
|
||
relative requirements. */
|
||
-
|
||
-static bool
|
||
-checkOriginLoopInfo (LoopOp loop)
|
||
+static bool checkOriginLoopInfo(LoopOp loop)
|
||
{
|
||
- if (!checkExitBB (loop))
|
||
+ if (!checkExitBB (loop)) {
|
||
return false;
|
||
+ }
|
||
|
||
- if (getValueDefCode(originLoop.base) != IDefineCode::SSA)
|
||
+ if (getValueDefCode(originLoop.base) != IDefineCode::SSA) {
|
||
return false;
|
||
+ }
|
||
|
||
- if (getValueDefCode(originLoop.limit) != IDefineCode::SSA)
|
||
+ if (getValueDefCode(originLoop.limit) != IDefineCode::SSA) {
|
||
return false;
|
||
+ }
|
||
|
||
auto limitssaop = dyn_cast<SSAOp>(originLoop.limit.getDefiningOp());
|
||
-
|
||
- if (!limitssaop.readOnly().getValue())
|
||
+ if (!limitssaop.readOnly().getValue()) {
|
||
return false;
|
||
+ }
|
||
|
||
if (!getPluginTypeofValue(originLoop.arr1).isa<PluginIR::PluginPointerType>()
|
||
- || !getPluginTypeofValue(originLoop.arr2).isa<PluginIR::PluginPointerType>())
|
||
+ || !getPluginTypeofValue(originLoop.arr2).isa<PluginIR::PluginPointerType>()) {
|
||
return false;
|
||
+ }
|
||
|
||
auto arr1type = getPluginTypeofValue(originLoop.arr1).dyn_cast<PluginIR::PluginPointerType>();
|
||
auto arr2type = getPluginTypeofValue(originLoop.arr2).dyn_cast<PluginIR::PluginPointerType>();
|
||
-
|
||
- if (!arr1type.isReadOnlyElem() || !arr2type.isReadOnlyElem())
|
||
+ if (!arr1type.isReadOnlyElem() || !arr2type.isReadOnlyElem()) {
|
||
return false;
|
||
+ }
|
||
|
||
if (!arr1type.getElementType().isa<PluginIR::PluginIntegerType>()
|
||
- || !arr2type.getElementType().isa<PluginIR::PluginIntegerType>())
|
||
+ || !arr2type.getElementType().isa<PluginIR::PluginIntegerType>()) {
|
||
return false;
|
||
+ }
|
||
|
||
auto elemTy1 = arr1type.getElementType().dyn_cast<PluginIR::PluginIntegerType>();
|
||
auto elemTy2 = arr2type.getElementType().dyn_cast<PluginIR::PluginIntegerType>();
|
||
-
|
||
- if (elemTy1.getWidth() != 8 || elemTy2.getWidth() != 8)
|
||
+ if (elemTy1.getWidth() != 8 || elemTy2.getWidth() != 8) {
|
||
return false;
|
||
+ }
|
||
|
||
return true;
|
||
}
|
||
|
||
// /* Record the useful information of the original loop and judge whether the
|
||
// information meets the specified conditions. */
|
||
-
|
||
-static bool
|
||
-checkRecordLoopForm (LoopOp loop)
|
||
+static bool checkRecordLoopForm(LoopOp loop)
|
||
{
|
||
- if (!recordOriginLoopExitInfo (loop))
|
||
- {
|
||
+ if (!recordOriginLoopExitInfo (loop)) {
|
||
printf ("\nFailed to record loop exit information.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (!recordOriginLoopHeader (loop))
|
||
- {
|
||
+ if (!recordOriginLoopHeader (loop)) {
|
||
printf ("\nFailed to record loop header information.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (!recordOriginLoopLatch (loop))
|
||
- {
|
||
+ if (!recordOriginLoopLatch (loop)) {
|
||
printf ("\nFailed to record loop latch information.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (!recordOriginLoopBody (loop))
|
||
- {
|
||
+ if (!recordOriginLoopBody (loop)) {
|
||
printf ("\nFailed to record loop body information.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (!checkOriginLoopInfo (loop))
|
||
- {
|
||
+ if (!checkOriginLoopInfo (loop)) {
|
||
printf ("\nFailed to check origin loop information.\n");
|
||
return false;
|
||
}
|
||
|
||
- return true;
|
||
+ return true;
|
||
}
|
||
|
||
-static bool
|
||
-determineLoopForm(LoopOp loop)
|
||
+static bool determineLoopForm(LoopOp loop)
|
||
{
|
||
- if (loop.innerLoopIdAttr().getInt() != 0 && loop.numBlockAttr().getInt() != 3)
|
||
- {
|
||
+ if (loop.innerLoopIdAttr().getInt() != 0 && loop.numBlockAttr().getInt() != 3) {
|
||
printf ("\nWrong loop form, there is inner loop or redundant bb.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (loop.GetSingleExit().first || !loop.GetLatch())
|
||
- {
|
||
+ if (loop.GetSingleExit().first || !loop.GetLatch()) {
|
||
printf ("\nWrong loop form, only one exit or loop_latch does not exist.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (!isLoopSingleBackedge(loop))
|
||
- {
|
||
+ if (!isLoopSingleBackedge(loop)) {
|
||
printf ("\nWrong loop form, loop back edges are not unique.\n");
|
||
return false;
|
||
}
|
||
|
||
- if (!isLoopSinglePreheaderBB(loop))
|
||
- {
|
||
+ if (!isLoopSinglePreheaderBB(loop)) {
|
||
printf ("\nWrong loop form, loop preheader bb are not unique.\n");
|
||
return false;
|
||
}
|
||
|
||
- initOriginLoopStructure();
|
||
- if (!checkRecordLoopForm(loop))
|
||
+ InitOriginLoopStructure();
|
||
+ if (!checkRecordLoopForm(loop)) {
|
||
return false;
|
||
+ }
|
||
return true;
|
||
}
|
||
|
||
-
|
||
-static void
|
||
-update_loop_dominator(uint64_t dir, FunctionOp* funcOp)
|
||
+static void update_loop_dominator(uint64_t dir, FunctionOp* funcOp)
|
||
{
|
||
ControlFlowAPI cfAPI;
|
||
mlir::Region ®ion = funcOp->bodyRegion();
|
||
PluginServerAPI pluginAPI;
|
||
|
||
- for (auto &bb : region.getBlocks())
|
||
- {
|
||
+ for (auto &bb : region.getBlocks()) {
|
||
uint64_t bbAddr = pluginAPI.FindBasicBlock(&bb);
|
||
- if (bbAddr == 0) continue;
|
||
+ if (bbAddr == 0) {
|
||
+ continue;
|
||
+ }
|
||
uint64_t i_bbAddr = cfAPI.GetImmediateDominator(dir, bbAddr);
|
||
if (!i_bbAddr || &bb == originLoop.exitBB1) {
|
||
cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(&bb), \
|
||
@@ -1026,8 +990,7 @@ update_loop_dominator(uint64_t dir, FunctionOp* funcOp)
|
||
}
|
||
}
|
||
|
||
-static void
|
||
-remove_originLoop(LoopOp *loop, FunctionOp* funcOp)
|
||
+static void remove_originLoop(LoopOp *loop, FunctionOp* funcOp)
|
||
{
|
||
vector<mlir::Block*> body;
|
||
ControlFlowAPI controlapi;
|
||
@@ -1035,15 +998,13 @@ remove_originLoop(LoopOp *loop, FunctionOp* funcOp)
|
||
body = loop->GetLoopBody();
|
||
unsigned n = loop->numBlockAttr().getInt();
|
||
for (unsigned i = 0; i < n; i++) {
|
||
- // body[i]->erase();
|
||
controlapi.DeleteBlock(body[i], funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(body[i]));
|
||
}
|
||
loop->Delete();
|
||
}
|
||
|
||
-static void
|
||
-create_prolog_bb(
|
||
- Block *prolog_bb, Block *after_bb, Block *dominator_bb, LoopOp *outer, edge entryEdge, FunctionOp *funcOp, Block *ftBB)
|
||
+static void create_prolog_bb(Block *prolog_bb, Block *after_bb, Block *dominator_bb,
|
||
+ LoopOp *outer, edge entryEdge, FunctionOp *funcOp, Block *ftBB)
|
||
{
|
||
mlir::Value lhs1;
|
||
|
||
@@ -1052,14 +1013,14 @@ create_prolog_bb(
|
||
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(prolog_bb), outer->idAttr().getInt());
|
||
|
||
- FallThroughOp fp =llvm::dyn_cast<FallThroughOp>(entryEdge.src->back());
|
||
- pluginAPI.RedirectFallthroughTarget(fp, pluginAPI.FindBasicBlock(entryEdge.src), pluginAPI.FindBasicBlock(prolog_bb));
|
||
+ FallThroughOp fp = llvm::dyn_cast<FallThroughOp>(entryEdge.src->back());
|
||
+ pluginAPI.RedirectFallthroughTarget(fp, pluginAPI.FindBasicBlock(entryEdge.src),
|
||
+ pluginAPI.FindBasicBlock(prolog_bb));
|
||
cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(prolog_bb), pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
SSAOp baseSsa = dyn_cast<mlir::Plugin::SSAOp>(originLoop.base.getDefiningOp());
|
||
lhs1 = baseSsa.Copy();
|
||
|
||
-
|
||
opBuilder->setInsertionPointToStart(prolog_bb);
|
||
llvm::SmallVector<mlir::Value> ops;
|
||
if (originLoop.existPrologAssgin) {
|
||
@@ -1069,8 +1030,7 @@ create_prolog_bb(
|
||
mlir::Value step = ConstOp::CreateConst(*opBuilder, attr, originLoop.base.getType());
|
||
ops.push_back(step);
|
||
AssignOp opa = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::Plus, prolog_bb);
|
||
- }
|
||
- else {
|
||
+ } else {
|
||
ops.push_back(lhs1);
|
||
ops.push_back(originLoop.base);
|
||
AssignOp op = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::Nop, prolog_bb);
|
||
@@ -1080,8 +1040,7 @@ create_prolog_bb(
|
||
defs_map.emplace(prolog_bb, lhs1);
|
||
}
|
||
|
||
-static void
|
||
-create_loop_pred_bb(
|
||
+static void create_loop_pred_bb(
|
||
Block *loop_pred_bb, Block* after_bb, Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
{
|
||
ControlFlowAPI cfAPI;
|
||
@@ -1095,8 +1054,7 @@ create_loop_pred_bb(
|
||
defs_map.emplace(loop_pred_bb, baseSsa.GetCurrentDef());
|
||
}
|
||
|
||
-static void
|
||
-create_align_loop_header(Block *align_loop_header, Block* after_bb,
|
||
+static void create_align_loop_header(Block *align_loop_header, Block* after_bb,
|
||
Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block* tb, Block* fb)
|
||
{
|
||
CondOp cond_stmt;
|
||
@@ -1114,11 +1072,11 @@ create_align_loop_header(Block *align_loop_header, Block* after_bb,
|
||
cfAPI.CreateNewDef(entry_node, phi.getOperation());
|
||
res = phi.GetResult();
|
||
|
||
-
|
||
opBuilder->setInsertionPointToStart(align_loop_header);
|
||
llvm::SmallVector<mlir::Value> ops;
|
||
|
||
- PluginIR::PluginTypeBase baseType = PluginIR::PluginIntegerType::get(context, 64, PluginIR::PluginIntegerType::Unsigned);
|
||
+ PluginIR::PluginTypeBase baseType = PluginIR::PluginIntegerType::get(context, 64,
|
||
+ PluginIR::PluginIntegerType::Unsigned);
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, baseType));
|
||
ops.push_back(res);
|
||
AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::Nop, (align_loop_header));
|
||
@@ -1138,25 +1096,25 @@ create_align_loop_header(Block *align_loop_header, Block* after_bb,
|
||
ops.push_back(lhs2);
|
||
ops.push_back(lhs3);
|
||
|
||
- cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(), IComparisonCode::le, lhs2, lhs3, tb, fb, (align_loop_header));
|
||
+ cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(), IComparisonCode::le,
|
||
+ lhs2, lhs3, tb, fb, (align_loop_header));
|
||
|
||
baseSsa.SetCurrentDef(res);
|
||
defs_map.emplace(align_loop_header, res);
|
||
}
|
||
|
||
-static void
|
||
-rewrite_add_phi_arg(Block* bb)
|
||
+static void rewrite_add_phi_arg(Block* bb)
|
||
{
|
||
ControlFlowAPI cf;
|
||
PluginServerAPI pluginAPI;
|
||
vector<PhiOp> phis = cf.GetAllPhiOpInsideBlock(bb);
|
||
for (auto phi : phis) {
|
||
Value res = phi.GetResult();
|
||
- vector<Block *> bv = getPredecessors (bb);
|
||
+ vector<Block *> bv = getPredecessors (bb);
|
||
int j = 0;
|
||
for (int i = bv.size()-1; i>=0; i--) {
|
||
if (phi.GetArgDef(j++)) {
|
||
- continue;
|
||
+ continue;
|
||
}
|
||
|
||
Value var = (defs_map[bv[i]]);
|
||
@@ -1181,9 +1139,8 @@ static LoopOp *init_new_loop(LoopOp *outer_loop, Block* header, Block* latch, Fu
|
||
return new_loop;
|
||
}
|
||
|
||
-static void
|
||
-create_align_loop_body_bb(Block *align_loop_body_bb, Block* after_bb, Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp,
|
||
- Block* tb, Block* fb)
|
||
+static void create_align_loop_body_bb(Block *align_loop_body_bb, Block* after_bb, Block* dominator_bb,
|
||
+ LoopOp *outer, FunctionOp *funcOp, Block* tb, Block* fb)
|
||
{
|
||
CondOp cond_stmt;
|
||
Value lhs1, lhs2;
|
||
@@ -1192,27 +1149,32 @@ create_align_loop_body_bb(Block *align_loop_body_bb, Block* after_bb, Block* dom
|
||
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(align_loop_body_bb), outer->idAttr().getInt());
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(align_loop_body_bb), pluginAPI.FindBasicBlock(dominator_bb));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(align_loop_body_bb),
|
||
+ pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
opBuilder->setInsertionPointToStart(align_loop_body_bb);
|
||
llvm::SmallVector<mlir::Value> ops;
|
||
|
||
SSAOp baseSsa = dyn_cast<mlir::Plugin::SSAOp>(originLoop.base.getDefiningOp());
|
||
- PluginIR::PluginTypeBase sizeType = PluginIR::PluginIntegerType::get(context, 64, PluginIR::PluginIntegerType::Unsigned);
|
||
+ PluginIR::PluginTypeBase sizeType = PluginIR::PluginIntegerType::get(context, 64,
|
||
+ PluginIR::PluginIntegerType::Unsigned);
|
||
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, sizeType));
|
||
|
||
ops.push_back(baseSsa.GetCurrentDef());
|
||
- AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::Nop, (align_loop_body_bb));
|
||
+ AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::Nop, (align_loop_body_bb));
|
||
Value var = op1.GetLHS();
|
||
ops.clear();
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, originLoop.arr2.getType()));
|
||
ops.push_back(originLoop.arr2);
|
||
ops.push_back(var);
|
||
- AssignOp op2 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::PtrPlus, (align_loop_body_bb));
|
||
+ AssignOp op2 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::PtrPlus, (align_loop_body_bb));
|
||
lhs1 = op2.GetLHS();
|
||
ops.clear();
|
||
- PluginIR::PluginTypeBase baseType = PluginIR::PluginIntegerType::get(context, 64, PluginIR::PluginIntegerType::Unsigned);
|
||
+ PluginIR::PluginTypeBase baseType = PluginIR::PluginIntegerType::get(context, 64,
|
||
+ PluginIR::PluginIntegerType::Unsigned);
|
||
PluginIR::PluginTypeBase pointerTy = PluginIR::PluginPointerType::get(context, baseType, 0);
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, baseType));
|
||
mlir::Attribute asdada = opBuilder->getI64IntegerAttr(0);
|
||
@@ -1224,7 +1186,8 @@ create_align_loop_body_bb(Block *align_loop_body_bb, Block* after_bb, Block* dom
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, originLoop.arr1.getType()));
|
||
ops.push_back(originLoop.arr1);
|
||
ops.push_back(var);
|
||
- AssignOp op4 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::PtrPlus, (align_loop_body_bb));
|
||
+ AssignOp op4 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::PtrPlus, (align_loop_body_bb));
|
||
lhs2 = op4.GetLHS();
|
||
ops.clear();
|
||
|
||
@@ -1232,15 +1195,16 @@ create_align_loop_body_bb(Block *align_loop_body_bb, Block* after_bb, Block* dom
|
||
ops.push_back(pluginAPI.BuildMemRef(
|
||
baseType, lhs2, ConstOp::CreateConst(*opBuilder, opBuilder->getI64IntegerAttr(0), pointerTy)));
|
||
|
||
- AssignOp op5 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::UNDEF, (align_loop_body_bb));
|
||
+ AssignOp op5 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::UNDEF, (align_loop_body_bb));
|
||
lhs2 = op5.GetLHS();
|
||
|
||
- cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(),
|
||
+ cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(),
|
||
llvm::dyn_cast<CondOp>(originLoop.condOp2).condCode(), lhs1, lhs2, tb, fb, (align_loop_body_bb));
|
||
}
|
||
|
||
-static void
|
||
-create_align_loop_latch(Block *align_loop_latch, Block* after_bb, Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
+static void create_align_loop_latch(Block *align_loop_latch, Block* after_bb, Block* dominator_bb,
|
||
+ LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
{
|
||
Value res;
|
||
ControlFlowAPI cfAPI;
|
||
@@ -1251,7 +1215,8 @@ create_align_loop_latch(Block *align_loop_latch, Block* after_bb, Block* dominat
|
||
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(align_loop_latch), outer->idAttr().getInt());
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(align_loop_latch), pluginAPI.FindBasicBlock(dominator_bb));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(align_loop_latch),
|
||
+ pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
res = baseSsa.Copy();
|
||
|
||
@@ -1265,8 +1230,8 @@ create_align_loop_latch(Block *align_loop_latch, Block* after_bb, Block* dominat
|
||
defs_map.emplace(align_loop_latch, res);
|
||
}
|
||
|
||
-static void
|
||
-create_align_loop_exit_bb(Block *align_loop_exit_bb, Block* after_bb, Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
+static void create_align_loop_exit_bb(Block *align_loop_exit_bb, Block* after_bb, Block* dominator_bb,
|
||
+ LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
{
|
||
CondOp cond_stmt;
|
||
Value lhs1, lhs2;
|
||
@@ -1279,7 +1244,8 @@ create_align_loop_exit_bb(Block *align_loop_exit_bb, Block* after_bb, Block* dom
|
||
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(align_loop_exit_bb), outer->idAttr().getInt());
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(align_loop_exit_bb), pluginAPI.FindBasicBlock(dominator_bb));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(align_loop_exit_bb),
|
||
+ pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
cond_stmt = llvm::dyn_cast<CondOp>(after_bb->back());
|
||
cond_lhs = cond_stmt.GetLHS();
|
||
@@ -1290,12 +1256,14 @@ create_align_loop_exit_bb(Block *align_loop_exit_bb, Block* after_bb, Block* dom
|
||
ops.push_back((SSAOp::MakeSSA(*opBuilder, cond_lhs.getType())));
|
||
ops.push_back(cond_lhs);
|
||
ops.push_back(cond_rhs);
|
||
- AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::BitXOR, (align_loop_exit_bb));
|
||
+ AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::BitXOR, (align_loop_exit_bb));
|
||
lhs1 = op1.GetLHS();
|
||
ops.clear();
|
||
ops.push_back(lhs1);
|
||
build_ctzll = opBuilder->create<CallOp>(opBuilder->getUnknownLoc(), ops, (align_loop_exit_bb));
|
||
- PluginIR::PluginTypeBase intType = PluginIR::PluginIntegerType::get(context, 32, PluginIR::PluginIntegerType::Signed);
|
||
+ PluginIR::PluginTypeBase intType =
|
||
+ PluginIR::PluginIntegerType::get(context, 32, PluginIR::PluginIntegerType::Signed);
|
||
lhs1 = SSAOp::MakeSSA(*opBuilder, intType);
|
||
build_ctzll.SetLHS(lhs1);
|
||
|
||
@@ -1325,8 +1293,8 @@ create_align_loop_exit_bb(Block *align_loop_exit_bb, Block* after_bb, Block* dom
|
||
defs_map.emplace(align_loop_exit_bb, lhs2);
|
||
}
|
||
|
||
-static void
|
||
-create_epilogue_loop_header(Block *epilogue_loop_header, Block* after_bb, Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block* tb, Block* fb)
|
||
+static void create_epilogue_loop_header(Block *epilogue_loop_header, Block* after_bb, Block* dominator_bb,
|
||
+ LoopOp *outer, FunctionOp *funcOp, Block* tb, Block* fb)
|
||
{
|
||
CondOp cond_stmt;
|
||
Value res;
|
||
@@ -1337,10 +1305,10 @@ create_epilogue_loop_header(Block *epilogue_loop_header, Block* after_bb, Block*
|
||
SSAOp baseSsa = dyn_cast<mlir::Plugin::SSAOp>(originLoop.base.getDefiningOp());
|
||
Value entry_node = baseSsa.GetCurrentDef();
|
||
|
||
-
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(epilogue_loop_header), outer->idAttr().getInt());
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(epilogue_loop_header), pluginAPI.FindBasicBlock(dominator_bb));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(epilogue_loop_header),
|
||
+ pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
phi = PhiOp::CreatePhi(nullptr, epilogue_loop_header);
|
||
cfAPI.CreateNewDef(entry_node, phi.getOperation());
|
||
@@ -1348,17 +1316,16 @@ create_epilogue_loop_header(Block *epilogue_loop_header, Block* after_bb, Block*
|
||
|
||
opBuilder->setInsertionPointToStart(epilogue_loop_header);
|
||
|
||
- cond_stmt =
|
||
- opBuilder->create<CondOp>(opBuilder->getUnknownLoc(), llvm::dyn_cast<CondOp>(originLoop.condOp1).condCode(), res, originLoop.limit, tb, fb, (epilogue_loop_header));
|
||
+ cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(),
|
||
+ llvm::dyn_cast<CondOp>(originLoop.condOp1).condCode(), res, originLoop.limit, tb, fb, (epilogue_loop_header));
|
||
|
||
baseSsa.SetCurrentDef(res);
|
||
defs_map.emplace(epilogue_loop_header, res);
|
||
}
|
||
|
||
-static void
|
||
-create_epilogue_loop_body_bb(Block *epilogue_loop_body_bb, Block* after_bb, Block* dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block* tb, Block* fb)
|
||
+static void create_epilogue_loop_body_bb(Block *epilogue_loop_body_bb, Block* after_bb, Block* dominator_bb,
|
||
+ LoopOp *outer, FunctionOp *funcOp, Block* tb, Block* fb)
|
||
{
|
||
-
|
||
AssignOp g;
|
||
CondOp cond_stmt;
|
||
Value lhs1, lhs2, lhs3;
|
||
@@ -1368,30 +1335,35 @@ create_epilogue_loop_body_bb(Block *epilogue_loop_body_bb, Block* after_bb, Bloc
|
||
SSAOp baseSsa = dyn_cast<mlir::Plugin::SSAOp>(originLoop.base.getDefiningOp());
|
||
Value entry_node = baseSsa.GetCurrentDef();
|
||
|
||
-
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(epilogue_loop_body_bb), outer->idAttr().getInt());
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(epilogue_loop_body_bb), pluginAPI.FindBasicBlock(dominator_bb));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(epilogue_loop_body_bb),
|
||
+ pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
opBuilder->setInsertionPointToStart(epilogue_loop_body_bb);
|
||
llvm::SmallVector<mlir::Value> ops;
|
||
|
||
- PluginIR::PluginTypeBase sizeType = PluginIR::PluginIntegerType::get(context, 64, PluginIR::PluginIntegerType::Unsigned);
|
||
+ PluginIR::PluginTypeBase sizeType = PluginIR::PluginIntegerType::get(context, 64,
|
||
+ PluginIR::PluginIntegerType::Unsigned);
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, sizeType));
|
||
ops.push_back(entry_node);
|
||
- AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::Nop, (epilogue_loop_body_bb));
|
||
+ AssignOp op1 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::Nop, (epilogue_loop_body_bb));
|
||
lhs1 = op1.GetLHS();
|
||
ops.clear();
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, originLoop.arr1.getType()));
|
||
ops.push_back(originLoop.arr1);
|
||
ops.push_back(lhs1);
|
||
- AssignOp op2 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::PtrPlus, (epilogue_loop_body_bb));
|
||
+ AssignOp op2 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::PtrPlus, (epilogue_loop_body_bb));
|
||
lhs2 = op2.GetLHS();
|
||
|
||
ops.clear();
|
||
- PluginIR::PluginTypeBase charType = PluginIR::PluginIntegerType::get(context, 8, PluginIR::PluginIntegerType::Unsigned);
|
||
+ PluginIR::PluginTypeBase charType = PluginIR::PluginIntegerType::get(context, 8,
|
||
+ PluginIR::PluginIntegerType::Unsigned);
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, charType));
|
||
- ops.push_back(pluginAPI.BuildMemRef(charType, lhs2, ConstOp::CreateConst(*opBuilder, opBuilder->getI64IntegerAttr(0), lhs2.getType())));
|
||
+ ops.push_back(pluginAPI.BuildMemRef(charType, lhs2,
|
||
+ ConstOp::CreateConst(*opBuilder, opBuilder->getI64IntegerAttr(0), lhs2.getType())));
|
||
g = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::UNDEF, (epilogue_loop_body_bb));
|
||
|
||
lhs2 = g.GetLHS();
|
||
@@ -1400,37 +1372,37 @@ create_epilogue_loop_body_bb(Block *epilogue_loop_body_bb, Block* after_bb, Bloc
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, originLoop.arr2.getType()));
|
||
ops.push_back(originLoop.arr2);
|
||
ops.push_back(lhs1);
|
||
- AssignOp op3 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::PtrPlus, (epilogue_loop_body_bb));
|
||
+ AssignOp op3 = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops,
|
||
+ IExprCode::PtrPlus, (epilogue_loop_body_bb));
|
||
lhs3 = op3.GetLHS();
|
||
|
||
ops.clear();
|
||
|
||
ops.push_back(SSAOp::MakeSSA(*opBuilder, charType));
|
||
- ops.push_back(pluginAPI.BuildMemRef(charType, lhs3, ConstOp::CreateConst(*opBuilder, opBuilder->getI64IntegerAttr(0), lhs3.getType())));
|
||
+ ops.push_back(pluginAPI.BuildMemRef(charType, lhs3, ConstOp::CreateConst(*opBuilder,
|
||
+ opBuilder->getI64IntegerAttr(0), lhs3.getType())));
|
||
g = opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::UNDEF, (epilogue_loop_body_bb));
|
||
|
||
Value res = g.GetLHS();
|
||
- cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(), llvm::dyn_cast<CondOp>(originLoop.condOp1).condCode(), res, originLoop.limit, tb, fb, (epilogue_loop_body_bb));
|
||
+ cond_stmt = opBuilder->create<CondOp>(opBuilder->getUnknownLoc(),
|
||
+ llvm::dyn_cast<CondOp>(originLoop.condOp1).condCode(), res, originLoop.limit, tb, fb, (epilogue_loop_body_bb));
|
||
|
||
defs_map.emplace(epilogue_loop_body_bb, baseSsa.GetCurrentDef());
|
||
}
|
||
|
||
-static void
|
||
-create_epilogue_loop_latch(Block *epilogue_loop_latch,
|
||
- Block *after_bb, Block *dominator_bb,
|
||
- LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
+static void create_epilogue_loop_latch(Block *epilogue_loop_latch,
|
||
+ Block *after_bb, Block *dominator_bb, LoopOp *outer, FunctionOp *funcOp, Block *ftBB)
|
||
{
|
||
-
|
||
Value res;
|
||
ControlFlowAPI cfAPI;
|
||
PluginServerAPI pluginAPI;
|
||
SSAOp baseSsa = dyn_cast<mlir::Plugin::SSAOp>(originLoop.base.getDefiningOp());
|
||
Value entry_node = baseSsa.GetCurrentDef();
|
||
|
||
-
|
||
pluginAPI.AddBlockToLoop(pluginAPI.FindBasicBlock(epilogue_loop_latch), outer->idAttr().getInt());
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(epilogue_loop_latch), pluginAPI.FindBasicBlock(dominator_bb));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(epilogue_loop_latch),
|
||
+ pluginAPI.FindBasicBlock(dominator_bb));
|
||
|
||
SSAOp entrySsa = dyn_cast<mlir::Plugin::SSAOp>(entry_node.getDefiningOp());
|
||
res = entrySsa.Copy();
|
||
@@ -1439,7 +1411,8 @@ create_epilogue_loop_latch(Block *epilogue_loop_latch,
|
||
llvm::SmallVector<mlir::Value> ops;
|
||
ops.push_back(res);
|
||
ops.push_back(entry_node);
|
||
- ops.push_back(ConstOp::CreateConst(*opBuilder, opBuilder->getI64IntegerAttr(originLoop.step), entry_node.getType()));
|
||
+ ops.push_back(ConstOp::CreateConst(*opBuilder,
|
||
+ opBuilder->getI64IntegerAttr(originLoop.step), entry_node.getType()));
|
||
opBuilder->create<AssignOp>(opBuilder->getUnknownLoc(), ops, IExprCode::Plus, (epilogue_loop_latch));
|
||
|
||
opBuilder->create<FallThroughOp>(opBuilder->getUnknownLoc(), pluginAPI.FindBasicBlock(epilogue_loop_latch), ftBB);
|
||
@@ -1447,8 +1420,7 @@ create_epilogue_loop_latch(Block *epilogue_loop_latch,
|
||
defs_map.emplace(epilogue_loop_latch, res);
|
||
}
|
||
|
||
-static void
|
||
-create_new_loops(edge entryEdge, FunctionOp *funcOp)
|
||
+static void create_new_loops(edge entryEdge, FunctionOp *funcOp)
|
||
{
|
||
Block* prolog_bb;
|
||
Block* align_loop_header, *align_loop_latch, *align_loop_body_bb;
|
||
@@ -1461,78 +1433,97 @@ create_new_loops(edge entryEdge, FunctionOp *funcOp)
|
||
ControlFlowAPI cfAPI;
|
||
LoopOp outer = pluginAPI.GetBlockLoopFather(pluginAPI.FindBasicBlock(entryEdge.src));
|
||
|
||
- uint64_t bbAddr = cfAPI.CreateBlock(entryEdge.src, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(entryEdge.src));
|
||
+ uint64_t bbAddr = cfAPI.CreateBlock(entryEdge.src, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(entryEdge.src));
|
||
prolog_bb = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(prolog_bb, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(prolog_bb));
|
||
- // pluginAPI.InsertCreatedBlock(bbAddr, prolog_bb);
|
||
+ bbAddr = cfAPI.CreateBlock(prolog_bb, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(prolog_bb));
|
||
align_pred_bb = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(align_pred_bb, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(align_pred_bb));
|
||
+ bbAddr = cfAPI.CreateBlock(align_pred_bb, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(align_pred_bb));
|
||
align_loop_header = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(align_loop_header, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(align_loop_header));
|
||
+ bbAddr = cfAPI.CreateBlock(align_loop_header, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(align_loop_header));
|
||
align_loop_body_bb = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(align_loop_body_bb, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(align_loop_body_bb));
|
||
+ bbAddr = cfAPI.CreateBlock(align_loop_body_bb, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(align_loop_body_bb));
|
||
align_loop_latch = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(align_loop_body_bb, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(align_loop_body_bb));
|
||
+ bbAddr = cfAPI.CreateBlock(align_loop_body_bb, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(align_loop_body_bb));
|
||
align_loop_exit_bb = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(align_loop_header, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(align_loop_header));
|
||
+ bbAddr = cfAPI.CreateBlock(align_loop_header, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(align_loop_header));
|
||
epilogue_loop_pred_bb = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(epilogue_loop_pred_bb, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(epilogue_loop_pred_bb));
|
||
+ bbAddr = cfAPI.CreateBlock(epilogue_loop_pred_bb, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(epilogue_loop_pred_bb));
|
||
epilogue_loop_header = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(epilogue_loop_header, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(epilogue_loop_header));
|
||
+ bbAddr = cfAPI.CreateBlock(epilogue_loop_header, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(epilogue_loop_header));
|
||
epilogue_loop_body_bb = pluginAPI.FindBlock(bbAddr);
|
||
|
||
- bbAddr = cfAPI.CreateBlock(epilogue_loop_body_bb, funcOp->idAttr().getInt(), pluginAPI.FindBasicBlock(epilogue_loop_body_bb));
|
||
+ bbAddr = cfAPI.CreateBlock(epilogue_loop_body_bb, funcOp->idAttr().getInt(),
|
||
+ pluginAPI.FindBasicBlock(epilogue_loop_body_bb));
|
||
epilogue_loop_latch = pluginAPI.FindBlock(bbAddr);
|
||
|
||
create_prolog_bb(prolog_bb, entryEdge.src, entryEdge.src, &outer, entryEdge, funcOp, align_pred_bb);
|
||
|
||
create_loop_pred_bb(align_pred_bb, prolog_bb, prolog_bb, &outer, funcOp, align_loop_header);
|
||
|
||
- create_align_loop_header(align_loop_header, align_pred_bb, align_pred_bb, &outer, funcOp, align_loop_body_bb, epilogue_loop_pred_bb);
|
||
+ create_align_loop_header(align_loop_header, align_pred_bb, align_pred_bb, &outer,
|
||
+ funcOp, align_loop_body_bb, epilogue_loop_pred_bb);
|
||
|
||
- create_align_loop_body_bb(align_loop_body_bb, align_loop_header, align_loop_header, &outer, funcOp, align_loop_exit_bb, align_loop_latch);
|
||
+ create_align_loop_body_bb(align_loop_body_bb, align_loop_header, align_loop_header, &outer,
|
||
+ funcOp, align_loop_exit_bb, align_loop_latch);
|
||
|
||
- create_align_loop_latch(align_loop_latch, align_loop_body_bb, align_loop_body_bb, &outer, funcOp, align_loop_header);
|
||
+ create_align_loop_latch(align_loop_latch, align_loop_body_bb, align_loop_body_bb, &outer,
|
||
+ funcOp, align_loop_header);
|
||
|
||
rewrite_add_phi_arg(align_loop_header);
|
||
|
||
align_loop = init_new_loop(&outer, align_loop_header, align_loop_latch, funcOp);
|
||
|
||
- create_align_loop_exit_bb(align_loop_exit_bb, align_loop_body_bb, align_loop_body_bb, &outer, funcOp, originLoop.exitBB1);
|
||
+ create_align_loop_exit_bb(align_loop_exit_bb, align_loop_body_bb, align_loop_body_bb, &outer,
|
||
+ funcOp, originLoop.exitBB1);
|
||
|
||
- create_loop_pred_bb(epilogue_loop_pred_bb, align_loop_header, align_loop_header, &outer, funcOp, epilogue_loop_header);
|
||
+ create_loop_pred_bb(epilogue_loop_pred_bb, align_loop_header, align_loop_header, &outer,
|
||
+ funcOp, epilogue_loop_header);
|
||
|
||
- create_epilogue_loop_header(epilogue_loop_header, epilogue_loop_pred_bb, epilogue_loop_pred_bb, &outer, funcOp, epilogue_loop_body_bb, originLoop.exitBB1);
|
||
+ create_epilogue_loop_header(epilogue_loop_header, epilogue_loop_pred_bb, epilogue_loop_pred_bb, &outer,
|
||
+ funcOp, epilogue_loop_body_bb, originLoop.exitBB1);
|
||
|
||
- create_epilogue_loop_body_bb(epilogue_loop_body_bb, epilogue_loop_header, epilogue_loop_header, &outer, funcOp, originLoop.exitBB1 , epilogue_loop_latch);
|
||
+ create_epilogue_loop_body_bb(epilogue_loop_body_bb, epilogue_loop_header, epilogue_loop_header, &outer,
|
||
+ funcOp, originLoop.exitBB1, epilogue_loop_latch);
|
||
|
||
- create_epilogue_loop_latch(epilogue_loop_latch, epilogue_loop_body_bb, epilogue_loop_body_bb, &outer, funcOp, epilogue_loop_header);
|
||
+ create_epilogue_loop_latch(epilogue_loop_latch, epilogue_loop_body_bb, epilogue_loop_body_bb, &outer,
|
||
+ funcOp, epilogue_loop_header);
|
||
|
||
rewrite_add_phi_arg(epilogue_loop_header);
|
||
|
||
epilogue_loop = init_new_loop(&outer, epilogue_loop_header, epilogue_loop_latch, funcOp);
|
||
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(originLoop.exitBB1), pluginAPI.FindBasicBlock(entryEdge.src));
|
||
- cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(originLoop.exitBB2), pluginAPI.FindBasicBlock(entryEdge.src));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(originLoop.exitBB1),
|
||
+ pluginAPI.FindBasicBlock(entryEdge.src));
|
||
+ cfAPI.SetImmediateDominator(1, pluginAPI.FindBasicBlock(originLoop.exitBB2),
|
||
+ pluginAPI.FindBasicBlock(entryEdge.src));
|
||
|
||
rewrite_add_phi_arg(originLoop.exitBB1);
|
||
rewrite_add_phi_arg(originLoop.exitBB2);
|
||
|
||
- cfAPI.RemoveEdge(pluginAPI.FindBasicBlock(originLoop.exitE1.src), pluginAPI.FindBasicBlock(originLoop.exitE1.dest));
|
||
- cfAPI.RemoveEdge(pluginAPI.FindBasicBlock(originLoop.exitE2.src), pluginAPI.FindBasicBlock(originLoop.exitE2.dest));
|
||
+ cfAPI.RemoveEdge(pluginAPI.FindBasicBlock(originLoop.exitE1.src),
|
||
+ pluginAPI.FindBasicBlock(originLoop.exitE1.dest));
|
||
+ cfAPI.RemoveEdge(pluginAPI.FindBasicBlock(originLoop.exitE2.src),
|
||
+ pluginAPI.FindBasicBlock(originLoop.exitE2.dest));
|
||
}
|
||
|
||
-
|
||
-static void
|
||
-convertToNewLoop(LoopOp* loop, FunctionOp* funcOp)
|
||
+static void convertToNewLoop(LoopOp* loop, FunctionOp* funcOp)
|
||
{
|
||
ControlFlowAPI cfAPI;
|
||
create_new_loops(originLoop.entryEdge, funcOp);
|
||
@@ -1542,9 +1533,7 @@ convertToNewLoop(LoopOp* loop, FunctionOp* funcOp)
|
||
return;
|
||
}
|
||
|
||
-
|
||
-static void
|
||
-ProcessArrayWiden(void)
|
||
+static void ProcessArrayWiden(void)
|
||
{
|
||
std::cout << "Running first pass, awiden\n";
|
||
|
||
@@ -1567,13 +1556,33 @@ 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)
|
||
{
|
||
- PluginServer::GetInstance()->RegisterUserFunc(HANDLE_BEFORE_IPA, UserOptimizeFunc);
|
||
- PluginServer::GetInstance()->RegisterUserFunc(HANDLE_BEFORE_IPA, LocalVarSummery);
|
||
- // ManagerSetupData setupData;
|
||
- // setupData.refPassName = PASS_PHIOPT;
|
||
- // setupData.passNum = 1;
|
||
- // setupData.passPosition = PASS_INSERT_AFTER;
|
||
- // PluginServer::GetInstance()->RegisterPassManagerSetup(HANDLE_MANAGER_SETUP, setupData, ProcessArrayWiden);
|
||
+ 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>());
|
||
}
|
||
--
|
||
2.33.0
|
||
|