2015-12-27 16:41:34 +08:00
|
|
|
//===- InferFunctionAttrs.cpp - Infer implicit function attributes --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
|
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2016-01-05 06:49:23 +08:00
|
|
|
#include "llvm/Analysis/MemoryBuiltins.h"
|
2015-12-27 16:41:34 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-04-28 03:04:40 +08:00
|
|
|
#include "llvm/Transforms/Utils/BuildLibCalls.h"
|
2015-12-27 16:41:34 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "inferattrs"
|
|
|
|
|
|
|
|
static bool inferAllPrototypeAttributes(Module &M,
|
|
|
|
const TargetLibraryInfo &TLI) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
for (Function &F : M.functions())
|
2016-04-28 03:04:40 +08:00
|
|
|
// We only infer things using the prototype and the name; we don't need
|
|
|
|
// definitions.
|
|
|
|
if (F.isDeclaration() && !F.hasFnAttribute((Attribute::OptimizeNone)))
|
|
|
|
Changed |= inferLibFuncAttributes(F, TLI);
|
2015-12-27 16:41:34 +08:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses InferFunctionAttrsPass::run(Module &M,
|
2016-08-09 08:28:38 +08:00
|
|
|
ModuleAnalysisManager &AM) {
|
2016-03-11 19:05:24 +08:00
|
|
|
auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
|
2015-12-27 16:41:34 +08:00
|
|
|
|
|
|
|
if (!inferAllPrototypeAttributes(M, TLI))
|
|
|
|
// If we didn't infer anything, preserve all analyses.
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
|
|
|
|
// Otherwise, we may have changed fundamental function attributes, so clear
|
|
|
|
// out all the passes.
|
|
|
|
return PreservedAnalyses::none();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct InferFunctionAttrsLegacyPass : public ModulePass {
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
InferFunctionAttrsLegacyPass() : ModulePass(ID) {
|
|
|
|
initializeInferFunctionAttrsLegacyPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnModule(Module &M) override {
|
2016-04-23 06:06:11 +08:00
|
|
|
if (skipModule(M))
|
|
|
|
return false;
|
|
|
|
|
2015-12-27 16:41:34 +08:00
|
|
|
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
|
|
|
return inferAllPrototypeAttributes(M, TLI);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
char InferFunctionAttrsLegacyPass::ID = 0;
|
|
|
|
INITIALIZE_PASS_BEGIN(InferFunctionAttrsLegacyPass, "inferattrs",
|
|
|
|
"Infer set function attributes", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_END(InferFunctionAttrsLegacyPass, "inferattrs",
|
|
|
|
"Infer set function attributes", false, false)
|
|
|
|
|
|
|
|
Pass *llvm::createInferFunctionAttrsLegacyPass() {
|
|
|
|
return new InferFunctionAttrsLegacyPass();
|
|
|
|
}
|