From d8c42ec77001c29291a31484031cb7b5f2b52d48 Mon Sep 17 00:00:00 2001 From: Mingchuan Wu Date: Tue, 21 Feb 2023 16:53:09 +0800 Subject: [PATCH 8/9] [Pin-gcc-client] Fix bug for BuildCallOp. Now we can convert the function pointer. diff --git a/include/Dialect/PluginOps.td b/include/Dialect/PluginOps.td index bac84be..713623c 100644 --- a/include/Dialect/PluginOps.td +++ b/include/Dialect/PluginOps.td @@ -85,12 +85,15 @@ def CallOp : Plugin_Op<"call", [ The arguments list must match the arguments expected by the callee. }]; let arguments = (ins UI64Attr:$id, - FlatSymbolRefAttr:$callee, + OptionalAttr:$callee, Variadic:$inputs); let results = (outs Optional:$result); let builders = [ OpBuilderDAG<(ins "uint64_t":$id, "StringRef":$callee, - "ArrayRef":$arguments, "Type":$retType)> + "ArrayRef":$arguments, "Type":$retType)>, + OpBuilderDAG<(ins "uint64_t":$id, + "ArrayRef":$arguments, + "Type":$retType)> ]; let extraClassDeclaration = [{ Type getResultType() { return this->getOperation()->getResult(0).getType(); } diff --git a/lib/Dialect/PluginOps.cpp b/lib/Dialect/PluginOps.cpp index da5f3f3..1ea3b5a 100644 --- a/lib/Dialect/PluginOps.cpp +++ b/lib/Dialect/PluginOps.cpp @@ -146,6 +146,14 @@ void CallOp::build(OpBuilder &builder, OperationState &state, if (retType != nullptr) state.addTypes(retType); } +void CallOp::build(OpBuilder &builder, OperationState &state, + uint64_t id, ArrayRef arguments, Type retType) +{ + state.addAttribute("id", builder.getI64IntegerAttr(id)); + state.addOperands(arguments); + if (retType != nullptr) state.addTypes(retType); +} + /// Return the callee of the generic call operation, this is required by the /// call interface. CallInterfaceCallable CallOp::getCallableForCallee() diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp index ccadf10..966d35e 100755 --- a/lib/PluginClient/PluginJson.cpp +++ b/lib/PluginClient/PluginJson.cpp @@ -341,7 +341,10 @@ Json::Value PluginJson::CallOpJsonSerialize(CallOp& data) { Json::Value item; item["id"] = std::to_string(data.idAttr().getInt()); - item["callee"] = data.callee().str(); + Optional calleeName = data.callee(); + if (calleeName) { + item["callee"] = calleeName->str(); + } item["OperationName"] = data.getOperation()->getName().getStringRef().str(); size_t opIdx = 0; for (mlir::Value v : data.getArgOperands()) { diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp index c4e5611..515e5e6 100644 --- a/lib/Translate/GimpleToPluginOps.cpp +++ b/lib/Translate/GimpleToPluginOps.cpp @@ -645,10 +645,6 @@ uint64_t GimpleToPluginOps::CreateGphiNode(uint64_t argId, uint64_t blockId) CallOp GimpleToPluginOps::BuildCallOp(uint64_t gcallId) { gcall *stmt = reinterpret_cast(gcallId); - tree fndecl = gimple_call_fndecl(stmt); - if (fndecl == NULL_TREE || DECL_NAME(fndecl) == NULL_TREE) { - return nullptr; - } llvm::SmallVector ops; ops.reserve(gimple_call_num_args(stmt)); for (unsigned i = 0; i < gimple_call_num_args(stmt); i++) { @@ -658,11 +654,18 @@ CallOp GimpleToPluginOps::BuildCallOp(uint64_t gcallId) Value arg = TreeToValue(argId); ops.push_back(arg); } - StringRef callName(IDENTIFIER_POINTER(DECL_NAME(fndecl))); tree returnType = gimple_call_return_type(stmt); PluginTypeBase rPluginType = typeTranslator.translateType((intptr_t)returnType); - CallOp ret = builder.create(builder.getUnknownLoc(), - gcallId, callName, ops, rPluginType); + tree fndecl = gimple_call_fndecl(stmt); + CallOp ret; + if (fndecl == NULL_TREE || DECL_NAME(fndecl) == NULL_TREE) { + ret = builder.create(builder.getUnknownLoc(), + gcallId, ops, rPluginType); + } else { + StringRef callName(IDENTIFIER_POINTER(DECL_NAME(fndecl))); + ret = builder.create(builder.getUnknownLoc(), + gcallId, callName, ops, rPluginType); + } return ret; } @@ -860,6 +863,10 @@ Value GimpleToPluginOps::TreeToValue(uint64_t treeId) } else { abort(); } + opValue = builder.create( + builder.getUnknownLoc(), treeId, IDefineCode::IntCST, + readOnly, initAttr, rPluginType); + break; } case MEM_REF : { tree operand0 = TREE_OPERAND(t, 0); -- 2.27.0.windows.1