Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:27

0001 //===-- include/llvm/CodeGen/ByteProvider.h - Map bytes ---------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // \file
0010 // This file implements ByteProvider. The purpose of ByteProvider is to provide
0011 // a map between a target node's byte (byte position is DestOffset) and the
0012 // source (and byte position) that provides it (in Src and SrcOffset
0013 // respectively) See CodeGen/SelectionDAG/DAGCombiner.cpp MatchLoadCombine
0014 //
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_CODEGEN_BYTEPROVIDER_H
0018 #define LLVM_CODEGEN_BYTEPROVIDER_H
0019 
0020 #include <optional>
0021 #include <type_traits>
0022 
0023 namespace llvm {
0024 
0025 /// Represents known origin of an individual byte in combine pattern. The
0026 /// value of the byte is either constant zero, or comes from memory /
0027 /// some other productive instruction (e.g. arithmetic instructions).
0028 /// Bit manipulation instructions like shifts are not ByteProviders, rather
0029 /// are used to extract Bytes.
0030 template <typename ISelOp> class ByteProvider {
0031 private:
0032   ByteProvider(std::optional<ISelOp> Src, int64_t DestOffset, int64_t SrcOffset)
0033       : Src(Src), DestOffset(DestOffset), SrcOffset(SrcOffset) {}
0034 
0035   // TODO -- use constraint in c++20
0036   // Does this type correspond with an operation in selection DAG
0037   template <typename T> class is_op {
0038   private:
0039     using yes = std::true_type;
0040     using no = std::false_type;
0041 
0042     // Only allow classes with member function getOpcode
0043     template <typename U>
0044     static auto test(int) -> decltype(std::declval<U>().getOpcode(), yes());
0045 
0046     template <typename> static no test(...);
0047 
0048   public:
0049     using remove_pointer_t = typename std::remove_pointer<T>::type;
0050     static constexpr bool value =
0051         std::is_same<decltype(test<remove_pointer_t>(0)), yes>::value;
0052   };
0053 
0054 public:
0055   // For constant zero providers Src is set to nullopt. For actual providers
0056   // Src represents the node which originally produced the relevant bits.
0057   std::optional<ISelOp> Src = std::nullopt;
0058   // DestOffset is the offset of the byte in the dest we are trying to map for.
0059   int64_t DestOffset = 0;
0060   // SrcOffset is the offset in the ultimate source node that maps to the
0061   // DestOffset
0062   int64_t SrcOffset = 0;
0063 
0064   ByteProvider() = default;
0065 
0066   static ByteProvider getSrc(std::optional<ISelOp> Val, int64_t ByteOffset,
0067                              int64_t VectorOffset) {
0068     static_assert(is_op<ISelOp>().value,
0069                   "ByteProviders must contain an operation in selection DAG.");
0070     return ByteProvider(Val, ByteOffset, VectorOffset);
0071   }
0072 
0073   static ByteProvider getConstantZero() {
0074     return ByteProvider<ISelOp>(std::nullopt, 0, 0);
0075   }
0076   bool isConstantZero() const { return !Src; }
0077 
0078   bool hasSrc() const { return Src.has_value(); }
0079 
0080   bool hasSameSrc(const ByteProvider &Other) const { return Other.Src == Src; }
0081 
0082   bool operator==(const ByteProvider &Other) const {
0083     return Other.Src == Src && Other.DestOffset == DestOffset &&
0084            Other.SrcOffset == SrcOffset;
0085   }
0086 };
0087 } // end namespace llvm
0088 
0089 #endif // LLVM_CODEGEN_BYTEPROVIDER_H