19 #include "llvm/ADT/TypeSwitch.h"
20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/IR/InlineAsm.h"
22 #include "llvm/IR/Instructions.h"
23 #include "llvm/IR/MDBuilder.h"
24 #include "llvm/IR/MatrixBuilder.h"
25 #include "llvm/IR/Operator.h"
31 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
34 using llvmFMF = llvm::FastMathFlags;
35 using FuncT = void (llvmFMF::*)(bool);
36 const std::pair<FastmathFlags, FuncT> handlers[] = {
38 {FastmathFlags::nnan, &llvmFMF::setNoNaNs},
39 {FastmathFlags::ninf, &llvmFMF::setNoInfs},
40 {FastmathFlags::nsz, &llvmFMF::setNoSignedZeros},
41 {FastmathFlags::arcp, &llvmFMF::setAllowReciprocal},
43 {FastmathFlags::afn, &llvmFMF::setApproxFunc},
44 {FastmathFlags::reassoc, &llvmFMF::setAllowReassoc},
47 llvm::FastMathFlags ret;
48 ::mlir::LLVM::FastmathFlags fmfMlir = op.getFastmathAttr().getValue();
49 for (
auto it : handlers)
50 if (bitEnumContainsAll(fmfMlir, it.first))
51 (ret.*(it.second))(
true);
58 llvm::append_range(position, indices);
63 static std::string
diagStr(
const llvm::Type *type) {
65 llvm::raw_string_ostream os(str);
73 static FailureOr<llvm::Function *>
78 for (
Type type : op->getOperandTypes())
79 allArgTys.push_back(moduleTranslation.
convertType(type));
82 if (op.getNumResults() == 0)
83 resTy = llvm::Type::getVoidTy(module->getContext());
85 resTy = moduleTranslation.
convertType(op.getResult(0).getType());
91 getIntrinsicInfoTableEntries(
id,
table);
95 if (llvm::Intrinsic::matchIntrinsicSignature(ft, tableRef,
97 llvm::Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
99 <<
diagStr(ft) <<
" to overloaded intrinsic " << op.getIntrinAttr()
100 <<
" does not match any of the overloads";
104 return llvm::Intrinsic::getOrInsertDeclaration(module,
id,
105 overloadedArgTysRef);
108 static llvm::OperandBundleDef
111 std::vector<llvm::Value *> operands;
112 operands.reserve(bundleOperands.size());
113 for (
Value bundleArg : bundleOperands)
114 operands.push_back(moduleTranslation.
lookupValue(bundleArg));
115 return llvm::OperandBundleDef(bundleTag.str(), std::move(operands));
122 bundles.reserve(bundleOperands.size());
124 for (
auto [operands, tagAttr] : llvm::zip_equal(bundleOperands, bundleTags)) {
125 StringRef tag = cast<StringAttr>(tagAttr).getValue();
133 std::optional<ArrayAttr> bundleTags,
142 ArrayAttr resAttrsArray, llvm::CallBase *call,
146 if (
auto argAttrs = cast<DictionaryAttr>(argAttrsAttr);
148 FailureOr<llvm::AttrBuilder> attrBuilder =
150 if (failed(attrBuilder))
152 call->addParamAttrs(argIdx, *attrBuilder);
157 if (resAttrsArray && resAttrsArray.size() > 0) {
158 if (resAttrsArray.size() != 1)
160 if (
auto resAttrs = cast<DictionaryAttr>(resAttrsArray[0]);
162 FailureOr<llvm::AttrBuilder> attrBuilder =
164 if (failed(attrBuilder))
166 call->addRetAttrs(*attrBuilder);
176 callOp.getLoc(), callOp.getArgAttrsAttr(), callOp.getResAttrsAttr(), call,
184 llvm::Module *module = builder.GetInsertBlock()->getModule();
186 llvm::Intrinsic::lookupIntrinsicID(op.getIntrinAttr());
189 << op.getIntrinAttr();
191 llvm::Function *fn =
nullptr;
192 if (llvm::Intrinsic::isOverloaded(
id)) {
195 if (failed(fnOrFailure))
199 fn = llvm::Intrinsic::getOrInsertDeclaration(module,
id, {});
203 const llvm::Type *intrinType =
204 op.getNumResults() == 0
205 ? llvm::Type::getVoidTy(module->getContext())
206 : moduleTranslation.
convertType(op.getResultTypes().front());
207 if (intrinType != fn->getReturnType()) {
209 <<
diagStr(intrinType) <<
" but " << op.getIntrinAttr()
210 <<
" actually returns " <<
diagStr(fn->getReturnType());
215 if (!fn->getFunctionType()->isVarArg() &&
216 op.getArgs().size() != fn->arg_size()) {
218 << op.getArgs().size() <<
" operands but " << op.getIntrinAttr()
219 <<
" expects " << fn->arg_size();
221 if (fn->getFunctionType()->isVarArg() &&
222 op.getArgs().size() < fn->arg_size()) {
224 << op.getArgs().size() <<
" operands but variadic "
225 << op.getIntrinAttr() <<
" expects at least " << fn->arg_size();
228 for (
unsigned i = 0, e = fn->arg_size(); i != e; ++i) {
229 const llvm::Type *expected = fn->getArg(i)->getType();
230 const llvm::Type *actual =
231 moduleTranslation.
convertType(op.getOperandTypes()[i]);
232 if (actual != expected) {
234 << i <<
" has type " <<
diagStr(actual) <<
" but "
235 << op.getIntrinAttr() <<
" expects " <<
diagStr(expected);
239 FastmathFlagsInterface itf = op;
242 auto *inst = builder.CreateCall(
248 op.getResAttrsAttr(), inst,
252 if (op.getNumResults() == 1)
253 moduleTranslation.
mapValue(op->getResults().front()) = inst;
258 llvm::IRBuilderBase &builder,
260 llvm::Module *llvmModule = moduleTranslation.
getLLVMModule();
261 llvm::LLVMContext &context = llvmModule->getContext();
262 llvm::NamedMDNode *linkerMDNode =
263 llvmModule->getOrInsertNamedMetadata(
"llvm.linker.options");
265 MDNodes.reserve(
options.size());
266 for (
auto s :
options.getAsRange<StringAttr>()) {
268 MDNodes.push_back(MDNode);
272 linkerMDNode->addOperand(listMDNode);
275 static llvm::Metadata *
277 llvm::IRBuilderBase &builder,
279 llvm::LLVMContext &context = builder.getContext();
280 llvm::MDBuilder mdb(context);
283 if (key == LLVMDialect::getModuleFlagKeyCGProfileName()) {
284 for (
auto entry : arrayAttr.getAsRange<ModuleFlagCGProfileEntryAttr>()) {
285 llvm::Metadata *fromMetadata =
288 entry.getFrom().getValue()))
290 llvm::Metadata *toMetadata =
296 llvm::Metadata *vals[] = {
297 fromMetadata, toMetadata,
299 llvm::Type::getInt64Ty(context), entry.getCount()))};
302 return llvm::MDTuple::getDistinct(context, nodes);
308 StringRef key, ModuleFlagProfileSummaryAttr summaryAttr,
310 llvm::LLVMContext &context = builder.getContext();
311 llvm::MDBuilder mdb(context);
313 auto getIntTuple = [&](StringRef key, uint64_t val) -> llvm::MDTuple * {
316 llvm::Type::getInt64Ty(context), val))};
321 mdb.createString(
"ProfileFormat"),
323 stringifyProfileSummaryFormatKind(summaryAttr.getFormat()))};
327 getIntTuple(
"TotalCount", summaryAttr.getTotalCount()),
328 getIntTuple(
"MaxCount", summaryAttr.getMaxCount()),
329 getIntTuple(
"MaxInternalCount", summaryAttr.getMaxInternalCount()),
330 getIntTuple(
"MaxFunctionCount", summaryAttr.getMaxFunctionCount()),
331 getIntTuple(
"NumCounts", summaryAttr.getNumCounts()),
332 getIntTuple(
"NumFunctions", summaryAttr.getNumFunctions()),
335 if (summaryAttr.getIsPartialProfile())
337 getIntTuple(
"IsPartialProfile", *summaryAttr.getIsPartialProfile()));
339 if (summaryAttr.getPartialProfileRatio()) {
341 mdb.createString(
"PartialProfileRatio"),
343 llvm::Type::getDoubleTy(context),
344 summaryAttr.getPartialProfileRatio().getValue()))};
349 llvm::Type *llvmInt64Type = llvm::Type::getInt64Ty(context);
350 for (ModuleFlagProfileSummaryDetailedAttr detailedEntry :
351 summaryAttr.getDetailedSummary()) {
358 llvmInt64Type, detailedEntry.getNumCounts()))};
362 mdb.createString(
"DetailedSummary"),
371 llvm::Module *llvmModule = moduleTranslation.
getLLVMModule();
372 for (
auto flagAttr : flags.getAsRange<ModuleFlagAttr>()) {
373 llvm::Metadata *valueMetadata =
375 .Case<StringAttr>([&](
auto strAttr) {
379 .Case<IntegerAttr>([&](
auto intAttr) {
381 llvm::Type::getInt32Ty(builder.getContext()),
384 .Case<ArrayAttr>([&](
auto arrayAttr) {
389 .Case([&](ModuleFlagProfileSummaryAttr summaryAttr) {
391 flagAttr.getKey().getValue(), summaryAttr, builder,
394 .Default([](
auto) {
return nullptr; });
396 assert(valueMetadata &&
"expected valid metadata");
397 llvmModule->addModuleFlag(
398 convertModFlagBehaviorToLLVM(flagAttr.getBehavior()),
399 flagAttr.getKey().getValue(), valueMetadata);
407 llvm::IRBuilder<>::FastMathFlagGuard fmfGuard(builder);
408 if (
auto fmf = dyn_cast<FastmathFlagsInterface>(opInst))
411 #include "mlir/Dialect/LLVMIR/LLVMConversions.inc"
412 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicConversions.inc"
418 if (
auto callOp = dyn_cast<LLVM::CallOp>(opInst)) {
419 auto operands = moduleTranslation.
lookupValues(callOp.getCalleeOperands());
422 callOp.getOpBundleTags(), moduleTranslation);
424 llvm::CallInst *call;
425 if (
auto attr = callOp.getCalleeAttr()) {
427 builder.CreateCall(moduleTranslation.
lookupFunction(attr.getValue()),
428 operandsRef, opBundles);
430 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
431 moduleTranslation.
convertType(callOp.getCalleeFunctionType()));
432 call = builder.CreateCall(calleeType, operandsRef.front(),
433 operandsRef.drop_front(), opBundles);
435 call->setCallingConv(convertCConvToLLVM(callOp.getCConv()));
436 call->setTailCallKind(convertTailCallKindToLLVM(callOp.getTailCallKind()));
437 if (callOp.getConvergentAttr())
438 call->addFnAttr(llvm::Attribute::Convergent);
439 if (callOp.getNoUnwindAttr())
440 call->addFnAttr(llvm::Attribute::NoUnwind);
441 if (callOp.getWillReturnAttr())
442 call->addFnAttr(llvm::Attribute::WillReturn);
443 if (callOp.getNoInlineAttr())
444 call->addFnAttr(llvm::Attribute::NoInline);
445 if (callOp.getAlwaysInlineAttr())
446 call->addFnAttr(llvm::Attribute::AlwaysInline);
447 if (callOp.getInlineHintAttr())
448 call->addFnAttr(llvm::Attribute::InlineHint);
453 if (MemoryEffectsAttr memAttr = callOp.getMemoryEffectsAttr()) {
454 llvm::MemoryEffects memEffects =
455 llvm::MemoryEffects(llvm::MemoryEffects::Location::ArgMem,
456 convertModRefInfoToLLVM(memAttr.getArgMem())) |
458 llvm::MemoryEffects::Location::InaccessibleMem,
459 convertModRefInfoToLLVM(memAttr.getInaccessibleMem())) |
460 llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
461 convertModRefInfoToLLVM(memAttr.getOther()));
462 call->setMemoryEffects(memEffects);
473 else if (!call->getType()->isVoidTy())
475 moduleTranslation.
mapCall(callOp, call);
479 if (
auto inlineAsmOp = dyn_cast<LLVM::InlineAsmOp>(opInst)) {
483 llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
486 if (inlineAsmOp.getNumResults() == 0) {
489 assert(inlineAsmOp.getNumResults() == 1);
490 resultType = inlineAsmOp.getResultTypes()[0];
493 llvm::InlineAsm *inlineAsmInst =
494 inlineAsmOp.getAsmDialect()
496 static_cast<llvm::FunctionType *
>(
498 inlineAsmOp.getAsmString(), inlineAsmOp.getConstraints(),
499 inlineAsmOp.getHasSideEffects(),
500 inlineAsmOp.getIsAlignStack(),
501 convertAsmDialectToLLVM(*inlineAsmOp.getAsmDialect()))
504 inlineAsmOp.getAsmString(),
505 inlineAsmOp.getConstraints(),
506 inlineAsmOp.getHasSideEffects(),
507 inlineAsmOp.getIsAlignStack());
508 llvm::CallInst *inst = builder.CreateCall(
510 moduleTranslation.
lookupValues(inlineAsmOp.getOperands()));
511 inst->setTailCallKind(convertTailCallKindToLLVM(
512 inlineAsmOp.getTailCallKindAttr().getTailCallKind()));
513 if (
auto maybeOperandAttrs = inlineAsmOp.getOperandAttrs()) {
514 llvm::AttributeList attrList;
519 DictionaryAttr dAttr = cast<DictionaryAttr>(attr);
523 cast<TypeAttr>(dAttr.get(InlineAsmOp::getElementTypeAttrName()));
525 llvm::Type *ty = moduleTranslation.
convertType(tAttr.getValue());
526 b.addTypeAttr(llvm::Attribute::ElementType, ty);
530 attrList = attrList.addAttributesAtIndex(
533 inst->setAttributes(attrList);
541 if (
auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
542 auto operands = moduleTranslation.
lookupValues(invOp.getCalleeOperands());
545 invOp.getOpBundleTags(), moduleTranslation);
547 llvm::InvokeInst *result;
549 result = builder.CreateInvoke(
551 moduleTranslation.
lookupBlock(invOp.getSuccessor(0)),
552 moduleTranslation.
lookupBlock(invOp.getSuccessor(1)), operandsRef,
555 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
556 moduleTranslation.
convertType(invOp.getCalleeFunctionType()));
557 result = builder.CreateInvoke(
558 calleeType, operandsRef.front(),
559 moduleTranslation.
lookupBlock(invOp.getSuccessor(0)),
560 moduleTranslation.
lookupBlock(invOp.getSuccessor(1)),
561 operandsRef.drop_front(), opBundles);
563 result->setCallingConv(convertCConvToLLVM(invOp.getCConv()));
567 moduleTranslation.
mapBranch(invOp, result);
569 if (invOp->getNumResults() != 0) {
573 return success(result->getType()->isVoidTy());
576 if (
auto lpOp = dyn_cast<LLVM::LandingpadOp>(opInst)) {
577 llvm::Type *ty = moduleTranslation.
convertType(lpOp.getType());
578 llvm::LandingPadInst *lpi =
579 builder.CreateLandingPad(ty, lpOp.getNumOperands());
580 lpi->setCleanup(lpOp.getCleanup());
583 for (llvm::Value *operand :
586 if (
auto *constOperand = dyn_cast<llvm::Constant>(operand))
587 lpi->addClause(constOperand);
589 moduleTranslation.
mapValue(lpOp.getResult(), lpi);
595 if (
auto brOp = dyn_cast<LLVM::BrOp>(opInst)) {
596 llvm::BranchInst *branch =
597 builder.CreateBr(moduleTranslation.
lookupBlock(brOp.getSuccessor()));
598 moduleTranslation.
mapBranch(&opInst, branch);
602 if (
auto condbrOp = dyn_cast<LLVM::CondBrOp>(opInst)) {
603 llvm::BranchInst *branch = builder.CreateCondBr(
604 moduleTranslation.
lookupValue(condbrOp.getOperand(0)),
605 moduleTranslation.
lookupBlock(condbrOp.getSuccessor(0)),
606 moduleTranslation.
lookupBlock(condbrOp.getSuccessor(1)));
607 moduleTranslation.
mapBranch(&opInst, branch);
611 if (
auto switchOp = dyn_cast<LLVM::SwitchOp>(opInst)) {
612 llvm::SwitchInst *switchInst = builder.CreateSwitch(
613 moduleTranslation.
lookupValue(switchOp.getValue()),
614 moduleTranslation.
lookupBlock(switchOp.getDefaultDestination()),
615 switchOp.getCaseDestinations().size());
618 if (!switchOp.getCaseValues())
621 auto *ty = llvm::cast<llvm::IntegerType>(
622 moduleTranslation.
convertType(switchOp.getValue().getType()));
624 llvm::zip(llvm::cast<DenseIntElementsAttr>(*switchOp.getCaseValues()),
625 switchOp.getCaseDestinations()))
630 moduleTranslation.
mapBranch(&opInst, switchInst);
633 if (
auto indBrOp = dyn_cast<LLVM::IndirectBrOp>(opInst)) {
634 llvm::IndirectBrInst *indBr = builder.CreateIndirectBr(
636 indBrOp->getNumSuccessors());
637 for (
auto *succ : indBrOp.getSuccessors())
638 indBr->addDestination(moduleTranslation.
lookupBlock(succ));
639 moduleTranslation.
mapBranch(&opInst, indBr);
646 if (
auto addressOfOp = dyn_cast<LLVM::AddressOfOp>(opInst)) {
647 LLVM::GlobalOp global =
648 addressOfOp.getGlobal(moduleTranslation.
symbolTable());
649 LLVM::LLVMFuncOp
function =
650 addressOfOp.getFunction(moduleTranslation.
symbolTable());
651 LLVM::AliasOp alias = addressOfOp.getAlias(moduleTranslation.
symbolTable());
654 assert((global ||
function || alias) &&
655 "referencing an undefined global, function, or alias");
657 llvm::Value *llvmValue =
nullptr;
665 moduleTranslation.
mapValue(addressOfOp.getResult(), llvmValue);
671 if (
auto dsoLocalEquivalentOp =
672 dyn_cast<LLVM::DSOLocalEquivalentOp>(opInst)) {
673 LLVM::LLVMFuncOp
function =
674 dsoLocalEquivalentOp.getFunction(moduleTranslation.
symbolTable());
675 LLVM::AliasOp alias =
676 dsoLocalEquivalentOp.getAlias(moduleTranslation.
symbolTable());
679 assert((
function || alias) &&
680 "referencing an undefined function, or alias");
682 llvm::Value *llvmValue =
nullptr;
689 dsoLocalEquivalentOp.getResult(),
696 if (
auto blockAddressOp = dyn_cast<LLVM::BlockAddressOp>(opInst)) {
697 BlockAddressAttr blockAddressAttr = blockAddressOp.getBlockAddr();
698 llvm::BasicBlock *llvmBlock =
701 llvm::Value *llvmValue =
nullptr;
702 StringRef fnName = blockAddressAttr.getFunction().getValue();
704 llvm::Function *llvmFn = moduleTranslation.
lookupFunction(fnName);
713 llvmValue =
new llvm::GlobalVariable(
716 true, llvm::GlobalValue::LinkageTypes::ExternalLinkage,
718 Twine(
"__mlir_block_address_")
720 .
concat(Twine((uint64_t)blockAddressOp.getOperation())));
724 moduleTranslation.
mapValue(blockAddressOp.getResult(), llvmValue);
730 if (
auto blockTagOp = dyn_cast<LLVM::BlockTagOp>(opInst)) {
731 auto funcOp = blockTagOp->getParentOfType<LLVMFuncOp>();
736 blockTagOp.getTag());
738 builder.GetInsertBlock());
748 class LLVMDialectLLVMIRTranslationInterface
756 convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
764 registry.
insert<LLVM::LLVMDialect>();
766 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 LogicalResult convertParameterAndResultAttrs(mlir::Location loc, ArrayAttr argAttrsArray, ArrayAttr resAttrsArray, llvm::CallBase *call, LLVM::ModuleTranslation &moduleTranslation)
static llvm::Metadata * convertModuleFlagProfileSummaryAttr(StringRef key, ModuleFlagProfileSummaryAttr summaryAttr, llvm::IRBuilderBase &builder, 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.
Base class for dialect interfaces providing translation to LLVM IR.
LLVMTranslationDialectInterface(Dialect *dialect)
Implementation class for module translation.
void mapUnresolvedBlockAddress(BlockAddressOp op, llvm::Value *cst)
Maps a blockaddress operation to its corresponding placeholder LLVM value.
llvm::Value * lookupValue(Value value) const
Finds an LLVM IR value corresponding to the given MLIR value.
void mapCall(Operation *mlir, llvm::CallInst *llvm)
Stores a mapping between an MLIR call operation and a corresponding LLVM call instruction.
FailureOr< llvm::AttrBuilder > convertParameterAttrs(mlir::Location loc, DictionaryAttr paramAttrs)
Translates parameter attributes of a call and adds them to the returned AttrBuilder.
void mapBranch(Operation *mlir, llvm::Instruction *llvm)
Stores the mapping between an MLIR operation with successors and a corresponding LLVM IR instruction.
SmallVector< llvm::Value * > lookupValues(ValueRange values)
Looks up remapped a list of remapped values.
llvm::BasicBlock * lookupBlock(Block *block) const
Finds an LLVM IR basic block that corresponds to the given MLIR block.
SymbolTableCollection & symbolTable()
llvm::Type * convertType(Type type)
Converts the type from MLIR LLVM dialect to LLVM.
llvm::GlobalValue * lookupAlias(Operation *op)
Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global alias va...
void setTBAAMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst)
Sets LLVM TBAA metadata for memory operations that have TBAA attributes.
llvm::LLVMContext & getLLVMContext() const
Returns the LLVM context in which the IR is being constructed.
llvm::GlobalValue * lookupGlobal(Operation *op)
Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global value.
llvm::Module * getLLVMModule()
Returns the LLVM module in which the IR is being constructed.
llvm::Function * lookupFunction(StringRef name) const
Finds an LLVM IR function by its name.
llvm::BasicBlock * lookupBlockAddress(BlockAddressAttr attr) const
Finds the LLVM basic block that corresponds to the given BlockAddressAttr.
void setAliasScopeMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst)
void setAccessGroupsMetadata(AccessGroupOpInterface op, llvm::Instruction *inst)
MLIRContext & getContext()
Returns the MLIR context of the module being translated.
void mapValue(Value mlir, llvm::Value *llvm)
Stores the mapping between an MLIR value and its LLVM IR counterpart.
void mapBlockAddress(BlockAddressAttr attr, llvm::BasicBlock *block)
Maps a BlockAddressAttr to its corresponding LLVM basic block.
void setLoopMetadata(Operation *op, llvm::Instruction *inst)
Sets LLVM loop metadata for branch operations that have a loop annotation attribute.
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.
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...