Skip to content

Commit 46a36af

Browse files
authored
[llvm-c] Add support for setting/getting new disjoint flag on or instructions (#74517)
Follows #73952 doing the same thing for the nneg flag on zext (i.e., exposing support in the C API).
1 parent 322c7c7 commit 46a36af

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ Changes to the C API
200200
The option structure exposes an additional setting (i.e., the target ABI) and
201201
provides default values for unspecified settings.
202202

203-
* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for setting/getting the new nneg flag
204-
on zext instructions
203+
* Added ``LLVMGetNNeg`` and ``LLVMSetNNeg`` for getting/setting the new nneg flag
204+
on zext instructions, and ``LLVMGetIsDisjoint`` and ``LLVMSetIsDisjoint``
205+
for getting/setting the new disjoint flag on or instructions.
205206

206207
Changes to the CodeGen infrastructure
207208
-------------------------------------

llvm/include/llvm-c/Core.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,17 @@ LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst);
39853985
*/
39863986
void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg);
39873987

3988+
/**
3989+
* Gets whether the instruction has the disjoint flag set.
3990+
* Only valid for or instructions.
3991+
*/
3992+
LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst);
3993+
/**
3994+
* Sets the disjoint flag for the instruction.
3995+
* Only valid for or instructions.
3996+
*/
3997+
void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint);
3998+
39883999
/* Memory */
39894000
LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
39904001
LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,

llvm/lib/IR/Core.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,6 +3464,16 @@ void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg) {
34643464
cast<Instruction>(P)->setNonNeg(IsNonNeg);
34653465
}
34663466

3467+
LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst) {
3468+
Value *P = unwrap<Value>(Inst);
3469+
return cast<PossiblyDisjointInst>(P)->isDisjoint();
3470+
}
3471+
3472+
void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint) {
3473+
Value *P = unwrap<Value>(Inst);
3474+
cast<PossiblyDisjointInst>(P)->setIsDisjoint(IsDisjoint);
3475+
}
3476+
34673477
/*--.. Memory ..............................................................--*/
34683478

34693479
LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,

llvm/test/Bindings/llvm-c/echo.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ define i32 @iops(i32 %a, i32 %b) {
9292
%23 = ashr exact i32 %22, %14
9393
%24 = zext i32 %23 to i64
9494
%25 = zext nneg i32 %23 to i64
95-
ret i32 %23
95+
%26 = or disjoint i32 %23, %a
96+
ret i32 %26
9697
}
9798

9899
define i32 @call() {

llvm/tools/llvm-c-test/echo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,9 @@ struct FunCloner {
656656
case LLVMOr: {
657657
LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));
658658
LLVMValueRef RHS = CloneValue(LLVMGetOperand(Src, 1));
659+
LLVMBool IsDisjoint = LLVMGetIsDisjoint(Src);
659660
Dst = LLVMBuildOr(Builder, LHS, RHS, Name);
661+
LLVMSetIsDisjoint(Dst, IsDisjoint);
660662
break;
661663
}
662664
case LLVMXor: {

0 commit comments

Comments
 (0)