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 "strip_unknown_attributes.h" 18 19 namespace slang { 20 21 StripUnknownAttributes::StripUnknownAttributes() : ModulePass(ID) { 22 } 23 24 25 bool StripUnknownAttributes::runOnFunction(llvm::Function &F) { 26 bool changed = false; 27 for (llvm::Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); 28 I != E; ++I) { 29 llvm::Argument &A = *I; 30 // Remove any readnone/readonly attributes from function parameters. 31 if (A.onlyReadsMemory()) { 32 llvm::AttrBuilder B; 33 B.addAttribute(llvm::Attribute::ReadNone); 34 B.addAttribute(llvm::Attribute::ReadOnly); 35 llvm::AttributeSet ToStrip = llvm::AttributeSet::get(F.getContext(), 36 A.getArgNo() + 1, B); 37 A.removeAttr(ToStrip); 38 changed = true; 39 } 40 } 41 return changed; 42 } 43 44 45 bool StripUnknownAttributes::runOnModule(llvm::Module &M) { 46 bool Changed = false; 47 for (llvm::Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { 48 Changed |= runOnFunction(*I); 49 } 50 return Changed; 51 } 52 53 54 llvm::ModulePass * createStripUnknownAttributesPass() { 55 return new StripUnknownAttributes(); 56 } 57 58 59 char StripUnknownAttributes::ID = 0; 60 static llvm::RegisterPass<StripUnknownAttributes> RPSUA( 61 "StripUnknownAttributes", "Strip Unknown Attributes Pass"); 62 63 } // namespace slang 64