[llvm] r315383 - [Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Eugene Zelenko via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 15:49:55 PDT 2017
Author: eugenezelenko
Date: Tue Oct 10 15:49:55 2017
New Revision: 315383
URL: http://llvm.org/viewvc/llvm-project?rev=315383&view=rev
Log:
[Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Modified:
llvm/trunk/include/llvm/Transforms/IPO/ConstantMerge.h
llvm/trunk/include/llvm/Transforms/IPO/DeadArgumentElimination.h
llvm/trunk/include/llvm/Transforms/IPO/ElimAvailExtern.h
llvm/trunk/include/llvm/Transforms/IPO/FunctionImport.h
llvm/trunk/include/llvm/Transforms/IPO/GlobalOpt.h
llvm/trunk/include/llvm/Transforms/IPO/GlobalSplit.h
llvm/trunk/include/llvm/Transforms/IPO/PartialInlining.h
llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp
llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
llvm/trunk/lib/Transforms/IPO/ElimAvailExtern.cpp
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp
llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp
Modified: llvm/trunk/include/llvm/Transforms/IPO/ConstantMerge.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/ConstantMerge.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/ConstantMerge.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/ConstantMerge.h Tue Oct 10 15:49:55 2017
@@ -20,16 +20,18 @@
#ifndef LLVM_TRANSFORMS_IPO_CONSTANTMERGE_H
#define LLVM_TRANSFORMS_IPO_CONSTANTMERGE_H
-#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
+class Module;
+
/// A pass that merges duplicate global constants into a single constant.
class ConstantMergePass : public PassInfoMixin<ConstantMergePass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
};
-}
+
+} // end namespace llvm
#endif // LLVM_TRANSFORMS_IPO_CONSTANTMERGE_H
Modified: llvm/trunk/include/llvm/Transforms/IPO/DeadArgumentElimination.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/DeadArgumentElimination.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/DeadArgumentElimination.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/DeadArgumentElimination.h Tue Oct 10 15:49:55 2017
@@ -20,15 +20,21 @@
#ifndef LLVM_TRANSFORMS_IPO_DEADARGUMENTELIMINATION_H
#define LLVM_TRANSFORMS_IPO_DEADARGUMENTELIMINATION_H
-#include "llvm/IR/Module.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/PassManager.h"
-
#include <map>
#include <set>
#include <string>
+#include <tuple>
namespace llvm {
+class Module;
+class Use;
+class Value;
+
/// Eliminate dead arguments (and return values) from functions.
class DeadArgumentEliminationPass
: public PassInfoMixin<DeadArgumentEliminationPass> {
@@ -37,12 +43,13 @@ public:
/// argument. Used so that arguments and return values can be used
/// interchangeably.
struct RetOrArg {
- RetOrArg(const Function *F, unsigned Idx, bool IsArg)
- : F(F), Idx(Idx), IsArg(IsArg) {}
const Function *F;
unsigned Idx;
bool IsArg;
+ RetOrArg(const Function *F, unsigned Idx, bool IsArg)
+ : F(F), Idx(Idx), IsArg(IsArg) {}
+
/// Make RetOrArg comparable, so we can put it into a map.
bool operator<(const RetOrArg &O) const {
return std::tie(F, Idx, IsArg) < std::tie(O.F, O.Idx, O.IsArg);
@@ -67,16 +74,23 @@ public:
/// thus become dead in the end.
enum Liveness { Live, MaybeLive };
+ DeadArgumentEliminationPass(bool ShouldHackArguments_ = false)
+ : ShouldHackArguments(ShouldHackArguments_) {}
+
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
+
/// Convenience wrapper
RetOrArg CreateRet(const Function *F, unsigned Idx) {
return RetOrArg(F, Idx, false);
}
+
/// Convenience wrapper
RetOrArg CreateArg(const Function *F, unsigned Idx) {
return RetOrArg(F, Idx, true);
}
- typedef std::multimap<RetOrArg, RetOrArg> UseMap;
+ using UseMap = std::multimap<RetOrArg, RetOrArg>;
+
/// This maps a return value or argument to any MaybeLive return values or
/// arguments it uses. This allows the MaybeLive values to be marked live
/// when any of its users is marked live.
@@ -93,25 +107,21 @@ public:
/// directly to F.
UseMap Uses;
- typedef std::set<RetOrArg> LiveSet;
- typedef std::set<const Function *> LiveFuncSet;
+ using LiveSet = std::set<RetOrArg>;
+ using LiveFuncSet = std::set<const Function *>;
/// This set contains all values that have been determined to be live.
LiveSet LiveValues;
+
/// This set contains all values that are cannot be changed in any way.
LiveFuncSet LiveFunctions;
- typedef SmallVector<RetOrArg, 5> UseVector;
+ using UseVector = SmallVector<RetOrArg, 5>;
/// This allows this pass to do double-duty as the dead arg hacking pass
/// (used only by bugpoint).
bool ShouldHackArguments = false;
-public:
- DeadArgumentEliminationPass(bool ShouldHackArguments_ = false)
- : ShouldHackArguments(ShouldHackArguments_) {}
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
-
private:
Liveness MarkIfNotLive(RetOrArg Use, UseVector &MaybeLiveUses);
Liveness SurveyUse(const Use *U, UseVector &MaybeLiveUses,
@@ -128,6 +138,7 @@ private:
bool DeleteDeadVarargs(Function &Fn);
bool RemoveDeadArgumentsFromCallers(Function &Fn);
};
-}
+
+} // end namespace llvm
#endif // LLVM_TRANSFORMS_IPO_DEADARGUMENTELIMINATION_H
Modified: llvm/trunk/include/llvm/Transforms/IPO/ElimAvailExtern.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/ElimAvailExtern.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/ElimAvailExtern.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/ElimAvailExtern.h Tue Oct 10 15:49:55 2017
@@ -15,17 +15,19 @@
#ifndef LLVM_TRANSFORMS_IPO_ELIMAVAILEXTERN_H
#define LLVM_TRANSFORMS_IPO_ELIMAVAILEXTERN_H
-#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
+class Module;
+
/// A pass that transforms external global definitions into declarations.
class EliminateAvailableExternallyPass
: public PassInfoMixin<EliminateAvailableExternallyPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
};
-}
+
+} // end namespace llvm
#endif // LLVM_TRANSFORMS_IPO_ELIMAVAILEXTERN_H
Modified: llvm/trunk/include/llvm/Transforms/IPO/FunctionImport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/FunctionImport.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/FunctionImport.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/FunctionImport.h Tue Oct 10 15:49:55 2017
@@ -7,23 +7,26 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_FUNCTIONIMPORT_H
-#define LLVM_FUNCTIONIMPORT_H
+#ifndef LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
+#define LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Error.h"
-
#include <functional>
#include <map>
+#include <memory>
+#include <string>
+#include <system_error>
#include <unordered_set>
#include <utility>
namespace llvm {
-class LLVMContext;
-class GlobalValueSummary;
+
class Module;
/// The function importer is automatically importing function from other modules
@@ -34,19 +37,19 @@ public:
/// containing all the functions to import for a source module.
/// The keys is the GUID identifying a function to import, and the value
/// is the threshold applied when deciding to import it.
- typedef std::map<GlobalValue::GUID, unsigned> FunctionsToImportTy;
+ using FunctionsToImportTy = std::map<GlobalValue::GUID, unsigned>;
/// The map contains an entry for every module to import from, the key being
/// the module identifier to pass to the ModuleLoader. The value is the set of
/// functions to import.
- typedef StringMap<FunctionsToImportTy> ImportMapTy;
+ using ImportMapTy = StringMap<FunctionsToImportTy>;
/// The set contains an entry for every global value the module exports.
- typedef std::unordered_set<GlobalValue::GUID> ExportSetTy;
+ using ExportSetTy = std::unordered_set<GlobalValue::GUID>;
/// A function of this type is used to load modules referenced by the index.
- typedef std::function<Expected<std::unique_ptr<Module>>(StringRef Identifier)>
- ModuleLoaderTy;
+ using ModuleLoaderTy =
+ std::function<Expected<std::unique_ptr<Module>>(StringRef Identifier)>;
/// Create a Function Importer.
FunctionImporter(const ModuleSummaryIndex &Index, ModuleLoaderTy ModuleLoader)
@@ -132,6 +135,7 @@ void thinLTOResolveWeakForLinkerModule(M
/// during global summary-based analysis.
void thinLTOInternalizeModule(Module &TheModule,
const GVSummaryMapTy &DefinedGlobals);
-}
-#endif // LLVM_FUNCTIONIMPORT_H
+} // end namespace llvm
+
+#endif // LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
Modified: llvm/trunk/include/llvm/Transforms/IPO/GlobalOpt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/GlobalOpt.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/GlobalOpt.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/GlobalOpt.h Tue Oct 10 15:49:55 2017
@@ -16,17 +16,18 @@
#ifndef LLVM_TRANSFORMS_IPO_GLOBALOPT_H
#define LLVM_TRANSFORMS_IPO_GLOBALOPT_H
-#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
+class Module;
+
/// Optimize globals that never have their address taken.
class GlobalOptPass : public PassInfoMixin<GlobalOptPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
-}
+} // end namespace llvm
#endif // LLVM_TRANSFORMS_IPO_GLOBALOPT_H
Modified: llvm/trunk/include/llvm/Transforms/IPO/GlobalSplit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/GlobalSplit.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/GlobalSplit.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/GlobalSplit.h Tue Oct 10 15:49:55 2017
@@ -17,14 +17,18 @@
#ifndef LLVM_TRANSFORMS_IPO_GLOBALSPLIT_H
#define LLVM_TRANSFORMS_IPO_GLOBALSPLIT_H
-#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
+
+class Module;
+
/// Pass to perform split of global variables.
class GlobalSplitPass : public PassInfoMixin<GlobalSplitPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
-}
+
+} // end namespace llvm
+
#endif // LLVM_TRANSFORMS_IPO_GLOBALSPLIT_H
Modified: llvm/trunk/include/llvm/Transforms/IPO/PartialInlining.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/PartialInlining.h?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/PartialInlining.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/PartialInlining.h Tue Oct 10 15:49:55 2017
@@ -1,4 +1,4 @@
-//===- PartialInlining.h - Inline parts of functions --------------------===//
+//===- PartialInlining.h - Inline parts of functions ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -15,15 +15,18 @@
#ifndef LLVM_TRANSFORMS_IPO_PARTIALINLINING_H
#define LLVM_TRANSFORMS_IPO_PARTIALINLINING_H
-#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
+class Module;
+
/// Pass to remove unused function declarations.
class PartialInlinerPass : public PassInfoMixin<PartialInlinerPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
};
-}
+
+} // end namespace llvm
+
#endif // LLVM_TRANSFORMS_IPO_PARTIALINLINING_H
Modified: llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ConstantMerge.cpp Tue Oct 10 15:49:55 2017
@@ -19,16 +19,23 @@
#include "llvm/Transforms/IPO/ConstantMerge.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/Operator.h"
#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Transforms/IPO.h"
+#include <algorithm>
+#include <cassert>
+#include <utility>
+
using namespace llvm;
#define DEBUG_TYPE "constmerge"
@@ -102,8 +109,7 @@ static bool mergeConstants(Module &M) {
// constants together may allow us to merge other constants together if the
// second level constants have initializers which point to the globals that
// were just merged.
- while (1) {
-
+ while (true) {
// First: Find the canonical constants others will be merged with.
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
GVI != E; ) {
@@ -225,23 +231,27 @@ PreservedAnalyses ConstantMergePass::run
}
namespace {
+
struct ConstantMergeLegacyPass : public ModulePass {
static char ID; // Pass identification, replacement for typeid
+
ConstantMergeLegacyPass() : ModulePass(ID) {
initializeConstantMergeLegacyPassPass(*PassRegistry::getPassRegistry());
}
// For this pass, process all of the globals in the module, eliminating
// duplicate constants.
- bool runOnModule(Module &M) {
+ bool runOnModule(Module &M) override {
if (skipModule(M))
return false;
return mergeConstants(M);
}
};
-}
+
+} // end anonymous namespace
char ConstantMergeLegacyPass::ID = 0;
+
INITIALIZE_PASS(ConstantMergeLegacyPass, "constmerge",
"Merge Duplicate Global Constants", false, false)
Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Tue Oct 10 15:49:55 2017
@@ -1,4 +1,4 @@
-//===-- DeadArgumentElimination.cpp - Eliminate dead arguments ------------===//
+//===- DeadArgumentElimination.cpp - Eliminate dead arguments -------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -20,24 +20,36 @@
#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/Argument.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
-#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constant.h"
-#include "llvm/IR/DIBuilder.h"
-#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
-#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
-#include <set>
-#include <tuple>
+#include <cassert>
+#include <cstdint>
+#include <utility>
+#include <vector>
+
using namespace llvm;
#define DEBUG_TYPE "deadargelim"
@@ -46,9 +58,10 @@ STATISTIC(NumArgumentsEliminated, "Numbe
STATISTIC(NumRetValsEliminated , "Number of unused return values removed");
STATISTIC(NumArgumentsReplacedWithUndef,
"Number of unread args replaced with undef");
+
namespace {
+
/// DAE - The dead argument elimination pass.
- ///
class DAE : public ModulePass {
protected:
// DAH uses this to specify a different ID.
@@ -56,6 +69,7 @@ namespace {
public:
static char ID; // Pass identification, replacement for typeid
+
DAE() : ModulePass(ID) {
initializeDAEPass(*PassRegistry::getPassRegistry());
}
@@ -71,33 +85,38 @@ namespace {
virtual bool ShouldHackArguments() const { return false; }
};
-}
+} // end anonymous namespace
char DAE::ID = 0;
+
INITIALIZE_PASS(DAE, "deadargelim", "Dead Argument Elimination", false, false)
namespace {
+
/// DAH - DeadArgumentHacking pass - Same as dead argument elimination, but
/// deletes arguments to functions which are external. This is only for use
/// by bugpoint.
struct DAH : public DAE {
static char ID;
+
DAH() : DAE(ID) {}
bool ShouldHackArguments() const override { return true; }
};
-}
+
+} // end anonymous namespace
char DAH::ID = 0;
+
INITIALIZE_PASS(DAH, "deadarghaX0r",
"Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)",
false, false)
/// createDeadArgEliminationPass - This pass removes arguments from functions
/// which are not used by the body of the function.
-///
ModulePass *llvm::createDeadArgEliminationPass() { return new DAE(); }
+
ModulePass *llvm::createDeadArgHackingPass() { return new DAH(); }
/// DeleteDeadVarargs - If this is an function that takes a ... list, and if
@@ -140,7 +159,7 @@ bool DeadArgumentEliminationPass::Delete
// the old function, but doesn't have isVarArg set.
FunctionType *FTy = Fn.getFunctionType();
- std::vector<Type*> Params(FTy->param_begin(), FTy->param_end());
+ std::vector<Type *> Params(FTy->param_begin(), FTy->param_end());
FunctionType *NFTy = FunctionType::get(FTy->getReturnType(),
Params, false);
unsigned NumArgs = Params.size();
@@ -155,7 +174,7 @@ bool DeadArgumentEliminationPass::Delete
// Loop over all of the callers of the function, transforming the call sites
// to pass in a smaller number of arguments into the new function.
//
- std::vector<Value*> Args;
+ std::vector<Value *> Args;
for (Value::user_iterator I = Fn.user_begin(), E = Fn.user_end(); I != E; ) {
CallSite CS(*I++);
if (!CS)
@@ -214,7 +233,6 @@ bool DeadArgumentEliminationPass::Delete
// Loop over the argument list, transferring uses of the old arguments over to
// the new arguments, also transferring over the names as well. While we're at
// it, remove the dead arguments from the DeadArguments list.
- //
for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end(),
I2 = NF->arg_begin(); I != E; ++I, ++I2) {
// Move the name and users over to the new version.
@@ -343,7 +361,6 @@ DeadArgumentEliminationPass::MarkIfNotLi
return MaybeLive;
}
-
/// SurveyUse - This looks at a single use of an argument or return value
/// and determines if it should be alive or not. Adds this use to MaybeLiveUses
/// if it causes the used value to become MaybeLive.
@@ -460,7 +477,6 @@ DeadArgumentEliminationPass::SurveyUses(
//
// We consider arguments of non-internal functions to be intrinsically alive as
// well as arguments to functions which have their "address taken".
-//
void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
// Functions with inalloca parameters are expecting args in a particular
// register and memory layout.
@@ -478,11 +494,14 @@ void DeadArgumentEliminationPass::Survey
}
unsigned RetCount = NumRetVals(&F);
+
// Assume all return values are dead
- typedef SmallVector<Liveness, 5> RetVals;
+ using RetVals = SmallVector<Liveness, 5>;
+
RetVals RetValLiveness(RetCount, MaybeLive);
- typedef SmallVector<UseVector, 5> RetUses;
+ using RetUses = SmallVector<UseVector, 5>;
+
// These vectors map each return value to the uses that make it MaybeLive, so
// we can add those to the Uses map if the return value really turns out to be
// MaybeLive. Initialized to a list of RetCount empty lists.
@@ -601,15 +620,15 @@ void DeadArgumentEliminationPass::Survey
void DeadArgumentEliminationPass::MarkValue(const RetOrArg &RA, Liveness L,
const UseVector &MaybeLiveUses) {
switch (L) {
- case Live: MarkLive(RA); break;
+ case Live:
+ MarkLive(RA);
+ break;
case MaybeLive:
- {
// Note any uses of this value, so this return value can be
// marked live whenever one of the uses becomes live.
for (const auto &MaybeLiveUse : MaybeLiveUses)
Uses.insert(std::make_pair(MaybeLiveUse, RA));
break;
- }
}
}
@@ -762,7 +781,7 @@ bool DeadArgumentEliminationPass::Remove
// One return type? Just a simple value then, but only if we didn't use to
// return a struct with that simple value before.
NRetTy = RetTypes.front();
- else if (RetTypes.size() == 0)
+ else if (RetTypes.empty())
// No return types? Make it void, but only if we didn't use to return {}.
NRetTy = Type::getVoidTy(F->getContext());
}
@@ -808,7 +827,6 @@ bool DeadArgumentEliminationPass::Remove
// Loop over all of the callers of the function, transforming the call sites
// to pass in a smaller number of arguments into the new function.
- //
std::vector<Value*> Args;
while (!F->use_empty()) {
CallSite CS(F->user_back());
Modified: llvm/trunk/lib/Transforms/IPO/ElimAvailExtern.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ElimAvailExtern.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ElimAvailExtern.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ElimAvailExtern.cpp Tue Oct 10 15:49:55 2017
@@ -1,5 +1,4 @@
-//===-- ElimAvailExtern.cpp - DCE unreachable internal functions
-//----------------===//
+//===- ElimAvailExtern.cpp - DCE unreachable internal functions -----------===//
//
// The LLVM Compiler Infrastructure
//
@@ -15,11 +14,15 @@
#include "llvm/Transforms/IPO/ElimAvailExtern.h"
#include "llvm/ADT/Statistic.h"
-#include "llvm/IR/Constants.h"
+#include "llvm/IR/Constant.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/GlobalStatus.h"
+
using namespace llvm;
#define DEBUG_TYPE "elim-avail-extern"
@@ -69,8 +72,10 @@ EliminateAvailableExternallyPass::run(Mo
}
namespace {
+
struct EliminateAvailableExternallyLegacyPass : public ModulePass {
static char ID; // Pass identification, replacement for typeid
+
EliminateAvailableExternallyLegacyPass() : ModulePass(ID) {
initializeEliminateAvailableExternallyLegacyPassPass(
*PassRegistry::getPassRegistry());
@@ -78,16 +83,17 @@ struct EliminateAvailableExternallyLegac
// run - Do the EliminateAvailableExternally pass on the specified module,
// optionally updating the specified callgraph to reflect the changes.
- //
- bool runOnModule(Module &M) {
+ bool runOnModule(Module &M) override {
if (skipModule(M))
return false;
return eliminateAvailableExternally(M);
}
};
-}
+
+} // end anonymous namespace
char EliminateAvailableExternallyLegacyPass::ID = 0;
+
INITIALIZE_PASS(EliminateAvailableExternallyLegacyPass, "elim-avail-extern",
"Eliminate Available Externally Globals", false, false)
Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Tue Oct 10 15:49:55 2017
@@ -12,30 +12,51 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO/FunctionImport.h"
-
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
-#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/AutoUpgrade.h"
-#include "llvm/IR/DiagnosticPrinter.h"
-#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalAlias.h"
+#include "llvm/IR/GlobalObject.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/Verifier.h"
+#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IRReader/IRReader.h"
-#include "llvm/Linker/Linker.h"
-#include "llvm/Object/IRObjectFile.h"
+#include "llvm/Linker/IRMover.h"
+#include "llvm/Object/ModuleSymbolTable.h"
+#include "llvm/Object/SymbolicFile.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
-
-#define DEBUG_TYPE "function-import"
+#include <cassert>
+#include <memory>
+#include <set>
+#include <string>
+#include <system_error>
+#include <tuple>
+#include <utility>
using namespace llvm;
+#define DEBUG_TYPE "function-import"
+
STATISTIC(NumImportedFunctions, "Number of functions imported");
STATISTIC(NumImportedModules, "Number of modules imported from");
STATISTIC(NumDeadSymbols, "Number of dead stripped symbols in index");
@@ -91,6 +112,12 @@ static cl::opt<bool> EnableImportMetadat
),
cl::Hidden, cl::desc("Enable import metadata like 'thinlto_src_module'"));
+/// Summary file to use for function importing when using -function-import from
+/// the command line.
+static cl::opt<std::string>
+ SummaryFile("summary-file",
+ cl::desc("The summary file to use for function importing."));
+
// Load lazily a module from \p FileName in \p Context.
static std::unique_ptr<Module> loadFile(const std::string &FileName,
LLVMContext &Context) {
@@ -109,8 +136,6 @@ static std::unique_ptr<Module> loadFile(
return Result;
}
-namespace {
-
/// Given a list of possible callee implementation for a call site, select one
/// that fits the \p Threshold.
///
@@ -184,9 +209,13 @@ selectCallee(const ModuleSummaryIndex &I
return cast<GlobalValueSummary>(It->get());
}
+namespace {
+
using EdgeInfo = std::tuple<const FunctionSummary *, unsigned /* Threshold */,
GlobalValue::GUID>;
+} // anonymous namespace
+
static ValueInfo
updateValueInfoForIndirectCalls(const ModuleSummaryIndex &Index, ValueInfo VI) {
if (!VI.getSummaryList().empty())
@@ -354,8 +383,6 @@ static void ComputeImportForModule(
}
}
-} // anonymous namespace
-
/// Compute all the import and export for every module using the Index.
void llvm::ComputeCrossModuleImport(
const ModuleSummaryIndex &Index,
@@ -409,7 +436,6 @@ void llvm::ComputeCrossModuleImport(
void llvm::ComputeCrossModuleImportForModule(
StringRef ModulePath, const ModuleSummaryIndex &Index,
FunctionImporter::ImportMapTy &ImportList) {
-
// Collect the list of functions this module defines.
// GUID -> Summary
GVSummaryMapTy FunctionSummaryMap;
@@ -663,12 +689,11 @@ void llvm::thinLTOInternalizeModule(Modu
// FIXME: See if we can just internalize directly here via linkage changes
// based on the index, rather than invoking internalizeModule.
- llvm::internalizeModule(TheModule, MustPreserveGV);
+ internalizeModule(TheModule, MustPreserveGV);
}
// Automatically import functions in Module \p DestModule based on the summaries
// index.
-//
Expected<bool> FunctionImporter::importFunctions(
Module &DestModule, const FunctionImporter::ImportMapTy &ImportList) {
DEBUG(dbgs() << "Starting import for Module "
@@ -715,10 +740,9 @@ Expected<bool> FunctionImporter::importF
// Add 'thinlto_src_module' metadata for statistics and debugging.
F.setMetadata(
"thinlto_src_module",
- llvm::MDNode::get(
- DestModule.getContext(),
- {llvm::MDString::get(DestModule.getContext(),
- SrcModule->getSourceFileName())}));
+ MDNode::get(DestModule.getContext(),
+ {MDString::get(DestModule.getContext(),
+ SrcModule->getSourceFileName())}));
}
GlobalsToImport.insert(&F);
}
@@ -779,12 +803,6 @@ Expected<bool> FunctionImporter::importF
return ImportedCount;
}
-/// Summary file to use for function importing when using -function-import from
-/// the command line.
-static cl::opt<std::string>
- SummaryFile("summary-file",
- cl::desc("The summary file to use for function importing."));
-
static bool doImportingForModule(Module &M) {
if (SummaryFile.empty())
report_fatal_error("error: -function-import requires -summary-file\n");
@@ -838,17 +856,18 @@ static bool doImportingForModule(Module
}
namespace {
+
/// Pass that performs cross-module function import provided a summary file.
class FunctionImportLegacyPass : public ModulePass {
public:
/// Pass identification, replacement for typeid
static char ID;
+ explicit FunctionImportLegacyPass() : ModulePass(ID) {}
+
/// Specify pass name for debug output
StringRef getPassName() const override { return "Function Importing"; }
- explicit FunctionImportLegacyPass() : ModulePass(ID) {}
-
bool runOnModule(Module &M) override {
if (skipModule(M))
return false;
@@ -856,7 +875,8 @@ public:
return doImportingForModule(M);
}
};
-} // anonymous namespace
+
+} // end anonymous namespace
PreservedAnalyses FunctionImportPass::run(Module &M,
ModuleAnalysisManager &AM) {
@@ -871,7 +891,9 @@ INITIALIZE_PASS(FunctionImportLegacyPass
"Summary Based Function Import", false, false)
namespace llvm {
+
Pass *createFunctionImportPass() {
return new FunctionImportLegacyPass();
}
-}
+
+} // end namespace llvm
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Oct 10 15:49:55 2017
@@ -20,24 +20,41 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
+#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
+#include "llvm/IR/GlobalAlias.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
-#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Pass.h"
+#include "llvm/Support/AtomicOrdering.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
@@ -47,7 +64,11 @@
#include "llvm/Transforms/Utils/Evaluator.h"
#include "llvm/Transforms/Utils/GlobalStatus.h"
#include "llvm/Transforms/Utils/Local.h"
-#include <algorithm>
+#include <cassert>
+#include <cstdint>
+#include <utility>
+#include <vector>
+
using namespace llvm;
#define DEBUG_TYPE "globalopt"
@@ -141,7 +162,7 @@ static bool IsSafeComputationToRemove(Va
}
V = I->getOperand(0);
- } while (1);
+ } while (true);
}
/// This GV is a pointer root. Loop over all users of the global and clean up
@@ -222,7 +243,7 @@ static bool CleanupPointerRootUsers(Glob
break;
I->eraseFromParent();
I = J;
- } while (1);
+ } while (true);
I->eraseFromParent();
}
}
@@ -350,7 +371,6 @@ static bool isSafeSROAElementUse(Value *
return true;
}
-
/// U is a direct user of the specified global value. Look at it and its uses
/// and decide whether it is safe to SROA this global.
static bool IsUserOfGlobalSafeForSRA(User *U, GlobalValue *GV) {
@@ -436,7 +456,6 @@ static void transferSRADebugInfo(GlobalV
}
}
-
/// Perform scalar replacement of aggregates on the specified global variable.
/// This opens the door for other optimizations by exposing the behavior of the
/// program in a more fine-grained way. We have determined that this
@@ -451,7 +470,7 @@ static GlobalVariable *SRAGlobal(GlobalV
Constant *Init = GV->getInitializer();
Type *Ty = Init->getType();
- std::vector<GlobalVariable*> NewGlobals;
+ std::vector<GlobalVariable *> NewGlobals;
Module::GlobalListType &Globals = GV->getParent()->getGlobalList();
// Get the alignment of the global, either explicit or target-specific.
@@ -717,7 +736,6 @@ static bool OptimizeAwayTrappingUsesOfVa
return Changed;
}
-
/// The specified global has only one non-null value stored into it. If there
/// are uses of the loaded value that would trap if the loaded value is
/// dynamically null, then we know that they cannot be reachable with a null
@@ -1073,7 +1091,6 @@ static bool LoadUsesSimpleEnoughForHeapS
return true;
}
-
/// If all users of values loaded from GV are simple enough to perform HeapSRA,
/// return true.
static bool AllGlobalLoadUsesSimpleEnoughForHeapSRA(const GlobalVariable *GV,
@@ -1123,9 +1140,9 @@ static bool AllGlobalLoadUsesSimpleEnoug
}
static Value *GetHeapSROAValue(Value *V, unsigned FieldNo,
- DenseMap<Value*, std::vector<Value*> > &InsertedScalarizedValues,
- std::vector<std::pair<PHINode*, unsigned> > &PHIsToRewrite) {
- std::vector<Value*> &FieldVals = InsertedScalarizedValues[V];
+ DenseMap<Value *, std::vector<Value *>> &InsertedScalarizedValues,
+ std::vector<std::pair<PHINode *, unsigned>> &PHIsToRewrite) {
+ std::vector<Value *> &FieldVals = InsertedScalarizedValues[V];
if (FieldNo >= FieldVals.size())
FieldVals.resize(FieldNo+1);
@@ -1167,8 +1184,8 @@ static Value *GetHeapSROAValue(Value *V,
/// Given a load instruction and a value derived from the load, rewrite the
/// derived value to use the HeapSRoA'd load.
static void RewriteHeapSROALoadUser(Instruction *LoadUser,
- DenseMap<Value*, std::vector<Value*> > &InsertedScalarizedValues,
- std::vector<std::pair<PHINode*, unsigned> > &PHIsToRewrite) {
+ DenseMap<Value *, std::vector<Value *>> &InsertedScalarizedValues,
+ std::vector<std::pair<PHINode *, unsigned>> &PHIsToRewrite) {
// If this is a comparison against null, handle it.
if (ICmpInst *SCI = dyn_cast<ICmpInst>(LoadUser)) {
assert(isa<ConstantPointerNull>(SCI->getOperand(1)));
@@ -1215,7 +1232,7 @@ static void RewriteHeapSROALoadUser(Inst
// processed.
PHINode *PN = cast<PHINode>(LoadUser);
if (!InsertedScalarizedValues.insert(std::make_pair(PN,
- std::vector<Value*>())).second)
+ std::vector<Value *>())).second)
return;
// If this is the first time we've seen this PHI, recursively process all
@@ -1230,8 +1247,8 @@ static void RewriteHeapSROALoadUser(Inst
/// global. Eliminate all uses of Ptr, making them use FieldGlobals instead.
/// All uses of loaded values satisfy AllGlobalLoadUsesSimpleEnoughForHeapSRA.
static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load,
- DenseMap<Value*, std::vector<Value*> > &InsertedScalarizedValues,
- std::vector<std::pair<PHINode*, unsigned> > &PHIsToRewrite) {
+ DenseMap<Value *, std::vector<Value *>> &InsertedScalarizedValues,
+ std::vector<std::pair<PHINode *, unsigned> > &PHIsToRewrite) {
for (auto UI = Load->user_begin(), E = Load->user_end(); UI != E;) {
Instruction *User = cast<Instruction>(*UI++);
RewriteHeapSROALoadUser(User, InsertedScalarizedValues, PHIsToRewrite);
@@ -1260,8 +1277,8 @@ static GlobalVariable *PerformHeapAllocS
// Okay, at this point, there are no users of the malloc. Insert N
// new mallocs at the same place as CI, and N globals.
- std::vector<Value*> FieldGlobals;
- std::vector<Value*> FieldMallocs;
+ std::vector<Value *> FieldGlobals;
+ std::vector<Value *> FieldMallocs;
SmallVector<OperandBundleDef, 1> OpBundles;
CI->getOperandBundlesAsDefs(OpBundles);
@@ -1358,10 +1375,10 @@ static GlobalVariable *PerformHeapAllocS
/// As we process loads, if we can't immediately update all uses of the load,
/// keep track of what scalarized loads are inserted for a given load.
- DenseMap<Value*, std::vector<Value*> > InsertedScalarizedValues;
+ DenseMap<Value *, std::vector<Value *>> InsertedScalarizedValues;
InsertedScalarizedValues[GV] = FieldGlobals;
- std::vector<std::pair<PHINode*, unsigned> > PHIsToRewrite;
+ std::vector<std::pair<PHINode *, unsigned>> PHIsToRewrite;
// Okay, the malloc site is completely handled. All of the uses of GV are now
// loads, and all uses of those loads are simple. Rewrite them to use loads
@@ -1407,7 +1424,7 @@ static GlobalVariable *PerformHeapAllocS
}
// Drop all inter-phi links and any loads that made it this far.
- for (DenseMap<Value*, std::vector<Value*> >::iterator
+ for (DenseMap<Value *, std::vector<Value *>>::iterator
I = InsertedScalarizedValues.begin(), E = InsertedScalarizedValues.end();
I != E; ++I) {
if (PHINode *PN = dyn_cast<PHINode>(I->first))
@@ -1417,7 +1434,7 @@ static GlobalVariable *PerformHeapAllocS
}
// Delete all the phis and loads now that inter-references are dead.
- for (DenseMap<Value*, std::vector<Value*> >::iterator
+ for (DenseMap<Value *, std::vector<Value *>>::iterator
I = InsertedScalarizedValues.begin(), E = InsertedScalarizedValues.end();
I != E; ++I) {
if (PHINode *PN = dyn_cast<PHINode>(I->first))
@@ -2275,7 +2292,7 @@ static void setUsedInitializer(GlobalVar
// Type of pointer to the array of pointers.
PointerType *Int8PtrTy = Type::getInt8PtrTy(V.getContext(), 0);
- SmallVector<llvm::Constant *, 8> UsedArray;
+ SmallVector<Constant *, 8> UsedArray;
for (GlobalValue *GV : Init) {
Constant *Cast
= ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, Int8PtrTy);
@@ -2288,14 +2305,15 @@ static void setUsedInitializer(GlobalVar
Module *M = V.getParent();
V.removeFromParent();
GlobalVariable *NV =
- new GlobalVariable(*M, ATy, false, llvm::GlobalValue::AppendingLinkage,
- llvm::ConstantArray::get(ATy, UsedArray), "");
+ new GlobalVariable(*M, ATy, false, GlobalValue::AppendingLinkage,
+ ConstantArray::get(ATy, UsedArray), "");
NV->takeName(&V);
NV->setSection("llvm.metadata");
delete &V;
}
namespace {
+
/// An easy to access representation of llvm.used and llvm.compiler.used.
class LLVMUsed {
SmallPtrSet<GlobalValue *, 8> Used;
@@ -2308,25 +2326,34 @@ public:
UsedV = collectUsedGlobalVariables(M, Used, false);
CompilerUsedV = collectUsedGlobalVariables(M, CompilerUsed, true);
}
- typedef SmallPtrSet<GlobalValue *, 8>::iterator iterator;
- typedef iterator_range<iterator> used_iterator_range;
+
+ using iterator = SmallPtrSet<GlobalValue *, 8>::iterator;
+ using used_iterator_range = iterator_range<iterator>;
+
iterator usedBegin() { return Used.begin(); }
iterator usedEnd() { return Used.end(); }
+
used_iterator_range used() {
return used_iterator_range(usedBegin(), usedEnd());
}
+
iterator compilerUsedBegin() { return CompilerUsed.begin(); }
iterator compilerUsedEnd() { return CompilerUsed.end(); }
+
used_iterator_range compilerUsed() {
return used_iterator_range(compilerUsedBegin(), compilerUsedEnd());
}
+
bool usedCount(GlobalValue *GV) const { return Used.count(GV); }
+
bool compilerUsedCount(GlobalValue *GV) const {
return CompilerUsed.count(GV);
}
+
bool usedErase(GlobalValue *GV) { return Used.erase(GV); }
bool compilerUsedErase(GlobalValue *GV) { return CompilerUsed.erase(GV); }
bool usedInsert(GlobalValue *GV) { return Used.insert(GV).second; }
+
bool compilerUsedInsert(GlobalValue *GV) {
return CompilerUsed.insert(GV).second;
}
@@ -2338,7 +2365,8 @@ public:
setUsedInitializer(*CompilerUsedV, CompilerUsed);
}
};
-}
+
+} // end anonymous namespace
static bool hasUseOtherThanLLVMUsed(GlobalAlias &GA, const LLVMUsed &U) {
if (GA.use_empty()) // No use at all.
@@ -2653,8 +2681,10 @@ PreservedAnalyses GlobalOptPass::run(Mod
}
namespace {
+
struct GlobalOptLegacyPass : public ModulePass {
static char ID; // Pass identification, replacement for typeid
+
GlobalOptLegacyPass() : ModulePass(ID) {
initializeGlobalOptLegacyPassPass(*PassRegistry::getPassRegistry());
}
@@ -2676,9 +2706,11 @@ struct GlobalOptLegacyPass : public Modu
AU.addRequired<DominatorTreeWrapperPass>();
}
};
-}
+
+} // end anonymous namespace
char GlobalOptLegacyPass::ID = 0;
+
INITIALIZE_PASS_BEGIN(GlobalOptLegacyPass, "globalopt",
"Global Variable Optimizer", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
Modified: llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp Tue Oct 10 15:49:55 2017
@@ -15,22 +15,30 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO/GlobalSplit.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/User.h"
#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Transforms/IPO.h"
-
-#include <set>
+#include <cstdint>
+#include <vector>
using namespace llvm;
-namespace {
-
-bool splitGlobal(GlobalVariable &GV) {
+static bool splitGlobal(GlobalVariable &GV) {
// If the address of the global is taken outside of the module, we cannot
// apply this transformation.
if (!GV.hasLocalLinkage())
@@ -130,7 +138,7 @@ bool splitGlobal(GlobalVariable &GV) {
return true;
}
-bool splitGlobals(Module &M) {
+static bool splitGlobals(Module &M) {
// First, see if the module uses either of the llvm.type.test or
// llvm.type.checked.load intrinsics, which indicates that splitting globals
// may be beneficial.
@@ -151,12 +159,16 @@ bool splitGlobals(Module &M) {
return Changed;
}
+namespace {
+
struct GlobalSplit : public ModulePass {
static char ID;
+
GlobalSplit() : ModulePass(ID) {
initializeGlobalSplitPass(*PassRegistry::getPassRegistry());
}
- bool runOnModule(Module &M) {
+
+ bool runOnModule(Module &M) override {
if (skipModule(M))
return false;
@@ -164,11 +176,12 @@ struct GlobalSplit : public ModulePass {
}
};
-}
+} // end anonymous namespace
-INITIALIZE_PASS(GlobalSplit, "globalsplit", "Global splitter", false, false)
char GlobalSplit::ID = 0;
+INITIALIZE_PASS(GlobalSplit, "globalsplit", "Global splitter", false, false)
+
ModulePass *llvm::createGlobalSplitPass() {
return new GlobalSplit;
}
Modified: llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp?rev=315383&r1=315382&r2=315383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp Tue Oct 10 15:49:55 2017
@@ -13,26 +13,54 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO/PartialInlining.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
-#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
+#include "llvm/IR/CallSite.h"
+#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/User.h"
#include "llvm/Pass.h"
+#include "llvm/Support/BlockFrequency.h"
+#include "llvm/Support/BranchProbability.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/CodeExtractor.h"
+#include "llvm/Transforms/Utils/ValueMapper.h"
+#include <algorithm>
+#include <cassert>
+#include <cstdint>
+#include <functional>
+#include <iterator>
+#include <memory>
+#include <tuple>
+#include <vector>
+
using namespace llvm;
#define DEBUG_TYPE "partial-inlining"
@@ -44,6 +72,7 @@ STATISTIC(NumPartialInlined,
static cl::opt<bool>
DisablePartialInlining("disable-partial-inlining", cl::init(false),
cl::Hidden, cl::desc("Disable partial ininling"));
+
// This is an option used by testing:
static cl::opt<bool> SkipCostAnalysis("skip-partial-inlining-cost-analysis",
cl::init(false), cl::ZeroOrMore,
@@ -76,9 +105,8 @@ static cl::opt<unsigned> ExtraOutliningP
namespace {
struct FunctionOutliningInfo {
- FunctionOutliningInfo()
- : Entries(), ReturnBlock(nullptr), NonReturnBlock(nullptr),
- ReturnBlockPreds() {}
+ FunctionOutliningInfo() = default;
+
// Returns the number of blocks to be inlined including all blocks
// in Entries and one return block.
unsigned GetNumInlinedBlocks() const { return Entries.size() + 1; }
@@ -86,10 +114,13 @@ struct FunctionOutliningInfo {
// A set of blocks including the function entry that guard
// the region to be outlined.
SmallVector<BasicBlock *, 4> Entries;
+
// The return block that is not included in the outlined region.
- BasicBlock *ReturnBlock;
+ BasicBlock *ReturnBlock = nullptr;
+
// The dominating block of the region to be outlined.
- BasicBlock *NonReturnBlock;
+ BasicBlock *NonReturnBlock = nullptr;
+
// The set of blocks in Entries that that are predecessors to ReturnBlock
SmallVector<BasicBlock *, 4> ReturnBlockPreds;
};
@@ -101,6 +132,7 @@ struct PartialInlinerImpl {
Optional<function_ref<BlockFrequencyInfo &(Function &)>> GBFI,
ProfileSummaryInfo *ProfSI)
: GetAssumptionCache(GetAC), GetTTI(GTTI), GetBFI(GBFI), PSI(ProfSI) {}
+
bool run(Module &M);
Function *unswitchFunction(Function *F);
@@ -197,17 +229,18 @@ private:
// - The second value is the estimated size of the new call sequence in
// basic block Cloner.OutliningCallBB;
std::tuple<int, int> computeOutliningCosts(FunctionCloner &Cloner);
+
// Compute the 'InlineCost' of block BB. InlineCost is a proxy used to
// approximate both the size and runtime cost (Note that in the current
// inline cost analysis, there is no clear distinction there either).
static int computeBBInlineCost(BasicBlock *BB);
std::unique_ptr<FunctionOutliningInfo> computeOutliningInfo(Function *F);
-
};
struct PartialInlinerLegacyPass : public ModulePass {
static char ID; // Pass identification, replacement for typeid
+
PartialInlinerLegacyPass() : ModulePass(ID) {
initializePartialInlinerLegacyPassPass(*PassRegistry::getPassRegistry());
}
@@ -217,6 +250,7 @@ struct PartialInlinerLegacyPass : public
AU.addRequired<ProfileSummaryInfoWrapperPass>();
AU.addRequired<TargetTransformInfoWrapperPass>();
}
+
bool runOnModule(Module &M) override {
if (skipModule(M))
return false;
@@ -240,7 +274,8 @@ struct PartialInlinerLegacyPass : public
return PartialInlinerImpl(&GetAssumptionCache, &GetTTI, None, PSI).run(M);
}
};
-}
+
+} // end anonymous namespace
std::unique_ptr<FunctionOutliningInfo>
PartialInlinerImpl::computeOutliningInfo(Function *F) {
@@ -320,7 +355,6 @@ PartialInlinerImpl::computeOutliningInfo
OutliningInfo->Entries.push_back(CurrEntry);
CurrEntry = OtherSucc;
-
} while (true);
if (!CandidateFound)
@@ -414,7 +448,6 @@ static bool hasProfileData(Function *F,
BranchProbability
PartialInlinerImpl::getOutliningCallBBRelativeFreq(FunctionCloner &Cloner) {
-
auto EntryFreq =
Cloner.ClonedFuncBFI->getBlockFreq(&Cloner.ClonedFunc->getEntryBlock());
auto OutliningCallFreq =
@@ -451,8 +484,8 @@ PartialInlinerImpl::getOutliningCallBBRe
bool PartialInlinerImpl::shouldPartialInline(
CallSite CS, FunctionCloner &Cloner, BlockFrequency WeightedOutliningRcost,
OptimizationRemarkEmitter &ORE) {
-
using namespace ore;
+
if (SkipCostAnalysis)
return true;
@@ -567,7 +600,6 @@ int PartialInlinerImpl::computeBBInlineC
std::tuple<int, int>
PartialInlinerImpl::computeOutliningCosts(FunctionCloner &Cloner) {
-
// Now compute the cost of the call sequence to the outlined function
// 'OutlinedFunction' in BB 'OutliningCallBB':
int OutliningFuncCallCost = computeBBInlineCost(Cloner.OutliningCallBB);
@@ -661,7 +693,6 @@ PartialInlinerImpl::FunctionCloner::Func
}
void PartialInlinerImpl::FunctionCloner::NormalizeReturnBlock() {
-
auto getFirstPHI = [](BasicBlock *BB) {
BasicBlock::iterator I = BB->begin();
PHINode *FirstPhi = nullptr;
@@ -798,7 +829,6 @@ PartialInlinerImpl::FunctionCloner::~Fun
}
Function *PartialInlinerImpl::unswitchFunction(Function *F) {
-
if (F->hasAddressTaken())
return nullptr;
@@ -955,6 +985,7 @@ bool PartialInlinerImpl::run(Module &M)
}
char PartialInlinerLegacyPass::ID = 0;
+
INITIALIZE_PASS_BEGIN(PartialInlinerLegacyPass, "partial-inliner",
"Partial Inliner", false, false)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
More information about the llvm-commits
mailing list