[llvm] r254764 - [OperandBundles] Allow operand-specific attributes in operand bundles
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 4 12:34:37 PST 2015
Author: sanjoy
Date: Fri Dec 4 14:34:37 2015
New Revision: 254764
URL: http://llvm.org/viewvc/llvm-project?rev=254764&view=rev
Log:
[OperandBundles] Allow operand-specific attributes in operand bundles
Currently `OperandBundleUse::operandsHaveAttr` computes its result
without being given a specific operand. This is problematic because it
forces us to say that, e.g., even non-pointer operands in `"deopt"`
operand bundles are `readonly`, which doesn't make sense.
This commit changes `operandsHaveAttr` to work in the context of a
specific operand, so that we can give the operand attributes that make
sense for the operands's `llvm::Type`.
Modified:
llvm/trunk/include/llvm/IR/InstrTypes.h
llvm/trunk/lib/IR/Instructions.cpp
Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=254764&r1=254763&r2=254764&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Fri Dec 4 14:34:37 2015
@@ -1121,14 +1121,12 @@ struct OperandBundleUse {
explicit OperandBundleUse(StringMapEntry<uint32_t> *Tag, ArrayRef<Use> Inputs)
: Inputs(Inputs), Tag(Tag) {}
- /// \brief Return true if all the operands in this operand bundle have the
- /// attribute A.
- ///
- /// Currently there is no way to have attributes on operand bundles differ on
- /// a per operand granularity.
- bool operandsHaveAttr(Attribute::AttrKind A) const {
+ /// \brief Return true if the operand at index \p Idx in this operand bundle
+ /// has the attribute A.
+ bool operandHasAttr(unsigned Idx, Attribute::AttrKind A) const {
if (isDeoptOperandBundle())
- return A == Attribute::ReadOnly || A == Attribute::NoCapture;
+ if (A == Attribute::ReadOnly || A == Attribute::NoCapture)
+ return Inputs[Idx]->getType()->isPointerTy();
// Conservative answer: no operands have any attributes.
return false;
@@ -1351,11 +1349,7 @@ public:
/// It is an error to call this with an OpIdx that does not correspond to an
/// bundle operand.
OperandBundleUse getOperandBundleForOperand(unsigned OpIdx) const {
- for (auto &BOI : bundle_op_infos())
- if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
- return operandBundleFromBundleOpInfo(BOI);
-
- llvm_unreachable("Did not find operand bundle for operand!");
+ return operandBundleFromBundleOpInfo(getBundleOpInfoForOperand(OpIdx));
}
/// \brief Return true if this operand bundle user has operand bundles that
@@ -1382,6 +1376,14 @@ public:
return false;
}
+ /// \brief Return true if the bundle operand at index \p OpIdx has the
+ /// attribute \p A.
+ bool bundleOperandHasAttr(unsigned OpIdx, Attribute::AttrKind A) const {
+ auto &BOI = getBundleOpInfoForOperand(OpIdx);
+ auto OBU = operandBundleFromBundleOpInfo(BOI);
+ return OBU.operandHasAttr(OpIdx - BOI.Begin, A);
+ }
+
protected:
/// \brief Is the function attribute S disallowed by some operand bundle on
/// this operand bundle user?
@@ -1518,6 +1520,18 @@ protected:
return It;
}
+ /// \brief Return the BundleOpInfo for the operand at index OpIdx.
+ ///
+ /// It is an error to call this with an OpIdx that does not correspond to an
+ /// bundle operand.
+ const BundleOpInfo &getBundleOpInfoForOperand(unsigned OpIdx) const {
+ for (auto &BOI : bundle_op_infos())
+ if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
+ return BOI;
+
+ llvm_unreachable("Did not find operand bundle for operand!");
+ }
+
/// \brief Return the total number of values used in \p Bundles.
static unsigned CountBundleInputs(ArrayRef<OperandBundleDef> Bundles) {
unsigned Total = 0;
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=254764&r1=254763&r2=254764&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Fri Dec 4 14:34:37 2015
@@ -369,7 +369,7 @@ bool CallInst::dataOperandHasImpliedAttr
assert(hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) &&
"Must be either a call argument or an operand bundle!");
- return getOperandBundleForOperand(i - 1).operandsHaveAttr(A);
+ return bundleOperandHasAttr(i - 1, A);
}
/// IsConstantOne - Return true only if val is constant int 1
@@ -646,7 +646,7 @@ bool InvokeInst::dataOperandHasImpliedAt
assert(hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) &&
"Must be either an invoke argument or an operand bundle!");
- return getOperandBundleForOperand(i - 1).operandsHaveAttr(A);
+ return bundleOperandHasAttr(i - 1, A);
}
void InvokeInst::addAttribute(unsigned i, Attribute::AttrKind attr) {
More information about the llvm-commits
mailing list