1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#pragma once
#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include <llvm/IR/InstVisitor.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/Analysis/LoopPass.h>
#include "common/LLVMWarningsPop.hpp"
#include "Compiler/IGCPassSupport.h"
#include "Compiler/CodeGenPublic.h"
namespace IGC
{
// Forward declaration
struct SInstrTypes;
class CheckInstrTypes : public llvm::FunctionPass, public llvm::InstVisitor<CheckInstrTypes>
{
llvm::LoopInfo* LI;
public:
static char ID;
CheckInstrTypes() : FunctionPass(ID), g_InstrTypes(nullptr), g_metrics(nullptr), LI(nullptr)
{
};
CheckInstrTypes(IGC::SInstrTypes* instrList, IGCMetrics::IGCMetric* metrics);
virtual bool runOnFunction(llvm::Function& F) override;
void checkGlobalLocal(llvm::Instruction& I);
virtual llvm::StringRef getPassName() const override
{
return "CheckInstrTypes";
}
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
{
AU.addRequired<llvm::LoopInfoWrapperPass>();
AU.setPreservesAll();
}
void visitInstruction(llvm::Instruction& I);
void visitCallInst(llvm::CallInst& C);
void visitBranchInst(llvm::BranchInst& I);
void visitSwitchInst(llvm::SwitchInst& I);
void visitIndirectBrInst(llvm::IndirectBrInst& I);
void visitICmpInst(llvm::ICmpInst& I);
void visitFCmpInst(llvm::FCmpInst& I);
void visitAllocaInst(llvm::AllocaInst& I);
void visitLoadInst(llvm::LoadInst& I);
void visitStoreInst(llvm::StoreInst& I);
void visitGetElementPtrInst(llvm::GetElementPtrInst& I);
void visitPHINode(llvm::PHINode& PN);
void visitSelectInst(llvm::SelectInst& I);
void SetLoopFlags(llvm::Function& F);
private:
IGC::SInstrTypes* g_InstrTypes;
IGCMetrics::IGCMetric* g_metrics;
};
class InstrStatistic : public llvm::FunctionPass, public llvm::InstVisitor<InstrStatistic>
{
public:
static char ID;
InstrStatistic() : FunctionPass(ID), m_ctx(nullptr), m_type(InstrStatTypes(0)),
m_stage(InstrStatStage::BEGIN), m_threshold(0), m_LI(nullptr)
{
};
InstrStatistic(CodeGenContext* ctx, InstrStatTypes type, InstrStatStage stage, int threshold);
virtual bool runOnFunction(llvm::Function& F) override;
virtual llvm::StringRef getPassName() const override
{
return "InstrStatistic";
}
void visitInstruction(llvm::Instruction& I);
void visitLoadInst(llvm::LoadInst& I);
void visitStoreInst(llvm::StoreInst& I);
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
{
AU.addRequired<llvm::LoopInfoWrapperPass>();
AU.setPreservesAll();
}
private:
CodeGenContext* m_ctx;
IGC::InstrStatTypes m_type;
InstrStatStage m_stage;
int m_threshold;
llvm::LoopInfo* m_LI;
bool parseLoops();
bool parseLoop(llvm::Loop* loop);
};
} // namespace IGC
|