@@ -821,6 +821,13 @@ struct IRPosition {
821
821
" There is no attribute index for a floating or invalid position!" );
822
822
}
823
823
824
+ // / Return the value attributes are attached to.
825
+ Value *getAttrListAnchor () const {
826
+ if (auto *CB = dyn_cast<CallBase>(&getAnchorValue ()))
827
+ return CB;
828
+ return getAssociatedFunction ();
829
+ }
830
+
824
831
// / Return the attributes associated with this function or call site scope.
825
832
AttributeList getAttrList () const {
826
833
if (auto *CB = dyn_cast<CallBase>(&getAnchorValue ()))
@@ -878,51 +885,6 @@ struct IRPosition {
878
885
return IRP_FLOAT;
879
886
}
880
887
881
- // / TODO: Figure out if the attribute related helper functions should live
882
- // / here or somewhere else.
883
-
884
- // / Return true if any kind in \p AKs existing in the IR at a position that
885
- // / will affect this one. See also getAttrs(...).
886
- // / \param IgnoreSubsumingPositions Flag to determine if subsuming positions,
887
- // / e.g., the function position if this is an
888
- // / argument position, should be ignored.
889
- bool hasAttr (ArrayRef<Attribute::AttrKind> AKs,
890
- bool IgnoreSubsumingPositions = false ,
891
- Attributor *A = nullptr ) const ;
892
-
893
- // / Return the attributes of any kind in \p AKs existing in the IR at a
894
- // / position that will affect this one. While each position can only have a
895
- // / single attribute of any kind in \p AKs, there are "subsuming" positions
896
- // / that could have an attribute as well. This method returns all attributes
897
- // / found in \p Attrs.
898
- // / \param IgnoreSubsumingPositions Flag to determine if subsuming positions,
899
- // / e.g., the function position if this is an
900
- // / argument position, should be ignored.
901
- void getAttrs (ArrayRef<Attribute::AttrKind> AKs,
902
- SmallVectorImpl<Attribute> &Attrs,
903
- bool IgnoreSubsumingPositions = false ,
904
- Attributor *A = nullptr ) const ;
905
-
906
- // / Remove the attribute of kind \p AKs existing in the IR at this position.
907
- void removeAttrs (ArrayRef<Attribute::AttrKind> AKs) const {
908
- if (getPositionKind () == IRP_INVALID || getPositionKind () == IRP_FLOAT)
909
- return ;
910
-
911
- AttributeList AttrList = getAttrList ();
912
-
913
- bool Changed = false ;
914
- unsigned Idx = getAttrIdx ();
915
- LLVMContext &Ctx = getAnchorValue ().getContext ();
916
- for (Attribute::AttrKind AK : AKs) {
917
- if (!AttrList.hasAttributeAtIndex (Idx, AK))
918
- continue ;
919
- Changed = true ;
920
- AttrList = AttrList.removeAttributeAtIndex (Ctx, Idx, AK);
921
- }
922
- if (Changed)
923
- setAttrList (AttrList);
924
- }
925
-
926
888
bool isAnyCallSitePosition () const {
927
889
switch (getPositionKind ()) {
928
890
case IRPosition::IRP_CALL_SITE:
@@ -1041,16 +1003,6 @@ struct IRPosition {
1041
1003
// / Verify internal invariants.
1042
1004
void verify ();
1043
1005
1044
- // / Return the attributes of kind \p AK existing in the IR as attribute.
1045
- bool getAttrsFromIRAttr (Attribute::AttrKind AK,
1046
- SmallVectorImpl<Attribute> &Attrs) const ;
1047
-
1048
- // / Return the attributes of kind \p AK existing in the IR as operand bundles
1049
- // / of an llvm.assume.
1050
- bool getAttrsFromAssumes (Attribute::AttrKind AK,
1051
- SmallVectorImpl<Attribute> &Attrs,
1052
- Attributor &A) const ;
1053
-
1054
1006
// / Return the underlying pointer as Value *, valid for all positions but
1055
1007
// / IRP_CALL_SITE_ARGUMENT.
1056
1008
Value *getAsValuePtr () const {
@@ -1893,6 +1845,52 @@ struct Attributor {
1893
1845
ToBeDeletedFunctions.insert (&F);
1894
1846
}
1895
1847
1848
+ // / Return the attributes of kind \p AK existing in the IR as operand bundles
1849
+ // / of an llvm.assume.
1850
+ bool getAttrsFromAssumes (const IRPosition &IRP, Attribute::AttrKind AK,
1851
+ SmallVectorImpl<Attribute> &Attrs);
1852
+
1853
+ // / Return true if any kind in \p AKs existing in the IR at a position that
1854
+ // / will affect this one. See also getAttrs(...).
1855
+ // / \param IgnoreSubsumingPositions Flag to determine if subsuming positions,
1856
+ // / e.g., the function position if this is an
1857
+ // / argument position, should be ignored.
1858
+ bool hasAttr (const IRPosition &IRP, ArrayRef<Attribute::AttrKind> AKs,
1859
+ bool IgnoreSubsumingPositions = false ,
1860
+ Attribute::AttrKind ImpliedAttributeKind = Attribute::None);
1861
+
1862
+ // / Return the attributes of any kind in \p AKs existing in the IR at a
1863
+ // / position that will affect this one. While each position can only have a
1864
+ // / single attribute of any kind in \p AKs, there are "subsuming" positions
1865
+ // / that could have an attribute as well. This method returns all attributes
1866
+ // / found in \p Attrs.
1867
+ // / \param IgnoreSubsumingPositions Flag to determine if subsuming positions,
1868
+ // / e.g., the function position if this is an
1869
+ // / argument position, should be ignored.
1870
+ void getAttrs (const IRPosition &IRP, ArrayRef<Attribute::AttrKind> AKs,
1871
+ SmallVectorImpl<Attribute> &Attrs,
1872
+ bool IgnoreSubsumingPositions = false );
1873
+
1874
+ ChangeStatus removeAttrs (const IRPosition &IRP,
1875
+ const ArrayRef<Attribute::AttrKind> &AttrKinds);
1876
+
1877
+ ChangeStatus manifestAttrs (const IRPosition &IRP,
1878
+ const ArrayRef<Attribute> &DeducedAttrs,
1879
+ bool ForceReplace = false );
1880
+
1881
+ private:
1882
+ // / Helper to apply \p CB on all attributes of type \p AttrDescs of \p IRP.
1883
+ template <typename DescTy>
1884
+ ChangeStatus updateAttrMap (const IRPosition &IRP,
1885
+ const ArrayRef<DescTy> &AttrDescs,
1886
+ function_ref<bool (const DescTy &, AttributeSet,
1887
+ AttributeMask &, AttrBuilder &)>
1888
+ CB);
1889
+
1890
+ // / Mapping from functions/call sites to their attributes.
1891
+ DenseMap<Value *, AttributeList> AttrsMap;
1892
+
1893
+ public:
1896
1894
// / If \p IRP is assumed to be a constant, return it, if it is unclear yet,
1897
1895
// / return std::nullopt, otherwise return `nullptr`.
1898
1896
std::optional<Constant *> getAssumedConstant (const IRPosition &IRP,
@@ -3095,14 +3093,6 @@ template <typename BaseTy> struct SetState : public AbstractState {
3095
3093
bool IsAtFixedpoint;
3096
3094
};
3097
3095
3098
- // / Helper struct necessary as the modular build fails if the virtual method
3099
- // / IRAttribute::manifest is defined in the Attributor.cpp.
3100
- struct IRAttributeManifest {
3101
- static ChangeStatus manifestAttrs (Attributor &A, const IRPosition &IRP,
3102
- const ArrayRef<Attribute> &DeducedAttrs,
3103
- bool ForceReplace = false );
3104
- };
3105
-
3106
3096
// / Helper to tie a abstract state implementation to an abstract attribute.
3107
3097
template <typename StateTy, typename BaseType, class ... Ts>
3108
3098
struct StateWrapper : public BaseType , public StateTy {
@@ -3129,7 +3119,7 @@ struct IRAttribute : public BaseType {
3129
3119
bool IgnoreSubsumingPositions = false ) {
3130
3120
if (isa<UndefValue>(IRP.getAssociatedValue ()))
3131
3121
return true ;
3132
- return IRP .hasAttr (AttrKinds, IgnoreSubsumingPositions, &A );
3122
+ return A .hasAttr (IRP, AttrKinds, IgnoreSubsumingPositions );
3133
3123
}
3134
3124
3135
3125
// / See AbstractAttribute::initialize(...).
@@ -3147,8 +3137,9 @@ struct IRAttribute : public BaseType {
3147
3137
return ChangeStatus::UNCHANGED;
3148
3138
SmallVector<Attribute, 4 > DeducedAttrs;
3149
3139
getDeducedAttributes (this ->getAnchorValue ().getContext (), DeducedAttrs);
3150
- return IRAttributeManifest::manifestAttrs (A, this ->getIRPosition (),
3151
- DeducedAttrs);
3140
+ if (DeducedAttrs.empty ())
3141
+ return ChangeStatus::UNCHANGED;
3142
+ return A.manifestAttrs (this ->getIRPosition (), DeducedAttrs);
3152
3143
}
3153
3144
3154
3145
// / Return the kind that identifies the abstract attribute implementation.
@@ -3627,8 +3618,8 @@ struct AAWillReturn
3627
3618
return false ;
3628
3619
3629
3620
SmallVector<Attribute, 1 > Attrs;
3630
- IRP .getAttrs ({Attribute::Memory}, Attrs,
3631
- /* IgnoreSubsumingPositions */ false );
3621
+ A .getAttrs (IRP, {Attribute::Memory}, Attrs,
3622
+ /* IgnoreSubsumingPositions */ false );
3632
3623
3633
3624
MemoryEffects ME = MemoryEffects::unknown ();
3634
3625
for (const Attribute &Attr : Attrs)
0 commit comments