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"
30 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
33 using llvmFMF = llvm::FastMathFlags;
34 using FuncT = void (llvmFMF::*)(bool);
35 const std::pair<FastmathFlags, FuncT> handlers[] = {
37 {FastmathFlags::nnan, &llvmFMF::setNoNaNs},
38 {FastmathFlags::ninf, &llvmFMF::setNoInfs},
39 {FastmathFlags::nsz, &llvmFMF::setNoSignedZeros},
40 {FastmathFlags::arcp, &llvmFMF::setAllowReciprocal},
42 {FastmathFlags::afn, &llvmFMF::setApproxFunc},
43 {FastmathFlags::reassoc, &llvmFMF::setAllowReassoc},
46 llvm::FastMathFlags ret;
47 ::mlir::LLVM::FastmathFlags fmfMlir = op.getFastmathAttr().getValue();
48 for (
auto it : handlers)
49 if (bitEnumContainsAll(fmfMlir, it.first))
50 (ret.*(it.second))(
true);
57 llvm::append_range(position, indices);
62 static std::string
diagStr(
const llvm::Type *type) {
64 llvm::raw_string_ostream os(str);
72 static FailureOr<llvm::Function *>
77 for (
Type type : op->getOperandTypes())
78 allArgTys.push_back(moduleTranslation.
convertType(type));
81 if (op.getNumResults() == 0)
82 resTy = llvm::Type::getVoidTy(module->getContext());
84 resTy = moduleTranslation.
convertType(op.getResult(0).getType());
90 getIntrinsicInfoTableEntries(
id,
table);
94 if (llvm::Intrinsic::matchIntrinsicSignature(ft, tableRef,
96 llvm::Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
98 <<
diagStr(ft) <<
" to overloaded intrinsic " << op.getIntrinAttr()
99 <<
" does not match any of the overloads";
103 return llvm::Intrinsic::getOrInsertDeclaration(module,
id,
104 overloadedArgTysRef);
107 static llvm::OperandBundleDef
110 std::vector<llvm::Value *> operands;
111 operands.reserve(bundleOperands.size());
112 for (
Value bundleArg : bundleOperands)
113 operands.push_back(moduleTranslation.
lookupValue(bundleArg));
114 return llvm::OperandBundleDef(bundleTag.str(), std::move(operands));
121 bundles.reserve(bundleOperands.size());
123 for (
auto [operands, tagAttr] : llvm::zip_equal(bundleOperands, bundleTags)) {
124 StringRef tag = cast<StringAttr>(tagAttr).getValue();
132 std::optional<ArrayAttr> bundleTags,
141 ArrayAttr resAttrsArray, llvm::CallBase *call,
145 if (
auto argAttrs = cast<DictionaryAttr>(argAttrsAttr);
147 FailureOr<llvm::AttrBuilder> attrBuilder =
149 if (failed(attrBuilder))
151 call->addParamAttrs(argIdx, *attrBuilder);
156 if (resAttrsArray && resAttrsArray.size() > 0) {
157 if (resAttrsArray.size() != 1)
159 if (
auto resAttrs = cast<DictionaryAttr>(resAttrsArray[0]);
161 FailureOr<llvm::AttrBuilder> attrBuilder =
163 if (failed(attrBuilder))
165 call->addRetAttrs(*attrBuilder);
175 callOp.getLoc(), callOp.getArgAttrsAttr(), callOp.getResAttrsAttr(), call,
183 llvm::Module *module = builder.GetInsertBlock()->getModule();
185 llvm::Intrinsic::lookupIntrinsicID(op.getIntrinAttr());
188 << op.getIntrinAttr();
190 llvm::Function *fn =
nullptr;
191 if (llvm::Intrinsic::isOverloaded(
id)) {
194 if (failed(fnOrFailure))
198 fn = llvm::Intrinsic::getOrInsertDeclaration(module,
id, {});
202 const llvm::Type *intrinType =
203 op.getNumResults() == 0
204 ? llvm::Type::getVoidTy(module->getContext())
205 : moduleTranslation.
convertType(op.getResultTypes().front());
206 if (intrinType != fn->getReturnType()) {
208 <<
diagStr(intrinType) <<
" but " << op.getIntrinAttr()
209 <<
" actually returns " <<
diagStr(fn->getReturnType());
214 if (!fn->getFunctionType()->isVarArg() &&
215 op.getArgs().size() != fn->arg_size()) {
217 << op.getArgs().size() <<
" operands but " << op.getIntrinAttr()
218 <<
" expects " << fn->arg_size();
220 if (fn->getFunctionType()->isVarArg() &&
221 op.getArgs().size() < fn->arg_size()) {
223 << op.getArgs().size() <<
" operands but variadic "
224 << op.getIntrinAttr() <<
" expects at least " << fn->arg_size();
227 for (
unsigned i = 0, e = fn->arg_size(); i != e; ++i) {
228 const llvm::Type *expected = fn->getArg(i)->getType();
229 const llvm::Type *actual =
230 moduleTranslation.
convertType(op.getOperandTypes()[i]);
231 if (actual != expected) {
233 << i <<
" has type " <<
diagStr(actual) <<
" but "
234 << op.getIntrinAttr() <<
" expects " <<
diagStr(expected);
238 FastmathFlagsInterface itf = op;
241 auto *inst = builder.CreateCall(
247 op.getResAttrsAttr(), inst,
251 if (op.getNumResults() == 1)
252 moduleTranslation.
mapValue(op->getResults().front()) = inst;
257 llvm::IRBuilderBase &builder,
259 llvm::Module *llvmModule = moduleTranslation.
getLLVMModule();
260 llvm::LLVMContext &context = llvmModule->getContext();
261 llvm::NamedMDNode *linkerMDNode =
262 llvmModule->getOrInsertNamedMetadata(
"llvm.linker.options");
264 MDNodes.reserve(
options.size());
265 for (
auto s :
options.getAsRange<StringAttr>()) {
267 MDNodes.push_back(MDNode);
271 linkerMDNode->addOperand(listMDNode);
274 static llvm::Metadata *
276 llvm::IRBuilderBase &builder,
278 llvm::LLVMContext &context = builder.getContext();
279 llvm::MDBuilder mdb(context);
282 if (key == LLVMDialect::getModuleFlagKeyCGProfileName()) {
283 for (
auto entry : arrayAttr.getAsRange<ModuleFlagCGProfileEntryAttr>()) {
284 llvm::Metadata *fromMetadata =
287 entry.getFrom().getValue()))
289 llvm::Metadata *toMetadata =
295 llvm::Metadata *vals[] = {
296 fromMetadata, toMetadata,
298 llvm::Type::getInt64Ty(context), entry.getCount()))};
301 return llvm::MDTuple::getDistinct(context, nodes);
307 StringRef key, ModuleFlagProfileSummaryAttr summaryAttr,
309 llvm::LLVMContext &context = builder.getContext();
310 llvm::MDBuilder mdb(context);
312 auto getIntTuple = [&](StringRef key, uint64_t val) -> llvm::MDTuple * {
315 llvm::Type::getInt64Ty(context), val))};
320 mdb.createString(
"ProfileFormat"),
322 stringifyProfileSummaryFormatKind(summaryAttr.getFormat()))};
326 getIntTuple(
"TotalCount", summaryAttr.getTotalCount()),
327 getIntTuple(
"MaxCount", summaryAttr.getMaxCount()),
328 getIntTuple(
"MaxInternalCount", summaryAttr.getMaxInternalCount()),
329 getIntTuple(
"MaxFunctionCount", summaryAttr.getMaxFunctionCount()),
330 getIntTuple(
"NumCounts", summaryAttr.getNumCounts()),
331 getIntTuple(
"NumFunctions", summaryAttr.getNumFunctions()),
334 if (summaryAttr.getIsPartialProfile())
336 getIntTuple(
"IsPartialProfile", *summaryAttr.getIsPartialProfile()));
338 if (summaryAttr.getPartialProfileRatio()) {
340 mdb.createString(
"PartialProfileRatio"),
342 llvm::Type::getDoubleTy(context),
343 summaryAttr.getPartialProfileRatio().getValue()))};
348 llvm::Type *llvmInt64Type = llvm::Type::getInt64Ty(context);
349 for (ModuleFlagProfileSummaryDetailedAttr detailedEntry :
350 summaryAttr.getDetailedSummary()) {
357 llvmInt64Type, detailedEntry.getNumCounts()))};
361 mdb.createString(
"DetailedSummary"),
370 llvm::Module *llvmModule = moduleTranslation.
getLLVMModule();
371 for (
auto flagAttr : flags.getAsRange<ModuleFlagAttr>()) {
372 llvm::Metadata *valueMetadata =
374 .Case<StringAttr>([&](
auto strAttr) {
378 .Case<IntegerAttr>([&](
auto intAttr) {
380 llvm::Type::getInt32Ty(builder.getContext()),
383 .Case<ArrayAttr>([&](
auto arrayAttr) {
388 .Case([&](ModuleFlagProfileSummaryAttr summaryAttr) {
390 flagAttr.getKey().getValue(), summaryAttr, builder,
393 .Default([](
auto) {
return nullptr; });
395 assert(valueMetadata &&
"expected valid metadata");
396 llvmModule->addModuleFlag(
397 convertModFlagBehaviorToLLVM(flagAttr.getBehavior()),
398 flagAttr.getKey().getValue(), valueMetadata);
406 llvm::IRBuilder<>::FastMathFlagGuard fmfGuard(builder);
407 if (
auto fmf = dyn_cast<FastmathFlagsInterface>(opInst))
410 #include "mlir/Dialect/LLVMIR/LLVMConversions.inc"
411 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicConversions.inc"
417 if (
auto callOp = dyn_cast<LLVM::CallOp>(opInst)) {
418 auto operands = moduleTranslation.
lookupValues(callOp.getCalleeOperands());
421 callOp.getOpBundleTags(), moduleTranslation);
423 llvm::CallInst *call;
424 if (
auto attr = callOp.getCalleeAttr()) {
425 if (llvm::Function *
function =
427 call = builder.CreateCall(
function, operandsRef, opBundles);
432 llvm::GlobalValue *ifunc = moduleTranslation.
lookupIFunc(ifuncOp);
433 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
434 moduleTranslation.
convertType(callOp.getCalleeFunctionType()));
435 call = builder.CreateCall(calleeType, ifunc, operandsRef, opBundles);
438 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
439 moduleTranslation.
convertType(callOp.getCalleeFunctionType()));
440 call = builder.CreateCall(calleeType, operandsRef.front(),
441 operandsRef.drop_front(), opBundles);
443 call->setCallingConv(convertCConvToLLVM(callOp.getCConv()));
444 call->setTailCallKind(convertTailCallKindToLLVM(callOp.getTailCallKind()));
445 if (callOp.getConvergentAttr())
446 call->addFnAttr(llvm::Attribute::Convergent);
447 if (callOp.getNoUnwindAttr())
448 call->addFnAttr(llvm::Attribute::NoUnwind);
449 if (callOp.getWillReturnAttr())
450 call->addFnAttr(llvm::Attribute::WillReturn);
451 if (callOp.getNoInlineAttr())
452 call->addFnAttr(llvm::Attribute::NoInline);
453 if (callOp.getAlwaysInlineAttr())
454 call->addFnAttr(llvm::Attribute::AlwaysInline);
455 if (callOp.getInlineHintAttr())
456 call->addFnAttr(llvm::Attribute::InlineHint);
461 if (MemoryEffectsAttr memAttr = callOp.getMemoryEffectsAttr()) {
462 llvm::MemoryEffects memEffects =
463 llvm::MemoryEffects(llvm::MemoryEffects::Location::ArgMem,
464 convertModRefInfoToLLVM(memAttr.getArgMem())) |
466 llvm::MemoryEffects::Location::InaccessibleMem,
467 convertModRefInfoToLLVM(memAttr.getInaccessibleMem())) |
468 llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
469 convertModRefInfoToLLVM(memAttr.getOther()));
470 call->setMemoryEffects(memEffects);
481 else if (!call->getType()->isVoidTy())
483 moduleTranslation.
mapCall(callOp, call);
487 if (
auto inlineAsmOp = dyn_cast<LLVM::InlineAsmOp>(opInst)) {
491 llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
494 if (inlineAsmOp.getNumResults() == 0) {
497 assert(inlineAsmOp.getNumResults() == 1);
498 resultType = inlineAsmOp.getResultTypes()[0];
501 llvm::InlineAsm *inlineAsmInst =
502 inlineAsmOp.getAsmDialect()
504 static_cast<llvm::FunctionType *
>(
506 inlineAsmOp.getAsmString(), inlineAsmOp.getConstraints(),
507 inlineAsmOp.getHasSideEffects(),
508 inlineAsmOp.getIsAlignStack(),
509 convertAsmDialectToLLVM(*inlineAsmOp.getAsmDialect()))
512 inlineAsmOp.getAsmString(),
513 inlineAsmOp.getConstraints(),
514 inlineAsmOp.getHasSideEffects(),
515 inlineAsmOp.getIsAlignStack());
516 llvm::CallInst *inst = builder.CreateCall(
518 moduleTranslation.
lookupValues(inlineAsmOp.getOperands()));
519 inst->setTailCallKind(convertTailCallKindToLLVM(
520 inlineAsmOp.getTailCallKindAttr().getTailCallKind()));
521 if (
auto maybeOperandAttrs = inlineAsmOp.getOperandAttrs()) {
522 llvm::AttributeList attrList;
527 DictionaryAttr dAttr = cast<DictionaryAttr>(attr);
531 cast<TypeAttr>(dAttr.get(InlineAsmOp::getElementTypeAttrName()));
533 llvm::Type *ty = moduleTranslation.
convertType(tAttr.getValue());
534 b.addTypeAttr(llvm::Attribute::ElementType, ty);
538 attrList = attrList.addAttributesAtIndex(
541 inst->setAttributes(attrList);
549 if (
auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
550 auto operands = moduleTranslation.
lookupValues(invOp.getCalleeOperands());
553 invOp.getOpBundleTags(), moduleTranslation);
555 llvm::InvokeInst *result;
557 result = builder.CreateInvoke(
559 moduleTranslation.
lookupBlock(invOp.getSuccessor(0)),
560 moduleTranslation.
lookupBlock(invOp.getSuccessor(1)), operandsRef,
563 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
564 moduleTranslation.
convertType(invOp.getCalleeFunctionType()));
565 result = builder.CreateInvoke(
566 calleeType, operandsRef.front(),
567 moduleTranslation.
lookupBlock(invOp.getSuccessor(0)),
568 moduleTranslation.
lookupBlock(invOp.getSuccessor(1)),
569 operandsRef.drop_front(), opBundles);
571 result->setCallingConv(convertCConvToLLVM(invOp.getCConv()));
575 moduleTranslation.
mapBranch(invOp, result);
577 if (invOp->getNumResults() != 0) {
581 return success(result->getType()->isVoidTy());
584 if (
auto lpOp = dyn_cast<LLVM::LandingpadOp>(opInst)) {
585 llvm::Type *ty = moduleTranslation.
convertType(lpOp.getType());
586 llvm::LandingPadInst *lpi =
587 builder.CreateLandingPad(ty, lpOp.getNumOperands());
588 lpi->setCleanup(lpOp.getCleanup());
591 for (llvm::Value *operand :
594 if (
auto *constOperand = dyn_cast<llvm::Constant>(operand))
595 lpi->addClause(constOperand);
597 moduleTranslation.
mapValue(lpOp.getResult(), lpi);
603 if (
auto brOp = dyn_cast<LLVM::BrOp>(opInst)) {
604 llvm::BranchInst *branch =
605 builder.CreateBr(moduleTranslation.
lookupBlock(brOp.getSuccessor()));
606 moduleTranslation.
mapBranch(&opInst, branch);
610 if (
auto condbrOp = dyn_cast<LLVM::CondBrOp>(opInst)) {
611 llvm::BranchInst *branch = builder.CreateCondBr(
612 moduleTranslation.
lookupValue(condbrOp.getOperand(0)),
613 moduleTranslation.
lookupBlock(condbrOp.getSuccessor(0)),
614 moduleTranslation.
lookupBlock(condbrOp.getSuccessor(1)));
615 moduleTranslation.
mapBranch(&opInst, branch);
619 if (
auto switchOp = dyn_cast<LLVM::SwitchOp>(opInst)) {
620 llvm::SwitchInst *switchInst = builder.CreateSwitch(
621 moduleTranslation.
lookupValue(switchOp.getValue()),
622 moduleTranslation.
lookupBlock(switchOp.getDefaultDestination()),
623 switchOp.getCaseDestinations().size());
626 if (!switchOp.getCaseValues())
629 auto *ty = llvm::cast<llvm::IntegerType>(
630 moduleTranslation.
convertType(switchOp.getValue().getType()));
632 llvm::zip(llvm::cast<DenseIntElementsAttr>(*switchOp.getCaseValues()),
633 switchOp.getCaseDestinations()))
638 moduleTranslation.
mapBranch(&opInst, switchInst);
641 if (
auto indBrOp = dyn_cast<LLVM::IndirectBrOp>(opInst)) {
642 llvm::IndirectBrInst *indBr = builder.CreateIndirectBr(
644 indBrOp->getNumSuccessors());
645 for (
auto *succ : indBrOp.getSuccessors())
646 indBr->addDestination(moduleTranslation.
lookupBlock(succ));
647 moduleTranslation.
mapBranch(&opInst, indBr);
654 if (
auto addressOfOp = dyn_cast<LLVM::AddressOfOp>(opInst)) {
655 LLVM::GlobalOp global =
656 addressOfOp.getGlobal(moduleTranslation.
symbolTable());
657 LLVM::LLVMFuncOp
function =
658 addressOfOp.getFunction(moduleTranslation.
symbolTable());
659 LLVM::AliasOp alias = addressOfOp.getAlias(moduleTranslation.
symbolTable());
660 LLVM::IFuncOp ifunc = addressOfOp.getIFunc(moduleTranslation.
symbolTable());
663 assert((global ||
function || alias || ifunc) &&
664 "referencing an undefined global, function, alias, or ifunc");
666 llvm::Value *llvmValue =
nullptr;
676 moduleTranslation.
mapValue(addressOfOp.getResult(), llvmValue);
682 if (
auto dsoLocalEquivalentOp =
683 dyn_cast<LLVM::DSOLocalEquivalentOp>(opInst)) {
684 LLVM::LLVMFuncOp
function =
685 dsoLocalEquivalentOp.getFunction(moduleTranslation.
symbolTable());
686 LLVM::AliasOp alias =
687 dsoLocalEquivalentOp.getAlias(moduleTranslation.
symbolTable());
690 assert((
function || alias) &&
691 "referencing an undefined function, or alias");
693 llvm::Value *llvmValue =
nullptr;
700 dsoLocalEquivalentOp.getResult(),
707 if (
auto blockAddressOp = dyn_cast<LLVM::BlockAddressOp>(opInst)) {
708 BlockAddressAttr blockAddressAttr = blockAddressOp.getBlockAddr();
709 llvm::BasicBlock *llvmBlock =
712 llvm::Value *llvmValue =
nullptr;
713 StringRef fnName = blockAddressAttr.getFunction().getValue();
715 llvm::Function *llvmFn = moduleTranslation.
lookupFunction(fnName);
724 llvmValue =
new llvm::GlobalVariable(
727 true, llvm::GlobalValue::LinkageTypes::ExternalLinkage,
729 Twine(
"__mlir_block_address_")
731 .
concat(Twine((uint64_t)blockAddressOp.getOperation())));
735 moduleTranslation.
mapValue(blockAddressOp.getResult(), llvmValue);
741 if (
auto blockTagOp = dyn_cast<LLVM::BlockTagOp>(opInst)) {
742 auto funcOp = blockTagOp->getParentOfType<LLVMFuncOp>();
747 blockTagOp.getTag());
749 builder.GetInsertBlock());
759 class LLVMDialectLLVMIRTranslationInterface
767 convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
775 registry.
insert<LLVM::LLVMDialect>();
777 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::GlobalValue * lookupIFunc(Operation *op)
Finds an LLVM IR global value that corresponds to the given MLIR operation defining an IFunc.
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.
virtual Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
Look up a symbol with the specified name within the specified symbol table 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...