Add a Function::isExternal utility to simplify checks for external functions.
authorRiver Riddle <riverriddle@google.com>
Tue, 26 Feb 2019 18:27:09 +0000 (10:27 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 23:43:50 +0000 (16:43 -0700)
PiperOrigin-RevId: 235746553

mlir/include/mlir/IR/Function.h
mlir/lib/Analysis/Verifier.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/Pass/Pass.cpp
mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp

index 3afb021c8ec4b9547039bbb69ca19d191e95ee76..2a4a88a919dbb03d542dc2f837327718628e9aca 100644 (file)
@@ -80,6 +80,9 @@ public:
   /// Unlink this function from its module and delete it.
   void erase();
 
+  /// Returns true if this function is external, i.e. it has no body.
+  bool isExternal() const { return empty(); }
+
   //===--------------------------------------------------------------------===//
   // Body Handling
   //===--------------------------------------------------------------------===//
index 45c760dbb1fb36e41eb995096b45bd37ff6d22ef..fbdf178769552629c8b1fd3d749d78e4508a4bd7 100644 (file)
@@ -90,7 +90,7 @@ bool FuncVerifier::verify() {
                                    fn.getName().c_str());
 
   // External functions have nothing more to check.
-  if (fn.empty())
+  if (fn.isExternal())
     return false;
 
   // Verify the first block has no predecessors.
index 9af1794cb0523752cb7728477a984738672309b0..3742367b8e7ef3bd863a7a12f4ca260df5816536 100644 (file)
@@ -1301,7 +1301,7 @@ void FunctionPrinter::printFunctionSignature() {
   auto fnType = function->getType();
 
   // If this is an external function, don't print argument labels.
-  if (function->empty()) {
+  if (function->isExternal()) {
     interleaveComma(fnType.getInputs(),
                     [&](Type eltType) { printType(eltType); });
   } else {
index 6a41cafcf1ee14c3d2fd008f48225be9efb95cb3..fddcb6e92aa77d3ce1965be21422e364f7d04342 100644 (file)
@@ -37,7 +37,7 @@ void ModulePass::anchor() {}
 PassResult FunctionPass::runOnModule(Module *m) {
   for (auto &fn : *m) {
     // All function passes ignore external functions.
-    if (fn.empty())
+    if (fn.isExternal())
       continue;
 
     if (runOnFunction(&fn))
index c5d611763d3662474728f1bf94cba519df1ca4ae..dfdf57ed64f13b21182650066ed2877316a6e17d 100644 (file)
@@ -513,7 +513,7 @@ bool ModuleTranslation::convertFunctions() {
   // Convert functions.
   for (const Function &function : mlirModule) {
     // Ignore external functions.
-    if (function.empty())
+    if (function.isExternal())
       continue;
 
     if (convertOneFunction(function))