Path: blob/main/contrib/llvm-project/clang/lib/Analysis/PostOrderCFGView.cpp
35233 views
//===- PostOrderCFGView.cpp - Post order view of CFG blocks ---------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements post order view of the blocks in a CFG.9//10//===----------------------------------------------------------------------===//1112#include "clang/Analysis/Analyses/PostOrderCFGView.h"13#include "clang/Analysis/AnalysisDeclContext.h"14#include "clang/Analysis/CFG.h"1516using namespace clang;1718void PostOrderCFGView::anchor() {}1920PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {21Blocks.reserve(cfg->getNumBlockIDs());22CFGBlockSet BSet(cfg);2324for (po_iterator I = po_iterator::begin(cfg, BSet),25E = po_iterator::end(cfg, BSet); I != E; ++I) {26BlockOrder[*I] = Blocks.size() + 1;27Blocks.push_back(*I);28}29}3031std::unique_ptr<PostOrderCFGView>32PostOrderCFGView::create(AnalysisDeclContext &ctx) {33const CFG *cfg = ctx.getCFG();34if (!cfg)35return nullptr;36return std::make_unique<PostOrderCFGView>(cfg);37}3839const void *PostOrderCFGView::getTag() { static int x; return &x; }4041bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,42const CFGBlock *b2) const {43PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);44PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);4546unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;47unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;48return b1V > b2V;49}505152