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

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: Clarify documentation. 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 (size_t T = 0, E = array_lengthof(AtomicTypes); T != E; ++T) {
205 addIntrinsic(Intrinsic::nacl_atomic_load, AtomicTypes[T]);
206 addIntrinsic(Intrinsic::nacl_atomic_store, AtomicTypes[T]);
207 addIntrinsic(Intrinsic::nacl_atomic_rmw, AtomicTypes[T]);
208 addIntrinsic(Intrinsic::nacl_atomic_cmpxchg, AtomicTypes[T]);
209 }
210 addIntrinsic(Intrinsic::nacl_atomic_fence);
211
200 // Stack save and restore are used to support C99 VLAs. 212 // Stack save and restore are used to support C99 VLAs.
201 addIntrinsic(Intrinsic::stacksave); 213 addIntrinsic(Intrinsic::stacksave);
202 addIntrinsic(Intrinsic::stackrestore); 214 addIntrinsic(Intrinsic::stackrestore);
203 215
204 addIntrinsic(Intrinsic::trap); 216 addIntrinsic(Intrinsic::trap);
205 217
206 // We only allow the variants of memcpy/memmove/memset with an i32 218 // We only allow the variants of memcpy/memmove/memset with an i32
207 // "len" argument, not an i64 argument. 219 // "len" argument, not an i64 argument.
208 Type *MemcpyTypes[] = { I8Ptr, I8Ptr, I32 }; 220 Type *MemcpyTypes[] = { I8Ptr, I8Ptr, I32 };
209 addIntrinsic(Intrinsic::memcpy, MemcpyTypes); 221 addIntrinsic(Intrinsic::memcpy, MemcpyTypes);
210 addIntrinsic(Intrinsic::memmove, MemcpyTypes); 222 addIntrinsic(Intrinsic::memmove, MemcpyTypes);
211 Type *MemsetTypes[] = { I8Ptr, I32 }; 223 Type *MemsetTypes[] = { I8Ptr, I32 };
212 addIntrinsic(Intrinsic::memset, MemsetTypes); 224 addIntrinsic(Intrinsic::memset, MemsetTypes);
213 } 225 }
214 226
215 bool AllowedIntrinsics::isAllowed(const Function *Func) { 227 bool AllowedIntrinsics::isAllowed(const Function *Func) {
216 // Keep 3 categories of intrinsics for now. 228 // Keep 3 categories of intrinsics for now.
217 // (1) Allowed always, provided the exact name and type match. 229 // (1) Allowed always, provided the exact name and type match.
218 // (2) Never allowed 230 // (2) Never allowed.
219 // (3) "Dev" intrinsics, which may or may not be allowed. 231 // (3) "Dev" intrinsics, which may or may not be allowed.
220 // "Dev" intrinsics are controlled by the PNaClABIAllowDevIntrinsics flag. 232 // "Dev" intrinsics are controlled by the PNaClABIAllowDevIntrinsics flag.
221 // Please keep these sorted or grouped in a sensible way, within 233 // Please keep these sorted or grouped in a sensible way, within
222 // each category. 234 // each category.
223 235
224 // (1) Allowed always, provided the exact name and type match. 236 // (1) Allowed always, provided the exact name and type match.
225 if (Mapping.count(Func->getName()) == 1) 237 if (Mapping.count(Func->getName()) == 1)
226 return Func->getFunctionType() == Mapping[Func->getName()]; 238 return Func->getFunctionType() == Mapping[Func->getName()];
227 239
228 switch (Func->getIntrinsicID()) { 240 switch (Func->getIntrinsicID()) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 514 }
503 515
504 char PNaClABIVerifyModule::ID = 0; 516 char PNaClABIVerifyModule::ID = 0;
505 INITIALIZE_PASS(PNaClABIVerifyModule, "verify-pnaclabi-module", 517 INITIALIZE_PASS(PNaClABIVerifyModule, "verify-pnaclabi-module",
506 "Verify module for PNaCl", false, true) 518 "Verify module for PNaCl", false, true)
507 519
508 ModulePass *llvm::createPNaClABIVerifyModulePass( 520 ModulePass *llvm::createPNaClABIVerifyModulePass(
509 PNaClABIErrorReporter *Reporter, bool StreamingMode) { 521 PNaClABIErrorReporter *Reporter, bool StreamingMode) {
510 return new PNaClABIVerifyModule(Reporter, StreamingMode); 522 return new PNaClABIVerifyModule(Reporter, StreamingMode);
511 } 523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698