Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: lib/Analysis/NaCl/PNaClABIVerifyModule.cpp

Issue 17777004: Concurrency support for PNaCl ABI (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Missed one cleanup file. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/StringMap.h" 17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/Twine.h" 18 #include "llvm/ADT/Twine.h"
19 #include "llvm/Analysis/NaCl.h" 19 #include "llvm/Analysis/NaCl.h"
20 #include "llvm/IR/Constants.h" 20 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DerivedTypes.h" 21 #include "llvm/IR/DerivedTypes.h"
22 #include "llvm/IR/Instructions.h"
22 #include "llvm/IR/Intrinsics.h" 23 #include "llvm/IR/Intrinsics.h"
23 #include "llvm/IR/Module.h" 24 #include "llvm/IR/Module.h"
25 #include "llvm/Pass.h"
24 #include "llvm/Support/Debug.h" 26 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/raw_ostream.h" 27 #include "llvm/Support/raw_ostream.h"
26 28
27 #include "PNaClABITypeChecker.h" 29 #include "PNaClABITypeChecker.h"
28 using namespace llvm; 30 using namespace llvm;
29 31
30 namespace llvm { 32 namespace llvm {
31 cl::opt<bool> 33 cl::opt<bool>
32 PNaClABIAllowDebugMetadata("pnaclabi-allow-debug-metadata", 34 PNaClABIAllowDebugMetadata("pnaclabi-allow-debug-metadata",
33 cl::desc("Allow debug metadata during PNaCl ABI verification."), 35 cl::desc("Allow debug metadata during PNaCl ABI verification."),
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // definitions, but that should be done by user-toolchain 168 // definitions, but that should be done by user-toolchain
167 // optimization passes, not by the PNaCl translator. 169 // optimization passes, not by the PNaCl translator.
168 if (GV->hasUnnamedAddr()) { 170 if (GV->hasUnnamedAddr()) {
169 Reporter->addError() << GVTypeName << GV->getName() 171 Reporter->addError() << GVTypeName << GV->getName()
170 << " has disallowed \"unnamed_addr\" attribute\n"; 172 << " has disallowed \"unnamed_addr\" attribute\n";
171 } 173 }
172 } 174 }
173 175
174 AllowedIntrinsics::AllowedIntrinsics(LLVMContext *Context) : Context(Context) { 176 AllowedIntrinsics::AllowedIntrinsics(LLVMContext *Context) : Context(Context) {
175 Type *I8Ptr = Type::getInt8PtrTy(*Context); 177 Type *I8Ptr = Type::getInt8PtrTy(*Context);
178 Type *I8 = Type::getInt8Ty(*Context);
176 Type *I16 = Type::getInt16Ty(*Context); 179 Type *I16 = Type::getInt16Ty(*Context);
177 Type *I32 = Type::getInt32Ty(*Context); 180 Type *I32 = Type::getInt32Ty(*Context);
178 Type *I64 = Type::getInt64Ty(*Context); 181 Type *I64 = Type::getInt64Ty(*Context);
179 182
180 // We accept bswap for a limited set of types (i16, i32, i64). The 183 // We accept bswap for a limited set of types (i16, i32, i64). The
181 // various backends are able to generate instructions to implement 184 // various backends are able to generate instructions to implement
182 // the intrinsic. Also, i16 and i64 are easy to implement as along 185 // the intrinsic. Also, i16 and i64 are easy to implement as along
183 // as there is a way to do i32. 186 // as there is a way to do i32.
184 addIntrinsic(Intrinsic::bswap, I16); 187 addIntrinsic(Intrinsic::bswap, I16);
185 addIntrinsic(Intrinsic::bswap, I32); 188 addIntrinsic(Intrinsic::bswap, I32);
186 addIntrinsic(Intrinsic::bswap, I64); 189 addIntrinsic(Intrinsic::bswap, I64);
187 190
188 // We accept cttz, ctlz, and ctpop for a limited set of types (i32, i64). 191 // We accept cttz, ctlz, and ctpop for a limited set of types (i32, i64).
189 addIntrinsic(Intrinsic::ctlz, I32); 192 addIntrinsic(Intrinsic::ctlz, I32);
190 addIntrinsic(Intrinsic::ctlz, I64); 193 addIntrinsic(Intrinsic::ctlz, I64);
191 addIntrinsic(Intrinsic::cttz, I32); 194 addIntrinsic(Intrinsic::cttz, I32);
192 addIntrinsic(Intrinsic::cttz, I64); 195 addIntrinsic(Intrinsic::cttz, I64);
193 addIntrinsic(Intrinsic::ctpop, I32); 196 addIntrinsic(Intrinsic::ctpop, I32);
194 addIntrinsic(Intrinsic::ctpop, I64); 197 addIntrinsic(Intrinsic::ctpop, I64);
195 198
196 addIntrinsic(Intrinsic::nacl_read_tp); 199 addIntrinsic(Intrinsic::nacl_read_tp);
197 addIntrinsic(Intrinsic::nacl_longjmp); 200 addIntrinsic(Intrinsic::nacl_longjmp);
198 addIntrinsic(Intrinsic::nacl_setjmp); 201 addIntrinsic(Intrinsic::nacl_setjmp);
199 202
203 Type *AtomicTypes[] = { I8, I16, I32, I64 };
204 for (Type **T = &AtomicTypes[0], **E = T + array_lengthof(AtomicTypes);
205 T != E; ++T) {
206 addIntrinsic(Intrinsic::nacl_atomic_load, *T);
207 addIntrinsic(Intrinsic::nacl_atomic_store, *T);
208 addIntrinsic(Intrinsic::nacl_atomic_rmw, *T);
209 addIntrinsic(Intrinsic::nacl_atomic_cmpxchg, *T);
210 }
211 addIntrinsic(Intrinsic::nacl_atomic_fence);
212
200 // Stack save and restore are used to support C99 VLAs. 213 // Stack save and restore are used to support C99 VLAs.
201 addIntrinsic(Intrinsic::stacksave); 214 addIntrinsic(Intrinsic::stacksave);
202 addIntrinsic(Intrinsic::stackrestore); 215 addIntrinsic(Intrinsic::stackrestore);
203 216
204 addIntrinsic(Intrinsic::trap); 217 addIntrinsic(Intrinsic::trap);
205 218
206 // We only allow the variants of memcpy/memmove/memset with an i32 219 // We only allow the variants of memcpy/memmove/memset with an i32
207 // "len" argument, not an i64 argument. 220 // "len" argument, not an i64 argument.
208 Type *MemcpyTypes[] = { I8Ptr, I8Ptr, I32 }; 221 Type *MemcpyTypes[] = { I8Ptr, I8Ptr, I32 };
209 addIntrinsic(Intrinsic::memcpy, MemcpyTypes); 222 addIntrinsic(Intrinsic::memcpy, MemcpyTypes);
210 addIntrinsic(Intrinsic::memmove, MemcpyTypes); 223 addIntrinsic(Intrinsic::memmove, MemcpyTypes);
211 Type *MemsetTypes[] = { I8Ptr, I32 }; 224 Type *MemsetTypes[] = { I8Ptr, I32 };
212 addIntrinsic(Intrinsic::memset, MemsetTypes); 225 addIntrinsic(Intrinsic::memset, MemsetTypes);
213 } 226 }
214 227
215 bool AllowedIntrinsics::isAllowed(const Function *Func) { 228 bool AllowedIntrinsics::isAllowed(const Function *Func) {
216 // Keep 3 categories of intrinsics for now. 229 // Keep 3 categories of intrinsics for now.
217 // (1) Allowed always, provided the exact name and type match. 230 // (1) Allowed always, provided the exact name and type match.
218 // (2) Never allowed 231 // (2) Never allowed.
219 // (3) "Dev" intrinsics, which may or may not be allowed. 232 // (3) "Dev" intrinsics, which may or may not be allowed.
220 // "Dev" intrinsics are controlled by the PNaClABIAllowDevIntrinsics flag. 233 // "Dev" intrinsics are controlled by the PNaClABIAllowDevIntrinsics flag.
221 // Please keep these sorted or grouped in a sensible way, within 234 // Please keep these sorted or grouped in a sensible way, within
222 // each category. 235 // each category.
223 236
224 // (1) Allowed always, provided the exact name and type match. 237 // (1) Allowed always, provided the exact name and type match.
225 if (Mapping.count(Func->getName()) == 1) 238 if (Mapping.count(Func->getName()) == 1)
226 return Func->getFunctionType() == Mapping[Func->getName()]; 239 return Func->getFunctionType() == Mapping[Func->getName()];
227 240
228 switch (Func->getIntrinsicID()) { 241 switch (Func->getIntrinsicID()) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 515 }
503 516
504 char PNaClABIVerifyModule::ID = 0; 517 char PNaClABIVerifyModule::ID = 0;
505 INITIALIZE_PASS(PNaClABIVerifyModule, "verify-pnaclabi-module", 518 INITIALIZE_PASS(PNaClABIVerifyModule, "verify-pnaclabi-module",
506 "Verify module for PNaCl", false, true) 519 "Verify module for PNaCl", false, true)
507 520
508 ModulePass *llvm::createPNaClABIVerifyModulePass( 521 ModulePass *llvm::createPNaClABIVerifyModulePass(
509 PNaClABIErrorReporter *Reporter, bool StreamingMode) { 522 PNaClABIErrorReporter *Reporter, bool StreamingMode) {
510 return new PNaClABIVerifyModule(Reporter, StreamingMode); 523 return new PNaClABIVerifyModule(Reporter, StreamingMode);
511 } 524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698