| 282 | } |
| 283 | |
| 284 | bool RecursiveCompilabilityChecker::IsCompilableNode( |
| 285 | const Node& node, FunctionLibraryRuntime* lib_runtime, |
| 286 | std::vector<StackFrameView>* stack_trace, |
| 287 | std::vector<UncompilableNodeInfo>* uncompilable_nodes) const { |
| 288 | auto stack_depth = stack_trace->size(); |
| 289 | if (node.IsSource() || node.IsSink()) { |
| 290 | absl::string_view uncompilable_reason = "source or sink node"; |
| 291 | MaybeMarkUncompilableNode(uncompilable_reason, *stack_trace, |
| 292 | uncompilable_nodes); |
| 293 | LogNotCompilable(node, uncompilable_reason); |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | // _Arg nodes in a top-level function represent feeds and _Retval nodes in a |
| 298 | // top-level function represent fetches. |
| 299 | if (stack_depth == 1 && |
| 300 | (node.type_string() == "_Arg" || node.type_string() == "_Retval")) { |
| 301 | absl::string_view uncompilable_reason = "top level _Arg or _Retval"; |
| 302 | MaybeMarkUncompilableNode(uncompilable_reason, *stack_trace, |
| 303 | uncompilable_nodes); |
| 304 | LogNotCompilable(node, uncompilable_reason); |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | if (node.attrs().Find("_scoped_allocator") || |
| 309 | node.attrs().Find("_forward_from")) { |
| 310 | // TODO(b/128858118): XLA does not support _scoped_allocator and |
| 311 | // _forward_from. |
| 312 | absl::string_view uncompilable_reason = |
| 313 | "_scoped_allocator or _forward_from attribute"; |
| 314 | MaybeMarkUncompilableNode(uncompilable_reason, *stack_trace, |
| 315 | uncompilable_nodes); |
| 316 | LogNotCompilable(node, uncompilable_reason); |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | if (IsFunctionCall(*lib_runtime->GetFunctionLibraryDefinition(), node)) { |
| 321 | if (!IsCompilableCall(node.def(), lib_runtime, stack_trace, |
| 322 | uncompilable_nodes)) { |
| 323 | LogNotCompilable(node, "unsupported function"); |
| 324 | return false; |
| 325 | } |
| 326 | } else if (!HasXLAKernel(node)) { |
| 327 | absl::string_view uncompilable_reason = "unsupported op"; |
| 328 | MaybeMarkUncompilableNode(uncompilable_reason, *stack_trace, |
| 329 | uncompilable_nodes); |
| 330 | LogNotCompilable(node, uncompilable_reason); |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | if (node.IsWhileNode() && |
| 335 | !IsCompilableWhile(node, lib_runtime, stack_trace, uncompilable_nodes)) { |
| 336 | LogNotCompilable(node, "unsupported while"); |
| 337 | return false; |
| 338 | } |
| 339 | |
| 340 | if (node.IsIfNode() && |
| 341 | !IsCompilableIf(node, lib_runtime, stack_trace, uncompilable_nodes)) { |