2009-06-02 17:52:33 +00:00
|
|
|
//===-- Target.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-02-20 12:57:14 +00:00
|
|
|
// This file implements the common infrastructure (including C bindings) for
|
|
|
|
// libLLVMTarget.a, which implements target information.
|
2009-06-02 17:52:33 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/Target.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm-c/Initialization.h"
|
|
|
|
#include "llvm/InitializePasses.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2012-12-02 13:10:19 +00:00
|
|
|
#include "llvm/DataLayout.h"
|
2011-10-20 21:10:27 +00:00
|
|
|
#include "llvm/Target/TargetLibraryInfo.h"
|
2010-01-01 10:31:22 +00:00
|
|
|
#include "llvm/LLVMContext.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
void llvm::initializeTarget(PassRegistry &Registry) {
|
2012-12-02 13:10:19 +00:00
|
|
|
initializeDataLayoutPass(Registry);
|
2011-02-20 12:57:14 +00:00
|
|
|
initializeTargetLibraryInfoPass(Registry);
|
2012-12-02 13:10:19 +00:00
|
|
|
initializeTargetTransformInfoPass(Registry);
|
2011-02-20 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInitializeTarget(LLVMPassRegistryRef R) {
|
|
|
|
initializeTarget(*unwrap(R));
|
|
|
|
}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
|
2012-12-02 13:10:19 +00:00
|
|
|
return wrap(new DataLayout(StringRep));
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
|
2012-12-02 13:10:19 +00:00
|
|
|
unwrap(PM)->add(new DataLayout(*unwrap(TD)));
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2011-10-20 21:10:27 +00:00
|
|
|
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
|
|
|
|
LLVMPassManagerRef PM) {
|
|
|
|
unwrap(PM)->add(new TargetLibraryInfo(*unwrap(TLI)));
|
|
|
|
}
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD) {
|
|
|
|
std::string StringRep = unwrap(TD)->getStringRepresentation();
|
|
|
|
return strdup(StringRep.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD) {
|
2010-01-15 15:37:28 +00:00
|
|
|
return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian;
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPointerSize(LLVMTargetDataRef TD) {
|
2012-12-02 13:10:19 +00:00
|
|
|
return unwrap(TD)->getPointerSize(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
|
|
|
return unwrap(TD)->getPointerSize(AS);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) {
|
2009-10-14 17:57:32 +00:00
|
|
|
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext()));
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS) {
|
|
|
|
return wrap(unwrap(TD)->getIntPtrType(getGlobalContext(), AS));
|
|
|
|
}
|
|
|
|
|
2009-06-02 17:52:33 +00: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) {
|
|
|
|
return unwrap(TD)->getTypeAllocSize(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getABITypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
|
|
|
|
return unwrap(TD)->getCallFrameTypeAlignment(unwrap(Ty));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-20 21:10:27 +00:00
|
|
|
StructType *STy = unwrap<StructType>(StructTy);
|
2009-06-02 17:52:33 +00:00
|
|
|
return unwrap(TD)->getStructLayout(STy)->getElementContainingOffset(Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
|
|
|
|
unsigned Element) {
|
2011-10-20 21:10:27 +00:00
|
|
|
StructType *STy = unwrap<StructType>(StructTy);
|
2009-06-02 17:52:33 +00:00
|
|
|
return unwrap(TD)->getStructLayout(STy)->getElementOffset(Element);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeTargetData(LLVMTargetDataRef TD) {
|
|
|
|
delete unwrap(TD);
|
|
|
|
}
|