[mlir][LLVM] Add builders for llvm.intr.assume (#113317)

This patch adds several new builders for llvm.intr.assume that build the
operation with additional operand bundles.
This commit is contained in:
Sirui Mu 2024-10-27 11:52:00 +08:00 committed by GitHub
parent 0dd9fdcf83
commit 93da6423af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 2 deletions

View File

@ -33,6 +33,7 @@
#include "mlir/Support/ThreadLocalCache.h"
#include "llvm/ADT/PointerEmbeddedInt.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
@ -87,6 +88,13 @@ public:
} // namespace LLVM
} // namespace mlir
namespace mlir {
namespace LLVM {
struct AssumeAlignTag {};
struct AssumeSeparateStorageTag {};
} // namespace LLVM
} // namespace mlir
///// Ops /////
#define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"

View File

@ -450,7 +450,14 @@ def LLVM_AssumeOp
}];
let builders = [
OpBuilder<(ins "Value":$cond)>
OpBuilder<(ins "Value":$cond)>,
OpBuilder<(ins "Value":$cond,
"ArrayRef<llvm::OperandBundleDefT<Value>>":$opBundles)>,
OpBuilder<(ins "Value":$cond, "llvm::StringRef":$tag, "ValueRange":$args)>,
OpBuilder<(ins "Value":$cond, "AssumeAlignTag":$tag, "Value":$ptr,
"Value":$align)>,
OpBuilder<(ins "Value":$cond, "AssumeSeparateStorageTag":$tag,
"Value":$ptr1, "Value":$ptr2)>
];
let hasVerifier = 1;

View File

@ -3438,7 +3438,44 @@ void InlineAsmOp::getEffects(
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
mlir::Value cond) {
return build(builder, state, cond, /*op_bundle_operands=*/{},
/*op_bundle_tags=*/{});
/*op_bundle_tags=*/ArrayAttr{});
}
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
Value cond,
ArrayRef<llvm::OperandBundleDefT<Value>> opBundles) {
SmallVector<ValueRange> opBundleOperands;
SmallVector<Attribute> opBundleTags;
opBundleOperands.reserve(opBundles.size());
opBundleTags.reserve(opBundles.size());
for (const llvm::OperandBundleDefT<Value> &bundle : opBundles) {
opBundleOperands.emplace_back(bundle.inputs());
opBundleTags.push_back(
StringAttr::get(builder.getContext(), bundle.getTag()));
}
auto opBundleTagsAttr = ArrayAttr::get(builder.getContext(), opBundleTags);
return build(builder, state, cond, opBundleOperands, opBundleTagsAttr);
}
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
Value cond, llvm::StringRef tag, ValueRange args) {
llvm::OperandBundleDefT<Value> opBundle(
tag.str(), SmallVector<Value>(args.begin(), args.end()));
return build(builder, state, cond, opBundle);
}
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
Value cond, AssumeAlignTag, Value ptr, Value align) {
return build(builder, state, cond, "align", ValueRange{ptr, align});
}
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
Value cond, AssumeSeparateStorageTag, Value ptr1,
Value ptr2) {
return build(builder, state, cond, "separate_storage",
ValueRange{ptr1, ptr2});
}
LogicalResult LLVM::AssumeOp::verify() { return verifyOperandBundles(*this); }