summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Adjust License.txt file to use the LLVM licenseMehdi Amini2019-12-231-13/+4
| | | | PiperOrigin-RevId: 286906740
* NFC: Remove unnecessary 'llvm::' prefix from uses of llvm symbols declared ↵River Riddle2019-12-181-2/+2
| | | | | | | | in `mlir` namespace. Aside from being cleaner, this also makes the codebase more consistent. PiperOrigin-RevId: 286206974
* Change MLIR translation functions signatureLei Zhang2019-09-171-11/+2
| | | | | | | | | | This CL changes translation functions to take MemoryBuffer as input and raw_ostream as output. It is generally better to avoid handling files directly in a library (unless the library is specifically for file manipulation) and we can unify all file handling to the mlir-translate binary itself. PiperOrigin-RevId: 269625911
* NFC: Rename Module to ModuleOp.River Riddle2019-07-101-2/+2
| | | | | | Module is a legacy name that only exists as a typedef of ModuleOp. PiperOrigin-RevId: 257427248
* Make TranslateFromMLIRFunction type return LogicalResult instead of boolAlex Zinenko2019-07-041-4/+4
| | | | | | This interface was created before MLIR introduced LogicalResult. PiperOrigin-RevId: 256554557
* NFC: Refactor Module to be value typed.River Riddle2019-07-021-3/+3
| | | | | | As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction. PiperOrigin-RevId: 256196193
* Remove unnecessary C++ specifier in CPP files. NFC.Jacques Pienaar2019-05-201-1/+1
| | | | | | | | These are only required in .h files to disambiguate between C and C++ header files. -- PiperOrigin-RevId: 248219135
* Add transformation of the NVVM dialect to an LLVM module. Only handlesStephan Herhut2019-05-061-447/+6
| | | | | | | | the generation of intrinsics out of NVVM index ops for now. -- PiperOrigin-RevId: 245933152
* Introduce std.varargs attribute to mark variadic arguments functionsMehdi Amini2019-04-071-6/+10
| | | | | | | | | | | This is only teaching the LLVM converter to propagate the attribute onto the function type. MLIR will not recognize this arguments, so it would only be useful when calling for example `printf` with the same arguments across a module. Since varargs is part of the ABI lowering, this is not NFC. -- PiperOrigin-RevId: 242382427
* ExecutionEngine: allow for running MLIR passes during JIT-compilationAlex Zinenko2019-04-071-2/+2
| | | | | | | | | | | | | | | | | The existing implementation of the ExecutionEngine unconditionally runs a list of "default" MLIR passes on the module upon creation. These passes include, among others, dialect conversions from affine to standard and from standard to LLVM IR dialects. In some cases, these conversions might have been performed before ExecutionEngine is created. More advanced use cases may be performing additional transformations that the "default" passes will conflict with. Provide an overload for ExecutionEngine::create that takes a PassManager configured with the passes to run on the module. If it is not provided, do not run any passes. The engine will not be created if the input module, after the pass manager, has any other dialect than the LLVM IR dialect. -- PiperOrigin-RevId: 242127393
* Replace remaining usages of the Instruction class with Operation.River Riddle2019-03-291-27/+27
| | | | PiperOrigin-RevId: 240777521
* Replace remaining usages of "Op::operator->" with "." and remove it.River Riddle2019-03-291-6/+6
| | | | PiperOrigin-RevId: 240210336
* Remove const from Value, Instruction, Argument, and the various methods on theChris Lattner2019-03-291-10/+9
| | | | | | *Op classes. This is a net reduction by almost 400LOC. PiperOrigin-RevId: 239972443
* Remove const from mlir::Block.Chris Lattner2019-03-291-15/+14
| | | | | | This also eliminates some incorrect reinterpret_cast logic working around it, and numerous const-incorrect issues (like block argument iteration). PiperOrigin-RevId: 239712029
* Continue pushing const out of the core IR types - in this case, remove constChris Lattner2019-03-291-9/+9
| | | | | | from Function. PiperOrigin-RevId: 239638635
* Continue pushing const out of the IR types - removing the notion of a 'constChris Lattner2019-03-291-6/+5
| | | | | | Module'. NFC. PiperOrigin-RevId: 239532885
* TableGen most of the LLVM IR Dialect to LLVM IR conversionsAlex Zinenko2019-03-291-122/+23
| | | | | | | | | | | | | | | | | | | | The LLVM IR Dialect strives to be close to the original LLVM IR instructions. The conversion from the LLVM IR Dialect to LLVM IR proper is mostly mechanical and can be automated. Implement TableGen support for generating conversions from a concise pattern form in the TableGen definition of the LLVM IR Dialect operations. It is used for all operations except calls and branches. These operations need access to function and block remapping tables and would require significantly more code to generate the conversions from TableGen definitions than the current manually written conversions. This implementation is accompanied by various necessary changes to the TableGen operation definition infrastructure. In particular, operation definitions now contain named accessors to results as well as named accessors to the variadic operand (returning a vector of operands). The base operation support TableGen file now contains a FunctionAttr definition. The TableGen now allows to query the names of the operation results. PiperOrigin-RevId: 237203077
* Using llvm.noalias attribute when generating LLVMIR.Dimitrios Vytiniotis2019-03-291-1/+18
| | | | PiperOrigin-RevId: 237063104
* Use consistent names for dialect op source filesLei Zhang2019-03-291-1/+1
| | | | | | | | | | | | | | | This CL changes dialect op source files (.h, .cpp, .td) to follow the following convention: <full-dialect-name>/<dialect-namespace>Ops.{h|cpp|td} Builtin and standard dialects are specially treated, though. Both of them do not have dialect namespace; the former is still named as BuiltinOps.* and the latter is named as Ops.*. Purely mechanical. NFC. PiperOrigin-RevId: 236371358
* LLVM IR Dialect: unify call and call0 operationsAlex Zinenko2019-03-291-7/+8
| | | | | | | | | | | | | | When the LLVM IR dialect was implemented, TableGen operation definition scheme did not support operations with variadic results. Therefore, the `call` instruction was split into `call` and `call0` for the single- and zero-result calls (LLVM does not support multi-result operations). Unify `call` and `call0` using the recently added TableGen support for operations with Variadic results. Explicitly verify that the new operation has 0 or 1 results. As a side effect, this change enables clean-ups in the conversion to the LLVM IR dialect that no longer needs to rely on wrapped LLVM IR void types when constructing zero-result calls. PiperOrigin-RevId: 236119197
* Add a Function::isExternal utility to simplify checks for external functions.River Riddle2019-03-291-1/+1
| | | | PiperOrigin-RevId: 235746553
* LLVM IR dialect and translation: support conditional branches with argumentsAlex Zinenko2019-03-291-2/+6
| | | | | | | | | | | | | | | | | Since the goal of the LLVM IR dialect is to reflect LLVM IR in MLIR, the dialect and the conversion procedure must account for the differences betweeen block arguments and LLVM IR PHI nodes. In particular, LLVM IR disallows PHI nodes with different values coming from the same source. Therefore, the LLVM IR dialect now disallows `cond_br` operations that have identical successors accepting arguments, which would lead to invalid PHI nodes. The conversion process resolves the potential PHI source ambiguity by injecting dummy blocks if the same block is used more than once as a successor in an instruction. These dummy blocks branch unconditionally to the original successors, pass them the original operands (available in the dummy block because it is dominated by the original block) and are used instead of them in the original terminator operation. PiperOrigin-RevId: 235682798
* LLVM dialect conversion and target: support indirect callsAlex Zinenko2019-03-291-17/+35
| | | | | | | | | | | | | | | | | | | | Add support for converting MLIR `call_indirect` instructions to the LLVM IR dialect. In LLVM IR, the same instruction is used for direct and indirect calls. In the dialect, we have `llvm.call` and `llvm.call0` to work around the absence of the void type in MLIR. For direct calls, the callee is stored as instruction attribute. Use the same pair of instructions for indirect calls by omitting the callee attribute. In the MLIR to LLVM IR translator, check the presence of attribute to decide whether to construct a direct or an indirect call using different LLVM IR Builder functions. Add support for converting constants of function type to the LLVM IR dialect and for translating them to the LLVM IR proper. The `llvm.constant` operation works similarly to other types: its attribute has MLIR function type but the value it produces has LLVM IR function type wrapped in the dialect type. While lowering, look up the pointer to the converted function in the corresponding mapping. PiperOrigin-RevId: 234132351
* Reimplement LLVM IR translation to use the MLIR LLVM IR dialectAlex Zinenko2019-03-291-709/+317
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Original implementation of the translation from MLIR to LLVM IR operated on the Standard+BuiltIn dialect, with a later addition of the SuperVector dialect. This required the translation to be aware of a potetially large number of other dialects as the infrastructure extended. With the recent introduction of the LLVM IR dialect into MLIR, the translation can be switched to only translate the LLVM IR dialect, and the translation of the operations becomes largely mechanical. The reimplementation of the translator follows the lines of the original translator in function and basic block conversion. In particular, block arguments are converted to LLVM IR PHI nodes, which are connected to their sources after all blocks of a function had been converted. Thanks to LLVM IR types being wrapped in the MLIR LLVM dialect type, type conversion is simplified to only convert function types, all other types are simply unwrapped. Individual instructions are constructed using the LLVM IRBuilder, which has a great potential for being table-generated from the LLVM IR dialect operation definitions. The input of the test/Target/llvmir.mlir is updated to use the MLIR LLVM IR dialect. While it is now redundant with the dialect conversion test, the point of the exercise is to guarantee exactly the same LLVM IR is emitted. (Only the name of the allocation function is changed from `__mlir_alloc` to `alloc` in the CHECK lines.) It will be simplified in a follow-up commit. PiperOrigin-RevId: 233842306
* Remove remaining references to OperationInst in all directories except for ↵River Riddle2019-03-291-12/+11
| | | | | | lib/Transforms. PiperOrigin-RevId: 232322771
* Fold the functionality of OperationInst into Instruction. OperationInst ↵River Riddle2019-03-291-1/+1
| | | | | | still exists as a forward declaration and will be removed incrementally in a set of followup cleanup patches. PiperOrigin-RevId: 232198540
* Fix use of llvm::Module::getOrInsertFunction after the upstream opaque ↵River Riddle2019-03-291-5/+6
| | | | | | pointer type changes. PiperOrigin-RevId: 232002583
* Use formatv for the error instead of string stream.Jacques Pienaar2019-03-291-5/+3
| | | | PiperOrigin-RevId: 231507680
* Migrate VectorOrTensorType/MemRefType shape api to use int64_t instead of int.River Riddle2019-03-291-1/+1
| | | | PiperOrigin-RevId: 230605756
* Fix outdated commentsUday Bondhugula2019-03-291-11/+9
| | | | PiperOrigin-RevId: 229300301
* Extract openInputFile() into Support/FileUtilitiesLei Zhang2019-03-291-0/+1
| | | | | | | | | | Multiple binaries have the needs to open input files. Use this function to de-duplicate the code. Also changed openOutputFile() to return errors using std::string since it is a library call and accessing I/O in library call is not friendly. PiperOrigin-RevId: 228878221
* LLVM IR lowering: support integer division and remainder operationsAlex Zinenko2019-03-291-0/+16
| | | | | | | | | | These operations trivially map to LLVM IR counterparts for operands of scalar and (one-dimensional) vector type. Multi-dimensional vector and tensor type operands would fail type conversion before the operation conversion takes place. Add tests for scalar and vector cases. Also add a test for vector `select` instruction for consistency with other tests. PiperOrigin-RevId: 228077564
* Split the standard types from builtin types and move them into separate ↵River Riddle2019-03-291-4/+4
| | | | | | source files(StandardTypes.cpp/h). After this cl only FunctionType and IndexType are builtin types, but IndexType will likely become a standard type when the ml/cfgfunc merger is done. Mechanical NFC. PiperOrigin-RevId: 227750918
* LLVM IR Lowering: support "select"Alex Zinenko2019-03-291-0/+8
| | | | | | | This commit adds support for the "select" operation that lowers directly into its LLVM IR counterpart. A simple test is included. PiperOrigin-RevId: 227527893
* Simplify the remapFunctionAttrs logic, merging CFG/ML function handling.Chris Lattner2019-03-291-14/+11
| | | | | | | | | | | Remove an unnecessary restriction in forward substitution. Slightly simplify LLVM IR lowering, which previously would crash if given an ML function, it should now produce a clean error if given a function with an if/for instruction in it, just like it does any other unsupported op. This is step 27/n towards merging instructions and statements. PiperOrigin-RevId: 227324542
* Tidy up references to "basic blocks" that should refer to blocks now. NFC.Chris Lattner2019-03-291-2/+2
| | | | PiperOrigin-RevId: 227196077
* Standardize naming of statements -> instructions, revisting the code base to beChris Lattner2019-03-291-1/+1
| | | | | | | | | consistent and moving the using declarations over. Hopefully this is the last truly massive patch in this refactoring. This is step 21/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227178245
* Rename BasicBlock and StmtBlock to Block, and make a pass cleaning it up. I ↵Chris Lattner2019-03-291-9/+7
| | | | | | | | | | | did not make an effort to rename all of the 'bb' names in the codebase, since they are still correct and any specific missed once can be fixed up on demand. The last major renaming is Statement -> Instruction, which is why Statement and Stmt still appears in various places. This is step 19/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227163082
* Eliminate the using decls for MLFunction and CFGFunction standardizing onChris Lattner2019-03-291-6/+6
| | | | | | | | Function. This is step 18/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227139399
* Rename BBArgument -> BlockArgument, Op::getOperation -> Op::getInst(),Chris Lattner2019-03-291-6/+7
| | | | | | | | StmtResult -> InstResult, StmtOperand -> InstOperand, and remove the old names. This is step 17/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227121537
* Merge Operation into OperationInst and standardize nomenclature aroundChris Lattner2019-03-291-6/+6
| | | | | | | | OperationInst. This is a big mechanical patch. This is step 16/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227093712
* Merge SSAValue, CFGValue, and MLValue together into a single Value class, whichChris Lattner2019-03-291-13/+12
| | | | | | | | | is the new base of the SSA value hierarchy. This CL also standardizes all the nomenclature and comments to use 'Value' where appropriate. This also eliminates a large number of cast<MLValue>(x)'s, which is very soothing. This is step 11/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227064624
* Eliminate the Instruction, BasicBlock, CFGFunction, MLFunction, and ↵Chris Lattner2019-03-291-12/+15
| | | | | | | | | | | | ExtFunction classes, using the Statement/StmtBlock hierarchy and Function instead. This *only* changes the internal data structures, it does not affect the user visible syntax or structure of MLIR code. Function gets new "isCFG()" sorts of predicates as a transitional measure. This patch is gross in a number of ways, largely in an effort to reduce the amount of mechanical churn in one go. It introduces a bunch of using decls to keep the old names alive for now, and a bunch of stuff needs to be renamed. This is step 10/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227044402
* LLVM IR lowering: support SubIOp and SubFOpAlex Zinenko2019-03-291-0/+10
| | | | | | | | The binary subtraction operations were not supported by the lowering because they were not essential for the testing flow. Add support for these operations. PiperOrigin-RevId: 226941463
* LLVM IR lowering: support vector_type_castAlex Zinenko2019-03-291-0/+23
| | | | | | | | | | | | | | | | Introduce support for lowering vector_type_cast to LLVM IR. It consists in creating a new MemRef descriptor with the base pointer with the type that corresponds to the lowered element type of the target memref. Since `vector_type_cast` does not support dynamic shapes in the target type, no dynamic size conversion is necessary. This commit goes in the opposite direction of what is expected of LLVM IR lowering: it should not be aware of all the other dialects. Instead, we should have separate definitions for conversions in a global lowering framework. However, this requires LLVM dialect to be implemented, which is currently blocked by the absence of user-defined types. Implement the lowering anyway to unblock end-to-end vectorization experiments. PiperOrigin-RevId: 225887368
* Type system: replace Type::getBitWidth with getIntOrFloatBitWidthAlex Zinenko2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | As MLIR moves towards dialect-specific types, a generic Type::getBitWidth does not make sense for all of them. Even with the current type system, the bit width is not defined (and causes the method in question to abort) for all TensorFlow types. This commit restricts the bit width definition to primitive standard types that have a number of bits appearing verbatim in their type, i.e., integers and floats. As a side effect, it delegates the decision on the bit width of the `index` to the backends. Existing backends currently hardcode it to 64 bits. The Type::getBitWidth method is replaced by Type::getIntOrFloatBitWidth that only applies to integers and floats. The call sites are updated to use the new method, where applicable, or rewritten so as not rely on it. Incidentally, this fixes a utility method that did not account for memrefs being allowed to have vectors as element types in the size computation. As an observation, several places in the code use Type in places where a more specific type could be used instead. Some of those are fixed by this commit. PiperOrigin-RevId: 225844792
* LLVM IR lowering: support 1D vector operationsAlex Zinenko2019-03-291-19/+93
| | | | | | | | | | | | | | | | Introduce initial support for 1D vector operations. LLVM does not support higher-dimensional vectors so the caller must make sure they don't appear in the input MLIR. Handle the presence of higher-dimensional vectors by failing gracefully. Introduce the type conversion for 1D vector types and hook it up with the rest of the type convresion system. Support "splat" constants for vector types. As a side effect, this refactors constant operation emission by separating out scalar integer constants into a separate case and by extracting out the helper function for scalar float construction. Existing binary operations apply to vectors transparently. PiperOrigin-RevId: 225172349
* Return bool from all emitError methods similar to Operation::emitOpErrorSmit Hinsu2019-03-291-23/+12
| | | | | | | | | | | | | This simplifies call-sites returning true after emitting an error. After the conversion, dropped braces around single statement blocks as that seems more common. Also, switched to emitError method instead of emitting Error kind using the emitDiagnostic method. TESTED with existing unit tests PiperOrigin-RevId: 224527868
* LLVM IR Lowering: support multi-value returns.Alex Zinenko2019-03-291-19/+86
| | | | | | | | | Unlike MLIR, LLVM IR does not support functions that return multiple values. Simulate this by packing values into the LLVM structure type in the same order as they appear in the MLIR return. If the function returns only a single value, return it directly without packing. PiperOrigin-RevId: 223964886
* LLVM IR lowering: support 'dim' operation.Alex Zinenko2019-03-291-0/+29
| | | | | | | | | | Add support for translating 'dim' opreation on MemRefs to LLVM IR. For a static size, this operation merely defines an LLVM IR constant value that may not appear in the output IR if not used (and had not been removed before by DCE). For a dynamic size, this operation is translated into an access to the MemRef descriptor that contains the dynamic size. PiperOrigin-RevId: 223160774
OpenPOWER on IntegriCloud