llvm.org GIT mirror llvm / f14d6e1
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287534 91177308-0d34-0410-b5e6-96231b3b80d8 Marcin Koscielnicki 4 years ago
3 changed file(s) with 49 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
2020
2121 namespace llvm {
2222
23 class TargetLibraryInfo;
24
2325 /// Instrumentation based profiling lowering pass. This pass lowers
2426 /// the profile instrumented code generated by FE or the IR based
2527 /// instrumentation pass.
2931 InstrProfiling(const InstrProfOptions &Options) : Options(Options) {}
3032
3133 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
32 bool run(Module &M);
34 bool run(Module &M, const TargetLibraryInfo &TLI);
3335
3436 private:
3537 InstrProfOptions Options;
3638 Module *M;
39 const TargetLibraryInfo *TLI;
3740 struct PerFunctionProfileData {
3841 uint32_t NumValueSites[IPVK_Last + 1];
3942 GlobalVariable *RegionCounters;
1414
1515 #include "llvm/Transforms/InstrProfiling.h"
1616 #include "llvm/ADT/Triple.h"
17 #include "llvm/Analysis/TargetLibraryInfo.h"
1718 #include "llvm/IR/IRBuilder.h"
1819 #include "llvm/IR/IntrinsicInst.h"
1920 #include "llvm/IR/Module.h"
5657 return "Frontend instrumentation-based coverage lowering";
5758 }
5859
59 bool runOnModule(Module &M) override { return InstrProf.run(M); }
60 bool runOnModule(Module &M) override {
61 return InstrProf.run(M, getAnalysis().getTLI());
62 }
6063
6164 void getAnalysisUsage(AnalysisUsage &AU) const override {
6265 AU.setPreservesCFG();
66 AU.addRequired();
6367 }
6468 };
6569
6670 } // anonymous namespace
6771
6872 PreservedAnalyses InstrProfiling::run(Module &M, ModuleAnalysisManager &AM) {
69 if (!run(M))
73 auto &TLI = AM.getResult(M);
74 if (!run(M, TLI))
7075 return PreservedAnalyses::all();
7176
7277 return PreservedAnalyses::none();
7378 }
7479
7580 char InstrProfilingLegacyPass::ID = 0;
76 INITIALIZE_PASS(InstrProfilingLegacyPass, "instrprof",
77 "Frontend instrumentation-based coverage lowering.", false,
78 false)
81 INITIALIZE_PASS_BEGIN(
82 InstrProfilingLegacyPass, "instrprof",
83 "Frontend instrumentation-based coverage lowering.", false, false)
84 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
85 INITIALIZE_PASS_END(
86 InstrProfilingLegacyPass, "instrprof",
87 "Frontend instrumentation-based coverage lowering.", false, false)
7988
8089 ModulePass *
8190 llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options) {
113122 return dyn_cast(Instr);
114123 }
115124
116 bool InstrProfiling::run(Module &M) {
125 bool InstrProfiling::run(Module &M, const TargetLibraryInfo &TLI) {
117126 bool MadeChange = false;
118127
119128 this->M = &M;
129 this->TLI = &TLI;
120130 NamesVar = nullptr;
121131 NamesSize = 0;
122132 ProfileDataMap.clear();
172182 return true;
173183 }
174184
175 static Constant *getOrInsertValueProfilingCall(Module &M) {
185 static Constant *getOrInsertValueProfilingCall(Module &M,
186 const TargetLibraryInfo &TLI) {
176187 LLVMContext &Ctx = M.getContext();
177188 auto *ReturnTy = Type::getVoidTy(M.getContext());
178189 Type *ParamTypes[] = {
181192 };
182193 auto *ValueProfilingCallTy =
183194 FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false);
184 return M.getOrInsertFunction(getInstrProfValueProfFuncName(),
185 ValueProfilingCallTy);
195 Constant *Res = M.getOrInsertFunction(getInstrProfValueProfFuncName(),
196 ValueProfilingCallTy);
197 if (Function *FunRes = dyn_cast(Res)) {
198 if (auto AK = TLI.getExtAttrForI32Param(false))
199 FunRes->addAttribute(3, AK);
200 }
201 return Res;
186202 }
187203
188204 void InstrProfiling::computeNumValueSiteCounts(InstrProfValueProfileInst *Ind) {
216232 Value *Args[3] = {Ind->getTargetValue(),
217233 Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
218234 Builder.getInt32(Index)};
219 Ind->replaceAllUsesWith(
220 Builder.CreateCall(getOrInsertValueProfilingCall(*M), Args));
235 CallInst *Call = Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI),
236 Args);
237 if (auto AK = TLI->getExtAttrForI32Param(false))
238 Call->addAttribute(3, AK);
239 Ind->replaceAllUsesWith(Call);
221240 Ind->eraseFromParent();
222241 }
223242
11
22 ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -vp-static-alloc=true -instrprof -S | FileCheck %s --check-prefix=STATIC
33 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC
4 ; RUN: opt < %s -mtriple=powerpc-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC
5 ; RUN: opt < %s -mtriple=sparc-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC
6 ; RUN: opt < %s -mtriple=s390x-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC-EXT
7 ; RUN: opt < %s -mtriple=powerpc64-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC-EXT
8 ; RUN: opt < %s -mtriple=sparc64-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC-EXT
9 ; RUN: opt < %s -mtriple=mips-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC-SEXT
10 ; RUN: opt < %s -mtriple=mips64-unknown-linux -instrprof -vp-static-alloc=true -S | FileCheck %s --check-prefix=STATIC-SEXT
411 ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -vp-static-alloc=false -instrprof -S | FileCheck %s --check-prefix=DYN
512 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -vp-static-alloc=false -S | FileCheck %s --check-prefix=DYN
613
2835
2936 ; DYN-NOT: @__profvp_foo
3037 ; DYN-NOT: @__llvm_prf_vnodes
38
39 ; STATIC: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [1 x i16] }* @__profd_foo to i8*), i32 0)
40 ; STATIC-EXT: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [1 x i16] }* @__profd_foo to i8*), i32 zeroext 0)
41 ; STATIC-SEXT: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [1 x i16] }* @__profd_foo to i8*), i32 signext 0)
42
43 ; STATIC: declare void @__llvm_profile_instrument_target(i64, i8*, i32)
44 ; STATIC-EXT: declare void @__llvm_profile_instrument_target(i64, i8*, i32 zeroext)
45 ; STATIC-SEXT: declare void @__llvm_profile_instrument_target(i64, i8*, i32 signext)