1 //===- llvm/IR/DbgVariableFragmentInfo.h ------------------------*- 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 // Helper struct to describe a fragment of a debug variable. 10 // 11 //===----------------------------------------------------------------------===// 12 #ifndef LLVM_IR_DBGVARIABLEFRAGMENTINFO_H 13 #define LLVM_IR_DBGVARIABLEFRAGMENTINFO_H 14 15 #include <cstdint> 16 17 namespace llvm { 18 struct DbgVariableFragmentInfo { 19 DbgVariableFragmentInfo() = default; DbgVariableFragmentInfoDbgVariableFragmentInfo20 DbgVariableFragmentInfo(uint64_t SizeInBits, uint64_t OffsetInBits) 21 : SizeInBits(SizeInBits), OffsetInBits(OffsetInBits) {} 22 uint64_t SizeInBits; 23 uint64_t OffsetInBits; 24 /// Return the index of the first bit of the fragment. startInBitsDbgVariableFragmentInfo25 uint64_t startInBits() const { return OffsetInBits; } 26 /// Return the index of the bit after the end of the fragment, e.g. for 27 /// fragment offset=16 and size=32 return their sum, 48. endInBitsDbgVariableFragmentInfo28 uint64_t endInBits() const { return OffsetInBits + SizeInBits; } 29 30 /// Returns a zero-sized fragment if A and B don't intersect. intersectDbgVariableFragmentInfo31 static DbgVariableFragmentInfo intersect(DbgVariableFragmentInfo A, 32 DbgVariableFragmentInfo B) { 33 // Don't use std::max or min to avoid including <algorithm>. 34 uint64_t StartInBits = 35 A.OffsetInBits > B.OffsetInBits ? A.OffsetInBits : B.OffsetInBits; 36 uint64_t EndInBits = 37 A.endInBits() < B.endInBits() ? A.endInBits() : B.endInBits(); 38 if (EndInBits <= StartInBits) 39 return {0, 0}; 40 return DbgVariableFragmentInfo(EndInBits - StartInBits, StartInBits); 41 } 42 }; 43 } // end namespace llvm 44 45 #endif // LLVM_IR_DBGVARIABLEFRAGMENTINFO_H 46