File: UserAddrSpaceMD.cpp

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (75 lines) | stat: -rw-r--r-- 2,557 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*========================== begin_copyright_notice ============================

Copyright (C) 2023 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#include "UserAddrSpaceMD.hpp"
#include "IGC/Probe/Assertion.h"

using namespace IGC;

UserAddrSpaceMD::UserAddrSpaceMD(llvm::LLVMContext *ctx) {
  this->ctx = ctx;
  user_addrspace_priv = ctx->getMDKindID("user_as_priv");
  user_addrspace_global = ctx->getMDKindID("user_as_global");
  user_addrspace_local = ctx->getMDKindID("user_as_local");
  user_addrspace_generic = ctx->getMDKindID("user_as_generic");
  user_addrspace_raystack = ctx->getMDKindID("user_as_raystack");

  dummyNode = llvm::MDNode::get(*ctx, llvm::MDString::get(*ctx, ""));
}

void UserAddrSpaceMD::Set(llvm::Instruction *inst, LSC_DOC_ADDR_SPACE type, llvm::MDNode *node) {
  if (inst) {
    llvm::MDNode *chosen_node = node != nullptr ? node : dummyNode;

    user_addrspace chosen_type = -1;

    switch (type) {
    case LSC_DOC_ADDR_SPACE::PRIVATE:
      chosen_type = user_addrspace_priv;
      break;
    case LSC_DOC_ADDR_SPACE::GLOBAL:
      chosen_type = user_addrspace_global;
      break;
    case LSC_DOC_ADDR_SPACE::LOCAL:
      chosen_type = user_addrspace_local;
      break;
    case LSC_DOC_ADDR_SPACE::GENERIC:
      chosen_type = user_addrspace_generic;
      break;
    case LSC_DOC_ADDR_SPACE::RAYSTACK:
      chosen_type = user_addrspace_raystack;
      break;
    default:
      IGC_ASSERT_MESSAGE(0, "Unsupport addrspace type");
      break;
    }
    inst->setMetadata(chosen_type, chosen_node);
  }
}

LSC_DOC_ADDR_SPACE UserAddrSpaceMD::Get(llvm::Instruction *inst) {
  LSC_DOC_ADDR_SPACE addrSpace = LSC_DOC_ADDR_SPACE::INVALID;

  if (inst) {
    if (auto md_addrspace_org = inst->getMetadata(user_addrspace_priv)) {
      addrSpace = LSC_DOC_ADDR_SPACE::PRIVATE;
    } else if (auto md_addrspace_org = inst->getMetadata(user_addrspace_global)) {
      addrSpace = LSC_DOC_ADDR_SPACE::GLOBAL;
    } else if (auto md_addrspace_org = inst->getMetadata(user_addrspace_local)) {
      addrSpace = LSC_DOC_ADDR_SPACE::LOCAL;
    } else if (auto md_addrspace_org = inst->getMetadata(user_addrspace_generic)) {
      addrSpace = LSC_DOC_ADDR_SPACE::GENERIC;
    } else if (auto md_addrspace_org = inst->getMetadata(user_addrspace_raystack)) {
      addrSpace = LSC_DOC_ADDR_SPACE::RAYSTACK;
    }
  }

  return addrSpace;
}

bool UserAddrSpaceMD::Has(llvm::Instruction *inst, LSC_DOC_ADDR_SPACE type) { return Get(inst) == type; }