|
21 | 21 | #include "llvm/ADT/StringRef.h" |
22 | 22 | #include "llvm/ADT/iterator_range.h" |
23 | 23 | #include "llvm/IR/Constants.h" |
24 | | -#include "llvm/IR/DbgVariableFragmentInfo.h" |
25 | 24 | #include "llvm/IR/Metadata.h" |
26 | 25 | #include "llvm/IR/PseudoProbe.h" |
27 | 26 | #include "llvm/Support/Casting.h" |
@@ -2887,7 +2886,29 @@ class DIExpression : public MDNode { |
2887 | 2886 | /// Return whether there is exactly one operator and it is a DW_OP_deref; |
2888 | 2887 | bool isDeref() const; |
2889 | 2888 |
|
2890 | | - using FragmentInfo = DbgVariableFragmentInfo; |
| 2889 | + /// Holds the characteristics of one fragment of a larger variable. |
| 2890 | + struct FragmentInfo { |
| 2891 | + FragmentInfo() = default; |
| 2892 | + FragmentInfo(uint64_t SizeInBits, uint64_t OffsetInBits) |
| 2893 | + : SizeInBits(SizeInBits), OffsetInBits(OffsetInBits) {} |
| 2894 | + uint64_t SizeInBits; |
| 2895 | + uint64_t OffsetInBits; |
| 2896 | + /// Return the index of the first bit of the fragment. |
| 2897 | + uint64_t startInBits() const { return OffsetInBits; } |
| 2898 | + /// Return the index of the bit after the end of the fragment, e.g. for |
| 2899 | + /// fragment offset=16 and size=32 return their sum, 48. |
| 2900 | + uint64_t endInBits() const { return OffsetInBits + SizeInBits; } |
| 2901 | + |
| 2902 | + /// Returns a zero-sized fragment if A and B don't intersect. |
| 2903 | + static DIExpression::FragmentInfo intersect(DIExpression::FragmentInfo A, |
| 2904 | + DIExpression::FragmentInfo B) { |
| 2905 | + uint64_t StartInBits = std::max(A.OffsetInBits, B.OffsetInBits); |
| 2906 | + uint64_t EndInBits = std::min(A.endInBits(), B.endInBits()); |
| 2907 | + if (EndInBits <= StartInBits) |
| 2908 | + return {0, 0}; |
| 2909 | + return DIExpression::FragmentInfo(EndInBits - StartInBits, StartInBits); |
| 2910 | + } |
| 2911 | + }; |
2891 | 2912 |
|
2892 | 2913 | /// Return the number of bits that have an active value, i.e. those that |
2893 | 2914 | /// aren't known to be zero/sign (depending on the type of Var) and which |
|
0 commit comments