LLVM数据流分析的理论
LLVM數據流分析的理論
標量優(yōu)化(scalar目錄): 死代碼消除(BDCE.cpp[code],ADCE.cpp[code],DCE.cpp[code]), 全局值編號(GVN.cpp[code]), 代碼提升(ConstantHoisting.cpp[code]), 公共子表達式消除(EarlyCSE.cpp[code]), 代碼下沉(Sink.cpp[code]), 以及各種循環(huán)優(yōu)化等
過程間優(yōu)化(IPO目錄):無效參數消除(DeadArgumentElimination.cpp[code]) , 全局死代碼消除(GlobalDCE.cpp[code]), 常量傳播(IPConstantPropagation.cpp[code]), 循環(huán)外提(LoopExtractor.cpp[code]),稀疏條件常量傳播(SCCP.cpp[code]),函數合并(MergeFunctions.cpp[code])等
介紹
本文檔描述了構成 LLVM的內部軟件,不是 LLVM 的外部使用。這里沒有關于如何使用 LLVM 的說明,只有構成軟件的 API。有關使用說明,請參閱程序員指南或參考手冊。
警告
本文檔直接從帶有 doxygen 的源代碼生成。由于 LLVM 一直在積極開發(fā)中,可能仍然有用,因為 LLVM 的某些部分非常穩(wěn)定。
Transforms Directory Reference
AggressiveInstCombine.cpp File Reference
#include “l(fā)lvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h”
#include “AggressiveInstCombineInternal.h”
#include “l(fā)lvm-c/Initialization.h”
#include “l(fā)lvm-c/Transforms/AggressiveInstCombine.h”
#include “l(fā)lvm/ADT/Statistic.h”
#include “l(fā)lvm/Analysis/AliasAnalysis.h”
#include “l(fā)lvm/Analysis/AssumptionCache.h”
#include “l(fā)lvm/Analysis/BasicAliasAnalysis.h”
#include “l(fā)lvm/Analysis/GlobalsModRef.h”
#include “l(fā)lvm/Analysis/TargetLibraryInfo.h”
#include “l(fā)lvm/Analysis/ValueTracking.h”
#include “l(fā)lvm/IR/DataLayout.h”
#include “l(fā)lvm/IR/Dominators.h”
#include “l(fā)lvm/IR/Function.h”
#include “l(fā)lvm/IR/IRBuilder.h”
#include “l(fā)lvm/IR/LegacyPassManager.h”
#include “l(fā)lvm/IR/PatternMatch.h”
#include “l(fā)lvm/InitializePasses.h”
#include “l(fā)lvm/Pass.h”
#include “l(fā)lvm/Transforms/Utils/Local.h”
AggressiveInstCombineInternal.h File Reference
#include “l(fā)lvm/ADT/MapVector.h”
#include “l(fā)lvm/ADT/SmallVector.h”
#include “l(fā)lvm/Analysis/ValueTracking.h”
#include “l(fā)lvm/Support/KnownBits.h”
Include dependency graph for AggressiveInstCombineInternal.h:
CFGuard Directory Reference
Directory dependency graph for CFGuard:
CFGuard.cpp File Reference
#include “l(fā)lvm/Transforms/CFGuard.h”
#include “l(fā)lvm/ADT/SmallVector.h”
#include “l(fā)lvm/ADT/Statistic.h”
#include “l(fā)lvm/ADT/Triple.h”
#include “l(fā)lvm/IR/CallingConv.h”
#include “l(fā)lvm/IR/IRBuilder.h”
#include “l(fā)lvm/IR/Instruction.h”
#include “l(fā)lvm/InitializePasses.h”
#include “l(fā)lvm/Pass.h”
Include dependency graph for CFGuard.cpp:
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/llvm/include/llvm/ADT/ilist_node.h
侵入式列表節(jié)點。用于啟用侵入式列表成員資格的基類,包括simple_ilist、iplist和ilist。第一個模板參數是列表的value_type。
可以使用編譯時,選項配置 ilist 節(jié)點,更改行為和/或添加 API。
默認情況下,當且僅當 LLVM_ENABLE_ABI_BREAKING_CHECKS 時,ilist_node 才知道是否是列表監(jiān)測(ilist_sentinel的實例)。函數isKnownSentinel()總是返回false跟蹤關閉。Sentinel 跟蹤從“prev”鏈接中竊取了一點,在遞減迭代器時,添加了掩碼操作,但在ilist_iterator 中啟用了錯誤查找斷言。
要始終打開監(jiān)測跟蹤,請傳入 ilist_sentinel_tracking 模板參數。這也啟用了isSentinel()函數。必須將相同的選項傳遞給侵入式列表。( ilist_sentinel_tracking 始終關閉監(jiān)測跟蹤。)
通過傳入不同的ilist_tag選項,一個類型可以多次從 ilist_node 繼承。這允許將單個實例同時插入到多個列表中,其中每個列表都被賦予相同的標簽。
struct A {}; struct B {}; struct N : ilist_node<N, ilist_tag>, ilist_node<N, ilist_tag> {};
void foo() { simple_ilist<N, ilist_tag> ListA; simple_ilist<N, ilist_tag> ListB; N N1; ListA.push_back(N1); ListB.push_back(N1); } \endexample
See is_valid_option for steps on adding a new option.
//=- llvm/ADT/ilist_node.h - Intrusive Linked List Helper ------ C++ --=//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//=----------------------------------------------------------------------=//
//
// This file defines the ilist_node class template, which is a convenient
// base class for creating classes that can be used with ilists.
//
//=----------------------------------------------------------------------=//
#ifndef LLVM_ADT_ILIST_NODE_H
#define LLVM_ADT_ILIST_NODE_H
#include “l(fā)lvm/ADT/ilist_node_base.h”
#include “l(fā)lvm/ADT/ilist_node_options.h”
namespace llvm {
namespace ilist_detail {
struct NodeAccess;
} // end namespace ilist_detail
template <class OptionsT, bool IsReverse, bool IsConst> class ilist_iterator;
template class ilist_sentinel;
/// Implementation for an ilist node.
///
/// Templated on an appropriate \a ilist_detail::node_options, usually computed
/// by \a ilist_detail::compute_node_options.
///
/// This is a wrapper around \a ilist_node_base whose main purpose is to
/// provide type safety: you can’t insert nodes of \a ilist_node_impl into the
/// wrong \a simple_ilist or \a iplist.
template class ilist_node_impl : OptionsT::node_base_type {
using value_type = typename OptionsT::value_type;
using node_base_type = typename OptionsT::node_base_type;
using list_base_type = typename OptionsT::list_base_type;
friend typename OptionsT::list_base_type;
friend struct ilist_detail::NodeAccess;
friend class ilist_sentinel;
friend class ilist_iterator<OptionsT, false, false>;
friend class ilist_iterator<OptionsT, false, true>;
friend class ilist_iterator<OptionsT, true, false>;
friend class ilist_iterator<OptionsT, true, true>;
protected:
using self_iterator = ilist_iterator<OptionsT, false, false>;
using const_self_iterator = ilist_iterator<OptionsT, false, true>;
using reverse_self_iterator = ilist_iterator<OptionsT, true, false>;
using const_reverse_self_iterator = ilist_iterator<OptionsT, true, true>;
ilist_node_impl() = default;
private:
ilist_node_impl *getPrev() {
return static_cast<ilist_node_impl *>(node_base_type::getPrev());
}
ilist_node_impl *getNext() {
return static_cast<ilist_node_impl *>(node_base_type::getNext());
}
const ilist_node_impl *getPrev() const {
return static_cast<ilist_node_impl *>(node_base_type::getPrev());
}
const ilist_node_impl *getNext() const {
return static_cast<ilist_node_impl *>(node_base_type::getNext());
}
void setPrev(ilist_node_impl *N) { node_base_type::setPrev(N); }
void setNext(ilist_node_impl *N) { node_base_type::setNext(N); }
public:
self_iterator getIterator() { return self_iterator(*this); }
const_self_iterator getIterator() const { return const_self_iterator(*this); }
reverse_self_iterator getReverseIterator() {
return reverse_self_iterator(*this);
}
const_reverse_self_iterator getReverseIterator() const {
return const_reverse_self_iterator(*this);
}
// Under-approximation, but always available for assertions.
using node_base_type::isKnownSentinel;
/// Check whether this is the sentinel node.
///
/// This requires sentinel tracking to be explicitly enabled. Use the
/// ilist_sentinel_tracking option to get this API.
bool isSentinel() const {
static_assert(OptionsT::is_sentinel_tracking_explicit,
“Use ilist_sentinel_tracking to enable isSentinel()”);
return node_base_type::isSentinel();
}
};
/// An intrusive list node.
///
/// A base class to enable membership in intrusive lists, including \a
/// simple_ilist, \a iplist, and \a ilist. The first template parameter is the
/// \a value_type for the list.
///
/// An ilist node can be configured with compile-time options to change
/// behaviour and/or add API.
///
/// By default, an \a ilist_node knows whether it is the list sentinel (an
/// instance of \a ilist_sentinel) if and only if
/// LLVM_ENABLE_ABI_BREAKING_CHECKS. The function \a isKnownSentinel() always
/// returns \c false tracking is off. Sentinel tracking steals a bit from the
/// “prev” link, which adds a mask operation when decrementing an iterator, but
/// enables bug-finding assertions in \a ilist_iterator.
///
/// To turn sentinel tracking on all the time, pass in the
/// ilist_sentinel_tracking template parameter. This also enables the \a
/// isSentinel() function. The same option must be passed to the intrusive
/// list. (ilist_sentinel_tracking turns sentinel tracking off all the
/// time.)
///
/// A type can inherit from ilist_node multiple times by passing in different
/// \a ilist_tag options. This allows a single instance to be inserted into
/// multiple lists simultaneously, where each list is given the same tag.
///
/// \example
/// struct A {};
/// struct B {};
/// struct N : ilist_node<N, ilist_tag>, ilist_node<N, ilist_tag> {};
///
/// void foo() {
/// simple_ilist<N, ilist_tag> ListA;
/// simple_ilist<N, ilist_tag> ListB;
/// N N1;
/// ListA.push_back(N1);
/// ListB.push_back(N1);
/// }
/// \endexample
///
/// See \a is_valid_option for steps on adding a new option.
template <class T, class… Options>
class ilist_node
: public ilist_node_impl<
typename ilist_detail::compute_node_options<T, Options…>::type> {
static_assert(ilist_detail::check_options<Options…>::value,
“Unrecognized node option!”);
};
namespace ilist_detail {
/// An access class for ilist_node private API.
///
/// This gives access to the private parts of ilist nodes. Nodes for an ilist
/// should friend this class if they inherit privately from ilist_node.
///
/// Using this class outside of the ilist implementation is unsupported.
struct NodeAccess {
protected:
template
static ilist_node_impl *getNodePtr(typename OptionsT::pointer N) {
return N;
}
template
static const ilist_node_impl *
getNodePtr(typename OptionsT::const_pointer N) {
return N;
}
template
static typename OptionsT::pointer getValuePtr(ilist_node_impl *N) {
return static_cast(N);
}
template
static typename OptionsT::const_pointer
getValuePtr(const ilist_node_impl *N) {
return static_cast(N);
}
template
static ilist_node_impl *getPrev(ilist_node_impl &N) {
return N.getPrev();
}
template
static ilist_node_impl *getNext(ilist_node_impl &N) {
return N.getNext();
}
template
static const ilist_node_impl *
getPrev(const ilist_node_impl &N) {
return N.getPrev();
}
template
static const ilist_node_impl *
getNext(const ilist_node_impl &N) {
return N.getNext();
}
};
template struct SpecificNodeAccess : NodeAccess {
protected:
using pointer = typename OptionsT::pointer;
using const_pointer = typename OptionsT::const_pointer;
using node_type = ilist_node_impl;
static node_type *getNodePtr(pointer N) {
return NodeAccess::getNodePtr(N);
}
static const node_type *getNodePtr(const_pointer N) {
return NodeAccess::getNodePtr(N);
}
static pointer getValuePtr(node_type *N) {
return NodeAccess::getValuePtr(N);
}
static const_pointer getValuePtr(const node_type *N) {
return NodeAccess::getValuePtr(N);
}
};
} // end namespace ilist_detail
template
class ilist_sentinel : public ilist_node_impl {
public:
ilist_sentinel() {
this->initializeSentinel();
reset();
}
void reset() {
this->setPrev(this);
this->setNext(this);
}
bool empty() const { return this == this->getPrev(); }
};
/// An ilist node that can access its parent list.
///
/// Requires \c NodeTy to have \a getParent() to find the parent node, and the
/// \c ParentTy to have \a getSublistAccess() to get a reference to the list.
template <typename NodeTy, typename ParentTy, class… Options>
class ilist_node_with_parent : public ilist_node<NodeTy, Options…> {
protected:
ilist_node_with_parent() = default;
private:
/// Forward to NodeTy::getParent().
///
/// Note: do not use the name “getParent()”. We want a compile error
/// (instead of recursion) when the subclass fails to implement \a
/// getParent().
const ParentTy *getNodeParent() const {
return static_cast<const NodeTy *>(this)->getParent();
}
public:
/// @name Adjacent Node Accessors
/// @{
/// Get the previous node, or \c nullptr for the list head.
NodeTy getPrevNode() {
// Should be separated to a reused function, but then we couldn’t use auto
// (and would need the type of the list).
const auto &List =
getNodeParent()->(ParentTy::getSublistAccess((NodeTy *)nullptr));
return List.getPrevNode(*static_cast<NodeTy *>(this));
}
/// Get the previous node, or \c nullptr for the list head.
const NodeTy *getPrevNode() const {
return const_cast<ilist_node_with_parent *>(this)->getPrevNode();
}
/// Get the next node, or \c nullptr for the list tail.
NodeTy getNextNode() {
// Should be separated to a reused function, but then we couldn’t use auto
// (and would need the type of the list).
const auto &List =
getNodeParent()->(ParentTy::getSublistAccess((NodeTy *)nullptr));
return List.getNextNode(*static_cast<NodeTy *>(this));
}
/// Get the next node, or \c nullptr for the list tail.
const NodeTy *getNextNode() const {
return const_cast<ilist_node_with_parent *>(this)->getNextNode();
}
/// @}
};
} // end namespace llvm
#endif // LLVM_ADT_ILIST_NODE_H
參考鏈接:
https://www.zhihu.com/question/41123019
https://llvm.org/doxygen/index.html
總結
以上是生活随笔為你收集整理的LLVM数据流分析的理论的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LLVM一些编程语法语义特性
- 下一篇: C++高级编程总结