@@ -112,6 +112,9 @@ class PatternEmitter {
112
112
// Returns the symbol of the old value serving as the replacement.
113
113
StringRef handleReplaceWithValue (DagNode tree);
114
114
115
+ // Returns the location value to use.
116
+ std::pair<bool , std::string> getLocation (DagNode tree);
117
+
115
118
// Returns the location value to use.
116
119
std::string handleLocationDirective (DagNode tree);
117
120
@@ -779,13 +782,18 @@ std::string PatternEmitter::handleReplaceWithNativeCodeCall(DagNode tree) {
779
782
PrintFatalError (loc, " unsupported NativeCodeCall argument numbers: " +
780
783
Twine (tree.getNumArgs ()));
781
784
}
782
- for (int i = 0 , e = tree.getNumArgs (); i != e; ++i) {
785
+ bool hasLocationDirective;
786
+ std::string locToUse;
787
+ std::tie (hasLocationDirective, locToUse) = getLocation (tree);
788
+
789
+ for (int i = 0 , e = tree.getNumArgs () - hasLocationDirective; i != e; ++i) {
783
790
attrs[i] = handleOpArgument (tree.getArgAsLeaf (i), tree.getArgName (i));
784
791
LLVM_DEBUG (llvm::dbgs () << " NativeCodeCall argument #" << i
785
792
<< " replacement: " << attrs[i] << " \n " );
786
793
}
787
- return std::string (tgfmt (fmt, &fmtCtx, attrs[0 ], attrs[1 ], attrs[2 ], attrs[3 ],
788
- attrs[4 ], attrs[5 ], attrs[6 ], attrs[7 ]));
794
+ return std::string (tgfmt (fmt, &fmtCtx.addSubst (" _loc" , locToUse), attrs[0 ],
795
+ attrs[1 ], attrs[2 ], attrs[3 ], attrs[4 ], attrs[5 ],
796
+ attrs[6 ], attrs[7 ]));
789
797
}
790
798
791
799
int PatternEmitter::getNodeValueCount (DagNode node) {
@@ -804,6 +812,20 @@ int PatternEmitter::getNodeValueCount(DagNode node) {
804
812
return 1 ;
805
813
}
806
814
815
+ std::pair<bool , std::string> PatternEmitter::getLocation (DagNode tree) {
816
+ auto numPatArgs = tree.getNumArgs ();
817
+
818
+ if (numPatArgs != 0 ) {
819
+ if (auto lastArg = tree.getArgAsNestedDag (numPatArgs - 1 ))
820
+ if (lastArg.isLocationDirective ()) {
821
+ return std::make_pair (true , handleLocationDirective (lastArg));
822
+ }
823
+ }
824
+
825
+ // If no explicit location is given, use the default, all fused, location.
826
+ return std::make_pair (false , " odsLoc" );
827
+ }
828
+
807
829
std::string PatternEmitter::handleOpCreation (DagNode tree, int resultIndex,
808
830
int depth) {
809
831
LLVM_DEBUG (llvm::dbgs () << " create op for pattern: " );
@@ -814,26 +836,18 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex,
814
836
auto numOpArgs = resultOp.getNumArgs ();
815
837
auto numPatArgs = tree.getNumArgs ();
816
838
817
- // Get the location for this operation if explicitly provided.
839
+ bool hasLocationDirective;
818
840
std::string locToUse;
819
- if (numPatArgs != 0 ) {
820
- if (auto lastArg = tree.getArgAsNestedDag (numPatArgs - 1 ))
821
- if (lastArg.isLocationDirective ())
822
- locToUse = handleLocationDirective (lastArg);
823
- }
841
+ std::tie (hasLocationDirective, locToUse) = getLocation (tree);
824
842
825
- auto inPattern = numPatArgs - !locToUse. empty () ;
843
+ auto inPattern = numPatArgs - hasLocationDirective ;
826
844
if (numOpArgs != inPattern) {
827
845
PrintFatalError (loc,
828
846
formatv (" resultant op '{0}' argument number mismatch: "
829
847
" {1} in pattern vs. {2} in definition" ,
830
848
resultOp.getOperationName (), inPattern, numOpArgs));
831
849
}
832
850
833
- // If no explicit location is given, use the default, all fused, location.
834
- if (locToUse.empty ())
835
- locToUse = " odsLoc" ;
836
-
837
851
// A map to collect all nested DAG child nodes' names, with operand index as
838
852
// the key. This includes both bound and unbound child nodes.
839
853
ChildNodeIndexNameMap childNodeNames;
0 commit comments