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()) {
426 builder.CreateCall(moduleTranslation.
lookupFunction(attr.getValue()),
427 operandsRef, opBundles);
429 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
430 moduleTranslation.
convertType(callOp.getCalleeFunctionType()));
431 call = builder.CreateCall(calleeType, operandsRef.front(),
432 operandsRef.drop_front(), opBundles);
434 call->setCallingConv(convertCConvToLLVM(callOp.getCConv()));
435 call->setTailCallKind(convertTailCallKindToLLVM(callOp.getTailCallKind()));
436 if (callOp.getConvergentAttr())
437 call->addFnAttr(llvm::Attribute::Convergent);
438 if (callOp.getNoUnwindAttr())
439 call->addFnAttr(llvm::Attribute::NoUnwind);
440 if (callOp.getWillReturnAttr())
441 call->addFnAttr(llvm::Attribute::WillReturn);
442 if (callOp.getNoInlineAttr())
443 call->addFnAttr(llvm::Attribute::NoInline);
444 if (callOp.getAlwaysInlineAttr())
445 call->addFnAttr(llvm::Attribute::AlwaysInline);
446 if (callOp.getInlineHintAttr())
447 call->addFnAttr(llvm::Attribute::InlineHint);
452 if (MemoryEffectsAttr memAttr = callOp.getMemoryEffectsAttr()) {
453 llvm::MemoryEffects memEffects =
454 llvm::MemoryEffects(llvm::MemoryEffects::Location::ArgMem,
455 convertModRefInfoToLLVM(memAttr.getArgMem())) |
457 llvm::MemoryEffects::Location::InaccessibleMem,
458 convertModRefInfoToLLVM(memAttr.getInaccessibleMem())) |
459 llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
460 convertModRefInfoToLLVM(memAttr.getOther()));
461 call->setMemoryEffects(memEffects);
472 else if (!call->getType()->isVoidTy())
474 moduleTranslation.
mapCall(callOp, call);
478 if (
auto inlineAsmOp = dyn_cast<LLVM::InlineAsmOp>(opInst)) {
482 llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
485 if (inlineAsmOp.getNumResults() == 0) {
488 assert(inlineAsmOp.getNumResults() == 1);
489 resultType = inlineAsmOp.getResultTypes()[0];
492 llvm::InlineAsm *inlineAsmInst =
493 inlineAsmOp.getAsmDialect()
495 static_cast<llvm::FunctionType *
>(
497 inlineAsmOp.getAsmString(), inlineAsmOp.getConstraints(),
498 inlineAsmOp.getHasSideEffects(),
499 inlineAsmOp.getIsAlignStack(),
500 convertAsmDialectToLLVM(*inlineAsmOp.getAsmDialect()))
503 inlineAsmOp.getAsmString(),
504 inlineAsmOp.getConstraints(),
505 inlineAsmOp.getHasSideEffects(),
506 inlineAsmOp.getIsAlignStack());
507 llvm::CallInst *inst = builder.CreateCall(
509 moduleTranslation.
lookupValues(inlineAsmOp.getOperands()));
510 inst->setTailCallKind(convertTailCallKindToLLVM(
511 inlineAsmOp.getTailCallKindAttr().getTailCallKind()));
512 if (
auto maybeOperandAttrs = inlineAsmOp.getOperandAttrs()) {
513 llvm::AttributeList attrList;
518 DictionaryAttr dAttr = cast<DictionaryAttr>(attr);
522 cast<TypeAttr>(dAttr.get(InlineAsmOp::getElementTypeAttrName()));
524 llvm::Type *ty = moduleTranslation.
convertType(tAttr.getValue());
525 b.addTypeAttr(llvm::Attribute::ElementType, ty);
529 attrList = attrList.addAttributesAtIndex(
532 inst->setAttributes(attrList);
540 if (
auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
541 auto operands = moduleTranslation.
lookupValues(invOp.getCalleeOperands());
544 invOp.getOpBundleTags(), moduleTranslation);
546 llvm::InvokeInst *result;
548 result = builder.CreateInvoke(
550 moduleTranslation.
lookupBlock(invOp.getSuccessor(0)),
551 moduleTranslation.
lookupBlock(invOp.getSuccessor(1)), operandsRef,
554 llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
555 moduleTranslation.
convertType(invOp.getCalleeFunctionType()));
556 result = builder.CreateInvoke(
557 calleeType, operandsRef.front(),
558 moduleTranslation.
lookupBlock(invOp.getSuccessor(0)),
559 moduleTranslation.
lookupBlock(invOp.getSuccessor(1)),
560 operandsRef.drop_front(), opBundles);
562 result->setCallingConv(convertCConvToLLVM(invOp.getCConv()));
566 moduleTranslation.
mapBranch(invOp, result);
568 if (invOp->getNumResults() != 0) {
572 return success(result->getType()->isVoidTy());
575 if (
auto lpOp = dyn_cast<LLVM::LandingpadOp>(opInst)) {
576 llvm::Type *ty = moduleTranslation.
convertType(lpOp.getType());
577 llvm::LandingPadInst *lpi =
578 builder.CreateLandingPad(ty, lpOp.getNumOperands());
579 lpi->setCleanup(lpOp.getCleanup());
582 for (llvm::Value *operand :
585 if (
auto *constOperand = dyn_cast<llvm::Constant>(operand))
586 lpi->addClause(constOperand);
588 moduleTranslation.
mapValue(lpOp.getResult(), lpi);
594 if (
auto brOp = dyn_cast<LLVM::BrOp>(opInst)) {
595 llvm::BranchInst *branch =
596 builder.CreateBr(moduleTranslation.
lookupBlock(brOp.getSuccessor()));
597 moduleTranslation.
mapBranch(&opInst, branch);
601 if (
auto condbrOp = dyn_cast<LLVM::CondBrOp>(opInst)) {
602 llvm::BranchInst *branch = builder.CreateCondBr(
603 moduleTranslation.
lookupValue(condbrOp.getOperand(0)),
604 moduleTranslation.
lookupBlock(condbrOp.getSuccessor(0)),
605 moduleTranslation.
lookupBlock(condbrOp.getSuccessor(1)));
606 moduleTranslation.
mapBranch(&opInst, branch);
610 if (
auto switchOp = dyn_cast<LLVM::SwitchOp>(opInst)) {
611 llvm::SwitchInst *switchInst = builder.CreateSwitch(
612 moduleTranslation.
lookupValue(switchOp.getValue()),
613 moduleTranslation.
lookupBlock(switchOp.getDefaultDestination()),
614 switchOp.getCaseDestinations().size());
617 if (!switchOp.getCaseValues())
620 auto *ty = llvm::cast<llvm::IntegerType>(
621 moduleTranslation.
convertType(switchOp.getValue().getType()));
623 llvm::zip(llvm::cast<DenseIntElementsAttr>(*switchOp.getCaseValues()),
624 switchOp.getCaseDestinations()))
629 moduleTranslation.
mapBranch(&opInst, switchInst);
632 if (
auto indBrOp = dyn_cast<LLVM::IndirectBrOp>(opInst)) {
633 llvm::IndirectBrInst *indBr = builder.CreateIndirectBr(
635 indBrOp->getNumSuccessors());
636 for (
auto *succ : indBrOp.getSuccessors())
637 indBr->addDestination(moduleTranslation.
lookupBlock(succ));
638 moduleTranslation.
mapBranch(&opInst, indBr);
645 if (
auto addressOfOp = dyn_cast<LLVM::AddressOfOp>(opInst)) {
646 LLVM::GlobalOp global =
647 addressOfOp.getGlobal(moduleTranslation.
symbolTable());
648 LLVM::LLVMFuncOp
function =
649 addressOfOp.getFunction(moduleTranslation.
symbolTable());
650 LLVM::AliasOp alias = addressOfOp.getAlias(moduleTranslation.
symbolTable());
653 assert((global ||
function || alias) &&
654 "referencing an undefined global, function, or alias");
656 llvm::Value *llvmValue =
nullptr;
664 moduleTranslation.
mapValue(addressOfOp.getResult(), llvmValue);
670 if (
auto dsoLocalEquivalentOp =
671 dyn_cast<LLVM::DSOLocalEquivalentOp>(opInst)) {
672 LLVM::LLVMFuncOp
function =
673 dsoLocalEquivalentOp.getFunction(moduleTranslation.
symbolTable());
674 LLVM::AliasOp alias =
675 dsoLocalEquivalentOp.getAlias(moduleTranslation.
symbolTable());
678 assert((
function || alias) &&
679 "referencing an undefined function, or alias");
681 llvm::Value *llvmValue =
nullptr;
688 dsoLocalEquivalentOp.getResult(),
695 if (
auto blockAddressOp = dyn_cast<LLVM::BlockAddressOp>(opInst)) {
696 BlockAddressAttr blockAddressAttr = blockAddressOp.getBlockAddr();
697 llvm::BasicBlock *llvmBlock =
700 llvm::Value *llvmValue =
nullptr;
701 StringRef fnName = blockAddressAttr.getFunction().getValue();
703 llvm::Function *llvmFn = moduleTranslation.
lookupFunction(fnName);
712 llvmValue =
new llvm::GlobalVariable(
715 true, llvm::GlobalValue::LinkageTypes::ExternalLinkage,
717 Twine(
"__mlir_block_address_")
719 .
concat(Twine((uint64_t)blockAddressOp.getOperation())));
723 moduleTranslation.
mapValue(blockAddressOp.getResult(), llvmValue);
729 if (
auto blockTagOp = dyn_cast<LLVM::BlockTagOp>(opInst)) {
730 auto funcOp = blockTagOp->getParentOfType<LLVMFuncOp>();
735 blockTagOp.getTag());
737 builder.GetInsertBlock());
747 class LLVMDialectLLVMIRTranslationInterface
755 convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
763 registry.
insert<LLVM::LLVMDialect>();
765 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...