44 return TargetToValue.
lookup(BI->getSuccessor());
47 Builder.SetInsertPoint(
T);
53 if (
LHS ==
nullptr ||
RHS ==
nullptr)
55 return Builder.CreateSelect(BI->getCondition(),
LHS,
RHS);
71static bool runOnConvergenceRegionNoRecurse(
LoopInfo &LI,
83 if (ExitTargets.
size() <= 1)
92 F->begin()->getFirstInsertionPt());
97 std::vector<BasicBlock *> SortedExitTargets;
98 std::vector<BasicBlock *> SortedExits;
100 if (ExitTargets.
count(&BB) != 0)
101 SortedExitTargets.push_back(&BB);
102 if (CR->
Exits.count(&BB) != 0)
103 SortedExits.push_back(&BB);
111 std::make_pair(
Target, Builder.getInt32(TargetToValue.
size())));
115 std::vector<std::pair<BasicBlock *, Value *>> ExitToVariable;
116 for (
auto Exit : SortedExits) {
119 B2.SetInsertPoint(
Exit->getFirstInsertionPt());
120 B2.CreateStore(
Value, Variable);
121 ExitToVariable.emplace_back(std::make_pair(Exit,
Value));
124 llvm::Value *
Load = Builder.CreateLoad(Builder.getInt32Ty(), Variable);
128 SortedExitTargets.size() - 1);
129 for (
size_t i = 1; i < SortedExitTargets.size(); i++) {
131 Sw->
addCase(TargetToValue[BB], BB);
135 for (
auto Exit : CR->
Exits) {
139 I.getUse()->set(NewExitTarget);
156 if (runOnConvergenceRegion(LI, Child))
159 return runOnConvergenceRegionNoRecurse(LI, CR);
167 validateRegionExits(Child);
169 std::unordered_set<BasicBlock *> ExitTargets;
170 for (
auto *Exit : CR->
Exits) {
173 ExitTargets.insert(BB);
177 assert(ExitTargets.size() <= 1);
183 auto *TopLevelRegion =
RegionInfo.getWritableTopLevelRegion();
190 while (runOnConvergenceRegion(LI, TopLevelRegion)) {
194#if !defined(NDEBUG) || defined(EXPENSIVE_CHECKS)
195 validateRegionExits(TopLevelRegion);
200class SPIRVMergeRegionExitTargetsLegacy :
public FunctionPass {
204 SPIRVMergeRegionExitTargetsLegacy() : FunctionPass(ID) {}
207 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
208 auto &RegionInfo = getAnalysis<SPIRVConvergenceRegionAnalysisWrapperPass>()
213 void getAnalysisUsage(AnalysisUsage &AU)
const override {
216 AU.
addRequired<SPIRVConvergenceRegionAnalysisWrapperPass>();
218 AU.
addPreserved<SPIRVConvergenceRegionAnalysisWrapperPass>();
219 FunctionPass::getAnalysisUsage(AU);
232char SPIRVMergeRegionExitTargetsLegacy::ID = 0;
235 "split-region-exit-blocks",
236 "SPIRV split region exit blocks",
false,
false)
243 "split-region-exit-blocks",
247 return new SPIRVMergeRegionExitTargetsLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
static bool runImpl(Function &F, const TargetLowering &TLI, const LibcallLoweringInfo &Libcalls, AssumptionCache *AC)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallPtrSet class.
an instruction to allocate memory on the stack
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
A parsed version of the target data layout string in and methods for querying it.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Legacy analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Analysis pass that exposes the LoopInfo for a function.
The legacy pass manager's analysis pass to compute loop information.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
SmallVector< ConvergenceRegion * > Children
SmallPtrSet< BasicBlock *, 2 > Exits
ConvergenceRegion * Parent
SmallPtrSet< BasicBlock *, 8 > Blocks
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
FunctionPass * createSPIRVMergeRegionExitTargetsPass()
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.