comparison lib/Target/NVPTX/NVPTXUtilities.cpp @ 95:afa8332a0e37 LLVM3.8

LLVM 3.8
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 13 Oct 2015 17:48:58 +0900
parents 60c9769439b8
children 7d135dc70f03
comparison
equal deleted inserted replaced
84:f3e34b893a5f 95:afa8332a0e37
291 291
292 bool llvm::isKernelFunction(const Function &F) { 292 bool llvm::isKernelFunction(const Function &F) {
293 unsigned x = 0; 293 unsigned x = 0;
294 bool retval = llvm::findOneNVVMAnnotation( 294 bool retval = llvm::findOneNVVMAnnotation(
295 &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_ISKERNEL_FUNCTION], x); 295 &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_ISKERNEL_FUNCTION], x);
296 if (retval == false) { 296 if (!retval) {
297 // There is no NVVM metadata, check the calling convention 297 // There is no NVVM metadata, check the calling convention
298 if (F.getCallingConv() == llvm::CallingConv::PTX_Kernel) 298 return F.getCallingConv() == llvm::CallingConv::PTX_Kernel;
299 return true;
300 else
301 return false;
302 } 299 }
303 return (x == 1); 300 return (x == 1);
304 } 301 }
305 302
306 bool llvm::getAlign(const Function &F, unsigned index, unsigned &align) { 303 bool llvm::getAlign(const Function &F, unsigned index, unsigned &align) {
307 std::vector<unsigned> Vs; 304 std::vector<unsigned> Vs;
308 bool retval = llvm::findAllNVVMAnnotation( 305 bool retval = llvm::findAllNVVMAnnotation(
309 &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_ALIGN], Vs); 306 &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_ALIGN], Vs);
310 if (retval == false) 307 if (!retval)
311 return false; 308 return false;
312 for (int i = 0, e = Vs.size(); i < e; i++) { 309 for (int i = 0, e = Vs.size(); i < e; i++) {
313 unsigned v = Vs[i]; 310 unsigned v = Vs[i];
314 if ((v >> 16) == index) { 311 if ((v >> 16) == index) {
315 align = v & 0xFFFF; 312 align = v & 0xFFFF;
337 } 334 }
338 return false; 335 return false;
339 } 336 }
340 337
341 bool llvm::isBarrierIntrinsic(Intrinsic::ID id) { 338 bool llvm::isBarrierIntrinsic(Intrinsic::ID id) {
342 if ((id == Intrinsic::nvvm_barrier0) || 339 return (id == Intrinsic::nvvm_barrier0) ||
343 (id == Intrinsic::nvvm_barrier0_popc) || 340 (id == Intrinsic::nvvm_barrier0_popc) ||
344 (id == Intrinsic::nvvm_barrier0_and) || 341 (id == Intrinsic::nvvm_barrier0_and) ||
345 (id == Intrinsic::nvvm_barrier0_or) || 342 (id == Intrinsic::nvvm_barrier0_or) ||
346 (id == Intrinsic::cuda_syncthreads)) 343 (id == Intrinsic::cuda_syncthreads);
347 return true;
348 return false;
349 } 344 }
350 345
351 // Interface for checking all memory space transfer related intrinsics 346 // Interface for checking all memory space transfer related intrinsics
352 bool llvm::isMemorySpaceTransferIntrinsic(Intrinsic::ID id) { 347 bool llvm::isMemorySpaceTransferIntrinsic(Intrinsic::ID id) {
353 if (id == Intrinsic::nvvm_ptr_local_to_gen || 348 return id == Intrinsic::nvvm_ptr_local_to_gen ||
354 id == Intrinsic::nvvm_ptr_shared_to_gen || 349 id == Intrinsic::nvvm_ptr_shared_to_gen ||
355 id == Intrinsic::nvvm_ptr_global_to_gen || 350 id == Intrinsic::nvvm_ptr_global_to_gen ||
356 id == Intrinsic::nvvm_ptr_constant_to_gen || 351 id == Intrinsic::nvvm_ptr_constant_to_gen ||
357 id == Intrinsic::nvvm_ptr_gen_to_global || 352 id == Intrinsic::nvvm_ptr_gen_to_global ||
358 id == Intrinsic::nvvm_ptr_gen_to_shared || 353 id == Intrinsic::nvvm_ptr_gen_to_shared ||
359 id == Intrinsic::nvvm_ptr_gen_to_local || 354 id == Intrinsic::nvvm_ptr_gen_to_local ||
360 id == Intrinsic::nvvm_ptr_gen_to_constant || 355 id == Intrinsic::nvvm_ptr_gen_to_constant ||
361 id == Intrinsic::nvvm_ptr_gen_to_param) { 356 id == Intrinsic::nvvm_ptr_gen_to_param;
362 return true;
363 }
364
365 return false;
366 } 357 }
367 358
368 // consider several special intrinsics in striping pointer casts, and 359 // consider several special intrinsics in striping pointer casts, and
369 // provide an option to ignore GEP indicies for find out the base address only 360 // provide an option to ignore GEP indices for find out the base address only
370 // which could be used in simple alias disambigurate. 361 // which could be used in simple alias disambiguation.
371 const Value * 362 const Value *
372 llvm::skipPointerTransfer(const Value *V, bool ignore_GEP_indices) { 363 llvm::skipPointerTransfer(const Value *V, bool ignore_GEP_indices) {
373 V = V->stripPointerCasts(); 364 V = V->stripPointerCasts();
374 while (true) { 365 while (true) {
375 if (const IntrinsicInst *IS = dyn_cast<IntrinsicInst>(V)) { 366 if (const IntrinsicInst *IS = dyn_cast<IntrinsicInst>(V)) {
386 } 377 }
387 return V; 378 return V;
388 } 379 }
389 380
390 // consider several special intrinsics in striping pointer casts, and 381 // consider several special intrinsics in striping pointer casts, and
391 // - ignore GEP indicies for find out the base address only, and 382 // - ignore GEP indices for find out the base address only, and
392 // - tracking PHINode 383 // - tracking PHINode
393 // which could be used in simple alias disambigurate. 384 // which could be used in simple alias disambiguation.
394 const Value * 385 const Value *
395 llvm::skipPointerTransfer(const Value *V, std::set<const Value *> &processed) { 386 llvm::skipPointerTransfer(const Value *V, std::set<const Value *> &processed) {
396 if (processed.find(V) != processed.end()) 387 if (processed.find(V) != processed.end())
397 return nullptr; 388 return nullptr;
398 processed.insert(V); 389 processed.insert(V);
435 break; 426 break;
436 } 427 }
437 return V; 428 return V;
438 } 429 }
439 430
440 // The following are some useful utilities for debuggung 431 // The following are some useful utilities for debugging
441 432
442 BasicBlock *llvm::getParentBlock(Value *v) { 433 BasicBlock *llvm::getParentBlock(Value *v) {
443 if (BasicBlock *B = dyn_cast<BasicBlock>(v)) 434 if (BasicBlock *B = dyn_cast<BasicBlock>(v))
444 return B; 435 return B;
445 436
491 } 482 }
492 483
493 return nullptr; 484 return nullptr;
494 } 485 }
495 486
496 // Dump an instruction by nane 487 // Dump an instruction by name
497 void llvm::dumpInst(Value *base, char *instName) { 488 void llvm::dumpInst(Value *base, char *instName) {
498 Instruction *I = getInst(base, instName); 489 Instruction *I = getInst(base, instName);
499 if (I) 490 if (I)
500 I->dump(); 491 I->dump();
501 } 492 }