File: NontemporalLoadsAndStoresInAssert.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 (56 lines) | stat: -rw-r--r-- 2,059 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
/*========================== begin_copyright_notice ============================

Copyright (C) 2023 Intel Corporation

SPDX-License-Identifier: MIT

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

#include "Compiler/Optimizer/OpenCLPasses/NontemporalLoadsAndStoresInAssert/NontemporalLoadsAndStoresInAssert.hpp"
#include "Compiler/IGCPassSupport.h"

#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Constants.h>
#include "common/LLVMWarningsPop.hpp"

using namespace llvm;
using namespace IGC;

// Register pass to igc-opt
#define PASS_FLAG "igc-nontemporal-loads-and-stores-in-assert"
#define PASS_DESCRIPTION "Mark loads and stores inside assert implementation as nontemporal to avoid caching"
#define PASS_CFG_ONLY false
#define PASS_ANALYSIS false
IGC_INITIALIZE_PASS_BEGIN(NontemporalLoadsAndStoresInAssert, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
IGC_INITIALIZE_PASS_DEPENDENCY(MetaDataUtilsWrapper)
IGC_INITIALIZE_PASS_END(NontemporalLoadsAndStoresInAssert, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)

char NontemporalLoadsAndStoresInAssert::ID = 0;

static const char *ASSERT_FUNCTION_NAME = "__devicelib_assert_fail";

NontemporalLoadsAndStoresInAssert::NontemporalLoadsAndStoresInAssert() : ModulePass(ID) {
  initializeNontemporalLoadsAndStoresInAssertPass(*PassRegistry::getPassRegistry());
}

bool NontemporalLoadsAndStoresInAssert::runOnModule(Module &M) {
  bool changed = false;
  for (Function &F : M) {

    if (!F.getName().equals(ASSERT_FUNCTION_NAME))
      continue;

    for (auto I = inst_begin(F); I != inst_end(F); ++I) {
      if (isa<LoadInst>(*I) || isa<StoreInst>(*I)) {
        Constant *One = ConstantInt::get(Type::getInt32Ty(I->getContext()), 1);
        MDNode *Node = MDNode::get(I->getContext(), ConstantAsMetadata::get(One));
        I->setMetadata(LLVMContext::MD_nontemporal, Node);
        changed = true;
      }
    }
  }
  return changed;
}