Skip to content

Commit a25baf0

Browse files
LancernNoumanAmir657
authored andcommitted
[mlir][LLVM] Add builders for llvm.intr.assume (llvm#113317)
This patch adds several new builders for llvm.intr.assume that build the operation with additional operand bundles.
1 parent 82779ca commit a25baf0

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "mlir/Support/ThreadLocalCache.h"
3434
#include "llvm/ADT/PointerEmbeddedInt.h"
3535
#include "llvm/IR/DerivedTypes.h"
36+
#include "llvm/IR/InstrTypes.h"
3637
#include "llvm/IR/LLVMContext.h"
3738
#include "llvm/IR/Module.h"
3839
#include "llvm/IR/Type.h"
@@ -87,6 +88,13 @@ class GEPArg : public PointerUnion<Value, GEPConstantIndex> {
8788
} // namespace LLVM
8889
} // namespace mlir
8990

91+
namespace mlir {
92+
namespace LLVM {
93+
struct AssumeAlignTag {};
94+
struct AssumeSeparateStorageTag {};
95+
} // namespace LLVM
96+
} // namespace mlir
97+
9098
///// Ops /////
9199
#define GET_OP_CLASSES
92100
#include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"

mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,14 @@ def LLVM_AssumeOp
450450
}];
451451

452452
let builders = [
453-
OpBuilder<(ins "Value":$cond)>
453+
OpBuilder<(ins "Value":$cond)>,
454+
OpBuilder<(ins "Value":$cond,
455+
"ArrayRef<llvm::OperandBundleDefT<Value>>":$opBundles)>,
456+
OpBuilder<(ins "Value":$cond, "llvm::StringRef":$tag, "ValueRange":$args)>,
457+
OpBuilder<(ins "Value":$cond, "AssumeAlignTag":$tag, "Value":$ptr,
458+
"Value":$align)>,
459+
OpBuilder<(ins "Value":$cond, "AssumeSeparateStorageTag":$tag,
460+
"Value":$ptr1, "Value":$ptr2)>
454461
];
455462

456463
let hasVerifier = 1;

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3438,7 +3438,44 @@ void InlineAsmOp::getEffects(
34383438
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
34393439
mlir::Value cond) {
34403440
return build(builder, state, cond, /*op_bundle_operands=*/{},
3441-
/*op_bundle_tags=*/{});
3441+
/*op_bundle_tags=*/ArrayAttr{});
3442+
}
3443+
3444+
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
3445+
Value cond,
3446+
ArrayRef<llvm::OperandBundleDefT<Value>> opBundles) {
3447+
SmallVector<ValueRange> opBundleOperands;
3448+
SmallVector<Attribute> opBundleTags;
3449+
opBundleOperands.reserve(opBundles.size());
3450+
opBundleTags.reserve(opBundles.size());
3451+
3452+
for (const llvm::OperandBundleDefT<Value> &bundle : opBundles) {
3453+
opBundleOperands.emplace_back(bundle.inputs());
3454+
opBundleTags.push_back(
3455+
StringAttr::get(builder.getContext(), bundle.getTag()));
3456+
}
3457+
3458+
auto opBundleTagsAttr = ArrayAttr::get(builder.getContext(), opBundleTags);
3459+
return build(builder, state, cond, opBundleOperands, opBundleTagsAttr);
3460+
}
3461+
3462+
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
3463+
Value cond, llvm::StringRef tag, ValueRange args) {
3464+
llvm::OperandBundleDefT<Value> opBundle(
3465+
tag.str(), SmallVector<Value>(args.begin(), args.end()));
3466+
return build(builder, state, cond, opBundle);
3467+
}
3468+
3469+
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
3470+
Value cond, AssumeAlignTag, Value ptr, Value align) {
3471+
return build(builder, state, cond, "align", ValueRange{ptr, align});
3472+
}
3473+
3474+
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
3475+
Value cond, AssumeSeparateStorageTag, Value ptr1,
3476+
Value ptr2) {
3477+
return build(builder, state, cond, "separate_storage",
3478+
ValueRange{ptr1, ptr2});
34423479
}
34433480

34443481
LogicalResult LLVM::AssumeOp::verify() { return verifyOperandBundles(*this); }

0 commit comments

Comments
 (0)