2008-03-17 04:08:03 +08:00
|
|
|
//===-- Target.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-10-08 04:05:18 +08:00
|
|
|
// This file implements the common infrastructure (including C bindings) for
|
2010-10-08 02:50:11 +08:00
|
|
|
// libLLVMTarget.a, which implements target information.
|
2008-03-17 04:08:03 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/Target.h"
|
2010-10-08 02:50:11 +08:00
|
|
|
#include "llvm-c/Initialization.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2013-05-02 04:59:00 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
2010-10-08 02:50:11 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2008-03-17 04:08:03 +08:00
|
|
|
#include "llvm/PassManager.h"
|
2011-07-26 05:20:54 +08:00
|
|
|
#include "llvm/Target/TargetLibraryInfo.h"
|
2008-04-05 00:08:00 +08:00
|
|
|
#include <cstring>
|
2008-03-17 04:08:03 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-04-23 06:47:22 +08:00
|
|
|
inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
|
|
|
|
return reinterpret_cast<TargetLibraryInfo*>(P);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
|
|
|
|
TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
|
|
|
|
return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
|
|
|
|
}
|
|
|
|
|
2010-10-08 02:50:11 +08:00
|
|
|
void llvm::initializeTarget(PassRegistry &Registry) {
|
2014-02-26 01:30:31 +08:00
|
|
|
initializeDataLayoutPassPass(Registry);
|
2011-02-19 05:50:34 +08:00
|
|
|
initializeTargetLibraryInfoPass(Registry);
|
2010-10-08 02:50:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInitializeTarget(LLVMPassRegistryRef R) {
|
|
|
|
initializeTarget(*unwrap(R));
|
|
|
|
}
|
|
|
|
|
2008-03-17 04:08:03 +08:00
|
|
|
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
|
2012-10-09 00:38:25 +08:00
|
|
|
return wrap(new DataLayout(StringRep));
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
|
2014-02-26 07:25:17 +08:00
|
|
|
// The DataLayoutPass must now be in sync with the module. Unfortunatelly we
|
|
|
|
// cannot enforce that from the C api.
|
2014-02-26 01:30:31 +08:00
|
|
|
unwrap(PM)->add(new DataLayoutPass(*unwrap(TD)));
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 05:20:54 +08:00
|
|
|
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
|
|
|
|
LLVMPassManagerRef PM) {
|
|
|
|
unwrap(PM)->add(new TargetLibraryInfo(*unwrap(TLI)));
|
|
|
|
}
|
|
|
|
|
2008-03-17 04:08:03 +08:00
|
|
|
char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
|
|
|
|
std::string StringRep = unwrap(TD)->getStringRepresentation();
|
|
|
|
return strdup(StringRep.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
|
2010-01-10 06:27:07 +08:00
|
|
|
return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian;
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
|
2012-10-16 00:24:29 +08:00
|
|
|
return unwrap(TD)->getPointerSize(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
|
|
|
return unwrap(TD)->getPointerSize(AS);
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
|
2012-11-01 16:07:29 +08:00
|
|
|
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext()));
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
2012-10-16 00:24:29 +08:00
|
|
|
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
|
|
|
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext(), AS));
|
|
|
|
}
|
|
|
|
|
2013-10-18 02:51:01 +08:00
|
|
|
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD) {
|
|
|
|
return wrap(unwrap(TD)->getIntPtrType(*unwrap(C)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD, unsigned AS) {
|
|
|
|
return wrap(unwrap(TD)->getIntPtrType(*unwrap(C), AS));
|
|
|
|
}
|
|
|
|
|
2008-03-17 04:08:03 +08:00
|
|
|
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getTypeSizeInBits(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getTypeStoreSize(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
2009-05-09 15:06:46 +08:00
|
|
|
return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
2014-01-02 06:29:43 +08:00
|
|
|
return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
|
2008-03-17 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getPrefTypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
|
|
|
|
LLVMValueRef GlobalVar) {
|
|
|
|
return unwrap(TD)->getPreferredAlignment(unwrap<GlobalVariable>(GlobalVar));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
|
|
|
|
unsigned long long Offset) {
|
2011-07-18 12:54:35 +08:00
|
|
|
StructType *STy = unwrap<StructType>(StructTy);
|
2008-03-17 04:08:03 +08:00
|
|
|
return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
|
|
|
|
unsigned Element) {
|
2011-07-18 12:54:35 +08:00
|
|
|
StructType *STy = unwrap<StructType>(StructTy);
|
2008-03-17 04:08:03 +08:00
|
|
|
return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeTargetData(LLVMTargetDataRef TD) {
|
|
|
|
delete unwrap(TD);
|
|
|
|
}
|