MLIR  20.0.0git
LLVMToLLVMIRTranslation.cpp
Go to the documentation of this file.
1 //===- LLVMToLLVMIRTranslation.cpp - Translate LLVM dialect to LLVM IR ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a translation between the MLIR LLVM dialect and LLVM IR.
10 //
11 //===----------------------------------------------------------------------===//
12 
15 #include "mlir/IR/Operation.h"
16 #include "mlir/Support/LLVM.h"
18 
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/IR/InlineAsm.h"
21 #include "llvm/IR/MDBuilder.h"
22 #include "llvm/IR/MatrixBuilder.h"
23 #include "llvm/IR/Operator.h"
24 
25 using namespace mlir;
26 using namespace mlir::LLVM;
28 
29 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
30 
31 static llvm::FastMathFlags getFastmathFlags(FastmathFlagsInterface &op) {
32  using llvmFMF = llvm::FastMathFlags;
33  using FuncT = void (llvmFMF::*)(bool);
34  const std::pair<FastmathFlags, FuncT> handlers[] = {
35  // clang-format off
36  {FastmathFlags::nnan, &llvmFMF::setNoNaNs},
37  {FastmathFlags::ninf, &llvmFMF::setNoInfs},
38  {FastmathFlags::nsz, &llvmFMF::setNoSignedZeros},
39  {FastmathFlags::arcp, &llvmFMF::setAllowReciprocal},
40  {FastmathFlags::contract, &llvmFMF::setAllowContract},
41  {FastmathFlags::afn, &llvmFMF::setApproxFunc},
42  {FastmathFlags::reassoc, &llvmFMF::setAllowReassoc},
43  // clang-format on
44  };
45  llvm::FastMathFlags ret;
46  ::mlir::LLVM::FastmathFlags fmfMlir = op.getFastmathAttr().getValue();
47  for (auto it : handlers)
48  if (bitEnumContainsAll(fmfMlir, it.first))
49  (ret.*(it.second))(true);
50  return ret;
51 }
52 
53 /// Convert the value of a DenseI64ArrayAttr to a vector of unsigned indices.
55  SmallVector<unsigned> position;
56  llvm::append_range(position, indices);
57  return position;
58 }
59 
60 /// Convert an LLVM type to a string for printing in diagnostics.
61 static std::string diagStr(const llvm::Type *type) {
62  std::string str;
63  llvm::raw_string_ostream os(str);
64  type->print(os);
65  return str;
66 }
67 
68 /// Get the declaration of an overloaded llvm intrinsic. First we get the
69 /// overloaded argument types and/or result type from the CallIntrinsicOp, and
70 /// then use those to get the correct declaration of the overloaded intrinsic.
71 static FailureOr<llvm::Function *>
73  llvm::Module *module,
74  LLVM::ModuleTranslation &moduleTranslation) {
76  for (Type type : op->getOperandTypes())
77  allArgTys.push_back(moduleTranslation.convertType(type));
78 
79  llvm::Type *resTy;
80  if (op.getNumResults() == 0)
81  resTy = llvm::Type::getVoidTy(module->getContext());
82  else
83  resTy = moduleTranslation.convertType(op.getResult(0).getType());
84 
85  // ATM we do not support variadic intrinsics.
86  llvm::FunctionType *ft = llvm::FunctionType::get(resTy, allArgTys, false);
87 
89  getIntrinsicInfoTableEntries(id, table);
91 
92  SmallVector<llvm::Type *, 8> overloadedArgTys;
93  if (llvm::Intrinsic::matchIntrinsicSignature(ft, tableRef,
94  overloadedArgTys) !=
95  llvm::Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
96  return mlir::emitError(op.getLoc(), "call intrinsic signature ")
97  << diagStr(ft) << " to overloaded intrinsic " << op.getIntrinAttr()
98  << " does not match any of the overloads";
99  }
100 
101  ArrayRef<llvm::Type *> overloadedArgTysRef = overloadedArgTys;
102  return llvm::Intrinsic::getDeclaration(module, id, overloadedArgTysRef);
103 }
104 
105 static llvm::OperandBundleDef
106 convertOperandBundle(OperandRange bundleOperands, StringRef bundleTag,
107  LLVM::ModuleTranslation &moduleTranslation) {
108  std::vector<llvm::Value *> operands;
109  operands.reserve(bundleOperands.size());
110  for (Value bundleArg : bundleOperands)
111  operands.push_back(moduleTranslation.lookupValue(bundleArg));
112  return llvm::OperandBundleDef(bundleTag.str(), std::move(operands));
113 }
114 
117  ArrayRef<std::string> bundleTags,
118  LLVM::ModuleTranslation &moduleTranslation) {
120  bundles.reserve(bundleOperands.size());
121 
122  for (auto [operands, tag] : llvm::zip_equal(bundleOperands, bundleTags))
123  bundles.push_back(convertOperandBundle(operands, tag, moduleTranslation));
124  return bundles;
125 }
126 
127 /// Builder for LLVM_CallIntrinsicOp
128 static LogicalResult
129 convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase &builder,
130  LLVM::ModuleTranslation &moduleTranslation) {
131  llvm::Module *module = builder.GetInsertBlock()->getModule();
133  llvm::Intrinsic::lookupIntrinsicID(op.getIntrinAttr());
134  if (!id)
135  return mlir::emitError(op.getLoc(), "could not find LLVM intrinsic: ")
136  << op.getIntrinAttr();
137 
138  llvm::Function *fn = nullptr;
139  if (llvm::Intrinsic::isOverloaded(id)) {
140  auto fnOrFailure =
141  getOverloadedDeclaration(op, id, module, moduleTranslation);
142  if (failed(fnOrFailure))
143  return failure();
144  fn = *fnOrFailure;
145  } else {
146  fn = llvm::Intrinsic::getDeclaration(module, id, {});
147  }
148 
149  // Check the result type of the call.
150  const llvm::Type *intrinType =
151  op.getNumResults() == 0
152  ? llvm::Type::getVoidTy(module->getContext())
153  : moduleTranslation.convertType(op.getResultTypes().front());
154  if (intrinType != fn->getReturnType()) {
155  return mlir::emitError(op.getLoc(), "intrinsic call returns ")
156  << diagStr(intrinType) << " but " << op.getIntrinAttr()
157  << " actually returns " << diagStr(fn->getReturnType());
158  }
159 
160  // Check the argument types of the call. If the function is variadic, check
161  // the subrange of required arguments.
162  if (!fn->getFunctionType()->isVarArg() &&
163  op.getArgs().size() != fn->arg_size()) {
164  return mlir::emitError(op.getLoc(), "intrinsic call has ")
165  << op.getArgs().size() << " operands but " << op.getIntrinAttr()
166  << " expects " << fn->arg_size();
167  }
168  if (fn->getFunctionType()->isVarArg() &&
169  op.getArgs().size() < fn->arg_size()) {
170  return mlir::emitError(op.getLoc(), "intrinsic call has ")
171  << op.getArgs().size() << " operands but variadic "
172  << op.getIntrinAttr() << " expects at least " << fn->arg_size();
173  }
174  // Check the arguments up to the number the function requires.
175  for (unsigned i = 0, e = fn->arg_size(); i != e; ++i) {
176  const llvm::Type *expected = fn->getArg(i)->getType();
177  const llvm::Type *actual =
178  moduleTranslation.convertType(op.getOperandTypes()[i]);
179  if (actual != expected) {
180  return mlir::emitError(op.getLoc(), "intrinsic call operand #")
181  << i << " has type " << diagStr(actual) << " but "
182  << op.getIntrinAttr() << " expects " << diagStr(expected);
183  }
184  }
185 
186  FastmathFlagsInterface itf = op;
187  builder.setFastMathFlags(getFastmathFlags(itf));
188 
189  auto *inst = builder.CreateCall(
190  fn, moduleTranslation.lookupValues(op.getArgs()),
191  convertOperandBundles(op.getOpBundleOperands(), op.getOpBundleTags(),
192  moduleTranslation));
193  if (op.getNumResults() == 1)
194  moduleTranslation.mapValue(op->getResults().front()) = inst;
195  return success();
196 }
197 
198 static void convertLinkerOptionsOp(ArrayAttr options,
199  llvm::IRBuilderBase &builder,
200  LLVM::ModuleTranslation &moduleTranslation) {
201  llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
202  llvm::LLVMContext &context = llvmModule->getContext();
203  llvm::NamedMDNode *linkerMDNode =
204  llvmModule->getOrInsertNamedMetadata("llvm.linker.options");
206  MDNodes.reserve(options.size());
207  for (auto s : options.getAsRange<StringAttr>()) {
208  auto *MDNode = llvm::MDString::get(context, s.getValue());
209  MDNodes.push_back(MDNode);
210  }
211 
212  auto *listMDNode = llvm::MDTuple::get(context, MDNodes);
213  linkerMDNode->addOperand(listMDNode);
214 }
215 
216 static LogicalResult
217 convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
218  LLVM::ModuleTranslation &moduleTranslation) {
219 
220  llvm::IRBuilder<>::FastMathFlagGuard fmfGuard(builder);
221  if (auto fmf = dyn_cast<FastmathFlagsInterface>(opInst))
222  builder.setFastMathFlags(getFastmathFlags(fmf));
223 
224 #include "mlir/Dialect/LLVMIR/LLVMConversions.inc"
225 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicConversions.inc"
226 
227  // Emit function calls. If the "callee" attribute is present, this is a
228  // direct function call and we also need to look up the remapped function
229  // itself. Otherwise, this is an indirect call and the callee is the first
230  // operand, look it up as a normal value.
231  if (auto callOp = dyn_cast<LLVM::CallOp>(opInst)) {
232  auto operands = moduleTranslation.lookupValues(callOp.getCalleeOperands());
234  convertOperandBundles(callOp.getOpBundleOperands(),
235  callOp.getOpBundleTags(), moduleTranslation);
236  ArrayRef<llvm::Value *> operandsRef(operands);
237  llvm::CallInst *call;
238  if (auto attr = callOp.getCalleeAttr()) {
239  call =
240  builder.CreateCall(moduleTranslation.lookupFunction(attr.getValue()),
241  operandsRef, opBundles);
242  } else {
243  llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
244  moduleTranslation.convertType(callOp.getCalleeFunctionType()));
245  call = builder.CreateCall(calleeType, operandsRef.front(),
246  operandsRef.drop_front(), opBundles);
247  }
248  call->setCallingConv(convertCConvToLLVM(callOp.getCConv()));
249  call->setTailCallKind(convertTailCallKindToLLVM(callOp.getTailCallKind()));
250  if (callOp.getConvergentAttr())
251  call->addFnAttr(llvm::Attribute::Convergent);
252  if (callOp.getNoUnwindAttr())
253  call->addFnAttr(llvm::Attribute::NoUnwind);
254  if (callOp.getWillReturnAttr())
255  call->addFnAttr(llvm::Attribute::WillReturn);
256 
257  if (MemoryEffectsAttr memAttr = callOp.getMemoryEffectsAttr()) {
258  llvm::MemoryEffects memEffects =
259  llvm::MemoryEffects(llvm::MemoryEffects::Location::ArgMem,
260  convertModRefInfoToLLVM(memAttr.getArgMem())) |
261  llvm::MemoryEffects(
262  llvm::MemoryEffects::Location::InaccessibleMem,
263  convertModRefInfoToLLVM(memAttr.getInaccessibleMem())) |
264  llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
265  convertModRefInfoToLLVM(memAttr.getOther()));
266  call->setMemoryEffects(memEffects);
267  }
268 
269  moduleTranslation.setAccessGroupsMetadata(callOp, call);
270  moduleTranslation.setAliasScopeMetadata(callOp, call);
271  moduleTranslation.setTBAAMetadata(callOp, call);
272  // If the called function has a result, remap the corresponding value. Note
273  // that LLVM IR dialect CallOp has either 0 or 1 result.
274  if (opInst.getNumResults() != 0)
275  moduleTranslation.mapValue(opInst.getResult(0), call);
276  // Check that LLVM call returns void for 0-result functions.
277  else if (!call->getType()->isVoidTy())
278  return failure();
279  moduleTranslation.mapCall(callOp, call);
280  return success();
281  }
282 
283  if (auto inlineAsmOp = dyn_cast<LLVM::InlineAsmOp>(opInst)) {
284  // TODO: refactor function type creation which usually occurs in std-LLVM
285  // conversion.
286  SmallVector<Type, 8> operandTypes;
287  llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
288 
289  Type resultType;
290  if (inlineAsmOp.getNumResults() == 0) {
291  resultType = LLVM::LLVMVoidType::get(&moduleTranslation.getContext());
292  } else {
293  assert(inlineAsmOp.getNumResults() == 1);
294  resultType = inlineAsmOp.getResultTypes()[0];
295  }
296  auto ft = LLVM::LLVMFunctionType::get(resultType, operandTypes);
297  llvm::InlineAsm *inlineAsmInst =
298  inlineAsmOp.getAsmDialect()
300  static_cast<llvm::FunctionType *>(
301  moduleTranslation.convertType(ft)),
302  inlineAsmOp.getAsmString(), inlineAsmOp.getConstraints(),
303  inlineAsmOp.getHasSideEffects(),
304  inlineAsmOp.getIsAlignStack(),
305  convertAsmDialectToLLVM(*inlineAsmOp.getAsmDialect()))
306  : llvm::InlineAsm::get(static_cast<llvm::FunctionType *>(
307  moduleTranslation.convertType(ft)),
308  inlineAsmOp.getAsmString(),
309  inlineAsmOp.getConstraints(),
310  inlineAsmOp.getHasSideEffects(),
311  inlineAsmOp.getIsAlignStack());
312  llvm::CallInst *inst = builder.CreateCall(
313  inlineAsmInst,
314  moduleTranslation.lookupValues(inlineAsmOp.getOperands()));
315  if (auto maybeOperandAttrs = inlineAsmOp.getOperandAttrs()) {
316  llvm::AttributeList attrList;
317  for (const auto &it : llvm::enumerate(*maybeOperandAttrs)) {
318  Attribute attr = it.value();
319  if (!attr)
320  continue;
321  DictionaryAttr dAttr = cast<DictionaryAttr>(attr);
322  TypeAttr tAttr =
323  cast<TypeAttr>(dAttr.get(InlineAsmOp::getElementTypeAttrName()));
324  llvm::AttrBuilder b(moduleTranslation.getLLVMContext());
325  llvm::Type *ty = moduleTranslation.convertType(tAttr.getValue());
326  b.addTypeAttr(llvm::Attribute::ElementType, ty);
327  // shift to account for the returned value (this is always 1 aggregate
328  // value in LLVM).
329  int shift = (opInst.getNumResults() > 0) ? 1 : 0;
330  attrList = attrList.addAttributesAtIndex(
331  moduleTranslation.getLLVMContext(), it.index() + shift, b);
332  }
333  inst->setAttributes(attrList);
334  }
335 
336  if (opInst.getNumResults() != 0)
337  moduleTranslation.mapValue(opInst.getResult(0), inst);
338  return success();
339  }
340 
341  if (auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
342  auto operands = moduleTranslation.lookupValues(invOp.getCalleeOperands());
344  convertOperandBundles(invOp.getOpBundleOperands(),
345  invOp.getOpBundleTags(), moduleTranslation);
346  ArrayRef<llvm::Value *> operandsRef(operands);
347  llvm::InvokeInst *result;
348  if (auto attr = opInst.getAttrOfType<FlatSymbolRefAttr>("callee")) {
349  result = builder.CreateInvoke(
350  moduleTranslation.lookupFunction(attr.getValue()),
351  moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
352  moduleTranslation.lookupBlock(invOp.getSuccessor(1)), operandsRef,
353  opBundles);
354  } else {
355  llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
356  moduleTranslation.convertType(invOp.getCalleeFunctionType()));
357  result = builder.CreateInvoke(
358  calleeType, operandsRef.front(),
359  moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
360  moduleTranslation.lookupBlock(invOp.getSuccessor(1)),
361  operandsRef.drop_front(), opBundles);
362  }
363  result->setCallingConv(convertCConvToLLVM(invOp.getCConv()));
364  moduleTranslation.mapBranch(invOp, result);
365  // InvokeOp can only have 0 or 1 result
366  if (invOp->getNumResults() != 0) {
367  moduleTranslation.mapValue(opInst.getResult(0), result);
368  return success();
369  }
370  return success(result->getType()->isVoidTy());
371  }
372 
373  if (auto lpOp = dyn_cast<LLVM::LandingpadOp>(opInst)) {
374  llvm::Type *ty = moduleTranslation.convertType(lpOp.getType());
375  llvm::LandingPadInst *lpi =
376  builder.CreateLandingPad(ty, lpOp.getNumOperands());
377  lpi->setCleanup(lpOp.getCleanup());
378 
379  // Add clauses
380  for (llvm::Value *operand :
381  moduleTranslation.lookupValues(lpOp.getOperands())) {
382  // All operands should be constant - checked by verifier
383  if (auto *constOperand = dyn_cast<llvm::Constant>(operand))
384  lpi->addClause(constOperand);
385  }
386  moduleTranslation.mapValue(lpOp.getResult(), lpi);
387  return success();
388  }
389 
390  // Emit branches. We need to look up the remapped blocks and ignore the
391  // block arguments that were transformed into PHI nodes.
392  if (auto brOp = dyn_cast<LLVM::BrOp>(opInst)) {
393  llvm::BranchInst *branch =
394  builder.CreateBr(moduleTranslation.lookupBlock(brOp.getSuccessor()));
395  moduleTranslation.mapBranch(&opInst, branch);
396  moduleTranslation.setLoopMetadata(&opInst, branch);
397  return success();
398  }
399  if (auto condbrOp = dyn_cast<LLVM::CondBrOp>(opInst)) {
400  llvm::BranchInst *branch = builder.CreateCondBr(
401  moduleTranslation.lookupValue(condbrOp.getOperand(0)),
402  moduleTranslation.lookupBlock(condbrOp.getSuccessor(0)),
403  moduleTranslation.lookupBlock(condbrOp.getSuccessor(1)));
404  moduleTranslation.mapBranch(&opInst, branch);
405  moduleTranslation.setLoopMetadata(&opInst, branch);
406  return success();
407  }
408  if (auto switchOp = dyn_cast<LLVM::SwitchOp>(opInst)) {
409  llvm::SwitchInst *switchInst = builder.CreateSwitch(
410  moduleTranslation.lookupValue(switchOp.getValue()),
411  moduleTranslation.lookupBlock(switchOp.getDefaultDestination()),
412  switchOp.getCaseDestinations().size());
413 
414  // Handle switch with zero cases.
415  if (!switchOp.getCaseValues())
416  return success();
417 
418  auto *ty = llvm::cast<llvm::IntegerType>(
419  moduleTranslation.convertType(switchOp.getValue().getType()));
420  for (auto i :
421  llvm::zip(llvm::cast<DenseIntElementsAttr>(*switchOp.getCaseValues()),
422  switchOp.getCaseDestinations()))
423  switchInst->addCase(
424  llvm::ConstantInt::get(ty, std::get<0>(i).getLimitedValue()),
425  moduleTranslation.lookupBlock(std::get<1>(i)));
426 
427  moduleTranslation.mapBranch(&opInst, switchInst);
428  return success();
429  }
430 
431  // Emit addressof. We need to look up the global value referenced by the
432  // operation and store it in the MLIR-to-LLVM value mapping. This does not
433  // emit any LLVM instruction.
434  if (auto addressOfOp = dyn_cast<LLVM::AddressOfOp>(opInst)) {
435  LLVM::GlobalOp global =
436  addressOfOp.getGlobal(moduleTranslation.symbolTable());
437  LLVM::LLVMFuncOp function =
438  addressOfOp.getFunction(moduleTranslation.symbolTable());
439 
440  // The verifier should not have allowed this.
441  assert((global || function) &&
442  "referencing an undefined global or function");
443 
444  moduleTranslation.mapValue(
445  addressOfOp.getResult(),
446  global ? moduleTranslation.lookupGlobal(global)
447  : moduleTranslation.lookupFunction(function.getName()));
448  return success();
449  }
450 
451  return failure();
452 }
453 
454 namespace {
455 /// Implementation of the dialect interface that converts operations belonging
456 /// to the LLVM dialect to LLVM IR.
457 class LLVMDialectLLVMIRTranslationInterface
459 public:
461 
462  /// Translates the given operation to LLVM IR using the provided IR builder
463  /// and saving the state in `moduleTranslation`.
464  LogicalResult
465  convertOperation(Operation *op, llvm::IRBuilderBase &builder,
466  LLVM::ModuleTranslation &moduleTranslation) const final {
467  return convertOperationImpl(*op, builder, moduleTranslation);
468  }
469 };
470 } // namespace
471 
473  registry.insert<LLVM::LLVMDialect>();
474  registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
475  dialect->addInterfaces<LLVMDialectLLVMIRTranslationInterface>();
476  });
477 }
478 
480  DialectRegistry registry;
482  context.appendDialectRegistry(registry);
483 }
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 SmallVector< llvm::OperandBundleDef > convertOperandBundles(OperandRangeRange bundleOperands, ArrayRef< std::string > bundleTags, 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 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 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.
const float * table
Attributes are known-constant values of operations.
Definition: Attributes.h:25
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.
Base class for dialect interfaces providing translation to LLVM IR.
Implementation class for module translation.
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.
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.
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.
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 setLoopMetadata(Operation *op, llvm::Instruction *inst)
Sets LLVM loop metadata for branch operations that have a loop annotation attribute.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
void appendDialectRegistry(const DialectRegistry &registry)
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.
Definition: ValueRange.h:82
This class implements the operand iterators for the Operation class.
Definition: ValueRange.h:42
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
AttrClass getAttrOfType(StringAttr name)
Definition: Operation.h:545
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Definition: Operation.h:402
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:223
operand_type_range getOperandTypes()
Definition: Operation.h:392
result_type_range getResultTypes()
Definition: Operation.h:423
result_range getResults()
Definition: Operation.h:410
unsigned getNumResults()
Return the number of results held by this operation.
Definition: Operation.h:399
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Type front()
Return first type in the range.
Definition: TypeRange.h:148
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
Type getType() const
Return the type of this value.
Definition: Value.h:129
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)
Definition: Matchers.h:344
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
void registerLLVMDialectTranslation(DialectRegistry &registry)
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...