-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid post-processing generated LLVM IR
Signed-off-by: Whitney Tsang <whitney.tsang@intel.com>
- Loading branch information
1 parent
3acbc5d
commit e3064fd
Showing
14 changed files
with
147 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
third_party/intel/include/Target/LLVMIR/Dialect/TritonGEN/TritonGENToLLVMIRTranslation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//===-TritonGENToLLVMIRTranslation.h-TritonGEN Dialect to LLVM IR - C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This provides registration calls for TritonGEN dialect to LLVM IR | ||
// translation. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TRITON_TARGET_LLVMIR_DIALECT_TRITONGEN_TRITONGENTOLLVMIRTRANSLATION_H | ||
#define TRITON_TARGET_LLVMIR_DIALECT_TRITONGEN_TRITONGENTOLLVMIRTRANSLATION_H | ||
|
||
namespace mlir { | ||
|
||
class DialectRegistry; | ||
class MLIRContext; | ||
|
||
/// Register the TritonGEN dialect and the translation from it to the LLVM IR in | ||
/// the given registry; | ||
void registerTritonGENDialectTranslation(DialectRegistry ®istry); | ||
|
||
/// Register the TritonGEN dialect and the translation from it in the registry | ||
/// associated with the given context. | ||
void registerTritonGENDialectTranslation(MLIRContext &context); | ||
|
||
} // namespace mlir | ||
|
||
#endif // TRITON_TARGET_LLVMIR_DIALECT_TRITONGEN_TRITONGENTOLLVMIRTRANSLATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
add_subdirectory(Dialect) | ||
add_subdirectory(GPUToTritonGEN) | ||
add_subdirectory(Target) | ||
add_subdirectory(TritonGENToLLVM) | ||
add_subdirectory(TritonIntelGPUToLLVM) | ||
add_subdirectory(TritonIntelGPUTransforms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(LLVMIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(Dialect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(TritonGEN) |
13 changes: 13 additions & 0 deletions
13
third_party/intel/lib/Target/LLVMIR/Dialect/TritonGEN/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_mlir_translation_library(TritonGENToLLVMIRTranslation | ||
TritonGENToLLVMIRTranslation.cpp | ||
|
||
LINK_COMPONENTS | ||
Core | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
TritonGENIR | ||
MLIRLLVMDialect | ||
MLIRSupport | ||
MLIRTargetLLVMIRExport | ||
) |
83 changes: 83 additions & 0 deletions
83
third_party/intel/lib/Target/LLVMIR/Dialect/TritonGEN/TritonGENToLLVMIRTranslation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//===-TritonGENToLLVMIRTranslation.cpp - TritonGEN Dialect to LLVM IR -----===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements a translation between the TritonGEN dialect and LLVM IR. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Target/LLVMIR/Dialect/TritonGEN/TritonGENToLLVMIRTranslation.h" | ||
|
||
#include "Dialect/TritonGEN/IR/TritonGENDialect.h" | ||
#include "mlir/Dialect/Utils/StaticValueUtils.h" | ||
#include "mlir/IR/DialectRegistry.h" | ||
#include "mlir/IR/MLIRContext.h" | ||
#include "mlir/Support/LogicalResult.h" | ||
#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" | ||
#include "mlir/Target/LLVMIR/ModuleTranslation.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/IR/LLVMContext.h" | ||
#include "llvm/IR/Metadata.h" | ||
|
||
namespace { | ||
using namespace mlir; | ||
class TritonGENDialectLLVMIRTranslationInterface | ||
: public LLVMTranslationDialectInterface { | ||
public: | ||
using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface; | ||
|
||
LogicalResult | ||
amendOperation(Operation *op, ArrayRef<llvm::Instruction *> instructions, | ||
NamedAttribute attribute, | ||
LLVM::ModuleTranslation &moduleTranslation) const final { | ||
llvm::LLVMContext &llvmContext = moduleTranslation.getLLVMContext(); | ||
llvm::Function *llvmFunc = | ||
moduleTranslation.lookupFunction(cast<LLVM::LLVMFuncOp>(op).getName()); | ||
if (isKernel(op)) | ||
amendKernel(llvmContext, llvmFunc, attribute); | ||
return success(); | ||
} | ||
|
||
private: | ||
// Checks if the given operation is a kernel function. | ||
bool isKernel(Operation *op) const { | ||
auto fn = dyn_cast<LLVM::LLVMFuncOp>(op); | ||
return fn && fn.getCConv() == LLVM::CConv::SPIR_KERNEL; | ||
} | ||
|
||
// The attribute is converted into metadata and added to the function. | ||
void amendKernel(llvm::LLVMContext &llvmContext, llvm::Function *llvmFunc, | ||
NamedAttribute attribute) const { | ||
SmallVector<llvm::Metadata *, 3> metadata; | ||
llvm::Type *i64 = llvm::IntegerType::get(llvmContext, 64); | ||
for (int64_t i : | ||
extractFromIntegerArrayAttr<int64_t>(attribute.getValue())) { | ||
llvm::Constant *constant = llvm::ConstantInt::get(i64, i); | ||
metadata.push_back(llvm::ConstantAsMetadata::get(constant)); | ||
} | ||
llvm::MDNode *node = llvm::MDNode::get(llvmContext, metadata); | ||
llvmFunc->setMetadata(attribute.getName().getValue().drop_front(11), node); | ||
} | ||
}; | ||
} // namespace | ||
|
||
namespace mlir { | ||
void registerTritonGENDialectTranslation(DialectRegistry ®istry) { | ||
registry.insert<triton::TritonGEN::TritonGENDialect>(); | ||
registry.addExtension( | ||
+[](MLIRContext *ctx, triton::TritonGEN::TritonGENDialect *dialect) { | ||
dialect->addInterfaces<TritonGENDialectLLVMIRTranslationInterface>(); | ||
}); | ||
} | ||
|
||
void registerTritonGENDialectTranslation(MLIRContext &context) { | ||
DialectRegistry registry; | ||
registerTritonGENDialectTranslation(registry); | ||
context.appendDialectRegistry(registry); | ||
} | ||
} // namespace mlir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters