Add a Function::isExternal utility to simplify checks for external functions.

PiperOrigin-RevId: 235746553
This commit is contained in:
River Riddle 2019-02-26 10:27:09 -08:00 committed by jpienaar
parent cdbfd48471
commit 79944e5eef
5 changed files with 7 additions and 4 deletions

View 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
//===--------------------------------------------------------------------===//

View 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.

View 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 {

View 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))

View 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))