|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "mlir-c/Dialect/LLVM.h"
|
| 10 | +#include "mlir-c/IR.h" |
| 11 | +#include "mlir-c/Support.h" |
10 | 12 | #include "mlir/CAPI/Registration.h"
|
| 13 | +#include "mlir/CAPI/Wrap.h" |
| 14 | +#include "mlir/Dialect/LLVMIR/LLVMAttrs.h" |
11 | 15 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
| 16 | +#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.h.inc" |
12 | 17 | #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
|
| 18 | +#include "mlir/IR/Attributes.h" |
| 19 | +#include "mlir/IR/BuiltinAttributes.h" |
| 20 | +#include <stdint.h> |
13 | 21 |
|
14 | 22 | using namespace mlir;
|
15 | 23 | using namespace mlir::LLVM;
|
@@ -110,3 +118,158 @@ MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType,
|
110 | 118 | cast<LLVM::LLVMStructType>(unwrap(structType))
|
111 | 119 | .setBody(unwrapList(nFieldTypes, fieldTypes, fields), isPacked));
|
112 | 120 | }
|
| 121 | + |
| 122 | +/* fails to compile with: error: no viable conversion from 'mlir::Attribute' to |
| 123 | +'ValueParamT' (aka 'mlir::LLVM::DIExpressionElemAttr') MlirAttribute |
| 124 | +mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations, MlirAttribute |
| 125 | +const *operations) { SmallVector<DIExpressionElemAttr, 2> valueStorage; return |
| 126 | +wrap(DIExpressionAttr::get( unwrap(ctx), unwrapList(nOperations, operations, |
| 127 | +valueStorage))); |
| 128 | +} |
| 129 | +*/ |
| 130 | + |
| 131 | +MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) { |
| 132 | + return wrap(DINullTypeAttr::get(unwrap(ctx))); |
| 133 | +} |
| 134 | + |
| 135 | +MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag, |
| 136 | + MlirAttribute name, |
| 137 | + uint64_t sizeInBits, |
| 138 | + unsigned int encoding) { |
| 139 | + return wrap(DIBasicTypeAttr::get( |
| 140 | + unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, encoding)); |
| 141 | +} |
| 142 | + |
| 143 | +/* fails to compile with: error: no viable conversion from 'mlir::Attribute' to |
| 144 | +'ValueParamT' (aka 'mlir::LLVM::DINodeAttr') MlirAttribute |
| 145 | +mlirLLVMDICompositeTypeAttrGet( MlirContext ctx, unsigned int tag, MlirAttribute |
| 146 | +name, MlirAttribute file, uint32_t line, MlirAttribute scope, MlirAttribute |
| 147 | +baseType, int64_t flags, uint64_t sizeInBits, uint64_t alignInBits, intptr_t |
| 148 | +nElements, MlirAttribute const *elements) { |
| 149 | + SmallVector<DINodeAttr, 2> |
| 150 | +elementsStorage; elementsStorage.reserve(nElements); mlir::ArrayRef<DINodeAttr> |
| 151 | +list = unwrapList(nElements, elements, elementsStorage); return |
| 152 | +wrap(DICompositeTypeAttr::get( unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), |
| 153 | + cast<DIFileAttr>(unwrap(file)), line, cast<DIScopeAttr>(unwrap(scope)), |
| 154 | + cast<DITypeAttr>(unwrap(baseType)), DIFlags(flags), sizeInBits, |
| 155 | + alignInBits, list)); |
| 156 | +} |
| 157 | +*/ |
| 158 | + |
| 159 | +MlirAttribute mlirLLVMDIDerivedTypeAttrGet(MlirContext ctx, unsigned int tag, |
| 160 | + MlirAttribute name, |
| 161 | + MlirAttribute baseType, |
| 162 | + uint64_t sizeInBits, |
| 163 | + uint32_t alignInBits, |
| 164 | + uint64_t offsetInBits) { |
| 165 | + return wrap(DIDerivedTypeAttr::get(unwrap(ctx), tag, |
| 166 | + cast<StringAttr>(unwrap(name)), |
| 167 | + cast<DITypeAttr>(unwrap(baseType)), |
| 168 | + sizeInBits, alignInBits, offsetInBits)); |
| 169 | +} |
| 170 | + |
| 171 | +MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, uint64_t cconv) { |
| 172 | + return wrap(CConvAttr::get(unwrap(ctx), CConv(cconv))); |
| 173 | +} |
| 174 | + |
| 175 | +MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, uint64_t comdat) { |
| 176 | + return wrap(ComdatAttr::get(unwrap(ctx), comdat::Comdat(comdat))); |
| 177 | +} |
| 178 | + |
| 179 | +MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, uint64_t linkage) { |
| 180 | + return wrap(LinkageAttr::get(unwrap(ctx), linkage::Linkage(linkage))); |
| 181 | +} |
| 182 | + |
| 183 | +MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name, |
| 184 | + MlirAttribute directory) { |
| 185 | + return wrap(DIFileAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)), |
| 186 | + cast<StringAttr>(unwrap(directory)))); |
| 187 | +} |
| 188 | + |
| 189 | +MlirAttribute mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id, |
| 190 | + unsigned int sourceLanguage, |
| 191 | + MlirAttribute file, |
| 192 | + MlirAttribute producer, |
| 193 | + bool isOptimized, |
| 194 | + uint64_t emissionKind) { |
| 195 | + return wrap(DICompileUnitAttr::get( |
| 196 | + unwrap(ctx), cast<DistinctAttr>(unwrap(id)), sourceLanguage, |
| 197 | + cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)), |
| 198 | + isOptimized, DIEmissionKind(emissionKind))); |
| 199 | +} |
| 200 | + |
| 201 | +MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) { |
| 202 | + return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value))); |
| 203 | +} |
| 204 | + |
| 205 | +MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, |
| 206 | + MlirAttribute scope, |
| 207 | + MlirAttribute file, |
| 208 | + unsigned int line, |
| 209 | + unsigned int column) { |
| 210 | + return wrap( |
| 211 | + DILexicalBlockAttr::get(unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)), |
| 212 | + cast<DIFileAttr>(unwrap(file)), line, column)); |
| 213 | +} |
| 214 | + |
| 215 | +MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, |
| 216 | + MlirAttribute scope, |
| 217 | + MlirAttribute file, |
| 218 | + unsigned int discriminator) { |
| 219 | + return wrap(DILexicalBlockFileAttr::get( |
| 220 | + unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)), |
| 221 | + cast<DIFileAttr>(unwrap(file)), discriminator)); |
| 222 | +} |
| 223 | + |
| 224 | +MlirAttribute |
| 225 | +mlirLLVMDILocalVariableAttrGet(MlirContext ctx, MlirAttribute scope, |
| 226 | + MlirAttribute name, MlirAttribute diFile, |
| 227 | + unsigned int line, unsigned int arg, |
| 228 | + unsigned int alignInBits, MlirAttribute diType) { |
| 229 | + return wrap(DILocalVariableAttr::get( |
| 230 | + unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)), |
| 231 | + cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line, |
| 232 | + arg, alignInBits, cast<DITypeAttr>(unwrap(diType)))); |
| 233 | +} |
| 234 | + |
| 235 | +// fails to compile with error: no viable conversion from 'mlir::Attribute' to |
| 236 | +// 'ValueParamT' (aka 'mlir::LLVM::DITypeAttr') |
| 237 | +/* |
| 238 | +MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, |
| 239 | + unsigned int callingConvention, |
| 240 | + intptr_t nTypes, |
| 241 | + MlirAttribute const *types) { |
| 242 | + SmallVector<DITypeAttr, 2> elementsStorage; |
| 243 | + elementsStorage.reserve(nTypes); |
| 244 | + mlir::ArrayRef<DITypeAttr> list = unwrapList(nTypes, types, elementsStorage); |
| 245 | + return wrap(DISubroutineTypeAttr::get(unwrap(ctx), callingConvention, list)); |
| 246 | +} |
| 247 | +*/ |
| 248 | + |
| 249 | +MlirAttribute mlirLLVMDISubprogramAttrGet( |
| 250 | + MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit, |
| 251 | + MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName, |
| 252 | + MlirAttribute file, unsigned int line, unsigned int scopeLine, |
| 253 | + uint64_t subprogramFlags, MlirAttribute type) { |
| 254 | + return wrap(DISubprogramAttr::get( |
| 255 | + unwrap(ctx), cast<DistinctAttr>(unwrap(id)), |
| 256 | + cast<DICompileUnitAttr>(unwrap(compileUnit)), |
| 257 | + cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)), |
| 258 | + cast<StringAttr>(unwrap(linkageName)), cast<DIFileAttr>(unwrap(file)), |
| 259 | + line, scopeLine, DISubprogramFlags(subprogramFlags), |
| 260 | + cast<DISubroutineTypeAttr>(unwrap(type)))); |
| 261 | +} |
| 262 | + |
| 263 | +MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file, |
| 264 | + MlirAttribute scope, MlirAttribute name, |
| 265 | + MlirAttribute configMacros, |
| 266 | + MlirAttribute includePath, |
| 267 | + MlirAttribute apinotes, unsigned int line, |
| 268 | + bool isDecl) { |
| 269 | + return wrap(DIModuleAttr::get( |
| 270 | + unwrap(ctx), cast<DIFileAttr>(unwrap(file)), |
| 271 | + cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)), |
| 272 | + cast<StringAttr>(unwrap(configMacros)), |
| 273 | + cast<StringAttr>(unwrap(includePath)), cast<StringAttr>(unwrap(apinotes)), |
| 274 | + line, isDecl)); |
| 275 | +} |
0 commit comments