37static bool runOnConvergenceRegionNoRecurse(
LoopInfo &LI,
49 if (ExitTargets.
size() <= 1)
62 std::vector<BasicBlock *> SortedExitTargets;
63 std::vector<BasicBlock *> SortedExits;
65 if (ExitTargets.
count(&BB) != 0)
66 SortedExitTargets.push_back(&BB);
67 if (CR->
Exits.count(&BB) != 0)
68 SortedExits.push_back(&BB);
76 std::make_pair(
Target, Builder.getInt32(TargetToValue.
size())));
80 std::vector<std::pair<BasicBlock *, Value *>> ExitToVariable;
81 for (
auto Exit : SortedExits) {
84 B2.SetInsertPoint(
Exit->getFirstInsertionPt());
85 B2.CreateStore(
Value, Variable);
86 ExitToVariable.emplace_back(std::make_pair(Exit,
Value));
93 SortedExitTargets.size() - 1);
94 for (
size_t i = 1; i < SortedExitTargets.size(); i++) {
96 Sw->
addCase(TargetToValue[BB], BB);
100 for (
auto Exit : CR->
Exits) {
104 I.getUse()->set(NewExitTarget);
121 if (runOnConvergenceRegion(LI, Child))
124 return runOnConvergenceRegionNoRecurse(LI, CR);
132 validateRegionExits(Child);
134 std::unordered_set<BasicBlock *> ExitTargets;
135 for (
auto *Exit : CR->
Exits) {
138 ExitTargets.insert(BB);
142 assert(ExitTargets.size() <= 1);
148 auto *TopLevelRegion =
RegionInfo.getWritableTopLevelRegion();
155 while (runOnConvergenceRegion(LI, TopLevelRegion)) {
159#if !defined(NDEBUG) || defined(EXPENSIVE_CHECKS)
160 validateRegionExits(TopLevelRegion);
165class SPIRVMergeRegionExitTargetsLegacy :
public FunctionPass {
169 SPIRVMergeRegionExitTargetsLegacy() : FunctionPass(ID) {}
172 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
173 auto &RegionInfo = getAnalysis<SPIRVConvergenceRegionAnalysisWrapperPass>()
178 void getAnalysisUsage(AnalysisUsage &AU)
const override {
181 AU.
addRequired<SPIRVConvergenceRegionAnalysisWrapperPass>();
183 AU.
addPreserved<SPIRVConvergenceRegionAnalysisWrapperPass>();
184 FunctionPass::getAnalysisUsage(AU);
197char SPIRVMergeRegionExitTargetsLegacy::ID = 0;
200 "split-region-exit-blocks",
201 "SPIRV split region exit blocks",
false,
false)
208 "split-region-exit-blocks",
212 return new SPIRVMergeRegionExitTargetsLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
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.
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
auto successors(const MachineBasicBlock *BB)
AllocaInst * createVariable(Function &F, Type *Type)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
Value * createExitVariable(BasicBlock *BB, const DenseMap< BasicBlock *, ConstantInt * > &TargetToValue)
FunctionPass * createSPIRVMergeRegionExitTargetsPass()
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.