LLVMReactor: set alignment when allocating stack variables Bug: none Change-Id: I1e9d97e95fea1e9c2863211c711feda6d794a825 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/45268 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp index 9e5ad40..eacba83 100644 --- a/src/Reactor/LLVMReactor.cpp +++ b/src/Reactor/LLVMReactor.cpp
@@ -26,6 +26,9 @@ #if LLVM_VERSION_MAJOR >= 9 # include "llvm/IR/IntrinsicsX86.h" #endif +#if LLVM_VERSION_MAJOR >= 10 +# include "llvm/Support/Alignment.h" +#endif #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/Transforms/Coroutines.h" @@ -747,13 +750,21 @@ llvm::Instruction *declaration; +#if LLVM_VERSION_MAJOR >= 11 + auto align = jit->module->getDataLayout().getPrefTypeAlign(T(type)); +#elif LLVM_VERSION_MAJOR >= 10 + auto align = llvm::MaybeAlign(jit->module->getDataLayout().getPrefTypeAlignment(T(type))); +#else + auto align = jit->module->getDataLayout().getPrefTypeAlignment(T(type)); +#endif + if(arraySize) { - declaration = new llvm::AllocaInst(T(type), 0, V(Nucleus::createConstantInt(arraySize))); + declaration = new llvm::AllocaInst(T(type), 0, V(Nucleus::createConstantInt(arraySize)), align); } else { - declaration = new llvm::AllocaInst(T(type), 0, (llvm::Value *)nullptr); + declaration = new llvm::AllocaInst(T(type), 0, (llvm::Value *)nullptr, align); } entryBlock.getInstList().push_front(declaration);