pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #include "source/opt/pass.h"
  17. #include "source/opt/iterator.h"
  18. namespace spvtools {
  19. namespace opt {
  20. namespace {
  21. const uint32_t kTypePointerTypeIdInIdx = 1;
  22. } // namespace
  23. Pass::Pass() : consumer_(nullptr), context_(nullptr), already_run_(false) {}
  24. Pass::Status Pass::Run(IRContext* ctx) {
  25. if (already_run_) {
  26. return Status::Failure;
  27. }
  28. already_run_ = true;
  29. context_ = ctx;
  30. Pass::Status status = Process();
  31. context_ = nullptr;
  32. if (status == Status::SuccessWithChange) {
  33. ctx->InvalidateAnalysesExceptFor(GetPreservedAnalyses());
  34. }
  35. assert(ctx->IsConsistent());
  36. return status;
  37. }
  38. uint32_t Pass::GetPointeeTypeId(const Instruction* ptrInst) const {
  39. const uint32_t ptrTypeId = ptrInst->type_id();
  40. const Instruction* ptrTypeInst = get_def_use_mgr()->GetDef(ptrTypeId);
  41. return ptrTypeInst->GetSingleWordInOperand(kTypePointerTypeIdInIdx);
  42. }
  43. } // namespace opt
  44. } // namespace spvtools