Author: Zhengyang Liu
Date: 2020-11-25T17:33:51-07:00
New Revision: 75f50e15bf8fff6fba1d4678adedd33ef6a945e5
URL:
https://github.com/llvm/llvm-project/commit/75f50e15bf8fff6fba1d4678adedd33ef6a945e5
DIFF:
https://github.com/llvm/llvm-project/commit/75f50e15bf8fff6fba1d4678adedd33ef6a945e5.diff
LOG: Adding PoisonValue for representing poison value explicitly in IR
Define ConstantData::PoisonValue.
Add support for poison value to LLLexer/LLParser/BitcodeReader/BitcodeWriter.
Add support for poison value to llvm-c interface.
Add support for poison value to OCaml binding.
Add m_Poison in PatternMatch.
Differential Revision: https://reviews.llvm.org/D71126
Added:
llvm/test/CodeGen/X86/poison-ops.ll
Modified:
llvm/bindings/ocaml/llvm/llvm.ml
llvm/bindings/ocaml/llvm/llvm.mli
llvm/bindings/ocaml/llvm/llvm_ocaml.c
llvm/include/llvm-c/Core.h
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/PatternMatch.h
llvm/include/llvm/IR/Value.def
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/AsmParser/LLParser.h
llvm/lib/AsmParser/LLToken.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/Core.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/test/Bindings/OCaml/core.ml
llvm/test/Bitcode/compatibility.ll
llvm/tools/llvm-c-test/echo.cpp
Removed:
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml
b/llvm/bindings/ocaml/llvm/llvm.ml
index fdef6eb176d6..723ac66ffd05 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -314,6 +314,7 @@ module ValueKind = struct
| GlobalIFunc
| GlobalVariable
| UndefValue
+ | PoisonValue
| Instruction of Opcode.t
end
@@ -547,8 +548,10 @@ external const_null : lltype -> llvalue = "LLVMConstNull"
external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
external const_pointer_null : lltype -> llvalue = "LLVMConstPointerNull"
external undef : lltype -> llvalue = "LLVMGetUndef"
+external poison : lltype -> llvalue = "LLVMGetPoison"
external is_null : llvalue -> bool = "llvm_is_null"
external is_undef : llvalue -> bool = "llvm_is_undef"
+external is_poison : llvalue -> bool = "llvm_is_poison"
external constexpr_opcode : llvalue -> Opcode.t = "llvm_constexpr_get_opcode"
(*--... Operations on instructions
.--*)
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli
b/llvm/bindings/ocaml/llvm/llvm.mli
index 04e27438a479..ba9e6c1f2120 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -347,6 +347,7 @@ module ValueKind : sig
| GlobalIFunc
| GlobalVariable
| UndefValue
+ | PoisonValue
| Instruction of Opcode.t
end
@@ -842,6 +843,10 @@ val const_pointer_null : lltype -> llvalue
See the method [llvm::UndefValue::get]. *)
val undef : lltype -> llvalue
+(** [poison ty] returns the poison value of the type [ty].
+See the method [llvm::PoisonValue::get]. *)
+val poison : lltype -> llvalue
+
(** [is_null v] returns [true] if the value [v] is the null (zero) value.
See the method [llvm::Constant::isNullValue]. *)
val is_null : llvalue -> bool
@@ -850,6 +855,10 @@ val is_null : llvalue -> bool
otherwise. Similar to [llvm::isa]. *)
val is_undef : llvalue -> bool
+(** [is_poison v] returns [true] if the value [v] is a poison value, [false]
+otherwise. Similar to [llvm::isa]. *)
+val is_poison : llvalue -> bool
+
(** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
val constexpr_opcode : llvalue -> Opcode.t
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 1552abf29c03..5845783278d9 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -627,6 +627,7 @@ enum ValueKind {
GlobalIFunc,
GlobalVariable,
UndefValue,
+ PoisonValue,
Instruction
};
@@ -669,6 +670,7 @@ CAMLprim value llvm_classify_value(LLVMValueRef Val) {
DEFINE_CASE(Val, MDNode);
DEFINE_CASE(Val, MDString);
DEFINE_CASE(Val, UndefValue);
+ DEFINE_CASE(Val, PoisonValue);
failwith("Unknown Value class");
}
@@ -762,6 +764,11 @@ CAMLprim value llvm_is_undef(LLVMValueRef Val) {
return Val_bool(LLVMIsUndef(Val));
}
+/* llvalue -> bool */
+CAMLprim value llvm_is_poison(LLVMValueRef Val) {
+ return Val_bool(LLVMIsPoison(Val));
+}
+
/* llvalue -> Opcode.t */
CAMLprim value llvm_constexpr_get_opcode(LLVMValueRef Val) {
return LLVMIsAConstantExpr(Val) ?
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index e95038724276..1803c38b445d 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-