24#define DEBUG_TYPE "spirv-regularizer"
36 StringRef getPassName()
const override {
return "SPIR-V Regularizer"; }
38 void getAnalysisUsage(AnalysisUsage &AU)
const override {
39 FunctionPass::getAnalysisUsage(AU);
44char SPIRVRegularizerLegacy::ID = 0;
57static
void runLowerConstExpr(
Function &
F) {
59 std::list<Instruction *> WorkList;
61 WorkList.push_back(&
II);
63 auto FBegin =
F.begin();
64 while (!WorkList.empty()) {
65 Instruction *II = WorkList.front();
67 auto LowerOp = [&II, &FBegin, &F](Value *V) -> Value * {
70 auto *CE = cast<ConstantExpr>(V);
71 LLVM_DEBUG(dbgs() <<
"[lowerConstantExpressions] " << *CE);
72 auto ReplInst = CE->getAsInstruction();
73 auto InsPoint = II->getParent() == &*FBegin ? II : &FBegin->back();
74 ReplInst->insertBefore(InsPoint->getIterator());
75 LLVM_DEBUG(dbgs() <<
" -> " << *ReplInst <<
'\n');
76 std::vector<Instruction *> Users;
78 for (auto U : CE->users()) {
79 LLVM_DEBUG(dbgs() <<
"[lowerConstantExpressions] Use: " << *U <<
'\n');
80 auto InstUser = dyn_cast<Instruction>(U);
82 if (InstUser && InstUser->getParent()->getParent() == &F)
83 Users.push_back(InstUser);
85 for (auto &User : Users) {
86 if (ReplInst->getParent() == User->getParent() &&
87 User->comesBefore(ReplInst))
88 ReplInst->moveBefore(User->getIterator());
89 User->replaceUsesOfWith(CE, ReplInst);
95 for (
unsigned OI = 0, OE =
II->getNumOperands(); OI != OE; ++OI) {
96 auto *Op = II->getOperand(OI);
97 if (auto CE = dyn_cast<ConstantExpr>(Op)) {
98 WorkList.push_front(cast<Instruction>(LowerOp(CE)));
107 Value *ReplInst = LowerOp(CE);
110 II->setOperand(OI, RepMDVal);
127 bool IsI1 = Cmp->getOperand(0)->getType()->getScalarType()->isIntegerTy(1);
131 auto Pred = Cmp->getPredicate();
137 Value *
P = Cmp->getOperand(0);
138 Value *Q = Cmp->getOperand(1);
141 Value *Result =
nullptr;
146 Result = Builder.CreateAnd(
P, Builder.CreateNot(Q));
151 Result = Builder.CreateAnd(Q, Builder.CreateNot(
P));
156 Result = Builder.CreateOr(Q, Builder.CreateNot(
P));
161 Result = Builder.CreateOr(
P, Builder.CreateNot(Q));
167 Result->takeName(Cmp);
168 Cmp->replaceAllUsesWith(Result);
169 Cmp->eraseFromParent();
175 runLowerConstExpr(
F);
185 return new SPIRVRegularizerLegacy();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool runImpl(MachineFunction &MF)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static void runLowerI1Comparisons(Function &F)
static bool runImpl(Function &F)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
This is an important base class in LLVM.
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...
This is an important class for using LLVM in a threaded context.
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)
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.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
FunctionPass * createSPIRVRegularizerPass()
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.