Skip to content

Commit c791da3

Browse files
committed
Refactored verification code to NVVMDialect.cpp
1 parent c26f5db commit c791da3

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,7 @@ class NVVM_PureSpecialRangeableRegisterOp<string mnemonic, list<Trait> traits =
283283

284284
// Verify the range attribute satisfies LLVM ConstantRange constructor requirements.
285285
::llvm::LogicalResult $cppClass::verify() {
286-
auto rangeAttr = getRange();
287-
if (!rangeAttr)
288-
return ::mlir::success(); // No range specified, validation passes
289-
290-
const ::llvm::APInt &lower = rangeAttr->getLower();
291-
const ::llvm::APInt &upper = rangeAttr->getUpper();
292-
293-
// Check LLVM ConstantRange constructor condition
294-
if (lower == upper && !lower.isMaxValue() && !lower.isMinValue()) {
295-
unsigned bitWidth = lower.getBitWidth();
296-
::llvm::APInt minVal = ::llvm::APInt::getMinValue(bitWidth);
297-
::llvm::APInt maxVal = ::llvm::APInt::getMaxValue(bitWidth);
298-
return emitOpError("invalid range attribute: Lower == Upper, but they aren't min (")
299-
<< ::llvm::toString(minVal, 10, false) << ") or max ("
300-
<< ::llvm::toString(maxVal, 10, false) << ") value! This is an invalid constant range.";
301-
}
302-
303-
return ::mlir::success();
286+
return verifyConstantRangeAttr(getOperation(), getRange());
304287
}
305288
}];
306289

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,32 @@ static void nvvmInferResultRanges(Operation *op, Value result,
23062306
}
23072307
}
23082308

2309+
/// Verify the range attribute satisfies LLVM ConstantRange constructor
2310+
/// requirements for NVVM SpecialRangeableRegisterOp.
2311+
static LogicalResult
2312+
verifyConstantRangeAttr(Operation *op,
2313+
std::optional<LLVM::ConstantRangeAttr> rangeAttr) {
2314+
if (!rangeAttr)
2315+
return success();
2316+
2317+
const llvm::APInt &lower = rangeAttr->getLower();
2318+
const llvm::APInt &upper = rangeAttr->getUpper();
2319+
2320+
// Check LLVM ConstantRange constructor condition
2321+
if (lower == upper && !lower.isMaxValue() && !lower.isMinValue()) {
2322+
unsigned bitWidth = lower.getBitWidth();
2323+
llvm::APInt minVal = llvm::APInt::getMinValue(bitWidth);
2324+
llvm::APInt maxVal = llvm::APInt::getMaxValue(bitWidth);
2325+
return op->emitOpError(
2326+
"invalid range attribute: Lower == Upper, but they aren't min (")
2327+
<< llvm::toString(minVal, 10, false) << ") or max ("
2328+
<< llvm::toString(maxVal, 10, false)
2329+
<< ") value! This is an invalid constant range.";
2330+
}
2331+
2332+
return success();
2333+
}
2334+
23092335
static llvm::Value *getAsPackedI32(llvm::Value *arg,
23102336
llvm::IRBuilderBase &builder) {
23112337
return builder.CreateBitCast(arg,

0 commit comments

Comments
 (0)