• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, 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 "strip_unknown_attributes.h"
18 
19 #include "llvm/IR/Function.h"
20 
21 namespace slang {
22 
stripUnknownAttributes(llvm::Function & F)23 bool stripUnknownAttributes(llvm::Function &F) {
24   bool changed = false;
25   for (llvm::Function::arg_iterator I = F.arg_begin(), E = F.arg_end();
26        I != E; ++I) {
27     llvm::Argument &A = *I;
28     // Remove any readnone/readonly attributes from function parameters.
29     if (A.onlyReadsMemory()) {
30       llvm::AttrBuilder B;
31       B.addAttribute(llvm::Attribute::ReadNone);
32       B.addAttribute(llvm::Attribute::ReadOnly);
33       llvm::AttributeSet ToStrip = llvm::AttributeSet::get(F.getContext(),
34           A.getArgNo() + 1, B);
35       A.removeAttr(ToStrip);
36       changed = true;
37     }
38   }
39   F.removeFnAttr(llvm::Attribute::ArgMemOnly);
40   return changed;
41 }
42 
43 }  // namespace slang
44