aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineOutliner.cpp
diff options
context:
space:
mode:
authorJessica Paquette <jpaquette@apple.com>2018-11-07 18:36:43 +0000
committerJessica Paquette <jpaquette@apple.com>2018-11-07 18:36:43 +0000
commita3eb0fac3be2373516d454717d8f4584831908ec (patch)
treef4e3796ec7650a332eaad894a2a35dbe8dc45ef2 /llvm/lib/CodeGen/MachineOutliner.cpp
parent5dc0fba2e38a63f861462e7e57a346afffc786d6 (diff)
downloadllvm-a3eb0fac3be2373516d454717d8f4584831908ec.zip
llvm-a3eb0fac3be2373516d454717d8f4584831908ec.tar.gz
llvm-a3eb0fac3be2373516d454717d8f4584831908ec.tar.bz2
[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). llvm-svn: 346340
Diffstat (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineOutliner.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index bccf952..1b2b448 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -801,7 +801,8 @@ struct MachineOutliner : public ModulePass {
/// Creates a function for \p OF and inserts it into the module.
MachineFunction *createOutlinedFunction(Module &M, const OutlinedFunction &OF,
- InstructionMapper &Mapper);
+ InstructionMapper &Mapper,
+ unsigned Name);
/// Find potential outlining candidates and store them in \p CandidateList.
///
@@ -1035,7 +1036,6 @@ unsigned MachineOutliner::findCandidates(
for (unsigned i = StartIdx; i < StartIdx + StringLen; i++)
Seq.push_back(ST.Str[i]);
OF.Sequence = Seq;
- OF.Name = FunctionList.size();
// Is it better to outline this candidate than not?
if (OF.getBenefit() < 1) {
@@ -1190,13 +1190,16 @@ unsigned MachineOutliner::buildCandidateList(
MachineFunction *
MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
- InstructionMapper &Mapper) {
+ InstructionMapper &Mapper,
+ unsigned Name) {
// Create the function name. This should be unique. For now, just hash the
// module name and include it in the function name plus the number of this
// function.
std::ostringstream NameStream;
- NameStream << "OUTLINED_FUNCTION_" << OF.Name;
+ // FIXME: We should have a better naming scheme. This should be stable,
+ // regardless of changes to the outliner's cost model/traversal order.
+ NameStream << "OUTLINED_FUNCTION_" << Name;
// Create the function using an IR-level function.
LLVMContext &C = M.getContext();
@@ -1295,6 +1298,10 @@ bool MachineOutliner::outline(
std::vector<OutlinedFunction> &FunctionList, InstructionMapper &Mapper) {
bool OutlinedSomething = false;
+
+ // Number to append to the current outlined function.
+ unsigned OutlinedFunctionNum = 0;
+
// Replace the candidates with calls to their respective outlined functions.
for (const std::shared_ptr<Candidate> &Cptr : CandidateList) {
Candidate &C = *Cptr;
@@ -1311,9 +1318,10 @@ bool MachineOutliner::outline(
// Does this candidate have a function yet?
if (!OF.MF) {
- OF.MF = createOutlinedFunction(M, OF, Mapper);
+ OF.MF = createOutlinedFunction(M, OF, Mapper, OutlinedFunctionNum);
emitOutlinedFunctionRemark(OF);
FunctionsCreated++;
+ OutlinedFunctionNum++; // Created a function, move to the next name.
}
MachineFunction *MF = OF.MF;