• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef RS2SPIRV_RS_ALLOCATION_UTILS_H
18 #define RS2SPIRV_RS_ALLOCATION_UTILS_H
19 
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/SmallVector.h"
22 
23 #include <string>
24 
25 namespace llvm {
26 class CallInst;
27 class GlobalVariable;
28 class Module;
29 class Type;
30 } // namespace llvm
31 
32 namespace rs2spirv {
33 
34 struct RSAllocationInfo {
35   std::string VarName;
36   llvm::Optional<std::string> RSElementType;
37   llvm::GlobalVariable *GlobalVar;
38   // Assigned unique identifier for this allocation;
39   // not the slot #.
40   // Represents the index of this allocation's metadata
41   // in the global allocation metadata Vulkan buffer
42   int ID;
hasIDRSAllocationInfo43   bool hasID(void) const { return ID >= 0; }
assignIDRSAllocationInfo44   void assignID(int no) { ID = no; }
45 };
46 
47 enum class RSAllocAccessKind { GEA, SEA, DIMX };
48 
49 struct RSAllocationCallInfo {
50   RSAllocationInfo &RSAlloc;
51   llvm::CallInst *FCall;
52   RSAllocAccessKind Kind;
53   std::string RSElementTy;
54 };
55 
56 bool isRSAllocation(const llvm::GlobalVariable &GV);
57 bool getRSAllocationInfo(llvm::Module &M,
58                          llvm::SmallVectorImpl<RSAllocationInfo> &Allocs);
59 bool getRSAllocAccesses(llvm::SmallVectorImpl<RSAllocationInfo> &Allocs,
60                         llvm::SmallVectorImpl<RSAllocationCallInfo> &Calls);
61 bool solidifyRSAllocAccess(llvm::Module &M, RSAllocationCallInfo CallInfo);
62 
63 } // namespace rs2spirv
64 
65 #endif
66