Skip to content

Commit

Permalink
[Transforms] Fix some Clang-tidy modernize and Include What You Use w…
Browse files Browse the repository at this point in the history
…arnings; other minor fixes (NFC).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316187 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
EugeneZelenko committed Oct 19, 2017
1 parent fb5a67b commit ab16d0a
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 127 deletions.
5 changes: 3 additions & 2 deletions include/llvm/Transforms/IPO/ArgumentPromotion.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/IR/PassManager.h"

namespace llvm {

Expand All @@ -26,6 +27,6 @@ class ArgumentPromotionPass : public PassInfoMixin<ArgumentPromotionPass> {
LazyCallGraph &CG, CGSCCUpdateResult &UR);
};

}
} // end namespace llvm

#endif
#endif // LLVM_TRANSFORMS_IPO_ARGUMENTPROMOTION_H
10 changes: 8 additions & 2 deletions include/llvm/Transforms/IPO/FunctionAttrs.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//===-- FunctionAttrs.h - Compute function attrs --------------------------===//
//===- FunctionAttrs.h - Compute function attributes ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// \file
/// Provides passes for computing function attributes based on interprocedural
/// analyses.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
Expand All @@ -21,6 +23,9 @@
namespace llvm {

class AAResults;
class Function;
class Module;
class Pass;

/// The three kinds of memory access relevant to 'readonly' and
/// 'readnone' attributes.
Expand Down Expand Up @@ -66,6 +71,7 @@ class ReversePostOrderFunctionAttrsPass
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
}

} // end namespace llvm

#endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
17 changes: 9 additions & 8 deletions include/llvm/Transforms/IPO/Inliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h"
#include <utility>

namespace llvm {

class AssumptionCacheTracker;
class CallSite;
class DataLayout;
class InlineCost;
class OptimizationRemarkEmitter;
class CallGraph;
class ProfileSummaryInfo;

/// This class contains all of the helper code which is used to perform the
Expand All @@ -44,6 +44,7 @@ struct LegacyInlinerBase : public CallGraphSCCPass {
bool runOnSCC(CallGraphSCC &SCC) override;

using llvm::Pass::doFinalization;

/// Remove now-dead linkonce functions at the end of processing to avoid
/// breaking the SCC traversal.
bool doFinalization(CallGraph &CG) override;
Expand All @@ -69,7 +70,7 @@ struct LegacyInlinerBase : public CallGraphSCCPass {

private:
// Insert @llvm.lifetime intrinsics.
bool InsertLifetime;
bool InsertLifetime = true;

protected:
AssumptionCacheTracker *ACT;
Expand Down Expand Up @@ -103,6 +104,6 @@ class InlinerPass : public PassInfoMixin<InlinerPass> {
InlineParams Params;
};

} // End llvm namespace
} // end namespace llvm

#endif
#endif // LLVM_TRANSFORMS_IPO_INLINER_H
2 changes: 1 addition & 1 deletion include/llvm/Transforms/IPO/LowerTypeTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define LLVM_TRANSFORMS_IPO_LOWERTYPETESTS_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include <cstdint>
#include <cstring>
Expand All @@ -26,6 +25,7 @@

namespace llvm {

class Module;
class raw_ostream;

namespace lowertypetests {
Expand Down
68 changes: 49 additions & 19 deletions lib/Transforms/IPO/ArgumentPromotion.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- ArgumentPromotion.cpp - Promote by-reference arguments ------------===//
//===- ArgumentPromotion.cpp - Promote by-reference arguments -------------===//
//
// The LLVM Compiler Infrastructure
//
Expand Down Expand Up @@ -31,30 +31,59 @@

#include "llvm/Transforms/IPO/ArgumentPromotion.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.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/LLVMContext.h"
#include "llvm/IR/Metadata.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 <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace llvm;

#define DEBUG_TYPE "argpromotion"
Expand All @@ -65,7 +94,7 @@ STATISTIC(NumByValArgsPromoted, "Number of byval arguments promoted");
STATISTIC(NumArgumentsDead, "Number of dead pointer args eliminated");

/// A vector used to hold the indices of a single GEP instruction
typedef std::vector<uint64_t> IndicesVector;
using IndicesVector = std::vector<uint64_t>;

/// DoPromotion - This method actually performs the promotion of the specified
/// arguments, and returns the new function. At this point, we know that it's
Expand All @@ -75,21 +104,19 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
SmallPtrSetImpl<Argument *> &ByValArgsToTransform,
Optional<function_ref<void(CallSite OldCS, CallSite NewCS)>>
ReplaceCallSite) {

// Start by computing a new prototype for the function, which is the same as
// the old function, but has modified arguments.
FunctionType *FTy = F->getFunctionType();
std::vector<Type *> Params;

typedef std::set<std::pair<Type *, IndicesVector>> ScalarizeTable;
using ScalarizeTable = std::set<std::pair<Type *, IndicesVector>>;

// ScalarizedElements - If we are promoting a pointer that has elements
// accessed out of it, keep track of which elements are accessed so that we
// can add one argument for each.
//
// Arguments that are directly loaded will have a zero element value here, to
// handle cases where there are both a direct load and GEP accesses.
//
std::map<Argument *, ScalarizeTable> ScalarizedElements;

// OriginalLoads - Keep track of a representative load instruction from the
Expand Down Expand Up @@ -335,7 +362,6 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,

// Loop over the argument list, transferring uses of the old arguments over to
// the new arguments, also transferring over the names as well.
//
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(),
I2 = NF->arg_begin();
I != E; ++I) {
Expand Down Expand Up @@ -537,7 +563,7 @@ static void markIndicesSafe(const IndicesVector &ToMark,
/// arguments passed in.
static bool isSafeToPromoteArgument(Argument *Arg, bool isByValOrInAlloca,
AAResults &AAR, unsigned MaxElements) {
typedef std::set<IndicesVector> GEPIndicesSet;
using GEPIndicesSet = std::set<IndicesVector>;

// Quick exit for unused arguments
if (Arg->use_empty())
Expand Down Expand Up @@ -714,7 +740,6 @@ static bool isSafeToPromoteArgument(Argument *Arg, bool isByValOrInAlloca,

/// \brief Checks if a type could have padding bytes.
static bool isDenselyPacked(Type *type, const DataLayout &DL) {

// There is no size information, so be conservative.
if (!type->isSized())
return false;
Expand Down Expand Up @@ -749,7 +774,6 @@ static bool isDenselyPacked(Type *type, const DataLayout &DL) {

/// \brief Checks if the padding bytes of an argument could be accessed.
static bool canPaddingBeAccessed(Argument *arg) {

assert(arg->hasByValAttr());

// Track all the pointers to the argument to make sure they are not captured.
Expand Down Expand Up @@ -788,7 +812,6 @@ static bool canPaddingBeAccessed(Argument *arg) {
/// are any promotable arguments and if it is safe to promote the function (for
/// example, all callers are direct). If safe to promote some arguments, it
/// calls the DoPromotion method.
///
static Function *
promoteArguments(Function *F, function_ref<AAResults &(Function &F)> AARGetter,
unsigned MaxElements,
Expand Down Expand Up @@ -964,9 +987,17 @@ PreservedAnalyses ArgumentPromotionPass::run(LazyCallGraph::SCC &C,
}

namespace {

/// ArgPromotion - The 'by reference' to 'by value' argument promotion pass.
///
struct ArgPromotion : public CallGraphSCCPass {
// Pass identification, replacement for typeid
static char ID;

explicit ArgPromotion(unsigned MaxElements = 3)
: CallGraphSCCPass(ID), MaxElements(MaxElements) {
initializeArgPromotionPass(*PassRegistry::getPassRegistry());
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<TargetLibraryInfoWrapperPass>();
Expand All @@ -975,21 +1006,20 @@ struct ArgPromotion : public CallGraphSCCPass {
}

bool runOnSCC(CallGraphSCC &SCC) override;
static char ID; // Pass identification, replacement for typeid
explicit ArgPromotion(unsigned MaxElements = 3)
: CallGraphSCCPass(ID), MaxElements(MaxElements) {
initializeArgPromotionPass(*PassRegistry::getPassRegistry());
}

private:
using llvm::Pass::doInitialization;

bool doInitialization(CallGraph &CG) override;

/// The maximum number of elements to expand, or 0 for unlimited.
unsigned MaxElements;
};
}

} // end anonymous namespace

char ArgPromotion::ID = 0;

INITIALIZE_PASS_BEGIN(ArgPromotion, "argpromotion",
"Promote 'by reference' arguments to scalars", false,
false)
Expand Down
Loading

0 comments on commit ab16d0a

Please sign in to comment.