Skip to content

Commit

Permalink
Merge from 'main' to 'sycl-web' (#6)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/utils/TableGen/ClangProgModelBuiltinEmitter.cpp
  • Loading branch information
abhinavgaba committed Jun 11, 2021
2 parents 1ceab64 + ca964b4 commit 5339876
Show file tree
Hide file tree
Showing 26 changed files with 1,278 additions and 89 deletions.
5 changes: 2 additions & 3 deletions clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// RUN: cp -r %S/Inputs/remarks %t
// RUN: cp %s %t/t.cpp

// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-module-import' t.cpp -- \
// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-module-import' %t/t.cpp -- \
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
// RUN: -fsyntax-only \
// RUN: -I%S/Inputs/remarks \
// RUN: -working-directory=%t \
// RUN: -Rmodule-build -Rmodule-import t.cpp 2>&1 |\
// RUN: -Rmodule-build -Rmodule-import 2>&1 |\
// RUN: FileCheck %s -implicit-check-not "remark:"

#include "A.h"
// CHECK: remark: importing module 'A' from {{.*}} [clang-diagnostic-module-import]

58 changes: 31 additions & 27 deletions clang/utils/TableGen/ClangProgModelBuiltinEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@
//
//===----------------------------------------------------------------------===//
//
// These backends consume the definitions of builtin functions in
// clang/lib/Sema/*Builtins.td and produce builtin handling code for
// inclusion in SemaLookup.cpp, or a test file that calls all declared builtins.
//
//===----------------------------------------------------------------------===//

#include "TableGenBackends.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/StringMatcher.h"
#include "llvm/TableGen/TableGenBackend.h"

using namespace llvm;

namespace {

// A list of signatures that are shared by one or more builtin functions.
struct BuiltinTableEntries {
SmallVector<StringRef, 4> Names;
std::vector<std::pair<const Record *, unsigned>> Signatures;
};

// This tablegen backend emits code for checking whether a function is a
// builtin function of a programming model. If so, all overloads of this
// function are added to the LookupResult. The generated include file is
Expand Down Expand Up @@ -53,33 +84,6 @@
// One ProgModelTypeStruct can represent multiple types, primarily when using
// GenTypes.
//
//===----------------------------------------------------------------------===//

#include "TableGenBackends.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/StringMatcher.h"
#include "llvm/TableGen/TableGenBackend.h"

using namespace llvm;

namespace {

// A list of signatures that are shared by one or more builtin functions.
struct BuiltinTableEntries {
SmallVector<StringRef, 4> Names;
std::vector<std::pair<const Record *, unsigned>> Signatures;
};

class BuiltinNameEmitter {
public:
BuiltinNameEmitter(RecordKeeper &Records, raw_ostream &OS,
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/builtins/clear_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void __clear_cache(void *start, void *end) {
addr += icache_line_size)
__asm __volatile("ic ivau, %0" ::"r"(addr));
}
__asm __volatile("dsb ish");
__asm __volatile("isb sy");
#elif defined(__powerpc64__)
const size_t line_size = 32;
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void initializeForceFunctionAttrsLegacyPassPass(PassRegistry&);
void initializeForwardControlFlowIntegrityPass(PassRegistry&);
void initializeFuncletLayoutPass(PassRegistry&);
void initializeFunctionImportLegacyPassPass(PassRegistry&);
void initializeFunctionSpecializationLegacyPassPass(PassRegistry &);
void initializeGCMachineCodeAnalysisPass(PassRegistry&);
void initializeGCModuleInfoPass(PassRegistry&);
void initializeGCOVProfilerLegacyPassPass(PassRegistry&);
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/LinkAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ namespace {
(void) llvm::createInjectTLIMappingsLegacyPass();
(void) llvm::createUnifyLoopExitsPass();
(void) llvm::createFixIrreduciblePass();
(void)llvm::createFunctionSpecializationPass();

(void)new llvm::IntervalPartition();
(void)new llvm::ScalarEvolutionWrapperPass();
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/Transforms/IPO.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ Pass *createOpenMPOptCGSCCLegacyPass();
///
ModulePass *createIPSCCPPass();

//===----------------------------------------------------------------------===//
/// createFunctionSpecializationPass - This pass propagates constants from call
/// sites to the specialized version of the callee function.
ModulePass *createFunctionSpecializationPass();

//===----------------------------------------------------------------------===//
//
/// createLoopExtractorPass - This pass extracts all natural loops from the
Expand Down
8 changes: 8 additions & 0 deletions llvm/include/llvm/Transforms/IPO/SCCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class IPSCCPPass : public PassInfoMixin<IPSCCPPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

/// Pass to perform interprocedural constant propagation by specializing
/// functions
class FunctionSpecializationPass
: public PassInfoMixin<FunctionSpecializationPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

} // end namespace llvm

#endif // LLVM_TRANSFORMS_IPO_SCCP_H
8 changes: 8 additions & 0 deletions llvm/include/llvm/Transforms/Scalar/SCCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
Expand All @@ -42,6 +43,13 @@ class SCCPPass : public PassInfoMixin<SCCPPass> {
bool runIPSCCP(Module &M, const DataLayout &DL,
std::function<const TargetLibraryInfo &(Function &)> GetTLI,
function_ref<AnalysisResultsForFn(Function &)> getAnalysis);

bool runFunctionSpecialization(
Module &M, const DataLayout &DL,
std::function<TargetLibraryInfo &(Function &)> GetTLI,
std::function<TargetTransformInfo &(Function &)> GetTTI,
std::function<AssumptionCache &(Function &)> GetAC,
function_ref<AnalysisResultsForFn(Function &)> GetAnalysis);
} // end namespace llvm

#endif // LLVM_TRANSFORMS_SCALAR_SCCP_H
17 changes: 17 additions & 0 deletions llvm/include/llvm/Transforms/Utils/SCCPSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ class SCCPSolver {
/// Helper to return a Constant if \p LV is either a constant or a constant
/// range with a single element.
Constant *getConstant(const ValueLatticeElement &LV) const;

/// Return a reference to the set of argument tracked functions.
SmallPtrSetImpl<Function *> &getArgumentTrackedFunctions();

/// Mark argument \p A constant with value \p C in a new function
/// specialization. The argument's parent function is a specialization of the
/// original function \p F. All other arguments of the specialization inherit
/// the lattice state of their corresponding values in the original function.
void markArgInFuncSpecialization(Function *F, Argument *A, Constant *C);

/// Mark all of the blocks in function \p F non-executable. Clients can used
/// this method to erase a function from the module (e.g., if it has been
/// completely specialized and is no longer needed).
void markFunctionUnreachable(Function *F);

void visit(Instruction *I);
void visitCall(CallInst &I);
};

} // namespace llvm
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
namespace llvm {
extern cl::opt<unsigned> MaxDevirtIterations;
extern cl::opt<bool> EnableConstraintElimination;
extern cl::opt<bool> EnableFunctionSpecialization;
extern cl::opt<bool> EnableGVNHoist;
extern cl::opt<bool> EnableGVNSink;
extern cl::opt<bool> EnableHotColdSplit;
Expand Down Expand Up @@ -1134,6 +1135,10 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
for (auto &C : PipelineEarlySimplificationEPCallbacks)
C(MPM, Level);

// Specialize functions with IPSCCP.
if (EnableFunctionSpecialization)
MPM.addPass(FunctionSpecializationPass());

// Interprocedural constant propagation now that basic cleanup has occurred
// and prior to optimizing globals.
// FIXME: This position in the pipeline hasn't been carefully considered in
Expand Down Expand Up @@ -1701,6 +1706,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
// produce the same result as if we only do promotion here.
MPM.addPass(PGOIndirectCallPromotion(
true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));

if (EnableFunctionSpecialization)
MPM.addPass(FunctionSpecializationPass());
// Propagate constants at call sites into the functions they call. This
// opens opportunities for globalopt (and inlining) by substituting function
// pointers passed as arguments to direct uses of functions.
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
MODULE_PASS("extract-blocks", BlockExtractorPass())
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
MODULE_PASS("function-import", FunctionImportPass())
MODULE_PASS("function-specialization", FunctionSpecializationPass())
MODULE_PASS("globaldce", GlobalDCEPass())
MODULE_PASS("globalopt", GlobalOptPass())
MODULE_PASS("globalsplit", GlobalSplitPass())
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/IPO/IPO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
initializeDAHPass(Registry);
initializeDAESYCLPass(Registry);
initializeForceFunctionAttrsLegacyPassPass(Registry);
initializeFunctionSpecializationLegacyPassPass(Registry);
initializeGlobalDCELegacyPassPass(Registry);
initializeGlobalOptLegacyPassPass(Registry);
initializeGlobalSplitPass(Registry);
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Target/CGPassBuilderOption.h"
Expand All @@ -43,6 +44,7 @@
#include "llvm/Transforms/Scalar/InstSimplifyPass.h"
#include "llvm/Transforms/Scalar/LICM.h"
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
#include "llvm/Transforms/Scalar/SCCP.h"
#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Vectorize.h"
Expand Down Expand Up @@ -170,6 +172,10 @@ cl::opt<bool> EnableConstraintElimination(
cl::desc(
"Enable pass to eliminate conditions based on linear constraints."));

cl::opt<bool> EnableFunctionSpecialization(
"enable-function-specialization", cl::init(false), cl::Hidden,
cl::desc("Enable Function Specialization pass"));

cl::opt<AttributorRunOption> AttributorRun(
"attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE),
cl::desc("Enable the attributor inter-procedural deduction pass."),
Expand Down Expand Up @@ -748,6 +754,10 @@ void PassManagerBuilder::populateModulePassManager(
if (OptLevel > 2)
MPM.add(createCallSiteSplittingPass());

// Propage constant function arguments by specializing the functions.
if (OptLevel > 2 && EnableFunctionSpecialization)
MPM.add(createFunctionSpecializationPass());

MPM.add(createIPSCCPPass()); // IP SCCP
MPM.add(createCalledValuePropagationPass());

Expand Down Expand Up @@ -1005,6 +1015,10 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
PM.add(
createPGOIndirectCallPromotionLegacyPass(true, !PGOSampleUse.empty()));

// Propage constant function arguments by specializing the functions.
if (EnableFunctionSpecialization)
PM.add(createFunctionSpecializationPass());

// Propagate constants at call sites into the functions they call. This
// opens opportunities for globalopt (and inlining) by substituting function
// pointers passed as arguments to direct uses of functions.
Expand Down
90 changes: 90 additions & 0 deletions llvm/lib/Transforms/IPO/SCCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Scalar/SCCP.h"
Expand Down Expand Up @@ -103,3 +104,92 @@ INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",

// createIPSCCPPass - This is the public interface to this file.
ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }

PreservedAnalyses FunctionSpecializationPass::run(Module &M,
ModuleAnalysisManager &AM) {
const DataLayout &DL = M.getDataLayout();
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
return FAM.getResult<TargetLibraryAnalysis>(F);
};
auto GetTTI = [&FAM](Function &F) -> TargetTransformInfo & {
return FAM.getResult<TargetIRAnalysis>(F);
};
auto GetAC = [&FAM](Function &F) -> AssumptionCache & {
return FAM.getResult<AssumptionAnalysis>(F);
};
auto GetAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
return {std::make_unique<PredicateInfo>(
F, DT, FAM.getResult<AssumptionAnalysis>(F)),
&DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
};

if (!runFunctionSpecialization(M, DL, GetTLI, GetTTI, GetAC, GetAnalysis))
return PreservedAnalyses::all();

PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
PA.preserve<PostDominatorTreeAnalysis>();
PA.preserve<FunctionAnalysisManagerModuleProxy>();
return PA;
}

struct FunctionSpecializationLegacyPass : public ModulePass {
static char ID; // Pass identification, replacement for typeid
FunctionSpecializationLegacyPass() : ModulePass(ID) {}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.addRequired<TargetTransformInfoWrapperPass>();
}

virtual bool runOnModule(Module &M) override {
if (skipModule(M))
return false;

const DataLayout &DL = M.getDataLayout();
auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
};
auto GetTTI = [this](Function &F) -> TargetTransformInfo & {
return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
};
auto GetAC = [this](Function &F) -> AssumptionCache & {
return this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
};

auto GetAnalysis = [this](Function &F) -> AnalysisResultsForFn {
DominatorTree &DT =
this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
return {
std::make_unique<PredicateInfo>(
F, DT,
this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F)),
nullptr, // We cannot preserve the DT or PDT with the legacy pass
nullptr}; // manager, so set them to nullptr.
};
return runFunctionSpecialization(M, DL, GetTLI, GetTTI, GetAC, GetAnalysis);
}
};

char FunctionSpecializationLegacyPass::ID = 0;

INITIALIZE_PASS_BEGIN(
FunctionSpecializationLegacyPass, "function-specialization",
"Propagate constant arguments by specializing the function", false, false)

INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_END(FunctionSpecializationLegacyPass, "function-specialization",
"Propagate constant arguments by specializing the function",
false, false)

ModulePass *llvm::createFunctionSpecializationPass() {
return new FunctionSpecializationLegacyPass();
}
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Scalar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_llvm_component_library(LLVMScalarOpts
EarlyCSE.cpp
FlattenCFGPass.cpp
Float2Int.cpp
FunctionSpecialization.cpp
GuardWidening.cpp
GVN.cpp
GVNHoist.cpp
Expand Down
Loading

0 comments on commit 5339876

Please sign in to comment.