2
0

Region.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "BackEnd.h"
  6. Region *
  7. Region::New(RegionType type, Region * parent, Func * func)
  8. {
  9. Region * region = JitAnew(func->m_alloc, Region);
  10. region->type = type;
  11. region->parent = parent;
  12. region->bailoutReturnThunkLabel = IR::LabelInstr::New(Js::OpCode::Label, func, true);
  13. if (type == RegionTypeTry)
  14. {
  15. region->selfOrFirstTryAncestor = region;
  16. }
  17. return region;
  18. }
  19. void
  20. Region::AllocateEHBailoutData(Func * func, IR::Instr * tryInstr)
  21. {
  22. if (this->GetType() == RegionTypeRoot)
  23. {
  24. this->ehBailoutData = NativeCodeDataNew(func->GetNativeCodeDataAllocator(), Js::EHBailoutData, -1 /*nestingDepth*/, 0 /*catchOffset*/, nullptr /*parent*/);
  25. }
  26. else
  27. {
  28. this->ehBailoutData = NativeCodeDataNew(func->GetNativeCodeDataAllocator(), Js::EHBailoutData, this->GetParent()->ehBailoutData->nestingDepth + 1, 0, this->GetParent()->ehBailoutData);
  29. if (this->GetType() == RegionTypeTry)
  30. {
  31. Assert(tryInstr);
  32. if (tryInstr->m_opcode == Js::OpCode::TryCatch)
  33. {
  34. this->ehBailoutData->catchOffset = tryInstr->AsBranchInstr()->GetTarget()->GetByteCodeOffset(); // ByteCode offset of the Catch
  35. }
  36. }
  37. }
  38. }
  39. Region *
  40. Region::GetSelfOrFirstTryAncestor()
  41. {
  42. if (!this->selfOrFirstTryAncestor)
  43. {
  44. Region* region = this;
  45. while (region && region->GetType() != RegionTypeTry)
  46. {
  47. region = region->GetParent();
  48. }
  49. this->selfOrFirstTryAncestor = region;
  50. }
  51. return this->selfOrFirstTryAncestor;
  52. }