Update prebuilt Clang to match Android kernel.
Bug: 132428451
Change-Id: I8f6e2cb23f381fc0c02ddea99b867e58e925e5be
diff --git a/linux-x64/clang/include/llvm/Analysis/MustExecute.h b/linux-x64/clang/include/llvm/Analysis/MustExecute.h
index 40a0273..3ef539c 100644
--- a/linux-x64/clang/include/llvm/Analysis/MustExecute.h
+++ b/linux-x64/clang/include/llvm/Analysis/MustExecute.h
@@ -1,9 +1,8 @@
//===- MustExecute.h - Is an instruction known to execute--------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
/// \file
@@ -19,6 +18,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/EHPersonalities.h"
+#include "llvm/Analysis/InstructionPrecedenceTracking.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
@@ -45,33 +45,30 @@
/// loop were made and the info wasn't recomputed properly, the behavior of all
/// methods except for computeLoopSafetyInfo is undefined.
class LoopSafetyInfo {
- bool MayThrow = false; // The current loop contains an instruction which
- // may throw.
- bool HeaderMayThrow = false; // Same as previous, but specific to loop header
-
- /// Collect all blocks from \p CurLoop which lie on all possible paths from
- /// the header of \p CurLoop (inclusive) to BB (exclusive) into the set
- /// \p Predecessors. If \p BB is the header, \p Predecessors will be empty.
- void collectTransitivePredecessors(
- const Loop *CurLoop, const BasicBlock *BB,
- SmallPtrSetImpl<const BasicBlock *> &Predecessors) const;
-
-public:
// Used to update funclet bundle operands.
DenseMap<BasicBlock *, ColorVector> BlockColors;
- /// Returns true iff the header block of the loop for which this info is
- /// calculated contains an instruction that may throw or otherwise exit
- /// abnormally.
- bool headerMayThrow() const;
+protected:
+ /// Computes block colors.
+ void computeBlockColors(const Loop *CurLoop);
+
+public:
+ /// Returns block colors map that is used to update funclet operand bundles.
+ const DenseMap<BasicBlock *, ColorVector> &getBlockColors() const;
+
+ /// Copy colors of block \p Old into the block \p New.
+ void copyColors(BasicBlock *New, BasicBlock *Old);
+
+ /// Returns true iff the block \p BB potentially may throw exception. It can
+ /// be false-positive in cases when we want to avoid complex analysis.
+ virtual bool blockMayThrow(const BasicBlock *BB) const = 0;
/// Returns true iff any block of the loop for which this info is contains an
/// instruction that may throw or otherwise exit abnormally.
- bool anyBlockMayThrow() const;
+ virtual bool anyBlockMayThrow() const = 0;
/// Return true if we must reach the block \p BB under assumption that the
- /// loop \p CurLoop is entered and no instruction throws or otherwise exits
- /// abnormally.
+ /// loop \p CurLoop is entered.
bool allLoopPathsLeadToBlock(const Loop *CurLoop, const BasicBlock *BB,
const DominatorTree *DT) const;
@@ -80,16 +77,92 @@
/// as argument. Updates safety information in LoopSafetyInfo argument.
/// Note: This is defined to clear and reinitialize an already initialized
/// LoopSafetyInfo. Some callers rely on this fact.
- void computeLoopSafetyInfo(Loop *);
+ virtual void computeLoopSafetyInfo(const Loop *CurLoop) = 0;
+
+ /// Returns true if the instruction in a loop is guaranteed to execute at
+ /// least once (under the assumption that the loop is entered).
+ virtual bool isGuaranteedToExecute(const Instruction &Inst,
+ const DominatorTree *DT,
+ const Loop *CurLoop) const = 0;
LoopSafetyInfo() = default;
+
+ virtual ~LoopSafetyInfo() = default;
};
-/// Returns true if the instruction in a loop is guaranteed to execute at least
-/// once (under the assumption that the loop is entered).
-bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT,
- const Loop *CurLoop,
- const LoopSafetyInfo *SafetyInfo);
+
+/// Simple and conservative implementation of LoopSafetyInfo that can give
+/// false-positive answers to its queries in order to avoid complicated
+/// analysis.
+class SimpleLoopSafetyInfo: public LoopSafetyInfo {
+ bool MayThrow = false; // The current loop contains an instruction which
+ // may throw.
+ bool HeaderMayThrow = false; // Same as previous, but specific to loop header
+
+public:
+ virtual bool blockMayThrow(const BasicBlock *BB) const;
+
+ virtual bool anyBlockMayThrow() const;
+
+ virtual void computeLoopSafetyInfo(const Loop *CurLoop);
+
+ virtual bool isGuaranteedToExecute(const Instruction &Inst,
+ const DominatorTree *DT,
+ const Loop *CurLoop) const;
+
+ SimpleLoopSafetyInfo() : LoopSafetyInfo() {};
+
+ virtual ~SimpleLoopSafetyInfo() {};
+};
+
+/// This implementation of LoopSafetyInfo use ImplicitControlFlowTracking to
+/// give precise answers on "may throw" queries. This implementation uses cache
+/// that should be invalidated by calling the methods insertInstructionTo and
+/// removeInstruction whenever we modify a basic block's contents by adding or
+/// removing instructions.
+class ICFLoopSafetyInfo: public LoopSafetyInfo {
+ bool MayThrow = false; // The current loop contains an instruction which
+ // may throw.
+ // Contains information about implicit control flow in this loop's blocks.
+ mutable ImplicitControlFlowTracking ICF;
+ // Contains information about instruction that may possibly write memory.
+ mutable MemoryWriteTracking MW;
+
+public:
+ virtual bool blockMayThrow(const BasicBlock *BB) const;
+
+ virtual bool anyBlockMayThrow() const;
+
+ virtual void computeLoopSafetyInfo(const Loop *CurLoop);
+
+ virtual bool isGuaranteedToExecute(const Instruction &Inst,
+ const DominatorTree *DT,
+ const Loop *CurLoop) const;
+
+ /// Returns true if we could not execute a memory-modifying instruction before
+ /// we enter \p BB under assumption that \p CurLoop is entered.
+ bool doesNotWriteMemoryBefore(const BasicBlock *BB, const Loop *CurLoop)
+ const;
+
+ /// Returns true if we could not execute a memory-modifying instruction before
+ /// we execute \p I under assumption that \p CurLoop is entered.
+ bool doesNotWriteMemoryBefore(const Instruction &I, const Loop *CurLoop)
+ const;
+
+ /// Inform the safety info that we are planning to insert a new instruction
+ /// \p Inst into the basic block \p BB. It will make all cache updates to keep
+ /// it correct after this insertion.
+ void insertInstructionTo(const Instruction *Inst, const BasicBlock *BB);
+
+ /// Inform safety info that we are planning to remove the instruction \p Inst
+ /// from its block. It will make all cache updates to keep it correct after
+ /// this removal.
+ void removeInstruction(const Instruction *Inst);
+
+ ICFLoopSafetyInfo(DominatorTree *DT) : LoopSafetyInfo(), ICF(DT), MW(DT) {};
+
+ virtual ~ICFLoopSafetyInfo() {};
+};
}