1/*
2 * Copyright 2013, The Android Open Source Project
3 *
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 */
16
17#include "llvm/IR/Attributes.h"
18
19// Shared functionality for legacy function attribute encoding.
20static inline uint64_t encodeLLVMAttributesForBitcode(llvm::AttributeSet A,
21                                                      unsigned i) {
22  uint64_t EncodedAttrs = A.Raw(i) & 0xffff;
23  if (A.hasAttribute(i, llvm::Attribute::Alignment)) {
24    // The alignment is stored as an actual power of 2 value (instead of the
25    // compressed log2 form). It occupies bits 31-16 inclusive.
26    EncodedAttrs |= (A.getParamAlignment(i) << 16);
27  }
28  // There are only 12 remaining attributes (bits 21-32), hence our 0xfff mask.
29  EncodedAttrs |= (A.Raw(i) & (0xfffull << 21))  << 11;
30  return EncodedAttrs;
31}
32
33