From b05c6745c8da270bfe2beb9d80466644f185e2e6 Mon Sep 17 00:00:00 2001 From: Martin Erhart Date: Mon, 16 Dec 2024 11:46:52 +0100 Subject: [PATCH] [RTG][Elaboration] Move ConstantLike check after TypeSwitch for better performance --- .../RTG/Transforms/ElaborationPass.cpp | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Dialect/RTG/Transforms/ElaborationPass.cpp b/lib/Dialect/RTG/Transforms/ElaborationPass.cpp index 86c79fe7c703..de37d58cf781 100644 --- a/lib/Dialect/RTG/Transforms/ElaborationPass.cpp +++ b/lib/Dialect/RTG/Transforms/ElaborationPass.cpp @@ -696,6 +696,28 @@ class Elaborator : public RTGOpVisitor> { } FailureOr visitExternalOp(Operation *op) { + if (op->hasTrait()) { + SmallVector result; + auto foldResult = op->fold(result); + (void)foldResult; // Make sure there is a user when assertions are off. + assert(succeeded(foldResult) && + "constant folder of a constant-like must always succeed"); + auto attr = dyn_cast(result[0].dyn_cast()); + if (!attr) + return op->emitError( + "only typed attributes supported for constant-like operations"); + + auto intAttr = dyn_cast(attr); + if (intAttr && isa(attr.getType())) + internalizeResult(op->getResult(0), intAttr.getInt()); + else if (intAttr && intAttr.getType().isSignlessInteger(1)) + internalizeResult(op->getResult(0), intAttr.getInt()); + else + internalizeResult(op->getResult(0), attr); + + return DeletionKind::Delete; + } + // TODO: we only have this to be able to write tests for this pass without // having to add support for more operations for now, so it should be // removed once it is not necessary anymore for writing tests @@ -970,28 +992,6 @@ class Elaborator : public RTGOpVisitor> { } FailureOr dispatchOpVisitor(Operation *op) { - if (op->hasTrait()) { - SmallVector result; - auto foldResult = op->fold(result); - (void)foldResult; // Make sure there is a user when assertions are off. - assert(succeeded(foldResult) && - "constant folder of a constant-like must always succeed"); - auto attr = dyn_cast(result[0].dyn_cast()); - if (!attr) - return op->emitError( - "only typed attributes supported for constant-like operations"); - - auto intAttr = dyn_cast(attr); - if (intAttr && isa(attr.getType())) - internalizeResult(op->getResult(0), intAttr.getInt()); - else if (intAttr && intAttr.getType().isSignlessInteger(1)) - internalizeResult(op->getResult(0), intAttr.getInt()); - else - internalizeResult(op->getResult(0), attr); - - return DeletionKind::Delete; - } - return TypeSwitch>(op) .Case< // Index ops