LLVM 18.0.0git
ByteProvider.h
Go to the documentation of this file.
1//===-- include/llvm/CodeGen/ByteProvider.h - Map bytes ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// \file
10// This file implements ByteProvider. The purpose of ByteProvider is to provide
11// a map between a target node's byte (byte position is DestOffset) and the
12// source (and byte position) that provides it (in Src and SrcOffset
13// respectively) See CodeGen/SelectionDAG/DAGCombiner.cpp MatchLoadCombine
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_BYTEPROVIDER_H
18#define LLVM_CODEGEN_BYTEPROVIDER_H
19
20#include <optional>
21#include <type_traits>
22
23namespace llvm {
24
25/// Represents known origin of an individual byte in combine pattern. The
26/// value of the byte is either constant zero, or comes from memory /
27/// some other productive instruction (e.g. arithmetic instructions).
28/// Bit manipulation instructions like shifts are not ByteProviders, rather
29/// are used to extract Bytes.
30template <typename ISelOp> class ByteProvider {
31private:
32 ByteProvider(std::optional<ISelOp> Src, int64_t DestOffset, int64_t SrcOffset)
34
35 ByteProvider(std::optional<ISelOp> Src, int64_t DestOffset, int64_t SrcOffset,
36 std::optional<bool> IsSigned)
39
40 // TODO -- use constraint in c++20
41 // Does this type correspond with an operation in selection DAG
42 template <typename T> class is_op {
43 private:
44 using yes = std::true_type;
45 using no = std::false_type;
46
47 // Only allow classes with member function getOpcode
48 template <typename U>
49 static auto test(int) -> decltype(std::declval<U>().getOpcode(), yes());
50
51 template <typename> static no test(...);
52
53 public:
54 using remove_pointer_t = typename std::remove_pointer<T>::type;
55 static constexpr bool value =
56 std::is_same<decltype(test<remove_pointer_t>(0)), yes>::value;
57 };
58
59public:
60 // For constant zero providers Src is set to nullopt. For actual providers
61 // Src represents the node which originally produced the relevant bits.
62 std::optional<ISelOp> Src = std::nullopt;
63 // DestOffset is the offset of the byte in the dest we are trying to map for.
64 int64_t DestOffset = 0;
65 // SrcOffset is the offset in the ultimate source node that maps to the
66 // DestOffset
67 int64_t SrcOffset = 0;
68
69 // Whether or not the path to this Src involved signed extensions
70 std::optional<bool> IsSigned;
71
72 ByteProvider() = default;
73
74 static ByteProvider getSrc(std::optional<ISelOp> Val, int64_t ByteOffset,
75 int64_t VectorOffset) {
76 static_assert(is_op<ISelOp>().value,
77 "ByteProviders must contain an operation in selection DAG.");
78 return ByteProvider(Val, ByteOffset, VectorOffset);
79 }
80
81 static ByteProvider getSrc(std::optional<ISelOp> Val, int64_t ByteOffset,
82 int64_t VectorOffset,
83 std::optional<bool> IsSigned) {
84 static_assert(is_op<ISelOp>().value,
85 "ByteProviders must contain an operation in selection DAG.");
86 return ByteProvider(Val, ByteOffset, VectorOffset, IsSigned);
87 }
88
90 return ByteProvider<ISelOp>(std::nullopt, 0, 0);
91 }
92 bool isConstantZero() const { return !Src; }
93
94 bool hasSrc() const { return Src.has_value(); }
95
96 bool hasSameSrc(const ByteProvider &Other) const { return Other.Src == Src; }
97
98 bool operator==(const ByteProvider &Other) const {
99 return Other.Src == Src && Other.DestOffset == DestOffset &&
100 Other.SrcOffset == SrcOffset;
101 }
102};
103} // end namespace llvm
104
105#endif // LLVM_CODEGEN_BYTEPROVIDER_H
Given that RA is a live value
modulo schedule test
Represents known origin of an individual byte in combine pattern.
Definition: ByteProvider.h:30
ByteProvider()=default
static ByteProvider getConstantZero()
Definition: ByteProvider.h:89
bool operator==(const ByteProvider &Other) const
Definition: ByteProvider.h:98
static ByteProvider getSrc(std::optional< ISelOp > Val, int64_t ByteOffset, int64_t VectorOffset)
Definition: ByteProvider.h:74
bool hasSameSrc(const ByteProvider &Other) const
Definition: ByteProvider.h:96
bool hasSrc() const
Definition: ByteProvider.h:94
static ByteProvider getSrc(std::optional< ISelOp > Val, int64_t ByteOffset, int64_t VectorOffset, std::optional< bool > IsSigned)
Definition: ByteProvider.h:81
std::optional< bool > IsSigned
Definition: ByteProvider.h:70
std::optional< ISelOp > Src
Definition: ByteProvider.h:62
bool isConstantZero() const
Definition: ByteProvider.h:92
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Other
Any other memory.