blob: 95e15a8877a6b6006b2e6a33e852e92a27b5213a [file] [log] [blame]
alan-baker04f3a952020-03-24 10:39:53 -04001// Copyright 2020 The Clspv Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "llvm/IR/Attributes.h"
16#include "llvm/IR/Module.h"
17#include "llvm/Pass.h"
18
19#include "Constants.h"
20#include "Passes.h"
21
22#define DEBUG_TYPE "addfunctionattributes"
23
24using namespace llvm;
25
26namespace {
27class AddFunctionAttributesPass : public ModulePass {
28public:
29 static char ID;
30 AddFunctionAttributesPass() : ModulePass(ID) {}
31
32 bool runOnModule(Module &M) override;
33};
34} // namespace
35
36char AddFunctionAttributesPass::ID = 0;
37INITIALIZE_PASS(AddFunctionAttributesPass, "AddFunctionAttributes",
38 "Add function attributes to builtin functions", false, false)
39
40namespace clspv {
41ModulePass *createAddFunctionAttributesPass() {
42 return new AddFunctionAttributesPass();
43}
44} // namespace clspv
45
46bool AddFunctionAttributesPass::runOnModule(Module &M) {
47 bool changed = false;
48
49 // Add ReadNone and Speculatable to literal sampler functions to avoid loop
50 // optimizations producing phis with them.
51 if (auto F = M.getFunction(clspv::TranslateSamplerInitializerFunction())) {
52 F->addFnAttr(Attribute::AttrKind::ReadNone);
53 F->addFnAttr(Attribute::AttrKind::Speculatable);
54 changed = true;
55 }
56
57 return changed;
58}