• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 The Khronos Group Inc.
2 // Copyright (c) 2017 Valve Corporation
3 // Copyright (c) 2017 LunarG Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include "source/opt/pass.h"
18 
19 #include "source/opt/iterator.h"
20 
21 namespace spvtools {
22 namespace opt {
23 
24 namespace {
25 
26 const uint32_t kTypePointerTypeIdInIdx = 1;
27 
28 }  // namespace
29 
Pass()30 Pass::Pass() : consumer_(nullptr), context_(nullptr), already_run_(false) {}
31 
Run(IRContext * ctx)32 Pass::Status Pass::Run(IRContext* ctx) {
33   if (already_run_) {
34     return Status::Failure;
35   }
36   already_run_ = true;
37 
38   context_ = ctx;
39   Pass::Status status = Process();
40   context_ = nullptr;
41 
42   if (status == Status::SuccessWithChange) {
43     ctx->InvalidateAnalysesExceptFor(GetPreservedAnalyses());
44   }
45   assert(ctx->IsConsistent());
46   return status;
47 }
48 
GetPointeeTypeId(const Instruction * ptrInst) const49 uint32_t Pass::GetPointeeTypeId(const Instruction* ptrInst) const {
50   const uint32_t ptrTypeId = ptrInst->type_id();
51   const Instruction* ptrTypeInst = get_def_use_mgr()->GetDef(ptrTypeId);
52   return ptrTypeInst->GetSingleWordInOperand(kTypePointerTypeIdInIdx);
53 }
54 
55 }  // namespace opt
56 }  // namespace spvtools
57