From 1c2bd1e9f34eab5e79dc74bf4959859fa72ec7f6 Mon Sep 17 00:00:00 2001 From: Marcin Koscielnicki Date: Mon, 21 Nov 2016 11:57:19 +0000 Subject: [InstrProfiling] Mark __llvm_profile_instrument_target last parameter as i32 zeroext if appropriate. On some architectures (s390x, ppc64, sparc64, mips), C-level int is passed as i32 signext instead of plain i32. Likewise, unsigned int may be passed as i32, i32 signext, or i32 zeroext depending on the platform. Mark __llvm_profile_instrument_target properly (its last parameter is unsigned int). This (together with the clang change) makes compiler-rt profile testsuite pass on s390x. Differential Revision: http://reviews.llvm.org/D21736 llvm-svn: 287534 --- .../Transforms/Instrumentation/InstrProfiling.cpp | 41 ++++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 8b3e4fc9fe1..8da3e31200f 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -15,6 +15,7 @@ #include "llvm/Transforms/InstrProfiling.h" #include "llvm/ADT/Triple.h" +#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" @@ -57,26 +58,34 @@ public: return "Frontend instrumentation-based coverage lowering"; } - bool runOnModule(Module &M) override { return InstrProf.run(M); } + bool runOnModule(Module &M) override { + return InstrProf.run(M, getAnalysis().getTLI()); + } void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); + AU.addRequired(); } }; } // anonymous namespace PreservedAnalyses InstrProfiling::run(Module &M, ModuleAnalysisManager &AM) { - if (!run(M)) + auto &TLI = AM.getResult(M); + if (!run(M, TLI)) return PreservedAnalyses::all(); return PreservedAnalyses::none(); } char InstrProfilingLegacyPass::ID = 0; -INITIALIZE_PASS(InstrProfilingLegacyPass, "instrprof", - "Frontend instrumentation-based coverage lowering.", false, - false) +INITIALIZE_PASS_BEGIN( + InstrProfilingLegacyPass, "instrprof", + "Frontend instrumentation-based coverage lowering.", false, false) +INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) +INITIALIZE_PASS_END( + InstrProfilingLegacyPass, "instrprof", + "Frontend instrumentation-based coverage lowering.", false, false) ModulePass * llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options) { @@ -114,10 +123,11 @@ static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) { return dyn_cast(Instr); } -bool InstrProfiling::run(Module &M) { +bool InstrProfiling::run(Module &M, const TargetLibraryInfo &TLI) { bool MadeChange = false; this->M = &M; + this->TLI = &TLI; NamesVar = nullptr; NamesSize = 0; ProfileDataMap.clear(); @@ -173,7 +183,8 @@ bool InstrProfiling::run(Module &M) { return true; } -static Constant *getOrInsertValueProfilingCall(Module &M) { +static Constant *getOrInsertValueProfilingCall(Module &M, + const TargetLibraryInfo &TLI) { LLVMContext &Ctx = M.getContext(); auto *ReturnTy = Type::getVoidTy(M.getContext()); Type *ParamTypes[] = { @@ -182,8 +193,13 @@ static Constant *getOrInsertValueProfilingCall(Module &M) { }; auto *ValueProfilingCallTy = FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false); - return M.getOrInsertFunction(getInstrProfValueProfFuncName(), - ValueProfilingCallTy); + Constant *Res = M.getOrInsertFunction(getInstrProfValueProfFuncName(), + ValueProfilingCallTy); + if (Function *FunRes = dyn_cast(Res)) { + if (auto AK = TLI.getExtAttrForI32Param(false)) + FunRes->addAttribute(3, AK); + } + return Res; } void InstrProfiling::computeNumValueSiteCounts(InstrProfValueProfileInst *Ind) { @@ -217,8 +233,11 @@ void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) { Value *Args[3] = {Ind->getTargetValue(), Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()), Builder.getInt32(Index)}; - Ind->replaceAllUsesWith( - Builder.CreateCall(getOrInsertValueProfilingCall(*M), Args)); + CallInst *Call = Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI), + Args); + if (auto AK = TLI->getExtAttrForI32Param(false)) + Call->addAttribute(3, AK); + Ind->replaceAllUsesWith(Call); Ind->eraseFromParent(); } -- cgit v1.2.3