summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMomchil Velikov <momchil.velikov@arm.com>2019-07-17 10:53:13 +0000
committerMomchil Velikov <momchil.velikov@arm.com>2019-07-17 10:53:13 +0000
commit52c39396151978ca946e2a80d9118c8672bace14 (patch)
treecd02861b46bf93f58c8612d3fecb4479c5d506e9
parent11b06242a7e554f489c10bc9613be3e3c9e0c70a (diff)
downloadbcm5719-llvm-52c39396151978ca946e2a80d9118c8672bace14.tar.gz
bcm5719-llvm-52c39396151978ca946e2a80d9118c8672bace14.zip
[TableGen] Do not set ReadNone attribute on intrinsics with side effects
If an intrinsic is defined without outputs, but having side effects, it still can be removed completely from the program. This patch makes TableGen not set Attribute::ReadNone for intrinsics which are declared with IntrHasSideEffects. Differential Revision: https://reviews.llvm.org/D64414 llvm-svn: 366312
-rw-r--r--llvm/test/TableGen/intrin-side-effects.td39
-rw-r--r--llvm/utils/TableGen/CodeGenDAGPatterns.cpp2
-rw-r--r--llvm/utils/TableGen/IntrinsicEmitter.cpp4
3 files changed, 43 insertions, 2 deletions
diff --git a/llvm/test/TableGen/intrin-side-effects.td b/llvm/test/TableGen/intrin-side-effects.td
new file mode 100644
index 00000000000..7588855830f
--- /dev/null
+++ b/llvm/test/TableGen/intrin-side-effects.td
@@ -0,0 +1,39 @@
+// RUN: llvm-tblgen -gen-intrinsic-impl -I %p/../../include %s | FileCheck %s
+
+// Get the minimum blurb necessary to process ...
+include "llvm/CodeGen/ValueTypes.td"
+include "llvm/CodeGen/SDNodeProperties.td"
+
+class LLVMType<ValueType vt> {
+ ValueType VT = vt;
+ int isAny = 0;
+}
+
+def llvm_i32_ty : LLVMType<i32>;
+
+class IntrinsicProperty;
+def IntrNoMem : IntrinsicProperty;
+def IntrHasSideEffects : IntrinsicProperty;
+
+
+class Intrinsic<list<LLVMType> ret_types,
+ list<LLVMType> param_types = [],
+ list<IntrinsicProperty> intr_properties = [],
+ string name = "",
+ list<SDNodeProperty> sd_properties = []> : SDPatternOperator {
+ string LLVMName = name;
+ string TargetPrefix = "";
+ list<LLVMType> RetTypes = ret_types;
+ list<LLVMType> ParamTypes = param_types;
+ list<IntrinsicProperty> IntrProperties = intr_properties;
+ let Properties = sd_properties;
+
+ bit isTarget = 0;
+}
+
+// ... this intrinsic.
+def int_random_gen : Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrHasSideEffects]>;
+
+// CHECK: 1, // llvm.random.gen
+// CHECK: case 1:
+// CHECK-NEXT: Atts[] = {Attribute::NoUnwind}
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index a0e8696001b..c8f710d66a0 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -2807,7 +2807,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
// chain.
if (Int.IS.RetVTs.empty())
Operator = getDAGPatterns().get_intrinsic_void_sdnode();
- else if (Int.ModRef != CodeGenIntrinsic::NoMem)
+ else if (Int.ModRef != CodeGenIntrinsic::NoMem || Int.hasSideEffects)
// Has side-effects, requires chain.
Operator = getDAGPatterns().get_intrinsic_w_chain_sdnode();
else // Otherwise, no chain.
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index bcb8af2fc56..6bcdc3d777a 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -685,7 +685,7 @@ void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
}
if (!intrinsic.canThrow ||
- intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem ||
+ (intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem && !intrinsic.hasSideEffects) ||
intrinsic.isNoReturn || intrinsic.isCold || intrinsic.isNoDuplicate ||
intrinsic.isConvergent || intrinsic.isSpeculatable) {
OS << " const Attribute::AttrKind Atts[] = {";
@@ -727,6 +727,8 @@ void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
switch (intrinsic.ModRef) {
case CodeGenIntrinsic::NoMem:
+ if (intrinsic.hasSideEffects)
+ break;
if (addComma)
OS << ",";
OS << "Attribute::ReadNone";
OpenPOWER on IntegriCloud