[TableGen] Allocate `Operator` object on heap in `RecordOperatorMap`
authorLei Zhang <antiagainst@google.com>
Fri, 12 Apr 2019 16:52:11 +0000 (09:52 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Thu, 18 Apr 2019 18:47:43 +0000 (11:47 -0700)
commit2dc6d205acb367fc0c1f3ed5172da00a438d50c1
tree03a5a23ccd0f6f2ae38026b31a95ff622472b09d
parent138c972d11b4afe583dd9038968c6530f8bb7be4
[TableGen] Allocate `Operator` object on heap in `RecordOperatorMap`

    Iterators for a `llvm::DenseMap` can be invalidated when an insertion occurs.
    In Pattern's `collectBoundArguments()`, we recursively handle all nested DAG
    nodes and grow the the `RecordOperatorMap`, while retaining a reference.
    This can cause the reference to be invalid and the program to behave randomly.
    Allocate each `Operator` object specifically to solve this issue.

    Also, `llvm::DenseMap` is a great way to map pointers to pointers, or map
    other small types to each other. This avoids placing the `Operator` object
    directly into the map.

--

PiperOrigin-RevId: 243281486
mlir/include/mlir/TableGen/Pattern.h
mlir/lib/TableGen/Pattern.cpp