diff options
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 6 | ||||
-rw-r--r-- | llvm/include/llvm/Analysis/ScalarEvolution.h | 4 | ||||
-rw-r--r-- | llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h | 74 | ||||
-rw-r--r-- | llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h | 3 | ||||
-rw-r--r-- | llvm/include/llvm/Frontend/OpenMP/OMP.td | 1 | ||||
-rw-r--r-- | llvm/include/llvm/Frontend/OpenMP/OMPKinds.def | 2 | ||||
-rw-r--r-- | llvm/include/llvm/IR/IntrinsicsRISCVXsf.td | 94 | ||||
-rw-r--r-- | llvm/include/llvm/Support/SpecialCaseList.h | 16 | ||||
-rw-r--r-- | llvm/include/llvm/TableGen/CodeGenHelpers.h | 29 |
9 files changed, 207 insertions, 22 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 7d81c63..2440e76 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -529,13 +529,15 @@ inline std::string join_items(Sep Separator, Args &&... Items) { class ListSeparator { bool First = true; StringRef Separator; + StringRef Prefix; public: - ListSeparator(StringRef Separator = ", ") : Separator(Separator) {} + ListSeparator(StringRef Separator = ", ", StringRef Prefix = "") + : Separator(Separator), Prefix(Prefix) {} operator StringRef() { if (First) { First = false; - return {}; + return Prefix; } return Separator; } diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 8876e4e..e5a6c8c 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -2316,10 +2316,6 @@ private: /// an add rec on said loop. void getUsedLoops(const SCEV *S, SmallPtrSetImpl<const Loop *> &LoopsUsed); - /// Try to match the pattern generated by getURemExpr(A, B). If successful, - /// Assign A and B to LHS and RHS, respectively. - LLVM_ABI bool matchURem(const SCEV *Expr, const SCEV *&LHS, const SCEV *&RHS); - /// Look for a SCEV expression with type `SCEVType` and operands `Ops` in /// `UniqueSCEVs`. Return if found, else nullptr. SCEV *findExistingSCEVInCache(SCEVTypes SCEVType, ArrayRef<const SCEV *> Ops); diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h index 07a482d..871028d 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h @@ -252,6 +252,80 @@ m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1) { return m_scev_Binary<SCEVUDivExpr>(Op0, Op1); } +/// Match unsigned remainder pattern. +/// Matches patterns generated by getURemExpr. +template <typename Op0_t, typename Op1_t> struct SCEVURem_match { + Op0_t Op0; + Op1_t Op1; + ScalarEvolution &SE; + + SCEVURem_match(Op0_t Op0, Op1_t Op1, ScalarEvolution &SE) + : Op0(Op0), Op1(Op1), SE(SE) {} + + bool match(const SCEV *Expr) const { + if (Expr->getType()->isPointerTy()) + return false; + + // Try to match 'zext (trunc A to iB) to iY', which is used + // for URem with constant power-of-2 second operands. Make sure the size of + // the operand A matches the size of the whole expressions. + const SCEV *LHS; + if (SCEVPatternMatch::match(Expr, m_scev_ZExt(m_scev_Trunc(m_SCEV(LHS))))) { + Type *TruncTy = cast<SCEVZeroExtendExpr>(Expr)->getOperand()->getType(); + // Bail out if the type of the LHS is larger than the type of the + // expression for now. + if (SE.getTypeSizeInBits(LHS->getType()) > + SE.getTypeSizeInBits(Expr->getType())) + return false; + if (LHS->getType() != Expr->getType()) + LHS = SE.getZeroExtendExpr(LHS, Expr->getType()); + const SCEV *RHS = + SE.getConstant(APInt(SE.getTypeSizeInBits(Expr->getType()), 1) + << SE.getTypeSizeInBits(TruncTy)); + return Op0.match(LHS) && Op1.match(RHS); + } + const auto *Add = dyn_cast<SCEVAddExpr>(Expr); + if (Add == nullptr || Add->getNumOperands() != 2) + return false; + + const SCEV *A = Add->getOperand(1); + const auto *Mul = dyn_cast<SCEVMulExpr>(Add->getOperand(0)); + + if (Mul == nullptr) + return false; + + const auto MatchURemWithDivisor = [&](const SCEV *B) { + // (SomeExpr + (-(SomeExpr / B) * B)). + if (Expr == SE.getURemExpr(A, B)) + return Op0.match(A) && Op1.match(B); + return false; + }; + + // (SomeExpr + (-1 * (SomeExpr / B) * B)). + if (Mul->getNumOperands() == 3 && isa<SCEVConstant>(Mul->getOperand(0))) + return MatchURemWithDivisor(Mul->getOperand(1)) || + MatchURemWithDivisor(Mul->getOperand(2)); + + // (SomeExpr + ((-SomeExpr / B) * B)) or (SomeExpr + ((SomeExpr / B) * -B)). + if (Mul->getNumOperands() == 2) + return MatchURemWithDivisor(Mul->getOperand(1)) || + MatchURemWithDivisor(Mul->getOperand(0)) || + MatchURemWithDivisor(SE.getNegativeSCEV(Mul->getOperand(1))) || + MatchURemWithDivisor(SE.getNegativeSCEV(Mul->getOperand(0))); + return false; + } +}; + +/// Match the mathematical pattern A - (A / B) * B, where A and B can be +/// arbitrary expressions. Also match zext (trunc A to iB) to iY, which is used +/// for URem with constant power-of-2 second operands. It's not always easy, as +/// A and B can be folded (imagine A is X / 2, and B is 4, A / B becomes X / 8). +template <typename Op0_t, typename Op1_t> +inline SCEVURem_match<Op0_t, Op1_t> m_scev_URem(Op0_t LHS, Op1_t RHS, + ScalarEvolution &SE) { + return SCEVURem_match<Op0_t, Op1_t>(LHS, RHS, SE); +} + inline class_match<const Loop> m_Loop() { return class_match<const Loop>(); } /// Match an affine SCEVAddRecExpr. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h index a4a7fa4..a5f6c4f 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h @@ -272,6 +272,9 @@ struct ExecutorAddrRange { } bool contains(ExecutorAddr Addr) const { return Start <= Addr && Addr < End; } + bool contains(const ExecutorAddrRange &Other) { + return (Other.Start >= Start && Other.End <= End); + } bool overlaps(const ExecutorAddrRange &Other) { return !(Other.End <= Start || End <= Other.Start); } diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td index bba0d6e..86a9e24 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -353,6 +353,7 @@ def OMPC_Novariants : Clause<[Spelling<"novariants">]> { } def OMPC_NoWait : Clause<[Spelling<"nowait">]> { let clangClass = "OMPNowaitClause"; + let isValueOptional = true; } def OMP_NUMTASKS_Strict : EnumVal<"strict", 1, 1> {} def OMP_NUMTASKS_Unknown : EnumVal<"unknown", 2, 0> { let isDefault = 1; } diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def index 1694a33..46b3d53 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def +++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def @@ -472,7 +472,7 @@ __OMP_RTL(__kmpc_target_init, false, Int32, KernelEnvironmentPtr, KernelLaunchEn __OMP_RTL(__kmpc_target_deinit, false, Void,) __OMP_RTL(__kmpc_kernel_prepare_parallel, false, Void, VoidPtr) __OMP_RTL(__kmpc_parallel_51, false, Void, IdentPtr, Int32, Int32, Int32, Int32, - FuncPtrTy, VoidPtr, VoidPtrPtr, SizeTy) + FuncPtrTy, FuncPtrTy, VoidPtrPtr, SizeTy) __OMP_RTL(__kmpc_for_static_loop_4, false, Void, IdentPtr, VoidPtr, VoidPtr, Int32, Int32, Int32, Int8) __OMP_RTL(__kmpc_for_static_loop_4u, false, Void, IdentPtr, VoidPtr, VoidPtr, Int32, Int32, Int32, Int8) __OMP_RTL(__kmpc_for_static_loop_8, false, Void, IdentPtr, VoidPtr, VoidPtr, Int64, Int64, Int64, Int8) diff --git a/llvm/include/llvm/IR/IntrinsicsRISCVXsf.td b/llvm/include/llvm/IR/IntrinsicsRISCVXsf.td index bf20080..4a0272c 100644 --- a/llvm/include/llvm/IR/IntrinsicsRISCVXsf.td +++ b/llvm/include/llvm/IR/IntrinsicsRISCVXsf.td @@ -180,4 +180,98 @@ let TargetPrefix = "riscv" in { // XSfvfnrclipxfqf defm int_riscv_sf_vfnrclip_x_f_qf : RISCVSFCustomVFNRCLIP; defm int_riscv_sf_vfnrclip_xu_f_qf : RISCVSFCustomVFNRCLIP; + + // XSfmm + // Output: (output_len) + // Input: (input_len, vsew, twiden) + class RISCVSFVSet + : DefaultAttrsIntrinsic<[llvm_anyint_ty], + [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], + [ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>, IntrNoMem]>; + + // Input: (tss, base, tn) + class RISCVSFTileLoad + : DefaultAttrsIntrinsic<[], + [llvm_anyint_ty, llvm_ptr_ty, LLVMMatchType<0>], + [NoCapture<ArgIndex<1>>, IntrHasSideEffects]>, + RISCVVIntrinsic; + + // Input: (tss, base, tn) + class RISCVSFTileStore + : DefaultAttrsIntrinsic<[], + [llvm_anyint_ty, llvm_ptr_ty, LLVMMatchType<0>], + [NoCapture<ArgIndex<1>>, IntrWriteMem, + IntrHasSideEffects]>, + RISCVVIntrinsic; + + // Output: () + // Input: (mtd, mat1, mat2, tm, tn, tk, twiden) + class RISCVSFCustomMatMul<bit is_float = false> + : DefaultAttrsIntrinsic<[], [llvm_anyint_ty, llvm_anyvector_ty, + !if(is_float, LLVMMatchType<1>, + llvm_anyvector_ty), + LLVMMatchType<0>, LLVMMatchType<0>, + LLVMMatchType<0>, LLVMMatchType<0>], + [IntrNoMem, IntrHasSideEffects, + ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<6>>]>, + RISCVVIntrinsic; + + def int_riscv_sf_vsettnt : RISCVSFVSet; + def int_riscv_sf_vsettm : RISCVSFVSet; + def int_riscv_sf_vsettk : RISCVSFVSet; + + def int_riscv_sf_vlte8 : RISCVSFTileLoad; + def int_riscv_sf_vlte16 : RISCVSFTileLoad; + def int_riscv_sf_vlte32 : RISCVSFTileLoad; + def int_riscv_sf_vlte64 : RISCVSFTileLoad; + def int_riscv_sf_vste8 : RISCVSFTileStore; + def int_riscv_sf_vste16 : RISCVSFTileStore; + def int_riscv_sf_vste32 : RISCVSFTileStore; + def int_riscv_sf_vste64 : RISCVSFTileStore; + + // Output: (vd) + // Input: (tss, tn) + def int_riscv_sf_vtmv_v_t + : DefaultAttrsIntrinsic<[llvm_anyvector_ty], + [llvm_anyint_ty, LLVMMatchType<1>], + [IntrNoMem, IntrHasSideEffects]>, + RISCVVIntrinsic { + let VLOperand = 2; + } + // Output: () + // Input: (tss, vs2, tn) + def int_riscv_sf_vtmv_t_v + : DefaultAttrsIntrinsic<[], [LLVMMatchType<1>, llvm_anyvector_ty, + llvm_anyint_ty], [IntrNoMem, IntrHasSideEffects]>, + RISCVVIntrinsic { + let VLOperand = 2; + } + + foreach a = ["u", "s"] in { + foreach b = ["u", "s"] in { + def int_riscv_sf_mm_ # a # _ # b : RISCVSFCustomMatMul; + } + } + + def int_riscv_sf_mm_f_f : RISCVSFCustomMatMul<true>; + foreach e1 = [5, 4] in + foreach e2 = [5, 4] in + def int_riscv_sf_mm_e # e1 # m # !sub(7, e1) # _e # e2 # m # !sub(7, e2) + : RISCVSFCustomMatMul<true>; + + // Output: () + // Input: (mtd) + def int_riscv_sf_vtzero_t + : DefaultAttrsIntrinsic<[], + [llvm_anyint_ty, LLVMMatchType<0>,LLVMMatchType<0>, + LLVMMatchType<0>, LLVMMatchType<0>], + [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<3>>, + ImmArg<ArgIndex<4>>, IntrNoMem, IntrHasSideEffects]>, + RISCVVIntrinsic; + + // Output: () + // Input: () + def int_riscv_sf_vtdiscard + : DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>, + RISCVVIntrinsic; } // TargetPrefix = "riscv" diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index 466e2a4..ead7655 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -115,7 +115,8 @@ protected: // classes. LLVM_ABI bool createInternal(const std::vector<std::string> &Paths, vfs::FileSystem &VFS, std::string &Error); - LLVM_ABI bool createInternal(const MemoryBuffer *MB, std::string &Error); + LLVM_ABI bool createInternal(const MemoryBuffer *MB, std::string &Error, + bool OrderBySize = false); SpecialCaseList() = default; SpecialCaseList(SpecialCaseList const &) = delete; @@ -126,6 +127,8 @@ private: class RegexMatcher { public: LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber); + LLVM_ABI void preprocess(bool BySize); + LLVM_ABI void match(StringRef Query, llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const; @@ -144,6 +147,8 @@ private: class GlobMatcher { public: LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber); + LLVM_ABI void preprocess(bool BySize); + LLVM_ABI void match(StringRef Query, llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const; @@ -164,6 +169,9 @@ private: public: LLVM_ABI Matcher(bool UseGlobs, bool RemoveDotSlash); + LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber); + LLVM_ABI void preprocess(bool BySize); + LLVM_ABI void match(StringRef Query, llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const; @@ -174,8 +182,6 @@ private: return R; } - LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber); - std::variant<RegexMatcher, GlobMatcher> M; bool RemoveDotSlash; }; @@ -206,6 +212,8 @@ protected: StringRef Category) const; private: + friend class SpecialCaseList; + LLVM_ABI void preprocess(bool OrderBySize); LLVM_ABI const SpecialCaseList::Matcher * findMatcher(StringRef Prefix, StringRef Category) const; }; @@ -222,7 +230,7 @@ private: /// Parses just-constructed SpecialCaseList entries from a memory buffer. LLVM_ABI bool parse(unsigned FileIdx, const MemoryBuffer *MB, - std::string &Error); + std::string &Error, bool OrderBySize); }; } // namespace llvm diff --git a/llvm/include/llvm/TableGen/CodeGenHelpers.h b/llvm/include/llvm/TableGen/CodeGenHelpers.h index 7dca6a0..5b823db 100644 --- a/llvm/include/llvm/TableGen/CodeGenHelpers.h +++ b/llvm/include/llvm/TableGen/CodeGenHelpers.h @@ -38,28 +38,35 @@ private: // namespace (empty for anonymous namespace) or nested namespace. class NamespaceEmitter { public: - NamespaceEmitter(raw_ostream &OS, StringRef Name) : OS(OS) { - emitNamespaceStarts(Name); + NamespaceEmitter(raw_ostream &OS, StringRef Name) + : Name(trim(Name).str()), OS(OS) { + OS << "namespace " << this->Name << " {\n"; } ~NamespaceEmitter() { close(); } // Explicit function to close the namespace scopes. void close() { - for (StringRef NS : llvm::reverse(Namespaces)) - OS << "} // namespace " << NS << "\n"; - Namespaces.clear(); + if (!Closed) + OS << "} // namespace " << Name << "\n"; + Closed = true; } private: - void emitNamespaceStarts(StringRef Name) { - llvm::SplitString(Name, Namespaces, "::"); - for (StringRef NS : Namespaces) - OS << "namespace " << NS << " {\n"; + // Trim "::" prefix. If the namespace specified is ""::mlir::toy", then the + // generated namespace scope needs to use + // + // namespace mlir::toy { + // } + // + // and cannot use "namespace ::mlir::toy". + static StringRef trim(StringRef Name) { + Name.consume_front("::"); + return Name; } - - SmallVector<StringRef, 2> Namespaces; + std::string Name; raw_ostream &OS; + bool Closed = false; }; } // end namespace llvm |