Skip to content

Commit

Permalink
[CIR] Add MemRead/MemWrite markers to bitfield ops (llvm#507)
Browse files Browse the repository at this point in the history
This PR adds MemRead/MemWrite markers to the `GetBitfieldOp` and
`SetBitfieldOp` (as discussed in llvm#487)
Also, minor renaming in the `SetBitfieldOp`

---------

Co-authored-by: Bruno Cardoso Lopes <[email protected]>
  • Loading branch information
2 people authored and lanza committed Jun 20, 2024
1 parent 69fa22a commit 6e6fb5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1759,20 +1759,20 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
}];

let arguments = (ins
CIR_PointerType:$dst,
Arg<CIR_PointerType, "the address to store the value", [MemWrite]>:$addr,
CIR_AnyType:$src,
BitfieldInfoAttr:$bitfield_info,
UnitAttr:$is_volatile
);

let results = (outs CIR_IntType:$result);

let assemblyFormat = [{ `(`$bitfield_info`,` $dst`:`qualified(type($dst))`,`
let assemblyFormat = [{ `(`$bitfield_info`,` $addr`:`qualified(type($addr))`,`
$src`:`type($src) `)` attr-dict `->` type($result) }];

let builders = [
OpBuilder<(ins "Type":$type,
"Value":$dst,
"Value":$addr,
"Type":$storage_type,
"Value":$src,
"StringRef":$name,
Expand All @@ -1786,7 +1786,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
BitfieldInfoAttr::get($_builder.getContext(),
name, storage_type,
size, offset, is_signed);
build($_builder, $_state, type, dst, src, info, is_volatile);
build($_builder, $_state, type, addr, src, info, is_volatile);
}]>
];
}
Expand Down Expand Up @@ -1838,7 +1838,7 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
}];

let arguments = (ins
CIR_PointerType:$addr,
Arg<CIR_PointerType, "the address to load from", [MemRead]>:$addr,
BitfieldInfoAttr:$bitfield_info,
UnitAttr:$is_volatile
);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,7 @@ class CIRSetBitfieldLowering
assert(storageSize > size && "Invalid bitfield size.");

mlir::Value val = rewriter.create<mlir::LLVM::LoadOp>(
op.getLoc(), intType, adaptor.getDst(), /* alignment */ 0,
op.getLoc(), intType, adaptor.getAddr(), /* alignment */ 0,
op.getIsVolatile());

srcVal = createAnd(rewriter, srcVal,
Expand All @@ -2647,7 +2647,7 @@ class CIRSetBitfieldLowering
srcVal = rewriter.create<mlir::LLVM::OrOp>(op.getLoc(), val, srcVal);
}

rewriter.create<mlir::LLVM::StoreOp>(op.getLoc(), srcVal, adaptor.getDst(),
rewriter.create<mlir::LLVM::StoreOp>(op.getLoc(), srcVal, adaptor.getAddr(),
/* alignment */ 0, op.getIsVolatile());

auto resultTy = getTypeConverter()->convertType(op.getType());
Expand Down

0 comments on commit 6e6fb5a

Please sign in to comment.