llvm.org GIT mirror llvm / fc6b6a7
[MachineOutliner] Don't store outlined function numberings on OutlinedFunction NFC-ish. This doesn't change the behaviour of the outliner, but does make sure that you won't end up with say OUTLINED_FUNCTION_2: ... ret OUTLINED_FUNCTION_248: ... ret as the only outlined functions in your module. Those should really be OUTLINED_FUNCTION_0: ... ret OUTLINED_FUNCTION_1: ... ret If we produce outlined functions, they probably should have sequential numbers attached to them. This makes it a bit easier+stable to write outliner tests. The point of this is to move towards a bit more stability in outlined function names. By doing this, we at least don't rely on the traversal order of the suffix tree. Instead, we rely on the order of the candidate list, which is *far* more consistent. The candidate list is ordered by the end indices of candidates, so we're more likely to get a stable ordering. This is still susceptible to changes in the cost model though (like, if we suddenly find new candidates, for example). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346340 91177308-0d34-0410-b5e6-96231b3b80d8 Jessica Paquette 11 months ago
2 changed file(s) with 13 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
168168 /// This is initialized after we go through and create the actual function.
169169 MachineFunction *MF = nullptr;
170170
171 /// A number assigned to this function which appears at the end of its name.
172 unsigned Name;
173
174171 /// The sequence of integers corresponding to the instructions in this
175172 /// function.
176173 std::vector Sequence;
800800
801801 /// Creates a function for \p OF and inserts it into the module.
802802 MachineFunction *createOutlinedFunction(Module &M, const OutlinedFunction &OF,
803 InstructionMapper &Mapper);
803 InstructionMapper &Mapper,
804 unsigned Name);
804805
805806 /// Find potential outlining candidates and store them in \p CandidateList.
806807 ///
10341035 for (unsigned i = StartIdx; i < StartIdx + StringLen; i++)
10351036 Seq.push_back(ST.Str[i]);
10361037 OF.Sequence = Seq;
1037 OF.Name = FunctionList.size();
10381038
10391039 // Is it better to outline this candidate than not?
10401040 if (OF.getBenefit() < 1) {
11891189
11901190 MachineFunction *
11911191 MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
1192 InstructionMapper &Mapper) {
1192 InstructionMapper &Mapper,
1193 unsigned Name) {
11931194
11941195 // Create the function name. This should be unique. For now, just hash the
11951196 // module name and include it in the function name plus the number of this
11961197 // function.
11971198 std::ostringstream NameStream;
1198 NameStream << "OUTLINED_FUNCTION_" << OF.Name;
1199 // FIXME: We should have a better naming scheme. This should be stable,
1200 // regardless of changes to the outliner's cost model/traversal order.
1201 NameStream << "OUTLINED_FUNCTION_" << Name;
11991202
12001203 // Create the function using an IR-level function.
12011204 LLVMContext &C = M.getContext();
12941297 std::vector &FunctionList, InstructionMapper &Mapper) {
12951298
12961299 bool OutlinedSomething = false;
1300
1301 // Number to append to the current outlined function.
1302 unsigned OutlinedFunctionNum = 0;
1303
12971304 // Replace the candidates with calls to their respective outlined functions.
12981305 for (const std::shared_ptr &Cptr : CandidateList) {
12991306 Candidate &C = *Cptr;
13101317
13111318 // Does this candidate have a function yet?
13121319 if (!OF.MF) {
1313 OF.MF = createOutlinedFunction(M, OF, Mapper);
1320 OF.MF = createOutlinedFunction(M, OF, Mapper, OutlinedFunctionNum);
13141321 emitOutlinedFunctionRemark(OF);
13151322 FunctionsCreated++;
1323 OutlinedFunctionNum++; // Created a function, move to the next name.
13161324 }
13171325
13181326 MachineFunction *MF = OF.MF;