35#define DEBUG_TYPE "lowerintrinsics"
40#include <llvm/Transforms/Scalar.h>
41#include <llvm/Transforms/Utils/UnifyFunctionExitNodes.h>
42#include <tce_config.h>
43#include <llvm/IR/Module.h>
44#include <llvm/IR/Instructions.h>
45#include <llvm/IR/Constants.h>
46#include <llvm/IR/Intrinsics.h>
47#include <llvm/IR/DerivedTypes.h>
48#include <llvm/IR/LLVMContext.h>
49#include <llvm/Support/Compiler.h>
50#include <llvm/IR/Function.h>
52#include <llvm/Passes/PassBuilder.h>
53#include <llvm/Passes/PassPlugin.h>
54#include <llvm/CodeGen/IntrinsicLowering.h>
55#include <tce_config.h>
59#include <llvm/IR/DataLayout.h>
70 PreservedAnalyses
run(Function &F, FunctionAnalysisManager &AM);
88 FunctionAnalysisManager &AM) {
90 Module *parentModule = F.getParent();
92 for (BasicBlock &BB : F) {
96 return PreservedAnalyses::all();
104 replace_.insert(Intrinsic::get_rounding);
111 replace_.insert(Intrinsic::memmove);
138 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
139 CallInst* ci = dyn_cast<CallInst>(&(*I));
140 if (ci != NULL && ci->arg_size() != 0) {
141 Function* callee = ci->getCalledFunction();
142 if (callee != NULL && callee->isIntrinsic() &&
144 if (callee->getIntrinsicID() == Intrinsic::get_rounding) {
148 I->replaceAllUsesWith(
150 Type::getInt32Ty(BB.getContext()), 0,
true));
151 I->eraseFromParent();
169 return {LLVM_PLUGIN_API_VERSION,
"LowerIntrinsics", LLVM_VERSION_STRING,
170 [](PassBuilder &PB) {
171 PB.registerVectorizerStartEPCallback(
172 [](llvm::FunctionPassManager &PM, OptimizationLevel Level) {
175 PB.registerPipelineParsingCallback(
176 [](StringRef Name, llvm::FunctionPassManager &PM,
177 ArrayRef<llvm::PassBuilder::PipelineElement>) {
178 if (Name ==
"lowerintrinsic") {
187#ifndef LLVM_LOWERINTRINSICS_LINK_INTO_TOOLS
188extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
#define assert(condition)
#define IGNORE_COMPILER_WARNING(X)
#define POP_COMPILER_DIAGS
llvm::DataLayout TargetData
POP_COMPILER_DIAGS typedef llvm::DataLayout TargetData
llvm::PassPluginLibraryInfo getLowerIntrinsicsPluginInfo()
LLVM_ATTRIBUTE_WEAK::llvm::PassPluginLibraryInfo llvmGetPassPluginInfo()
bool doInitialization(Module &M)
bool doFinalization(Module &M)
bool runOnBasicBlock(BasicBlock &BB)
IntrinsicLowering * iLowering_
std::set< unsigned > replace_
List of intrinsics to replace.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)