mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-05 02:16:46 +00:00
Pass AssumptionCacheTracker from SampleProfileLoader to Inliner
Summary: Inliner needs ACT when calling InlineFunction. Instead of nullptr, we need to pass it in from SampleProfileLoader Reviewers: davidxl Subscribers: eraman, vsk, danielcdh, llvm-commits Differential Revision: http://reviews.llvm.org/D21205 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
920d0ae595
commit
8122c25a1a
@ -27,6 +27,7 @@
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Analysis/AssumptionCache.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/PostDominators.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
@ -105,11 +106,13 @@ typedef DenseMap<const BasicBlock *, SmallVector<const BasicBlock *, 8>>
|
||||
class SampleProfileLoader {
|
||||
public:
|
||||
SampleProfileLoader(StringRef Name = SampleProfileFile)
|
||||
: DT(nullptr), PDT(nullptr), LI(nullptr), Reader(), Samples(nullptr),
|
||||
Filename(Name), ProfileIsValid(false), TotalCollectedSamples(0) {}
|
||||
: DT(nullptr), PDT(nullptr), LI(nullptr), ACT(nullptr), Reader(),
|
||||
Samples(nullptr), Filename(Name), ProfileIsValid(false),
|
||||
TotalCollectedSamples(0) {}
|
||||
|
||||
bool doInitialization(Module &M);
|
||||
bool runOnModule(Module &M);
|
||||
void setACT(AssumptionCacheTracker *A) { ACT = A; }
|
||||
|
||||
void dump() { Reader->dump(); }
|
||||
|
||||
@ -169,6 +172,8 @@ protected:
|
||||
std::unique_ptr<DominatorTreeBase<BasicBlock>> PDT;
|
||||
std::unique_ptr<LoopInfo> LI;
|
||||
|
||||
AssumptionCacheTracker *ACT;
|
||||
|
||||
/// \brief Predecessors for each basic block in the CFG.
|
||||
BlockEdgeMap Predecessors;
|
||||
|
||||
@ -213,6 +218,9 @@ public:
|
||||
const char *getPassName() const override { return "Sample profile pass"; }
|
||||
bool runOnModule(Module &M) override;
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<AssumptionCacheTracker>();
|
||||
}
|
||||
private:
|
||||
SampleProfileLoader SampleLoader;
|
||||
};
|
||||
@ -698,7 +706,7 @@ bool SampleProfileLoader::inlineHotFunctions(Function &F) {
|
||||
}
|
||||
}
|
||||
for (auto CI : CIS) {
|
||||
InlineFunctionInfo IFI;
|
||||
InlineFunctionInfo IFI(nullptr, ACT);
|
||||
Function *CalledFunction = CI->getCalledFunction();
|
||||
DebugLoc DLoc = CI->getDebugLoc();
|
||||
uint64_t NumSamples = findCalleeFunctionSamples(*CI)->getTotalSamples();
|
||||
@ -1226,7 +1234,10 @@ bool SampleProfileLoader::emitAnnotations(Function &F) {
|
||||
}
|
||||
|
||||
char SampleProfileLoaderLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(SampleProfileLoaderLegacyPass, "sample-profile",
|
||||
INITIALIZE_PASS_BEGIN(SampleProfileLoaderLegacyPass, "sample-profile",
|
||||
"Sample Profile loader", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
||||
INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass, "sample-profile",
|
||||
"Sample Profile loader", false, false)
|
||||
|
||||
bool SampleProfileLoader::doInitialization(Module &M) {
|
||||
@ -1268,6 +1279,8 @@ bool SampleProfileLoader::runOnModule(Module &M) {
|
||||
}
|
||||
|
||||
bool SampleProfileLoaderLegacyPass::runOnModule(Module &M) {
|
||||
// FIXME: pass in AssumptionCache correctly for the new pass manager.
|
||||
SampleLoader.setACT(&getAnalysis<AssumptionCacheTracker>());
|
||||
return SampleLoader.runOnModule(M);
|
||||
}
|
||||
|
||||
|
3
test/Transforms/SampleProfile/Inputs/inline-act.prof
Normal file
3
test/Transforms/SampleProfile/Inputs/inline-act.prof
Normal file
@ -0,0 +1,3 @@
|
||||
_Z3bari:100:0
|
||||
1: _Z3fooi:100
|
||||
2: 100
|
72
test/Transforms/SampleProfile/inline-act.ll
Normal file
72
test/Transforms/SampleProfile/inline-act.ll
Normal file
@ -0,0 +1,72 @@
|
||||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline-act.prof
|
||||
|
||||
; Sample profile should have non-empty ACT passed to inliner
|
||||
|
||||
; int t;
|
||||
; bool foo(int value) {
|
||||
; switch(value) {
|
||||
; case 0:
|
||||
; case 1:
|
||||
; case 3:
|
||||
; return true;
|
||||
; default:
|
||||
; return false;
|
||||
; }
|
||||
; }
|
||||
; void bar(int i) {
|
||||
; if (foo(i))
|
||||
; t *= 2;
|
||||
; }
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
@t = global i32 0, align 4
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define zeroext i1 @_Z3fooi(i32) #0 {
|
||||
%switch.tableidx = sub i32 %0, 0
|
||||
%2 = icmp ult i32 %switch.tableidx, 4
|
||||
br i1 %2, label %switch.lookup, label %3
|
||||
|
||||
switch.lookup: ; preds = %1
|
||||
%switch.cast = trunc i32 %switch.tableidx to i4
|
||||
%switch.shiftamt = mul i4 %switch.cast, 1
|
||||
%switch.downshift = lshr i4 -5, %switch.shiftamt
|
||||
%switch.masked = trunc i4 %switch.downshift to i1
|
||||
ret i1 %switch.masked
|
||||
|
||||
; <label>:3: ; preds = %1
|
||||
ret i1 false
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define void @_Z3bari(i32) #0 !dbg !9 {
|
||||
%2 = call zeroext i1 @_Z3fooi(i32 %0), !dbg !10
|
||||
br i1 %2, label %3, label %6, !dbg !10
|
||||
|
||||
; <label>:3: ; preds = %1
|
||||
%4 = load i32, i32* @t, align 4
|
||||
%5 = shl nsw i32 %4, 1
|
||||
store i32 %5, i32* @t, align 4
|
||||
br label %6
|
||||
|
||||
; <label>:6: ; preds = %3, %1
|
||||
ret void
|
||||
}
|
||||
|
||||
attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!3}
|
||||
!llvm.ident = !{!4}
|
||||
|
||||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 272227) (llvm/trunk 272226)", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
|
||||
!1 = !DIFile(filename: "test.cc", directory: "./")
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!4 = !{!"clang version 3.9.0 (trunk 272227) (llvm/trunk 272226)"}
|
||||
!6 = !DISubroutineType(types: !2)
|
||||
!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 14, type: !6, isLocal: false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
|
||||
!10 = !DILocation(line: 15, column: 7, scope: !9)
|
||||
!11 = !DILocation(line: 16, column: 7, scope: !9)
|
Loading…
Reference in New Issue
Block a user