#include "llvm/Transforms/Scalar/StructurizeCFG.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/RegionIterator.h"
#include "llvm/Analysis/RegionPass.h"
#include "llvm/Analysis/UniformityAnalysis.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include <algorithm>
#include <cassert>
#include <utility>
usingnamespacellvm;
usingnamespacellvm::PatternMatch;
#define DEBUG_TYPE …
const char FlowBlockName[] = …;
namespace {
static cl::opt<bool> ForceSkipUniformRegions(
"structurizecfg-skip-uniform-regions",
cl::Hidden,
cl::desc("Force whether the StructurizeCFG pass skips uniform regions"),
cl::init(false));
static cl::opt<bool>
RelaxedUniformRegions("structurizecfg-relaxed-uniform-regions", cl::Hidden,
cl::desc("Allow relaxed uniform region checks"),
cl::init(true));
BBValuePair;
RNVector;
BBVector;
BranchVector;
BBValueVector;
BBSet;
PhiMap;
BB2BBVecMap;
BBPhiMap;
MaybeCondBranchWeights;
class CondBranchWeights { … };
ValueWeightPair;
BBPredicates;
PredMap;
BB2BBMap;
BranchDebugLocMap;
struct SubGraphTraits { … };
class NearestCommonDominator { … };
class StructurizeCFG { … };
class StructurizeCFGLegacyPass : public RegionPass { … };
}
char StructurizeCFGLegacyPass::ID = …;
INITIALIZE_PASS_BEGIN(StructurizeCFGLegacyPass, "structurizecfg",
"Structurize the CFG", false, false)
INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(RegionInfoPass)
INITIALIZE_PASS_END(StructurizeCFGLegacyPass, "structurizecfg",
"Structurize the CFG", false, false)
void StructurizeCFG::orderNodes() { … }
void StructurizeCFG::analyzeLoops(RegionNode *N) { … }
ValueWeightPair StructurizeCFG::buildCondition(BranchInst *Term, unsigned Idx,
bool Invert) { … }
void StructurizeCFG::gatherPredicates(RegionNode *N) { … }
void StructurizeCFG::collectInfos() { … }
void StructurizeCFG::insertConditions(bool Loops) { … }
void StructurizeCFG::simplifyConditions() { … }
void StructurizeCFG::delPhiValues(BasicBlock *From, BasicBlock *To) { … }
void StructurizeCFG::addPhiValues(BasicBlock *From, BasicBlock *To) { … }
void StructurizeCFG::findUndefBlocks(
BasicBlock *PHIBlock, const SmallSet<BasicBlock *, 8> &Incomings,
SmallVector<BasicBlock *> &UndefBlks) const { … }
void StructurizeCFG::setPhiValues() { … }
void StructurizeCFG::simplifyAffectedPhis() { … }
void StructurizeCFG::killTerminator(BasicBlock *BB) { … }
void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
bool IncludeDominator) { … }
BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) { … }
BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) { … }
BasicBlock *StructurizeCFG::needPostfix(BasicBlock *Flow,
bool ExitUseAllowed) { … }
void StructurizeCFG::setPrevNode(BasicBlock *BB) { … }
bool StructurizeCFG::dominatesPredicates(BasicBlock *BB, RegionNode *Node) { … }
bool StructurizeCFG::isPredictableTrue(RegionNode *Node) { … }
void StructurizeCFG::wireFlow(bool ExitUseAllowed,
BasicBlock *LoopEnd) { … }
void StructurizeCFG::handleLoops(bool ExitUseAllowed,
BasicBlock *LoopEnd) { … }
void StructurizeCFG::createFlow() { … }
void StructurizeCFG::rebuildSSA() { … }
static bool hasOnlyUniformBranches(Region *R, unsigned UniformMDKindID,
const UniformityInfo &UA) { … }
void StructurizeCFG::init(Region *R) { … }
bool StructurizeCFG::makeUniformRegion(Region *R, UniformityInfo &UA) { … }
bool StructurizeCFG::run(Region *R, DominatorTree *DT) { … }
Pass *llvm::createStructurizeCFGPass(bool SkipUniformRegions) { … }
static void addRegionIntoQueue(Region &R, std::vector<Region *> &Regions) { … }
StructurizeCFGPass::StructurizeCFGPass(bool SkipUniformRegions_)
: … { … }
void StructurizeCFGPass::printPipeline(
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) { … }
PreservedAnalyses StructurizeCFGPass::run(Function &F,
FunctionAnalysisManager &AM) { … }