20 #include "llvm/ADT/TypeSwitch.h"
21 #include "llvm/IR/DIBuilder.h"
22 #include "llvm/IR/IRBuilder.h"
23 #include "llvm/IR/InlineAsm.h"
24 #include "llvm/IR/Instructions.h"
25 #include "llvm/IR/MDBuilder.h"
26 #include "llvm/IR/MatrixBuilder.h"
32 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
35 using llvmFMF = llvm::FastMathFlags;
36 using FuncT = void (llvmFMF::*)(bool);
37 const std::pair<FastmathFlags, FuncT> handlers[] = {
39 {FastmathFlags::nnan, &llvmFMF::setNoNaNs},
40 {FastmathFlags::ninf, &llvmFMF::setNoInfs},
41 {FastmathFlags::nsz, &llvmFMF::setNoSignedZeros},
42 {FastmathFlags::arcp, &llvmFMF::setAllowReciprocal},
44 {FastmathFlags::afn, &llvmFMF::setApproxFunc},
45 {FastmathFlags::reassoc, &llvmFMF::setAllowReassoc},
48 llvm::FastMathFlags ret;
49 ::mlir::LLVM::FastmathFlags fmfMlir = op.getFastmathAttr().getValue();
50 for (
auto it : handlers)
51 if (bitEnumContainsAll(fmfMlir, it.first))
52 (ret.*(it.second))(
true);
59 llvm::append_range(position, indices);
64 static std::string
diagStr(
const llvm::Type *type) {
66 llvm::raw_string_ostream os(str);
74 static FailureOr<llvm::Function *>
77 LLVM::ModuleTranslation &moduleTranslation) {
79 for (
Type type : op->getOperandTypes())
80 allArgTys.push_back(moduleTranslation.convertType(type));
83 if (op.getNumResults() == 0)
84 resTy = llvm::Type::getVoidTy(module->getContext());
86 resTy = moduleTranslation.convertType(op.getResult(0).getType());
92 getIntrinsicInfoTableEntries(
id,
table);
96 if (llvm::Intrinsic::matchIntrinsicSignature(ft, tableRef,
98 llvm::Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
100 <<
diagStr(ft) <<
" to overloaded intrinsic " << op.getIntrinAttr()
101 <<
" does not match any of the overloads";
105 return llvm::Intrinsic::getOrInsertDeclaration(module,
id,
106 overloadedArgTysRef);
109 static llvm::OperandBundleDef
111 LLVM::ModuleTranslation &moduleTranslation) {
112 std::vector<llvm::Value *> operands;
113 operands.reserve(bundleOperands.size());
114 for (
Value bundleArg : bundleOperands)
115 operands.push_back(moduleTranslation.lookupValue(bundleArg));
116 return llvm::OperandBundleDef(bundleTag.str(), std::move(operands));
121 LLVM::ModuleTranslation &moduleTranslation) {
123 bundles.reserve(bundleOperands.size());
125 for (
auto [operands, tagAttr] : llvm::zip_equal(bundleOperands, bundleTags)) {
126 StringRef tag = cast<StringAttr>(tagAttr).getValue();
134 std::optional<ArrayAttr> bundleTags,
135 LLVM::ModuleTranslation &moduleTranslation) {
144 LLVM::ModuleTranslation &moduleTranslation) {
145 llvm::Module *module = builder.GetInsertBlock()->getModule();
147 llvm::Intrinsic::lookupIntrinsicID(op.getIntrinAttr());
150 << op.getIntrinAttr();
152 llvm::Function *fn =
nullptr;
153 if (llvm::Intrinsic::isOverloaded(
id)) {
160 fn = llvm::Intrinsic::getOrInsertDeclaration(module,
id, {});
164 const llvm::Type *intrinType =
165 op.getNumResults() == 0
166 ? llvm::Type::getVoidTy(module->getContext())
167 : moduleTranslation.convertType(op.getResultTypes().front());
168 if (intrinType != fn->getReturnType()) {
170 <<
diagStr(intrinType) <<
" but " << op.getIntrinAttr()
171 <<
" actually returns " <<
diagStr(fn->getReturnType());
176 if (!fn->getFunctionType()->isVarArg() &&
177 op.getArgs().size() != fn->arg_size()) {
179 << op.getArgs().size() <<
" operands but " << op.getIntrinAttr()
180 <<
" expects " << fn->arg_size();
182 if (fn->getFunctionType()->isVarArg() &&
183 op.getArgs().size() < fn->arg_size()) {
185 << op.getArgs().size() <<
" operands but variadic "
186 << op.getIntrinAttr() <<
" expects at least " << fn->arg_size();
189 for (
unsigned i = 0, e = fn->arg_size(); i != e; ++i) {
190 const llvm::Type *expected = fn->getArg(i)->getType();
191 const llvm::Type *actual =
192 moduleTranslation.convertType(op.getOperandTypes()[i]);
193 if (actual != expected) {
195 << i <<
" has type " <<
diagStr(actual) <<
" but "
196 << op.getIntrinAttr() <<
" expects " <<
diagStr(expected);
200 FastmathFlagsInterface itf = op;
203 auto *inst = builder.CreateCall(
204 fn, moduleTranslation.lookupValues(op.getArgs()),
208 if (
failed(moduleTranslation.convertArgAndResultAttrs(op, inst)))
211 if (op.getNumResults() == 1)
212 moduleTranslation.mapValue(op->getResults().front()) = inst;
217 llvm::IRBuilderBase &builder,
218 LLVM::ModuleTranslation &moduleTranslation) {
219 llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
220 llvm::LLVMContext &context = llvmModule->getContext();
221 llvm::NamedMDNode *linkerMDNode =
222 llvmModule->getOrInsertNamedMetadata(
"llvm.linker.options");
224 MDNodes.reserve(
options.size());
225 for (
auto s :
options.getAsRange<StringAttr>()) {
227 MDNodes.push_back(MDNode);
231 linkerMDNode->addOperand(listMDNode);
234 static llvm::Metadata *
236 llvm::IRBuilderBase &builder,
237 LLVM::ModuleTranslation &moduleTranslation) {
238 llvm::LLVMContext &context = builder.getContext();
239 llvm::MDBuilder mdb(context);
242 if (key == LLVMDialect::getModuleFlagKeyCGProfileName()) {
243 for (
auto entry : arrayAttr.getAsRange<ModuleFlagCGProfileEntryAttr>()) {
244 llvm::Metadata *fromMetadata =
247 entry.getFrom().getValue()))
249 llvm::Metadata *toMetadata =
252 moduleTranslation.lookupFunction(entry.getTo().getValue()))
255 llvm::Metadata *vals[] = {
256 fromMetadata, toMetadata,
258 llvm::Type::getInt64Ty(context), entry.getCount()))};
261 return llvm::MDTuple::getDistinct(context, nodes);
267 StringRef key, ModuleFlagProfileSummaryAttr summaryAttr,
268 llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation) {
269 llvm::LLVMContext &context = builder.getContext();
270 llvm::MDBuilder mdb(context);
272 auto getIntTuple = [&](StringRef key, uint64_t val) -> llvm::MDTuple * {
275 llvm::Type::getInt64Ty(context), val))};
280 mdb.createString(
"ProfileFormat"),
282 stringifyProfileSummaryFormatKind(summaryAttr.getFormat()))};
286 getIntTuple(
"TotalCount", summaryAttr.getTotalCount()),
287 getIntTuple(
"MaxCount", summaryAttr.getMaxCount()),
288 getIntTuple(
"MaxInternalCount", summaryAttr.getMaxInternalCount()),
289 getIntTuple(
"MaxFunctionCount", summaryAttr.getMaxFunctionCount()),
290 getIntTuple(
"NumCounts", summaryAttr.getNumCounts()),
291 getIntTuple(
"NumFunctions", summaryAttr.getNumFunctions()),
294 if (summaryAttr.getIsPartialProfile())
296 getIntTuple(
"IsPartialProfile", *summaryAttr.getIsPartialProfile()));
298 if (summaryAttr.getPartialProfileRatio()) {
300 mdb.createString(
"PartialProfileRatio"),
302 llvm::Type::getDoubleTy(context),
303 summaryAttr.getPartialProfileRatio().getValue()))};
308 llvm::Type *llvmInt64Type = llvm::Type::getInt64Ty(context);
309 for (ModuleFlagProfileSummaryDetailedAttr detailedEntry :
310 summaryAttr.getDetailedSummary()) {
317 llvmInt64Type, detailedEntry.getNumCounts()))};
321 mdb.createString(
"DetailedSummary"),
329 LLVM::ModuleTranslation &moduleTranslation) {
330 llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
331 for (
auto flagAttr : flags.getAsRange<ModuleFlagAttr>()) {
332 llvm::Metadata *valueMetadata =
334 .Case<StringAttr>([&](
auto strAttr) {
338 .Case<IntegerAttr>([&](
auto intAttr) {
340 llvm::Type::getInt32Ty(builder.getContext()),
343 .Case<ArrayAttr>([&](
auto arrayAttr) {
348 .Case([&](ModuleFlagProfileSummaryAttr summaryAttr) {
350 flagAttr.getKey().getValue(), summaryAttr, builder,
353 .Default([](
auto) {
return nullptr; });
355 assert(valueMetadata &&
"expected valid metadata");
356 llvmModule->addModuleFlag(
357 convertModFlagBehaviorToLLVM(flagAttr.getBehavior()),
358 flagAttr.getKey().getValue(), valueMetadata);
362 static llvm::DILocalScope *
364 LLVM::ModuleTranslation &moduleTranslation) {
367 if (
auto *localScope = llvm::dyn_cast<llvm::DILocalScope>(
368 moduleTranslation.translateDebugInfo(scopeLoc.getMetadata())))
370 return builder.GetInsertBlock()->getParent()->getSubprogram();
375 LLVM::ModuleTranslation &moduleTranslation) {
377 llvm::IRBuilder<>::FastMathFlagGuard fmfGuard(builder);
378 if (
auto fmf = dyn_cast<FastmathFlagsInterface>(opInst))
381 #include "mlir/Dialect/LLVMIR/LLVMConversions.inc"
382 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicConversions.inc"
388 if (
auto callOp = dyn_cast<LLVM::CallOp>(opInst)) {
389 auto operands = moduleTranslation.lookupValues(callOp.getCalleeOperands());
392 callOp.getOpBundleTags(), moduleTranslation);
394 llvm::CallInst *call;
395 if (
auto attr = callOp.getCalleeAttr()) {
396 if (llvm::Function *
function =
397 moduleTranslation.lookupFunction(attr.getValue())) {
398 call = builder.CreateCall(
function, operandsRef, opBundles);
402 moduleTranslation.symbolTable().lookupSymbolIn(moduleOp, attr);
403 llvm::GlobalValue *ifunc = moduleTranslation.lookupIFunc(ifuncOp);
404 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
405 moduleTranslation.convertType(callOp.getCalleeFunctionType()));
406 call = builder.CreateCall(calleeType, ifunc, operandsRef, opBundles);
409 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
410 moduleTranslation.convertType(callOp.getCalleeFunctionType()));
411 call = builder.CreateCall(calleeType, operandsRef.front(),
412 operandsRef.drop_front(), opBundles);
414 call->setCallingConv(convertCConvToLLVM(callOp.getCConv()));
415 call->setTailCallKind(convertTailCallKindToLLVM(callOp.getTailCallKind()));
416 if (callOp.getConvergentAttr())
417 call->addFnAttr(llvm::Attribute::Convergent);
418 if (callOp.getNoUnwindAttr())
419 call->addFnAttr(llvm::Attribute::NoUnwind);
420 if (callOp.getWillReturnAttr())
421 call->addFnAttr(llvm::Attribute::WillReturn);
422 if (callOp.getNoInlineAttr())
423 call->addFnAttr(llvm::Attribute::NoInline);
424 if (callOp.getAlwaysInlineAttr())
425 call->addFnAttr(llvm::Attribute::AlwaysInline);
426 if (callOp.getInlineHintAttr())
427 call->addFnAttr(llvm::Attribute::InlineHint);
429 if (
failed(moduleTranslation.convertArgAndResultAttrs(callOp, call)))
432 if (MemoryEffectsAttr memAttr = callOp.getMemoryEffectsAttr()) {
433 llvm::MemoryEffects memEffects =
434 llvm::MemoryEffects(llvm::MemoryEffects::Location::ArgMem,
435 convertModRefInfoToLLVM(memAttr.getArgMem())) |
437 llvm::MemoryEffects::Location::InaccessibleMem,
438 convertModRefInfoToLLVM(memAttr.getInaccessibleMem())) |
439 llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
440 convertModRefInfoToLLVM(memAttr.getOther()));
441 call->setMemoryEffects(memEffects);
444 moduleTranslation.setAccessGroupsMetadata(callOp, call);
445 moduleTranslation.setAliasScopeMetadata(callOp, call);
446 moduleTranslation.setTBAAMetadata(callOp, call);
450 moduleTranslation.mapValue(opInst.
getResult(0), call);
452 else if (!call->getType()->isVoidTy())
454 moduleTranslation.mapCall(callOp, call);
458 if (
auto inlineAsmOp = dyn_cast<LLVM::InlineAsmOp>(opInst)) {
462 llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
465 if (inlineAsmOp.getNumResults() == 0) {
468 assert(inlineAsmOp.getNumResults() == 1);
469 resultType = inlineAsmOp.getResultTypes()[0];
472 llvm::InlineAsm *inlineAsmInst =
473 inlineAsmOp.getAsmDialect()
475 static_cast<llvm::FunctionType *
>(
476 moduleTranslation.convertType(ft)),
477 inlineAsmOp.getAsmString(), inlineAsmOp.getConstraints(),
478 inlineAsmOp.getHasSideEffects(),
479 inlineAsmOp.getIsAlignStack(),
480 convertAsmDialectToLLVM(*inlineAsmOp.getAsmDialect()))
482 moduleTranslation.convertType(ft)),
483 inlineAsmOp.getAsmString(),
484 inlineAsmOp.getConstraints(),
485 inlineAsmOp.getHasSideEffects(),
486 inlineAsmOp.getIsAlignStack());
487 llvm::CallInst *inst = builder.CreateCall(
489 moduleTranslation.lookupValues(inlineAsmOp.getOperands()));
490 inst->setTailCallKind(convertTailCallKindToLLVM(
491 inlineAsmOp.getTailCallKindAttr().getTailCallKind()));
492 if (
auto maybeOperandAttrs = inlineAsmOp.getOperandAttrs()) {
493 llvm::AttributeList attrList;
498 DictionaryAttr dAttr = cast<DictionaryAttr>(attr);
502 cast<TypeAttr>(dAttr.get(InlineAsmOp::getElementTypeAttrName()));
503 llvm::AttrBuilder b(moduleTranslation.getLLVMContext());
504 llvm::Type *ty = moduleTranslation.convertType(tAttr.getValue());
505 b.addTypeAttr(llvm::Attribute::ElementType, ty);
509 attrList = attrList.addAttributesAtIndex(
510 moduleTranslation.getLLVMContext(), it.index() + shift, b);
512 inst->setAttributes(attrList);
516 moduleTranslation.mapValue(opInst.
getResult(0), inst);
520 if (
auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
521 auto operands = moduleTranslation.lookupValues(invOp.getCalleeOperands());
524 invOp.getOpBundleTags(), moduleTranslation);
526 llvm::InvokeInst *result;
528 result = builder.CreateInvoke(
529 moduleTranslation.lookupFunction(attr.getValue()),
530 moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
531 moduleTranslation.lookupBlock(invOp.getSuccessor(1)), operandsRef,
534 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
535 moduleTranslation.convertType(invOp.getCalleeFunctionType()));
536 result = builder.CreateInvoke(
537 calleeType, operandsRef.front(),
538 moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
539 moduleTranslation.lookupBlock(invOp.getSuccessor(1)),
540 operandsRef.drop_front(), opBundles);
542 result->setCallingConv(convertCConvToLLVM(invOp.getCConv()));
543 if (
failed(moduleTranslation.convertArgAndResultAttrs(invOp, result)))
545 moduleTranslation.mapBranch(invOp, result);
547 if (invOp->getNumResults() != 0) {
548 moduleTranslation.mapValue(opInst.
getResult(0), result);
551 return success(result->getType()->isVoidTy());
554 if (
auto lpOp = dyn_cast<LLVM::LandingpadOp>(opInst)) {
555 llvm::Type *ty = moduleTranslation.convertType(lpOp.getType());
556 llvm::LandingPadInst *lpi =
557 builder.CreateLandingPad(ty, lpOp.getNumOperands());
558 lpi->setCleanup(lpOp.getCleanup());
561 for (llvm::Value *operand :
562 moduleTranslation.lookupValues(lpOp.getOperands())) {
564 if (
auto *constOperand = dyn_cast<llvm::Constant>(operand))
565 lpi->addClause(constOperand);
567 moduleTranslation.mapValue(lpOp.getResult(), lpi);
573 if (
auto brOp = dyn_cast<LLVM::BrOp>(opInst)) {
574 llvm::BranchInst *branch =
575 builder.CreateBr(moduleTranslation.lookupBlock(brOp.getSuccessor()));
576 moduleTranslation.mapBranch(&opInst, branch);
577 moduleTranslation.setLoopMetadata(&opInst, branch);
580 if (
auto condbrOp = dyn_cast<LLVM::CondBrOp>(opInst)) {
581 llvm::BranchInst *branch = builder.CreateCondBr(
582 moduleTranslation.lookupValue(condbrOp.getOperand(0)),
583 moduleTranslation.lookupBlock(condbrOp.getSuccessor(0)),
584 moduleTranslation.lookupBlock(condbrOp.getSuccessor(1)));
585 moduleTranslation.mapBranch(&opInst, branch);
586 moduleTranslation.setLoopMetadata(&opInst, branch);
589 if (
auto switchOp = dyn_cast<LLVM::SwitchOp>(opInst)) {
590 llvm::SwitchInst *switchInst = builder.CreateSwitch(
591 moduleTranslation.lookupValue(switchOp.getValue()),
592 moduleTranslation.lookupBlock(switchOp.getDefaultDestination()),
593 switchOp.getCaseDestinations().size());
596 if (!switchOp.getCaseValues())
599 auto *ty = llvm::cast<llvm::IntegerType>(
600 moduleTranslation.convertType(switchOp.getValue().getType()));
602 llvm::zip(llvm::cast<DenseIntElementsAttr>(*switchOp.getCaseValues()),
603 switchOp.getCaseDestinations()))
606 moduleTranslation.lookupBlock(std::get<1>(i)));
608 moduleTranslation.mapBranch(&opInst, switchInst);
611 if (
auto indBrOp = dyn_cast<LLVM::IndirectBrOp>(opInst)) {
612 llvm::IndirectBrInst *indBr = builder.CreateIndirectBr(
613 moduleTranslation.lookupValue(indBrOp.getAddr()),
614 indBrOp->getNumSuccessors());
615 for (
auto *succ : indBrOp.getSuccessors())
616 indBr->addDestination(moduleTranslation.lookupBlock(succ));
617 moduleTranslation.mapBranch(&opInst, indBr);
624 if (
auto addressOfOp = dyn_cast<LLVM::AddressOfOp>(opInst)) {
625 LLVM::GlobalOp global =
626 addressOfOp.getGlobal(moduleTranslation.symbolTable());
627 LLVM::LLVMFuncOp
function =
628 addressOfOp.getFunction(moduleTranslation.symbolTable());
629 LLVM::AliasOp alias = addressOfOp.getAlias(moduleTranslation.symbolTable());
630 LLVM::IFuncOp ifunc = addressOfOp.getIFunc(moduleTranslation.symbolTable());
633 assert((global ||
function || alias || ifunc) &&
634 "referencing an undefined global, function, alias, or ifunc");
636 llvm::Value *llvmValue =
nullptr;
638 llvmValue = moduleTranslation.lookupGlobal(global);
640 llvmValue = moduleTranslation.lookupAlias(alias);
642 llvmValue = moduleTranslation.lookupFunction(
function.getName());
644 llvmValue = moduleTranslation.lookupIFunc(ifunc);
646 moduleTranslation.mapValue(addressOfOp.getResult(), llvmValue);
652 if (
auto dsoLocalEquivalentOp =
653 dyn_cast<LLVM::DSOLocalEquivalentOp>(opInst)) {
654 LLVM::LLVMFuncOp
function =
655 dsoLocalEquivalentOp.getFunction(moduleTranslation.symbolTable());
656 LLVM::AliasOp alias =
657 dsoLocalEquivalentOp.getAlias(moduleTranslation.symbolTable());
660 assert((
function || alias) &&
661 "referencing an undefined function, or alias");
663 llvm::Value *llvmValue =
nullptr;
665 llvmValue = moduleTranslation.lookupAlias(alias);
667 llvmValue = moduleTranslation.lookupFunction(
function.getName());
669 moduleTranslation.mapValue(
670 dsoLocalEquivalentOp.getResult(),
677 if (
auto blockAddressOp = dyn_cast<LLVM::BlockAddressOp>(opInst)) {
678 BlockAddressAttr blockAddressAttr = blockAddressOp.getBlockAddr();
679 llvm::BasicBlock *llvmBlock =
680 moduleTranslation.lookupBlockAddress(blockAddressAttr);
682 llvm::Value *llvmValue =
nullptr;
683 StringRef fnName = blockAddressAttr.getFunction().getValue();
685 llvm::Function *llvmFn = moduleTranslation.lookupFunction(fnName);
694 llvmValue =
new llvm::GlobalVariable(
695 *moduleTranslation.getLLVMModule(),
696 llvm::PointerType::getUnqual(moduleTranslation.getLLVMContext()),
697 true, llvm::GlobalValue::LinkageTypes::ExternalLinkage,
699 Twine(
"__mlir_block_address_")
701 .
concat(Twine((uint64_t)blockAddressOp.getOperation())));
702 moduleTranslation.mapUnresolvedBlockAddress(blockAddressOp, llvmValue);
705 moduleTranslation.mapValue(blockAddressOp.getResult(), llvmValue);
711 if (
auto blockTagOp = dyn_cast<LLVM::BlockTagOp>(opInst)) {
712 auto funcOp = blockTagOp->getParentOfType<LLVMFuncOp>();
714 &moduleTranslation.getContext(),
717 blockTagOp.getTag());
718 moduleTranslation.mapBlockAddress(blockAddressAttr,
719 builder.GetInsertBlock());
729 class LLVMDialectLLVMIRTranslationInterface
737 convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
738 LLVM::ModuleTranslation &moduleTranslation)
const final {
745 registry.
insert<LLVM::LLVMDialect>();
747 dialect->addInterfaces<LLVMDialectLLVMIRTranslationInterface>();
static SmallVector< unsigned > extractPosition(ArrayRef< int64_t > indices)
Convert the value of a DenseI64ArrayAttr to a vector of unsigned indices.
static std::string diagStr(const llvm::Type *type)
Convert an LLVM type to a string for printing in diagnostics.
static llvm::Metadata * convertModuleFlagProfileSummaryAttr(StringRef key, ModuleFlagProfileSummaryAttr summaryAttr, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static llvm::DILocalScope * getLocalScopeFromLoc(llvm::IRBuilderBase &builder, Location loc, LLVM::ModuleTranslation &moduleTranslation)
static void convertModuleFlagsOp(ArrayAttr flags, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static FailureOr< llvm::Function * > getOverloadedDeclaration(CallIntrinsicOp op, llvm::Intrinsic::ID id, llvm::Module *module, LLVM::ModuleTranslation &moduleTranslation)
Get the declaration of an overloaded llvm intrinsic.
static LogicalResult convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static SmallVector< llvm::OperandBundleDef > convertOperandBundles(OperandRangeRange bundleOperands, ArrayAttr bundleTags, LLVM::ModuleTranslation &moduleTranslation)
static LogicalResult convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
Builder for LLVM_CallIntrinsicOp.
static llvm::FastMathFlags getFastmathFlags(FastmathFlagsInterface &op)
static llvm::OperandBundleDef convertOperandBundle(OperandRange bundleOperands, StringRef bundleTag, LLVM::ModuleTranslation &moduleTranslation)
static llvm::Metadata * convertModuleFlagValue(StringRef key, ArrayAttr arrayAttr, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static void convertLinkerOptionsOp(ArrayAttr options, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static llvm::ManagedStatic< PassManagerOptions > options
static void contract(RootOrderingGraph &graph, ArrayRef< Value > cycle, const DenseMap< Value, unsigned > &parentDepths, DenseMap< Value, Value > &actualSource, DenseMap< Value, Value > &actualTarget)
Contracts the specified cycle in the given graph in-place.
Attributes are known-constant values of operations.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
A symbol reference with a reference path containing a single element.
static FlatSymbolRefAttr get(StringAttr value)
Construct a symbol reference for the given value name.
This class represents a fused location whose metadata is known to be an instance of the given type.
Base class for dialect interfaces providing translation to LLVM IR.
LLVMTranslationDialectInterface(Dialect *dialect)
T findInstanceOf()
Return an instance of the given location type if one is nested under the current location.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
void appendDialectRegistry(const DialectRegistry ®istry)
Append the contents of the given dialect registry to the registry associated with this context.
This class represents a contiguous range of operand ranges, e.g.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
AttrClass getAttrOfType(StringAttr name)
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
unsigned getNumResults()
Return the number of results held by this operation.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
llvm::Constant * getLLVMConstant(llvm::Type *llvmType, Attribute attr, Location loc, const ModuleTranslation &moduleTranslation)
Create an LLVM IR constant of llvmType from the MLIR attribute attr.
Operation * parentLLVMModule(Operation *op)
Lookup parent Module satisfying LLVM conditions on the Module Operation.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
SmallVector< AffineExpr, 4 > concat(ArrayRef< AffineExpr > a, ArrayRef< AffineExpr > b)
Return the vector that is the concatenation of a and b.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
void registerLLVMDialectTranslation(DialectRegistry ®istry)
Register the LLVM dialect and the translation from it to the LLVM IR in the given registry;.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...