Skip to content

[llvm-c] Add support for setting/getting new disjoint flag on or instructions #74517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ Changes to the C API
The option structure exposes an additional setting (i.e., the target ABI) and
provides default values for unspecified settings.

* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for setting/getting the new nneg flag
on zext instructions
* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for getting/setting the new nneg flag
on zext instructions, and ``LLVMGetIsDisjoint`` and ``LLVMSetIsDisjoint``
for getting/setting the new disjoint flag on or instructions.

Changes to the CodeGen infrastructure
-------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3985,6 +3985,17 @@ LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst);
*/
void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg);

/**
* Gets whether the instruction has the disjoint flag set.
* Only valid for or instructions.
*/
LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst);
/**
* Sets the disjoint flag for the instruction.
* Only valid for or instructions.
*/
void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint);

/* Memory */
LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3464,6 +3464,16 @@ void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg) {
cast<Instruction>(P)->setNonNeg(IsNonNeg);
}

LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst) {
Value *P = unwrap<Value>(Inst);
return cast<PossiblyDisjointInst>(P)->isDisjoint();
}

void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint) {
Value *P = unwrap<Value>(Inst);
cast<PossiblyDisjointInst>(P)->setIsDisjoint(IsDisjoint);
}

/*--.. Memory ..............................................................--*/

LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/Bindings/llvm-c/echo.ll
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ define i32 @iops(i32 %a, i32 %b) {
%23 = ashr exact i32 %22, %14
%24 = zext i32 %23 to i64
%25 = zext nneg i32 %23 to i64
ret i32 %23
%26 = or disjoint i32 %23, %a
ret i32 %26
}

define i32 @call() {
Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/llvm-c-test/echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,9 @@ struct FunCloner {
case LLVMOr: {
LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));
LLVMValueRef RHS = CloneValue(LLVMGetOperand(Src, 1));
LLVMBool IsDisjoint = LLVMGetIsDisjoint(Src);
Dst = LLVMBuildOr(Builder, LHS, RHS, Name);
LLVMSetIsDisjoint(Dst, IsDisjoint);
break;
}
case LLVMXor: {
Expand Down