MLIR  19.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 os.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 /// Builder for LLVM_CallIntrinsicOp
106 static LogicalResult
107 convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase &builder,
108  LLVM::ModuleTranslation &moduleTranslation) {
109  llvm::Module *module = builder.GetInsertBlock()->getModule();
111  llvm::Function::lookupIntrinsicID(op.getIntrinAttr());
112  if (!id)
113  return mlir::emitError(op.getLoc(), "could not find LLVM intrinsic: ")
114  << op.getIntrinAttr();
115 
116  llvm::Function *fn = nullptr;
117  if (llvm::Intrinsic::isOverloaded(id)) {
118  auto fnOrFailure =
119  getOverloadedDeclaration(op, id, module, moduleTranslation);
120  if (failed(fnOrFailure))
121  return failure();
122  fn = *fnOrFailure;
123  } else {
124  fn = llvm::Intrinsic::getDeclaration(module, id, {});
125  }
126 
127  // Check the result type of the call.
128  const llvm::Type *intrinType =
129  op.getNumResults() == 0
130  ? llvm::Type::getVoidTy(module->getContext())
131  : moduleTranslation.convertType(op.getResultTypes().front());
132  if (intrinType != fn->getReturnType()) {
133  return mlir::emitError(op.getLoc(), "intrinsic call returns ")
134  << diagStr(intrinType) << " but " << op.getIntrinAttr()
135  << " actually returns " << diagStr(fn->getReturnType());
136  }
137 
138  // Check the argument types of the call. If the function is variadic, check
139  // the subrange of required arguments.
140  if (!fn->getFunctionType()->isVarArg() &&
141  op.getNumOperands() != fn->arg_size()) {
142  return mlir::emitError(op.getLoc(), "intrinsic call has ")
143  << op.getNumOperands() << " operands but " << op.getIntrinAttr()
144  << " expects " << fn->arg_size();
145  }
146  if (fn->getFunctionType()->isVarArg() &&
147  op.getNumOperands() < fn->arg_size()) {
148  return mlir::emitError(op.getLoc(), "intrinsic call has ")
149  << op.getNumOperands() << " operands but variadic "
150  << op.getIntrinAttr() << " expects at least " << fn->arg_size();
151  }
152  // Check the arguments up to the number the function requires.
153  for (unsigned i = 0, e = fn->arg_size(); i != e; ++i) {
154  const llvm::Type *expected = fn->getArg(i)->getType();
155  const llvm::Type *actual =
156  moduleTranslation.convertType(op.getOperandTypes()[i]);
157  if (actual != expected) {
158  return mlir::emitError(op.getLoc(), "intrinsic call operand #")
159  << i << " has type " << diagStr(actual) << " but "
160  << op.getIntrinAttr() << " expects " << diagStr(expected);
161  }
162  }
163 
164  FastmathFlagsInterface itf = op;
165  builder.setFastMathFlags(getFastmathFlags(itf));
166 
167  auto *inst =
168  builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
169  if (op.getNumResults() == 1)
170  moduleTranslation.mapValue(op->getResults().front()) = inst;
171  return success();
172 }
173 
174 static void convertLinkerOptionsOp(ArrayAttr options,
175  llvm::IRBuilderBase &builder,
176  LLVM::ModuleTranslation &moduleTranslation) {
177  llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
178  llvm::LLVMContext &context = llvmModule->getContext();
179  llvm::NamedMDNode *linkerMDNode =
180  llvmModule->getOrInsertNamedMetadata("llvm.linker.options");
182  MDNodes.reserve(options.size());
183  for (auto s : options.getAsRange<StringAttr>()) {
184  auto *MDNode = llvm::MDString::get(context, s.getValue());
185  MDNodes.push_back(MDNode);
186  }
187 
188  auto *listMDNode = llvm::MDTuple::get(context, MDNodes);
189  linkerMDNode->addOperand(listMDNode);
190 }
191 
192 static LogicalResult
193 convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
194  LLVM::ModuleTranslation &moduleTranslation) {
195 
196  llvm::IRBuilder<>::FastMathFlagGuard fmfGuard(builder);
197  if (auto fmf = dyn_cast<FastmathFlagsInterface>(opInst))
198  builder.setFastMathFlags(getFastmathFlags(fmf));
199 
200 #include "mlir/Dialect/LLVMIR/LLVMConversions.inc"
201 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicConversions.inc"
202 
203  // Emit function calls. If the "callee" attribute is present, this is a
204  // direct function call and we also need to look up the remapped function
205  // itself. Otherwise, this is an indirect call and the callee is the first
206  // operand, look it up as a normal value.
207  if (auto callOp = dyn_cast<LLVM::CallOp>(opInst)) {
208  auto operands = moduleTranslation.lookupValues(callOp.getOperands());
209  ArrayRef<llvm::Value *> operandsRef(operands);
210  llvm::CallInst *call;
211  if (auto attr = callOp.getCalleeAttr()) {
212  call = builder.CreateCall(
213  moduleTranslation.lookupFunction(attr.getValue()), operandsRef);
214  } else {
215  llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
216  moduleTranslation.convertType(callOp.getCalleeFunctionType()));
217  call = builder.CreateCall(calleeType, operandsRef.front(),
218  operandsRef.drop_front());
219  }
220  call->setCallingConv(convertCConvToLLVM(callOp.getCConv()));
221  call->setTailCallKind(convertTailCallKindToLLVM(callOp.getTailCallKind()));
222  moduleTranslation.setAccessGroupsMetadata(callOp, call);
223  moduleTranslation.setAliasScopeMetadata(callOp, call);
224  moduleTranslation.setTBAAMetadata(callOp, call);
225  // If the called function has a result, remap the corresponding value. Note
226  // that LLVM IR dialect CallOp has either 0 or 1 result.
227  if (opInst.getNumResults() != 0)
228  moduleTranslation.mapValue(opInst.getResult(0), call);
229  // Check that LLVM call returns void for 0-result functions.
230  else if (!call->getType()->isVoidTy())
231  return failure();
232  moduleTranslation.mapCall(callOp, call);
233  return success();
234  }
235 
236  if (auto inlineAsmOp = dyn_cast<LLVM::InlineAsmOp>(opInst)) {
237  // TODO: refactor function type creation which usually occurs in std-LLVM
238  // conversion.
239  SmallVector<Type, 8> operandTypes;
240  llvm::append_range(operandTypes, inlineAsmOp.getOperands().getTypes());
241 
242  Type resultType;
243  if (inlineAsmOp.getNumResults() == 0) {
244  resultType = LLVM::LLVMVoidType::get(&moduleTranslation.getContext());
245  } else {
246  assert(inlineAsmOp.getNumResults() == 1);
247  resultType = inlineAsmOp.getResultTypes()[0];
248  }
249  auto ft = LLVM::LLVMFunctionType::get(resultType, operandTypes);
250  llvm::InlineAsm *inlineAsmInst =
251  inlineAsmOp.getAsmDialect()
253  static_cast<llvm::FunctionType *>(
254  moduleTranslation.convertType(ft)),
255  inlineAsmOp.getAsmString(), inlineAsmOp.getConstraints(),
256  inlineAsmOp.getHasSideEffects(),
257  inlineAsmOp.getIsAlignStack(),
258  convertAsmDialectToLLVM(*inlineAsmOp.getAsmDialect()))
259  : llvm::InlineAsm::get(static_cast<llvm::FunctionType *>(
260  moduleTranslation.convertType(ft)),
261  inlineAsmOp.getAsmString(),
262  inlineAsmOp.getConstraints(),
263  inlineAsmOp.getHasSideEffects(),
264  inlineAsmOp.getIsAlignStack());
265  llvm::CallInst *inst = builder.CreateCall(
266  inlineAsmInst,
267  moduleTranslation.lookupValues(inlineAsmOp.getOperands()));
268  if (auto maybeOperandAttrs = inlineAsmOp.getOperandAttrs()) {
269  llvm::AttributeList attrList;
270  for (const auto &it : llvm::enumerate(*maybeOperandAttrs)) {
271  Attribute attr = it.value();
272  if (!attr)
273  continue;
274  DictionaryAttr dAttr = cast<DictionaryAttr>(attr);
275  TypeAttr tAttr =
276  cast<TypeAttr>(dAttr.get(InlineAsmOp::getElementTypeAttrName()));
277  llvm::AttrBuilder b(moduleTranslation.getLLVMContext());
278  llvm::Type *ty = moduleTranslation.convertType(tAttr.getValue());
279  b.addTypeAttr(llvm::Attribute::ElementType, ty);
280  // shift to account for the returned value (this is always 1 aggregate
281  // value in LLVM).
282  int shift = (opInst.getNumResults() > 0) ? 1 : 0;
283  attrList = attrList.addAttributesAtIndex(
284  moduleTranslation.getLLVMContext(), it.index() + shift, b);
285  }
286  inst->setAttributes(attrList);
287  }
288 
289  if (opInst.getNumResults() != 0)
290  moduleTranslation.mapValue(opInst.getResult(0), inst);
291  return success();
292  }
293 
294  if (auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
295  auto operands = moduleTranslation.lookupValues(invOp.getCalleeOperands());
296  ArrayRef<llvm::Value *> operandsRef(operands);
297  llvm::InvokeInst *result;
298  if (auto attr = opInst.getAttrOfType<FlatSymbolRefAttr>("callee")) {
299  result = builder.CreateInvoke(
300  moduleTranslation.lookupFunction(attr.getValue()),
301  moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
302  moduleTranslation.lookupBlock(invOp.getSuccessor(1)), operandsRef);
303  } else {
304  llvm::FunctionType *calleeType = llvm::cast<llvm::FunctionType>(
305  moduleTranslation.convertType(invOp.getCalleeFunctionType()));
306  result = builder.CreateInvoke(
307  calleeType, operandsRef.front(),
308  moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
309  moduleTranslation.lookupBlock(invOp.getSuccessor(1)),
310  operandsRef.drop_front());
311  }
312  result->setCallingConv(convertCConvToLLVM(invOp.getCConv()));
313  moduleTranslation.mapBranch(invOp, result);
314  // InvokeOp can only have 0 or 1 result
315  if (invOp->getNumResults() != 0) {
316  moduleTranslation.mapValue(opInst.getResult(0), result);
317  return success();
318  }
319  return success(result->getType()->isVoidTy());
320  }
321 
322  if (auto lpOp = dyn_cast<LLVM::LandingpadOp>(opInst)) {
323  llvm::Type *ty = moduleTranslation.convertType(lpOp.getType());
324  llvm::LandingPadInst *lpi =
325  builder.CreateLandingPad(ty, lpOp.getNumOperands());
326  lpi->setCleanup(lpOp.getCleanup());
327 
328  // Add clauses
329  for (llvm::Value *operand :
330  moduleTranslation.lookupValues(lpOp.getOperands())) {
331  // All operands should be constant - checked by verifier
332  if (auto *constOperand = dyn_cast<llvm::Constant>(operand))
333  lpi->addClause(constOperand);
334  }
335  moduleTranslation.mapValue(lpOp.getResult(), lpi);
336  return success();
337  }
338 
339  // Emit branches. We need to look up the remapped blocks and ignore the
340  // block arguments that were transformed into PHI nodes.
341  if (auto brOp = dyn_cast<LLVM::BrOp>(opInst)) {
342  llvm::BranchInst *branch =
343  builder.CreateBr(moduleTranslation.lookupBlock(brOp.getSuccessor()));
344  moduleTranslation.mapBranch(&opInst, branch);
345  moduleTranslation.setLoopMetadata(&opInst, branch);
346  return success();
347  }
348  if (auto condbrOp = dyn_cast<LLVM::CondBrOp>(opInst)) {
349  llvm::BranchInst *branch = builder.CreateCondBr(
350  moduleTranslation.lookupValue(condbrOp.getOperand(0)),
351  moduleTranslation.lookupBlock(condbrOp.getSuccessor(0)),
352  moduleTranslation.lookupBlock(condbrOp.getSuccessor(1)));
353  moduleTranslation.mapBranch(&opInst, branch);
354  moduleTranslation.setLoopMetadata(&opInst, branch);
355  return success();
356  }
357  if (auto switchOp = dyn_cast<LLVM::SwitchOp>(opInst)) {
358  llvm::SwitchInst *switchInst = builder.CreateSwitch(
359  moduleTranslation.lookupValue(switchOp.getValue()),
360  moduleTranslation.lookupBlock(switchOp.getDefaultDestination()),
361  switchOp.getCaseDestinations().size());
362 
363  // Handle switch with zero cases.
364  if (!switchOp.getCaseValues())
365  return success();
366 
367  auto *ty = llvm::cast<llvm::IntegerType>(
368  moduleTranslation.convertType(switchOp.getValue().getType()));
369  for (auto i :
370  llvm::zip(llvm::cast<DenseIntElementsAttr>(*switchOp.getCaseValues()),
371  switchOp.getCaseDestinations()))
372  switchInst->addCase(
373  llvm::ConstantInt::get(ty, std::get<0>(i).getLimitedValue()),
374  moduleTranslation.lookupBlock(std::get<1>(i)));
375 
376  moduleTranslation.mapBranch(&opInst, switchInst);
377  return success();
378  }
379 
380  // Emit addressof. We need to look up the global value referenced by the
381  // operation and store it in the MLIR-to-LLVM value mapping. This does not
382  // emit any LLVM instruction.
383  if (auto addressOfOp = dyn_cast<LLVM::AddressOfOp>(opInst)) {
384  LLVM::GlobalOp global =
385  addressOfOp.getGlobal(moduleTranslation.symbolTable());
386  LLVM::LLVMFuncOp function =
387  addressOfOp.getFunction(moduleTranslation.symbolTable());
388 
389  // The verifier should not have allowed this.
390  assert((global || function) &&
391  "referencing an undefined global or function");
392 
393  moduleTranslation.mapValue(
394  addressOfOp.getResult(),
395  global ? moduleTranslation.lookupGlobal(global)
396  : moduleTranslation.lookupFunction(function.getName()));
397  return success();
398  }
399 
400  return failure();
401 }
402 
403 namespace {
404 /// Implementation of the dialect interface that converts operations belonging
405 /// to the LLVM dialect to LLVM IR.
406 class LLVMDialectLLVMIRTranslationInterface
408 public:
410 
411  /// Translates the given operation to LLVM IR using the provided IR builder
412  /// and saving the state in `moduleTranslation`.
413  LogicalResult
414  convertOperation(Operation *op, llvm::IRBuilderBase &builder,
415  LLVM::ModuleTranslation &moduleTranslation) const final {
416  return convertOperationImpl(*op, builder, moduleTranslation);
417  }
418 };
419 } // namespace
420 
422  registry.insert<LLVM::LLVMDialect>();
423  registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
424  dialect->addInterfaces<LLVMDialectLLVMIRTranslationInterface>();
425  });
426 }
427 
429  DialectRegistry registry;
431  context.appendDialectRegistry(registry);
432 }
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 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 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.
Definition: Attributes.h:25
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtension(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.
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
unsigned getNumOperands()
Definition: Operation.h:341
operand_type_range getOperandTypes()
Definition: Operation.h:392
result_type_range getResultTypes()
Definition: Operation.h:423
operand_range getOperands()
Returns an iterator on the underlying Value's.
Definition: Operation.h:373
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
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:285
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...