From f2de0c0a336d5ed5d8530baf212edd3eae5c0ff3 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Tue, 30 Apr 2024 15:22:00 +0300 Subject: [PATCH 01/10] Squashed commit of the following: commit db9fc3b8d0a58258218db715963335564e156f0c Author: Harry Kalogirou Date: Tue Apr 30 14:50:07 2024 +0300 update tests commit 89d51c4a92ca77a8b5491ecb3afe17e5a84ba004 Author: Harry Kalogirou Date: Tue Apr 30 14:34:45 2024 +0300 refactor and cleanup commit be91dfe79b5c27aa17399f1858d7f7341fa2503b Author: Harry Kalogirou Date: Tue Apr 30 14:29:42 2024 +0300 move data segment info to context commit 6903c22095e0dd354a22d54ad0b196a9d8c32206 Author: Harry Kalogirou Date: Tue Apr 30 14:22:54 2024 +0300 Refactor VenomCompiler class in venom_to_assembly.py commit 9b6117f3a2af66ca61700e775a8e3de47e32d511 Author: Harry Kalogirou Date: Tue Apr 30 12:00:34 2024 +0300 lint commit c14e33a54fac6036e17002b8ef68ccd4f4c0ea96 Author: Harry Kalogirou Date: Tue Apr 30 11:49:12 2024 +0300 add comment commit 5fec3f2479b39c1a4fd6c48514ef1215fb884b89 Author: Harry Kalogirou Date: Tue Apr 30 11:47:15 2024 +0300 fix symbol replacement bug in _merge_jumpdests function commit 89d1a5c0ee65176ef4b2c47108b761586a06efe2 Author: Harry Kalogirou Date: Tue Apr 30 11:32:51 2024 +0300 add test cases commit 99f0d364502176ba0d9a59a57336fdcaeab413a3 Merge: ddb79131 7fc748c8 Author: Harry Kalogirou Date: Tue Apr 30 12:10:47 2024 +0300 Merge branch 'feature/sccp' into refactor/irfunction commit 7fc748c814e0a0c007f810c574c60bb3b99576f3 Merge: 8bd05a91 04cadaa9 Author: Harry Kalogirou Date: Tue Apr 30 12:10:27 2024 +0300 Merge branch 'master' into feature/sccp commit ddb791319bf87b73a291ba1571e53411c9b6409b Author: Harry Kalogirou Date: Tue Apr 30 11:15:30 2024 +0300 Refactor IRContext and IRFunction classes in vyper/venom commit 506e2892d7dc3a6832e1a700380554dda407aecb Author: Harry Kalogirou Date: Tue Apr 30 10:32:33 2024 +0300 remove legacy function handling commit bcecd5a4598004b8255f0b95ffc681e9f43584dd Author: Harry Kalogirou Date: Tue Apr 30 10:28:54 2024 +0300 Chain basic blocks refactor commit d78409b9b5e388368950cf6ce2a1da00d2d2d83b Author: Harry Kalogirou Date: Mon Apr 29 18:47:52 2024 +0300 output context commit 8cc1b7578346513863c093ba3d4845c10e45e3f0 Author: Harry Kalogirou Date: Mon Apr 29 18:37:22 2024 +0300 Fix CFG altering instructions in IRFunction class commit 8516588e2735fbbc0bff73178a19edcbf6cf69b3 Author: Harry Kalogirou Date: Mon Apr 29 18:32:25 2024 +0300 Refactor IRContext and IRFunction classes in vyper/venom commit 2762f8ca996881a005ed96bc5af833511560a3be Author: Harry Kalogirou Date: Mon Apr 29 18:23:04 2024 +0300 Refactor IRContext and IRFunction classes in vyper/venom commit 81f2cb0dd85aaf1bba8f4abfd5ecfc854b74a331 Author: Harry Kalogirou Date: Mon Apr 29 17:47:46 2024 +0300 Fix type annotation in test_dominator_tree.py commit f44f54491ecfc0623b868c7e8caec32b0911fe98 Author: Harry Kalogirou Date: Mon Apr 29 17:47:22 2024 +0300 ctx to fn commit 8bd05a9154af84a0fbe3cd39bb01f59b41331556 Author: Charles Cooper Date: Fri Apr 26 09:29:57 2024 -0400 reference wegman+zadeck commit 2bee449b554c8e520c910027048b59fb81b9d80a Author: Harry Kalogirou Date: Fri Apr 26 14:41:26 2024 +0300 Fix typo commit 4c3b252ffd767fd166958c64ee094d8e5fdf7661 Author: Harry Kalogirou Date: Fri Apr 26 14:18:24 2024 +0300 compile/runtime tests commit 3dca106e17f59186c0987aff063b2b9bb3fb7549 Author: Harry Kalogirou Date: Fri Apr 26 14:17:39 2024 +0300 Fix typo in simplify_cfg.py commit e3b40d123f2a33a68c8ade51586c34eb7c165ebe Merge: 4bb67fb8 1592ea1b Author: Charles Cooper Date: Wed Apr 24 14:31:42 2024 -0400 Merge branch 'master' into feature/sccp commit 4bb67fb862690930c086e878c769020d7e0570f3 Author: Harry Kalogirou Date: Mon Apr 22 11:16:06 2024 +0300 lint commit a8a69514d6a8c72f307dc5cea3172514ae7da5ea Author: Harry Kalogirou Date: Mon Apr 22 11:12:16 2024 +0300 oob tests for compile/run time commit 3769faa9f574c88db25730ec4c6c567b18403214 Author: Harry Kalogirou Date: Mon Apr 22 10:32:26 2024 +0300 remove unused import commit 5e2be93d176f4c46fd44ed61873989b29a26c45f Author: Harry Kalogirou Date: Mon Apr 22 10:31:29 2024 +0300 add back check commit ea0b57fe2553c8fd01b3687ec458be2b60c80c27 Author: Harry Kalogirou Date: Mon Apr 22 10:23:37 2024 +0300 remove unused self.dom commit be86cbfffb8ccf1efd4b1683601b59adff517661 Author: Harry Kalogirou Date: Mon Apr 22 10:21:53 2024 +0300 refactor commit 3c3072c366c8e87b3315cd29bbc935ec134fe823 Author: Harry Kalogirou Date: Mon Apr 22 10:20:00 2024 +0300 Reform type assertion in IRInstruction class commit 34354a0cba284545e926cb54988110166ff02d19 Merge: cf478ed4 80708e6d Author: Harry Kalogirou Date: Mon Apr 22 10:14:30 2024 +0300 Merge branch 'master' into feature/sccp commit cf478ed42848f464550d317b26b440e303ecff33 Author: Harry Kalogirou Date: Wed Apr 17 19:54:45 2024 +0300 Raise invalid work item type handling in SCCP commit 1c8df40b0af6d6309c9cbd3df23c1d99533b96ab Author: Harry Kalogirou Date: Wed Apr 17 19:43:02 2024 +0300 nbytes commit a3185224d11b608a1c8d3aea3e0799e3b7873150 Author: Harry Kalogirou Date: Wed Apr 17 12:06:35 2024 +0300 remove fast return commit bc95d0cf7f336a514e800c0648b7783704500e54 Author: Harry Kalogirou Date: Wed Apr 17 12:03:58 2024 +0300 Move `cfg_in_exec` to `SCCP` commit 251181dbc6ff5e38edece9d2b81223ee9470ee28 Author: Harry Kalogirou Date: Wed Apr 17 11:51:04 2024 +0300 rename `vars` to `in_vars` commit 40ad2001dc2bcc9b7c6cb4577bee81dc1803bb8b Author: Harry Kalogirou Date: Wed Apr 17 11:49:12 2024 +0300 remove basic_block from SSAWorkItem commit 13d7cc2caca2f506d570f3b2a469d92663c67c59 Author: Harry Kalogirou Date: Wed Apr 17 11:44:37 2024 +0300 use snake_case naming convention commit c83940acd702c24fab2d9611b170ba550476ba56 Author: Harry Kalogirou Date: Wed Apr 17 11:41:34 2024 +0300 remove fast paths commit 1d0ae1cc1c98069513f160cdf8bac5353bf7b97b Author: Harry Kalogirou Date: Wed Apr 17 11:26:02 2024 +0300 generalize `mstore` insertion before `return` commit 5cd9c3e2cd203f0a177b7558b84dd00d8a194b08 Author: Harry Kalogirou Date: Wed Apr 17 11:20:50 2024 +0300 Rename Mem2Stack to Mem2Var commit 93ae7edd09333d90dff606e8336f5413b1807893 Merge: 6bd1822b e1adb7b3 Author: Harry Kalogirou Date: Tue Apr 16 11:22:55 2024 +0300 Merge branch 'master' into feature/sccp commit 6bd1822b56343fef3bd62571871a0e2509f661b8 Author: Harry Kalogirou Date: Tue Apr 16 09:54:28 2024 +0300 remove masking commit b01b9afad2f9ce36ce831bf8a90202fdaea0d3bc Author: Harry Kalogirou Date: Tue Apr 16 09:44:15 2024 +0300 Add input value bounds checks in SCCP evaluation functions commit c778fbb53cb724c9116c148fd967de3880197408 Author: Harry Kalogirou Date: Tue Apr 16 09:37:43 2024 +0300 refactor _evm_iszero function commit eba81af9ed066f415fac53477f25bfc94c7d5522 Author: Harry Kalogirou Date: Tue Apr 16 09:34:40 2024 +0300 Refactor EVM evaluation functions commit 09cb6ce596d33564abd57c2810df6ca0d05eec83 Author: Harry Kalogirou Date: Tue Apr 16 09:18:52 2024 +0300 make use of vyper signed/unsigned conversion utility functions commit 238d28e588beb2a36ba3e6635ecdc51369e1fb5f Author: Harry Kalogirou Date: Mon Apr 15 23:51:00 2024 +0300 refactor commit 75a0bcb7351cd066972577feb89ebe74011a8799 Author: Harry Kalogirou Date: Mon Apr 15 22:33:14 2024 +0300 Panic for too many iterations in SimplifyCFGPass commit 913124fa95a1d6700b262ca5613a2e3a0ec29348 Author: Harry Kalogirou Date: Mon Apr 15 22:02:27 2024 +0300 right right shift commit 298504f6a70616aa62557523642f9cd31eb08bcf Author: Harry Kalogirou Date: Mon Apr 15 21:35:38 2024 +0300 lint commit 8bda3f99d5e5ce36862d0944409b02c7b3280f1f Author: Harry Kalogirou Date: Mon Apr 15 21:14:56 2024 +0300 bound iterations commit e684bd48de411c11a374f627e6324f188e82245c Author: Harry Kalogirou Date: Mon Apr 15 21:07:31 2024 +0300 rename functions commit 02bcf8bdbe89094c5caf1c3733983e4683752cd4 Author: Harry Kalogirou Date: Mon Apr 15 21:03:58 2024 +0300 snakecasefy commit d23440080674b7d20537a009c83a09d65f098145 Author: Harry Kalogirou Date: Mon Apr 15 16:46:16 2024 +0300 use `pytest.raises()' commit 19c6a773336bc871f2ee2913369231aa1176005a Merge: e6022655 39b46ca3 Author: Harry Kalogirou Date: Mon Apr 15 16:39:37 2024 +0300 Merge branch 'master' into feature/sccp commit e60226551dd8d64f85833dd0dec26907780738bd Author: Harry Kalogirou Date: Mon Apr 15 16:38:31 2024 +0300 remove unsused local commit b105a01abf9564571c1325b11bd95577063327b9 Author: Harry Kalogirou Date: Mon Apr 15 16:36:32 2024 +0300 update test for venom compile type assert commit 9545e36345a39682f2c265330c41971cd7b55516 Author: Harry Kalogirou Date: Mon Apr 15 16:33:09 2024 +0300 formatting commit b1842064a219519c7ab73cc25babdb9a983115db Author: Harry Kalogirou Date: Mon Apr 15 16:32:22 2024 +0300 update tests for venom compile time asserts commit 1238c9690e3d09a9f43bf6417622ab653965b694 Author: Harry Kalogirou Date: Mon Apr 15 16:05:34 2024 +0300 formatting commit 975d4ebfa54d1361942db37a8eac6283d1e4c103 Author: Harry Kalogirou Date: Mon Apr 15 16:05:06 2024 +0300 `ast_source` made into `IRnode` commit 225c5937bde459cd0b819b1fe51cf27f1634712a Author: Harry Kalogirou Date: Mon Apr 15 16:04:32 2024 +0300 lint commit 2a77c88c8442695cb8720517978d2ee31ddf3993 Author: Harry Kalogirou Date: Mon Apr 15 16:04:09 2024 +0300 fix signextend commit 34593bf13b3b174f488acf59dc60f339f848967a Author: Harry Kalogirou Date: Mon Apr 15 12:39:03 2024 +0300 assertion failure and add get_ast_source method commit c2a17edcf573b53587c23473ed864944a475e1ff Author: Harry Kalogirou Date: Mon Apr 15 11:58:52 2024 +0300 Remove `abort` opcode, make false assertions into compile error commit b5548ebdfacf3a90114929f499b961062cb5a376 Author: Harry Kalogirou Date: Mon Apr 15 11:33:30 2024 +0300 lint commit ac841ecb4860da0d275d301e4acd25a66c98a86d Author: Harry Kalogirou Date: Mon Apr 15 11:15:43 2024 +0300 add comment commit cbec0a510dc3433e0a922f2853e8f430bcf841f7 Author: Harry Kalogirou Date: Mon Apr 15 11:14:43 2024 +0300 Remove unused code commit 5506b40189488ecfbf8f70c8e03ca869eb258892 Author: Harry Kalogirou Date: Mon Apr 15 01:11:07 2024 +0300 comments and cleanup commit 4e417197024c2ffb5d8bb8f99061524c92c025fa Author: Harry Kalogirou Date: Mon Apr 15 01:05:23 2024 +0300 comments and a small optimization commit 073ddd2729266d3f628a62962fcc666476e5d07a Author: Harry Kalogirou Date: Mon Apr 15 00:57:13 2024 +0300 Refactor `self.uses` handling to simplify code commit 8047ce139345572aa9364d9865da43b220dd9e0f Author: Harry Kalogirou Date: Mon Apr 15 00:45:11 2024 +0300 Remove unused function commit adcbda765f9669e31a85d318a88715a2dbaf977f Author: Harry Kalogirou Date: Sun Apr 14 22:35:07 2024 +0300 Remove commented code in ir_node_to_venom.py commit 1b227f793fb38a0ee8de93f15b35c550a9c29c85 Author: Harry Kalogirou Date: Sun Apr 14 22:25:38 2024 +0300 return iterators when posible commit ca409509b94bbc859c42d6d9a215cb0213d357bf Author: Harry Kalogirou Date: Sun Apr 14 22:06:29 2024 +0300 Enable liveness display in IRInstruction class commit 8a7024feed2a5a8083d0897b2a117d33b756b3b9 Author: Harry Kalogirou Date: Sun Apr 14 10:46:16 2024 +0300 refactor sccp code commit cbd5a581430e7accf9745ea23cfd9909180ee5e0 Author: Harry Kalogirou Date: Sat Apr 13 23:44:59 2024 +0300 Remove unused imports and optimize imports in venom/__init__.py commit 9f9f1da7cde42a662374fbfa7cfec91b3d1e5d08 Author: Harry Kalogirou Date: Sat Apr 13 23:14:49 2024 +0300 lint commit 2a5e22b36bb587c6d3e47c4859c2bd8d3f50ffd2 Author: Harry Kalogirou Date: Sat Apr 13 23:10:37 2024 +0300 raise CompilerPanic for unimplemented djmp with literal commit 96abd9f5a5c20352b5d49e799cac23ff9e13451b Author: Harry Kalogirou Date: Sat Apr 13 22:01:02 2024 +0300 lint commit 4a8def3207a9a26c6e1a513c33dc1db16136ab88 Author: Harry Kalogirou Date: Sat Apr 13 18:15:13 2024 +0300 Remove unused imports commit 8c728b049602d4b3eac89620987d70b6e66fcac7 Author: Harry Kalogirou Date: Sat Apr 13 17:42:50 2024 +0300 lint commit a76341a9bafe36fee882a20509951dbb9cad68a8 Author: Harry Kalogirou Date: Sat Apr 13 14:55:33 2024 +0300 Add type hinting for ARITHMETIC_OPS dictionary commit 6016d1ba876beb3d26b8baaa09735f6666578474 Merge: 63e23007 cb940684 Author: Harry Kalogirou Date: Fri Apr 12 21:52:10 2024 +0300 Merge branch 'master' into feature/sccp commit 63e23007ce55551da66cfe6493e5d4923bad98a7 Author: Harry Kalogirou Date: Fri Apr 12 21:47:54 2024 +0300 cleanup commit 2354c8ad189daa1c74f1d1c6b001b1ec4c49deae Author: Harry Kalogirou Date: Fri Apr 12 21:46:06 2024 +0300 Remove unused code and add new instruction "abort" commit c5ac59acac1826705d12aa74dc76b0828c3c270c Author: Harry Kalogirou Date: Fri Apr 12 21:32:53 2024 +0300 bugfix DFT commit 234b2080207278ec64755bd06cc51a292a54b42b Author: Harry Kalogirou Date: Fri Apr 12 16:17:32 2024 +0300 Remove xfail markers from test functions commit 393b2906bee718012e42ddb008071c353d1119c0 Author: Harry Kalogirou Date: Fri Apr 12 16:06:15 2024 +0300 Swap order of operands in _evm_signextend function commit 184f371ee4a3c2f1245d25d46fe17c7c6964658f Author: Harry Kalogirou Date: Fri Apr 12 16:05:49 2024 +0300 add `abort` venom instruction commit 153844aed9b35baf8773b04ce3d97b0cd53a8e2a Author: Harry Kalogirou Date: Fri Apr 12 12:20:41 2024 +0300 Fix signed integer operations in SCCP evaluation commit 36da602d9aaff9d6587464ee9101c41188c7321a Author: Harry Kalogirou Date: Fri Apr 12 12:03:07 2024 +0300 Fix incorrect lattice values in test_sccp.py commit 7c232b0972faead4561bfcdabdd2e25c7223b4df Author: Harry Kalogirou Date: Fri Apr 12 11:55:45 2024 +0300 fix successor phis commit d2d053d2b8949651605c8c341838b7e19a6d9a4e Author: Harry Kalogirou Date: Fri Apr 12 02:14:38 2024 +0300 Refactor exp in SCCP evaluation commit f4b2fdca46447d9fa753acb6fe810d69122d018d Author: Harry Kalogirou Date: Fri Apr 12 01:59:13 2024 +0300 lint commit dd481fc81ea247a6910ac2018764d2c1e72295f3 Author: Harry Kalogirou Date: Fri Apr 12 01:58:17 2024 +0300 fix exp evaluation commit b29975de51b347f6c04313568e2c7b487840c677 Author: Harry Kalogirou Date: Fri Apr 12 01:48:06 2024 +0300 fixes commit ca9713518b756c09e82c7aa6a4f0bccdb2f63b5e Author: Harry Kalogirou Date: Thu Apr 11 19:33:21 2024 +0300 disable variable propagation commit 536af1e12bd7e8bce31f4947bf5f126a57a486b6 Author: Harry Kalogirou Date: Thu Apr 11 19:17:11 2024 +0300 fix branch selection logic to actually use _meet() commit 85e6ad8a67b81904381be5c2b6b690c61016e06d Author: Harry Kalogirou Date: Thu Apr 11 18:23:22 2024 +0300 update test cases in test_sccp commit 53fcc755c33306d6785c686d2fc5daf3225d6271 Author: Harry Kalogirou Date: Thu Apr 11 17:45:37 2024 +0300 Add _evm_not function to handle bitwise NOT operation commit 1e9365078c20ff465520074b99773e294ef45996 Author: Harry Kalogirou Date: Thu Apr 11 10:29:13 2024 +0300 enable for internals commit 5ae8edea5e35a2fb56a25f30f8c6c350a15758b0 Author: Harry Kalogirou Date: Thu Apr 11 00:29:48 2024 +0300 Refactor Mem2Stack pass and add variable propagation commit 779ce77e47158fdc8daee75e5ed28a136058fe0a Author: Harry Kalogirou Date: Thu Apr 11 00:29:40 2024 +0300 Fix operand order in EVM shift operations commit b12717afcd22a944c32fbff15223578fb3814417 Author: Harry Kalogirou Date: Wed Apr 10 22:09:05 2024 +0300 Commented out SCCP pass and rearranged code commit ee833edd3b6beb4abc3f09376cb7fa8d64b42dbb Author: Harry Kalogirou Date: Wed Apr 10 22:08:52 2024 +0300 block optimization and remove unreachable blocks commit d116cc1ba68b6bb77aed913100e83609ead718c1 Author: Harry Kalogirou Date: Wed Apr 10 22:08:30 2024 +0300 Fix operand order in binary operations and add new EVM instructions commit 05194e39900a07687eab4b50148806a98e06b0c9 Merge: ddb5795e eb81c269 Author: Harry Kalogirou Date: Wed Apr 10 09:40:49 2024 +0300 Merge branch 'master' into feature/sccp commit ddb5795ed8664947b6e27dfca652fe702dc73c0e Merge: c75c89c9 8fcbde28 Author: Harry Kalogirou Date: Tue Apr 9 17:38:32 2024 +0300 Merge branch 'master' into feature/sccp commit c75c89c9b38a7d27888a7577a09144e133cea223 Author: Harry Kalogirou Date: Tue Apr 9 17:27:57 2024 +0300 fixes commit 6e3d7fc4183bb1c546763011ba4f1da65637356f Author: Harry Kalogirou Date: Tue Apr 9 16:27:26 2024 +0300 fix phi issue commit cda13481cd93a97f1399710fe226a4eba1a62683 Author: Harry Kalogirou Date: Tue Apr 9 15:53:22 2024 +0300 Update arithmetic operations in SCCP commit dcaaefd9a514bfe8f326fbd0d722db588ffca3b8 Author: Harry Kalogirou Date: Tue Apr 9 13:39:27 2024 +0300 Refactor arithmetic operations in SCCP evaluation commit 0f92f1e075fb0d6a64c2610c4d9bd952a4ca80f1 Author: Harry Kalogirou Date: Tue Apr 9 13:39:15 2024 +0300 clean sccp commit 2c30b7cbea0d7607ce2c236cd6dd85fc6ed8dbe9 Author: Harry Kalogirou Date: Tue Apr 9 13:18:38 2024 +0300 Add CEILING_UINT256 constant to SizeLimits class commit dcea498a8c9f1b06d23558bbad026599e03d87dd Author: Harry Kalogirou Date: Tue Apr 9 12:58:34 2024 +0300 Refactor SCCP pass files and evaluation functions commit 9055dca39116d7e55f89e7f8f7c5a00de83af165 Author: Harry Kalogirou Date: Tue Apr 9 01:42:12 2024 +0300 reverse condition order commit 50fbdd814745428f580598ef0e4723554fee0b48 Author: Harry Kalogirou Date: Tue Apr 9 01:26:38 2024 +0300 Refactor SCCP pass to propagate variables for cleaner code for humans commit 9a04a28fa4d7fd686f932f867dded3caf0cf9b34 Author: Harry Kalogirou Date: Tue Apr 9 01:15:57 2024 +0300 Fix phi operand bug in SCCP pass commit 1647e3e23d5b3713c15e8a1815fb60cce9974164 Author: Harry Kalogirou Date: Tue Apr 9 00:53:12 2024 +0300 Updated unreachable block elimination with new phi commit 78efcf76965a7cf7fe1831e1469a40c3d3e61ca9 Author: Harry Kalogirou Date: Tue Apr 9 00:52:35 2024 +0300 Remove phi operand method commit dde71b91350ac21a94794217facac2e0a6eff1ec Author: Harry Kalogirou Date: Tue Apr 9 00:35:23 2024 +0300 Fix SCCP propagation bug commit 2b69335484f3c1f4fd484e03ec1844297eb1c0c2 Author: Harry Kalogirou Date: Tue Apr 9 00:27:02 2024 +0300 Fix SCCP algorithm and add conditional jump optimization commit 313881a77a9fd7916f7adfb20c928b4898e245eb Author: Harry Kalogirou Date: Mon Apr 8 21:26:53 2024 +0300 temp commit 200f816241379ad98636ea45d6b77c7bb2251259 Author: Harry Kalogirou Date: Mon Apr 8 21:06:05 2024 +0300 `nop` instruction commit b04e08c8fc8a31664b5d61b3d39db3b673515f2c Author: Harry Kalogirou Date: Mon Apr 8 21:05:53 2024 +0300 lint commit 0e44392b8d496895943788a70417e42e5846c151 Author: Harry Kalogirou Date: Mon Apr 8 21:05:20 2024 +0300 constant jump optimization commit f3be0096c6c3bae88d3194388c2abda3c3e9649c Merge: 213b2057 c54d3b16 Author: Harry Kalogirou Date: Sun Apr 7 21:56:20 2024 +0300 Merge branch 'master' into feature/sccp commit 213b2057cf5caac35d705e7a0de24ff0e0c8aa71 Author: Harry Kalogirou Date: Sat Apr 6 21:54:44 2024 +0300 use isinstance commit cbd6a13ab7c11d62b8757e73c6f450ca3aae37b8 Merge: ae53c2dc 273f8144 Author: Harry Kalogirou Date: Sat Apr 6 21:52:26 2024 +0300 Merge branch 'refactor/venom_classes' into feature/sccp commit 273f81442b1b702e5960021900398ab9a7bc6db9 Merge: fae87baa 7485ceab Author: Harry Kalogirou Date: Sat Apr 6 21:44:20 2024 +0300 Merge branch 'master' into refactor/venom_classes commit fae87baafedd3e0a26db71f884a273e9d4236dc8 Author: Harry Kalogirou Date: Sat Apr 6 21:31:52 2024 +0300 Refactor IROperand checks to use isinstance() instead of custom functions commit ae53c2dc5861aae1bf454e1af5f5ee98092c5cd1 Author: Harry Kalogirou Date: Sat Apr 6 11:35:32 2024 +0300 refactors commit b1a8c37ebb253f2d1e8223889283545a286882e2 Merge: efd533ab ea34e4df Author: Harry Kalogirou Date: Sat Apr 6 11:29:15 2024 +0300 Merge branch 'refactor/venom_classes' into feature/sccp commit ea34e4df78ef301a13dff878b88b38b764e93fa3 Author: Harry Kalogirou Date: Sat Apr 6 10:11:47 2024 +0300 remove unused member commit 0fbd68a5a56beca65766ff649b75211c5f318f5a Author: Harry Kalogirou Date: Sat Apr 6 10:06:36 2024 +0300 lint commit 29ae288a7438eaf79c7c2c50c9c29423d34b3803 Author: Harry Kalogirou Date: Sat Apr 6 10:06:28 2024 +0300 refactor IROperand as base commit 63a6d8495d2eabee1fbbc718e24b4f2b54db59be Author: Harry Kalogirou Date: Sat Apr 6 09:46:11 2024 +0300 use new class structure and `is_` functions commit 2298a27d785d0e10926d2c47e1300dddc9040bca Author: Harry Kalogirou Date: Sat Apr 6 09:34:14 2024 +0300 refactor class hierarchy commit efd533abfed4dd653ad44a416a465e2e29bf6da0 Author: Harry Kalogirou Date: Sat Apr 6 09:26:18 2024 +0300 fixes commit 432b830c15158b810e2b3486373c08261d7712e5 Author: Harry Kalogirou Date: Sat Apr 6 00:28:31 2024 +0300 fix commit b09cddfbcc29a223b3c7480cc549cfe9e2b3289a Author: Harry Kalogirou Date: Sat Apr 6 00:26:54 2024 +0300 lint commit 8036078e2ec76712e0f7fad0b489d01a60ddd4ee Author: Harry Kalogirou Date: Sat Apr 6 00:26:39 2024 +0300 refactor commit f8b5a0429ee64b1d41d32fd11d062b957587695e Author: Harry Kalogirou Date: Sat Apr 6 00:26:25 2024 +0300 cleanup commit 07ba2102b3650d00636bd0bb3be8bd35509e02ea Author: Harry Kalogirou Date: Sat Apr 6 00:15:21 2024 +0300 fix merge accident commit a8e8576b8d14028be06e8c6048f01a982ab9ae8f Author: Harry Kalogirou Date: Sat Apr 6 00:15:05 2024 +0300 remove unused parameter commit 9dcd13699261358536642b1eea59f259cebd4645 Merge: 1a424c51 63b8d1da Author: Harry Kalogirou Date: Sat Apr 6 00:11:52 2024 +0300 Merge branch 'master' into feature/sccp commit 1a424c516feb8c0625eaeea8982fe09b4db0cecc Author: Harry Kalogirou Date: Sat Apr 6 00:10:15 2024 +0300 run sccp on all functions commit 3c4825860585d51d86d0ad094e2058e15989d67e Author: Harry Kalogirou Date: Fri Apr 5 23:39:02 2024 +0300 enable sccp commit ce9f447a185228c09efabcf88b5fee9c6444d086 Author: Harry Kalogirou Date: Fri Apr 5 23:32:22 2024 +0300 add global symbol saving/restoring for repeat body commit 69e3ec10c2eece9285e39da0f6d1b9e1c5205719 Author: Harry Kalogirou Date: Fri Apr 5 21:18:29 2024 +0300 Refactor if-else block in ir_node_to_venom.py commit 8d6699aeeb5dabe06815883aa25a407cfa5ac5b8 Author: Harry Kalogirou Date: Fri Apr 5 16:57:33 2024 +0300 Refactor memory allocation to use stack commit a60fa6cb744ce82ed42cd5513ba61d94b5795f15 Author: Harry Kalogirou Date: Fri Apr 5 16:29:11 2024 +0300 temp commit commit b193c709c3de56e33093fae9bf3c707f384b4c6f Author: Harry Kalogirou Date: Fri Apr 5 16:27:10 2024 +0300 Add global symbol tracking in ir_node_to_venom.py commit 6799b97407f4fdc4a6b8c90f7bb87ffdc3b9f28e Author: Harry Kalogirou Date: Thu Apr 4 10:06:18 2024 +0300 param alloca commit b28ac5a3711f3c08e1f669cdbc829e155242a90a Merge: 5c182840 d372ad9a Author: Harry Kalogirou Date: Thu Apr 4 10:01:56 2024 +0300 Merge branch 'venom-alloca' into feature/sccp commit 5c1828405459e4f28d9c5d81820c2b38daa12e6b Author: Harry Kalogirou Date: Thu Apr 4 10:00:55 2024 +0300 temp commit d372ad9a02392ce3f58558acddb4a674369063c4 Author: Charles Cooper Date: Wed Apr 3 18:05:00 2024 -0400 wip -- different kind of alloca for internal function params commit 53d1711dc2cf59297294ceaaa8c4484514c09f5f Merge: 4dd53845 45a225c4 Author: Harry Kalogirou Date: Thu Apr 4 00:29:16 2024 +0300 Merge branch 'master' into feature/sccp commit 4dd53845628d72feba6adc6bc33609a53029f02b Merge: 37a89858 731da639 Author: Harry Kalogirou Date: Thu Apr 4 00:28:31 2024 +0300 Merge branch 'mem2stack' into feature/sccp commit 731da6392d4f50079a8299d813ef7e639e9619d7 Author: Harry Kalogirou Date: Thu Apr 4 00:25:54 2024 +0300 Refactor Mem2Stack pass and MakeSSA pass commit ebf38d93365ef81e2d9e1b8b019f3df60da79688 Author: Harry Kalogirou Date: Thu Apr 4 00:16:25 2024 +0300 Refactor Mem2Stack pass to use DFG outputs commit b908cae6180dc8c56925d4b8cb2649149f97c1e2 Merge: 53587b9e 1a27693e Author: Harry Kalogirou Date: Wed Apr 3 20:13:15 2024 +0300 Merge branch 'venom-alloca' into mem2stack commit 1a27693e134d727278214239c8026d445841555b Author: Charles Cooper Date: Wed Apr 3 15:21:23 2024 +0000 fix a defaults test commit b0e918efa14c619c4687f3694d12dd14b0fcc79a Author: Charles Cooper Date: Wed Apr 3 15:18:44 2024 +0000 fix operand order commit 4a6fd78d4158feb42d65ad6b2eea6175f39ca8f5 Author: Charles Cooper Date: Wed Apr 3 15:12:37 2024 +0000 revert symbols change commit 37a898585ba3f2b56c167a712a7e3f5696e7a8b5 Author: Harry Kalogirou Date: Wed Apr 3 13:13:05 2024 +0300 Remove unnecessary __eq__ method from IRVariable class commit f8d88d2a355cacf6e6b04750653c38e13cfd4f10 Author: Harry Kalogirou Date: Wed Apr 3 13:08:34 2024 +0300 remove test commit 6fcea4dd155316993ddd143380dab6a944a44550 Author: Harry Kalogirou Date: Wed Apr 3 13:07:08 2024 +0300 remove parameters commit d529b4bdd9dabe0f113b8cee718b363e46022f7f Merge: bf0b2172 6fb76e29 Author: Harry Kalogirou Date: Wed Apr 3 13:04:35 2024 +0300 Merge branch 'fix/use_pass_instances' into feature/sccp commit 53587b9ec55969da238a880cc17decb08fb5641f Merge: ca4a817d 6fb76e29 Author: Harry Kalogirou Date: Wed Apr 3 12:54:23 2024 +0300 Merge branch 'fix/use_pass_instances' into mem2stack commit 6fb76e29d98c5daf0167a970805692cef5e50eb0 Author: Harry Kalogirou Date: Wed Apr 3 12:40:43 2024 +0300 Update tests to use pass instances commit 345f9f57dbd75bc3721fd5725728723af7124a5c Author: Harry Kalogirou Date: Wed Apr 3 12:35:16 2024 +0300 Update code to use pass instances commit 55b852efcc4c58ea2583866c11a05b7971888c28 Author: Harry Kalogirou Date: Wed Apr 3 12:30:41 2024 +0300 Refactor IRPass class to use instance methods instead of class methods commit ca4a817dd1dd34122c99c7b89874a36f70d6b4a0 Author: Harry Kalogirou Date: Wed Apr 3 00:34:21 2024 +0300 Add Mem2Stack pass to optimize memory usage commit 7569a343c1900037cbd555b15bf27cd18db37dd9 Author: Charles Cooper Date: Tue Apr 2 20:35:33 2024 +0000 another variable rename commit 5c3231b9304dd8691169f8c80af086fd14077548 Author: Charles Cooper Date: Tue Apr 2 20:32:16 2024 +0000 remove mstore from passthru instructions, add argument names commit 00bc09524252fd3961b2d4f75422c3d1b852a1bd Author: Charles Cooper Date: Tue Apr 2 15:48:14 2024 -0400 fix another variable commit e41e6d625978c02011d4e7665b53e47464b691df Author: Charles Cooper Date: Tue Apr 2 15:46:59 2024 -0400 fix bad variable commit f7d9432860b81679a1511ef20c96503f0ac1739d Author: Charles Cooper Date: Tue Apr 2 15:44:57 2024 -0400 fix order of arguments commit df3b5b8dcc9855ee504fd4c83826a71dabe5ac68 Merge: 24d7eaca e34ca9ca Author: Charles Cooper Date: Tue Apr 2 15:40:28 2024 -0400 Merge branch 'master' into venom-alloca commit 24d7eaca9885572c5752006f2ec6973668a10181 Author: Charles Cooper Date: Sun Mar 24 15:20:31 2024 +0000 fix a variable lookup commit 607502d1e8dff6a066adffd2470fbc4c74cdf289 Author: Charles Cooper Date: Sun Mar 24 12:44:11 2024 +0000 fix buf in revert with reason commit 77427f657824fc33f3fc9603d0e59071f104d1e3 Author: Charles Cooper Date: Sun Mar 24 12:41:36 2024 +0000 lint commit b22ab6178c0a7adcd80e4183dcffb85fbf8efa4a Author: Charles Cooper Date: Sun Mar 24 00:54:16 2024 +0000 remove mload and mstore handling in ir_node_to_venom commit 593d2ee5d6e2bf7b4e37f78a81cf8830595b6cea Author: Charles Cooper Date: Sun Mar 24 00:52:20 2024 +0000 remove memory elision code it better belongs in a separate pass commit 42289ddcbaf068a5c84ddf27d9d8b42f44e0b7de Author: Charles Cooper Date: Sun Mar 24 00:20:05 2024 +0000 update alloca generation commit 5adc7d41cf13d8594e0da2962e16ab1dfe6c1b2c Author: Charles Cooper Date: Sat Mar 23 23:40:45 2024 +0000 fix with variable shadowing commit 3221c1c469d15638c75d81b392a210acfcda5ae5 Author: Charles Cooper Date: Sat Mar 23 19:02:20 2024 +0000 update alloca check commit 0f7597371beebb0f43e7f49eb2c8594d31b0e346 Author: Charles Cooper Date: Sat Mar 23 18:48:15 2024 +0000 simplify alloca, lint commit ab9d60fc14a8d821f0190a963b080a619f4abbff Author: Charles Cooper Date: Sat Mar 23 18:32:09 2024 +0000 last fixes commit aa1920731a7b8a61e77ce07af837b384f9c0fd35 Author: Charles Cooper Date: Sat Mar 23 18:27:58 2024 +0000 fix a bad from_list commit 75169cc9d099a8ff5676fb4f57c755b235bbd632 Author: Charles Cooper Date: Sat Mar 23 18:10:16 2024 +0000 fix typo commit 597d00aa03e27e4f191c5863c2642dd96dd79be3 Author: Charles Cooper Date: Sat Mar 23 18:06:13 2024 +0000 fix another builtin bug commit a5dd7bb7519561a31e2bc28c5d7a56a9c1c46e9e Author: Charles Cooper Date: Sat Mar 23 18:04:26 2024 +0000 small fix commit b37d4d92a7e472223899721ceea65cd50918fcde Author: Charles Cooper Date: Sat Mar 23 17:54:42 2024 +0000 fix some fixtures commit 4a3bd4b70a8bd03e5ed054d93a019f06e1458959 Author: Charles Cooper Date: Sat Mar 23 17:38:53 2024 +0000 fix bad evm_version fixture commit 5518af3ff2e1fbb38896a2e0aa986e6b9aa08af3 Author: Charles Cooper Date: Thu Mar 21 20:35:18 2024 +0000 fix a comment commit 21eefb344f42e1c2611725bdf187a201a9f54eee Author: Charles Cooper Date: Thu Mar 21 20:28:01 2024 +0000 fix some more instances commit 73a68f1ee6f88f43d58baf900036a72f2b902526 Author: Charles Cooper Date: Thu Mar 21 20:03:14 2024 +0000 use more add_ofst / fix instances where IRnodes are not expected commit 685164cad26364f56281d9e2efdd59903a903f74 Author: Charles Cooper Date: Thu Mar 21 19:55:36 2024 +0000 fix a fixture scope commit b79403a6e8e91827d32b2a2400ac9e5d2ad26642 Author: Charles Cooper Date: Thu Mar 21 13:49:11 2024 -0400 pass thru alloca in gep commit a047691fc32ac916eadba62dd288fc066874223a Author: Charles Cooper Date: Thu Mar 21 13:48:13 2024 -0400 wip -- change new_variable to return IRnode with alloca metadata instead of int commit 319be84f7658bfdc0ebeac98b8b72d3736ec7b47 Author: Charles Cooper Date: Thu Mar 21 13:00:30 2024 -0400 do not perform deallocation in venom pipeline small refactor: refactor replicated code for variable deallocatoin commit 1c6d6f000a5ba43e8376b3dc9eb8fb5042b08f81 Author: Charles Cooper Date: Thu Mar 21 12:46:45 2024 -0400 make settings into a global object this unifies various functions which modify global settings: anchor_opt_level, anchor_evm_version, _set_debug commit bf0b217274770b98c1cfba5c10ce6fb9c94d509f Author: Harry Kalogirou Date: Tue Apr 2 17:27:24 2024 +0300 Add constant propagation method to SCCP pass commit 664cd8f1f599160d38494af7601927da45387819 Author: Harry Kalogirou Date: Tue Apr 2 15:27:02 2024 +0300 Add arithmetic optimization to SCCP pass commit 14f00b377e4a0f048bce7f91a37143bb5d1d98aa Author: Harry Kalogirou Date: Tue Apr 2 15:21:04 2024 +0300 handle unused commit 9206f81bbf8c80b1ff1b695fd4f5979e5139ebf4 Merge: 7ac26d83 34eba098 Author: Harry Kalogirou Date: Tue Apr 2 14:51:56 2024 +0300 Merge branch 'feature/venom_updates' into feature/sccp commit 34eba0987409f29d30aadd20ba88de9f761c6057 Author: Harry Kalogirou Date: Tue Apr 2 12:18:28 2024 +0300 missplaced comment commit 7ac26d83161bd607e931ca6f1662dca9a93fa37b Merge: 64c107d5 fece7b10 Author: Harry Kalogirou Date: Tue Apr 2 10:35:32 2024 +0300 Merge branch 'feature/venom_updates' into feature/sccp commit fece7b10f10a9572c387d65284b430947617d86c Author: Harry Kalogirou Date: Thu Mar 28 16:37:55 2024 +0200 remove stray alloca commit 6099dae8d922a91faa1f382dee62a96517352b3d Merge: f57a9d1c 4a8a472e Author: Harry Kalogirou Date: Thu Mar 28 12:26:15 2024 +0200 Merge branch 'feature/venom_updates' of github.com:harkal/vyper into feature/venom_updates commit f57a9d1c577888ebb2724246ae30ce3463ac0f3c Author: Harry Kalogirou Date: Thu Mar 28 12:25:38 2024 +0200 verify phi placement commit 4beaaa40545e75fda5ddc6f94de5a797fe638c82 Author: Harry Kalogirou Date: Thu Mar 28 12:10:08 2024 +0200 unlint commit 4a8a472ecae1a35776288c8258a858bbdbae5cf7 Author: Harry Kalogirou Date: Thu Mar 28 12:07:21 2024 +0200 Update vyper/codegen/stmt.py Co-authored-by: Charles Cooper commit 50cb1b4a546fe6312f0dba3e2cf1cdfe685eca2c Author: Harry Kalogirou Date: Thu Mar 28 12:05:59 2024 +0200 lint commit 85bbd8c87f19177ed1efd83723c2b82cf7ebc433 Merge: fec8b84a 45959387 Author: Harry Kalogirou Date: Thu Mar 28 12:05:28 2024 +0200 Merge branch 'master' into feature/venom_updates commit fec8b84af82f5e53a34e10efcb2b62e8f4096ade Author: Harry Kalogirou Date: Wed Mar 27 09:49:20 2024 +0200 ensure revaluation order for select commit 3e53d7f5fdf296ef0b5803400909c4183b8a64a0 Merge: a5a1844a 6e9b2c98 Author: Harry Kalogirou Date: Tue Mar 26 22:33:49 2024 +0200 Merge branch 'master' into feature/venom_updates commit a5a1844a6a5c292ff48d692f13eed341fbbf79f2 Author: Harry Kalogirou Date: Tue Mar 26 22:31:12 2024 +0200 add DominatorTree.build_dominator_tree() commit 52c6f61c0fa82ad21044ff645e0b15660e15479a Author: Harry Kalogirou Date: Tue Mar 26 22:23:41 2024 +0200 commenting commit 84004815ac4e23717f81cff8fe0d62219611a71f Author: Harry Kalogirou Date: Tue Mar 26 22:19:26 2024 +0200 rename variables, refactor code commit ebf776ea388f6e6164b2dace25a5ea89ed9ebe87 Author: Harry Kalogirou Date: Tue Mar 26 22:18:50 2024 +0200 refactor dominator tree constructor commit b1ba5cbd1a02c52635a2a8cf60a192646e8d097e Author: Charles Cooper Date: Tue Mar 26 12:43:42 2024 -0400 add review commit cedd51802ce3e08abd927773adb1bed603f20dd9 Merge: c3b4dc70 ea7f0818 Author: Harry Kalogirou Date: Tue Mar 26 17:41:42 2024 +0200 Merge branch 'master' into feature/venom_updates commit 64c107d5c4b85a8f7356b3cda481688c381beef0 Author: Harry Kalogirou Date: Tue Mar 26 11:48:02 2024 +0200 update dominator tree usage commit 193f2751ce708c156734f97fda75f6da91c34d60 Merge: ee301dab c3b4dc70 Author: Harry Kalogirou Date: Tue Mar 26 11:44:21 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit c3b4dc70da99f6ba4e1a54ef3d44fdd3f3e7ae42 Author: Harry Kalogirou Date: Sun Mar 24 10:37:32 2024 +0200 revert mstore evaluation order commit 990951320a6f9db2148a1ce90aed4ca2f311a2ca Author: Harry Kalogirou Date: Sun Mar 24 10:27:43 2024 +0200 protect b from double evaluation commit affdb09db4c486783aecd263f64061421340f17b Author: Harry Kalogirou Date: Sun Mar 24 10:24:24 2024 +0200 change mstore evaluation order commit 10d3c82b503d84264c89d6b491f21403cc9a68e4 Author: Harry Kalogirou Date: Sun Mar 24 10:19:50 2024 +0200 lint commit 15573c4c27ecb52c2e7c1150b44fdbb733e394a4 Merge: 0a0d5925 91a9401c Author: Harry Kalogirou Date: Sun Mar 24 10:16:33 2024 +0200 Merge branch 'feature/venom_updates' of github.com:harkal/vyper into feature/venom_updates commit 0a0d59257e5fc105b96e46938300b61ff9841de7 Merge: 91ea9bde cedf7087 Author: Harry Kalogirou Date: Sun Mar 24 10:16:18 2024 +0200 Merge branch 'master' into feature/venom_updates commit 91a9401cbe86577d8d0ce5dfe4cf775e3aca7519 Author: Charles Cooper Date: Sun Mar 24 03:08:21 2024 +0000 fix cursed __repr__ function commit c05bcfffa8a9de7aef63be95cc32e59d4d3f3255 Author: Charles Cooper Date: Sat Mar 23 23:32:36 2024 +0000 add some review comments commit 544c90cb95a50b5325cb9b72dbdb5569a9a1a5ac Author: Charles Cooper Date: Sat Mar 23 19:17:17 2024 -0400 add some comments, sanity check commit 91ea9bde11bfaefc585c2058ce25d6c33efb1024 Author: Harry Kalogirou Date: Sun Mar 24 00:04:32 2024 +0200 lint commit fb5d87d6524f13bd7b9683fd8ac643f7b87443da Merge: 66977b49 e5892786 Author: Charles Cooper Date: Sat Mar 23 17:19:30 2024 +0000 Merge branch 'master' into feature/venom_updates commit 66977b49445ee2530c7f2f8fec7755c71e3b710d Author: Charles Cooper Date: Fri Mar 22 21:25:16 2024 +0000 remove some xfails commit 6f9923e0d8ec6f9bb2d9f0cff36256a9baffeb06 Author: Harry Kalogirou Date: Fri Mar 22 23:18:19 2024 +0200 lint commit 8bc466fb1cc6e8d5bc8bdb34934be4c07079dbdf Author: Harry Kalogirou Date: Fri Mar 22 23:14:08 2024 +0200 fix workflow commit 0e59adbdfe4932053474033c09467167cf422f3f Merge: 84a02d76 58e1a336 Author: Harry Kalogirou Date: Fri Mar 22 19:35:17 2024 +0200 Merge pull request #5 from charles-cooper/perf/venom improve venom performance commit 58e1a336302b12846754dcf65302869cebc95be8 Author: Charles Cooper Date: Fri Mar 22 13:09:32 2024 -0400 fix a couple tests commit afa51731e2444efd9bfd5408849aa621c230a1d3 Author: Charles Cooper Date: Fri Mar 22 13:04:15 2024 -0400 some more small optimizations commit 84a02d76af58f3a7b8b2ed64b4320351ff1f613f Author: Harry Kalogirou Date: Fri Mar 22 18:40:38 2024 +0200 mark test commit 3e4de66300068586884ff34888200d7f2e793aad Author: Harry Kalogirou Date: Fri Mar 22 18:38:50 2024 +0200 cleanupo commit bcfa42ddd0e0e163b41bbcfc53a1fefc3de4d630 Author: Charles Cooper Date: Fri Mar 22 12:28:24 2024 -0400 OrderedSet hide dict implementation better commit 6ebf97707efa306c3e4be71999407024f3a1ecd4 Author: Charles Cooper Date: Fri Mar 22 11:21:12 2024 -0400 add comment commit fbe4e2828d8732a5ddf2910ea2149b7e8639a94c Author: Charles Cooper Date: Fri Mar 22 11:17:41 2024 -0400 index basic blocks commit 86acccb10baa773584e89702fbdf968bb2831147 Author: Charles Cooper Date: Fri Mar 22 11:12:00 2024 -0400 improvements to OrderedSet performance commit ef78ccf9e38bbf8305e920dc32113e7f6ea806c1 Author: Harry Kalogirou Date: Fri Mar 22 15:59:15 2024 +0200 before cleanup commit 1325d48024c5c5d8e10d7d4fbb8f5ba7b93a24b8 Author: Harry Kalogirou Date: Fri Mar 22 00:16:18 2024 +0200 revert commit 46fe75783d500e6887d6dbc79a5d3357353c7525 Author: Harry Kalogirou Date: Fri Mar 22 00:16:02 2024 +0200 fix dominator test commit d72a41f3a4a4e02987a041ad09e6b8ae8e98e1d2 Author: Harry Kalogirou Date: Fri Mar 22 00:15:53 2024 +0200 add volatile instruction commit 06d216fe76d59f5d720f3a8f2700fa7ac6ea7ac3 Author: Harry Kalogirou Date: Thu Mar 21 19:02:12 2024 +0200 lint commit 50146d1b85c83b60632dfd69a4a11b40514c360c Author: Harry Kalogirou Date: Thu Mar 21 18:56:15 2024 +0200 depth first commit 3c88c50de85f572ae0a183c0ad707a313aff32a0 Author: Charles Cooper Date: Thu Mar 21 12:43:59 2024 -0400 lint commit 625996205151d8c4a18dce7694a4160a8d238b2d Author: Harry Kalogirou Date: Thu Mar 21 16:21:24 2024 +0200 update dominator users commit 2a404cc02fe0720c08f77f1fb20d09767cf64310 Author: Harry Kalogirou Date: Thu Mar 21 15:39:49 2024 +0200 add documentation commit 20536bf3ba5381a4d8193e09465d8fde2b864711 Author: Harry Kalogirou Date: Thu Mar 21 15:35:52 2024 +0200 variable name elaboration commit 0b5e7645c2e4f930a843ba6d33d5ea2b5ef63d42 Author: Harry Kalogirou Date: Thu Mar 21 09:08:00 2024 +0200 remove unnecessary check commit 54feec49c910e84cd59cfcf6dce203243a60d362 Author: Harry Kalogirou Date: Wed Mar 20 12:16:39 2024 +0200 assert there is a producing instruction commit 0c066f6abd908a640f6214c9ee64f5e1499f5704 Author: Harry Kalogirou Date: Wed Mar 20 12:10:16 2024 +0200 lint commit b942c0329cfdc5b44e1b8930c5709ef40733c277 Author: Harry Kalogirou Date: Wed Mar 20 12:07:58 2024 +0200 rename members commit 560e4a94d14123d7ae3a4d89627aae74076a5892 Author: Harry Kalogirou Date: Wed Mar 20 12:05:29 2024 +0200 remove debugging leftover commit aff18ad9a79d0efbc4888bd0bb4aa1b9b8ac0942 Author: Harry Kalogirou Date: Wed Mar 20 12:04:36 2024 +0200 added comment commit a866575a09585102a6e03732842cc92f92d0c8a2 Author: Harry Kalogirou Date: Wed Mar 20 11:58:23 2024 +0200 style commit 43185a0ce51fee2b96d6a5fba7531ac73b950142 Author: Harry Kalogirou Date: Wed Mar 20 11:57:18 2024 +0200 style change commit c42011666a9f1022c3971ecffdb4585bb5aab02d Author: Harry Kalogirou Date: Wed Mar 20 11:56:06 2024 +0200 variable rename commit 5c453f30c18256c333d034d3663a16917099d5d5 Author: Harry Kalogirou Date: Wed Mar 20 11:51:10 2024 +0200 bound check int literal commit e5d2c4598286e470bf0c97270ffec2162199486b Author: Harry Kalogirou Date: Wed Mar 20 11:45:53 2024 +0200 compile with experimental commit 752b685189588ad6e1d4caa5c07ec4777939da51 Author: Harry Kalogirou Date: Wed Mar 20 11:43:50 2024 +0200 remove unnecessary assert commit 5e7f93cf7ee85513cdaf776c1f9772792716171f Author: Harry Kalogirou Date: Wed Mar 20 11:36:19 2024 +0200 equalities commit 5c58549db5dd0a4d7d08a937f291e894c01a4b62 Author: Harry Kalogirou Date: Wed Mar 20 11:34:38 2024 +0200 fixes commit 6de6e7dde4b2b0a5d1878a047cd9302198b153c0 Author: Charles Cooper Date: Tue Mar 19 12:07:06 2024 -0400 wip - alloca commit 5ec9e6052df50cf9e21935d86cc3eed69e0c226a Author: Charles Cooper Date: Tue Mar 19 11:45:00 2024 -0400 count iterations, not changes for exception commit 2a7cb0bbd397660b4909b513e8d5d2530d0a1688 Author: Charles Cooper Date: Tue Mar 19 11:43:04 2024 -0400 add a couple comments commit c3e0ac91e4d8fa54156e43501d7d0a2c4ae657fc Author: Charles Cooper Date: Tue Mar 19 11:38:54 2024 -0400 simplify ir_node_to_venom commit 5f4f5489fb9d983fbc42cfa81f87efea270990b2 Merge: 477643e6 41474df9 Author: Harry Kalogirou Date: Tue Mar 19 17:19:07 2024 +0200 Merge branch 'feature/venom_updates' of github.com:harkal/vyper into feature/venom_updates commit 41474df95ddbc2e8c8bfb69de71c50f44b9e68a1 Author: Charles Cooper Date: Tue Mar 19 11:18:55 2024 -0400 rename a variable commit 477643e64bdcbf2e0c3951c91322b4120f62eb52 Merge: ea076324 34316f35 Author: Harry Kalogirou Date: Tue Mar 19 17:01:36 2024 +0200 Merge branch 'feature/venom_updates' of github.com:harkal/vyper into feature/venom_updates commit 34316f352b68c72065baa6bff63ae575f5257ff7 Author: Charles Cooper Date: Tue Mar 19 10:52:58 2024 -0400 move an optimization to assembly commit e37e54a73fbdea0b60948be1d98dad235b2af996 Author: Charles Cooper Date: Tue Mar 19 10:19:43 2024 -0400 fixes from bad merge commit ea076324460378fcbdffd2f795525d0d2b1cd917 Author: Harry Kalogirou Date: Tue Mar 19 16:35:15 2024 +0200 remove print commit 9c63c3eef47bce81a12757d5ea38f0f195c31595 Author: Harry Kalogirou Date: Tue Mar 19 16:31:55 2024 +0200 fix typo commit 71882ed5ec76132cfae00afec056e9ccbd8bc9f1 Author: Harry Kalogirou Date: Tue Mar 19 16:29:38 2024 +0200 add passthrough_data commit 540b71a7602e24e9c11613388fed7c81bc802e6c Merge: d7ef9efc 84f1b695 Author: Charles Cooper Date: Tue Mar 19 10:09:18 2024 -0400 Merge branch 'feature/venom_updates' of github.com:harkal/vyper into feature/venom_updates commit d7ef9efcdadffca00395a3c5fa3f44078b356dd2 Author: Charles Cooper Date: Tue Mar 19 10:08:47 2024 -0400 rename venom_pipeline to experimental-codegen commit 2330f83fa7e4ad0ef7050fd6cd34abd3b11d8f90 Merge: 46f5f8c8 58ecff59 Author: Charles Cooper Date: Tue Mar 19 10:05:02 2024 -0400 Merge branch 'master' into feature/venom_updates commit 84f1b695101a8ff8fc3f3aa24be01732c8d5252f Author: Harry Kalogirou Date: Tue Mar 19 15:28:08 2024 +0200 docs commit 25fa225c71bac8e6f7ae2b8acbaaf913039ee9a0 Author: Harry Kalogirou Date: Tue Mar 19 15:25:32 2024 +0200 cleanup commit 1cd994c45ae30891f47edd218f0a267214fc2c13 Author: Harry Kalogirou Date: Tue Mar 19 11:09:45 2024 +0200 cleanup commit 24730adcbea9e6be95631fcffea73cf8870b70fd Author: Harry Kalogirou Date: Mon Mar 18 20:37:10 2024 +0200 optimize double swaps commit ee301dab014d748af8f9eede95fdef70b229f305 Merge: 49998ed0 dab020db Author: Harry Kalogirou Date: Fri Mar 15 13:10:12 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit dab020db2c992ebf86dc544ea83fa4a8baecffc1 Author: Harry Kalogirou Date: Fri Mar 15 13:08:15 2024 +0200 dfg testing commit 46f5f8c8465b7bc6e1eb962a96f0be9851bf39d8 Author: Harry Kalogirou Date: Thu Mar 14 11:14:15 2024 +0200 stack reorder pass scaffold commit 31e6c8eb6cf9253151244f1732c6e0237b185bb3 Author: Harry Kalogirou Date: Thu Mar 14 11:13:45 2024 +0200 small stack optimization commit dfc9b8602af2b0049bbad6e1919bb8142810a20d Author: Harry Kalogirou Date: Thu Mar 14 11:13:25 2024 +0200 fix commit 5477ec179239d584e469d489468915fc1d8cefc4 Author: Harry Kalogirou Date: Thu Mar 14 11:13:14 2024 +0200 graphviz output for DFG commit 559a80b7c07712bbd1fc65e4eaa0cc846ae9819d Author: Harry Kalogirou Date: Thu Mar 14 10:07:50 2024 +0200 update test commit 4d700775f138a92649298bfb2cc88e0258580e38 Author: Harry Kalogirou Date: Wed Mar 13 21:12:36 2024 +0200 no operation instructions for translator commit d513bb4c70383223de930a1196d3490fa487ea6e Author: Harry Kalogirou Date: Wed Mar 13 21:08:09 2024 +0200 cleanup, optimization commit 651a076c1aa774bb42063c2e9c25668c84f699d4 Author: Harry Kalogirou Date: Wed Mar 13 12:51:34 2024 +0200 optimization commit 7fc72a2509d04de06b8cb5e94c7f8c56b7437899 Author: Harry Kalogirou Date: Wed Mar 13 12:38:57 2024 +0200 change source_pos to ast_source commit 5a22d49fd6554a3b5bda57e313c4fdb6e3c515d6 Merge: 41cf781a a9ee6414 Author: Harry Kalogirou Date: Wed Mar 13 12:34:49 2024 +0200 Merge branch 'master' into feature/venom_updates commit 49998ed026fd39e9ec4e09c8578c1379321d01cd Merge: 59d062f4 41cf781a Author: Harry Kalogirou Date: Tue Mar 12 14:33:56 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit 41cf781a5ac3b26bcf17457f677cfd3743960f64 Merge: 4059e88f 39027dc8 Author: Harry Kalogirou Date: Tue Mar 12 14:32:33 2024 +0200 Merge branch 'master' into feature/venom_updates commit 59d062f43a6ba4c2d8ba2880ef1f11edaa6c9095 Merge: 3d1a5fb8 4059e88f Author: Harry Kalogirou Date: Tue Mar 12 09:56:50 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit 4059e88f25c0d4a6a63cab4847bde0143f8b1a8e Author: Harry Kalogirou Date: Tue Mar 12 09:56:31 2024 +0200 Add cfg and cfg_runtime output types commit 3d1a5fb802f077be54edf50ac0e7ce9594b5b98c Author: Harry Kalogirou Date: Tue Mar 12 09:50:34 2024 +0200 fix commit 74a40344d1eb9465bb4295b429f53e8057aa1d38 Merge: dbc322a6 743b15df Author: Harry Kalogirou Date: Tue Mar 12 09:18:25 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit 743b15dfef48a4e15b90374ce0f180c8579e4942 Author: Harry Kalogirou Date: Tue Mar 12 08:33:38 2024 +0200 mark xfail venom commit 47dfd0525f459e9589bf09816b6476cd6f12d5b5 Author: Harry Kalogirou Date: Tue Mar 12 00:38:35 2024 +0200 mark xfail commit 7e9b87802797573cb1caa87a7f881ad2bd0a0974 Author: Harry Kalogirou Date: Tue Mar 12 00:34:35 2024 +0200 use exit instruction commit e2b51abaebf26e4ff2cf9a15b7c71e8ed524e336 Author: Harry Kalogirou Date: Tue Mar 12 00:17:56 2024 +0200 mark tests xfail for venom commit 7e9ee92ad30f5a18bee4b4564c13d83105dc999b Author: Harry Kalogirou Date: Tue Mar 12 00:06:59 2024 +0200 exit venom instruction commit 5e496ef33c0e97701f7f16ba33183a719d8e784a Author: Harry Kalogirou Date: Mon Mar 11 18:12:43 2024 +0200 remove unsused imports commit 926eeb3dbe2ce032023edf95e87d3bf8d4469430 Author: Harry Kalogirou Date: Mon Mar 11 18:10:42 2024 +0200 simplify jumps commit f2e3871958cbdb1dd8852fc0e70cbdc0a2212903 Author: Harry Kalogirou Date: Mon Mar 11 17:01:26 2024 +0200 update cfg on remove unreachable blocks commit f1465da377723cf2d8ba09f73c6dc2b4aea8fda8 Author: Harry Kalogirou Date: Mon Mar 11 16:32:46 2024 +0200 simplify cfg refactor and optimization commit 75fc03522c568cc034281d5dcea85ccac0220156 Author: Harry Kalogirou Date: Mon Mar 11 13:10:36 2024 +0200 raise on dup out of stack commit 86ea74fcff263c0f323e634025dd994b49e6cb3b Author: Harry Kalogirou Date: Mon Mar 11 00:40:28 2024 +0200 fix commit c0b7de076c55566e88764b59aff03c4725a8ce3b Author: Harry Kalogirou Date: Sun Mar 10 23:57:16 2024 +0200 simplify cfg commit f455b666dfd789821545f10f4affc8a52cea9591 Author: Harry Kalogirou Date: Sun Mar 10 00:36:36 2024 +0200 fix tests for venom commit 7994423cb53217cab28f66cafff8306d7dd8f08b Author: Harry Kalogirou Date: Sun Mar 10 00:31:53 2024 +0200 fix test for venom commit ea8367402b44ff1940a937eefac20092eaa0e715 Author: Harry Kalogirou Date: Sat Mar 9 23:35:28 2024 +0200 update to new external call syntax commit a87076e0054e3d55f8b3d1f284733b8fea23b970 Author: Harry Kalogirou Date: Sat Mar 9 23:13:52 2024 +0200 lint commit 7bc1b13cc40bb8e8bb336fcd885b22c847c88891 Author: Harry Kalogirou Date: Sat Mar 9 23:10:40 2024 +0200 revert force experimental flag commit 2bf47c7df198fb20a3ace284f5c0d7e15602115f Author: Harry Kalogirou Date: Sat Mar 9 23:07:43 2024 +0200 lint commit c017371256ae45be1334bb54568efb5eb28d64c0 Author: Harry Kalogirou Date: Sat Mar 9 23:00:26 2024 +0200 update test for venom commit afdb086998b7945e567b65415c35578637fe0ee5 Merge: 3ebd99ee 9428196a Author: Harry Kalogirou Date: Sat Mar 9 22:33:25 2024 +0200 Merge branch 'master' into feature/venom_updates commit 3ebd99eed5354c9e88dc823ead135767d6a5f1a3 Author: Harry Kalogirou Date: Sat Mar 9 12:36:02 2024 +0200 pass down source pos commit 862bcd8161ab4dba76865c79ec3e6b94a0449b69 Author: Harry Kalogirou Date: Sat Mar 9 00:27:03 2024 +0200 fix test_assert_reason_revert_length commit dbc322a628bb977ae289b5208a1e1fe8736e3f2d Merge: 792443bb b62701ee Author: Harry Kalogirou Date: Fri Mar 8 23:40:07 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit b62701eed6f28073ba5ba0a887153afe30018dcd Merge: e8c8ba0e cf37ec27 Author: Harry Kalogirou Date: Fri Mar 8 23:39:32 2024 +0200 Merge branch 'master' into feature/venom_updates commit e8c8ba0ef7f1d3394672cc42cafb2488c716434e Author: Harry Kalogirou Date: Fri Mar 8 21:14:44 2024 +0200 handle raw data commit b01c7309eb34e00e155fb0c1c019fa2fdf1efc30 Author: Harry Kalogirou Date: Fri Mar 8 21:14:30 2024 +0200 Update dense selector to emit the target constrained djump instruction commit 14450967d1b7cdc8b1e772e25558619baabb4f4a Author: Harry Kalogirou Date: Fri Mar 8 21:00:56 2024 +0200 codesize dispatcher commit 792443bb2512590bb5aabe48e635603096a29d21 Merge: 957e773c 338dc09b Author: Harry Kalogirou Date: Fri Mar 8 20:03:13 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit 338dc09bffcd5ab97379efb88094154d34ca2172 Author: Harry Kalogirou Date: Fri Mar 8 19:49:39 2024 +0200 remove unused imports commit ef4e8a21f633811e6ae66c68cfb1558a46c3bbea Merge: b828a86f 787c562a Author: Harry Kalogirou Date: Fri Mar 8 19:34:35 2024 +0200 Merge branch 'master' into feature/venom_updates commit b828a86f9c8b7f3f6bf49ed51d35a35417aa514d Author: Harry Kalogirou Date: Fri Mar 8 16:26:58 2024 +0200 fix commit 7a650dfc7a7f0bd0e7ab0e711ba23c273feada49 Author: Harry Kalogirou Date: Fri Mar 8 13:06:48 2024 +0200 cleanup commit 94e7328e426d64003826f3a7d489ac00b6365c76 Author: Harry Kalogirou Date: Fri Mar 8 13:03:07 2024 +0200 fix lib issues commit bbb25fa68c97d07652cbd55cb266deaf39ad105b Author: Harry Kalogirou Date: Fri Mar 8 00:35:37 2024 +0200 temp commit 9d7336de9a753ad6a2b974243a0a56a784761537 Author: Harry Kalogirou Date: Fri Mar 8 00:10:26 2024 +0200 more fixes commit 6b74b20f513a5b73ae130b04a95196de7dcc3e0e Author: Harry Kalogirou Date: Fri Mar 8 00:03:07 2024 +0200 var list commit 43a11c227f60ede182483f3391f55303a5f58094 Author: Harry Kalogirou Date: Thu Mar 7 23:50:52 2024 +0200 cleanup commit 957e773c7b364c0540c9bc2d13c974ca3b326df7 Merge: a92af68a 5aa6c893 Author: Harry Kalogirou Date: Tue Mar 5 22:01:45 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit 5aa6c893af688e9950bd2dde58f1203476d0c0c9 Merge: a0ff8286 327e95ae Author: Harry Kalogirou Date: Tue Mar 5 21:59:14 2024 +0200 Merge branch 'master' into feature/venom_updates commit a0ff82864ece39fe4553c29a3251bed1a967243b Author: Charles Cooper Date: Tue Mar 5 08:21:31 2024 -0800 force strict=True for venom_xfail commit 04260acd2407a04cc17049e48ccf49ce53abce06 Author: Harry Kalogirou Date: Tue Mar 5 18:20:58 2024 +0200 fix case where cfg_in empty on non entry nodes commit a92af68ae704e9421afe5ecf320bf73a3556b8f3 Merge: 005e38eb 7f969b9b Author: Harry Kalogirou Date: Tue Mar 5 11:18:43 2024 +0200 Merge branch 'feature/venom_updates' into feature/sccp commit 7f969b9b859d508ec2d3aaa1969d7ce11b9a0b74 Merge: 51075a88 d3e7b7d3 Author: Harry Kalogirou Date: Tue Mar 5 11:18:02 2024 +0200 Merge branch 'master' into feature/venom_updates commit 005e38eb6dd06d2be8ee20d7fc384fa82694fd37 Merge: 36e22a67 d3e7b7d3 Author: Harry Kalogirou Date: Tue Mar 5 10:04:56 2024 +0200 Merge branch 'master' into feature/sccp commit 36e22a678a10729e571e992df78c399031085c8b Author: Harry Kalogirou Date: Mon Mar 4 18:59:28 2024 +0200 fixes commit 3601c23a4f0476dfb2fafbaf0979515ec2e90821 Author: Harry Kalogirou Date: Mon Mar 4 16:26:56 2024 +0200 fixes commit a95ff489fbf288cf4d3d51651c9011012d4845ba Author: Harry Kalogirou Date: Mon Mar 4 15:56:30 2024 +0200 more tests commit bba4cbb81ecbe0599295531e51501d77914d64a0 Author: Harry Kalogirou Date: Mon Mar 4 15:40:12 2024 +0200 update test commit b29e353952b7d6648f32ae6c207ad80d030a9994 Author: Harry Kalogirou Date: Mon Mar 4 15:37:06 2024 +0200 phi handling commit c6c79ba080375e665f7c4a818bfcca75e373e4d0 Author: Harry Kalogirou Date: Mon Mar 4 15:36:44 2024 +0200 add parent to inserted phi instructions commit 51b3cf18ac5310c7753b20ac368e991acd6e592d Author: Harry Kalogirou Date: Mon Mar 4 15:11:19 2024 +0200 add first() method in OrderedSet commit 71aca413ed834e5fe5bb7eb4b7acc96921048a53 Author: Harry Kalogirou Date: Mon Mar 4 12:47:42 2024 +0200 finalise test1 and add new onw commit 1c468a22b3687c581bc8ae10f5b933bd2b7c2324 Author: Harry Kalogirou Date: Mon Mar 4 12:47:20 2024 +0200 more implementation commit a4758b1cf7a407dc3225b69d7e17aa140574ec8c Author: Harry Kalogirou Date: Mon Mar 4 11:47:51 2024 +0200 progress commit e7d25e95ba67913c0fa87e7cb094d9cf41af8453 Author: Harry Kalogirou Date: Mon Mar 4 11:47:41 2024 +0200 add forgoted initializer commit 2ac9c477c24c86d5745f449d0d9a5fa2af887466 Author: Harry Kalogirou Date: Mon Mar 4 10:35:59 2024 +0200 update test commit 5a543be14aeb97afc7bd2f515e2a545de4a1e654 Author: Harry Kalogirou Date: Mon Mar 4 10:35:52 2024 +0200 compute uses commit 82f3f24acba1b3fb95cbed2006dbb4385e7fa9b1 Author: Harry Kalogirou Date: Mon Mar 4 10:20:49 2024 +0200 get_uses() in basic_block commit b19d084c3fb3c89daa57afdaf42138df6c46b387 Author: Harry Kalogirou Date: Mon Mar 4 10:20:32 2024 +0200 Use pass instances instead of classes commit 69d30c362c72ce02b17727fd631f9b231b4a771f Author: Harry Kalogirou Date: Mon Mar 4 09:47:39 2024 +0200 add test sccp commit 0c563e7b3262052ffa5fe21bae5f16e5b75a763e Author: Harry Kalogirou Date: Mon Mar 4 09:44:49 2024 +0200 visitPhi commit 9c1e5330081e808543dc687e0357a38f659b0cdd Author: Harry Kalogirou Date: Sun Mar 3 19:34:21 2024 +0200 data structures commit 92eed811efc89f3bd11fed70be3329d5456c6e94 Author: Harry Kalogirou Date: Sat Mar 2 22:43:30 2024 +0200 gg commit df9b90baa5b18681931709048935f348ceadef67 Author: Harry Kalogirou Date: Sat Mar 2 11:15:46 2024 +0200 add sccp pass commit 51075a88ea9ba0f8b1278351eb55ee49a40d775e Merge: 9f595ca1 d7b39b6e Author: Harry Kalogirou Date: Mon Mar 4 09:48:51 2024 +0200 Merge branch 'feature/venom_updates' of github.com:harkal/vyper into feature/venom_updates commit 9f595ca11edf1ff5e67aa310205535a5ad9b461d Author: Harry Kalogirou Date: Mon Mar 4 09:48:15 2024 +0200 cleanup make_ssa test commit d7b39b6e3da088d02fb4f541289c50f622731a59 Author: Charles Cooper Date: Sat Mar 2 11:44:20 2024 -0500 add `#pragma experimental-codegen` commit b0785f877dbcc871c152492bc40235112f43357f Author: Charles Cooper Date: Fri Mar 1 20:45:10 2024 +0000 some more xfails commit 619ab3dea916cf09396fd9948aa1bf7ded07ac07 Author: Charles Cooper Date: Fri Mar 1 20:31:59 2024 +0000 update workflow file commit a8053031426f93fa3e4255e4fb651b0f86b08bac Author: Charles Cooper Date: Fri Mar 1 20:30:55 2024 +0000 fix lint commit 60f0b6b8604e9fc4338fa590d3cc954ec69e31f5 Author: Charles Cooper Date: Fri Mar 1 20:23:39 2024 +0000 mark more xfails commit 28c10a69274eb2ae2852d6ead29bdb9f03bf1d99 Author: Charles Cooper Date: Fri Mar 1 20:23:26 2024 +0000 add test pipeline for venom commit d0ae1de90e22d6e14cc0c9d68dfe1993b5b64e0b Author: Charles Cooper Date: Fri Mar 1 20:07:01 2024 +0000 fix a setting commit ad619b76a2ff8b3489ca1bce2ea51f1980f257d7 Author: Charles Cooper Date: Fri Mar 1 19:56:38 2024 +0000 add --use-venom test option, venom_xfail fixture commit d1fa29561127b6acb0fae512278258dac03307c3 Author: Charles Cooper Date: Fri Mar 1 18:43:42 2024 +0000 update some tests commit 116bc7fa1b1e14dc226a4f5b1f54bfc38734619e Author: Charles Cooper Date: Fri Mar 1 13:38:21 2024 -0500 fix lint commit 6ed922f02474fc3aa23890e2aec30a033c9758c2 Author: Harry Kalogirou Date: Fri Mar 1 19:54:04 2024 +0200 lint commit 4595b1d75107d23af2222726df33eec6c1787740 Author: Harry Kalogirou Date: Fri Mar 1 19:43:06 2024 +0200 returndatacopy in reversed ops commit 760c4243d2c85f78724263f605a010a7dcd32004 Author: Harry Kalogirou Date: Fri Mar 1 19:32:35 2024 +0200 fix commit b3b9663a3f97115ba12f4f0af2be6dbda2025d89 Author: Harry Kalogirou Date: Fri Mar 1 19:23:40 2024 +0200 clean up phase 2 commit 18dd18d9cf566714e461c3f29e4977c02993aaa7 Author: Harry Kalogirou Date: Fri Mar 1 19:16:36 2024 +0200 cleanup commit a055a8372249f72cf06101bccfd1e5fcb061d720 Author: Harry Kalogirou Date: Fri Mar 1 18:47:57 2024 +0200 small cleanup / refactor commit 96f7c3b9e0ebe5181df8c8e5d106f64e993ded90 Author: Harry Kalogirou Date: Fri Mar 1 16:25:43 2024 +0200 multi phi get_depth commit f54da860db0c208435c94f4ed71185f047c89c8c Author: Harry Kalogirou Date: Fri Mar 1 16:12:09 2024 +0200 ret_ofst ret_size undefined case commit 48ea42995a86625b07278e59fcf5405fe1b928d3 Author: Harry Kalogirou Date: Fri Mar 1 15:35:30 2024 +0200 exit_to with no parameters commit c1b4965359ec5322968e7747eebcecec89a639f5 Author: Harry Kalogirou Date: Fri Mar 1 12:33:25 2024 +0200 exit_to acrobatics commit a9fefa633827e4257db8ef9825a9aa6ba4eb19ac Author: Harry Kalogirou Date: Fri Mar 1 10:40:50 2024 +0200 fix reordering of stack with duplicated commit 0fd4f574450fb2dc00b94673151a70e6ed06d789 Author: Harry Kalogirou Date: Thu Feb 29 23:25:35 2024 +0200 mcopy commit 1e182f7524b574d27780e1d6eafbd57b7e7d48db Author: Harry Kalogirou Date: Thu Feb 29 22:54:21 2024 +0200 transient storage commit 776a33ee23b821bc1e2fbe83298ae238a3ba8bcd Author: Harry Kalogirou Date: Thu Feb 29 20:50:25 2024 +0200 remove allocated_variables commit a1d21109130a62751a437092300bb38933ee71f6 Author: Harry Kalogirou Date: Thu Feb 29 17:03:59 2024 +0200 remove variables commit 4ca5bcbf462e6b4bb5031b5b79331219fd4d1e06 Author: Harry Kalogirou Date: Thu Feb 29 17:00:25 2024 +0200 remove get_variable commit a50fd1312143fa9e467110d51f254a5571621be2 Merge: b0fecda0 b4429cf8 Author: Harry Kalogirou Date: Thu Feb 29 16:56:21 2024 +0200 Merge remote-tracking branch 'origin/master' into feature/venom_updates commit b0fecda03d09d2d8ca0714485dc41cdcd575532f Author: Harry Kalogirou Date: Thu Feb 29 16:46:27 2024 +0200 get rid of passthrough_metadata commit 63aa60b21b56d982e98121ee01f5390a11110c27 Author: Harry Kalogirou Date: Thu Feb 29 16:36:52 2024 +0200 more func_t cleanup commit 3a3174ba1b5819e731ad3c9e4539e6f34c52c186 Author: Harry Kalogirou Date: Thu Feb 29 16:17:54 2024 +0200 func_t cleanup commit f6bcb25adb6695d455989e35f6a07e746496ef7c Author: Harry Kalogirou Date: Thu Feb 29 15:35:44 2024 +0200 add difficulty instruction commit a9ceb5a33b2ff00657a99d094993da4f5dbf5859 Author: Harry Kalogirou Date: Thu Feb 29 15:26:38 2024 +0200 fix test commit 4f8dbecaa61c2883323c78daf67cdd94769535eb Author: Harry Kalogirou Date: Thu Feb 29 15:14:50 2024 +0200 more fixes commit 5505b9bea53207e84ed8163dbb08c9b95a462285 Author: Harry Kalogirou Date: Wed Feb 28 14:24:30 2024 +0200 old call conv commit 5dcdfe6158621129575b6a81217d5596fa9e402f Author: Harry Kalogirou Date: Wed Feb 28 11:24:47 2024 +0200 call conv commit 76dc7eb2ebe46dc11497ece22ccc60cc40f0c7bc Merge: a91ac18e 9bab1146 Author: Harry Kalogirou Date: Sun Feb 25 21:25:35 2024 +0200 Merge branch 'master' into feature/venom_updates commit a91ac18ea2c00565c21a125586f8828bc93abde1 Author: Harry Kalogirou Date: Sun Feb 25 21:08:26 2024 +0200 fix commit b94eeeae7cba5ec4b39e2c6d63bc145f5b43a79d Author: Harry Kalogirou Date: Sun Feb 25 18:06:30 2024 +0200 fix commit 855e72698761a8c7c0246f1daf5d0333d1e13cd3 Author: Harry Kalogirou Date: Sun Feb 25 11:07:59 2024 +0200 more acrobatics for new cconv commit 813ab1081649136aed1821ef36216ec760806d58 Author: Harry Kalogirou Date: Sun Feb 25 00:26:35 2024 +0200 handle mstore arguments in order the old code expects commit 412a8b1ebcdd4e93c3f624187c66451810a95073 Author: Harry Kalogirou Date: Sun Feb 25 00:05:09 2024 +0200 for internals called from ctor commit dbe92023d5b395db19714cdaab8ea67b5cb50f1c Author: Harry Kalogirou Date: Sat Feb 24 22:01:03 2024 +0200 handle unused return values of volatile call and staticcall commit 935a2a9f7ad5156750a0e62da8351dbbda561982 Author: Harry Kalogirou Date: Fri Feb 23 22:39:57 2024 +0200 fix mload handling commit 5e6edd1f66d7b26c8faa0f5eacc2f0293f329d4a Author: Harry Kalogirou Date: Fri Feb 23 18:52:53 2024 +0200 more dynarray fixes commit 20bdc0834260352da9242d220e99b4dfc0a752be Author: Harry Kalogirou Date: Fri Feb 23 18:32:50 2024 +0200 dynarray fixes commit dba4ca2d110e2f6043f931b6c8b0039091c223a9 Merge: ef408e94 977ad793 Author: Harry Kalogirou Date: Fri Feb 23 17:39:48 2024 +0200 Merge branch 'master' into feature/venom_updates commit ef408e941d2370d956947378665ff56ad0c2ae3a Author: Harry Kalogirou Date: Thu Feb 22 23:06:42 2024 +0200 remove unused function commit 7fdf4a59aadcdc91971916f997d38b44e9f7fb58 Author: Harry Kalogirou Date: Thu Feb 22 23:04:56 2024 +0200 cleanup calldatacopy commit ddf41bca6a4ffc256dee82553a4f7eeded55d97f Author: Harry Kalogirou Date: Thu Feb 22 23:03:05 2024 +0200 remove unused function commit e1d5f735f153dc52473f4b4138861fe6bb833b59 Author: Harry Kalogirou Date: Thu Feb 22 18:26:40 2024 +0200 include postamble commit 48b7c6c3e825d03134be133f358b3fb69d21b652 Author: Harry Kalogirou Date: Thu Feb 22 18:20:50 2024 +0200 fix isqrt commit f6da3355680f48706195e9752c879262135f6efa Merge: 154fca3b 9a31ee68 Author: Harry Kalogirou Date: Thu Feb 22 12:48:46 2024 +0200 Merge branch 'master' into feature/venom_updates commit 154fca3b35a772bc927045d0477ad0110ebdfa00 Author: Harry Kalogirou Date: Mon Feb 19 19:25:44 2024 +0200 finalize repeat commit 4d4727a461c5ddc2a5e9b85467f506b60e782fc7 Author: Harry Kalogirou Date: Mon Feb 19 18:31:19 2024 +0200 implement loop bounds commit 231d1d703200495a97e343382bb2b527a3578a48 Author: Harry Kalogirou Date: Mon Feb 19 11:38:56 2024 +0200 fix and optimization commit c53afb8036e3358b13eb99be9be9f72d8d231f33 Author: Harry Kalogirou Date: Mon Feb 19 00:59:23 2024 +0200 more fixes commit c44ef817ccffcb9c2bdda9febd2979cdf784acaf Author: Harry Kalogirou Date: Sun Feb 18 19:43:19 2024 +0200 raise, unreachable, etc commit d04ea938e5695ba93bae143f4c2e463b845388f0 Author: Harry Kalogirou Date: Sun Feb 18 17:19:45 2024 +0200 external call logic simplifications commit af88463463d70fd0d35fce399a61cd0b9b9e76dc Author: Harry Kalogirou Date: Sun Feb 18 17:19:24 2024 +0200 more instructions commit 85d8ec5e096c431cfde9eb66cceb1c6acd0793ff Author: Harry Kalogirou Date: Sun Feb 18 01:43:47 2024 +0200 fix commit 2acf1546d7ba5085e2ba263659104c204fd481f2 Author: Harry Kalogirou Date: Sun Feb 18 00:01:07 2024 +0200 remove unused function commit 850f7af24611da17db53988bc463be0c7a11a23e Author: Harry Kalogirou Date: Sat Feb 17 23:28:46 2024 +0200 fix const array passing commit f754ff08c472fee49f1907685d27decd08dd5094 Author: Harry Kalogirou Date: Sat Feb 17 21:19:33 2024 +0200 add instructions commit e17ddecc37af0b6f13b742cd419e1083ae1454f1 Author: Harry Kalogirou Date: Sat Feb 17 21:02:31 2024 +0200 return buffer hacks commit b9927f96dc08a9777558b932223a58524985bc7f Author: Harry Kalogirou Date: Sat Feb 17 12:01:21 2024 +0200 array returns commit 277a28249a870f21c01647c59fde922552c5bc12 Author: Harry Kalogirou Date: Sat Feb 17 10:05:30 2024 +0200 fix parameter passing case commit d325ca17e0f1d9e84f5903c8aae86d51ecf0a712 Author: Harry Kalogirou Date: Fri Feb 16 23:38:10 2024 +0200 bugfix if commit eefb3ebef7a1482ad65c3e96890590711944da24 Author: Harry Kalogirou Date: Fri Feb 16 23:38:00 2024 +0200 in_vars property commit 9d18a54c2b5c0dda3693e8566985cca8ff24b9eb Author: Harry Kalogirou Date: Fri Feb 16 17:36:47 2024 +0200 fix push literals commit 5a6a260ef338668f1078b0f4280efdff7332a669 Author: Harry Kalogirou Date: Fri Feb 16 17:17:22 2024 +0200 revert commit ef4310340114153a693435236ca42d1a4fcd7393 Author: Harry Kalogirou Date: Fri Feb 16 15:31:57 2024 +0200 addmod mulmod commit c6572bcf538428304851eafe3667d98a0d812d6e Author: Harry Kalogirou Date: Fri Feb 16 15:19:45 2024 +0200 facepalm commit 38c550f0aecd8dfec08fee23834c835fa3e4dfba Author: Harry Kalogirou Date: Fri Feb 16 14:33:02 2024 +0200 extcodecopy commit d19bf392b0dd9f90ca2853d93839f161330cab63 Author: Harry Kalogirou Date: Fri Feb 16 12:25:23 2024 +0200 istore iload commit 60362dab02d120b07d89cfdfc1ec912ae14c19f8 Author: Harry Kalogirou Date: Fri Feb 16 11:56:13 2024 +0200 offset try commit d4ed07d06f3eaca197b06f98c9a3e3dd0a559d7e Author: Harry Kalogirou Date: Fri Feb 16 11:24:42 2024 +0200 creates commit 484df7f8f45ababf28bb86b3c27a8c5ad4cbc8d6 Author: Harry Kalogirou Date: Fri Feb 16 01:17:24 2024 +0200 stuff commit 882116e91cdb639dc7d8c0ed9efa4a43984cf152 Author: Harry Kalogirou Date: Thu Feb 15 21:16:20 2024 +0200 fix constructor exit issue commit 4e28eca264ab69c0dda2f8c88cc5cdceb45d7e35 Author: Harry Kalogirou Date: Thu Feb 15 12:13:40 2024 +0200 enable experimental commit b4cdfa752563a89bd60f90f6bee431bbdc5bf72d Author: Harry Kalogirou Date: Wed Feb 14 21:38:55 2024 +0200 fix internal invocation commit 287c0dd6eb8a11be0aac3b2972e1ce84da1aaef9 Author: Harry Kalogirou Date: Wed Feb 14 20:46:20 2024 +0200 cleanup commit 2057bf366bf9f6baaa5573fc4e1e69ccb6e113e9 Author: Harry Kalogirou Date: Wed Feb 14 16:50:28 2024 +0200 update test commit c5047e50fa0e54c92565ed3d11e34dff3d48b89b Author: Harry Kalogirou Date: Wed Feb 14 16:44:59 2024 +0200 add intersection method to OrderedSet commit 4b1b9b88ae41443f271238f91e6b2c57fc06df24 Author: Harry Kalogirou Date: Wed Feb 14 16:44:44 2024 +0200 move to orderedset commit 7f1e938e13487665512cfbd74306aa24d7bd65c8 Author: Harry Kalogirou Date: Wed Feb 14 13:48:06 2024 +0200 make ssa test commit 245cb271870c96949887d8b88e6523995c197efa Author: Harry Kalogirou Date: Wed Feb 14 13:47:51 2024 +0200 clear out vars on reseting liveness commit 0c0a3cb96704e514bed16a933ed426ef4238d4ee Author: Harry Kalogirou Date: Wed Feb 14 13:47:22 2024 +0200 debuging commit 5a44a8365ce7f414979c76d902ce77f93685fddc Author: Harry Kalogirou Date: Wed Feb 14 10:05:08 2024 +0200 remove debuging commit aa32d41389978928b0085aac456ddd1f5a504672 Author: Harry Kalogirou Date: Wed Feb 14 10:04:52 2024 +0200 bug fix then symbols commit e6f58c920fca84a0aba62650cc6a765734efc614 Author: Harry Kalogirou Date: Wed Feb 14 00:30:53 2024 +0200 fix commit 863a78a3c43a7695328e3dc41dedc5ab6f26fc62 Author: Harry Kalogirou Date: Wed Feb 14 00:30:32 2024 +0200 simplify commit a6533dff923870a0518b14d6b7716271bb5c7392 Author: Harry Kalogirou Date: Tue Feb 13 19:16:45 2024 +0200 refactor commit 0c99b0199b5d2f085c8e8ab0ed82891cf296e7b8 Author: Harry Kalogirou Date: Mon Feb 12 20:10:47 2024 +0200 Revert "get_variable_op" This reverts commit a3ba760444bc55dd71dace7d95fe8a71608840f3. commit a3ba760444bc55dd71dace7d95fe8a71608840f3 Author: Harry Kalogirou Date: Mon Feb 12 14:53:01 2024 +0200 get_variable_op commit b886630f001b60d30e1d032d64867b2ca26facc5 Author: Harry Kalogirou Date: Thu Feb 8 20:54:01 2024 +0200 fix if-else block handling commit 77a633af6dad4b12395b48dbdde6326d773a42b4 Author: Harry Kalogirou Date: Thu Feb 8 20:53:38 2024 +0200 Refactor variable handling in _convert_ir_bb function commit af5f16b9487fdf40a9bac5bf09a74d7d390e0d52 Author: Charles Cooper Date: Wed Feb 7 13:15:43 2024 -0500 add blockhash instruction commit 85ab7c1ded862cb2d2aaefa92dc169bbbeaa33a1 Author: Harry Kalogirou Date: Wed Feb 7 18:39:28 2024 +0200 trascription magic commit c79fae1246d08340bae76d8262a4e738b6dad2ae Author: Harry Kalogirou Date: Wed Feb 7 13:57:14 2024 +0200 fix symbol assignment bug in ir_node_to_venom.py commit eb8662a10e6e2dc8ccdf61cceab1fa53d348aedd Author: Harry Kalogirou Date: Wed Feb 7 12:07:57 2024 +0200 Remove unused method _cleanup_stack_for_ret() in VenomCompiler class commit 694cca3eaf25557438596787f2487a3a27e9eebc Author: Harry Kalogirou Date: Wed Feb 7 12:07:32 2024 +0200 unused params cleanup commit 757698d1570292de8e50e70859d273bb2dc5ef1a Author: Harry Kalogirou Date: Wed Feb 7 00:51:15 2024 +0200 fixes in handling of self calls and internal functions commit beeb6021fdcbb7616bdc78812650d8c53d2c91b4 Author: Harry Kalogirou Date: Wed Feb 7 00:50:49 2024 +0200 fix comment commit ea3d7da9849cc5350e4caee84521d250ed2fcc4f Author: Harry Kalogirou Date: Wed Feb 7 00:50:18 2024 +0200 pop values that are not used commit 5c8909021a1e5ce8ca3c06b801b8d20094f114a9 Author: Harry Kalogirou Date: Tue Feb 6 17:41:04 2024 +0200 Add stack overflow check in VenomCompiler class commit 32cd4b42e8d6b3b325ea338b0968869f9d5903c9 Author: Harry Kalogirou Date: Tue Feb 6 17:19:04 2024 +0200 Update import statement for ERC20 interface commit 3d6caaa9b1a864f1a448c7279ba010f1d2713d61 Author: Harry Kalogirou Date: Tue Feb 6 17:17:35 2024 +0200 Add error handling for variable not in stack commit ba997e32be6a52f3666426b4c647b155292e2e6f Author: Harry Kalogirou Date: Tue Feb 6 16:01:54 2024 +0200 separate dup requirements commit 6dd48735fcc8bdb2dd78cd7daac501621c86fca7 Author: Harry Kalogirou Date: Tue Feb 6 15:40:49 2024 +0200 Remove initial liveness commit f76eeea6cac9f996abacab597409d40555b747c3 Author: Harry Kalogirou Date: Tue Feb 6 15:40:12 2024 +0200 Add is_terminal property to IRBasicBlock and get_terminal_basicblocks method to IRFunction commit 93b910562af1fd58c67196d58ef443d320097100 Merge: 0207dea4 e20885e6 Author: Harry Kalogirou Date: Tue Feb 6 12:00:42 2024 +0200 Merge branch 'master' into feat/ir_to_venom commit 0207dea40b0710d3610e4677cdbb168e344a0c1d Author: Harry Kalogirou Date: Fri Jan 26 00:57:09 2024 +0200 refactor commit 8854cfd72e74f24d31d9331129405abec1312c4a Author: Harry Kalogirou Date: Fri Jan 26 00:53:08 2024 +0200 refactor left out commit eb94c49fe665ff2fe855022de17bb2a9c3e2e25b Author: Harry Kalogirou Date: Thu Jan 25 18:48:39 2024 +0200 oups commit 06b6db1467eca86a824988e49b320c73661c064c Author: Harry Kalogirou Date: Thu Jan 25 18:47:10 2024 +0200 remove old code commit b2a1ca8867b659591d3dcb9ba7e1181c74140407 Author: Harry Kalogirou Date: Thu Jan 25 12:48:05 2024 +0200 mypy commit e01e4565904aa43c34d63ef09ca65a000c0c3cdf Author: Harry Kalogirou Date: Thu Jan 25 12:40:03 2024 +0200 fixes commit 1781680fa41bc66997075853c0bb30fe5fd79d6c Author: Harry Kalogirou Date: Thu Jan 25 00:42:41 2024 +0200 change message to be more informative commit 1710e2d871e7ac5babbaa4f1dc5ef2ce1ce470ae Author: Harry Kalogirou Date: Thu Jan 25 00:40:00 2024 +0200 Add chainid instruction commit 36220984294d42918516e52d973cfbcb028b65ee Author: Harry Kalogirou Date: Thu Jan 25 00:37:58 2024 +0200 translator fix commit 4adbf5a42d37e91df339f1f9a9bb9cf20a9e3733 Author: Harry Kalogirou Date: Wed Jan 24 23:52:54 2024 +0200 Use variable name in allocation commit 38b87ad798fd1b499db8bf6df5dff54c10debc62 Author: Harry Kalogirou Date: Wed Jan 24 21:04:44 2024 +0200 comment commit 05f616b7ce76b11fde04ee4fbb776afcd86324eb Author: Harry Kalogirou Date: Wed Jan 24 20:49:44 2024 +0200 lint commit f31cfecbc74d3cdee4827991483e85dfa93ef6e8 Author: Harry Kalogirou Date: Wed Jan 24 20:39:11 2024 +0200 lint commit 1b6f136f77fc8d864d289ee31df2f03ee54bcbef Author: Harry Kalogirou Date: Wed Jan 24 20:36:48 2024 +0200 simplify repeat commit cc45efcafefa6933c1842aa4fe1f44963e9c2ca5 Author: Harry Kalogirou Date: Wed Jan 24 20:33:21 2024 +0200 Add MakeSSA passes to Venom IR commit 73faa806d9d34bdcd3b5a217482c5ed1943a3fa4 Author: Harry Kalogirou Date: Wed Jan 24 20:32:35 2024 +0200 remove final usage of manual phi commit 6a3593892308d8bc5d7239a0fe95a28fcc86a346 Author: Harry Kalogirou Date: Wed Jan 24 20:13:58 2024 +0200 remove phis commit 35fd6a811ab3bdc8dd257232f4e577ecb92d8ae6 Author: Harry Kalogirou Date: Wed Jan 24 20:13:44 2024 +0200 Update succesor phi instruction label in NormalizationPass commit 6fc5a07382a838ffe62ec813588fbb8ee7b54a55 Author: Harry Kalogirou Date: Wed Jan 24 18:59:53 2024 +0200 more dev commit c99b88bae98dc08da2227a05f740b58e79ca5e83 Author: Harry Kalogirou Date: Wed Jan 24 12:54:39 2024 +0200 Refactor repeat with auto phi commit efea6ba5b7d8ec257a5bb149be36796f79e12ce3 Author: Harry Kalogirou Date: Wed Jan 24 12:53:31 2024 +0200 Remove commented out code commit b7fd201988100317b168dbd31238568daca9e09f Author: Harry Kalogirou Date: Wed Jan 24 12:27:00 2024 +0200 Generalize phi to N inputs commit ad0eb26d70ca574d8faf19603fef3b48f085328f Author: Harry Kalogirou Date: Wed Jan 24 12:06:17 2024 +0200 Refactor conditional block in translator commit 0445941fbdccf2aef01bd7c0b9242066c6ede4f6 Author: Harry Kalogirou Date: Wed Jan 24 12:05:48 2024 +0200 Refactor variable renaming commit 6af5e70f9ba1d467292a9bf8eae66635e0b7d2c1 Author: Harry Kalogirou Date: Wed Jan 24 11:40:29 2024 +0200 Dont show zero commit da959693c68f4ed43855aa8521dd2bcf0de34dc8 Author: Harry Kalogirou Date: Wed Jan 24 11:39:22 2024 +0200 Fix variable version check in IRVariable class and remove commented commit cf8c1f26e004a62e90fb44bbad81dbecde045271 Author: Harry Kalogirou Date: Wed Jan 24 11:38:48 2024 +0200 Fix variable renaming in MakeSSA pass commit c701de729d6d73319921f8e8186cdc09501a671a Author: Harry Kalogirou Date: Tue Jan 23 11:59:22 2024 +0200 Test update commit ff2e2844a2e45ef37dfc0bb9cc97822af834c904 Author: Harry Kalogirou Date: Tue Jan 23 11:58:34 2024 +0200 Refactor MakeSSA pass to accept entry point commit 911ebb2d2b5aaa376c71bf2b0f8064448ac4b7a2 Author: Harry Kalogirou Date: Tue Jan 23 11:58:07 2024 +0200 IRVariables api updates commit 070b4760a1e73b0bf765bc922c4c224f139c3fb2 Author: Harry Kalogirou Date: Tue Jan 23 00:08:11 2024 +0200 Add versioning support to IRVariable constructor commit 9a5513fb4597608219624a3fefc2c2bea40625ba Author: Harry Kalogirou Date: Mon Jan 22 23:56:37 2024 +0200 improvements commit 6bb3dc6f93122dd02f1667170eb31576ae488b25 Author: Harry Kalogirou Date: Mon Jan 22 23:34:38 2024 +0200 more generic commit b1990e462dc223ad83d5db86b2451e3e77ce7166 Author: Harry Kalogirou Date: Mon Jan 22 22:14:04 2024 +0200 Fix formatting commit f7518f16bd4788688daa27f3a8029e8ae29c4e13 Author: Harry Kalogirou Date: Mon Jan 22 22:11:56 2024 +0200 lint commit 41b95977edeccc2d3b99002fcf274c6dd470ac0d Author: Harry Kalogirou Date: Mon Jan 22 22:07:41 2024 +0200 Fix variable renaming commit a6d969311abf89289afe1431131e2fd23231c614 Author: Harry Kalogirou Date: Mon Jan 22 21:54:04 2024 +0200 Add variable name property to IRVariable class and implement variable renaming in MakeSSA pass commit 4c25296d0fc67065c47a8f87028a9d26d933aa8a Author: Harry Kalogirou Date: Mon Jan 22 21:26:05 2024 +0200 refactor commit 109c697acedc901830ef8405e7faa23938586c85 Author: Harry Kalogirou Date: Mon Jan 22 21:13:54 2024 +0200 renaming start commit d441c5ed86638aa21071dacfb8dc49450483c232 Author: Harry Kalogirou Date: Mon Jan 22 21:13:34 2024 +0200 add get_assignments method commit 038caf91f53b4469aeb9d5223a5bb84aa9dd53ef Author: Harry Kalogirou Date: Mon Jan 22 21:13:09 2024 +0200 Add support for tracking dominated blocks in DominatorTree commit b3a450fcf29fa9e027224c1c240749ad3898d64b Author: Harry Kalogirou Date: Mon Jan 22 20:32:17 2024 +0200 phi placement commit 0be6409a105cb020731133a0685297fde50f10e5 Author: Harry Kalogirou Date: Mon Jan 22 14:41:04 2024 +0200 Remove testing code commit cbd0fd24717b40252b28688cc91f79bd80c49955 Author: Harry Kalogirou Date: Mon Jan 22 14:32:44 2024 +0200 Add test for phi placement commit 495d3f900e9ab630690fff1274f9b0f6909a68c7 Author: Harry Kalogirou Date: Mon Jan 22 14:12:24 2024 +0200 refactor test commit 73b81632dd18554797d67b1bc0a385075b5655ed Author: Harry Kalogirou Date: Mon Jan 22 13:52:11 2024 +0200 Add test for dominator tree calculation commit 9c294c787b4b0f2d5359348a46c988dc355f042b Author: Harry Kalogirou Date: Mon Jan 22 13:10:03 2024 +0200 Add dominance frontier computation commit 5b0a0622d7f920a5251acbea00dbc9820c807909 Author: Harry Kalogirou Date: Mon Jan 22 02:14:25 2024 +0200 Dominance calculations commit 9f2606be53aa3f0317784fa2edb8502973717db7 Author: Harry Kalogirou Date: Sun Jan 21 12:42:37 2024 +0200 Graphviz output commit 2c7999df708a8aa4fc7397f6849828adee3974dc Author: Harry Kalogirou Date: Sun Jan 21 00:12:08 2024 +0200 comment commit 91f9fd9f65d1aef5123b68720514328d33672bf5 Author: Harry Kalogirou Date: Sun Jan 21 00:01:34 2024 +0200 Add remove_instruction method, is_empty property to IRBasicBlock class commit 8dd4635837ad3c3219ea505def98cbf26df951ed Author: Harry Kalogirou Date: Sun Jan 21 00:00:43 2024 +0200 Fix unreachable block removal - remove orphan phis commit 6ba2e44b5916dc52f8e4ce286d35d06636db9fd3 Author: Harry Kalogirou Date: Sat Jan 20 18:53:12 2024 +0200 dyarray in loops issues commit e9ec36e426663d3b72a51411807fc74f10bf6b18 Author: Harry Kalogirou Date: Sat Jan 20 14:56:35 2024 +0200 add sink block at iftheelse code commit 45410440a021a744747ce04282b847b6acbe4c27 Author: Harry Kalogirou Date: Sat Jan 20 13:25:09 2024 +0200 Add Iterator support to OrderedSet class commit cad98ed81068e735c3ad2fc711d810b1f081314a Author: Harry Kalogirou Date: Fri Jan 19 20:05:28 2024 +0200 back to removal of bb commit 47a06862ddfa8607542975311ba64c0a19dc020f Author: Harry Kalogirou Date: Fri Jan 19 19:48:28 2024 +0200 Add daisy chaining of empty basic blocks as an alternative to block removal commit cb119d8b76a010cbc49b59bb1c86cc4794959352 Author: Harry Kalogirou Date: Fri Jan 19 19:06:06 2024 +0200 Update test_multi_entry_block.py with correct label names commit 185efde3904ce4eb37fd834493aaee7971231a91 Author: Harry Kalogirou Date: Fri Jan 19 19:05:55 2024 +0200 Update label naming issue in NormalizationPass and recalc reachability commit 128f0736ff7a46c56ea98ab84a9b8b2826670377 Author: Harry Kalogirou Date: Fri Jan 19 18:35:19 2024 +0200 Multi datacopy demultiplexing commit 40d2a0924ab0a22728ce5dd48e3f73c5e8896518 Author: Harry Kalogirou Date: Fri Jan 19 15:18:11 2024 +0200 Commented out stack reordering code commit 6b689987b945a1cddc5b8796e4c036f89eca6101 Author: Harry Kalogirou Date: Fri Jan 19 14:19:13 2024 +0200 Fix stack reordering multiples of operands case commit 96007e3bedd90448184b87aa8fce0a2e27e76a2a Author: Harry Kalogirou Date: Fri Jan 19 13:01:19 2024 +0200 call staticcall return fix commit 1d8276dbd1582e64386c080214bd666ff332db5e Merge: 33d015cc 55e18f6d Author: Harry Kalogirou Date: Fri Jan 19 01:33:37 2024 +0200 Merge remote-tracking branch 'origin-harkal/master' into feat/ir_to_venom commit 33d015cc5a9d7d5761ac566cf242ffc91814373e Author: Harry Kalogirou Date: Fri Jan 19 01:31:47 2024 +0200 lint commit 5f3b4d237c7e5b9b274d562dc625b13108aebf9a Author: Harry Kalogirou Date: Fri Jan 19 01:30:01 2024 +0200 New reachability commit a3b476cdde4582f4cc6d7a97c9885488f4017e09 Author: Harry Kalogirou Date: Fri Jan 19 00:54:50 2024 +0200 new bb reachability commit 7c0fe7581ad9aaafe7f12be36a09d92c293e6ae2 Author: Harry Kalogirou Date: Fri Jan 19 00:36:31 2024 +0200 Add iteration limit check in IR pass commit 5e4fe897b11e2b353b20849748bd179bc56d6cad Author: Harry Kalogirou Date: Thu Jan 18 22:41:57 2024 +0200 add call test commit e0e717707008428acf5daa9ea0976785da2e4fb9 Author: Harry Kalogirou Date: Thu Jan 18 22:25:43 2024 +0200 fix adding instruction to terminated bb add extra instructions commit 3455ef615359c0eb3412ae5c0473313c35cb8e3e Author: Harry Kalogirou Date: Thu Jan 18 16:00:56 2024 +0200 Invoke is a cfg altering instruction commit 470381133d804b295d007f7477e603527a116fae Merge: 929b546c 41777454 Author: Harry Kalogirou Date: Thu Jan 18 15:57:01 2024 +0200 Merge branch 'master' into feat/ir_to_venom commit 929b546cbf82eeb579cd5f6081985866cc8dd5c8 Merge: 6e86f176 c42b077c Author: Harry Kalogirou Date: Thu Jan 18 15:52:08 2024 +0200 Merge branch 'master' into feat/ir_to_venom commit 6e86f176c05c6b11b3647c17fa538211420ad720 Author: Harry Kalogirou Date: Thu Jan 18 14:59:35 2024 +0200 assert BasicBlock is not terminated when inserting commit cbbe21cdc2ad1e325241576084fe7b9702b00c90 Author: Harry Kalogirou Date: Thu Jan 18 12:59:17 2024 +0200 fix call return value issue commit 3697cf5980776e421e2e2701e58da6f2abba009a Author: Harry Kalogirou Date: Thu Jan 18 12:57:46 2024 +0200 insert_instruction default to insert at the end of the block commit 0cc222ad18df54678a0c084f4f15985168b94002 Author: Harry Kalogirou Date: Wed Jan 17 16:54:33 2024 +0200 Remove unused import statement commit 353fefa599e95e6bcc693e969fb57f11383d08a4 Author: Harry Kalogirou Date: Wed Jan 17 16:52:58 2024 +0200 Add test for liveness in a simple loop commit e7d2b40635377c662f2dcfef091fbbc1f4370ccb Author: Harry Kalogirou Date: Wed Jan 17 16:49:15 2024 +0200 update test commit 428c910a4de951768d066272197daf2651935742 Author: Harry Kalogirou Date: Wed Jan 17 16:48:19 2024 +0200 liveness calculation and fixed a bug * Converted algorithm to iterative * fixed a bug related to simple loops commit 1eae31b9287874c5f2c9e199f03ad297e0c9e09d Author: Harry Kalogirou Date: Tue Jan 16 15:49:43 2024 +0200 Remove unused function _get_symbols_accessed() commit 978316cd94b270c4c562119cde793d584a803e58 Author: Harry Kalogirou Date: Tue Jan 16 15:49:11 2024 +0200 Add _get_symbols_accessed function to ir_node_to_venom.py commit 33d1c72d20b6aa38ee5ae92e07f5bfc6373bfe1b Author: Harry Kalogirou Date: Mon Jan 15 21:50:59 2024 +0200 Fix conditional block termination issue commit 3ec3a51a367c2b8a83671c80d34a3d9a0623d7f5 Author: Harry Kalogirou Date: Mon Jan 15 14:11:49 2024 +0200 clean up ir to venom commit 33e5b5a7bab62b338b80b1084dbdbc3d9e1fed19 Author: Harry Kalogirou Date: Mon Jan 15 14:11:15 2024 +0200 Add new test cases for simple conversion in test_convert_basicblock_simple.py commit d6af7fe12ae858029bf0fbe4a36073e2ce37b6c5 Author: Harry Kalogirou Date: Mon Jan 15 09:00:03 2024 +0200 Clean up whitespace test_convert_basicblock_simple.py commit bcc63adcc58f4678dd7c8872dc3738f3c65cbcbe Author: Harry Kalogirou Date: Mon Jan 15 08:59:46 2024 +0200 Refactor code for cleaner venom output and lint stuff commit f338abe5734b6e8c2e98e4e07390f27a5675e30b Author: Harry Kalogirou Date: Mon Jan 15 08:52:56 2024 +0200 Add unit test for converting basic block in Venom compiler commit 5dd5fe65af431946152b72f8c417bba5d059f903 Author: Harry Kalogirou Date: Mon Jan 15 08:52:29 2024 +0200 Update IRFunction's __str__ method to remove trailing whitespace commit 2dc412c0d677d938af248b3faa1473c7f4a965f5 Author: Harry Kalogirou Date: Mon Jan 15 08:43:54 2024 +0200 Fix unterminated basic blocks in IR to Venom conversion commit bee2416a32bdd377cda1132810f353e67460477b Author: Harry Kalogirou Date: Mon Jan 15 08:40:24 2024 +0200 Generalize the conversion of IR nodes to venom Make the functions handle the case there is no deploy instructions updated function name from `_global` to `__global` generate labels in the context pass manager fixed bug in normalization pass refactored code in `bb_optimizer.py` added new analysis module fixed bug in VenomCompiler class refactors convert to just return false as no change made refactor remove bb_optimize update test fix tests remove unused import review comments, lint linter wrestling docs comments and refactor passmanager tied to function lint remove loop --- .../venom/test_convert_basicblock_simple.py | 4 +- .../compiler/venom/test_dominator_tree.py | 45 +-- .../compiler/venom/test_duplicate_operands.py | 7 +- tests/unit/compiler/venom/test_make_ssa.py | 32 +-- .../compiler/venom/test_multi_entry_block.py | 102 +++---- tests/unit/compiler/venom/test_sccp.py | 88 +++--- vyper/utils.py | 22 -- vyper/venom/__init__.py | 85 ++---- vyper/venom/analysis.py | 198 ------------- vyper/venom/analysis/__init__.py | 0 vyper/venom/analysis/analysis.py | 25 ++ vyper/venom/analysis/cfg.py | 43 +++ vyper/venom/analysis/dfg.py | 63 +++++ vyper/venom/{ => analysis}/dominators.py | 22 +- vyper/venom/analysis/dup_requirements.py | 15 + vyper/venom/analysis/liveness.py | 90 ++++++ vyper/venom/bb_optimizer.py | 93 ------- vyper/venom/context.py | 67 +++++ vyper/venom/function.py | 66 ++--- vyper/venom/ir_node_to_venom.py | 263 +++++++++--------- vyper/venom/passes/base_pass.py | 22 +- vyper/venom/passes/constant_propagation.py | 13 - vyper/venom/passes/dft.py | 19 +- vyper/venom/passes/make_ssa.py | 26 +- vyper/venom/passes/mem2var.py | 30 +- vyper/venom/passes/normalization.py | 35 ++- vyper/venom/passes/pass_manager.py | 60 ++++ vyper/venom/passes/remove_unused_variables.py | 22 ++ vyper/venom/passes/sccp/sccp.py | 42 +-- vyper/venom/passes/simplify_cfg.py | 69 ++++- vyper/venom/passes/stack_reorder.py | 11 +- vyper/venom/venom_to_assembly.py | 34 +-- 32 files changed, 901 insertions(+), 812 deletions(-) delete mode 100644 vyper/venom/analysis.py create mode 100644 vyper/venom/analysis/__init__.py create mode 100644 vyper/venom/analysis/analysis.py create mode 100644 vyper/venom/analysis/cfg.py create mode 100644 vyper/venom/analysis/dfg.py rename vyper/venom/{ => analysis}/dominators.py (93%) create mode 100644 vyper/venom/analysis/dup_requirements.py create mode 100644 vyper/venom/analysis/liveness.py delete mode 100644 vyper/venom/bb_optimizer.py create mode 100644 vyper/venom/context.py delete mode 100644 vyper/venom/passes/constant_propagation.py create mode 100644 vyper/venom/passes/pass_manager.py create mode 100644 vyper/venom/passes/remove_unused_variables.py diff --git a/tests/unit/compiler/venom/test_convert_basicblock_simple.py b/tests/unit/compiler/venom/test_convert_basicblock_simple.py index fdaa341a81..6dba9588bf 100644 --- a/tests/unit/compiler/venom/test_convert_basicblock_simple.py +++ b/tests/unit/compiler/venom/test_convert_basicblock_simple.py @@ -8,7 +8,9 @@ def test_simple(): venom = ir_node_to_venom(ir_node) assert venom is not None - bb = venom.basic_blocks[0] + fn = list(venom.functions.values())[0] + + bb = fn.basic_blocks[0] assert bb.instructions[0].opcode == "calldatasize" assert bb.instructions[1].opcode == "calldatacopy" diff --git a/tests/unit/compiler/venom/test_dominator_tree.py b/tests/unit/compiler/venom/test_dominator_tree.py index c5b7404b58..202aaefb75 100644 --- a/tests/unit/compiler/venom/test_dominator_tree.py +++ b/tests/unit/compiler/venom/test_dominator_tree.py @@ -2,18 +2,19 @@ from vyper.exceptions import CompilerPanic from vyper.utils import OrderedSet -from vyper.venom.analysis import calculate_cfg +from vyper.venom.analysis.dominators import DominatorTreeAnalysis from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRLabel, IRLiteral, IRVariable -from vyper.venom.dominators import DominatorTree +from vyper.venom.context import IRContext from vyper.venom.function import IRFunction from vyper.venom.passes.make_ssa import MakeSSA +from vyper.venom.passes.pass_manager import IRPassManager def _add_bb( - ctx: IRFunction, label: IRLabel, cfg_outs: [IRLabel], bb: Optional[IRBasicBlock] = None + fn: IRFunction, label: IRLabel, cfg_outs: list[IRLabel], bb: Optional[IRBasicBlock] = None ) -> IRBasicBlock: - bb = bb if bb is not None else IRBasicBlock(label, ctx) - ctx.append_basic_block(bb) + bb = bb if bb is not None else IRBasicBlock(label, fn) + fn.append_basic_block(bb) cfg_outs_len = len(cfg_outs) if cfg_outs_len == 0: bb.append_instruction("stop") @@ -29,27 +30,28 @@ def _add_bb( def _make_test_ctx(): lab = [IRLabel(str(i)) for i in range(0, 9)] - ctx = IRFunction(lab[1]) + ctx = IRContext() + fn = ctx.create_function(lab[1].value) - bb1 = ctx.basic_blocks[0] + bb1 = fn.basic_blocks[0] bb1.append_instruction("jmp", lab[2]) - _add_bb(ctx, lab[7], []) - _add_bb(ctx, lab[6], [lab[7], lab[2]]) - _add_bb(ctx, lab[5], [lab[6], lab[3]]) - _add_bb(ctx, lab[4], [lab[6]]) - _add_bb(ctx, lab[3], [lab[5]]) - _add_bb(ctx, lab[2], [lab[3], lab[4]]) + _add_bb(fn, lab[7], []) + _add_bb(fn, lab[6], [lab[7], lab[2]]) + _add_bb(fn, lab[5], [lab[6], lab[3]]) + _add_bb(fn, lab[4], [lab[6]]) + _add_bb(fn, lab[3], [lab[5]]) + _add_bb(fn, lab[2], [lab[3], lab[4]]) - return ctx + return fn def test_deminator_frontier_calculation(): - ctx = _make_test_ctx() - bb1, bb2, bb3, bb4, bb5, bb6, bb7 = [ctx.get_basic_block(str(i)) for i in range(1, 8)] + fn = _make_test_ctx() + bb1, bb2, bb3, bb4, bb5, bb6, bb7 = [fn.get_basic_block(str(i)) for i in range(1, 8)] - calculate_cfg(ctx) - dom = DominatorTree.build_dominator_tree(ctx, bb1) + pm = IRPassManager(fn) + dom = pm.request_analysis(DominatorTreeAnalysis) df = dom.dominator_frontiers assert len(df[bb1]) == 0, df[bb1] @@ -62,12 +64,13 @@ def test_deminator_frontier_calculation(): def test_phi_placement(): - ctx = _make_test_ctx() - bb1, bb2, bb3, bb4, bb5, bb6, bb7 = [ctx.get_basic_block(str(i)) for i in range(1, 8)] + fn = _make_test_ctx() + bb1, bb2, bb3, bb4, bb5, bb6, bb7 = [fn.get_basic_block(str(i)) for i in range(1, 8)] x = IRVariable("%x") bb1.insert_instruction(IRInstruction("mload", [IRLiteral(0)], x), 0) bb2.insert_instruction(IRInstruction("add", [x, IRLiteral(1)], x), 0) bb7.insert_instruction(IRInstruction("mstore", [x, IRLiteral(0)]), 0) - MakeSSA().run_pass(ctx, bb1) + pm = IRPassManager(fn) + MakeSSA(pm).run_pass() diff --git a/tests/unit/compiler/venom/test_duplicate_operands.py b/tests/unit/compiler/venom/test_duplicate_operands.py index 7cc58e6f5c..44c4ed0404 100644 --- a/tests/unit/compiler/venom/test_duplicate_operands.py +++ b/tests/unit/compiler/venom/test_duplicate_operands.py @@ -1,6 +1,6 @@ from vyper.compiler.settings import OptimizationLevel from vyper.venom import generate_assembly_experimental -from vyper.venom.function import IRFunction +from vyper.venom.context import IRContext def test_duplicate_operands(): @@ -15,8 +15,9 @@ def test_duplicate_operands(): Should compile to: [PUSH1, 10, DUP1, DUP1, DUP1, ADD, MUL, STOP] """ - ctx = IRFunction() - bb = ctx.get_basic_block() + ctx = IRContext() + fn = ctx.create_function("test") + bb = fn.get_basic_block() op = bb.append_instruction("store", 10) sum_ = bb.append_instruction("add", op, op) bb.append_instruction("mul", sum_, op) diff --git a/tests/unit/compiler/venom/test_make_ssa.py b/tests/unit/compiler/venom/test_make_ssa.py index da3a143b30..fd4b7d15b9 100644 --- a/tests/unit/compiler/venom/test_make_ssa.py +++ b/tests/unit/compiler/venom/test_make_ssa.py @@ -1,22 +1,23 @@ -from vyper.venom.analysis import calculate_cfg, calculate_liveness from vyper.venom.basicblock import IRBasicBlock, IRLabel -from vyper.venom.function import IRFunction +from vyper.venom.context import IRContext from vyper.venom.passes.make_ssa import MakeSSA +from vyper.venom.passes.pass_manager import IRPassManager def test_phi_case(): - ctx = IRFunction(IRLabel("_global")) + ctx = IRContext() + fn = ctx.create_function("_global") - bb = ctx.get_basic_block() + bb = fn.get_basic_block() - bb_cont = IRBasicBlock(IRLabel("condition"), ctx) - bb_then = IRBasicBlock(IRLabel("then"), ctx) - bb_else = IRBasicBlock(IRLabel("else"), ctx) - bb_if_exit = IRBasicBlock(IRLabel("if_exit"), ctx) - ctx.append_basic_block(bb_cont) - ctx.append_basic_block(bb_then) - ctx.append_basic_block(bb_else) - ctx.append_basic_block(bb_if_exit) + bb_cont = IRBasicBlock(IRLabel("condition"), fn) + bb_then = IRBasicBlock(IRLabel("then"), fn) + bb_else = IRBasicBlock(IRLabel("else"), fn) + bb_if_exit = IRBasicBlock(IRLabel("if_exit"), fn) + fn.append_basic_block(bb_cont) + fn.append_basic_block(bb_then) + fn.append_basic_block(bb_else) + fn.append_basic_block(bb_if_exit) v = bb.append_instruction("mload", 64) bb_cont.append_instruction("jnz", v, bb_then.label, bb_else.label) @@ -30,11 +31,10 @@ def test_phi_case(): bb.append_instruction("jmp", bb_cont.label) - calculate_cfg(ctx) - MakeSSA().run_pass(ctx, ctx.basic_blocks[0]) - calculate_liveness(ctx) + pm = IRPassManager(fn) + MakeSSA(pm).run_pass() - condition_block = ctx.get_basic_block("condition") + condition_block = fn.get_basic_block("condition") assert len(condition_block.instructions) == 2 phi_inst = condition_block.instructions[0] diff --git a/tests/unit/compiler/venom/test_multi_entry_block.py b/tests/unit/compiler/venom/test_multi_entry_block.py index 95b6e62daf..17528557e1 100644 --- a/tests/unit/compiler/venom/test_multi_entry_block.py +++ b/tests/unit/compiler/venom/test_multi_entry_block.py @@ -1,44 +1,48 @@ -from vyper.venom.analysis import calculate_cfg -from vyper.venom.function import IRBasicBlock, IRFunction, IRLabel +from vyper.venom.analysis.cfg import CFGAnalysis +from vyper.venom.context import IRContext +from vyper.venom.function import IRBasicBlock, IRLabel from vyper.venom.passes.normalization import NormalizationPass +from vyper.venom.passes.pass_manager import IRPassManager def test_multi_entry_block_1(): - ctx = IRFunction() + ctx = IRContext() + fn = ctx.create_function("__global") finish_label = IRLabel("finish") target_label = IRLabel("target") - block_1_label = IRLabel("block_1", ctx) + block_1_label = IRLabel("block_1", fn) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() op = bb.append_instruction("store", 10) acc = bb.append_instruction("add", op, op) bb.append_instruction("jnz", acc, finish_label, block_1_label) - block_1 = IRBasicBlock(block_1_label, ctx) - ctx.append_basic_block(block_1) + block_1 = IRBasicBlock(block_1_label, fn) + fn.append_basic_block(block_1) acc = block_1.append_instruction("add", acc, op) op = block_1.append_instruction("store", 10) block_1.append_instruction("mstore", acc, op) block_1.append_instruction("jnz", acc, finish_label, target_label) - target_bb = IRBasicBlock(target_label, ctx) - ctx.append_basic_block(target_bb) + target_bb = IRBasicBlock(target_label, fn) + fn.append_basic_block(target_bb) target_bb.append_instruction("mul", acc, acc) target_bb.append_instruction("jmp", finish_label) - finish_bb = IRBasicBlock(finish_label, ctx) - ctx.append_basic_block(finish_bb) + finish_bb = IRBasicBlock(finish_label, fn) + fn.append_basic_block(finish_bb) finish_bb.append_instruction("stop") - calculate_cfg(ctx) - assert not ctx.normalized, "CFG should not be normalized" + pm = IRPassManager(fn) + pm.request_analysis(CFGAnalysis) + assert not fn.normalized, "CFG should not be normalized" - NormalizationPass().run_pass(ctx) + NormalizationPass(pm).run_pass() - assert ctx.normalized, "CFG should be normalized" + assert fn.normalized, "CFG should be normalized" - finish_bb = ctx.get_basic_block(finish_label.value) + finish_bb = fn.get_basic_block(finish_label.value) cfg_in = list(finish_bb.cfg_in) assert cfg_in[0].label.value == "target", "Should contain target" assert cfg_in[1].label.value == "__global_split_finish", "Should contain __global_split_finish" @@ -47,50 +51,52 @@ def test_multi_entry_block_1(): # more complicated one def test_multi_entry_block_2(): - ctx = IRFunction() + ctx = IRContext() + fn = ctx.create_function("__global") finish_label = IRLabel("finish") target_label = IRLabel("target") - block_1_label = IRLabel("block_1", ctx) - block_2_label = IRLabel("block_2", ctx) + block_1_label = IRLabel("block_1", fn) + block_2_label = IRLabel("block_2", fn) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() op = bb.append_instruction("store", 10) acc = bb.append_instruction("add", op, op) bb.append_instruction("jnz", acc, finish_label, block_1_label) - block_1 = IRBasicBlock(block_1_label, ctx) - ctx.append_basic_block(block_1) + block_1 = IRBasicBlock(block_1_label, fn) + fn.append_basic_block(block_1) acc = block_1.append_instruction("add", acc, op) op = block_1.append_instruction("store", 10) block_1.append_instruction("mstore", acc, op) block_1.append_instruction("jnz", acc, target_label, finish_label) - block_2 = IRBasicBlock(block_2_label, ctx) - ctx.append_basic_block(block_2) + block_2 = IRBasicBlock(block_2_label, fn) + fn.append_basic_block(block_2) acc = block_2.append_instruction("add", acc, op) op = block_2.append_instruction("store", 10) block_2.append_instruction("mstore", acc, op) # switch the order of the labels, for fun and profit block_2.append_instruction("jnz", acc, finish_label, target_label) - target_bb = IRBasicBlock(target_label, ctx) - ctx.append_basic_block(target_bb) + target_bb = IRBasicBlock(target_label, fn) + fn.append_basic_block(target_bb) target_bb.append_instruction("mul", acc, acc) target_bb.append_instruction("jmp", finish_label) - finish_bb = IRBasicBlock(finish_label, ctx) - ctx.append_basic_block(finish_bb) + finish_bb = IRBasicBlock(finish_label, fn) + fn.append_basic_block(finish_bb) finish_bb.append_instruction("stop") - calculate_cfg(ctx) - assert not ctx.normalized, "CFG should not be normalized" + pm = IRPassManager(fn) + pm.request_analysis(CFGAnalysis) + assert not fn.normalized, "CFG should not be normalized" - NormalizationPass().run_pass(ctx) + NormalizationPass(pm).run_pass() - assert ctx.normalized, "CFG should be normalized" + assert fn.normalized, "CFG should be normalized" - finish_bb = ctx.get_basic_block(finish_label.value) + finish_bb = fn.get_basic_block(finish_label.value) cfg_in = list(finish_bb.cfg_in) assert cfg_in[0].label.value == "target", "Should contain target" assert cfg_in[1].label.value == "__global_split_finish", "Should contain __global_split_finish" @@ -98,40 +104,42 @@ def test_multi_entry_block_2(): def test_multi_entry_block_with_dynamic_jump(): - ctx = IRFunction() + ctx = IRContext() + fn = ctx.create_function("__global") finish_label = IRLabel("finish") target_label = IRLabel("target") - block_1_label = IRLabel("block_1", ctx) + block_1_label = IRLabel("block_1", fn) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() op = bb.append_instruction("store", 10) acc = bb.append_instruction("add", op, op) bb.append_instruction("djmp", acc, finish_label, block_1_label) - block_1 = IRBasicBlock(block_1_label, ctx) - ctx.append_basic_block(block_1) + block_1 = IRBasicBlock(block_1_label, fn) + fn.append_basic_block(block_1) acc = block_1.append_instruction("add", acc, op) op = block_1.append_instruction("store", 10) block_1.append_instruction("mstore", acc, op) block_1.append_instruction("jnz", acc, finish_label, target_label) - target_bb = IRBasicBlock(target_label, ctx) - ctx.append_basic_block(target_bb) + target_bb = IRBasicBlock(target_label, fn) + fn.append_basic_block(target_bb) target_bb.append_instruction("mul", acc, acc) target_bb.append_instruction("jmp", finish_label) - finish_bb = IRBasicBlock(finish_label, ctx) - ctx.append_basic_block(finish_bb) + finish_bb = IRBasicBlock(finish_label, fn) + fn.append_basic_block(finish_bb) finish_bb.append_instruction("stop") - calculate_cfg(ctx) - assert not ctx.normalized, "CFG should not be normalized" + pm = IRPassManager(fn) + pm.request_analysis(CFGAnalysis) + assert not fn.normalized, "CFG should not be normalized" - NormalizationPass().run_pass(ctx) - assert ctx.normalized, "CFG should be normalized" + NormalizationPass(pm).run_pass() + assert fn.normalized, "CFG should be normalized" - finish_bb = ctx.get_basic_block(finish_label.value) + finish_bb = fn.get_basic_block(finish_label.value) cfg_in = list(finish_bb.cfg_in) assert cfg_in[0].label.value == "target", "Should contain target" assert cfg_in[1].label.value == "__global_split_finish", "Should contain __global_split_finish" diff --git a/tests/unit/compiler/venom/test_sccp.py b/tests/unit/compiler/venom/test_sccp.py index 8102a0d89c..62f490d343 100644 --- a/tests/unit/compiler/venom/test_sccp.py +++ b/tests/unit/compiler/venom/test_sccp.py @@ -1,24 +1,26 @@ from vyper.venom.basicblock import IRBasicBlock, IRLabel, IRVariable -from vyper.venom.function import IRFunction +from vyper.venom.context import IRContext from vyper.venom.passes.make_ssa import MakeSSA +from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.passes.sccp import SCCP from vyper.venom.passes.sccp.sccp import LatticeEnum def test_simple_case(): - ctx = IRFunction(IRLabel("_global")) + ctx = IRContext() + fn = ctx.create_function("_global") - bb = ctx.get_basic_block() + bb = fn.get_basic_block() p1 = bb.append_instruction("param") op1 = bb.append_instruction("store", 32) op2 = bb.append_instruction("store", 64) op3 = bb.append_instruction("add", op1, op2) bb.append_instruction("return", p1, op3) - make_ssa_pass = MakeSSA() - make_ssa_pass.run_pass(ctx, ctx.basic_blocks[0]) - sccp = SCCP(make_ssa_pass.dom) - sccp.run_pass(ctx, ctx.basic_blocks[0]) + pm = IRPassManager(fn) + MakeSSA(pm).run_pass() + sccp = SCCP(pm) + sccp.run_pass() assert sccp.lattice[IRVariable("%1")] == LatticeEnum.BOTTOM assert sccp.lattice[IRVariable("%2")].value == 32 @@ -27,14 +29,15 @@ def test_simple_case(): def test_cont_jump_case(): - ctx = IRFunction(IRLabel("_global")) + ctx = IRContext() + fn = ctx.create_function("_global") - bb = ctx.get_basic_block() + bb = fn.get_basic_block() - br1 = IRBasicBlock(IRLabel("then"), ctx) - ctx.append_basic_block(br1) - br2 = IRBasicBlock(IRLabel("else"), ctx) - ctx.append_basic_block(br2) + br1 = IRBasicBlock(IRLabel("then"), fn) + fn.append_basic_block(br1) + br2 = IRBasicBlock(IRLabel("else"), fn) + fn.append_basic_block(br2) p1 = bb.append_instruction("param") op1 = bb.append_instruction("store", 32) @@ -47,10 +50,10 @@ def test_cont_jump_case(): br2.append_instruction("add", op3, p1) br2.append_instruction("stop") - make_ssa_pass = MakeSSA() - make_ssa_pass.run_pass(ctx, ctx.basic_blocks[0]) - sccp = SCCP(make_ssa_pass.dom) - sccp.run_pass(ctx, ctx.basic_blocks[0]) + pm = IRPassManager(fn) + MakeSSA(pm).run_pass() + sccp = SCCP(pm) + sccp.run_pass() assert sccp.lattice[IRVariable("%1")] == LatticeEnum.BOTTOM assert sccp.lattice[IRVariable("%2")].value == 32 @@ -61,16 +64,17 @@ def test_cont_jump_case(): def test_cont_phi_case(): - ctx = IRFunction(IRLabel("_global")) + ctx = IRContext() + fn = ctx.create_function("_global") - bb = ctx.get_basic_block() + bb = fn.get_basic_block() - br1 = IRBasicBlock(IRLabel("then"), ctx) - ctx.append_basic_block(br1) - br2 = IRBasicBlock(IRLabel("else"), ctx) - ctx.append_basic_block(br2) - join = IRBasicBlock(IRLabel("join"), ctx) - ctx.append_basic_block(join) + br1 = IRBasicBlock(IRLabel("then"), fn) + fn.append_basic_block(br1) + br2 = IRBasicBlock(IRLabel("else"), fn) + fn.append_basic_block(br2) + join = IRBasicBlock(IRLabel("join"), fn) + fn.append_basic_block(join) p1 = bb.append_instruction("param") op1 = bb.append_instruction("store", 32) @@ -85,11 +89,10 @@ def test_cont_phi_case(): join.append_instruction("return", op4, p1) - make_ssa_pass = MakeSSA() - make_ssa_pass.run_pass(ctx, ctx.basic_blocks[0]) - - sccp = SCCP(make_ssa_pass.dom) - sccp.run_pass(ctx, ctx.basic_blocks[0]) + pm = IRPassManager(fn) + MakeSSA(pm).run_pass() + sccp = SCCP(pm) + sccp.run_pass() assert sccp.lattice[IRVariable("%1")] == LatticeEnum.BOTTOM assert sccp.lattice[IRVariable("%2")].value == 32 @@ -101,16 +104,17 @@ def test_cont_phi_case(): def test_cont_phi_const_case(): - ctx = IRFunction(IRLabel("_global")) + ctx = IRContext() + fn = ctx.create_function("_global") - bb = ctx.get_basic_block() + bb = fn.get_basic_block() - br1 = IRBasicBlock(IRLabel("then"), ctx) - ctx.append_basic_block(br1) - br2 = IRBasicBlock(IRLabel("else"), ctx) - ctx.append_basic_block(br2) - join = IRBasicBlock(IRLabel("join"), ctx) - ctx.append_basic_block(join) + br1 = IRBasicBlock(IRLabel("then"), fn) + fn.append_basic_block(br1) + br2 = IRBasicBlock(IRLabel("else"), fn) + fn.append_basic_block(br2) + join = IRBasicBlock(IRLabel("join"), fn) + fn.append_basic_block(join) p1 = bb.append_instruction("store", 1) op1 = bb.append_instruction("store", 32) @@ -125,10 +129,10 @@ def test_cont_phi_const_case(): join.append_instruction("return", op4, p1) - make_ssa_pass = MakeSSA() - make_ssa_pass.run_pass(ctx, ctx.basic_blocks[0]) - sccp = SCCP(make_ssa_pass.dom) - sccp.run_pass(ctx, ctx.basic_blocks[0]) + pm = IRPassManager(fn) + MakeSSA(pm).run_pass() + sccp = SCCP(pm) + sccp.run_pass() assert sccp.lattice[IRVariable("%1")].value == 1 assert sccp.lattice[IRVariable("%2")].value == 32 diff --git a/vyper/utils.py b/vyper/utils.py index 01ae37e213..600f5552ab 100644 --- a/vyper/utils.py +++ b/vyper/utils.py @@ -578,25 +578,3 @@ def annotate_source_code( cleanup_lines += [""] * (num_lines - len(cleanup_lines)) return "\n".join(cleanup_lines) - - -def ir_pass(func): - """ - Decorator for IR passes. This decorator will run the pass repeatedly until - no more changes are made. - """ - - def wrapper(*args, **kwargs): - count = 0 - - while True: - changes = func(*args, **kwargs) or 0 - if isinstance(changes, list) or isinstance(changes, set): - changes = len(changes) - count += changes - if changes == 0: - break - - return count - - return wrapper diff --git a/vyper/venom/__init__.py b/vyper/venom/__init__.py index a60f679a76..c8cb0c663d 100644 --- a/vyper/venom/__init__.py +++ b/vyper/venom/__init__.py @@ -5,17 +5,15 @@ from vyper.codegen.ir_node import IRnode from vyper.compiler.settings import OptimizationLevel -from vyper.venom.analysis import DFG, calculate_cfg, calculate_liveness -from vyper.venom.bb_optimizer import ( - ir_pass_optimize_empty_blocks, - ir_pass_optimize_unused_variables, - ir_pass_remove_unreachable_blocks, -) +from vyper.venom.analysis.liveness import LivenessAnalysis +from vyper.venom.context import IRContext from vyper.venom.function import IRFunction from vyper.venom.ir_node_to_venom import ir_node_to_venom from vyper.venom.passes.dft import DFTPass from vyper.venom.passes.make_ssa import MakeSSA from vyper.venom.passes.mem2var import Mem2Var +from vyper.venom.passes.pass_manager import IRPassManager +from vyper.venom.passes.remove_unused_variables import RemoveUnusedVariablesPass from vyper.venom.passes.sccp import SCCP from vyper.venom.passes.simplify_cfg import SimplifyCFGPass from vyper.venom.venom_to_assembly import VenomCompiler @@ -24,8 +22,8 @@ def generate_assembly_experimental( - runtime_code: IRFunction, - deploy_code: Optional[IRFunction] = None, + runtime_code: IRContext, + deploy_code: Optional[IRContext] = None, optimize: OptimizationLevel = DEFAULT_OPT_LEVEL, ) -> list[str]: # note: VenomCompiler is sensitive to the order of these! @@ -38,73 +36,26 @@ def generate_assembly_experimental( return compiler.generate_evm(optimize == OptimizationLevel.NONE) -def _run_passes(ctx: IRFunction, optimize: OptimizationLevel) -> None: +def _run_passes(fn: IRFunction, optimize: OptimizationLevel) -> None: # Run passes on Venom IR # TODO: Add support for optimization levels - ir_pass_optimize_empty_blocks(ctx) - ir_pass_remove_unreachable_blocks(ctx) + pm = IRPassManager(fn) - internals = [ - bb - for bb in ctx.basic_blocks - if bb.label.value.startswith("internal") and len(bb.cfg_in) == 0 - ] + SimplifyCFGPass(pm).run_pass() + Mem2Var(pm).run_pass() + MakeSSA(pm).run_pass() + SCCP(pm).run_pass() - SimplifyCFGPass().run_pass(ctx, ctx.basic_blocks[0]) - for entry in internals: - SimplifyCFGPass().run_pass(ctx, entry) + SimplifyCFGPass(pm).run_pass() + RemoveUnusedVariablesPass(pm).run_pass() + DFTPass(pm).run_pass() - dfg = DFG.build_dfg(ctx) - Mem2Var().run_pass(ctx, ctx.basic_blocks[0], dfg) - for entry in internals: - Mem2Var().run_pass(ctx, entry, dfg) - make_ssa_pass = MakeSSA() - make_ssa_pass.run_pass(ctx, ctx.basic_blocks[0]) - - cfg_dirty = False - sccp_pass = SCCP(make_ssa_pass.dom) - sccp_pass.run_pass(ctx, ctx.basic_blocks[0]) - cfg_dirty |= sccp_pass.cfg_dirty - - for entry in internals: - make_ssa_pass.run_pass(ctx, entry) - sccp_pass = SCCP(make_ssa_pass.dom) - sccp_pass.run_pass(ctx, entry) - cfg_dirty |= sccp_pass.cfg_dirty - - calculate_cfg(ctx) - SimplifyCFGPass().run_pass(ctx, ctx.basic_blocks[0]) - - calculate_cfg(ctx) - calculate_liveness(ctx) - - while True: - changes = 0 - - changes += ir_pass_optimize_empty_blocks(ctx) - changes += ir_pass_remove_unreachable_blocks(ctx) - - calculate_liveness(ctx) - - changes += ir_pass_optimize_unused_variables(ctx) - - calculate_cfg(ctx) - calculate_liveness(ctx) - - changes += DFTPass().run_pass(ctx) - - calculate_cfg(ctx) - calculate_liveness(ctx) - - if changes == 0: - break - - -def generate_ir(ir: IRnode, optimize: OptimizationLevel) -> IRFunction: +def generate_ir(ir: IRnode, optimize: OptimizationLevel) -> IRContext: # Convert "old" IR to "new" IR ctx = ir_node_to_venom(ir) - _run_passes(ctx, optimize) + for fn in ctx.functions.values(): + _run_passes(fn, optimize) return ctx diff --git a/vyper/venom/analysis.py b/vyper/venom/analysis.py deleted file mode 100644 index 8e4c24fea3..0000000000 --- a/vyper/venom/analysis.py +++ /dev/null @@ -1,198 +0,0 @@ -from typing import Optional - -from vyper.exceptions import CompilerPanic -from vyper.utils import OrderedSet -from vyper.venom.basicblock import ( - BB_TERMINATORS, - CFG_ALTERING_INSTRUCTIONS, - IRBasicBlock, - IRInstruction, - IRVariable, -) -from vyper.venom.function import IRFunction - - -def calculate_cfg(ctx: IRFunction) -> None: - """ - Calculate (cfg) inputs for each basic block. - """ - for bb in ctx.basic_blocks: - bb.cfg_in = OrderedSet() - bb.cfg_out = OrderedSet() - bb.out_vars = OrderedSet() - - for bb in ctx.basic_blocks: - assert len(bb.instructions) > 0, "Basic block should not be empty" - last_inst = bb.instructions[-1] - assert last_inst.opcode in BB_TERMINATORS, f"Last instruction should be a terminator {bb}" - - for inst in bb.instructions: - if inst.opcode in CFG_ALTERING_INSTRUCTIONS: - ops = inst.get_label_operands() - for op in ops: - ctx.get_basic_block(op.value).add_cfg_in(bb) - - # Fill in the "out" set for each basic block - for bb in ctx.basic_blocks: - for in_bb in bb.cfg_in: - in_bb.add_cfg_out(bb) - - -def _reset_liveness(ctx: IRFunction) -> None: - for bb in ctx.basic_blocks: - bb.out_vars = OrderedSet() - for inst in bb.instructions: - inst.liveness = OrderedSet() - - -def _calculate_liveness(bb: IRBasicBlock) -> bool: - """ - Compute liveness of each instruction in the basic block. - Returns True if liveness changed - """ - orig_liveness = bb.instructions[0].liveness.copy() - liveness = bb.out_vars.copy() - for instruction in reversed(bb.instructions): - ins = instruction.get_inputs() - outs = instruction.get_outputs() - - if ins or outs: - # perf: only copy if changed - liveness = liveness.copy() - liveness.update(ins) - liveness.dropmany(outs) - - instruction.liveness = liveness - - return orig_liveness != bb.instructions[0].liveness - - -def _calculate_out_vars(bb: IRBasicBlock) -> bool: - """ - Compute out_vars of basic block. - Returns True if out_vars changed - """ - out_vars = bb.out_vars.copy() - for out_bb in bb.cfg_out: - target_vars = input_vars_from(bb, out_bb) - bb.out_vars = bb.out_vars.union(target_vars) - return out_vars != bb.out_vars - - -def calculate_liveness(ctx: IRFunction) -> None: - _reset_liveness(ctx) - while True: - changed = False - for bb in ctx.basic_blocks: - changed |= _calculate_out_vars(bb) - changed |= _calculate_liveness(bb) - - if not changed: - break - - -def calculate_dup_requirements(ctx: IRFunction) -> None: - for bb in ctx.basic_blocks: - last_liveness = bb.out_vars - for inst in reversed(bb.instructions): - inst.dup_requirements = OrderedSet() - ops = inst.get_inputs() - for op in ops: - if op in last_liveness: - inst.dup_requirements.add(op) - last_liveness = inst.liveness - - -# calculate the input variables into self from source -def input_vars_from(source: IRBasicBlock, target: IRBasicBlock) -> OrderedSet[IRVariable]: - liveness = target.instructions[0].liveness.copy() - assert isinstance(liveness, OrderedSet) - - for inst in target.instructions: - if inst.opcode == "phi": - # we arbitrarily choose one of the arguments to be in the - # live variables set (dependent on how we traversed into this - # basic block). the argument will be replaced by the destination - # operand during instruction selection. - # for instance, `%56 = phi %label1 %12 %label2 %14` - # will arbitrarily choose either %12 or %14 to be in the liveness - # set, and then during instruction selection, after this instruction, - # %12 will be replaced by %56 in the liveness set - - # bad path into this phi node - if source.label not in inst.operands: - raise CompilerPanic(f"unreachable: {inst} from {source.label}") - - for label, var in inst.phi_operands: - if label == source.label: - liveness.add(var) - else: - if var in liveness: - liveness.remove(var) - - return liveness - - -# DataFlow Graph -# this could be refactored into its own file, but it's only used here -# for now -class DFG: - _dfg_inputs: dict[IRVariable, list[IRInstruction]] - _dfg_outputs: dict[IRVariable, IRInstruction] - - def __init__(self): - self._dfg_inputs = dict() - self._dfg_outputs = dict() - - # return uses of a given variable - def get_uses(self, op: IRVariable) -> list[IRInstruction]: - return self._dfg_inputs.get(op, []) - - # the instruction which produces this variable. - def get_producing_instruction(self, op: IRVariable) -> Optional[IRInstruction]: - return self._dfg_outputs.get(op) - - @property - def outputs(self) -> dict[IRVariable, IRInstruction]: - return self._dfg_outputs - - @classmethod - def build_dfg(cls, ctx: IRFunction) -> "DFG": - dfg = cls() - - # Build DFG - - # %15 = add %13 %14 - # %16 = iszero %15 - # dfg_outputs of %15 is (%15 = add %13 %14) - # dfg_inputs of %15 is all the instructions which *use* %15, ex. [(%16 = iszero %15), ...] - for bb in ctx.basic_blocks: - for inst in bb.instructions: - operands = inst.get_inputs() - res = inst.get_outputs() - - for op in operands: - inputs = dfg._dfg_inputs.setdefault(op, []) - inputs.append(inst) - - for op in res: # type: ignore - dfg._dfg_outputs[op] = inst - - return dfg - - def as_graph(self) -> str: - """ - Generate a graphviz representation of the dfg - """ - lines = ["digraph dfg_graph {"] - for var, inputs in self._dfg_inputs.items(): - for input in inputs: - for op in input.get_outputs(): - if isinstance(op, IRVariable): - lines.append(f' " {var.name} " -> " {op.name} "') - - lines.append("}") - return "\n".join(lines) - - def __repr__(self) -> str: - return self.as_graph() diff --git a/vyper/venom/analysis/__init__.py b/vyper/venom/analysis/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vyper/venom/analysis/analysis.py b/vyper/venom/analysis/analysis.py new file mode 100644 index 0000000000..5e360b7fb9 --- /dev/null +++ b/vyper/venom/analysis/analysis.py @@ -0,0 +1,25 @@ +from vyper.venom.passes.pass_manager import IRPassManager + + +class IRAnalysis: + """ + Base class for all Venom IR analyses. + """ + + manager: IRPassManager + + def __init__(self, manager: IRPassManager): + self.manager = manager + + def analyze(self, *args, **kwargs): + """ + Override this method to perform the analysis. + """ + raise NotImplementedError + + def invalidate(self): + """ + Override this method to respond to an invalidation request, and possibly + invalidate any other analyses that depend on this one. + """ + raise NotImplementedError diff --git a/vyper/venom/analysis/cfg.py b/vyper/venom/analysis/cfg.py new file mode 100644 index 0000000000..9eeb9c7e57 --- /dev/null +++ b/vyper/venom/analysis/cfg.py @@ -0,0 +1,43 @@ +from vyper.utils import OrderedSet +from vyper.venom.analysis.analysis import IRAnalysis +from vyper.venom.basicblock import BB_TERMINATORS, CFG_ALTERING_INSTRUCTIONS + + +class CFGAnalysis(IRAnalysis): + """ + Compute control flow graph information for each basic block in the function. + """ + + def analyze(self) -> None: + fn = self.manager.function + for bb in fn.basic_blocks: + bb.cfg_in = OrderedSet() + bb.cfg_out = OrderedSet() + bb.out_vars = OrderedSet() + + for bb in fn.basic_blocks: + assert len(bb.instructions) > 0, "Basic block should not be empty" + last_inst = bb.instructions[-1] + assert ( + last_inst.opcode in BB_TERMINATORS + ), f"Last instruction should be a terminator {bb}" + + for inst in bb.instructions: + if inst.opcode in CFG_ALTERING_INSTRUCTIONS: + ops = inst.get_label_operands() + for op in ops: + fn.get_basic_block(op.value).add_cfg_in(bb) + + # Fill in the "out" set for each basic block + for bb in fn.basic_blocks: + for in_bb in bb.cfg_in: + in_bb.add_cfg_out(bb) + + def invalidate(self): + super().invalidate() + + from vyper.venom.analysis.dominators import DominatorTreeAnalysis + from vyper.venom.analysis.liveness import LivenessAnalysis + + self.manager.invalidate_analysis(DominatorTreeAnalysis) + self.manager.invalidate_analysis(LivenessAnalysis) diff --git a/vyper/venom/analysis/dfg.py b/vyper/venom/analysis/dfg.py new file mode 100644 index 0000000000..9484af7026 --- /dev/null +++ b/vyper/venom/analysis/dfg.py @@ -0,0 +1,63 @@ +from typing import Optional + +from vyper.venom.analysis.analysis import IRAnalysis +from vyper.venom.basicblock import IRInstruction, IRVariable +from vyper.venom.passes.pass_manager import IRPassManager + + +class DFGAnalysis(IRAnalysis): + _dfg_inputs: dict[IRVariable, list[IRInstruction]] + _dfg_outputs: dict[IRVariable, IRInstruction] + + def __init__(self, manager: IRPassManager): + super().__init__(manager) + self._dfg_inputs = dict() + self._dfg_outputs = dict() + + # return uses of a given variable + def get_uses(self, op: IRVariable) -> list[IRInstruction]: + return self._dfg_inputs.get(op, []) + + # the instruction which produces this variable. + def get_producing_instruction(self, op: IRVariable) -> Optional[IRInstruction]: + return self._dfg_outputs.get(op) + + @property + def outputs(self) -> dict[IRVariable, IRInstruction]: + return self._dfg_outputs + + def analyze(self): + # Build DFG + + # %15 = add %13 %14 + # %16 = iszero %15 + # dfg_outputs of %15 is (%15 = add %13 %14) + # dfg_inputs of %15 is all the instructions which *use* %15, ex. [(%16 = iszero %15), ...] + for bb in self.manager.function.basic_blocks: + for inst in bb.instructions: + operands = inst.get_inputs() + res = inst.get_outputs() + + for op in operands: + inputs = self._dfg_inputs.setdefault(op, []) + inputs.append(inst) + + for op in res: # type: ignore + self._dfg_outputs[op] = inst + + def as_graph(self) -> str: + """ + Generate a graphviz representation of the dfg + """ + lines = ["digraph dfg_graph {"] + for var, inputs in self._dfg_inputs.items(): + for input in inputs: + for op in input.get_outputs(): + if isinstance(op, IRVariable): + lines.append(f' " {var.name} " -> " {op.name} "') + + lines.append("}") + return "\n".join(lines) + + def __repr__(self) -> str: + return self.as_graph() diff --git a/vyper/venom/dominators.py b/vyper/venom/analysis/dominators.py similarity index 93% rename from vyper/venom/dominators.py rename to vyper/venom/analysis/dominators.py index b69c17e1d8..fe91a62bf6 100644 --- a/vyper/venom/dominators.py +++ b/vyper/venom/analysis/dominators.py @@ -1,17 +1,19 @@ from vyper.exceptions import CompilerPanic from vyper.utils import OrderedSet +from vyper.venom.analysis.analysis import IRAnalysis +from vyper.venom.analysis.cfg import CFGAnalysis from vyper.venom.basicblock import IRBasicBlock from vyper.venom.function import IRFunction -class DominatorTree: +class DominatorTreeAnalysis(IRAnalysis): """ Dominator tree implementation. This class computes the dominator tree of a function and provides methods to query the tree. The tree is computed using the Lengauer-Tarjan algorithm. """ - ctx: IRFunction + fn: IRFunction entry_block: IRBasicBlock dfs_order: dict[IRBasicBlock, int] dfs_walk: list[IRBasicBlock] @@ -20,18 +22,12 @@ class DominatorTree: dominated: dict[IRBasicBlock, OrderedSet[IRBasicBlock]] dominator_frontiers: dict[IRBasicBlock, OrderedSet[IRBasicBlock]] - @classmethod - def build_dominator_tree(cls, ctx, entry): - ret = DominatorTree() - ret.compute(ctx, entry) - return ret - - def compute(self, ctx: IRFunction, entry: IRBasicBlock): + def analyze(self): """ Compute the dominator tree. """ - self.ctx = ctx - self.entry_block = entry + self.fn = self.manager.function + self.entry_block = self.fn.basic_blocks[0] self.dfs_order = {} self.dfs_walk = [] self.dominators = {} @@ -39,6 +35,8 @@ def compute(self, ctx: IRFunction, entry: IRBasicBlock): self.dominated = {} self.dominator_frontiers = {} + self.manager.request_analysis(CFGAnalysis) + self._compute_dfs(self.entry_block, OrderedSet()) self._compute_dominators() self._compute_idoms() @@ -155,7 +153,7 @@ def as_graph(self) -> str: Generate a graphviz representation of the dominator tree. """ lines = ["digraph dominator_tree {"] - for bb in self.ctx.basic_blocks: + for bb in self.fn.basic_blocks: if bb == self.entry_block: continue idom = self.immediate_dominator(bb) diff --git a/vyper/venom/analysis/dup_requirements.py b/vyper/venom/analysis/dup_requirements.py new file mode 100644 index 0000000000..278beed310 --- /dev/null +++ b/vyper/venom/analysis/dup_requirements.py @@ -0,0 +1,15 @@ +from vyper.utils import OrderedSet +from vyper.venom.analysis.analysis import IRAnalysis + + +class DupRequirementsAnalysis(IRAnalysis): + def analyze(self): + for bb in self.manager.function.basic_blocks: + last_liveness = bb.out_vars + for inst in reversed(bb.instructions): + inst.dup_requirements = OrderedSet() + ops = inst.get_inputs() + for op in ops: + if op in last_liveness: + inst.dup_requirements.add(op) + last_liveness = inst.liveness diff --git a/vyper/venom/analysis/liveness.py b/vyper/venom/analysis/liveness.py new file mode 100644 index 0000000000..b1e75ccb41 --- /dev/null +++ b/vyper/venom/analysis/liveness.py @@ -0,0 +1,90 @@ +from vyper.exceptions import CompilerPanic +from vyper.utils import OrderedSet +from vyper.venom.analysis.analysis import IRAnalysis +from vyper.venom.analysis.cfg import CFGAnalysis +from vyper.venom.basicblock import IRBasicBlock, IRVariable + + +class LivenessAnalysis(IRAnalysis): + """ + Compute liveness information for each instruction in the function. + """ + + def analyze(self): + self.manager.request_analysis(CFGAnalysis) + self._reset_liveness() + while True: + changed = False + for bb in self.manager.function.basic_blocks: + changed |= self._calculate_out_vars(bb) + changed |= self._calculate_liveness(bb) + + if not changed: + break + + def _reset_liveness(self) -> None: + for bb in self.manager.function.basic_blocks: + bb.out_vars = OrderedSet() + for inst in bb.instructions: + inst.liveness = OrderedSet() + + def _calculate_liveness(self, bb: IRBasicBlock) -> bool: + """ + Compute liveness of each instruction in the basic block. + Returns True if liveness changed + """ + orig_liveness = bb.instructions[0].liveness.copy() + liveness = bb.out_vars.copy() + for instruction in reversed(bb.instructions): + ins = instruction.get_inputs() + outs = instruction.get_outputs() + + if ins or outs: + # perf: only copy if changed + liveness = liveness.copy() + liveness.update(ins) + liveness.dropmany(outs) + + instruction.liveness = liveness + + return orig_liveness != bb.instructions[0].liveness + + def _calculate_out_vars(self, bb: IRBasicBlock) -> bool: + """ + Compute out_vars of basic block. + Returns True if out_vars changed + """ + out_vars = bb.out_vars.copy() + for out_bb in bb.cfg_out: + target_vars = self.input_vars_from(bb, out_bb) + bb.out_vars = bb.out_vars.union(target_vars) + return out_vars != bb.out_vars + + # calculate the input variables into self from source + def input_vars_from(self, source: IRBasicBlock, target: IRBasicBlock) -> OrderedSet[IRVariable]: + liveness = target.instructions[0].liveness.copy() + assert isinstance(liveness, OrderedSet) + + for inst in target.instructions: + if inst.opcode == "phi": + # we arbitrarily choose one of the arguments to be in the + # live variables set (dependent on how we traversed into this + # basic block). the argument will be replaced by the destination + # operand during instruction selection. + # for instance, `%56 = phi %label1 %12 %label2 %14` + # will arbitrarily choose either %12 or %14 to be in the liveness + # set, and then during instruction selection, after this instruction, + # %12 will be replaced by %56 in the liveness set + + # bad path into this phi node + if source.label not in inst.operands: + raise CompilerPanic(f"unreachable: {inst} from {source.label}") + + for label, var in inst.phi_operands: + if label == source.label: + liveness.add(var) + else: + if var in liveness: + liveness.remove(var) + + return liveness diff --git a/vyper/venom/bb_optimizer.py b/vyper/venom/bb_optimizer.py deleted file mode 100644 index 284a1f1b9c..0000000000 --- a/vyper/venom/bb_optimizer.py +++ /dev/null @@ -1,93 +0,0 @@ -from vyper.utils import ir_pass -from vyper.venom.analysis import calculate_cfg -from vyper.venom.basicblock import IRInstruction, IRLabel -from vyper.venom.function import IRFunction - - -def _optimize_unused_variables(ctx: IRFunction) -> set[IRInstruction]: - """ - Remove unused variables. - """ - removeList = set() - for bb in ctx.basic_blocks: - for i, inst in enumerate(bb.instructions[:-1]): - if inst.volatile: - continue - next_liveness = bb.instructions[i + 1].liveness - if (inst.output and inst.output not in next_liveness) or inst.opcode == "nop": - removeList.add(inst) - - bb.instructions = [inst for inst in bb.instructions if inst not in removeList] - - return removeList - - -def _optimize_empty_basicblocks(ctx: IRFunction) -> int: - """ - Remove empty basic blocks. - """ - count = 0 - i = 0 - while i < len(ctx.basic_blocks): - bb = ctx.basic_blocks[i] - i += 1 - if len(bb.instructions) > 0: - continue - - replaced_label = bb.label - replacement_label = ctx.basic_blocks[i].label if i < len(ctx.basic_blocks) else None - if replacement_label is None: - continue - - # Try to preserve symbol labels - if replaced_label.is_symbol: - replaced_label, replacement_label = replacement_label, replaced_label - ctx.basic_blocks[i].label = replacement_label - - for bb2 in ctx.basic_blocks: - for inst in bb2.instructions: - for op in inst.operands: - if isinstance(op, IRLabel) and op.value == replaced_label.value: - op.value = replacement_label.value - - ctx.basic_blocks.remove(bb) - i -= 1 - count += 1 - - return count - - -def _daisychain_empty_basicblocks(ctx: IRFunction) -> int: - count = 0 - i = 0 - while i < len(ctx.basic_blocks): - bb = ctx.basic_blocks[i] - i += 1 - if bb.is_terminated: - continue - - if i < len(ctx.basic_blocks) - 1: - bb.append_instruction("jmp", ctx.basic_blocks[i + 1].label) - else: - bb.append_instruction("stop") - - count += 1 - - return count - - -@ir_pass -def ir_pass_optimize_empty_blocks(ctx: IRFunction) -> int: - changes = _optimize_empty_basicblocks(ctx) - calculate_cfg(ctx) - return changes - - -@ir_pass -def ir_pass_remove_unreachable_blocks(ctx: IRFunction) -> int: - return ctx.remove_unreachable_blocks() - - -@ir_pass -def ir_pass_optimize_unused_variables(ctx: IRFunction) -> int: - return len(_optimize_unused_variables(ctx)) diff --git a/vyper/venom/context.py b/vyper/venom/context.py new file mode 100644 index 0000000000..2e35967dfe --- /dev/null +++ b/vyper/venom/context.py @@ -0,0 +1,67 @@ +from typing import Optional + +from vyper.venom.basicblock import IRInstruction, IRLabel, IROperand +from vyper.venom.function import IRFunction + + +class IRContext: + functions: dict[IRLabel, IRFunction] + ctor_mem_size: Optional[int] + immutables_len: Optional[int] + data_segment: list[IRInstruction] + last_label: int + + def __init__(self) -> None: + self.functions = {} + self.ctor_mem_size = None + self.immutables_len = None + self.data_segment = [] + self.last_label = 0 + + def add_function(self, fn: IRFunction) -> None: + fn.ctx = self + self.functions[fn.name] = fn + + def create_function(self, name: str) -> IRFunction: + label = IRLabel(name, True) + fn = IRFunction(label, self) + self.add_function(fn) + return fn + + def get_function(self, name: IRLabel) -> IRFunction: + if name in self.functions: + return self.functions[name] + raise Exception(f"Function {name} not found in context") + + def get_next_label(self, suffix: str = "") -> IRLabel: + if suffix != "": + suffix = f"_{suffix}" + self.last_label += 1 + return IRLabel(f"{self.last_label}{suffix}") + + def chain_basic_blocks(self) -> None: + """ + Chain basic blocks together. This is necessary for the IR to be valid, and is done after + the IR is generated. + """ + for fn in self.functions.values(): + fn.chain_basic_blocks() + + def append_data(self, opcode: str, args: list[IROperand]) -> None: + """ + Append data + """ + self.data_segment.append(IRInstruction(opcode, args)) # type: ignore + + def __repr__(self) -> str: + s = ["IRContext:"] + for fn in self.functions.values(): + s.append(fn.__repr__()) + s.append("\n") + + if len(self.data_segment) > 0: + s += "\nData segment:\n" + for inst in self.data_segment: + s += f"{inst}\n" + + return "\n".join(s) diff --git a/vyper/venom/function.py b/vyper/venom/function.py index 8756642f80..11bb8fe488 100644 --- a/vyper/venom/function.py +++ b/vyper/venom/function.py @@ -2,16 +2,7 @@ from vyper.codegen.ir_node import IRnode from vyper.utils import OrderedSet -from vyper.venom.basicblock import ( - CFG_ALTERING_INSTRUCTIONS, - IRBasicBlock, - IRInstruction, - IRLabel, - IROperand, - IRVariable, -) - -GLOBAL_LABEL = IRLabel("__global") +from vyper.venom.basicblock import CFG_ALTERING_INSTRUCTIONS, IRBasicBlock, IRLabel, IRVariable class IRFunction: @@ -20,12 +11,10 @@ class IRFunction: """ name: IRLabel # symbol name + ctx: "IRContext" # type: ignore # noqa: F821 entry_points: list[IRLabel] # entry points args: list - ctor_mem_size: Optional[int] - immutables_len: Optional[int] basic_blocks: list[IRBasicBlock] - data_segment: list[IRInstruction] last_label: int last_variable: int @@ -34,17 +23,13 @@ class IRFunction: _error_msg_stack: list[str] _bb_index: dict[str, int] - def __init__(self, name: IRLabel = None) -> None: - if name is None: - name = GLOBAL_LABEL + def __init__(self, name: IRLabel, ctx: "IRContext" = None) -> None: # type: ignore # noqa: F821 + self.ctx = ctx self.name = name self.entry_points = [] self.args = [] - self.ctor_mem_size = None - self.immutables_len = None self.basic_blocks = [] - self.data_segment = [] - self.last_label = 0 + self.last_variable = 0 self._ast_source_stack = [] @@ -86,7 +71,9 @@ def _get_basicblock_index(self, label: str): # do a reindex self._bb_index = dict((bb.label.name, ix) for ix, bb in enumerate(self.basic_blocks)) # sanity check - no duplicate labels - assert len(self._bb_index) == len(self.basic_blocks) + assert len(self._bb_index) == len( + self.basic_blocks + ), f"Duplicate labels in function '{self.name}' {self._bb_index} {self.basic_blocks}" return self._bb_index[label] def get_basic_block(self, label: Optional[str] = None) -> IRBasicBlock: @@ -123,10 +110,7 @@ def get_basicblocks_in(self, basic_block: IRBasicBlock) -> list[IRBasicBlock]: return [bb for bb in self.basic_blocks if basic_block.label in bb.cfg_in] def get_next_label(self, suffix: str = "") -> IRLabel: - if suffix != "": - suffix = f"_{suffix}" - self.last_label += 1 - return IRLabel(f"{self.last_label}{suffix}") + return self.ctx.get_next_label(suffix) def get_next_variable(self) -> IRVariable: self.last_variable += 1 @@ -188,18 +172,12 @@ def _compute_reachability_from(self, bb: IRBasicBlock) -> None: return bb.is_reachable = True for inst in bb.instructions: - if inst.opcode in CFG_ALTERING_INSTRUCTIONS or inst.opcode == "invoke": + if inst.opcode in CFG_ALTERING_INSTRUCTIONS: # or inst.opcode == "invoke": for op in inst.get_label_operands(): out_bb = self.get_basic_block(op.value) bb.reachable.add(out_bb) self._compute_reachability_from(out_bb) - def append_data(self, opcode: str, args: list[IROperand]) -> None: - """ - Append data - """ - self.data_segment.append(IRInstruction(opcode, args)) # type: ignore - @property def normalized(self) -> bool: """ @@ -243,10 +221,28 @@ def ast_source(self) -> Optional[IRnode]: def error_msg(self) -> Optional[str]: return self._error_msg_stack[-1] if len(self._error_msg_stack) > 0 else None + def chain_basic_blocks(self) -> None: + """ + Chain basic blocks together. If a basic block is not terminated, jump to the next one. + Otherwise, append a stop instruction. This is necessary for the IR to be valid, and is + done after the IR is generated. + """ + for i, bb in enumerate(self.basic_blocks): + if not bb.is_terminated: + if len(self.basic_blocks) - 1 > i: + # TODO: revisit this. When contructor calls internal functions they + # are linked to the last ctor block. Should separate them before this + # so we don't have to handle this here + if self.basic_blocks[i + 1].label.value.startswith("internal"): + bb.append_instruction("stop") + else: + bb.append_instruction("jmp", self.basic_blocks[i + 1].label) + else: + bb.append_instruction("exit") + def copy(self): new = IRFunction(self.name) new.basic_blocks = self.basic_blocks.copy() - new.data_segment = self.data_segment.copy() new.last_label = self.last_label new.last_variable = self.last_variable return new @@ -281,8 +277,4 @@ def __repr__(self) -> str: str = f"IRFunction: {self.name}\n" for bb in self.basic_blocks: str += f"{bb}\n" - if len(self.data_segment) > 0: - str += "Data segment:\n" - for inst in self.data_segment: - str += f"{inst}\n" return str.strip() diff --git a/vyper/venom/ir_node_to_venom.py b/vyper/venom/ir_node_to_venom.py index bcf27bbb0c..063028a8ae 100644 --- a/vyper/venom/ir_node_to_venom.py +++ b/vyper/venom/ir_node_to_venom.py @@ -13,6 +13,7 @@ IROperand, IRVariable, ) +from vyper.venom.context import IRContext from vyper.venom.function import IRFunction # Instructions that are mapped to their inverse @@ -107,61 +108,51 @@ SymbolTable = dict[str, Optional[IROperand]] _global_symbols: SymbolTable = {} +MAIN_ENTRY_LABEL_NAME = "__main_entry" # convert IRnode directly to venom -def ir_node_to_venom(ir: IRnode) -> IRFunction: +def ir_node_to_venom(ir: IRnode) -> IRContext: global _global_symbols _global_symbols = {} - ctx = IRFunction() - _convert_ir_bb(ctx, ir, {}) + ctx = IRContext() + fn = ctx.create_function(MAIN_ENTRY_LABEL_NAME) - # Patch up basic blocks. Connect unterminated blocks to the next with - # a jump. terminate final basic block with STOP. - for i, bb in enumerate(ctx.basic_blocks): - if not bb.is_terminated: - if len(ctx.basic_blocks) - 1 > i: - # TODO: revisit this. When contructor calls internal functions they - # are linked to the last ctor block. Should separate them before this - # so we don't have to handle this here - if ctx.basic_blocks[i + 1].label.value.startswith("internal"): - bb.append_instruction("stop") - else: - bb.append_instruction("jmp", ctx.basic_blocks[i + 1].label) - else: - bb.append_instruction("exit") + _convert_ir_bb(fn, ir, {}) + + ctx.chain_basic_blocks() return ctx -def _append_jmp(ctx: IRFunction, label: IRLabel) -> None: - bb = ctx.get_basic_block() +def _append_jmp(fn: IRFunction, label: IRLabel) -> None: + bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(ctx.get_next_label("jmp_target"), ctx) - ctx.append_basic_block(bb) + bb = IRBasicBlock(fn.get_next_label("jmp_target"), fn) + fn.append_basic_block(bb) bb.append_instruction("jmp", label) -def _new_block(ctx: IRFunction) -> IRBasicBlock: - bb = IRBasicBlock(ctx.get_next_label(), ctx) - bb = ctx.append_basic_block(bb) +def _new_block(fn: IRFunction) -> IRBasicBlock: + bb = IRBasicBlock(fn.get_next_label(), fn) + bb = fn.append_basic_block(bb) return bb -def _append_return_args(ctx: IRFunction, ofst: int = 0, size: int = 0): - bb = ctx.get_basic_block() +def _append_return_args(fn: IRFunction, ofst: int = 0, size: int = 0): + bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(ctx.get_next_label("exit_to"), ctx) - ctx.append_basic_block(bb) + bb = IRBasicBlock(fn.get_next_label("exit_to"), fn) + fn.append_basic_block(bb) ret_ofst = IRVariable("ret_ofst") ret_size = IRVariable("ret_size") bb.append_instruction("store", ofst, ret=ret_ofst) bb.append_instruction("store", size, ret=ret_size) -def _handle_self_call(ctx: IRFunction, ir: IRnode, symbols: SymbolTable) -> Optional[IRVariable]: +def _handle_self_call(fn: IRFunction, ir: IRnode, symbols: SymbolTable) -> Optional[IRVariable]: setup_ir = ir.args[1] goto_ir = [ir for ir in ir.args if ir.value == "goto"][0] target_label = goto_ir.args[0].value # goto @@ -169,11 +160,11 @@ def _handle_self_call(ctx: IRFunction, ir: IRnode, symbols: SymbolTable) -> Opti ret_args: list[IROperand] = [IRLabel(target_label)] # type: ignore if setup_ir != goto_ir: - _convert_ir_bb(ctx, setup_ir, symbols) + _convert_ir_bb(fn, setup_ir, symbols) - return_buf = _convert_ir_bb(ctx, return_buf_ir, symbols) + return_buf = _convert_ir_bb(fn, return_buf_ir, symbols) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() if len(goto_ir.args) > 2: ret_args.append(return_buf) # type: ignore @@ -183,10 +174,10 @@ def _handle_self_call(ctx: IRFunction, ir: IRnode, symbols: SymbolTable) -> Opti def _handle_internal_func( - ctx: IRFunction, ir: IRnode, does_return_data: bool, symbols: SymbolTable -): - bb = IRBasicBlock(IRLabel(ir.args[0].args[0].value, True), ctx) # type: ignore - bb = ctx.append_basic_block(bb) + fn: IRFunction, ir: IRnode, does_return_data: bool, symbols: SymbolTable +) -> IRFunction: + fn = fn.ctx.create_function(ir.args[0].args[0].value) + bb = fn.get_basic_block() # return buffer if does_return_data: @@ -197,27 +188,29 @@ def _handle_internal_func( symbols["return_pc"] = bb.append_instruction("param") bb.instructions[-1].annotation = "return_pc" - _convert_ir_bb(ctx, ir.args[0].args[2], symbols) + _convert_ir_bb(fn, ir.args[0].args[2], symbols) + + return fn def _convert_ir_simple_node( - ctx: IRFunction, ir: IRnode, symbols: SymbolTable + fn: IRFunction, ir: IRnode, symbols: SymbolTable ) -> Optional[IRVariable]: # execute in order - args = _convert_ir_bb_list(ctx, ir.args, symbols) + args = _convert_ir_bb_list(fn, ir.args, symbols) # reverse output variables for stack args.reverse() - return ctx.get_basic_block().append_instruction(ir.value, *args) # type: ignore + return fn.get_basic_block().append_instruction(ir.value, *args) # type: ignore _break_target: Optional[IRBasicBlock] = None _continue_target: Optional[IRBasicBlock] = None -def _convert_ir_bb_list(ctx, ir, symbols): +def _convert_ir_bb_list(fn, ir, symbols): ret = [] for ir_node in ir: - venom = _convert_ir_bb(ctx, ir_node, symbols) + venom = _convert_ir_bb(fn, ir_node, symbols) ret.append(venom) return ret @@ -229,42 +222,42 @@ def _convert_ir_bb_list(ctx, ir, symbols): def pop_source_on_return(func): @functools.wraps(func) def pop_source(*args, **kwargs): - ctx = args[0] + fn = args[0] ret = func(*args, **kwargs) - ctx.pop_source() + fn.pop_source() return ret return pop_source @pop_source_on_return -def _convert_ir_bb(ctx, ir, symbols): +def _convert_ir_bb(fn, ir, symbols): assert isinstance(ir, IRnode), ir global _break_target, _continue_target, current_func, var_list, _global_symbols - ctx.push_source(ir) + fn.push_source(ir) if ir.value in INVERSE_MAPPED_IR_INSTRUCTIONS: org_value = ir.value ir.value = INVERSE_MAPPED_IR_INSTRUCTIONS[ir.value] - new_var = _convert_ir_simple_node(ctx, ir, symbols) + new_var = _convert_ir_simple_node(fn, ir, symbols) ir.value = org_value - return ctx.get_basic_block().append_instruction("iszero", new_var) + return fn.get_basic_block().append_instruction("iszero", new_var) elif ir.value in PASS_THROUGH_INSTRUCTIONS: - return _convert_ir_simple_node(ctx, ir, symbols) + return _convert_ir_simple_node(fn, ir, symbols) elif ir.value == "return": - ctx.get_basic_block().append_instruction( + fn.get_basic_block().append_instruction( "return", IRVariable("ret_size"), IRVariable("ret_ofst") ) elif ir.value == "deploy": - ctx.ctor_mem_size = ir.args[0].value - ctx.immutables_len = ir.args[2].value + fn.ctx.ctor_mem_size = ir.args[0].value + fn.ctx.immutables_len = ir.args[2].value return None elif ir.value == "seq": if len(ir.args) == 0: return None if ir.is_self_call: - return _handle_self_call(ctx, ir, symbols) + return _handle_self_call(fn, ir, symbols) elif ir.args[0].value == "label": current_func = ir.args[0].args[0].value is_external = current_func.startswith("external") @@ -275,68 +268,68 @@ def _convert_ir_bb(ctx, ir, symbols): does_return_data = IRnode.from_list(["return_buffer"]) in var_list.args _global_symbols = {} symbols = {} - _handle_internal_func(ctx, ir, does_return_data, symbols) + new_fn = _handle_internal_func(fn, ir, does_return_data, symbols) for ir_node in ir.args[1:]: - ret = _convert_ir_bb(ctx, ir_node, symbols) + ret = _convert_ir_bb(new_fn, ir_node, symbols) return ret elif is_external: _global_symbols = {} - ret = _convert_ir_bb(ctx, ir.args[0], symbols) - _append_return_args(ctx) + ret = _convert_ir_bb(fn, ir.args[0], symbols) + _append_return_args(fn) else: - bb = ctx.get_basic_block() + bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(ctx.get_next_label("seq"), ctx) - ctx.append_basic_block(bb) - ret = _convert_ir_bb(ctx, ir.args[0], symbols) + bb = IRBasicBlock(fn.get_next_label("seq"), fn) + fn.append_basic_block(bb) + ret = _convert_ir_bb(fn, ir.args[0], symbols) for ir_node in ir.args[1:]: - ret = _convert_ir_bb(ctx, ir_node, symbols) + ret = _convert_ir_bb(fn, ir_node, symbols) return ret elif ir.value == "if": cond = ir.args[0] # convert the condition - cont_ret = _convert_ir_bb(ctx, cond, symbols) - cond_block = ctx.get_basic_block() + cont_ret = _convert_ir_bb(fn, cond, symbols) + cond_block = fn.get_basic_block() saved_global_symbols = _global_symbols.copy() - then_block = IRBasicBlock(ctx.get_next_label("then"), ctx) - else_block = IRBasicBlock(ctx.get_next_label("else"), ctx) + then_block = IRBasicBlock(fn.get_next_label("then"), fn) + else_block = IRBasicBlock(fn.get_next_label("else"), fn) # convert "then" cond_symbols = symbols.copy() - ctx.append_basic_block(then_block) - then_ret_val = _convert_ir_bb(ctx, ir.args[1], cond_symbols) + fn.append_basic_block(then_block) + then_ret_val = _convert_ir_bb(fn, ir.args[1], cond_symbols) if isinstance(then_ret_val, IRLiteral): - then_ret_val = ctx.get_basic_block().append_instruction("store", then_ret_val) + then_ret_val = fn.get_basic_block().append_instruction("store", then_ret_val) - then_block_finish = ctx.get_basic_block() + then_block_finish = fn.get_basic_block() # convert "else" cond_symbols = symbols.copy() _global_symbols = saved_global_symbols.copy() - ctx.append_basic_block(else_block) + fn.append_basic_block(else_block) else_ret_val = None if len(ir.args) == 3: - else_ret_val = _convert_ir_bb(ctx, ir.args[2], cond_symbols) + else_ret_val = _convert_ir_bb(fn, ir.args[2], cond_symbols) if isinstance(else_ret_val, IRLiteral): assert isinstance(else_ret_val.value, int) # help mypy - else_ret_val = ctx.get_basic_block().append_instruction("store", else_ret_val) + else_ret_val = fn.get_basic_block().append_instruction("store", else_ret_val) - else_block_finish = ctx.get_basic_block() + else_block_finish = fn.get_basic_block() # finish the condition block cond_block.append_instruction("jnz", cont_ret, then_block.label, else_block.label) # exit bb - exit_bb = IRBasicBlock(ctx.get_next_label("if_exit"), ctx) - exit_bb = ctx.append_basic_block(exit_bb) + exit_bb = IRBasicBlock(fn.get_next_label("if_exit"), fn) + exit_bb = fn.append_basic_block(exit_bb) - if_ret = ctx.get_next_variable() + if_ret = fn.get_next_variable() if then_ret_val is not None and else_ret_val is not None: then_block_finish.append_instruction("store", then_ret_val, ret=if_ret) else_block_finish.append_instruction("store", else_ret_val, ret=if_ret) @@ -352,63 +345,63 @@ def _convert_ir_bb(ctx, ir, symbols): return if_ret elif ir.value == "with": - ret = _convert_ir_bb(ctx, ir.args[1], symbols) # initialization + ret = _convert_ir_bb(fn, ir.args[1], symbols) # initialization - ret = ctx.get_basic_block().append_instruction("store", ret) + ret = fn.get_basic_block().append_instruction("store", ret) sym = ir.args[0] with_symbols = symbols.copy() with_symbols[sym.value] = ret - return _convert_ir_bb(ctx, ir.args[2], with_symbols) # body + return _convert_ir_bb(fn, ir.args[2], with_symbols) # body elif ir.value == "goto": - _append_jmp(ctx, IRLabel(ir.args[0].value)) + _append_jmp(fn, IRLabel(ir.args[0].value)) elif ir.value == "djump": - args = [_convert_ir_bb(ctx, ir.args[0], symbols)] + args = [_convert_ir_bb(fn, ir.args[0], symbols)] for target in ir.args[1:]: args.append(IRLabel(target.value)) - ctx.get_basic_block().append_instruction("djmp", *args) - _new_block(ctx) + fn.get_basic_block().append_instruction("djmp", *args) + _new_block(fn) elif ir.value == "set": sym = ir.args[0] - arg_1 = _convert_ir_bb(ctx, ir.args[1], symbols) - ctx.get_basic_block().append_instruction("store", arg_1, ret=symbols[sym.value]) + arg_1 = _convert_ir_bb(fn, ir.args[1], symbols) + fn.get_basic_block().append_instruction("store", arg_1, ret=symbols[sym.value]) elif ir.value == "symbol": return IRLabel(ir.args[0].value, True) elif ir.value == "data": label = IRLabel(ir.args[0].value) - ctx.append_data("dbname", [label]) + fn.ctx.append_data("dbname", [label]) for c in ir.args[1:]: if isinstance(c, int): assert 0 <= c <= 255, "data with invalid size" - ctx.append_data("db", [c]) # type: ignore + fn.ctx.append_data("db", [c]) # type: ignore elif isinstance(c.value, bytes): - ctx.append_data("db", [c.value]) # type: ignore + fn.ctx.append_data("db", [c.value]) # type: ignore elif isinstance(c, IRnode): - data = _convert_ir_bb(ctx, c, symbols) - ctx.append_data("db", [data]) # type: ignore + data = _convert_ir_bb(fn, c, symbols) + fn.ctx.append_data("db", [data]) # type: ignore elif ir.value == "label": label = IRLabel(ir.args[0].value, True) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() if not bb.is_terminated: bb.append_instruction("jmp", label) - bb = IRBasicBlock(label, ctx) - ctx.append_basic_block(bb) + bb = IRBasicBlock(label, fn) + fn.append_basic_block(bb) code = ir.args[2] if code.value == "pass": bb.append_instruction("exit") else: - _convert_ir_bb(ctx, code, symbols) + _convert_ir_bb(fn, code, symbols) elif ir.value == "exit_to": - args = _convert_ir_bb_list(ctx, ir.args[1:], symbols) + args = _convert_ir_bb_list(fn, ir.args[1:], symbols) var_list = args - _append_return_args(ctx, *var_list) - bb = ctx.get_basic_block() + _append_return_args(fn, *var_list) + bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(ctx.get_next_label("exit_to"), ctx) - ctx.append_basic_block(bb) - bb = ctx.get_basic_block() + bb = IRBasicBlock(fn.get_next_label("exit_to"), fn) + fn.append_basic_block(bb) + bb = fn.get_basic_block() label = IRLabel(ir.args[0].value) if label.value == "return_pc": @@ -418,17 +411,17 @@ def _convert_ir_bb(ctx, ir, symbols): bb.append_instruction("jmp", label) elif ir.value == "dload": - arg_0 = _convert_ir_bb(ctx, ir.args[0], symbols) - bb = ctx.get_basic_block() + arg_0 = _convert_ir_bb(fn, ir.args[0], symbols) + bb = fn.get_basic_block() src = bb.append_instruction("add", arg_0, IRLabel("code_end")) bb.append_instruction("dloadbytes", 32, src, MemoryPositions.FREE_VAR_SPACE) return bb.append_instruction("mload", MemoryPositions.FREE_VAR_SPACE) elif ir.value == "dloadbytes": - dst, src_offset, len_ = _convert_ir_bb_list(ctx, ir.args, symbols) + dst, src_offset, len_ = _convert_ir_bb_list(fn, ir.args, symbols) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() src = bb.append_instruction("add", src_offset, IRLabel("code_end")) bb.append_instruction("dloadbytes", len_, src, dst) return None @@ -436,14 +429,14 @@ def _convert_ir_bb(ctx, ir, symbols): elif ir.value == "mstore": # some upstream code depends on reversed order of evaluation -- # to fix upstream. - val, ptr = _convert_ir_bb_list(ctx, reversed(ir.args), symbols) + val, ptr = _convert_ir_bb_list(fn, reversed(ir.args), symbols) - return ctx.get_basic_block().append_instruction("mstore", val, ptr) + return fn.get_basic_block().append_instruction("mstore", val, ptr) elif ir.value == "ceil32": x = ir.args[0] expanded = IRnode.from_list(["and", ["add", x, 31], ["not", 31]]) - return _convert_ir_bb(ctx, expanded, symbols) + return _convert_ir_bb(fn, expanded, symbols) elif ir.value == "select": cond, a, b = ir.args expanded = IRnode.from_list( @@ -459,7 +452,7 @@ def _convert_ir_bb(ctx, ir, symbols): ], ] ) - return _convert_ir_bb(ctx, expanded, symbols) + return _convert_ir_bb(fn, expanded, symbols) elif ir.value == "repeat": def emit_body_blocks(): @@ -467,12 +460,12 @@ def emit_body_blocks(): old_targets = _break_target, _continue_target _break_target, _continue_target = exit_block, incr_block saved_global_symbols = _global_symbols.copy() - _convert_ir_bb(ctx, body, symbols.copy()) + _convert_ir_bb(fn, body, symbols.copy()) _break_target, _continue_target = old_targets _global_symbols = saved_global_symbols sym = ir.args[0] - start, end, _ = _convert_ir_bb_list(ctx, ir.args[1:4], symbols) + start, end, _ = _convert_ir_bb_list(fn, ir.args[1:4], symbols) assert ir.args[3].is_literal, "repeat bound expected to be literal" @@ -486,15 +479,15 @@ def emit_body_blocks(): body = ir.args[4] - entry_block = IRBasicBlock(ctx.get_next_label("repeat"), ctx) - cond_block = IRBasicBlock(ctx.get_next_label("condition"), ctx) - body_block = IRBasicBlock(ctx.get_next_label("body"), ctx) - incr_block = IRBasicBlock(ctx.get_next_label("incr"), ctx) - exit_block = IRBasicBlock(ctx.get_next_label("exit"), ctx) + entry_block = IRBasicBlock(fn.get_next_label("repeat"), fn) + cond_block = IRBasicBlock(fn.get_next_label("condition"), fn) + body_block = IRBasicBlock(fn.get_next_label("body"), fn) + incr_block = IRBasicBlock(fn.get_next_label("incr"), fn) + exit_block = IRBasicBlock(fn.get_next_label("exit"), fn) - bb = ctx.get_basic_block() + bb = fn.get_basic_block() bb.append_instruction("jmp", entry_block.label) - ctx.append_basic_block(entry_block) + fn.append_basic_block(entry_block) counter_var = entry_block.append_instruction("store", start) symbols[sym.value] = counter_var @@ -505,52 +498,52 @@ def emit_body_blocks(): xor_ret = cond_block.append_instruction("xor", counter_var, end) cont_ret = cond_block.append_instruction("iszero", xor_ret) - ctx.append_basic_block(cond_block) + fn.append_basic_block(cond_block) - ctx.append_basic_block(body_block) + fn.append_basic_block(body_block) if bound: xor_ret = body_block.append_instruction("xor", counter_var, bound) body_block.append_instruction("assert", xor_ret) emit_body_blocks() - body_end = ctx.get_basic_block() + body_end = fn.get_basic_block() if body_end.is_terminated is False: body_end.append_instruction("jmp", incr_block.label) - ctx.append_basic_block(incr_block) + fn.append_basic_block(incr_block) incr_block.insert_instruction( IRInstruction("add", [counter_var, IRLiteral(1)], counter_var) ) incr_block.append_instruction("jmp", cond_block.label) - ctx.append_basic_block(exit_block) + fn.append_basic_block(exit_block) cond_block.append_instruction("jnz", cont_ret, exit_block.label, body_block.label) elif ir.value == "break": assert _break_target is not None, "Break with no break target" - ctx.get_basic_block().append_instruction("jmp", _break_target.label) - ctx.append_basic_block(IRBasicBlock(ctx.get_next_label(), ctx)) + fn.get_basic_block().append_instruction("jmp", _break_target.label) + fn.append_basic_block(IRBasicBlock(fn.get_next_label(), fn)) elif ir.value == "continue": assert _continue_target is not None, "Continue with no contrinue target" - ctx.get_basic_block().append_instruction("jmp", _continue_target.label) - ctx.append_basic_block(IRBasicBlock(ctx.get_next_label(), ctx)) + fn.get_basic_block().append_instruction("jmp", _continue_target.label) + fn.append_basic_block(IRBasicBlock(fn.get_next_label(), fn)) elif ir.value in NOOP_INSTRUCTIONS: pass elif isinstance(ir.value, str) and ir.value.startswith("log"): - args = reversed(_convert_ir_bb_list(ctx, ir.args, symbols)) + args = reversed(_convert_ir_bb_list(fn, ir.args, symbols)) topic_count = int(ir.value[3:]) assert topic_count >= 0 and topic_count <= 4, "invalid topic count" - ctx.get_basic_block().append_instruction("log", topic_count, *args) + fn.get_basic_block().append_instruction("log", topic_count, *args) elif isinstance(ir.value, str) and ir.value.upper() in get_opcodes(): - _convert_ir_opcode(ctx, ir, symbols) + _convert_ir_opcode(fn, ir, symbols) elif isinstance(ir.value, str): if ir.value.startswith("$alloca") and ir.value not in _global_symbols: alloca = ir.passthrough_metadata["alloca"] - ptr = ctx.get_basic_block().append_instruction("alloca", alloca.offset, alloca.size) + ptr = fn.get_basic_block().append_instruction("alloca", alloca.offset, alloca.size) _global_symbols[ir.value] = ptr elif ir.value.startswith("$palloca") and ir.value not in _global_symbols: alloca = ir.passthrough_metadata["alloca"] - ptr = ctx.get_basic_block().append_instruction("store", alloca.offset) + ptr = fn.get_basic_block().append_instruction("store", alloca.offset) _global_symbols[ir.value] = ptr return _global_symbols.get(ir.value) or symbols.get(ir.value) @@ -562,10 +555,10 @@ def emit_body_blocks(): return None -def _convert_ir_opcode(ctx: IRFunction, ir: IRnode, symbols: SymbolTable) -> None: +def _convert_ir_opcode(fn: IRFunction, ir: IRnode, symbols: SymbolTable) -> None: opcode = ir.value.upper() # type: ignore inst_args = [] for arg in ir.args: if isinstance(arg, IRnode): - inst_args.append(_convert_ir_bb(ctx, arg, symbols)) - ctx.get_basic_block().append_instruction(opcode, *inst_args) + inst_args.append(_convert_ir_bb(fn, arg, symbols)) + fn.get_basic_block().append_instruction(opcode, *inst_args) diff --git a/vyper/venom/passes/base_pass.py b/vyper/venom/passes/base_pass.py index 1851b35233..a4ad6be3ef 100644 --- a/vyper/venom/passes/base_pass.py +++ b/vyper/venom/passes/base_pass.py @@ -1,21 +1,15 @@ +from vyper.venom.passes.pass_manager import IRPassManager + + class IRPass: """ - Decorator for IR passes. This decorator will run the pass repeatedly - until no more changes are made. + Base class for all Venom IR passes. """ - def run_pass(self, *args, **kwargs): - count = 0 + manager: IRPassManager - for _ in range(1000): - changes_count = self._run_pass(*args, **kwargs) or 0 - count += changes_count - if changes_count == 0: - break - else: - raise Exception("Too many iterations in IR pass!", self.__class__) + def __init__(self, manager: IRPassManager): + self.manager = manager - return count - - def _run_pass(self, *args, **kwargs): + def run_pass(self, *args, **kwargs): raise NotImplementedError(f"Not implemented! {self.__class__}.run_pass()") diff --git a/vyper/venom/passes/constant_propagation.py b/vyper/venom/passes/constant_propagation.py deleted file mode 100644 index 94b556124e..0000000000 --- a/vyper/venom/passes/constant_propagation.py +++ /dev/null @@ -1,13 +0,0 @@ -from vyper.utils import ir_pass -from vyper.venom.basicblock import IRBasicBlock -from vyper.venom.function import IRFunction - - -def _process_basic_block(ctx: IRFunction, bb: IRBasicBlock): - pass - - -@ir_pass -def ir_pass_constant_propagation(ctx: IRFunction): - for bb in ctx.basic_blocks: - _process_basic_block(ctx, bb) diff --git a/vyper/venom/passes/dft.py b/vyper/venom/passes/dft.py index 994ab9d70d..e896b605f0 100644 --- a/vyper/venom/passes/dft.py +++ b/vyper/venom/passes/dft.py @@ -1,14 +1,19 @@ from vyper.utils import OrderedSet -from vyper.venom.analysis import DFG +from vyper.venom.analysis.dfg import DFGAnalysis from vyper.venom.basicblock import BB_TERMINATORS, IRBasicBlock, IRInstruction, IRVariable from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager class DFTPass(IRPass): + function: IRFunction inst_order: dict[IRInstruction, int] inst_order_num: int + def __init__(self, manager: IRPassManager): + super().__init__(manager) + def _process_instruction_r(self, bb: IRBasicBlock, inst: IRInstruction, offset: int = 0): for op in inst.get_outputs(): assert isinstance(op, IRVariable), f"expected variable, got {op}" @@ -50,7 +55,7 @@ def _process_instruction_r(self, bb: IRBasicBlock, inst: IRInstruction, offset: self.inst_order[inst] = self.inst_order_num + offset def _process_basic_block(self, bb: IRBasicBlock) -> None: - self.ctx.append_basic_block(bb) + self.function.append_basic_block(bb) for inst in bb.instructions: inst.fence_id = self.fence_id @@ -67,15 +72,15 @@ def _process_basic_block(self, bb: IRBasicBlock) -> None: bb.instructions.sort(key=lambda x: self.inst_order[x]) - def _run_pass(self, ctx: IRFunction) -> None: - self.ctx = ctx - self.dfg = DFG.build_dfg(ctx) + def run_pass(self) -> None: + self.function = self.manager.function + self.dfg = self.manager.request_analysis(DFGAnalysis) self.fence_id = 0 self.visited_instructions: OrderedSet[IRInstruction] = OrderedSet() - basic_blocks = ctx.basic_blocks - ctx.basic_blocks = [] + basic_blocks = self.function.basic_blocks + self.function.basic_blocks = [] for bb in basic_blocks: self._process_basic_block(bb) diff --git a/vyper/venom/passes/make_ssa.py b/vyper/venom/passes/make_ssa.py index 91611482a2..9a3e3aabbc 100644 --- a/vyper/venom/passes/make_ssa.py +++ b/vyper/venom/passes/make_ssa.py @@ -1,9 +1,10 @@ from vyper.utils import OrderedSet -from vyper.venom.analysis import calculate_cfg, calculate_liveness +from vyper.venom.analysis.cfg import CFGAnalysis +from vyper.venom.analysis.dominators import DominatorTreeAnalysis +from vyper.venom.analysis.liveness import LivenessAnalysis from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IROperand, IRVariable -from vyper.venom.dominators import DominatorTree -from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager class MakeSSA(IRPass): @@ -11,16 +12,21 @@ class MakeSSA(IRPass): This pass converts the function into Static Single Assignment (SSA) form. """ - dom: DominatorTree + dom: DominatorTreeAnalysis defs: dict[IRVariable, OrderedSet[IRBasicBlock]] - def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock) -> int: - self.ctx = ctx + def __init__(self, manager: IRPassManager): + super().__init__(manager) - calculate_cfg(ctx) - self.dom = DominatorTree.build_dominator_tree(ctx, entry) + def run_pass(self): + fn = self.manager.function + entry = fn.basic_blocks[0] - calculate_liveness(ctx) + self.manager.request_analysis(CFGAnalysis) + + self.dom = self.manager.request_analysis(DominatorTreeAnalysis) + + self.manager.request_analysis(LivenessAnalysis) self._add_phi_nodes() self.var_name_counters = {var.name: 0 for var in self.defs.keys()} @@ -28,8 +34,6 @@ def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock) -> int: self._rename_vars(entry) self._remove_degenerate_phis(entry) - return 0 - def _add_phi_nodes(self): """ Add phi nodes to the function. diff --git a/vyper/venom/passes/mem2var.py b/vyper/venom/passes/mem2var.py index 9d74dfec0b..ab8b5c27a2 100644 --- a/vyper/venom/passes/mem2var.py +++ b/vyper/venom/passes/mem2var.py @@ -1,8 +1,11 @@ from vyper.utils import OrderedSet -from vyper.venom.analysis import DFG, calculate_cfg, calculate_liveness +from vyper.venom.analysis.cfg import CFGAnalysis +from vyper.venom.analysis.dfg import DFGAnalysis +from vyper.venom.analysis.liveness import LivenessAnalysis from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRVariable from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager class Mem2Var(IRPass): @@ -11,20 +14,18 @@ class Mem2Var(IRPass): It does yet do any memory aliasing analysis, so it is conservative. """ - ctx: IRFunction + function: IRFunction defs: dict[IRVariable, OrderedSet[IRBasicBlock]] - dfg: DFG - def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock, dfg: DFG) -> int: - self.ctx = ctx - self.dfg = dfg + def __init__(self, manager: IRPassManager): + super().__init__(manager) - calculate_cfg(ctx) + def run_pass(self): + self.function = self.manager.function - dfg = DFG.build_dfg(ctx) - self.dfg = dfg - - calculate_liveness(ctx) + self.manager.request_analysis(CFGAnalysis) + dfg = self.manager.request_analysis(DFGAnalysis) + self.manager.request_analysis(LivenessAnalysis) self.var_name_count = 0 for var, inst in dfg.outputs.items(): @@ -32,9 +33,10 @@ def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock, dfg: DFG) -> int: continue self._process_alloca_var(dfg, var) - return 0 + self.manager.invalidate_analysis(DFGAnalysis) + self.manager.invalidate_analysis(LivenessAnalysis) - def _process_alloca_var(self, dfg: DFG, var: IRVariable): + def _process_alloca_var(self, dfg: DFGAnalysis, var: IRVariable): """ Process alloca allocated variable. If it is only used by mstore/mload/return instructions, it is promoted to a stack variable. Otherwise, it is left as is. @@ -57,7 +59,7 @@ def _process_alloca_var(self, dfg: DFG, var: IRVariable): inst.operands = [IRVariable(var_name)] elif inst.opcode == "return": bb = inst.parent - new_var = self.ctx.get_next_variable() + new_var = self.function.get_next_variable() idx = bb.instructions.index(inst) bb.insert_instruction( IRInstruction("mstore", [IRVariable(var_name), inst.operands[1]], new_var), diff --git a/vyper/venom/passes/normalization.py b/vyper/venom/passes/normalization.py index 9ca8127b2d..bbaed91f88 100644 --- a/vyper/venom/passes/normalization.py +++ b/vyper/venom/passes/normalization.py @@ -1,7 +1,8 @@ -from vyper.venom.analysis import calculate_cfg +from vyper.exceptions import CompilerPanic +from vyper.venom.analysis.cfg import CFGAnalysis from vyper.venom.basicblock import IRBasicBlock, IRLabel -from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager class NormalizationPass(IRPass): @@ -13,6 +14,9 @@ class NormalizationPass(IRPass): changes = 0 + def __init__(self, manager: IRPassManager): + super().__init__(manager) + def _split_basic_block(self, bb: IRBasicBlock) -> None: # Iterate over the predecessors to this basic block for in_bb in list(bb.cfg_in): @@ -27,14 +31,15 @@ def _insert_split_basicblock(self, bb: IRBasicBlock, in_bb: IRBasicBlock) -> IRB # Create an intermediary basic block and append it source = in_bb.label.value target = bb.label.value + fn = self.manager.function split_label = IRLabel(f"{source}_split_{target}") in_terminal = in_bb.instructions[-1] in_terminal.replace_label_operands({bb.label: split_label}) - split_bb = IRBasicBlock(split_label, self.ctx) + split_bb = IRBasicBlock(split_label, fn) split_bb.append_instruction("jmp", bb.label) - self.ctx.append_basic_block(split_bb) + fn.append_basic_block(split_bb) for inst in bb.instructions: if inst.opcode != "phi": @@ -44,24 +49,34 @@ def _insert_split_basicblock(self, bb: IRBasicBlock, in_bb: IRBasicBlock) -> IRB inst.operands[i] = split_bb.label # Update the labels in the data segment - for inst in self.ctx.data_segment: + for inst in fn.ctx.data_segment: if inst.opcode == "db" and inst.operands[0] == bb.label: inst.operands[0] = split_bb.label return split_bb - def _run_pass(self, ctx: IRFunction) -> int: - self.ctx = ctx + def _run_pass(self) -> int: + fn = self.manager.function self.changes = 0 + self.manager.request_analysis(CFGAnalysis) + # Split blocks that need splitting - for bb in ctx.basic_blocks: + for bb in fn.basic_blocks: if len(bb.cfg_in) > 1: self._split_basic_block(bb) # If we made changes, recalculate the cfg if self.changes > 0: - calculate_cfg(ctx) - ctx.remove_unreachable_blocks() + self.manager.force_analysis(CFGAnalysis) + fn.remove_unreachable_blocks() return self.changes + + def run_pass(self): + fn = self.manager.function + for _ in range(len(fn.basic_blocks) * 2): + if self._run_pass() == 0: + break + else: + raise CompilerPanic("Normalization pass did not converge") diff --git a/vyper/venom/passes/pass_manager.py b/vyper/venom/passes/pass_manager.py new file mode 100644 index 0000000000..9e2e921407 --- /dev/null +++ b/vyper/venom/passes/pass_manager.py @@ -0,0 +1,60 @@ +from typing import Type + +from vyper.venom.function import IRFunction + + +class IRPassManager: + """ + Manages the analysis and passes for the Venom IR. + """ + + function: IRFunction + valid_analyses: dict[Type["IRAnalysis"], "IRAnalysis"] # type: ignore # noqa: F821 + + def __init__(self, function: IRFunction): + self.function = function + self.valid_analyses = {} + + def request_analysis( + self, analysis_cls: "IRAnalysis", *args, **kwargs # type: ignore # noqa: F821 + ): + """ + Request a specific analysis to be run on the IR. The result is cached and + returned if the analysis has already been run. + """ + from vyper.venom.analysis.analysis import IRAnalysis + + assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" + if analysis_cls in self.valid_analyses: + return self.valid_analyses[analysis_cls] + analysis = analysis_cls(self) + analysis.analyze(*args, **kwargs) + + self.valid_analyses[analysis] = analysis + return analysis + + def invalidate_analysis(self, analysis_cls: "IRAnalysis"): # type: ignore # noqa: F821 + """ + Invalidate a specific analysis. This will remove the analysis from the cache. + """ + from vyper.venom.analysis.analysis import IRAnalysis + + assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" + if analysis_cls not in self.valid_analyses: + return + self.valid_analyses[analysis_cls].invalidate() + del self.valid_analyses[analysis_cls] + + def force_analysis( + self, analysis_cls: "IRAnalysis", *args, **kwargs # type: ignore # noqa: F821 + ): + """ + Force a specific analysis to be run on the IR even if it has already been run, + and is cached. + """ + from vyper.venom.analysis.analysis import IRAnalysis + + assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" + if analysis_cls in self.valid_analyses: + self.invalidate_analysis(analysis_cls) + return self.request_analysis(analysis_cls, *args, **kwargs) diff --git a/vyper/venom/passes/remove_unused_variables.py b/vyper/venom/passes/remove_unused_variables.py new file mode 100644 index 0000000000..b70e9b67e8 --- /dev/null +++ b/vyper/venom/passes/remove_unused_variables.py @@ -0,0 +1,22 @@ +from vyper.venom.analysis.dfg import DFGAnalysis +from vyper.venom.analysis.liveness import LivenessAnalysis +from vyper.venom.passes.base_pass import IRPass + + +class RemoveUnusedVariablesPass(IRPass): + def run_pass(self): + removeList = set() + + self.manager.request_analysis(LivenessAnalysis) + + for bb in self.manager.function.basic_blocks: + for i, inst in enumerate(bb.instructions[:-1]): + if inst.volatile: + continue + next_liveness = bb.instructions[i + 1].liveness + if (inst.output and inst.output not in next_liveness) or inst.opcode == "nop": + removeList.add(inst) + + bb.instructions = [inst for inst in bb.instructions if inst not in removeList] + + self.manager.invalidate_analysis(DFGAnalysis) diff --git a/vyper/venom/passes/sccp/sccp.py b/vyper/venom/passes/sccp/sccp.py index 7dfca8edd4..7c82cddb84 100644 --- a/vyper/venom/passes/sccp/sccp.py +++ b/vyper/venom/passes/sccp/sccp.py @@ -5,6 +5,8 @@ from vyper.exceptions import CompilerPanic, StaticAssertionException from vyper.utils import OrderedSet +from vyper.venom.analysis.cfg import CFGAnalysis +from vyper.venom.analysis.dominators import DominatorTreeAnalysis from vyper.venom.basicblock import ( IRBasicBlock, IRInstruction, @@ -13,9 +15,9 @@ IROperand, IRVariable, ) -from vyper.venom.dominators import DominatorTree from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.passes.sccp.eval import ARITHMETIC_OPS @@ -49,28 +51,30 @@ class SCCP(IRPass): with their constant values. """ - ctx: IRFunction - dom: DominatorTree + fn: IRFunction + dom: DominatorTreeAnalysis uses: dict[IRVariable, OrderedSet[IRInstruction]] lattice: Lattice work_list: list[WorkListItem] cfg_dirty: bool cfg_in_exec: dict[IRBasicBlock, OrderedSet[IRBasicBlock]] - def __init__(self, dom: DominatorTree): - self.dom = dom + def __init__(self, manager: IRPassManager): + super().__init__(manager) self.lattice = {} self.work_list: list[WorkListItem] = [] self.cfg_dirty = False - def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock) -> int: - self.ctx = ctx - self._compute_uses(self.dom) - self._calculate_sccp(entry) + def run_pass(self): + self.fn = self.manager.function + self.dom = self.manager.request_analysis(DominatorTreeAnalysis) + self._compute_uses() + self._calculate_sccp(self.fn.basic_blocks[0]) self._propagate_constants() # self._propagate_variables() - return 0 + + self.manager.invalidate_analysis(CFGAnalysis) def _calculate_sccp(self, entry: IRBasicBlock): """ @@ -83,9 +87,9 @@ def _calculate_sccp(self, entry: IRBasicBlock): and the work list. The `_propagate_constants()` method is responsible for updating the IR with the constant values. """ - self.cfg_in_exec = {bb: OrderedSet() for bb in self.ctx.basic_blocks} + self.cfg_in_exec = {bb: OrderedSet() for bb in self.fn.basic_blocks} - dummy = IRBasicBlock(IRLabel("__dummy_start"), self.ctx) + dummy = IRBasicBlock(IRLabel("__dummy_start"), self.fn) self.work_list.append(FlowWorkItem(dummy, entry)) # Initialize the lattice with TOP values for all variables @@ -143,7 +147,7 @@ def _visit_phi(self, inst: IRInstruction): assert inst.opcode == "phi", "Can't visit non phi instruction" in_vars: list[LatticeItem] = [] for bb_label, var in inst.phi_operands: - bb = self.ctx.get_basic_block(bb_label.name) + bb = self.fn.get_basic_block(bb_label.name) if bb not in self.cfg_in_exec[inst.parent]: continue in_vars.append(self.lattice[var]) @@ -162,7 +166,7 @@ def _visit_expr(self, inst: IRInstruction): self.lattice[inst.output] = self.lattice[inst.operands[0]] # type: ignore self._add_ssa_work_items(inst) elif opcode == "jmp": - target = self.ctx.get_basic_block(inst.operands[0].value) + target = self.fn.get_basic_block(inst.operands[0].value) self.work_list.append(FlowWorkItem(inst.parent, target)) elif opcode == "jnz": lat = self.lattice[inst.operands[0]] @@ -172,17 +176,17 @@ def _visit_expr(self, inst: IRInstruction): self.work_list.append(FlowWorkItem(inst.parent, out_bb)) else: if _meet(lat, IRLiteral(0)) == LatticeEnum.BOTTOM: - target = self.ctx.get_basic_block(inst.operands[1].name) + target = self.fn.get_basic_block(inst.operands[1].name) self.work_list.append(FlowWorkItem(inst.parent, target)) if _meet(lat, IRLiteral(1)) == LatticeEnum.BOTTOM: - target = self.ctx.get_basic_block(inst.operands[2].name) + target = self.fn.get_basic_block(inst.operands[2].name) self.work_list.append(FlowWorkItem(inst.parent, target)) elif opcode == "djmp": lat = self.lattice[inst.operands[0]] assert lat != LatticeEnum.TOP, f"Got undefined var at jmp at {inst.parent}" if lat == LatticeEnum.BOTTOM: for op in inst.operands[1:]: - target = self.ctx.get_basic_block(op.name) + target = self.fn.get_basic_block(op.name) self.work_list.append(FlowWorkItem(inst.parent, target)) elif isinstance(lat, IRLiteral): raise CompilerPanic("Unimplemented djmp with literal") @@ -239,14 +243,14 @@ def _add_ssa_work_items(self, inst: IRInstruction): for target_inst in self._get_uses(inst.output): # type: ignore self.work_list.append(SSAWorkListItem(target_inst)) - def _compute_uses(self, dom: DominatorTree): + def _compute_uses(self): """ This method computes the uses for each variable in the IR. It iterates over the dominator tree and collects all the instructions that use each variable. """ self.uses = {} - for bb in dom.dfs_walk: + for bb in self.dom.dfs_walk: for var, insts in bb.get_uses().items(): self._get_uses(var).update(insts) diff --git a/vyper/venom/passes/simplify_cfg.py b/vyper/venom/passes/simplify_cfg.py index bebf2acd32..8e89cfc8b6 100644 --- a/vyper/venom/passes/simplify_cfg.py +++ b/vyper/venom/passes/simplify_cfg.py @@ -1,14 +1,17 @@ from vyper.exceptions import CompilerPanic from vyper.utils import OrderedSet -from vyper.venom.basicblock import IRBasicBlock -from vyper.venom.bb_optimizer import ir_pass_remove_unreachable_blocks -from vyper.venom.function import IRFunction +from vyper.venom.analysis.cfg import CFGAnalysis +from vyper.venom.basicblock import IRBasicBlock, IRLabel from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager class SimplifyCFGPass(IRPass): visited: OrderedSet + def __init__(self, manager: IRPassManager): + super().__init__(manager) + def _merge_blocks(self, a: IRBasicBlock, b: IRBasicBlock): a.instructions.pop() for inst in b.instructions: @@ -31,7 +34,7 @@ def _merge_blocks(self, a: IRBasicBlock, b: IRBasicBlock): break inst.operands[inst.operands.index(b.label)] = a.label - self.ctx.basic_blocks.remove(b) + self.manager.function.basic_blocks.remove(b) def _merge_jump(self, a: IRBasicBlock, b: IRBasicBlock): next_bb = b.cfg_out.first() @@ -45,7 +48,7 @@ def _merge_jump(self, a: IRBasicBlock, b: IRBasicBlock): next_bb.remove_cfg_in(b) next_bb.add_cfg_in(a) - self.ctx.basic_blocks.remove(b) + self.manager.function.basic_blocks.remove(b) def _collapse_chained_blocks_r(self, bb: IRBasicBlock): """ @@ -83,12 +86,60 @@ def _collapse_chained_blocks(self, entry: IRBasicBlock): self.visited = OrderedSet() self._collapse_chained_blocks_r(entry) - def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock) -> None: - self.ctx = ctx + def _optimize_empty_basicblocks(self) -> int: + """ + Remove empty basic blocks. + """ + fn = self.manager.function + count = 0 + i = 0 + while i < len(fn.basic_blocks): + bb = fn.basic_blocks[i] + i += 1 + if len(bb.instructions) > 0: + continue + + replaced_label = bb.label + replacement_label = fn.basic_blocks[i].label if i < len(fn.basic_blocks) else None + if replacement_label is None: + continue + + # Try to preserve symbol labels + if replaced_label.is_symbol: + replaced_label, replacement_label = replacement_label, replaced_label + fn.basic_blocks[i].label = replacement_label + + for bb2 in fn.basic_blocks: + for inst in bb2.instructions: + for op in inst.operands: + if isinstance(op, IRLabel) and op.value == replaced_label.value: + op.value = replacement_label.value + + fn.basic_blocks.remove(bb) + i -= 1 + count += 1 - for _ in range(len(ctx.basic_blocks)): # essentially `while True` + return count + + def run_pass(self): + fn = self.manager.function + entry = fn.basic_blocks[0] + + for _ in range(len(fn.basic_blocks)): + changes = self._optimize_empty_basicblocks() + changes += fn.remove_unreachable_blocks() + if changes == 0: + break + else: + raise CompilerPanic("Too many iterations removing empty basic blocks") + + self.manager.force_analysis(CFGAnalysis) + + for _ in range(len(fn.basic_blocks)): # essentially `while True` self._collapse_chained_blocks(entry) - if ir_pass_remove_unreachable_blocks(ctx) == 0: + if fn.remove_unreachable_blocks() == 0: break else: raise CompilerPanic("Too many iterations collapsing chained blocks") + + self.manager.invalidate_analysis(CFGAnalysis) diff --git a/vyper/venom/passes/stack_reorder.py b/vyper/venom/passes/stack_reorder.py index b32ec4abde..3c52b23617 100644 --- a/vyper/venom/passes/stack_reorder.py +++ b/vyper/venom/passes/stack_reorder.py @@ -1,13 +1,16 @@ from vyper.utils import OrderedSet from vyper.venom.basicblock import IRBasicBlock -from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass +from vyper.venom.passes.pass_manager import IRPassManager class StackReorderPass(IRPass): visited: OrderedSet - def _reorder_stack(self, bb: IRBasicBlock): + def __init__(self, manager: IRPassManager): + super().__init__(manager) + + def _reorder_stack(self): pass def _visit(self, bb: IRBasicBlock): @@ -18,7 +21,7 @@ def _visit(self, bb: IRBasicBlock): for bb_out in bb.cfg_out: self._visit(bb_out) - def _run_pass(self, ctx: IRFunction, entry: IRBasicBlock): - self.ctx = ctx + def _run_pass(self): + entry = self.manager.function.basic_blocks[0] self.visited = OrderedSet() self._visit(entry) diff --git a/vyper/venom/venom_to_assembly.py b/vyper/venom/venom_to_assembly.py index e99b0a95b7..4ba13c3549 100644 --- a/vyper/venom/venom_to_assembly.py +++ b/vyper/venom/venom_to_assembly.py @@ -11,12 +11,8 @@ optimize_assembly, ) from vyper.utils import MemoryPositions, OrderedSet -from vyper.venom.analysis import ( - calculate_cfg, - calculate_dup_requirements, - calculate_liveness, - input_vars_from, -) +from vyper.venom.analysis.dup_requirements import DupRequirementsAnalysis +from vyper.venom.analysis.liveness import LivenessAnalysis from vyper.venom.basicblock import ( IRBasicBlock, IRInstruction, @@ -25,8 +21,9 @@ IROperand, IRVariable, ) -from vyper.venom.function import IRFunction +from vyper.venom.context import IRContext from vyper.venom.passes.normalization import NormalizationPass +from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.stack_model import StackModel # instructions which map one-to-one from venom to EVM @@ -127,12 +124,13 @@ def apply_line_numbers(inst: IRInstruction, asm) -> list[str]: # with the assembler. My suggestion is to let this be for now, and we can # refactor it later when we are finished phasing out the old IR. class VenomCompiler: - ctxs: list[IRFunction] + ctxs: list[IRContext] label_counter = 0 visited_instructions: OrderedSet # {IRInstruction} visited_basicblocks: OrderedSet # {IRBasicBlock} + liveness_analysis: LivenessAnalysis - def __init__(self, ctxs: list[IRFunction]): + def __init__(self, ctxs: list[IRContext]): self.ctxs = ctxs self.label_counter = 0 self.visited_instructions = OrderedSet() @@ -154,14 +152,16 @@ def generate_evm(self, no_optimize: bool = False) -> list[str]: # This is a side-effect of how dynamic jumps are temporarily being used # to support the O(1) dispatcher. -> look into calculate_cfg() for ctx in self.ctxs: - NormalizationPass().run_pass(ctx) - calculate_cfg(ctx) - calculate_liveness(ctx) - calculate_dup_requirements(ctx) + for fn in ctx.functions.values(): + pm = IRPassManager(fn) + + NormalizationPass(pm).run_pass() + self.liveness_analysis = pm.request_analysis(LivenessAnalysis) + pm.request_analysis(DupRequirementsAnalysis) - assert ctx.normalized, "Non-normalized CFG!" + assert fn.normalized, "Non-normalized CFG!" - self._generate_evm_for_basicblock_r(asm, ctx.basic_blocks[0], StackModel()) + self._generate_evm_for_basicblock_r(asm, fn.basic_blocks[0], StackModel()) # TODO make this property on IRFunction asm.extend(["_sym__ctor_exit", "JUMPDEST"]) @@ -321,7 +321,7 @@ def clean_stack_from_cfg_in( to_pop = OrderedSet[IRVariable]() for in_bb in basicblock.cfg_in: # inputs is the input variables we need from in_bb - inputs = input_vars_from(in_bb, basicblock) + inputs = self.liveness_analysis.input_vars_from(in_bb, basicblock) # layout is the output stack layout for in_bb (which works # for all possible cfg_outs from the in_bb). @@ -405,7 +405,7 @@ def _generate_evm_for_instruction( # prepare stack for jump into another basic block assert inst.parent and isinstance(inst.parent.cfg_out, OrderedSet) b = next(iter(inst.parent.cfg_out)) - target_stack = input_vars_from(inst.parent, b) + target_stack = self.liveness_analysis.input_vars_from(inst.parent, b) # TODO optimize stack reordering at entry and exit from basic blocks # NOTE: stack in general can contain multiple copies of the same variable, # however we are safe in the case of jmp/djmp/jnz as it's not going to From a88c57f4fe27d18740031638dcfa84501fdff542 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Thu, 2 May 2024 16:09:36 +0300 Subject: [PATCH 02/10] cleanup entry points from function --- .../venom/test_convert_basicblock_simple.py | 2 +- .../compiler/venom/test_dominator_tree.py | 3 +-- vyper/venom/analysis/dominators.py | 2 +- vyper/venom/function.py | 21 ++++--------------- vyper/venom/passes/make_ssa.py | 8 +++---- vyper/venom/passes/sccp/sccp.py | 2 +- vyper/venom/passes/simplify_cfg.py | 2 +- vyper/venom/venom_to_assembly.py | 2 +- 8 files changed, 13 insertions(+), 29 deletions(-) diff --git a/tests/unit/compiler/venom/test_convert_basicblock_simple.py b/tests/unit/compiler/venom/test_convert_basicblock_simple.py index 6dba9588bf..406ce5f6ff 100644 --- a/tests/unit/compiler/venom/test_convert_basicblock_simple.py +++ b/tests/unit/compiler/venom/test_convert_basicblock_simple.py @@ -10,7 +10,7 @@ def test_simple(): fn = list(venom.functions.values())[0] - bb = fn.basic_blocks[0] + bb = fn.entry assert bb.instructions[0].opcode == "calldatasize" assert bb.instructions[1].opcode == "calldatacopy" diff --git a/tests/unit/compiler/venom/test_dominator_tree.py b/tests/unit/compiler/venom/test_dominator_tree.py index 202aaefb75..54c2605c63 100644 --- a/tests/unit/compiler/venom/test_dominator_tree.py +++ b/tests/unit/compiler/venom/test_dominator_tree.py @@ -33,8 +33,7 @@ def _make_test_ctx(): ctx = IRContext() fn = ctx.create_function(lab[1].value) - bb1 = fn.basic_blocks[0] - bb1.append_instruction("jmp", lab[2]) + fn.entry.append_instruction("jmp", lab[2]) _add_bb(fn, lab[7], []) _add_bb(fn, lab[6], [lab[7], lab[2]]) diff --git a/vyper/venom/analysis/dominators.py b/vyper/venom/analysis/dominators.py index fe91a62bf6..1a3057cf44 100644 --- a/vyper/venom/analysis/dominators.py +++ b/vyper/venom/analysis/dominators.py @@ -27,7 +27,7 @@ def analyze(self): Compute the dominator tree. """ self.fn = self.manager.function - self.entry_block = self.fn.basic_blocks[0] + self.entry_block = self.fn.entry self.dfs_order = {} self.dfs_walk = [] self.dominators = {} diff --git a/vyper/venom/function.py b/vyper/venom/function.py index 11bb8fe488..f69edf508e 100644 --- a/vyper/venom/function.py +++ b/vyper/venom/function.py @@ -12,7 +12,6 @@ class IRFunction: name: IRLabel # symbol name ctx: "IRContext" # type: ignore # noqa: F821 - entry_points: list[IRLabel] # entry points args: list basic_blocks: list[IRBasicBlock] last_label: int @@ -26,7 +25,6 @@ class IRFunction: def __init__(self, name: IRLabel, ctx: "IRContext" = None) -> None: # type: ignore # noqa: F821 self.ctx = ctx self.name = name - self.entry_points = [] self.args = [] self.basic_blocks = [] @@ -36,20 +34,11 @@ def __init__(self, name: IRLabel, ctx: "IRContext" = None) -> None: # type: ign self._error_msg_stack = [] self._bb_index = {} - self.add_entry_point(name) self.append_basic_block(IRBasicBlock(name, self)) - def add_entry_point(self, label: IRLabel) -> None: - """ - Add entry point. - """ - self.entry_points.append(label) - - def remove_entry_point(self, label: IRLabel) -> None: - """ - Remove entry point. - """ - self.entry_points.remove(label) + @property + def entry(self) -> IRBasicBlock: + return self.basic_blocks[0] def append_basic_block(self, bb: IRBasicBlock) -> IRBasicBlock: """ @@ -160,9 +149,7 @@ def _compute_reachability(self) -> None: bb.reachable = OrderedSet() bb.is_reachable = False - for entry in self.entry_points: - entry_bb = self.get_basic_block(entry.value) - self._compute_reachability_from(entry_bb) + self._compute_reachability_from(self.entry) def _compute_reachability_from(self, bb: IRBasicBlock) -> None: """ diff --git a/vyper/venom/passes/make_ssa.py b/vyper/venom/passes/make_ssa.py index 9a3e3aabbc..5da2eb8b40 100644 --- a/vyper/venom/passes/make_ssa.py +++ b/vyper/venom/passes/make_ssa.py @@ -20,19 +20,17 @@ def __init__(self, manager: IRPassManager): def run_pass(self): fn = self.manager.function - entry = fn.basic_blocks[0] self.manager.request_analysis(CFGAnalysis) - self.dom = self.manager.request_analysis(DominatorTreeAnalysis) - self.manager.request_analysis(LivenessAnalysis) + self._add_phi_nodes() self.var_name_counters = {var.name: 0 for var in self.defs.keys()} self.var_name_stacks = {var.name: [0] for var in self.defs.keys()} - self._rename_vars(entry) - self._remove_degenerate_phis(entry) + self._rename_vars(fn.entry) + self._remove_degenerate_phis(fn.entry) def _add_phi_nodes(self): """ diff --git a/vyper/venom/passes/sccp/sccp.py b/vyper/venom/passes/sccp/sccp.py index 7c82cddb84..2471d9bf02 100644 --- a/vyper/venom/passes/sccp/sccp.py +++ b/vyper/venom/passes/sccp/sccp.py @@ -69,7 +69,7 @@ def run_pass(self): self.fn = self.manager.function self.dom = self.manager.request_analysis(DominatorTreeAnalysis) self._compute_uses() - self._calculate_sccp(self.fn.basic_blocks[0]) + self._calculate_sccp(self.fn.entry) self._propagate_constants() # self._propagate_variables() diff --git a/vyper/venom/passes/simplify_cfg.py b/vyper/venom/passes/simplify_cfg.py index 8e89cfc8b6..2f3b2d135b 100644 --- a/vyper/venom/passes/simplify_cfg.py +++ b/vyper/venom/passes/simplify_cfg.py @@ -123,7 +123,7 @@ def _optimize_empty_basicblocks(self) -> int: def run_pass(self): fn = self.manager.function - entry = fn.basic_blocks[0] + entry = fn.entry for _ in range(len(fn.basic_blocks)): changes = self._optimize_empty_basicblocks() diff --git a/vyper/venom/venom_to_assembly.py b/vyper/venom/venom_to_assembly.py index 4ba13c3549..20b448c91c 100644 --- a/vyper/venom/venom_to_assembly.py +++ b/vyper/venom/venom_to_assembly.py @@ -161,7 +161,7 @@ def generate_evm(self, no_optimize: bool = False) -> list[str]: assert fn.normalized, "Non-normalized CFG!" - self._generate_evm_for_basicblock_r(asm, fn.basic_blocks[0], StackModel()) + self._generate_evm_for_basicblock_r(asm, fn.entry, StackModel()) # TODO make this property on IRFunction asm.extend(["_sym__ctor_exit", "JUMPDEST"]) From 25d8a7f5162fef37dafe2908848ecc1385f5a205 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Thu, 2 May 2024 16:16:50 +0300 Subject: [PATCH 03/10] remove get_next_label from IRFunction --- vyper/venom/function.py | 3 -- vyper/venom/ir_node_to_venom.py | 43 +++++++++++++++-------------- vyper/venom/passes/stack_reorder.py | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/vyper/venom/function.py b/vyper/venom/function.py index f69edf508e..40b19e1003 100644 --- a/vyper/venom/function.py +++ b/vyper/venom/function.py @@ -98,9 +98,6 @@ def get_basicblocks_in(self, basic_block: IRBasicBlock) -> list[IRBasicBlock]: """ return [bb for bb in self.basic_blocks if basic_block.label in bb.cfg_in] - def get_next_label(self, suffix: str = "") -> IRLabel: - return self.ctx.get_next_label(suffix) - def get_next_variable(self) -> IRVariable: self.last_variable += 1 return IRVariable(f"%{self.last_variable}") diff --git a/vyper/venom/ir_node_to_venom.py b/vyper/venom/ir_node_to_venom.py index 063028a8ae..b4465e9f7b 100644 --- a/vyper/venom/ir_node_to_venom.py +++ b/vyper/venom/ir_node_to_venom.py @@ -129,14 +129,14 @@ def ir_node_to_venom(ir: IRnode) -> IRContext: def _append_jmp(fn: IRFunction, label: IRLabel) -> None: bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(fn.get_next_label("jmp_target"), fn) + bb = IRBasicBlock(fn.ctx.get_next_label("jmp_target"), fn) fn.append_basic_block(bb) bb.append_instruction("jmp", label) def _new_block(fn: IRFunction) -> IRBasicBlock: - bb = IRBasicBlock(fn.get_next_label(), fn) + bb = IRBasicBlock(fn.ctx.get_next_label(), fn) bb = fn.append_basic_block(bb) return bb @@ -144,7 +144,7 @@ def _new_block(fn: IRFunction) -> IRBasicBlock: def _append_return_args(fn: IRFunction, ofst: int = 0, size: int = 0): bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(fn.get_next_label("exit_to"), fn) + bb = IRBasicBlock(fn.ctx.get_next_label("exit_to"), fn) fn.append_basic_block(bb) ret_ofst = IRVariable("ret_ofst") ret_size = IRVariable("ret_size") @@ -235,6 +235,7 @@ def _convert_ir_bb(fn, ir, symbols): assert isinstance(ir, IRnode), ir global _break_target, _continue_target, current_func, var_list, _global_symbols + ctx = fn.ctx fn.push_source(ir) if ir.value in INVERSE_MAPPED_IR_INSTRUCTIONS: @@ -250,8 +251,8 @@ def _convert_ir_bb(fn, ir, symbols): "return", IRVariable("ret_size"), IRVariable("ret_ofst") ) elif ir.value == "deploy": - fn.ctx.ctor_mem_size = ir.args[0].value - fn.ctx.immutables_len = ir.args[2].value + ctx.ctor_mem_size = ir.args[0].value + ctx.immutables_len = ir.args[2].value return None elif ir.value == "seq": if len(ir.args) == 0: @@ -280,7 +281,7 @@ def _convert_ir_bb(fn, ir, symbols): else: bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(fn.get_next_label("seq"), fn) + bb = IRBasicBlock(ctx.get_next_label("seq"), fn) fn.append_basic_block(bb) ret = _convert_ir_bb(fn, ir.args[0], symbols) @@ -297,8 +298,8 @@ def _convert_ir_bb(fn, ir, symbols): saved_global_symbols = _global_symbols.copy() - then_block = IRBasicBlock(fn.get_next_label("then"), fn) - else_block = IRBasicBlock(fn.get_next_label("else"), fn) + then_block = IRBasicBlock(ctx.get_next_label("then"), fn) + else_block = IRBasicBlock(ctx.get_next_label("else"), fn) # convert "then" cond_symbols = symbols.copy() @@ -326,7 +327,7 @@ def _convert_ir_bb(fn, ir, symbols): cond_block.append_instruction("jnz", cont_ret, then_block.label, else_block.label) # exit bb - exit_bb = IRBasicBlock(fn.get_next_label("if_exit"), fn) + exit_bb = IRBasicBlock(ctx.get_next_label("if_exit"), fn) exit_bb = fn.append_basic_block(exit_bb) if_ret = fn.get_next_variable() @@ -371,16 +372,16 @@ def _convert_ir_bb(fn, ir, symbols): return IRLabel(ir.args[0].value, True) elif ir.value == "data": label = IRLabel(ir.args[0].value) - fn.ctx.append_data("dbname", [label]) + ctx.append_data("dbname", [label]) for c in ir.args[1:]: if isinstance(c, int): assert 0 <= c <= 255, "data with invalid size" - fn.ctx.append_data("db", [c]) # type: ignore + ctx.append_data("db", [c]) # type: ignore elif isinstance(c.value, bytes): - fn.ctx.append_data("db", [c.value]) # type: ignore + ctx.append_data("db", [c.value]) # type: ignore elif isinstance(c, IRnode): data = _convert_ir_bb(fn, c, symbols) - fn.ctx.append_data("db", [data]) # type: ignore + ctx.append_data("db", [data]) # type: ignore elif ir.value == "label": label = IRLabel(ir.args[0].value, True) bb = fn.get_basic_block() @@ -399,7 +400,7 @@ def _convert_ir_bb(fn, ir, symbols): _append_return_args(fn, *var_list) bb = fn.get_basic_block() if bb.is_terminated: - bb = IRBasicBlock(fn.get_next_label("exit_to"), fn) + bb = IRBasicBlock(ctx.get_next_label("exit_to"), fn) fn.append_basic_block(bb) bb = fn.get_basic_block() @@ -479,11 +480,11 @@ def emit_body_blocks(): body = ir.args[4] - entry_block = IRBasicBlock(fn.get_next_label("repeat"), fn) - cond_block = IRBasicBlock(fn.get_next_label("condition"), fn) - body_block = IRBasicBlock(fn.get_next_label("body"), fn) - incr_block = IRBasicBlock(fn.get_next_label("incr"), fn) - exit_block = IRBasicBlock(fn.get_next_label("exit"), fn) + entry_block = IRBasicBlock(ctx.get_next_label("repeat"), fn) + cond_block = IRBasicBlock(ctx.get_next_label("condition"), fn) + body_block = IRBasicBlock(ctx.get_next_label("body"), fn) + incr_block = IRBasicBlock(ctx.get_next_label("incr"), fn) + exit_block = IRBasicBlock(ctx.get_next_label("exit"), fn) bb = fn.get_basic_block() bb.append_instruction("jmp", entry_block.label) @@ -522,11 +523,11 @@ def emit_body_blocks(): elif ir.value == "break": assert _break_target is not None, "Break with no break target" fn.get_basic_block().append_instruction("jmp", _break_target.label) - fn.append_basic_block(IRBasicBlock(fn.get_next_label(), fn)) + fn.append_basic_block(IRBasicBlock(ctx.get_next_label(), fn)) elif ir.value == "continue": assert _continue_target is not None, "Continue with no contrinue target" fn.get_basic_block().append_instruction("jmp", _continue_target.label) - fn.append_basic_block(IRBasicBlock(fn.get_next_label(), fn)) + fn.append_basic_block(IRBasicBlock(ctx.get_next_label(), fn)) elif ir.value in NOOP_INSTRUCTIONS: pass elif isinstance(ir.value, str) and ir.value.startswith("log"): diff --git a/vyper/venom/passes/stack_reorder.py b/vyper/venom/passes/stack_reorder.py index 3c52b23617..3f7452c9ca 100644 --- a/vyper/venom/passes/stack_reorder.py +++ b/vyper/venom/passes/stack_reorder.py @@ -22,6 +22,6 @@ def _visit(self, bb: IRBasicBlock): self._visit(bb_out) def _run_pass(self): - entry = self.manager.function.basic_blocks[0] + entry = self.manager.function.entry self.visited = OrderedSet() self._visit(entry) From 3dfdda263db1e358cff59b0dbe0f6ac1ea045f5c Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Fri, 3 May 2024 20:14:41 +0300 Subject: [PATCH 04/10] fix ident --- vyper/venom/passes/pass_manager.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vyper/venom/passes/pass_manager.py b/vyper/venom/passes/pass_manager.py index 9e2e921407..60aa1be334 100644 --- a/vyper/venom/passes/pass_manager.py +++ b/vyper/venom/passes/pass_manager.py @@ -40,10 +40,9 @@ def invalidate_analysis(self, analysis_cls: "IRAnalysis"): # type: ignore # noq from vyper.venom.analysis.analysis import IRAnalysis assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" - if analysis_cls not in self.valid_analyses: - return - self.valid_analyses[analysis_cls].invalidate() - del self.valid_analyses[analysis_cls] + analysis = self.valid_analyses.pop(analysis_cls, None) + if analysis is not None: + analysis.invalidate() def force_analysis( self, analysis_cls: "IRAnalysis", *args, **kwargs # type: ignore # noqa: F821 From daa7ffea80b609135be47fb984724273da545608 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Sat, 4 May 2024 01:05:22 +0300 Subject: [PATCH 05/10] remove pass manager/create analyses cache --- vyper/venom/__init__.py | 19 +++--- vyper/venom/analysis/analysis.py | 64 +++++++++++++++++-- vyper/venom/analysis/cfg.py | 8 +-- vyper/venom/analysis/dfg.py | 11 ++-- vyper/venom/analysis/dominators.py | 4 +- vyper/venom/analysis/dup_requirements.py | 2 +- vyper/venom/analysis/liveness.py | 6 +- vyper/venom/function.py | 2 +- vyper/venom/passes/base_pass.py | 11 ++-- vyper/venom/passes/dft.py | 7 +- vyper/venom/passes/make_ssa.py | 12 ++-- vyper/venom/passes/mem2var.py | 16 ++--- vyper/venom/passes/normalization.py | 14 ++-- vyper/venom/passes/pass_manager.py | 59 ----------------- vyper/venom/passes/remove_unused_variables.py | 6 +- vyper/venom/passes/sccp/sccp.py | 12 ++-- vyper/venom/passes/simplify_cfg.py | 16 ++--- vyper/venom/passes/stack_reorder.py | 6 +- vyper/venom/venom_to_assembly.py | 11 ++-- 19 files changed, 129 insertions(+), 157 deletions(-) delete mode 100644 vyper/venom/passes/pass_manager.py diff --git a/vyper/venom/__init__.py b/vyper/venom/__init__.py index c8cb0c663d..b8b4f787fe 100644 --- a/vyper/venom/__init__.py +++ b/vyper/venom/__init__.py @@ -3,6 +3,8 @@ from typing import Optional +from vyper.venom.analysis.analysis import IRAnalysesCache + from vyper.codegen.ir_node import IRnode from vyper.compiler.settings import OptimizationLevel from vyper.venom.analysis.liveness import LivenessAnalysis @@ -12,7 +14,6 @@ from vyper.venom.passes.dft import DFTPass from vyper.venom.passes.make_ssa import MakeSSA from vyper.venom.passes.mem2var import Mem2Var -from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.passes.remove_unused_variables import RemoveUnusedVariablesPass from vyper.venom.passes.sccp import SCCP from vyper.venom.passes.simplify_cfg import SimplifyCFGPass @@ -40,16 +41,16 @@ def _run_passes(fn: IRFunction, optimize: OptimizationLevel) -> None: # Run passes on Venom IR # TODO: Add support for optimization levels - pm = IRPassManager(fn) + ac = IRAnalysesCache(fn) - SimplifyCFGPass(pm).run_pass() - Mem2Var(pm).run_pass() - MakeSSA(pm).run_pass() - SCCP(pm).run_pass() + SimplifyCFGPass(ac, fn).run_pass() + Mem2Var(ac, fn).run_pass() + MakeSSA(ac, fn).run_pass() + SCCP(ac, fn).run_pass() - SimplifyCFGPass(pm).run_pass() - RemoveUnusedVariablesPass(pm).run_pass() - DFTPass(pm).run_pass() + SimplifyCFGPass(ac, fn).run_pass() + RemoveUnusedVariablesPass(ac, fn).run_pass() + DFTPass(ac, fn).run_pass() def generate_ir(ir: IRnode, optimize: OptimizationLevel) -> IRContext: diff --git a/vyper/venom/analysis/analysis.py b/vyper/venom/analysis/analysis.py index 5e360b7fb9..670cd67d09 100644 --- a/vyper/venom/analysis/analysis.py +++ b/vyper/venom/analysis/analysis.py @@ -1,4 +1,6 @@ -from vyper.venom.passes.pass_manager import IRPassManager +from typing import Type + +from vyper.venom.function import IRFunction class IRAnalysis: @@ -6,10 +8,12 @@ class IRAnalysis: Base class for all Venom IR analyses. """ - manager: IRPassManager + function: "IRFunction" + analyses_cache: "IRAnalysesCache" - def __init__(self, manager: IRPassManager): - self.manager = manager + def __init__(self, analyses_cache: "IRAnalysesCache", function: IRFunction): + self.analyses_cache = analyses_cache + self.function = function def analyze(self, *args, **kwargs): """ @@ -22,4 +26,54 @@ def invalidate(self): Override this method to respond to an invalidation request, and possibly invalidate any other analyses that depend on this one. """ - raise NotImplementedError + pass + + +class IRAnalysesCache: + """ + Manages the analysis and passes for the Venom IR. + """ + + function: IRFunction + analyses_cache: dict[Type[IRAnalysis], IRAnalysis] + + def __init__(self, function: IRFunction): + self.analyses_cache = {} + self.function = function + + def request_analysis(self, analysis_cls: Type[IRAnalysis], *args, **kwargs): + """ + Request a specific analysis to be run on the IR. The result is cached and + returned if the analysis has already been run. + """ + from vyper.venom.analysis.analysis import IRAnalysis + + assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" + if analysis_cls in self.analyses_cache: + return self.analyses_cache[analysis_cls] + analysis = analysis_cls(self, self.function) + analysis.analyze(*args, **kwargs) + + self.analyses_cache[analysis_cls] = analysis + return analysis + + def invalidate_analysis(self, analysis_cls: Type[IRAnalysis]): + """ + Invalidate a specific analysis. This will remove the analysis from the cache. + """ + from vyper.venom.analysis.analysis import IRAnalysis + + assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" + analysis = self.analyses_cache.pop(analysis_cls, None) + if analysis is not None: + analysis.invalidate() + + def force_analysis(self, analysis_cls: Type[IRAnalysis], *args, **kwargs): + """ + Force a specific analysis to be run on the IR even if it has already been run, + and is cached. + """ + assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" + if analysis_cls in self.analyses_cache: + self.invalidate_analysis(analysis_cls) + return self.request_analysis(analysis_cls, *args, **kwargs) diff --git a/vyper/venom/analysis/cfg.py b/vyper/venom/analysis/cfg.py index 9eeb9c7e57..2a521ab131 100644 --- a/vyper/venom/analysis/cfg.py +++ b/vyper/venom/analysis/cfg.py @@ -9,7 +9,7 @@ class CFGAnalysis(IRAnalysis): """ def analyze(self) -> None: - fn = self.manager.function + fn = self.function for bb in fn.basic_blocks: bb.cfg_in = OrderedSet() bb.cfg_out = OrderedSet() @@ -34,10 +34,8 @@ def analyze(self) -> None: in_bb.add_cfg_out(bb) def invalidate(self): - super().invalidate() - from vyper.venom.analysis.dominators import DominatorTreeAnalysis from vyper.venom.analysis.liveness import LivenessAnalysis - self.manager.invalidate_analysis(DominatorTreeAnalysis) - self.manager.invalidate_analysis(LivenessAnalysis) + self.analyses_cache.invalidate_analysis(DominatorTreeAnalysis) + self.analyses_cache.invalidate_analysis(LivenessAnalysis) diff --git a/vyper/venom/analysis/dfg.py b/vyper/venom/analysis/dfg.py index 9484af7026..36a9e04702 100644 --- a/vyper/venom/analysis/dfg.py +++ b/vyper/venom/analysis/dfg.py @@ -1,16 +1,17 @@ from typing import Optional -from vyper.venom.analysis.analysis import IRAnalysis +from vyper.venom.function import IRFunction + +from vyper.venom.analysis.analysis import IRAnalysesCache, IRAnalysis from vyper.venom.basicblock import IRInstruction, IRVariable -from vyper.venom.passes.pass_manager import IRPassManager class DFGAnalysis(IRAnalysis): _dfg_inputs: dict[IRVariable, list[IRInstruction]] _dfg_outputs: dict[IRVariable, IRInstruction] - def __init__(self, manager: IRPassManager): - super().__init__(manager) + def __init__(self, analyses_cache: IRAnalysesCache, function: IRFunction): + super().__init__(analyses_cache, function) self._dfg_inputs = dict() self._dfg_outputs = dict() @@ -33,7 +34,7 @@ def analyze(self): # %16 = iszero %15 # dfg_outputs of %15 is (%15 = add %13 %14) # dfg_inputs of %15 is all the instructions which *use* %15, ex. [(%16 = iszero %15), ...] - for bb in self.manager.function.basic_blocks: + for bb in self.function.basic_blocks: for inst in bb.instructions: operands = inst.get_inputs() res = inst.get_outputs() diff --git a/vyper/venom/analysis/dominators.py b/vyper/venom/analysis/dominators.py index 1a3057cf44..c0b149d880 100644 --- a/vyper/venom/analysis/dominators.py +++ b/vyper/venom/analysis/dominators.py @@ -26,7 +26,7 @@ def analyze(self): """ Compute the dominator tree. """ - self.fn = self.manager.function + self.fn = self.function self.entry_block = self.fn.entry self.dfs_order = {} self.dfs_walk = [] @@ -35,7 +35,7 @@ def analyze(self): self.dominated = {} self.dominator_frontiers = {} - self.manager.request_analysis(CFGAnalysis) + self.analyses_cache.request_analysis(CFGAnalysis) self._compute_dfs(self.entry_block, OrderedSet()) self._compute_dominators() diff --git a/vyper/venom/analysis/dup_requirements.py b/vyper/venom/analysis/dup_requirements.py index 278beed310..015c7c5871 100644 --- a/vyper/venom/analysis/dup_requirements.py +++ b/vyper/venom/analysis/dup_requirements.py @@ -4,7 +4,7 @@ class DupRequirementsAnalysis(IRAnalysis): def analyze(self): - for bb in self.manager.function.basic_blocks: + for bb in self.function.basic_blocks: last_liveness = bb.out_vars for inst in reversed(bb.instructions): inst.dup_requirements = OrderedSet() diff --git a/vyper/venom/analysis/liveness.py b/vyper/venom/analysis/liveness.py index b1e75ccb41..95853e57aa 100644 --- a/vyper/venom/analysis/liveness.py +++ b/vyper/venom/analysis/liveness.py @@ -11,11 +11,11 @@ class LivenessAnalysis(IRAnalysis): """ def analyze(self): - self.manager.request_analysis(CFGAnalysis) + self.analyses_cache.request_analysis(CFGAnalysis) self._reset_liveness() while True: changed = False - for bb in self.manager.function.basic_blocks: + for bb in self.function.basic_blocks: changed |= self._calculate_out_vars(bb) changed |= self._calculate_liveness(bb) @@ -23,7 +23,7 @@ def analyze(self): break def _reset_liveness(self) -> None: - for bb in self.manager.function.basic_blocks: + for bb in self.function.basic_blocks: bb.out_vars = OrderedSet() for inst in bb.instructions: inst.liveness = OrderedSet() diff --git a/vyper/venom/function.py b/vyper/venom/function.py index 40b19e1003..556be28246 100644 --- a/vyper/venom/function.py +++ b/vyper/venom/function.py @@ -156,7 +156,7 @@ def _compute_reachability_from(self, bb: IRBasicBlock) -> None: return bb.is_reachable = True for inst in bb.instructions: - if inst.opcode in CFG_ALTERING_INSTRUCTIONS: # or inst.opcode == "invoke": + if inst.opcode in CFG_ALTERING_INSTRUCTIONS: for op in inst.get_label_operands(): out_bb = self.get_basic_block(op.value) bb.reachable.add(out_bb) diff --git a/vyper/venom/passes/base_pass.py b/vyper/venom/passes/base_pass.py index a4ad6be3ef..4d1bfe9647 100644 --- a/vyper/venom/passes/base_pass.py +++ b/vyper/venom/passes/base_pass.py @@ -1,4 +1,5 @@ -from vyper.venom.passes.pass_manager import IRPassManager +from vyper.venom.analysis.analysis import IRAnalysesCache +from vyper.venom.function import IRFunction class IRPass: @@ -6,10 +7,12 @@ class IRPass: Base class for all Venom IR passes. """ - manager: IRPassManager + function: IRFunction + analyses_cache: IRAnalysesCache - def __init__(self, manager: IRPassManager): - self.manager = manager + def __init__(self, analyses_cache: IRAnalysesCache, function: IRFunction): + self.function = function + self.analyses_cache = analyses_cache def run_pass(self, *args, **kwargs): raise NotImplementedError(f"Not implemented! {self.__class__}.run_pass()") diff --git a/vyper/venom/passes/dft.py b/vyper/venom/passes/dft.py index e896b605f0..e4e27ed813 100644 --- a/vyper/venom/passes/dft.py +++ b/vyper/venom/passes/dft.py @@ -3,7 +3,6 @@ from vyper.venom.basicblock import BB_TERMINATORS, IRBasicBlock, IRInstruction, IRVariable from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager class DFTPass(IRPass): @@ -11,9 +10,6 @@ class DFTPass(IRPass): inst_order: dict[IRInstruction, int] inst_order_num: int - def __init__(self, manager: IRPassManager): - super().__init__(manager) - def _process_instruction_r(self, bb: IRBasicBlock, inst: IRInstruction, offset: int = 0): for op in inst.get_outputs(): assert isinstance(op, IRVariable), f"expected variable, got {op}" @@ -73,8 +69,7 @@ def _process_basic_block(self, bb: IRBasicBlock) -> None: bb.instructions.sort(key=lambda x: self.inst_order[x]) def run_pass(self) -> None: - self.function = self.manager.function - self.dfg = self.manager.request_analysis(DFGAnalysis) + self.dfg = self.analyses_cache.request_analysis(DFGAnalysis) self.fence_id = 0 self.visited_instructions: OrderedSet[IRInstruction] = OrderedSet() diff --git a/vyper/venom/passes/make_ssa.py b/vyper/venom/passes/make_ssa.py index 5da2eb8b40..fd7861930a 100644 --- a/vyper/venom/passes/make_ssa.py +++ b/vyper/venom/passes/make_ssa.py @@ -4,7 +4,6 @@ from vyper.venom.analysis.liveness import LivenessAnalysis from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IROperand, IRVariable from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager class MakeSSA(IRPass): @@ -15,15 +14,12 @@ class MakeSSA(IRPass): dom: DominatorTreeAnalysis defs: dict[IRVariable, OrderedSet[IRBasicBlock]] - def __init__(self, manager: IRPassManager): - super().__init__(manager) - def run_pass(self): - fn = self.manager.function + fn = self.function - self.manager.request_analysis(CFGAnalysis) - self.dom = self.manager.request_analysis(DominatorTreeAnalysis) - self.manager.request_analysis(LivenessAnalysis) + self.analyses_cache.request_analysis(CFGAnalysis) + self.dom = self.analyses_cache.request_analysis(DominatorTreeAnalysis) + self.analyses_cache.request_analysis(LivenessAnalysis) self._add_phi_nodes() diff --git a/vyper/venom/passes/mem2var.py b/vyper/venom/passes/mem2var.py index ab8b5c27a2..0ad9c411f1 100644 --- a/vyper/venom/passes/mem2var.py +++ b/vyper/venom/passes/mem2var.py @@ -5,7 +5,6 @@ from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRVariable from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager class Mem2Var(IRPass): @@ -17,15 +16,10 @@ class Mem2Var(IRPass): function: IRFunction defs: dict[IRVariable, OrderedSet[IRBasicBlock]] - def __init__(self, manager: IRPassManager): - super().__init__(manager) - def run_pass(self): - self.function = self.manager.function - - self.manager.request_analysis(CFGAnalysis) - dfg = self.manager.request_analysis(DFGAnalysis) - self.manager.request_analysis(LivenessAnalysis) + self.analyses_cache.request_analysis(CFGAnalysis) + dfg = self.analyses_cache.request_analysis(DFGAnalysis) + self.analyses_cache.request_analysis(LivenessAnalysis) self.var_name_count = 0 for var, inst in dfg.outputs.items(): @@ -33,8 +27,8 @@ def run_pass(self): continue self._process_alloca_var(dfg, var) - self.manager.invalidate_analysis(DFGAnalysis) - self.manager.invalidate_analysis(LivenessAnalysis) + self.analyses_cache.invalidate_analysis(DFGAnalysis) + self.analyses_cache.invalidate_analysis(LivenessAnalysis) def _process_alloca_var(self, dfg: DFGAnalysis, var: IRVariable): """ diff --git a/vyper/venom/passes/normalization.py b/vyper/venom/passes/normalization.py index bbaed91f88..83c565b1be 100644 --- a/vyper/venom/passes/normalization.py +++ b/vyper/venom/passes/normalization.py @@ -2,7 +2,6 @@ from vyper.venom.analysis.cfg import CFGAnalysis from vyper.venom.basicblock import IRBasicBlock, IRLabel from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager class NormalizationPass(IRPass): @@ -14,9 +13,6 @@ class NormalizationPass(IRPass): changes = 0 - def __init__(self, manager: IRPassManager): - super().__init__(manager) - def _split_basic_block(self, bb: IRBasicBlock) -> None: # Iterate over the predecessors to this basic block for in_bb in list(bb.cfg_in): @@ -31,7 +27,7 @@ def _insert_split_basicblock(self, bb: IRBasicBlock, in_bb: IRBasicBlock) -> IRB # Create an intermediary basic block and append it source = in_bb.label.value target = bb.label.value - fn = self.manager.function + fn = self.function split_label = IRLabel(f"{source}_split_{target}") in_terminal = in_bb.instructions[-1] @@ -56,10 +52,10 @@ def _insert_split_basicblock(self, bb: IRBasicBlock, in_bb: IRBasicBlock) -> IRB return split_bb def _run_pass(self) -> int: - fn = self.manager.function + fn = self.function self.changes = 0 - self.manager.request_analysis(CFGAnalysis) + self.analyses_cache.request_analysis(CFGAnalysis) # Split blocks that need splitting for bb in fn.basic_blocks: @@ -68,13 +64,13 @@ def _run_pass(self) -> int: # If we made changes, recalculate the cfg if self.changes > 0: - self.manager.force_analysis(CFGAnalysis) + self.analyses_cache.force_analysis(CFGAnalysis) fn.remove_unreachable_blocks() return self.changes def run_pass(self): - fn = self.manager.function + fn = self.function for _ in range(len(fn.basic_blocks) * 2): if self._run_pass() == 0: break diff --git a/vyper/venom/passes/pass_manager.py b/vyper/venom/passes/pass_manager.py deleted file mode 100644 index 60aa1be334..0000000000 --- a/vyper/venom/passes/pass_manager.py +++ /dev/null @@ -1,59 +0,0 @@ -from typing import Type - -from vyper.venom.function import IRFunction - - -class IRPassManager: - """ - Manages the analysis and passes for the Venom IR. - """ - - function: IRFunction - valid_analyses: dict[Type["IRAnalysis"], "IRAnalysis"] # type: ignore # noqa: F821 - - def __init__(self, function: IRFunction): - self.function = function - self.valid_analyses = {} - - def request_analysis( - self, analysis_cls: "IRAnalysis", *args, **kwargs # type: ignore # noqa: F821 - ): - """ - Request a specific analysis to be run on the IR. The result is cached and - returned if the analysis has already been run. - """ - from vyper.venom.analysis.analysis import IRAnalysis - - assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" - if analysis_cls in self.valid_analyses: - return self.valid_analyses[analysis_cls] - analysis = analysis_cls(self) - analysis.analyze(*args, **kwargs) - - self.valid_analyses[analysis] = analysis - return analysis - - def invalidate_analysis(self, analysis_cls: "IRAnalysis"): # type: ignore # noqa: F821 - """ - Invalidate a specific analysis. This will remove the analysis from the cache. - """ - from vyper.venom.analysis.analysis import IRAnalysis - - assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" - analysis = self.valid_analyses.pop(analysis_cls, None) - if analysis is not None: - analysis.invalidate() - - def force_analysis( - self, analysis_cls: "IRAnalysis", *args, **kwargs # type: ignore # noqa: F821 - ): - """ - Force a specific analysis to be run on the IR even if it has already been run, - and is cached. - """ - from vyper.venom.analysis.analysis import IRAnalysis - - assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" - if analysis_cls in self.valid_analyses: - self.invalidate_analysis(analysis_cls) - return self.request_analysis(analysis_cls, *args, **kwargs) diff --git a/vyper/venom/passes/remove_unused_variables.py b/vyper/venom/passes/remove_unused_variables.py index b70e9b67e8..b7fb3abbf0 100644 --- a/vyper/venom/passes/remove_unused_variables.py +++ b/vyper/venom/passes/remove_unused_variables.py @@ -7,9 +7,9 @@ class RemoveUnusedVariablesPass(IRPass): def run_pass(self): removeList = set() - self.manager.request_analysis(LivenessAnalysis) + self.analyses_cache.request_analysis(LivenessAnalysis) - for bb in self.manager.function.basic_blocks: + for bb in self.function.basic_blocks: for i, inst in enumerate(bb.instructions[:-1]): if inst.volatile: continue @@ -19,4 +19,4 @@ def run_pass(self): bb.instructions = [inst for inst in bb.instructions if inst not in removeList] - self.manager.invalidate_analysis(DFGAnalysis) + self.analyses_cache.invalidate_analysis(DFGAnalysis) diff --git a/vyper/venom/passes/sccp/sccp.py b/vyper/venom/passes/sccp/sccp.py index 2471d9bf02..2aaf1f76f5 100644 --- a/vyper/venom/passes/sccp/sccp.py +++ b/vyper/venom/passes/sccp/sccp.py @@ -3,6 +3,7 @@ from functools import reduce from typing import Union +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.exceptions import CompilerPanic, StaticAssertionException from vyper.utils import OrderedSet from vyper.venom.analysis.cfg import CFGAnalysis @@ -17,7 +18,6 @@ ) from vyper.venom.function import IRFunction from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.passes.sccp.eval import ARITHMETIC_OPS @@ -59,22 +59,22 @@ class SCCP(IRPass): cfg_dirty: bool cfg_in_exec: dict[IRBasicBlock, OrderedSet[IRBasicBlock]] - def __init__(self, manager: IRPassManager): - super().__init__(manager) + def __init__(self, function: IRFunction, analyses_cache: IRAnalysesCache): + super().__init__(function, analyses_cache) self.lattice = {} self.work_list: list[WorkListItem] = [] self.cfg_dirty = False def run_pass(self): - self.fn = self.manager.function - self.dom = self.manager.request_analysis(DominatorTreeAnalysis) + self.fn = self.function + self.dom = self.analyses_cache.request_analysis(DominatorTreeAnalysis) self._compute_uses() self._calculate_sccp(self.fn.entry) self._propagate_constants() # self._propagate_variables() - self.manager.invalidate_analysis(CFGAnalysis) + self.analyses_cache.invalidate_analysis(CFGAnalysis) def _calculate_sccp(self, entry: IRBasicBlock): """ diff --git a/vyper/venom/passes/simplify_cfg.py b/vyper/venom/passes/simplify_cfg.py index 2f3b2d135b..bb5233eba0 100644 --- a/vyper/venom/passes/simplify_cfg.py +++ b/vyper/venom/passes/simplify_cfg.py @@ -3,15 +3,11 @@ from vyper.venom.analysis.cfg import CFGAnalysis from vyper.venom.basicblock import IRBasicBlock, IRLabel from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager class SimplifyCFGPass(IRPass): visited: OrderedSet - def __init__(self, manager: IRPassManager): - super().__init__(manager) - def _merge_blocks(self, a: IRBasicBlock, b: IRBasicBlock): a.instructions.pop() for inst in b.instructions: @@ -34,7 +30,7 @@ def _merge_blocks(self, a: IRBasicBlock, b: IRBasicBlock): break inst.operands[inst.operands.index(b.label)] = a.label - self.manager.function.basic_blocks.remove(b) + self.function.basic_blocks.remove(b) def _merge_jump(self, a: IRBasicBlock, b: IRBasicBlock): next_bb = b.cfg_out.first() @@ -48,7 +44,7 @@ def _merge_jump(self, a: IRBasicBlock, b: IRBasicBlock): next_bb.remove_cfg_in(b) next_bb.add_cfg_in(a) - self.manager.function.basic_blocks.remove(b) + self.function.basic_blocks.remove(b) def _collapse_chained_blocks_r(self, bb: IRBasicBlock): """ @@ -90,7 +86,7 @@ def _optimize_empty_basicblocks(self) -> int: """ Remove empty basic blocks. """ - fn = self.manager.function + fn = self.function count = 0 i = 0 while i < len(fn.basic_blocks): @@ -122,7 +118,7 @@ def _optimize_empty_basicblocks(self) -> int: return count def run_pass(self): - fn = self.manager.function + fn = self.function entry = fn.entry for _ in range(len(fn.basic_blocks)): @@ -133,7 +129,7 @@ def run_pass(self): else: raise CompilerPanic("Too many iterations removing empty basic blocks") - self.manager.force_analysis(CFGAnalysis) + self.analyses_cache.force_analysis(CFGAnalysis) for _ in range(len(fn.basic_blocks)): # essentially `while True` self._collapse_chained_blocks(entry) @@ -142,4 +138,4 @@ def run_pass(self): else: raise CompilerPanic("Too many iterations collapsing chained blocks") - self.manager.invalidate_analysis(CFGAnalysis) + self.analyses_cache.invalidate_analysis(CFGAnalysis) diff --git a/vyper/venom/passes/stack_reorder.py b/vyper/venom/passes/stack_reorder.py index 3f7452c9ca..a92fe0e626 100644 --- a/vyper/venom/passes/stack_reorder.py +++ b/vyper/venom/passes/stack_reorder.py @@ -1,15 +1,11 @@ from vyper.utils import OrderedSet from vyper.venom.basicblock import IRBasicBlock from vyper.venom.passes.base_pass import IRPass -from vyper.venom.passes.pass_manager import IRPassManager class StackReorderPass(IRPass): visited: OrderedSet - def __init__(self, manager: IRPassManager): - super().__init__(manager) - def _reorder_stack(self): pass @@ -22,6 +18,6 @@ def _visit(self, bb: IRBasicBlock): self._visit(bb_out) def _run_pass(self): - entry = self.manager.function.entry + entry = self.function.entry self.visited = OrderedSet() self._visit(entry) diff --git a/vyper/venom/venom_to_assembly.py b/vyper/venom/venom_to_assembly.py index 20b448c91c..d3c6d0bcf1 100644 --- a/vyper/venom/venom_to_assembly.py +++ b/vyper/venom/venom_to_assembly.py @@ -1,6 +1,8 @@ from collections import Counter from typing import Any +from vyper.venom.analysis.analysis import IRAnalysesCache + from vyper.exceptions import CompilerPanic, StackTooDeep from vyper.ir.compile_ir import ( PUSH, @@ -23,7 +25,6 @@ ) from vyper.venom.context import IRContext from vyper.venom.passes.normalization import NormalizationPass -from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.stack_model import StackModel # instructions which map one-to-one from venom to EVM @@ -153,11 +154,11 @@ def generate_evm(self, no_optimize: bool = False) -> list[str]: # to support the O(1) dispatcher. -> look into calculate_cfg() for ctx in self.ctxs: for fn in ctx.functions.values(): - pm = IRPassManager(fn) + ac = IRAnalysesCache(fn) - NormalizationPass(pm).run_pass() - self.liveness_analysis = pm.request_analysis(LivenessAnalysis) - pm.request_analysis(DupRequirementsAnalysis) + NormalizationPass(ac, fn).run_pass() + self.liveness_analysis = ac.request_analysis(LivenessAnalysis) + ac.request_analysis(DupRequirementsAnalysis) assert fn.normalized, "Non-normalized CFG!" From d5179427d5f900eb9279b657ff3c03c0ad688b4f Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Sat, 4 May 2024 01:15:29 +0300 Subject: [PATCH 06/10] lint --- vyper/venom/__init__.py | 3 +-- vyper/venom/analysis/dfg.py | 3 +-- vyper/venom/passes/sccp/sccp.py | 6 +++--- vyper/venom/venom_to_assembly.py | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/vyper/venom/__init__.py b/vyper/venom/__init__.py index b8b4f787fe..4e13a220ef 100644 --- a/vyper/venom/__init__.py +++ b/vyper/venom/__init__.py @@ -3,10 +3,9 @@ from typing import Optional -from vyper.venom.analysis.analysis import IRAnalysesCache - from vyper.codegen.ir_node import IRnode from vyper.compiler.settings import OptimizationLevel +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.analysis.liveness import LivenessAnalysis from vyper.venom.context import IRContext from vyper.venom.function import IRFunction diff --git a/vyper/venom/analysis/dfg.py b/vyper/venom/analysis/dfg.py index 36a9e04702..8b113e74bc 100644 --- a/vyper/venom/analysis/dfg.py +++ b/vyper/venom/analysis/dfg.py @@ -1,9 +1,8 @@ from typing import Optional -from vyper.venom.function import IRFunction - from vyper.venom.analysis.analysis import IRAnalysesCache, IRAnalysis from vyper.venom.basicblock import IRInstruction, IRVariable +from vyper.venom.function import IRFunction class DFGAnalysis(IRAnalysis): diff --git a/vyper/venom/passes/sccp/sccp.py b/vyper/venom/passes/sccp/sccp.py index 2aaf1f76f5..7f3fc7e03e 100644 --- a/vyper/venom/passes/sccp/sccp.py +++ b/vyper/venom/passes/sccp/sccp.py @@ -3,9 +3,9 @@ from functools import reduce from typing import Union -from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.exceptions import CompilerPanic, StaticAssertionException from vyper.utils import OrderedSet +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.analysis.cfg import CFGAnalysis from vyper.venom.analysis.dominators import DominatorTreeAnalysis from vyper.venom.basicblock import ( @@ -59,8 +59,8 @@ class SCCP(IRPass): cfg_dirty: bool cfg_in_exec: dict[IRBasicBlock, OrderedSet[IRBasicBlock]] - def __init__(self, function: IRFunction, analyses_cache: IRAnalysesCache): - super().__init__(function, analyses_cache) + def __init__(self, analyses_cache: IRAnalysesCache, function: IRFunction): + super().__init__(analyses_cache, function) self.lattice = {} self.work_list: list[WorkListItem] = [] self.cfg_dirty = False diff --git a/vyper/venom/venom_to_assembly.py b/vyper/venom/venom_to_assembly.py index d3c6d0bcf1..1274b94b5c 100644 --- a/vyper/venom/venom_to_assembly.py +++ b/vyper/venom/venom_to_assembly.py @@ -1,8 +1,6 @@ from collections import Counter from typing import Any -from vyper.venom.analysis.analysis import IRAnalysesCache - from vyper.exceptions import CompilerPanic, StackTooDeep from vyper.ir.compile_ir import ( PUSH, @@ -13,6 +11,7 @@ optimize_assembly, ) from vyper.utils import MemoryPositions, OrderedSet +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.analysis.dup_requirements import DupRequirementsAnalysis from vyper.venom.analysis.liveness import LivenessAnalysis from vyper.venom.basicblock import ( From a8176b9a6463f6078a01ebd18c7dfb8cd034ec63 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Sat, 4 May 2024 01:16:42 +0300 Subject: [PATCH 07/10] fix doc --- vyper/venom/analysis/analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/venom/analysis/analysis.py b/vyper/venom/analysis/analysis.py index 670cd67d09..13e8c3182d 100644 --- a/vyper/venom/analysis/analysis.py +++ b/vyper/venom/analysis/analysis.py @@ -31,7 +31,7 @@ def invalidate(self): class IRAnalysesCache: """ - Manages the analysis and passes for the Venom IR. + A cache for IR analyses. """ function: IRFunction From ba87704314157c2d0d7beddd79ad32b4f53bfe91 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Sat, 4 May 2024 01:26:39 +0300 Subject: [PATCH 08/10] update tests --- .../compiler/venom/test_dominator_tree.py | 10 +++---- tests/unit/compiler/venom/test_make_ssa.py | 6 ++--- .../compiler/venom/test_multi_entry_block.py | 20 +++++++------- tests/unit/compiler/venom/test_sccp.py | 26 +++++++++---------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/unit/compiler/venom/test_dominator_tree.py b/tests/unit/compiler/venom/test_dominator_tree.py index 54c2605c63..29f86df221 100644 --- a/tests/unit/compiler/venom/test_dominator_tree.py +++ b/tests/unit/compiler/venom/test_dominator_tree.py @@ -2,12 +2,12 @@ from vyper.exceptions import CompilerPanic from vyper.utils import OrderedSet +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.analysis.dominators import DominatorTreeAnalysis from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRLabel, IRLiteral, IRVariable from vyper.venom.context import IRContext from vyper.venom.function import IRFunction from vyper.venom.passes.make_ssa import MakeSSA -from vyper.venom.passes.pass_manager import IRPassManager def _add_bb( @@ -49,8 +49,8 @@ def test_deminator_frontier_calculation(): fn = _make_test_ctx() bb1, bb2, bb3, bb4, bb5, bb6, bb7 = [fn.get_basic_block(str(i)) for i in range(1, 8)] - pm = IRPassManager(fn) - dom = pm.request_analysis(DominatorTreeAnalysis) + ac = IRAnalysesCache(fn) + dom = ac.request_analysis(DominatorTreeAnalysis) df = dom.dominator_frontiers assert len(df[bb1]) == 0, df[bb1] @@ -71,5 +71,5 @@ def test_phi_placement(): bb2.insert_instruction(IRInstruction("add", [x, IRLiteral(1)], x), 0) bb7.insert_instruction(IRInstruction("mstore", [x, IRLiteral(0)]), 0) - pm = IRPassManager(fn) - MakeSSA(pm).run_pass() + ac = IRAnalysesCache(fn) + MakeSSA(ac, fn).run_pass() diff --git a/tests/unit/compiler/venom/test_make_ssa.py b/tests/unit/compiler/venom/test_make_ssa.py index fd4b7d15b9..9cea1a20a4 100644 --- a/tests/unit/compiler/venom/test_make_ssa.py +++ b/tests/unit/compiler/venom/test_make_ssa.py @@ -1,7 +1,7 @@ +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.basicblock import IRBasicBlock, IRLabel from vyper.venom.context import IRContext from vyper.venom.passes.make_ssa import MakeSSA -from vyper.venom.passes.pass_manager import IRPassManager def test_phi_case(): @@ -31,8 +31,8 @@ def test_phi_case(): bb.append_instruction("jmp", bb_cont.label) - pm = IRPassManager(fn) - MakeSSA(pm).run_pass() + ac = IRAnalysesCache(fn) + MakeSSA(ac, fn).run_pass() condition_block = fn.get_basic_block("condition") assert len(condition_block.instructions) == 2 diff --git a/tests/unit/compiler/venom/test_multi_entry_block.py b/tests/unit/compiler/venom/test_multi_entry_block.py index 17528557e1..313fbb3ebd 100644 --- a/tests/unit/compiler/venom/test_multi_entry_block.py +++ b/tests/unit/compiler/venom/test_multi_entry_block.py @@ -1,8 +1,8 @@ +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.analysis.cfg import CFGAnalysis from vyper.venom.context import IRContext from vyper.venom.function import IRBasicBlock, IRLabel from vyper.venom.passes.normalization import NormalizationPass -from vyper.venom.passes.pass_manager import IRPassManager def test_multi_entry_block_1(): @@ -34,11 +34,11 @@ def test_multi_entry_block_1(): fn.append_basic_block(finish_bb) finish_bb.append_instruction("stop") - pm = IRPassManager(fn) - pm.request_analysis(CFGAnalysis) + ac = IRAnalysesCache(fn) + ac.request_analysis(CFGAnalysis) assert not fn.normalized, "CFG should not be normalized" - NormalizationPass(pm).run_pass() + NormalizationPass(ac, fn).run_pass() assert fn.normalized, "CFG should be normalized" @@ -88,11 +88,11 @@ def test_multi_entry_block_2(): fn.append_basic_block(finish_bb) finish_bb.append_instruction("stop") - pm = IRPassManager(fn) - pm.request_analysis(CFGAnalysis) + ac = IRAnalysesCache(fn) + ac.request_analysis(CFGAnalysis) assert not fn.normalized, "CFG should not be normalized" - NormalizationPass(pm).run_pass() + NormalizationPass(ac, fn).run_pass() assert fn.normalized, "CFG should be normalized" @@ -132,11 +132,11 @@ def test_multi_entry_block_with_dynamic_jump(): fn.append_basic_block(finish_bb) finish_bb.append_instruction("stop") - pm = IRPassManager(fn) - pm.request_analysis(CFGAnalysis) + ac = IRAnalysesCache(fn) + ac.request_analysis(CFGAnalysis) assert not fn.normalized, "CFG should not be normalized" - NormalizationPass(pm).run_pass() + NormalizationPass(ac, fn).run_pass() assert fn.normalized, "CFG should be normalized" finish_bb = fn.get_basic_block(finish_label.value) diff --git a/tests/unit/compiler/venom/test_sccp.py b/tests/unit/compiler/venom/test_sccp.py index 62f490d343..37a8bc9000 100644 --- a/tests/unit/compiler/venom/test_sccp.py +++ b/tests/unit/compiler/venom/test_sccp.py @@ -1,7 +1,7 @@ +from vyper.venom.analysis.analysis import IRAnalysesCache from vyper.venom.basicblock import IRBasicBlock, IRLabel, IRVariable from vyper.venom.context import IRContext from vyper.venom.passes.make_ssa import MakeSSA -from vyper.venom.passes.pass_manager import IRPassManager from vyper.venom.passes.sccp import SCCP from vyper.venom.passes.sccp.sccp import LatticeEnum @@ -17,9 +17,9 @@ def test_simple_case(): op3 = bb.append_instruction("add", op1, op2) bb.append_instruction("return", p1, op3) - pm = IRPassManager(fn) - MakeSSA(pm).run_pass() - sccp = SCCP(pm) + ac = IRAnalysesCache(fn) + MakeSSA(ac, fn).run_pass() + sccp = SCCP(ac, fn) sccp.run_pass() assert sccp.lattice[IRVariable("%1")] == LatticeEnum.BOTTOM @@ -50,9 +50,9 @@ def test_cont_jump_case(): br2.append_instruction("add", op3, p1) br2.append_instruction("stop") - pm = IRPassManager(fn) - MakeSSA(pm).run_pass() - sccp = SCCP(pm) + ac = IRAnalysesCache(fn) + MakeSSA(ac, fn).run_pass() + sccp = SCCP(ac, fn) sccp.run_pass() assert sccp.lattice[IRVariable("%1")] == LatticeEnum.BOTTOM @@ -89,9 +89,9 @@ def test_cont_phi_case(): join.append_instruction("return", op4, p1) - pm = IRPassManager(fn) - MakeSSA(pm).run_pass() - sccp = SCCP(pm) + ac = IRAnalysesCache(fn) + MakeSSA(ac, fn).run_pass() + sccp = SCCP(ac, fn) sccp.run_pass() assert sccp.lattice[IRVariable("%1")] == LatticeEnum.BOTTOM @@ -129,9 +129,9 @@ def test_cont_phi_const_case(): join.append_instruction("return", op4, p1) - pm = IRPassManager(fn) - MakeSSA(pm).run_pass() - sccp = SCCP(pm) + ac = IRAnalysesCache(fn) + MakeSSA(ac, fn).run_pass() + sccp = SCCP(ac, fn) sccp.run_pass() assert sccp.lattice[IRVariable("%1")].value == 1 From c65592ce13ec736053bfcde439087c861d56507f Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Sat, 4 May 2024 01:28:03 +0300 Subject: [PATCH 09/10] remove leftout imports --- vyper/venom/analysis/analysis.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vyper/venom/analysis/analysis.py b/vyper/venom/analysis/analysis.py index 13e8c3182d..f154993925 100644 --- a/vyper/venom/analysis/analysis.py +++ b/vyper/venom/analysis/analysis.py @@ -46,8 +46,6 @@ def request_analysis(self, analysis_cls: Type[IRAnalysis], *args, **kwargs): Request a specific analysis to be run on the IR. The result is cached and returned if the analysis has already been run. """ - from vyper.venom.analysis.analysis import IRAnalysis - assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" if analysis_cls in self.analyses_cache: return self.analyses_cache[analysis_cls] @@ -61,8 +59,6 @@ def invalidate_analysis(self, analysis_cls: Type[IRAnalysis]): """ Invalidate a specific analysis. This will remove the analysis from the cache. """ - from vyper.venom.analysis.analysis import IRAnalysis - assert issubclass(analysis_cls, IRAnalysis), f"{analysis_cls} is not an IRAnalysis" analysis = self.analyses_cache.pop(analysis_cls, None) if analysis is not None: From 208a23e78a954ab61356d42a019ac88fed8281f0 Mon Sep 17 00:00:00 2001 From: Harry Kalogirou Date: Sat, 4 May 2024 02:00:20 +0300 Subject: [PATCH 10/10] remove comment --- vyper/venom/venom_to_assembly.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/vyper/venom/venom_to_assembly.py b/vyper/venom/venom_to_assembly.py index 1274b94b5c..26bad8882c 100644 --- a/vyper/venom/venom_to_assembly.py +++ b/vyper/venom/venom_to_assembly.py @@ -144,13 +144,6 @@ def generate_evm(self, no_optimize: bool = False) -> list[str]: asm: list[Any] = [] top_asm = asm - # Before emitting the assembly, we need to make sure that the - # CFG is normalized. Calling calculate_cfg() will denormalize IR (reset) - # so it should not be called after calling NormalizationPass().run_pass(). - # Liveness is then computed for the normalized IR, and we can proceed to - # assembly generation. - # This is a side-effect of how dynamic jumps are temporarily being used - # to support the O(1) dispatcher. -> look into calculate_cfg() for ctx in self.ctxs: for fn in ctx.functions.values(): ac = IRAnalysesCache(fn)