Skip to content

Commit 0e27fdc

Browse files
dmitryryintelsys_zuul
authored andcommitted
fix align wrapper for unset alignment
Change-Id: I7b014212602c805d31d5e7b50095bd9234c54f6c
1 parent f9f6566 commit 0e27fdc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

IGC/VectorCompiler/lib/GenXOpts/CMTrans/CMABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ class cloneInstWithNewOpsImpl
619619
Ptr,
620620
"",
621621
OrigLoad.isVolatile(),
622-
IGCLLVM::getAlign(OrigLoad.getAlignment()),
622+
IGCLLVM::getAlign(OrigLoad),
623623
OrigLoad.getOrdering(),
624624
OrigLoad.getSyncScopeID()};
625625
return NewLoad;

IGC/WrapperLLVM/include/llvmWrapper/Support/Alignment.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2828
#define IGCLLVM_SUPPORT_ALIGNMENT_H
2929

3030
#include <cstdint>
31+
#include <type_traits>
32+
#include "llvm/IR/Value.h"
3133
#include "llvm/Config/llvm-config.h"
3234
#if LLVM_VERSION_MAJOR >= 10
3335
#include "llvm/Support/Alignment.h"
@@ -75,6 +77,35 @@ namespace IGCLLVM {
7577
return T{ Val };
7678
}
7779

80+
// It is meant for copying alignement.
81+
// getAlign returns different type for different LLVM versions but
82+
// it can be overcome by using auto or direct usage in another LLVM
83+
// interface.
84+
#if LLVM_VERSION_MAJOR <= 9
85+
template <typename TValue,
86+
std::enable_if_t<std::is_base_of<llvm::Value, TValue>::value, int> = 0>
87+
unsigned getAlign(const TValue &Val)
88+
{
89+
return Val.getAlignment();
90+
}
91+
#elif LLVM_VERSION_MAJOR <= 10
92+
template <typename TValue,
93+
std::enable_if_t<std::is_base_of<llvm::Value, TValue>::value, int> = 0>
94+
llvm::MaybeAlign getAlign(const TValue &Val)
95+
{
96+
// LLVM 10 instructions accept MaybeAlign but do not provide
97+
// getMaybeAlignMethod
98+
return llvm::MaybeAlign(Val.getAlignment());
99+
}
100+
#else
101+
template <typename TValue,
102+
std::enable_if_t<std::is_base_of<llvm::Value, TValue>::value, int> = 0>
103+
llvm::Align getAlign(const TValue &Val)
104+
{
105+
return Val.getAlign();
106+
}
107+
#endif
108+
78109
} // namespace IGCLLVM
79110

80111
#endif

0 commit comments

Comments
 (0)