6#include "llvm/IR/IntrinsicsWebAssembly.h"
16struct WebAssemblyReduceToAnyAllTrueLegacy final :
FunctionPass {
19 WebAssemblyTargetMachine &TM;
20 Module *CachedModule =
nullptr;
21 bool ModuleHasInterestingIntrinsics =
false;
23 WebAssemblyReduceToAnyAllTrueLegacy(WebAssemblyTargetMachine &TM)
24 : FunctionPass(ID), TM(TM) {}
26 StringRef getPassName()
const override {
27 return "WebAssembly convert reduce to any_true/all_true";
34char WebAssemblyReduceToAnyAllTrueLegacy::ID = 0;
37 bool &ModuleHasInterestingIntrinsics) {
38 if (CachedModule == &M)
39 return ModuleHasInterestingIntrinsics;
42 ModuleHasInterestingIntrinsics =
false;
44 for (
const Function &Fn : M.functions()) {
45 switch (Fn.getIntrinsicID()) {
46 case Intrinsic::vector_reduce_or:
47 case Intrinsic::vector_reduce_and:
48 ModuleHasInterestingIntrinsics =
true;
60 bool &ModuleHasInterestingIntrinsics) {
65 ModuleHasInterestingIntrinsics))
71 for (
auto It = BB.begin(),
E = BB.end(); It !=
E;) {
77 Value *Reduce =
nullptr;
82 if (!
II || !
II->hasOneUse())
86 Value *Vec =
II->getArgOperand(0);
92 return B.CreateCall(Fn, {Arg});
97 switch (
II->getIntrinsicID()) {
98 case Intrinsic::vector_reduce_or: {
100 Value *
Any = makeIntrinsic(Intrinsic::wasm_anytrue, Vec);
101 New =
B.CreateICmpNE(
Any, ConstantInt::get(
Any->getType(), 0));
105 case Intrinsic::vector_reduce_and: {
116 Value *
All = makeIntrinsic(Intrinsic::wasm_alltrue,
LHS);
117 New =
B.CreateICmpNE(
All, ConstantInt::get(
All->getType(), 0));
125 Cmp->replaceAllUsesWith(New);
126 Cmp->eraseFromParent();
129 II->eraseFromParent();
138bool WebAssemblyReduceToAnyAllTrueLegacy::runOnFunction(
Function &
F) {
140 ModuleHasInterestingIntrinsics);
153 return new WebAssemblyReduceToAnyAllTrueLegacy(TM);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool runOnFunction(Function &F, bool PostInlining)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
static bool hasInterestingIntrinsics(Module &M, Module *&CachedModule, bool &ModuleHasInterestingIntrinsics)
static bool reduceToAnyAllTrue(Function &F, WebAssemblyTargetMachine &TM, Module *&CachedModule, bool &ModuleHasInterestingIntrinsics)
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file declares the WebAssembly-specific subclass of TargetMachine.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represents analyses that only rely on functions' control flow.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
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...
A Module instance is used to store all the information related to an LLVM module.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
LLVM Value Representation.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Pass manager infrastructure for declaring and invalidating analyses.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
bool match(Val *V, const Pattern &P)
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
auto m_Value()
Match an arbitrary value and ignore it.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
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.
FunctionPass * createWebAssemblyReduceToAnyAllTrueLegacyPass(WebAssemblyTargetMachine &TM)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.