/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * 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.
 */



static void VisitSafePoint([[maybe_unused]] GraphVisitor* visitor, Inst* inst) {
    
    if (cg->GetGraph()->GetRuntime()->GetGCEntryPoint() == 0) {
       // No GC_ENTRY - do not encode SafePoint
       return;
    }
    auto runtime_info = visitor->GetGraph()->GetRuntime();
    auto flag_addr_offset = runtime_info->GetFlagAddrOffset();
    auto tmp_reg = cg->EncodeReg(cg->GetTmp(), DataType::UINT64);
    auto arg_mem = vixl::aarch64::MemOperand(vixl::aarch64::sp, cg->GetStackOffset());
    __ Ldr(tmp_reg, arg_mem);
    // TMP <= ExecState Address
    auto safepoint_mem = vixl::aarch64::MemOperand(tmp_reg, flag_addr_offset);
    // safepoint_mem - memory for read flag value
    
    __ Ldr(cg->EncodeReg(cg->GetTmp(), DataType::UINT16), safepoint_mem);
    
    auto label = cg->GetLabelSS(inst);
    __ Cmp(cg->EncodeReg(cg->GetTmp(), DataType::UINT16), 0);
    __ B(vixl::aarch64::Condition::ne, label);
    
    __ Bind(cg->GetBackEdgeSP(inst));
}
