加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0010-Pin-server-Add-ComponentOp-ConstructorOp-AddressOp-F.patch 35.76 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
From b460122fefb5d4f889c807b704f252948d488893 Mon Sep 17 00:00:00 2001
From: huitailangzju <804544223@qq.com>
Date: Wed, 22 Feb 2023 11:42:02 +0800
Subject: [PATCH 10/23] =?UTF-8?q?[Pin-server]=20Add=20ComponentOp=E3=80=81?=
=?UTF-8?q?ConstructorOp=E3=80=81AddressOp=E3=80=81FieldDeclOp=E3=80=81Vec?=
=?UTF-8?q?Op=E3=80=81BlockOp=E3=80=81DeclBaseOp=E3=80=81ListOp=E3=80=81St?=
=?UTF-8?q?rOp=E3=80=81ArrayOp.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
diff --git a/include/Dialect/PluginDialect.td b/include/Dialect/PluginDialect.td
index d7db477..98a84d0 100644
--- a/include/Dialect/PluginDialect.td
+++ b/include/Dialect/PluginDialect.td
@@ -68,10 +68,22 @@ def IComparisonAttr : I32EnumAttr<
def IDefineCodeMemRef : I32EnumAttrCase<"MemRef", 0>;
def IDefineCodeIntCST : I32EnumAttrCase<"IntCST", 1>;
def IDefineCodeSSA : I32EnumAttrCase<"SSA", 2>;
-def IDefineCodeUNDEF : I32EnumAttrCase<"UNDEF", 3>;
+def IDefineCodeTREELIST : I32EnumAttrCase<"TREELIST", 3>;
+def IDefineCodeStrCST : I32EnumAttrCase<"StrCST", 4>;
+def IDefineCodeArrayRef : I32EnumAttrCase<"ArrayRef", 5>;
+def IDefineCodeDecl : I32EnumAttrCase<"Decl", 6>;
+def IDefineCodeFieldDecl : I32EnumAttrCase<"FieldDecl", 7>;
+def IDefineCodeAddrExp : I32EnumAttrCase<"AddrExp", 8>;
+def IDefineCodeConstructor : I32EnumAttrCase<"Constructor", 9>;
+def IDefineCodeVec : I32EnumAttrCase<"Vec", 10>;
+def IDefineCodeBLOCK : I32EnumAttrCase<"BLOCK", 11>;
+def IDefineCodeCOMPONENT : I32EnumAttrCase<"COMPONENT", 12>;
+def IDefineCodeUNDEF : I32EnumAttrCase<"UNDEF", 13>;
def IDefineCodeAttr : I32EnumAttr<
"IDefineCode", "plugin define code",
- [IDefineCodeMemRef, IDefineCodeIntCST, IDefineCodeSSA, IDefineCodeUNDEF]>{
+ [IDefineCodeMemRef, IDefineCodeIntCST, IDefineCodeSSA, IDefineCodeTREELIST,
+ IDefineCodeStrCST, IDefineCodeArrayRef, IDefineCodeDecl, IDefineCodeFieldDecl, IDefineCodeAddrExp,
+ IDefineCodeConstructor, IDefineCodeVec, IDefineCodeBLOCK, IDefineCodeCOMPONENT, IDefineCodeUNDEF]>{
let cppNamespace = "::mlir::Plugin";
}
diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td
index 3a88846..4967e91 100644
--- a/include/Dialect/PluginOps.td
+++ b/include/Dialect/PluginOps.td
@@ -166,7 +166,7 @@ def AssignOp : Plugin_Op<"assign", [NoSideEffect]> {
}];
}
-class Placeholder<string mnemonic> : Plugin_Op<mnemonic, [NoSideEffect]> {
+class Placeholder<string mnemonic> : Plugin_Op<mnemonic, [SameVariadicOperandSize]> {
dag commonArgs = (ins UI64Attr:$id,
OptionalAttr<IDefineCodeAttr>:$defCode,
OptionalAttr<BoolAttr>:$readOnly);
@@ -201,6 +201,61 @@ class Constant<string mnemonic> : Placeholder<mnemonic> {
let arguments = !con(commonArgs, ConstArgs);
}
+class List<string mnemonic> : Placeholder<mnemonic> {
+ dag ListArgs = (ins BoolAttr:$hasPurpose,
+ Variadic<AnyType>:$operands);
+ let arguments = !con(commonArgs, ListArgs);
+}
+
+class ComponentRef<string mnemonic> : Placeholder<mnemonic> {
+ dag ComponentRefArgs = (ins AnyType:$component,
+ AnyType:$field);
+ let arguments = !con(commonArgs, ComponentRefArgs);
+}
+
+class StringCST<string mnemonic> : Placeholder<mnemonic> {
+ dag StringArgs = (ins StrAttr:$str);
+ let arguments = !con(commonArgs, StringArgs);
+}
+
+class ArrayRef<string mnemonic> : Placeholder<mnemonic> {
+ dag ArrayRefArgs = (ins AnyType:$base,
+ AnyType:$offset);
+ let arguments = !con(commonArgs, ArrayRefArgs);
+}
+
+class DeclBase<string mnemonic> : Placeholder<mnemonic> {
+ dag DeclBaseArgs = (ins BoolAttr:$addressable, BoolAttr:$used, I32Attr:$uid,
+ AnyType:$initial, AnyType:$name, OptionalAttr<I64Attr>:$chain);
+ let arguments = !con(commonArgs, DeclBaseArgs);
+}
+
+class FieldDecl<string mnemonic> : DeclBase<mnemonic> {
+ dag FieldDeclArgs = (ins AnyType:$fieldOffset, AnyType:$fieldBitOffset);
+ let arguments = !con(commonArgs, DeclBaseArgs, FieldDeclArgs);
+}
+
+class Address<string mnemonic> : Placeholder<mnemonic> {
+ dag AddressArgs = (ins AnyType:$operand);
+ let arguments = !con(commonArgs, AddressArgs);
+}
+
+class Constructor<string mnemonic> : Placeholder<mnemonic> {
+ dag ConstructorArgs = (ins I32Attr:$len, Variadic<AnyType>:$idx, Variadic<AnyType>:$val);
+ let arguments = !con(commonArgs, ConstructorArgs);
+}
+
+class Vec<string mnemonic> : Placeholder<mnemonic> {
+ dag VecArgs = (ins I32Attr:$len, Variadic<AnyType>:$elements);
+ let arguments = !con(commonArgs, VecArgs);
+}
+
+class BLOCK<string mnemonic> : Placeholder<mnemonic> {
+ dag BLOCKArgs = (ins I32Attr:$len, Optional<AnyType>:$vars, OptionalAttr<I64Attr>:$supercontext,
+ Optional<AnyType>:$subblocks, Optional<AnyType>:$chain, Optional<AnyType>:$abstract_origin);
+ let arguments = !con(commonArgs, BLOCKArgs);
+}
+
def PlaceholderOp : Placeholder<"palceholder"> {
let summary = "PlaceHolder";
let description = [{TODO}];
@@ -210,6 +265,110 @@ def PlaceholderOp : Placeholder<"palceholder"> {
];
}
+def DeclBaseOp : DeclBase<"decl"> {
+ let summary = "DeclBaseOp";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode,
+ "bool":$readOnly, "bool":$addressable, "bool":$used, "int":$uid, "Value":$initial,
+ "Value":$name, "Optional<uint64_t>":$chain, "Type":$retType)>
+ ];
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ Value GetInitial() { return initial(); }
+ Value GetName() { return name(); }
+ Optional<uint64_t> GetChain() { return chain(); }
+ }];
+}
+
+def BlockOp : BLOCK<"block"> {
+ let summary = "BlockOp";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode,
+ "bool":$readOnly, "Optional<Value>":$vars, "Optional<uint64_t>":$supercontext,
+ "Optional<Value>":$subblocks, "Optional<Value>":$chain,
+ "Optional<Value>":$abstract_origin, "Type":$retType)>
+ ];
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ Value GetVars() { return vars(); }
+ Optional<uint64_t> GetSupercontext() { return supercontext(); }
+ Value GetSubblocks() { return subblocks(); }
+ Value GetChain() { return chain(); }
+ Value GetAbstractorigin() { return abstract_origin(); }
+ }];
+}
+
+def VecOp : Vec<"treevector"> {
+ let summary = "VectorOp";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode,
+ "bool":$readOnly, "int":$len, "ArrayRef<Value>":$elements, "Type":$retType)>
+ ];
+}
+
+def FieldDeclOp : FieldDecl<"field"> {
+ let summary = "FieldDeclOp";
+ let description = [{TODO}];
+
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode,
+ "bool":$readOnly, "bool":$addressable, "bool":$used, "int":$uid, "Value":$initial,
+ "Value":$name, "uint64_t":$chain, "Value":$fieldOffset, "Value":$fieldBitOffset, "Type":$retType)>
+];
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ Value GetInitial() { return initial(); }
+ Value GetName() { return name(); }
+ Optional<uint64_t> GetChain() { return chain(); }
+ Value GetFieldOffset() { return fieldOffset(); }
+ Value GetFieldBitOffset() { return fieldBitOffset(); }
+ }];
+}
+
+def AddressOp : Address<"address"> {
+ let summary = "AddressOp";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode,
+ "bool":$readOnly, "Value":$operand, "Type":$retType)>
+];
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ Value GetOperand() { return operand(); }
+ }];
+}
+
+def ConstructorOp : Constructor<"constructor"> {
+ let summary = "ConstructorOp";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode,
+ "bool":$readOnly, "int32_t":$len, "ArrayRef<Value>":$idx, "ArrayRef<Value>":$val,
+ "Type":$retType)>
+];
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ }];
+}
+
+def ComponentOp : ComponentRef<"component"> {
+ let summary = "Component reference op";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode, "bool":$readOnly,
+ "Value":$component, "Value":$field, "Type":$retType)>
+ ];
+ let results = (outs AnyType);
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ Value GetComponent() { return getOperand(0); }
+ Value GetField() { return getOperand(1); }
+ }];
+}
+
def PointerOp : Pointer<"pointer"> {
let summary = "pointer";
let description = [{TODO}];
@@ -266,6 +425,42 @@ def ConstOp : Constant<"constant value"> {
}];
}
+def ListOp : List<"tree list"> {
+ let summary = "tree list";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode, "bool":$readOnly,
+ "bool":$hasPurpose, "ArrayRef<Value>":$operands, "Type":$retType)>
+ ];
+ let results = (outs AnyType);
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ }];
+}
+
+def StrOp : StringCST<"string"> {
+ let summary = "string";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode, "bool":$readOnly,"StringRef":$str, "Type":$retType)>
+ ];
+}
+
+def ArrayOp : ArrayRef<"array ref"> {
+ let summary = "array ref";
+ let description = [{TODO}];
+ let builders = [
+ OpBuilderDAG<(ins "uint64_t":$id, "IDefineCode":$defCode, "bool":$readOnly,
+ "Value":$base, "Value":$offset, "Type":$retType)>
+ ];
+ let results = (outs AnyType);
+ let extraClassDeclaration = [{
+ Type getResultType() { return this->getOperation()->getResult(0).getType(); }
+ Value GetBase() { return getOperand(0); }
+ Value GetOffset() { return getOperand(1); }
+ }];
+}
+
def BaseOp : Plugin_Op<"statement_base", [NoSideEffect]> {
let summary = "Base operation, just like placeholder for statement.";
let description = [{TODO}];
diff --git a/include/PluginServer/PluginJson.h b/include/PluginServer/PluginJson.h
index 6f46187..4be2ae2 100755
--- a/include/PluginServer/PluginJson.h
+++ b/include/PluginServer/PluginJson.h
@@ -50,6 +50,16 @@ public:
void GetPhiOpsJsonDeSerialize(const string&, vector<mlir::Operation *>&);
mlir::Value SSAOpJsonDeSerialize(const string& data);
mlir::Plugin::LoopOp LoopOpJsonDeSerialize(const string& data);
+ mlir::Value ListOpDeSerialize(const string& data);
+ mlir::Value StrOpJsonDeSerialize(const string& data);
+ mlir::Value ArrayOpJsonDeSerialize(const string& data);
+ mlir::Value DeclBaseOpJsonDeSerialize(const string& data);
+ mlir::Value FieldDeclOpJsonDeSerialize(const string& data);
+ mlir::Value AddressOpJsonDeSerialize(const string& data);
+ mlir::Value ConstructorOpJsonDeSerialize(const string& data);
+ mlir::Value VecOpJsonDeSerialize(const string& data);
+ mlir::Value BlockOpJsonDeSerialize(const string& data);
+ mlir::Value ComponentOpJsonDeSerialize(const string& data);
PluginIR::PluginTypeBase TypeJsonDeSerialize(const string& data);
void OpJsonDeSerialize(const string&, vector<mlir::Operation *>&);
/* 将整形数据反序列化 */
diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp
index a30e9ed..c8714f6 100644
--- a/lib/Dialect/PluginOps.cpp
+++ b/lib/Dialect/PluginOps.cpp
@@ -44,6 +44,26 @@ static uint64_t GetValueId(Value v)
return ssaOp.id();
} else if (auto cstOp = dyn_cast<ConstOp>(op)) {
return cstOp.id();
+ } else if (auto treelistop = dyn_cast<ListOp>(op)) {
+ return treelistop.id();
+ } else if (auto strop = dyn_cast<StrOp>(op)) {
+ return strop.id();
+ } else if (auto arrayop = dyn_cast<ArrayOp>(op)) {
+ return arrayop.id();
+ } else if (auto declop = dyn_cast<DeclBaseOp>(op)) {
+ return declop.id();
+ } else if (auto fieldop = dyn_cast<FieldDeclOp>(op)) {
+ return fieldop.id();
+ } else if (auto addressop = dyn_cast<AddressOp>(op)) {
+ return addressop.id();
+ } else if (auto constructorop = dyn_cast<ConstructorOp>(op)) {
+ return constructorop.id();
+ } else if (auto vecop = dyn_cast<VecOp>(op)) {
+ return vecop.id();
+ } else if (auto blockop = dyn_cast<BlockOp>(op)) {
+ return blockop.id();
+ } else if (auto compOp = dyn_cast<ComponentOp>(op)) {
+ return compOp.id();
} else if (auto phOp = dyn_cast<PlaceholderOp>(op)) {
return phOp.id();
}
@@ -249,7 +269,143 @@ void MemOp::build(OpBuilder &builder, OperationState &state,
if (retType) state.addTypes(retType);
}
-// ===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+// DeclBaseOp
+
+void DeclBaseOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, bool addressable, bool used, int32_t uid, Value initial,
+ Value name, Optional<uint64_t> chain, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addAttribute("addressable", builder.getBoolAttr(addressable));
+ state.addAttribute("used", builder.getBoolAttr(used));
+ state.addAttribute("uid", builder.getI32IntegerAttr(uid));
+ state.addOperands(initial);
+ if(chain) {
+ state.addAttribute("chain", builder.getI64IntegerAttr(chain.getValue()));
+ }
+ state.addOperands(name);
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// BlockOp
+
+void BlockOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, Optional<Value> vars, Optional<uint64_t> supercontext,
+ Optional<Value> subblocks, Optional<Value> abstract_origin, Optional<Value> chain, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ if(vars) {
+ state.addOperands(vars.getValue());
+ }
+ if(supercontext) {
+ state.addAttribute("supercontext", builder.getI64IntegerAttr(supercontext.getValue()));
+ }
+ if(subblocks) {
+ state.addOperands(subblocks.getValue());
+ }
+ if(abstract_origin) {
+ state.addOperands(abstract_origin.getValue());
+ }
+ if(chain) {
+ state.addOperands(chain.getValue());
+ }
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// ComponentOp
+
+void ComponentOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id, IDefineCode defCode, bool readOnly,
+ Value component, Value field, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+
+ state.addOperands({component, field});
+ if (retType) state.addTypes(retType);
+}
+//===----------------------------------------------------------------------===//
+// VecOp
+
+void VecOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, int32_t len, ArrayRef<Value> elements, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addAttribute("len", builder.getI32IntegerAttr(len));
+ state.addOperands(elements);
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// ConstructorOp
+
+void ConstructorOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, int32_t len, ArrayRef<Value> idx,
+ ArrayRef<Value> val, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addAttribute("len", builder.getI32IntegerAttr(len));
+ state.addOperands(idx);
+ state.addOperands(val);
+
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// FieldDeclOp
+
+void FieldDeclOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, bool addressable, bool used, int32_t uid, Value initial,
+ Value name, uint64_t chain, Value fieldOffset, Value fieldBitOffset, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addAttribute("addressable", builder.getBoolAttr(addressable));
+ state.addAttribute("used", builder.getBoolAttr(used));
+ state.addAttribute("uid", builder.getI32IntegerAttr(uid));
+ state.addOperands(initial);
+ if(chain) {
+ state.addAttribute("chain", builder.getI64IntegerAttr(chain));
+ }
+ state.addOperands(name);
+ state.addOperands({fieldOffset, fieldBitOffset});
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// AddressOp
+
+void AddressOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, Value operand, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addOperands(operand);
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
// SSAOp
void SSAOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
@@ -345,8 +501,49 @@ void PointerOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
state.addAttribute("pointeeReadOnly", builder.getBoolAttr(pointeeReadOnly));
}
-// ===----------------------------------------------------------------------===//
-// CallOp
+//===----------------------------------------------------------------------===//
+// ListOp
+
+void ListOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, bool hasPurpose,
+ ArrayRef<Value> operands, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addAttribute("hasPurpose", builder.getBoolAttr(hasPurpose));
+ state.addOperands(operands);
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// StrOp
+void StrOp::build(OpBuilder &builder, OperationState &state, uint64_t id,
+ IDefineCode defCode, bool readOnly, StringRef str, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ state.addAttribute("str", builder.getStringAttr(str));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addTypes(retType);
+}
+
+//===----------------------------------------------------------------------===//
+// ArrayOp
+
+void ArrayOp::build(OpBuilder &builder, OperationState &state,
+ uint64_t id, IDefineCode defCode, bool readOnly,
+ Value addr, Value offset, Type retType)
+{
+ state.addAttribute("id", builder.getI64IntegerAttr(id));
+ state.addAttribute("readOnly", builder.getBoolAttr(readOnly));
+ state.addOperands({addr, offset});
+ state.addAttribute("defCode",
+ builder.getI32IntegerAttr(static_cast<int32_t>(defCode)));
+ if (retType) state.addTypes(retType);
+}
void CallOp::build(OpBuilder &builder, OperationState &state,
int64_t id, StringRef callee,
diff --git a/lib/PluginAPI/ControlFlowAPI.cpp b/lib/PluginAPI/ControlFlowAPI.cpp
index 92c0dd3..b2ed38d 100644
--- a/lib/PluginAPI/ControlFlowAPI.cpp
+++ b/lib/PluginAPI/ControlFlowAPI.cpp
@@ -29,6 +29,26 @@ static uint64_t GetValueId(mlir::Value v)
return ssaOp.id();
} else if (auto cstOp = llvm::dyn_cast<ConstOp>(op)) {
return cstOp.id();
+ } else if (auto treelistop = llvm::dyn_cast<ListOp>(op)) {
+ return treelistop.id();
+ } else if (auto strop = llvm::dyn_cast<StrOp>(op)) {
+ return strop.id();
+ } else if (auto arrayop = llvm::dyn_cast<ArrayOp>(op)) {
+ return arrayop.id();
+ } else if (auto declop = llvm::dyn_cast<DeclBaseOp>(op)) {
+ return declop.id();
+ } else if (auto fieldop = llvm::dyn_cast<FieldDeclOp>(op)) {
+ return fieldop.id();
+ } else if (auto addressop = llvm::dyn_cast<AddressOp>(op)) {
+ return addressop.id();
+ } else if (auto constructorop = llvm::dyn_cast<ConstructorOp>(op)) {
+ return constructorop.id();
+ } else if (auto vecop = llvm::dyn_cast<VecOp>(op)) {
+ return vecop.id();
+ } else if (auto blockop = llvm::dyn_cast<BlockOp>(op)) {
+ return blockop.id();
+ } else if (auto compop = llvm::dyn_cast<ComponentOp>(op)) {
+ return compop.id();
} else if (auto phOp = llvm::dyn_cast<PlaceholderOp>(op)) {
return phOp.id();
}
diff --git a/lib/PluginAPI/PluginServerAPI.cpp b/lib/PluginAPI/PluginServerAPI.cpp
index f81a3ad..01a799b 100644
--- a/lib/PluginAPI/PluginServerAPI.cpp
+++ b/lib/PluginAPI/PluginServerAPI.cpp
@@ -50,6 +50,26 @@ static uint64_t GetValueId(mlir::Value v)
return ssaOp.id();
} else if (auto cstOp = llvm::dyn_cast<ConstOp>(op)) {
return cstOp.id();
+ } else if (auto treelistop = llvm::dyn_cast<ListOp>(op)) {
+ return treelistop.id();
+ } else if (auto strop = llvm::dyn_cast<StrOp>(op)) {
+ return strop.id();
+ } else if (auto arrayop = llvm::dyn_cast<ArrayOp>(op)) {
+ return arrayop.id();
+ } else if (auto declop = llvm::dyn_cast<DeclBaseOp>(op)) {
+ return declop.id();
+ } else if (auto fieldop = llvm::dyn_cast<FieldDeclOp>(op)) {
+ return fieldop.id();
+ } else if (auto addressop = llvm::dyn_cast<AddressOp>(op)) {
+ return addressop.id();
+ } else if (auto constructorop = llvm::dyn_cast<ConstructorOp>(op)) {
+ return constructorop.id();
+ } else if (auto vecop = llvm::dyn_cast<VecOp>(op)) {
+ return vecop.id();
+ } else if (auto blockop = llvm::dyn_cast<BlockOp>(op)) {
+ return blockop.id();
+ } else if (auto compop = llvm::dyn_cast<ComponentOp>(op)) {
+ return compop.id();
} else if (auto phOp = llvm::dyn_cast<PlaceholderOp>(op)) {
return phOp.id();
}
diff --git a/lib/PluginServer/PluginJson.cpp b/lib/PluginServer/PluginJson.cpp
index 7bbf681..c5e302f 100755
--- a/lib/PluginServer/PluginJson.cpp
+++ b/lib/PluginServer/PluginJson.cpp
@@ -109,6 +109,46 @@ mlir::Value PluginJson::ValueJsonDeSerialize(Json::Value valueJson)
opValue = SSAOpJsonDeSerialize(valueJson.toStyledString());
break;
}
+ case IDefineCode::TREELIST : {
+ opValue = ListOpDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::StrCST : {
+ opValue = StrOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::ArrayRef : {
+ opValue = ArrayOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::Decl : {
+ opValue = DeclBaseOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::FieldDecl : {
+ opValue = FieldDeclOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::AddrExp : {
+ opValue = AddressOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::Constructor : {
+ opValue = ConstructorOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::Vec : {
+ opValue = VecOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::BLOCK : {
+ opValue = BlockOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
+ case IDefineCode::COMPONENT : {
+ opValue = ComponentOpJsonDeSerialize(valueJson.toStyledString());
+ break;
+ }
default: {
opValue = opBuilder->create<PlaceholderOp>(
opBuilder->getUnknownLoc(), opId, defCode, readOnly, retType);
@@ -592,6 +632,214 @@ void PluginJson::GetPhiOpsJsonDeSerialize(
}
}
+mlir::Value PluginJson::ListOpDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ bool hasPurpose = (bool)atoi(root["hasPurpose"].asString().c_str());
+ Json::Value operandJson = root["operands"];
+ Json::Value::Members operandMember = operandJson.getMemberNames();
+ llvm::SmallVector<mlir::Value, 4> ops;
+ for (size_t opIter = 0; opIter < operandMember.size(); opIter++) {
+ mlir::Value opValue = ValueJsonDeSerialize(operandJson[std::to_string(opIter).c_str()]);
+ ops.push_back(opValue);
+ }
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value trrelist = opBuilder->create<ListOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::TREELIST, readOnly, hasPurpose, ops, retType);
+ return trrelist;
+}
+
+mlir::Value PluginJson::StrOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ mlir::StringRef str(root["str"].asString());
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value strop = opBuilder->create<StrOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::StrCST, readOnly, str, retType);
+ return strop;
+}
+mlir::Value PluginJson::ArrayOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ mlir::Value base = ValueJsonDeSerialize(root["base"]);
+ mlir::Value offset = ValueJsonDeSerialize(root["offset"]);
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value arrayref = opBuilder->create<ArrayOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::ArrayRef, readOnly, base, offset, retType);
+ return arrayref;
+}
+
+mlir::Value PluginJson::DeclBaseOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ bool addressable = (bool)atoi(root["addressable"].asString().c_str());
+ bool used = (bool)atoi(root["used"].asString().c_str());
+ int32_t uid = GetID(root["uid"]);
+ mlir::Value initial = ValueJsonDeSerialize(root["initial"]);
+ mlir::Value name = ValueJsonDeSerialize(root["name"]);
+ llvm::Optional<uint64_t> chain;
+ if (root["chain"]) {
+ chain = GetID(root["chain"]);
+ }
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value declOp = opBuilder->create<DeclBaseOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::Decl, readOnly, addressable, used, uid, initial, name, chain, retType);
+ return declOp;
+}
+
+mlir::Value PluginJson::FieldDeclOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ bool addressable = (bool)atoi(root["addressable"].asString().c_str());
+ bool used = (bool)atoi(root["used"].asString().c_str());
+ int32_t uid = GetID(root["uid"]);
+ mlir::Value initial = ValueJsonDeSerialize(root["initial"]);
+ mlir::Value name = ValueJsonDeSerialize(root["name"]);
+ uint64_t chain = GetID(root["chain"]);
+ mlir::Value fieldOffset = ValueJsonDeSerialize(root["fieldOffset"]);
+ mlir::Value fieldBitOffset = ValueJsonDeSerialize(root["fieldBitOffset"]);
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value fieldOp = opBuilder->create<FieldDeclOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::FieldDecl, readOnly, addressable, used, uid, initial, name, chain,
+ fieldOffset, fieldBitOffset, retType);
+ return fieldOp;
+}
+
+mlir::Value PluginJson::AddressOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ mlir::Value operand = ValueJsonDeSerialize(root["operand"]);
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value addrOp = opBuilder->create<AddressOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::AddrExp, readOnly, operand, retType);
+ return addrOp;
+}
+
+mlir::Value PluginJson::ConstructorOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ uint64_t len = GetID(root["len"]);
+ Json::Value idxJson = root["idx"];
+ Json::Value::Members idxMember = idxJson.getMemberNames();
+ llvm::SmallVector<mlir::Value, 4> idx, val;
+ for (size_t iter = 0; iter < idxMember.size(); iter++) {
+ mlir::Value opValue = ValueJsonDeSerialize(idxJson[std::to_string(iter).c_str()]);
+ idx.push_back(opValue);
+ }
+ Json::Value valJson = root["val"];
+ Json::Value::Members valMember = valJson.getMemberNames();
+ for (size_t iter = 0; iter < valMember.size(); iter++) {
+ mlir::Value opValue = ValueJsonDeSerialize(valJson[std::to_string(iter).c_str()]);
+ val.push_back(opValue);
+ }
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value constructorOp = opBuilder->create<ConstructorOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::Constructor, readOnly, len, idx, val, retType);
+ return constructorOp;
+}
+
+mlir::Value PluginJson::VecOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ uint64_t len = GetID(root["len"]);
+ Json::Value elementsJson = root["elements"];
+ Json::Value::Members elementsMember = elementsJson.getMemberNames();
+ llvm::SmallVector<mlir::Value, 4> elements;
+ for (size_t iter = 0; iter < elementsMember.size(); iter++) {
+ mlir::Value opValue = ValueJsonDeSerialize(elementsJson[std::to_string(iter).c_str()]);
+ elements.push_back(opValue);
+ }
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value vecOp = opBuilder->create<VecOp>(opBuilder->getUnknownLoc(), id,
+ IDefineCode::Vec, readOnly, len, elements, retType);
+ return vecOp;
+}
+
+mlir::Value PluginJson::BlockOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ uint64_t supercontext = GetID(root["supercontext"]);
+ llvm::Optional<mlir::Value> vars, subblocks, chain, abstract_origin;
+ if (root["vars"]) {
+ vars = ValueJsonDeSerialize(root["vars"]);
+ }
+
+ if (root["subblocks"]) {
+ subblocks = ValueJsonDeSerialize(root["subblocks"]);
+ }
+ if (root["chain"]) {
+ chain = ValueJsonDeSerialize(root["chain"]);
+ }
+ if (root["abstract_origin"]) {
+ abstract_origin = ValueJsonDeSerialize(root["abstract_origin"]);
+ }
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value blockOp = opBuilder->create<BlockOp>(
+ opBuilder->getUnknownLoc(), id, IDefineCode::BLOCK, readOnly, vars, supercontext, subblocks,
+ chain, abstract_origin, retType);
+ return blockOp;
+}
+
+mlir::Value PluginJson::ComponentOpJsonDeSerialize(const string& data)
+{
+ Json::Value root;
+ Json::Reader reader;
+ reader.parse(data, root);
+ uint64_t id = GetID(root["id"]);
+ bool readOnly = (bool)atoi(root["readOnly"].asString().c_str());
+ mlir::Value component = ValueJsonDeSerialize(root["component"]);
+ mlir::Value field = ValueJsonDeSerialize(root["field"]);
+ mlir::Type retType = TypeJsonDeSerialize(root["retType"].toStyledString().c_str());
+ mlir::OpBuilder *opBuilder = PluginServer::GetInstance()->GetOpBuilder();
+ mlir::Value componentOp = opBuilder->create<ComponentOp>(
+ opBuilder->getUnknownLoc(), id, IDefineCode::COMPONENT, readOnly, component, field, retType);
+ return componentOp;
+}
void PluginJson::OpJsonDeSerialize(
const string& data, vector<mlir::Operation *>& opData)
{
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化