From 8a25ef92fb3af998124a1d9770fb7ef7dec84401 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Wed, 5 Mar 2014 05:05:34 +0000 Subject: [PATCH] [C API] Implement LLVM{Get,Set}Alignment for AllocaInst. Patch by Manuel Jacob. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202936 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/Core.h | 2 ++ lib/IR/Core.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index af1e01d8e1b..437023bfba6 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -1707,6 +1707,7 @@ void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class); /** * Obtain the preferred alignment of the value. + * @see llvm::AllocaInst::getAlignment() * @see llvm::LoadInst::getAlignment() * @see llvm::StoreInst::getAlignment() * @see llvm::GlobalValue::getAlignment() @@ -1715,6 +1716,7 @@ unsigned LLVMGetAlignment(LLVMValueRef V); /** * Set the preferred alignment of the value. + * @see llvm::AllocaInst::setAlignment() * @see llvm::LoadInst::setAlignment() * @see llvm::StoreInst::setAlignment() * @see llvm::GlobalValue::setAlignment() diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index c78ddae60be..f63263fd1f5 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1268,24 +1268,30 @@ unsigned LLVMGetAlignment(LLVMValueRef V) { Value *P = unwrap(V); if (GlobalValue *GV = dyn_cast(P)) return GV->getAlignment(); + if (AllocaInst *AI = dyn_cast(P)) + return AI->getAlignment(); if (LoadInst *LI = dyn_cast(P)) return LI->getAlignment(); if (StoreInst *SI = dyn_cast(P)) return SI->getAlignment(); - llvm_unreachable("only GlobalValue, LoadInst and StoreInst have alignment"); + llvm_unreachable( + "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment"); } void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) { Value *P = unwrap(V); if (GlobalValue *GV = dyn_cast(P)) GV->setAlignment(Bytes); + else if (AllocaInst *AI = dyn_cast(P)) + AI->setAlignment(Bytes); else if (LoadInst *LI = dyn_cast(P)) LI->setAlignment(Bytes); else if (StoreInst *SI = dyn_cast(P)) SI->setAlignment(Bytes); else - llvm_unreachable("only GlobalValue, LoadInst and StoreInst have alignment"); + llvm_unreachable( + "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment"); } /*--.. Operations on global variables ......................................--*/