alan-baker | 06cad65 | 2019-12-03 17:56:47 -0500 | [diff] [blame] | 1 | // Copyright 2019 The Clspv Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include <deque> |
| 16 | |
| 17 | #include "llvm/ADT/DenseSet.h" |
| 18 | #include "llvm/Analysis/LoopInfo.h" |
| 19 | #include "llvm/IR/BasicBlock.h" |
| 20 | #include "llvm/IR/Dominators.h" |
| 21 | |
| 22 | namespace clspv { |
| 23 | |
| 24 | // Produce structured sorting from |block| into |order|. |
| 25 | // |
| 26 | // This order has the following properties: |
| 27 | // * dominators come before all blocks they dominate |
| 28 | // * a merge block follows all blocks that are in control constructs of the |
| 29 | // associated header |
| 30 | // * blocks in a loop construct precede the blocks in the associated continue |
| 31 | // construct |
| 32 | // * no interleaving; blocks in one construct A are mixed with blocks in |
| 33 | // another construct B only if one is nested inside the other (without loss |
| 34 | // of generality, A's header dominates all blocks in B, and all B's blocks |
| 35 | // appear contiguously within A's blocks) |
| 36 | void ComputeStructuredOrder(llvm::BasicBlock *block, llvm::DominatorTree *DT, |
| 37 | const llvm::LoopInfo &LI, |
| 38 | std::deque<llvm::BasicBlock *> *order, |
| 39 | llvm::DenseSet<llvm::BasicBlock *> *visited); |
| 40 | } // namespace clspv |