-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathLowerAddrSpaceCastPass.h
76 lines (62 loc) · 2.86 KB
/
LowerAddrSpaceCastPass.h
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
// Copyright 2023 The Clspv Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _CLSPV_LIB_ADDRSPACECAST_PASS_H
#define _CLSPV_LIB_ADDRSPACECAST_PASS_H
#include "llvm/IR/InstVisitor.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "clspv/AddressSpace.h"
namespace clspv {
struct LowerAddrSpaceCastPass
: llvm::PassInfoMixin<LowerAddrSpaceCastPass>,
llvm::InstVisitor<LowerAddrSpaceCastPass, llvm::Value *> {
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &);
private:
// Implementation details for InstVisitor
using Visitor = llvm::InstVisitor<LowerAddrSpaceCastPass, llvm::Value *>;
using Visitor::visit;
friend Visitor;
llvm::Value *visit(llvm::Value *V);
llvm::Value *visitAllocaInst(llvm::AllocaInst &I);
llvm::Value *visitAtomicRMWInst(llvm::AtomicRMWInst &I);
llvm::Value *visitLoadInst(llvm::LoadInst &I);
llvm::Value *visitStoreInst(llvm::StoreInst &I);
llvm::Value *visitGetElementPtrInst(llvm::GetElementPtrInst &I);
llvm::Value *visitAddrSpaceCastInst(llvm::AddrSpaceCastInst &I);
llvm::Value *visitICmpInst(llvm::ICmpInst &I);
llvm::Value *visitCallInst(llvm::CallInst &I);
llvm::Value *visitIntToPtrInst(llvm::IntToPtrInst &I);
llvm::Value *visitPtrToIntInst(llvm::PtrToIntInst &I);
llvm::Value *visitPHINode(llvm::PHINode &I);
llvm::Value *visitInstruction(llvm::Instruction &I);
void runOnFunction(llvm::Function &F);
void registerReplacement(llvm::Value *U, llvm::Value *V);
/// Clears the dead instructions and others that might be rendered dead
/// by their removal.
void cleanDeadInstructions();
void cleanModule(llvm::Module &M);
/// A map between original values and their replacement.
///
/// The content of this mapping is valid only for the function being visited
/// at a given time. The keys in this mapping should be removed from the
/// function once all instructions in the current function have been visited
/// and transformed. Instructions are not removed from the function as they
/// are visited because this would invalidate iterators.
llvm::DenseMap<llvm::Value *, llvm::Value *> ValueMap;
llvm::DenseMap<llvm::Value *, llvm::Type *> TypeCache;
llvm::DenseMap<llvm::Function *, llvm::Function *> FunctionMap;
};
} // namespace clspv
#endif // _CLSPV_LIB_ADDRSPACECAST_PASS_H