| OLD | NEW |
| 1 //===- PNaClABIVerifyModule.cpp - Verify PNaCl ABI rules ------------------===// | 1 //===- PNaClABIVerifyModule.cpp - Verify PNaCl ABI rules ------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Verify module-level PNaCl ABI requirements (specifically those that do not | 10 // Verify module-level PNaCl ABI requirements (specifically those that do not |
| 11 // require looking at the function bodies) | 11 // require looking at the function bodies) |
| 12 // | 12 // |
| 13 // | 13 // |
| 14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 15 | 15 |
| 16 #include "llvm/Pass.h" | |
| 17 #include "llvm/ADT/Twine.h" | 16 #include "llvm/ADT/Twine.h" |
| 18 #include "llvm/Analysis/NaCl.h" | 17 #include "llvm/Analysis/NaCl.h" |
| 19 #include "llvm/IR/Constants.h" | 18 #include "llvm/IR/Constants.h" |
| 20 #include "llvm/IR/DerivedTypes.h" | 19 #include "llvm/IR/DerivedTypes.h" |
| 20 #include "llvm/IR/Instructions.h" |
| 21 #include "llvm/IR/Intrinsics.h" | 21 #include "llvm/IR/Intrinsics.h" |
| 22 #include "llvm/IR/Module.h" | 22 #include "llvm/IR/Module.h" |
| 23 #include "llvm/Pass.h" |
| 23 #include "llvm/Support/Debug.h" | 24 #include "llvm/Support/Debug.h" |
| 24 #include "llvm/Support/raw_ostream.h" | 25 #include "llvm/Support/raw_ostream.h" |
| 25 | 26 |
| 26 #include "PNaClABITypeChecker.h" | 27 #include "PNaClABITypeChecker.h" |
| 27 using namespace llvm; | 28 using namespace llvm; |
| 28 | 29 |
| 29 namespace llvm { | 30 namespace llvm { |
| 30 cl::opt<bool> | 31 cl::opt<bool> |
| 31 PNaClABIAllowDebugMetadata("pnaclabi-allow-debug-metadata", | 32 PNaClABIAllowDebugMetadata("pnaclabi-allow-debug-metadata", |
| 32 cl::desc("Allow debug metadata during PNaCl ABI verification."), | 33 cl::desc("Allow debug metadata during PNaCl ABI verification."), |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 return false; | 178 return false; |
| 178 Type *ParamType = FT->getParamType(0); | 179 Type *ParamType = FT->getParamType(0); |
| 179 LLVMContext &C = F->getContext(); | 180 LLVMContext &C = F->getContext(); |
| 180 Type *AcceptableTypes[] = { Type::getInt32Ty(C), Type::getInt64Ty(C) }; | 181 Type *AcceptableTypes[] = { Type::getInt32Ty(C), Type::getInt64Ty(C) }; |
| 181 return TypeAcceptable(ParamType, AcceptableTypes); | 182 return TypeAcceptable(ParamType, AcceptableTypes); |
| 182 } | 183 } |
| 183 | 184 |
| 184 bool PNaClABIVerifyModule::isWhitelistedIntrinsic(const Function *F, | 185 bool PNaClABIVerifyModule::isWhitelistedIntrinsic(const Function *F, |
| 185 unsigned ID) { | 186 unsigned ID) { |
| 186 // Keep 3 categories of intrinsics for now. | 187 // Keep 3 categories of intrinsics for now. |
| 187 // (1) Allowed always | 188 // (1) Allowed. |
| 188 // (2) Never allowed | 189 // (2) Never allowed. |
| 189 // (3) "Dev" intrinsics, which may or may not be allowed. | 190 // (3) "Dev" intrinsics, which may or may not be allowed. |
| 190 // "Dev" intrinsics are controlled by the PNaClABIAllowDevIntrinsics flag. | 191 // "Dev" intrinsics are controlled by the PNaClABIAllowDevIntrinsics flag. |
| 191 // Please keep these sorted or grouped in a sensible way, within | 192 // Please keep these sorted or grouped in a sensible way, within |
| 192 // each category. | 193 // each category. |
| 193 switch(ID) { | 194 switch(ID) { |
| 194 // Disallow by default. | 195 // Disallow by default. |
| 195 default: return false; | 196 default: return false; |
| 196 // (1) Always allowed. | 197 // (1) Allowed. |
| 198 case Intrinsic::memcpy: |
| 199 case Intrinsic::memmove: |
| 200 case Intrinsic::memset: |
| 201 case Intrinsic::nacl_atomic_8: |
| 202 case Intrinsic::nacl_atomic_16: |
| 203 case Intrinsic::nacl_atomic_32: |
| 204 case Intrinsic::nacl_atomic_64: |
| 205 case Intrinsic::nacl_setjmp: |
| 206 case Intrinsic::nacl_longjmp: |
| 207 case Intrinsic::nacl_read_tp: |
| 208 case Intrinsic::trap: |
| 209 return true; |
| 197 case Intrinsic::bswap: return isWhitelistedBswap(F); | 210 case Intrinsic::bswap: return isWhitelistedBswap(F); |
| 198 case Intrinsic::ctlz: | 211 case Intrinsic::ctlz: |
| 199 case Intrinsic::cttz: return isWhitelistedCountBits(F, 2); | 212 case Intrinsic::cttz: return isWhitelistedCountBits(F, 2); |
| 200 case Intrinsic::ctpop: return isWhitelistedCountBits(F, 1); | 213 case Intrinsic::ctpop: return isWhitelistedCountBits(F, 1); |
| 201 case Intrinsic::memcpy: | |
| 202 case Intrinsic::memmove: | |
| 203 case Intrinsic::memset: | |
| 204 case Intrinsic::nacl_read_tp: | |
| 205 case Intrinsic::nacl_setjmp: | |
| 206 case Intrinsic::nacl_longjmp: | |
| 207 case Intrinsic::trap: | |
| 208 return true; | |
| 209 | 214 |
| 210 // (2) Known to be never allowed. | 215 // (2) Known to be never allowed. |
| 211 case Intrinsic::not_intrinsic: | 216 case Intrinsic::not_intrinsic: |
| 212 // Trampolines depend on a target-specific-sized/aligned buffer. | 217 // Trampolines depend on a target-specific-sized/aligned buffer. |
| 213 case Intrinsic::adjust_trampoline: | 218 case Intrinsic::adjust_trampoline: |
| 214 case Intrinsic::init_trampoline: | 219 case Intrinsic::init_trampoline: |
| 215 // CXX exception handling is not stable. | 220 // CXX exception handling is not stable. |
| 216 case Intrinsic::eh_dwarf_cfa: | 221 case Intrinsic::eh_dwarf_cfa: |
| 217 case Intrinsic::eh_return_i32: | 222 case Intrinsic::eh_return_i32: |
| 218 case Intrinsic::eh_return_i64: | 223 case Intrinsic::eh_return_i64: |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 } | 476 } |
| 472 | 477 |
| 473 char PNaClABIVerifyModule::ID = 0; | 478 char PNaClABIVerifyModule::ID = 0; |
| 474 INITIALIZE_PASS(PNaClABIVerifyModule, "verify-pnaclabi-module", | 479 INITIALIZE_PASS(PNaClABIVerifyModule, "verify-pnaclabi-module", |
| 475 "Verify module for PNaCl", false, true) | 480 "Verify module for PNaCl", false, true) |
| 476 | 481 |
| 477 ModulePass *llvm::createPNaClABIVerifyModulePass( | 482 ModulePass *llvm::createPNaClABIVerifyModulePass( |
| 478 PNaClABIErrorReporter *Reporter, bool StreamingMode) { | 483 PNaClABIErrorReporter *Reporter, bool StreamingMode) { |
| 479 return new PNaClABIVerifyModule(Reporter, StreamingMode); | 484 return new PNaClABIVerifyModule(Reporter, StreamingMode); |
| 480 } | 485 } |
| OLD | NEW |