diff --git a/lib/Dialect/RTG/Transforms/ElaborationPass.cpp b/lib/Dialect/RTG/Transforms/ElaborationPass.cpp index 0b0391f9f2ad..b01012ffc325 100644 --- a/lib/Dialect/RTG/Transforms/ElaborationPass.cpp +++ b/lib/Dialect/RTG/Transforms/ElaborationPass.cpp @@ -738,6 +738,28 @@ class Elaborator } FailureOr visitExternalOp(Operation *op, VisitorInfo &info) { + 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())) + store(op->getResult(0), IndexValue(intAttr.getInt())); + else if (intAttr && intAttr.getType().isSignlessInteger(1)) + store(op->getResult(0), BoolValue(bool(intAttr.getInt()))); + else + store(op->getResult(0), AttributeValue(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 @@ -1010,28 +1032,6 @@ class Elaborator } FailureOr dispatchOpVisitor(Operation *op, VisitorInfo &info) { - 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())) - store(op->getResult(0), IndexValue(intAttr.getInt())); - else if (intAttr && intAttr.getType().isSignlessInteger(1)) - store(op->getResult(0), BoolValue(bool(intAttr.getInt()))); - else - store(op->getResult(0), AttributeValue(attr)); - - return DeletionKind::Delete; - } - return TypeSwitch>(op) .Case< // Index ops