From 7959f209ba8e63ffaf7335842deddda4ca0480e7 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Tue, 29 Oct 2013 09:02:02 +0000 Subject: llvm-c: Make LLVM{Get,Set}Alignment work on {Load,Store}Inst too Patch by Peter Zotov Differential Revision: http://llvm-reviews.chandlerc.com/D1910 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193597 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/Core.h | 29 +++++++++++++++++++++++++++-- lib/IR/Core.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index b9bae7e..004492b 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -1665,8 +1665,33 @@ const char *LLVMGetSection(LLVMValueRef Global); void LLVMSetSection(LLVMValueRef Global, const char *Section); LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); -unsigned LLVMGetAlignment(LLVMValueRef Global); -void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); + +/** + * @defgroup LLVMCCoreValueWithAlignment Values with alignment + * + * Functions in this group only apply to values with alignment, i.e. + * global variables, load and store instructions. + */ + +/** + * Obtain the preferred alignment of the value. + * @see llvm::LoadInst::getAlignment() + * @see llvm::StoreInst::getAlignment() + * @see llvm::GlobalValue::getAlignment() + */ +unsigned LLVMGetAlignment(LLVMValueRef V); + +/** + * Set the preferred alignment of the value. + * @see llvm::LoadInst::setAlignment() + * @see llvm::StoreInst::setAlignment() + * @see llvm::GlobalValue::setAlignment() + */ +void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes); + +/** + * @} + */ /** * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 16af733..f681b2e 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1240,12 +1240,30 @@ void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) { ->setVisibility(static_cast(Viz)); } -unsigned LLVMGetAlignment(LLVMValueRef Global) { - return unwrap(Global)->getAlignment(); +/*--.. Operations on global variables, load and store instructions .........--*/ + +unsigned LLVMGetAlignment(LLVMValueRef V) { + Value *P = unwrap(V); + if (GlobalValue *GV = dyn_cast(P)) + return GV->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"); } -void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) { - unwrap(Global)->setAlignment(Bytes); +void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) { + Value *P = unwrap(V); + if (GlobalValue *GV = dyn_cast(P)) + GV->setAlignment(Bytes); + else if (LoadInst *LI = dyn_cast(P)) + LI->setAlignment(Bytes); + else if (StoreInst *SI = dyn_cast(P)) + SI->setAlignment(Bytes); + + llvm_unreachable("only GlobalValue, LoadInst and StoreInst have alignment"); } /*--.. Operations on global variables ......................................--*/ -- cgit v1.1