Index: include/llvm/CodeGen/SDNodeProperties.td =================================================================== --- /dev/null +++ include/llvm/CodeGen/SDNodeProperties.td @@ -0,0 +1,34 @@ +//===- SDNodeProperties.td - Common code for DAG isels ---*- tablegen -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +class SDNodeProperty; + +// Selection DAG Pattern Operations +class SDPatternOperator { + list Properties = []; +} + +//===----------------------------------------------------------------------===// +// Selection DAG Node Properties. +// +// Note: These are hard coded into tblgen. +// +def SDNPCommutative : SDNodeProperty; // X op Y == Y op X +def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z) +def SDNPHasChain : SDNodeProperty; // R/W chain operand and result +def SDNPOutGlue : SDNodeProperty; // Write a flag result +def SDNPInGlue : SDNodeProperty; // Read a flag operand +def SDNPOptInGlue : SDNodeProperty; // Optionally read a flag operand +def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'. +def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'. +def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'. +def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand +def SDNPVariadic : SDNodeProperty; // Node has variable arguments. +def SDNPWantRoot : SDNodeProperty; // ComplexPattern gets the root of match +def SDNPWantParent : SDNodeProperty; // ComplexPattern gets the parent Index: include/llvm/IR/Intrinsics.td =================================================================== --- include/llvm/IR/Intrinsics.td +++ include/llvm/IR/Intrinsics.td @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// include "llvm/CodeGen/ValueTypes.td" +include "llvm/CodeGen/SDNodeProperties.td" //===----------------------------------------------------------------------===// // Properties we keep track of for intrinsics. @@ -264,16 +265,17 @@ // intrinsic. // * Properties can be set to describe the behavior of the intrinsic. // -class SDPatternOperator; class Intrinsic ret_types, list param_types = [], - list properties = [], - string name = ""> : SDPatternOperator { + list intr_properties = [], + string name = "", + list sd_properties = []> : SDPatternOperator { string LLVMName = name; string TargetPrefix = ""; // Set to a prefix for target-specific intrinsics. list RetTypes = ret_types; list ParamTypes = param_types; - list IntrProperties = properties; + list IntrProperties = intr_properties; + let Properties = sd_properties; bit isTarget = 0; } Index: include/llvm/Target/TargetSelectionDAG.td =================================================================== --- include/llvm/Target/TargetSelectionDAG.td +++ include/llvm/Target/TargetSelectionDAG.td @@ -285,32 +285,6 @@ class SDCallSeqEnd constraints> : SDTypeProfile<0, 2, constraints>; -//===----------------------------------------------------------------------===// -// Selection DAG Node Properties. -// -// Note: These are hard coded into tblgen. -// -class SDNodeProperty; -def SDNPCommutative : SDNodeProperty; // X op Y == Y op X -def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z) -def SDNPHasChain : SDNodeProperty; // R/W chain operand and result -def SDNPOutGlue : SDNodeProperty; // Write a flag result -def SDNPInGlue : SDNodeProperty; // Read a flag operand -def SDNPOptInGlue : SDNodeProperty; // Optionally read a flag operand -def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'. -def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'. -def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'. -def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand -def SDNPVariadic : SDNodeProperty; // Node has variable arguments. -def SDNPWantRoot : SDNodeProperty; // ComplexPattern gets the root of match -def SDNPWantParent : SDNodeProperty; // ComplexPattern gets the parent - -//===----------------------------------------------------------------------===// -// Selection DAG Pattern Operations -class SDPatternOperator { - list Properties = []; -} - //===----------------------------------------------------------------------===// // Selection DAG Node definitions. // Index: test/TableGen/intrinsic-long-name.td =================================================================== --- test/TableGen/intrinsic-long-name.td +++ test/TableGen/intrinsic-long-name.td @@ -2,6 +2,7 @@ // XFAIL: vg_leak class IntrinsicProperty; +class SDNodeProperty; class ValueType { string Namespace = "MVT"; @@ -20,6 +21,7 @@ list RetTypes = []; list ParamTypes = param_types; list IntrProperties = []; + list Properties = []; } def iAny : ValueType<0, 253>; Index: test/TableGen/intrinsic-struct.td =================================================================== --- test/TableGen/intrinsic-struct.td +++ test/TableGen/intrinsic-struct.td @@ -2,6 +2,7 @@ // XFAIL: vg_leak class IntrinsicProperty; +class SDNodeProperty; class ValueType { string Namespace = "MVT"; @@ -20,6 +21,7 @@ list RetTypes = ret_types; list ParamTypes = []; list IntrProperties = []; + list Properties = []; } def iAny : ValueType<0, 253>; Index: test/TableGen/intrinsic-varargs.td =================================================================== --- test/TableGen/intrinsic-varargs.td +++ test/TableGen/intrinsic-varargs.td @@ -2,6 +2,7 @@ // XFAIL: vg_leak class IntrinsicProperty; +class SDNodeProperty; class ValueType { string Namespace = "MVT"; @@ -20,6 +21,7 @@ list RetTypes = []; list ParamTypes = param_types; list IntrProperties = []; + list Properties = []; } // isVoid needs to match the definition in ValueTypes.td Index: utils/TableGen/CMakeLists.txt =================================================================== --- utils/TableGen/CMakeLists.txt +++ utils/TableGen/CMakeLists.txt @@ -32,6 +32,7 @@ PseudoLoweringEmitter.cpp RegisterBankEmitter.cpp RegisterInfoEmitter.cpp + SDNodeProperties.cpp SearchableTableEmitter.cpp SubtargetEmitter.cpp SubtargetFeatureInfo.cpp Index: utils/TableGen/CodeGenDAGPatterns.h =================================================================== --- utils/TableGen/CodeGenDAGPatterns.h +++ utils/TableGen/CodeGenDAGPatterns.h @@ -18,6 +18,7 @@ #include "CodeGenHwModes.h" #include "CodeGenIntrinsics.h" #include "CodeGenTarget.h" +#include "SDNodeProperties.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" @@ -1204,6 +1205,7 @@ MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP); return MadeChange; } + } // end namespace llvm #endif Index: utils/TableGen/CodeGenDAGPatterns.cpp =================================================================== --- utils/TableGen/CodeGenDAGPatterns.cpp +++ utils/TableGen/CodeGenDAGPatterns.cpp @@ -1591,37 +1591,7 @@ NumOperands = TypeProfile->getValueAsInt("NumOperands"); // Parse the properties. - Properties = 0; - for (Record *Property : R->getValueAsListOfDefs("Properties")) { - if (Property->getName() == "SDNPCommutative") { - Properties |= 1 << SDNPCommutative; - } else if (Property->getName() == "SDNPAssociative") { - Properties |= 1 << SDNPAssociative; - } else if (Property->getName() == "SDNPHasChain") { - Properties |= 1 << SDNPHasChain; - } else if (Property->getName() == "SDNPOutGlue") { - Properties |= 1 << SDNPOutGlue; - } else if (Property->getName() == "SDNPInGlue") { - Properties |= 1 << SDNPInGlue; - } else if (Property->getName() == "SDNPOptInGlue") { - Properties |= 1 << SDNPOptInGlue; - } else if (Property->getName() == "SDNPMayStore") { - Properties |= 1 << SDNPMayStore; - } else if (Property->getName() == "SDNPMayLoad") { - Properties |= 1 << SDNPMayLoad; - } else if (Property->getName() == "SDNPSideEffect") { - Properties |= 1 << SDNPSideEffect; - } else if (Property->getName() == "SDNPMemOperand") { - Properties |= 1 << SDNPMemOperand; - } else if (Property->getName() == "SDNPVariadic") { - Properties |= 1 << SDNPVariadic; - } else { - PrintFatalError("Unknown SD Node property '" + - Property->getName() + "' on node '" + - R->getName() + "'!"); - } - } - + Properties = parseSDPatternOperatorProperties(R); // Parse the type constraints. std::vector ConstraintList = @@ -2100,11 +2070,20 @@ if (isLeaf()) { if (const ComplexPattern *CP = getComplexPatternInfo(CGP)) return CP->hasProperty(Property); + return false; } - Record *Operator = getOperator(); - if (!Operator->isSubClassOf("SDNode")) return false; + if (Property != SDNPHasChain) { + // The chain proprety is already present on the different intrinsic node + // types (intrinsic_w_chain, intrinsic_void), and is not explicitly listed + // on the intrinsic. Anything else is specific to the individual intrinsic. + if (const CodeGenIntrinsic *Int = getIntrinsicInfo(CGP)) + return Int->hasProperty(Property); + } + + if (!Operator->isSubClassOf("SDPatternOperator")) + return false; return CGP.getSDNodeInfo(Operator).hasProperty(Property); } Index: utils/TableGen/CodeGenIntrinsics.h =================================================================== --- utils/TableGen/CodeGenIntrinsics.h +++ utils/TableGen/CodeGenIntrinsics.h @@ -14,6 +14,7 @@ #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H +#include "SDNodeProperties.h" #include "llvm/CodeGen/MachineValueType.h" #include #include @@ -104,6 +105,9 @@ }; ModRefBehavior ModRef; + /// SDPatternOperator Properties applied to the intrinsic. + unsigned Properties; + /// This is set to true if the intrinsic is overloaded by its argument /// types. bool isOverloaded; @@ -133,6 +137,10 @@ enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone }; std::vector> ArgumentAttributes; + bool hasProperty(enum SDNP Prop) const { + return Properties & (1 << Prop); + } + CodeGenIntrinsic(Record *R); }; Index: utils/TableGen/CodeGenTarget.h =================================================================== --- utils/TableGen/CodeGenTarget.h +++ utils/TableGen/CodeGenTarget.h @@ -21,6 +21,7 @@ #include "CodeGenInstruction.h" #include "CodeGenRegisters.h" #include "InfoByHwMode.h" +#include "SDNodeProperties.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TableGen/Record.h" #include @@ -31,25 +32,6 @@ class CodeGenSchedModels; class CodeGenTarget; -// SelectionDAG node properties. -// SDNPMemOperand: indicates that a node touches memory and therefore must -// have an associated memory operand that describes the access. -enum SDNP { - SDNPCommutative, - SDNPAssociative, - SDNPHasChain, - SDNPOutGlue, - SDNPInGlue, - SDNPOptInGlue, - SDNPMayLoad, - SDNPMayStore, - SDNPSideEffect, - SDNPMemOperand, - SDNPVariadic, - SDNPWantRoot, - SDNPWantParent -}; - /// getValueType - Return the MVT::SimpleValueType that the specified TableGen /// record corresponds to. MVT::SimpleValueType getValueType(Record *Rec); Index: utils/TableGen/CodeGenTarget.cpp =================================================================== --- utils/TableGen/CodeGenTarget.cpp +++ utils/TableGen/CodeGenTarget.cpp @@ -15,6 +15,7 @@ //===----------------------------------------------------------------------===// #include "CodeGenTarget.h" +#include "CodeGenDAGPatterns.h" #include "CodeGenIntrinsics.h" #include "CodeGenSchedule.h" #include "llvm/ADT/STLExtras.h" @@ -450,6 +451,7 @@ else Complexity = RawComplexity; + // FIXME: Why is this different from parseSDPatternOperatorProperties? // Parse the properties. Properties = 0; std::vector PropList = R->getValueAsListOfDefs("Properties"); @@ -512,6 +514,7 @@ TheDef = R; std::string DefName = R->getName(); ModRef = ReadWriteMem; + Properties = 0; isOverloaded = false; isCommutative = false; canThrow = false; @@ -681,6 +684,10 @@ llvm_unreachable("Unknown property!"); } + // Also record the SDPatternOperator Properties. + Properties = parseSDPatternOperatorProperties(R); + // Sort the argument attributes for later benefit. std::sort(ArgumentAttributes.begin(), ArgumentAttributes.end()); } + Index: utils/TableGen/SDNodeProperties.h =================================================================== --- /dev/null +++ utils/TableGen/SDNodeProperties.h @@ -0,0 +1,40 @@ +//===- SDNodeProperties.h ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_UTILS_TABLEGEN_SDNODEPROPERTIES_H +#define LLVM_UTILS_TABLEGEN_SDNODEPROPERTIES_H + +namespace llvm { + +class Record; + +// SelectionDAG node properties. +// SDNPMemOperand: indicates that a node touches memory and therefore must +// have an associated memory operand that describes the access. +enum SDNP { + SDNPCommutative, + SDNPAssociative, + SDNPHasChain, + SDNPOutGlue, + SDNPInGlue, + SDNPOptInGlue, + SDNPMayLoad, + SDNPMayStore, + SDNPSideEffect, + SDNPMemOperand, + SDNPVariadic, + SDNPWantRoot, + SDNPWantParent +}; + +unsigned parseSDPatternOperatorProperties(Record *R); + +} + +#endif Index: utils/TableGen/SDNodeProperties.cpp =================================================================== --- /dev/null +++ utils/TableGen/SDNodeProperties.cpp @@ -0,0 +1,49 @@ +//===- SDNodeProperties.cpp -----------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "SDNodeProperties.h" +#include "llvm/TableGen/Error.h" +#include "llvm/TableGen/Record.h" + +using namespace llvm; + +unsigned llvm::parseSDPatternOperatorProperties(Record *R) { + unsigned Properties = 0; + for (Record *Property : R->getValueAsListOfDefs("Properties")) { + if (Property->getName() == "SDNPCommutative") { + Properties |= 1 << SDNPCommutative; + } else if (Property->getName() == "SDNPAssociative") { + Properties |= 1 << SDNPAssociative; + } else if (Property->getName() == "SDNPHasChain") { + Properties |= 1 << SDNPHasChain; + } else if (Property->getName() == "SDNPOutGlue") { + Properties |= 1 << SDNPOutGlue; + } else if (Property->getName() == "SDNPInGlue") { + Properties |= 1 << SDNPInGlue; + } else if (Property->getName() == "SDNPOptInGlue") { + Properties |= 1 << SDNPOptInGlue; + } else if (Property->getName() == "SDNPMayStore") { + Properties |= 1 << SDNPMayStore; + } else if (Property->getName() == "SDNPMayLoad") { + Properties |= 1 << SDNPMayLoad; + } else if (Property->getName() == "SDNPSideEffect") { + Properties |= 1 << SDNPSideEffect; + } else if (Property->getName() == "SDNPMemOperand") { + Properties |= 1 << SDNPMemOperand; + } else if (Property->getName() == "SDNPVariadic") { + Properties |= 1 << SDNPVariadic; + } else { + PrintFatalError("Unknown SD Node property '" + + Property->getName() + "' on node '" + + R->getName() + "'!"); + } + } + + return Properties; +}