| 1 |
#ifndef LDC_GEN_TOLLVM_H |
|---|
| 2 |
#define LDC_GEN_TOLLVM_H |
|---|
| 3 |
|
|---|
| 4 |
#include "gen/llvm.h" |
|---|
| 5 |
#include "lexer.h" |
|---|
| 6 |
#include "mtype.h" |
|---|
| 7 |
#include "attrib.h" |
|---|
| 8 |
#include "declaration.h" |
|---|
| 9 |
|
|---|
| 10 |
#include "gen/structs.h" |
|---|
| 11 |
|
|---|
| 12 |
// D->LLVM type handling stuff |
|---|
| 13 |
const LLType* DtoType(Type* t); |
|---|
| 14 |
|
|---|
| 15 |
// same as DtoType except it converts 'void' to 'i8' |
|---|
| 16 |
const LLType* DtoTypeNotVoid(Type* t); |
|---|
| 17 |
|
|---|
| 18 |
// returns true is the type must be passed by pointer |
|---|
| 19 |
bool DtoIsPassedByRef(Type* type); |
|---|
| 20 |
|
|---|
| 21 |
// should argument be zero or sign extended |
|---|
| 22 |
unsigned DtoShouldExtend(Type* type); |
|---|
| 23 |
|
|---|
| 24 |
// tuple helper |
|---|
| 25 |
// takes a arguments list and makes a struct type out of them |
|---|
| 26 |
//const LLType* DtoStructTypeFromArguments(Arguments* arguments); |
|---|
| 27 |
|
|---|
| 28 |
// delegate helpers |
|---|
| 29 |
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs); |
|---|
| 30 |
|
|---|
| 31 |
// return linkage type for symbol using the current ir state for context |
|---|
| 32 |
LLGlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym); |
|---|
| 33 |
LLGlobalValue::LinkageTypes DtoInternalLinkage(Dsymbol* sym); |
|---|
| 34 |
LLGlobalValue::LinkageTypes DtoExternalLinkage(Dsymbol* sym); |
|---|
| 35 |
|
|---|
| 36 |
// TODO: this one should be removed!!! |
|---|
| 37 |
LLValue* DtoPointedType(LLValue* ptr, LLValue* val); |
|---|
| 38 |
|
|---|
| 39 |
// some types |
|---|
| 40 |
const LLIntegerType* DtoSize_t(); |
|---|
| 41 |
const LLStructType* DtoInterfaceInfoType(); |
|---|
| 42 |
const LLStructType* DtoMutexType(); |
|---|
| 43 |
const LLStructType* DtoModuleReferenceType(); |
|---|
| 44 |
|
|---|
| 45 |
// getelementptr helpers |
|---|
| 46 |
LLValue* DtoGEP1(LLValue* ptr, LLValue* i0, const char* var=NULL, llvm::BasicBlock* bb=NULL); |
|---|
| 47 |
LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const char* var=NULL, llvm::BasicBlock* bb=NULL); |
|---|
| 48 |
|
|---|
| 49 |
LLValue* DtoGEPi1(LLValue* ptr, unsigned i0, const char* var=NULL, llvm::BasicBlock* bb=NULL); |
|---|
| 50 |
LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const char* var=NULL, llvm::BasicBlock* bb=NULL); |
|---|
| 51 |
LLConstant* DtoGEPi(LLConstant* ptr, unsigned i0, unsigned i1); |
|---|
| 52 |
|
|---|
| 53 |
// to constant helpers |
|---|
| 54 |
LLConstantInt* DtoConstSize_t(uint64_t); |
|---|
| 55 |
LLConstantInt* DtoConstUint(unsigned i); |
|---|
| 56 |
LLConstantInt* DtoConstInt(int i); |
|---|
| 57 |
LLConstantInt* DtoConstUbyte(unsigned char i); |
|---|
| 58 |
LLConstant* DtoConstFP(Type* t, long double value); |
|---|
| 59 |
|
|---|
| 60 |
LLConstant* DtoConstString(const char*); |
|---|
| 61 |
LLConstant* DtoConstStringPtr(const char* str, const char* section = 0); |
|---|
| 62 |
LLConstant* DtoConstBool(bool); |
|---|
| 63 |
|
|---|
| 64 |
// llvm wrappers |
|---|
| 65 |
LLValue* DtoLoad(LLValue* src, const char* name=0); |
|---|
| 66 |
LLValue* DtoAlignedLoad(LLValue* src, const char* name=0); |
|---|
| 67 |
void DtoStore(LLValue* src, LLValue* dst); |
|---|
| 68 |
void DtoAlignedStore(LLValue* src, LLValue* dst); |
|---|
| 69 |
LLValue* DtoBitCast(LLValue* v, const LLType* t, const char* name=0); |
|---|
| 70 |
LLConstant* DtoBitCast(LLConstant* v, const LLType* t); |
|---|
| 71 |
LLValue* DtoInsertValue(LLValue* aggr, LLValue* v, unsigned idx); |
|---|
| 72 |
LLValue* DtoExtractValue(LLValue* aggr, unsigned idx); |
|---|
| 73 |
|
|---|
| 74 |
// llvm::dyn_cast wrappers |
|---|
| 75 |
const LLPointerType* isaPointer(LLValue* v); |
|---|
| 76 |
const LLPointerType* isaPointer(const LLType* t); |
|---|
| 77 |
const LLArrayType* isaArray(LLValue* v); |
|---|
| 78 |
const LLArrayType* isaArray(const LLType* t); |
|---|
| 79 |
const LLStructType* isaStruct(LLValue* v); |
|---|
| 80 |
const LLStructType* isaStruct(const LLType* t); |
|---|
| 81 |
const LLFunctionType* isaFunction(LLValue* v); |
|---|
| 82 |
const LLFunctionType* isaFunction(const LLType* t); |
|---|
| 83 |
LLConstant* isaConstant(LLValue* v); |
|---|
| 84 |
LLConstantInt* isaConstantInt(LLValue* v); |
|---|
| 85 |
llvm::Argument* isaArgument(LLValue* v); |
|---|
| 86 |
LLGlobalVariable* isaGlobalVar(LLValue* v); |
|---|
| 87 |
|
|---|
| 88 |
// llvm::T::get(...) wrappers |
|---|
| 89 |
const LLPointerType* getPtrToType(const LLType* t); |
|---|
| 90 |
const LLPointerType* getVoidPtrType(); |
|---|
| 91 |
llvm::ConstantPointerNull* getNullPtr(const LLType* t); |
|---|
| 92 |
LLConstant* getNullValue(const LLType* t); |
|---|
| 93 |
|
|---|
| 94 |
// type sizes |
|---|
| 95 |
size_t getTypeBitSize(const LLType* t); |
|---|
| 96 |
size_t getTypeStoreSize(const LLType* t); |
|---|
| 97 |
size_t getTypePaddedSize(const LLType* t); |
|---|
| 98 |
|
|---|
| 99 |
// type alignments |
|---|
| 100 |
unsigned char getABITypeAlign(const LLType* t); |
|---|
| 101 |
unsigned char getPrefTypeAlign(const LLType* t); |
|---|
| 102 |
|
|---|
| 103 |
// get biggest type, for unions ... |
|---|
| 104 |
const LLType* getBiggestType(const LLType** begin, size_t n); |
|---|
| 105 |
|
|---|
| 106 |
// pair type helpers |
|---|
| 107 |
LLValue* DtoAggrPair(const LLType* type, LLValue* V1, LLValue* V2, const char* name = 0); |
|---|
| 108 |
LLValue* DtoAggrPair(LLValue* V1, LLValue* V2, const char* name = 0); |
|---|
| 109 |
LLValue* DtoAggrPaint(LLValue* aggr, const LLType* as); |
|---|
| 110 |
LLValue* DtoAggrPairSwap(LLValue* aggr); |
|---|
| 111 |
|
|---|
| 112 |
/** |
|---|
| 113 |
* Generates a call to llvm.memset.i32 (or i64 depending on architecture). |
|---|
| 114 |
* @param dst Destination memory. |
|---|
| 115 |
* @param val The value to set. |
|---|
| 116 |
* @param nbytes Number of bytes to overwrite. |
|---|
| 117 |
*/ |
|---|
| 118 |
void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes); |
|---|
| 119 |
|
|---|
| 120 |
/** |
|---|
| 121 |
* Generates a call to llvm.memset.i32 (or i64 depending on architecture). |
|---|
| 122 |
* @param dst Destination memory. |
|---|
| 123 |
* @param nbytes Number of bytes to overwrite. |
|---|
| 124 |
*/ |
|---|
| 125 |
void DtoMemSetZero(LLValue* dst, LLValue* nbytes); |
|---|
| 126 |
|
|---|
| 127 |
/** |
|---|
| 128 |
* Generates a call to llvm.memcpy.i32 (or i64 depending on architecture). |
|---|
| 129 |
* @param dst Destination memory. |
|---|
| 130 |
* @param src Source memory. |
|---|
| 131 |
* @param nbytes Number of bytes to copy. |
|---|
| 132 |
* @param align The minimum alignment of the source and destination memory. |
|---|
| 133 |
*/ |
|---|
| 134 |
void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes, unsigned align = 0); |
|---|
| 135 |
|
|---|
| 136 |
/** |
|---|
| 137 |
* Generates a call to C memcmp. |
|---|
| 138 |
*/ |
|---|
| 139 |
LLValue* DtoMemCmp(LLValue* lhs, LLValue* rhs, LLValue* nbytes); |
|---|
| 140 |
|
|---|
| 141 |
/** |
|---|
| 142 |
* The same as DtoMemSetZero but figures out the size itself by "dereferencing" the v pointer once. |
|---|
| 143 |
* @param v Destination memory. |
|---|
| 144 |
*/ |
|---|
| 145 |
void DtoAggrZeroInit(LLValue* v); |
|---|
| 146 |
|
|---|
| 147 |
/** |
|---|
| 148 |
* The same as DtoMemCpy but figures out the size itself by "dereferencing" dst the pointer once. |
|---|
| 149 |
* @param dst Destination memory. |
|---|
| 150 |
* @param src Source memory. |
|---|
| 151 |
*/ |
|---|
| 152 |
void DtoAggrCopy(LLValue* dst, LLValue* src); |
|---|
| 153 |
|
|---|
| 154 |
/** |
|---|
| 155 |
* Generates a call to llvm.memory.barrier |
|---|
| 156 |
* @param ll load-load |
|---|
| 157 |
* @param ls load-store |
|---|
| 158 |
* @param sl store-load |
|---|
| 159 |
* @param ss store-store |
|---|
| 160 |
* @param device special device flag |
|---|
| 161 |
*/ |
|---|
| 162 |
void DtoMemoryBarrier(bool ll, bool ls, bool sl, bool ss, bool device=false); |
|---|
| 163 |
|
|---|
| 164 |
#include "enums.h" |
|---|
| 165 |
|
|---|
| 166 |
#endif // LDC_GEN_TOLLVM_H |
|---|