forked from OSchip/llvm-project
Add LLVM::IntToPtrOp and LLVM::PtrToIntOp to LLVM dialect.
-- PiperOrigin-RevId: 249604199
This commit is contained in:
parent
51feed5518
commit
b52112275d
|
@ -118,7 +118,7 @@ class LLVM_ArithmeticOp<string mnemonic, string builderFunc,
|
|||
Arguments<(ins LLVM_Type:$lhs, LLVM_Type:$rhs)>,
|
||||
LLVM_Builder<"$res = builder." # builderFunc # "($lhs, $rhs);"> {
|
||||
let parser = [{ return impl::parseBinaryOp(parser, result); }];
|
||||
let printer = [{ printLLVMBinaryOp(p, this->getOperation()); }];
|
||||
let printer = [{ mlir::impl::printBinaryOp(this->getOperation(), p); }];
|
||||
}
|
||||
|
||||
// Integer binary operations.
|
||||
|
@ -183,10 +183,23 @@ def LLVM_BitcastOp
|
|||
: LLVM_OneResultOp<"bitcast", [NoSideEffect]>,
|
||||
Arguments<(ins LLVM_Type:$arg)>,
|
||||
LLVM_Builder<"$res = builder.CreateBitCast($arg, $_resultType);"> {
|
||||
let parser = [{ return parseBitcastOp(parser, result); }];
|
||||
let printer = [{ printBitcastOp(p, *this); }];
|
||||
let parser = [{ return mlir::impl::parseCastOp(parser, result); }];
|
||||
let printer = [{ mlir::impl::printCastOp(this->getOperation(), p); }];
|
||||
}
|
||||
def LLVM_IntToPtrOp
|
||||
: LLVM_OneResultOp<"inttoptr", [NoSideEffect]>,
|
||||
Arguments<(ins LLVM_Type:$arg)>,
|
||||
LLVM_Builder<"$res = builder.CreateIntToPtr($arg, $_resultType);"> {
|
||||
let parser = [{ return mlir::impl::parseCastOp(parser, result); }];
|
||||
let printer = [{ mlir::impl::printCastOp(this->getOperation(), p); }];
|
||||
}
|
||||
def LLVM_PtrToIntOp
|
||||
: LLVM_OneResultOp<"ptrtoint", [NoSideEffect]>,
|
||||
Arguments<(ins LLVM_Type:$arg)>,
|
||||
LLVM_Builder<"$res = builder.CreatePtrToInt($arg, $_resultType);"> {
|
||||
let parser = [{ return mlir::impl::parseCastOp(parser, result); }];
|
||||
let printer = [{ mlir::impl::printCastOp(this->getOperation(), p); }];
|
||||
}
|
||||
|
||||
// Call-related operations.
|
||||
def LLVM_CallOp : LLVM_Op<"call">,
|
||||
Arguments<(ins OptionalAttr<FunctionAttr>:$callee,
|
||||
|
|
|
@ -990,6 +990,7 @@ ParseResult impl::parseCastOp(OpAsmParser *parser, OperationState *result) {
|
|||
OpAsmParser::OperandType srcInfo;
|
||||
Type srcType, dstType;
|
||||
return failure(parser->parseOperand(srcInfo) ||
|
||||
parser->parseOptionalAttributeDict(result->attributes) ||
|
||||
parser->parseColonType(srcType) ||
|
||||
parser->resolveOperand(srcInfo, srcType, result->operands) ||
|
||||
parser->parseKeywordType("to", dstType) ||
|
||||
|
@ -997,8 +998,10 @@ ParseResult impl::parseCastOp(OpAsmParser *parser, OperationState *result) {
|
|||
}
|
||||
|
||||
void impl::printCastOp(Operation *op, OpAsmPrinter *p) {
|
||||
*p << op->getName() << ' ' << *op->getOperand(0) << " : "
|
||||
<< op->getOperand(0)->getType() << " to " << op->getResult(0)->getType();
|
||||
*p << op->getName() << ' ' << *op->getOperand(0);
|
||||
p->printOptionalAttrDict(op->getAttrs());
|
||||
*p << " : " << op->getOperand(0)->getType() << " to "
|
||||
<< op->getResult(0)->getType();
|
||||
}
|
||||
|
||||
Value *impl::foldCastOp(Operation *op) {
|
||||
|
|
|
@ -35,24 +35,6 @@
|
|||
using namespace mlir;
|
||||
using namespace mlir::LLVM;
|
||||
|
||||
static void printLLVMBinaryOp(OpAsmPrinter *p, Operation *op) {
|
||||
// Fallback to the generic form if the op is not well-formed (may happen
|
||||
// during incomplete rewrites, and used for debugging).
|
||||
const auto *abstract = op->getAbstractOperation();
|
||||
(void)abstract;
|
||||
assert(abstract && "pretty printing an unregistered operation");
|
||||
|
||||
auto resultType = op->getResult(0)->getType();
|
||||
if (resultType != op->getOperand(0)->getType() ||
|
||||
resultType != op->getOperand(1)->getType())
|
||||
return p->printGenericOp(op);
|
||||
|
||||
*p << op->getName().getStringRef() << ' ' << *op->getOperand(0) << ", "
|
||||
<< *op->getOperand(1);
|
||||
p->printOptionalAttrDict(op->getAttrs());
|
||||
*p << " : " << op->getResult(0)->getType();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Printing/parsing for LLVM::ICmpOp.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -321,33 +303,6 @@ static ParseResult parseStoreOp(OpAsmParser *parser, OperationState *result) {
|
|||
return success();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Printing/parsing for LLVM::BitcastOp.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static void printBitcastOp(OpAsmPrinter *p, BitcastOp &op) {
|
||||
*p << op.getOperationName() << ' ' << *op.arg();
|
||||
p->printOptionalAttrDict(op.getAttrs());
|
||||
*p << " : " << op.arg()->getType() << " to " << op.getType();
|
||||
}
|
||||
|
||||
// <operation> ::= `llvm.bitcast` ssa-use attribute-dict? `:` type `to` type
|
||||
static ParseResult parseBitcastOp(OpAsmParser *parser, OperationState *result) {
|
||||
SmallVector<NamedAttribute, 4> attrs;
|
||||
OpAsmParser::OperandType arg;
|
||||
Type sourceType, type;
|
||||
|
||||
if (parser->parseOperand(arg) || parser->parseOptionalAttributeDict(attrs) ||
|
||||
parser->parseColonType(sourceType) || parser->parseKeyword("to") ||
|
||||
parser->parseType(type) ||
|
||||
parser->resolveOperand(arg, sourceType, result->operands))
|
||||
return failure();
|
||||
|
||||
result->attributes = attrs;
|
||||
result->addTypes(type);
|
||||
return success();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Printing/parsing for LLVM::CallOp.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -78,8 +78,16 @@ func @ops(%arg0 : !llvm.i32, %arg1 : !llvm.float) {
|
|||
|
||||
// Misc operations.
|
||||
// CHECK: %24 = llvm.select %7, %0, %1 : !llvm.i1, !llvm.i32
|
||||
// CHECK-NEXT: llvm.return
|
||||
%24 = llvm.select %7, %0, %1 : !llvm.i1, !llvm.i32
|
||||
|
||||
// Integer to pointer and pointer to integer conversions.
|
||||
//
|
||||
// CHECK: %25 = llvm.inttoptr %arg0 : !llvm.i32 to !llvm<"i32*">
|
||||
// CHECK-NEXT: %26 = llvm.ptrtoint %25 : !llvm<"i32*"> to !llvm.i32
|
||||
%25 = llvm.inttoptr %arg0 : !llvm.i32 to !llvm<"i32*">
|
||||
%26 = llvm.ptrtoint %25 : !llvm<"i32*"> to !llvm.i32
|
||||
|
||||
// CHECK: llvm.return
|
||||
llvm.return
|
||||
}
|
||||
|
||||
|
|
|
@ -810,3 +810,12 @@ func @llvm_noalias(%arg0: !llvm<"float*"> {llvm.noalias: true}) {
|
|||
// CHECK-LABEL: @llvm_varargs(...)
|
||||
func @llvm_varargs()
|
||||
attributes {std.varargs: true}
|
||||
|
||||
func @intpointerconversion(%arg0 : !llvm.i32) -> !llvm.i32 {
|
||||
// CHECK: %2 = inttoptr i32 %0 to i32*
|
||||
// CHECK-NEXT: %3 = ptrtoint i32* %2 to i32
|
||||
%1 = llvm.inttoptr %arg0 : !llvm.i32 to !llvm<"i32*">
|
||||
%2 = llvm.ptrtoint %1 : !llvm<"i32*"> to !llvm.i32
|
||||
llvm.return %2 : !llvm.i32
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue