11#include "llvm/Support/Casting.h"
16using namespace threadSafety;
51SExpr* Future::force() {
59 unsigned Idx = Predecessors.
size();
62 for (
auto *
E : Args) {
63 if (
auto *Ph = dyn_cast<Phi>(
E)) {
64 Ph->values().reserveCheck(1, Arena);
65 Ph->values().push_back(
nullptr);
72 Predecessors.
reserve(NumPreds, Arena);
73 for (
auto *
E : Args) {
74 if (
auto *Ph = dyn_cast<Phi>(
E)) {
75 Ph->values().reserve(NumPreds, Arena);
84 if (
const auto *
V = dyn_cast<Variable>(
E)) {
90 if (
const auto *Ph = dyn_cast<Phi>(
E)) {
106 if (
auto *
V = dyn_cast<Variable>(
E)) {
117 if (
auto *Ph = dyn_cast<Phi>(
E)) {
140 for (
unsigned i = 1, n = Ph->
values().
size(); i < n; ++i) {
152unsigned BasicBlock::renumberInstrs(
unsigned ID) {
153 for (
auto *Arg : Args)
154 Arg->setID(
this, ID++);
155 for (
auto *Instr : Instrs)
156 Instr->setID(
this, ID++);
157 TermInstr->
setID(
this, ID++);
167 if (Visited)
return ID;
170 ID =
Block->topologicalSort(Blocks, ID);
175 Blocks[BlockID] =
this;
193 if (!Visited)
return ID;
196 ID = DominatorNode.
Parent->topologicalFinalSort(Blocks, ID);
197 for (
auto *Pred : Predecessors)
198 ID = Pred->topologicalFinalSort(Blocks, ID);
199 assert(
static_cast<size_t>(ID) < Blocks.
size());
201 Blocks[BlockID] =
this;
208void BasicBlock::computeDominator() {
211 for (
auto *Pred : Predecessors) {
213 if (Pred->BlockID >= BlockID)
continue;
215 if (Candidate ==
nullptr) {
220 auto *Alternate = Pred;
221 while (Alternate != Candidate) {
222 if (Candidate->BlockID > Alternate->BlockID)
223 Candidate = Candidate->DominatorNode.
Parent;
225 Alternate = Alternate->DominatorNode.
Parent;
228 DominatorNode.
Parent = Candidate;
235void BasicBlock::computePostDominator() {
240 if (Succ->BlockID <= BlockID)
continue;
242 if (Candidate ==
nullptr) {
247 auto *Alternate = Succ;
248 while (Alternate != Candidate) {
249 if (Candidate->BlockID < Alternate->BlockID)
250 Candidate = Candidate->PostDominatorNode.
Parent;
252 Alternate = Alternate->PostDominatorNode.
Parent;
255 PostDominatorNode.
Parent = Candidate;
260void SCFG::renumberInstrs() {
261 unsigned InstrID = 0;
262 for (
auto *
Block : Blocks)
263 InstrID =
Block->renumberInstrs(InstrID);
292 unsigned NumUnreachableBlocks = Entry->topologicalSort(Blocks, Blocks.size());
293 if (NumUnreachableBlocks > 0) {
295 for (
unsigned I = NumUnreachableBlocks,
E = Blocks.size(); I <
E; ++I) {
296 unsigned NI = I - NumUnreachableBlocks;
297 Blocks[NI] = Blocks[I];
298 Blocks[NI]->BlockID = NI;
301 Blocks.drop(NumUnreachableBlocks);
305 for (
auto *
Block : Blocks)
306 Block->computeDominator();
309 unsigned NumBlocks = Exit->topologicalFinalSort(Blocks, 0);
310 assert(
static_cast<size_t>(NumBlocks) == Blocks.size());
318 for (
auto *
Block : Blocks.reverse()) {
319 Block->computePostDominator();
324 for (
auto *
Block : Blocks) {
329 for (
auto *
Block : Blocks.reverse()) {
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static void computeNodeSize(BasicBlock *B, BasicBlock::TopologyNode BasicBlock::*TN)
static void computeNodeID(BasicBlock *B, BasicBlock::TopologyNode BasicBlock::*TN)
A basic block is part of an SCFG.
unsigned addPredecessor(BasicBlock *Pred)
ArrayRef< BasicBlock * > successors()
void reservePredecessors(unsigned NumPreds)
virtual SExpr * compute()
Phi Node, for code in SSA form.
const ValArray & values() const
Base class for AST nodes in the typed intermediate language.
void setID(BasicBlock *B, unsigned id)
Set the basic block and instruction ID for this expression.
void reserve(size_t Ncp, MemRegionRef A)
void push_back(const T &Elem)
void reserveCheck(size_t N, MemRegionRef A)
bool isTrivial(const SExpr *E)
TIL_UnaryOpcode
Opcode for unary arithmetic operations.
void simplifyIncompleteArg(til::Phi *Ph)
StringRef getBinaryOpcodeString(TIL_BinaryOpcode Op)
Return the name of a binary opcode.
StringRef getUnaryOpcodeString(TIL_UnaryOpcode Op)
Return the name of a unary opcode.
TIL_BinaryOpcode
Opcode for binary arithmetic operations.
SExpr * simplifyToCanonicalVal(SExpr *E)
const SExpr * getCanonicalVal(const SExpr *E)
The JSON file list parser is used to communicate input to InstallAPI.