blob: 4992fd08df4cc5cb3844b94c5951b368b34cd0be [file] [log] [blame]
David Neto48f56a42017-10-06 16:44:25 -04001// Copyright 2017 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
David Neto4feb7a42017-10-06 17:29:42 -040015#ifndef CLSPV_LIB_ARGKIND_H_
16#define CLSPV_LIB_ARGKIND_H_
David Neto48f56a42017-10-06 16:44:25 -040017
Diego Novilloa4c44fa2019-04-11 10:56:15 -040018#include "llvm/ADT/DenseMap.h"
David Netoc6f3ab22018-04-06 18:02:31 -040019#include "llvm/IR/Function.h"
20#include "llvm/IR/Module.h"
21#include "llvm/IR/Type.h"
David Neto48f56a42017-10-06 16:44:25 -040022
alan-bakerf5e5f692018-11-27 08:33:24 -050023#include "clspv/ArgKind.h"
David Neto48f56a42017-10-06 16:44:25 -040024
alan-bakerf5e5f692018-11-27 08:33:24 -050025namespace clspv {
David Neto862b7d82018-06-14 18:48:37 -040026
alan-bakerc4579bb2020-04-29 14:15:50 -040027// Enum for how pod args are implemented. Gets added as metadata to each
28// kernel.
29enum PodArgImpl {
30 kSSBO,
31 kUBO,
32 kPushConstant,
33 // Shared interface across all shaders.
34 kGlobalPushConstant,
35};
David Neto862b7d82018-06-14 18:48:37 -040036
alan-bakerc4579bb2020-04-29 14:15:50 -040037// Returns the style of pod args used by |F|. Note that |F| must be a kernel.
38PodArgImpl GetPodArgsImpl(llvm::Function &F);
39
40// Returns the ArgKind for pod args in kernel |F|.
41ArgKind GetArgKindForPodArgs(llvm::Function &F);
42
43// Returns the ArgKind for |Arg|.
44ArgKind GetArgKind(llvm::Argument &Arg);
David Neto48f56a42017-10-06 16:44:25 -040045
David Netoc6f3ab22018-04-06 18:02:31 -040046// Returns true if the given type is a pointer-to-local type.
Diego Novilloa4c44fa2019-04-11 10:56:15 -040047bool IsLocalPtr(llvm::Type *type);
David Netoc6f3ab22018-04-06 18:02:31 -040048
Diego Novilloa4c44fa2019-04-11 10:56:15 -040049using ArgIdMapType = llvm::DenseMap<const llvm::Argument *, int>;
David Netoc6f3ab22018-04-06 18:02:31 -040050
51// Returns a mapping from pointer-to-local Argument to a specialization constant
52// ID for that argument's array size. The lowest value allocated is 3.
53//
54// The mapping is as follows:
55// - The first index used is 3.
56// - There are no gaps in the list of used indices.
57// - Arguments from earlier kernel bodies have lower indices than arguments from
58// later kernel bodies.
59// - Lower-numbered arguments have lower indices than higher-numbered arguments
60// in the same function.
61// Note that this mapping is stable as long as the order of kernel bodies is
62// retained, and the number and order of pointer-to-local arguments is retained.
63ArgIdMapType AllocateArgSpecIds(llvm::Module &M);
64
David Neto48f56a42017-10-06 16:44:25 -040065} // namespace clspv
66
67#endif