• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env ruby
2
3# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
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
16include_relative 'common.irt'
17
18function(:CheckCastInterfaceEntrypoint,
19          params: {obj: 'ptr', interface: 'ptr'},
20          regmap: $full_regmap,
21          regalloc_set: RegMask.new($full_regmap, :tmp1, :tmp2, :arg0, :arg1, :callee0, :callee2, :callee3),
22          mode: [:FastPath]) {
23    if Options.arch == :arm32
24        Intrinsic(:UNREACHABLE).ptr
25        next
26    end
27
28    klass := LoadI(obj).Imm(Constants::OBJECT_CLASS_OFFSET).ref
29    size := LoadI(klass).Imm(Constants::CLASS_ITABLE_ENTRIES_SIZE_OFFSET).word
30    elements0 := LoadI(klass).Imm(Constants::CLASS_ITABLE_ENTRIES_DATA_OFFSET).ptr
31    i0 := 0
32Label(:Loop)
33    elements_phi := Phi(elements0, elements1).ptr
34    i_phi := Phi(i0, i1).word
35    If(i_phi, size).CC(:CC_EQ) {
36        Goto(:SlowPath)
37    }
38    implemented_interface := LoadI(elements_phi).Imm(Constants::CLASS_ITABLE_ENTRY_INTERFACE_OFFSET).ptr
39    If(implemented_interface, interface).CC(:CC_EQ).b {
40        ReturnVoid()
41    }
42    elements1 := Add(elements_phi, Constants::CLASS_ITABLE_ENTRY_SIZE).ptr
43    i1 := Add(i_phi, 1).word
44    Goto(:Loop)
45Label(:SlowPath)
46    Intrinsic(:SLOW_PATH_ENTRY, obj, interface).AddImm(Constants::CHECK_CAST_SLOW_PATH).v0id
47    Intrinsic(:UNREACHABLE).ptr if defines.DEBUG
48}
49