OLD | NEW |
1 //===- PNaClABIVerifyFunctions.cpp - Verify PNaCl ABI rules ---------------===// | 1 //===- PNaClABIVerifyFunctions.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 function-level PNaCl ABI requirements. | 10 // Verify function-level PNaCl ABI requirements. |
11 // | 11 // |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "llvm/Analysis/NaCl/PNaClABIVerifyFunctions.h" | 15 #include "llvm/Analysis/NaCl/PNaClABIVerifyFunctions.h" |
16 #include "llvm/ADT/Twine.h" | 16 #include "llvm/ADT/Twine.h" |
17 #include "llvm/Analysis/NaCl.h" | 17 #include "llvm/Analysis/NaCl.h" |
18 #include "llvm/Analysis/NaCl/PNaClABITypeChecker.h" | 18 #include "llvm/Analysis/NaCl/PNaClABITypeChecker.h" |
| 19 #include "llvm/Analysis/NaCl/PNaClAllowedIntrinsics.h" |
19 #include "llvm/IR/Function.h" | 20 #include "llvm/IR/Function.h" |
20 #include "llvm/IR/Instructions.h" | 21 #include "llvm/IR/Instructions.h" |
21 #include "llvm/IR/IntrinsicInst.h" | 22 #include "llvm/IR/IntrinsicInst.h" |
22 #include "llvm/IR/LLVMContext.h" | 23 #include "llvm/IR/LLVMContext.h" |
23 #include "llvm/IR/Metadata.h" | 24 #include "llvm/IR/Metadata.h" |
24 #include "llvm/IR/Operator.h" | 25 #include "llvm/IR/Operator.h" |
25 #include "llvm/Support/raw_ostream.h" | 26 #include "llvm/Support/raw_ostream.h" |
26 | 27 |
27 using namespace llvm; | 28 using namespace llvm; |
28 | 29 |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return "inline assembly"; | 432 return "inline assembly"; |
432 if (!Call->getAttributes().isEmpty()) | 433 if (!Call->getAttributes().isEmpty()) |
433 return "bad call attributes"; | 434 return "bad call attributes"; |
434 if (!PNaClABIProps::isValidCallingConv(Call->getCallingConv())) | 435 if (!PNaClABIProps::isValidCallingConv(Call->getCallingConv())) |
435 return "bad calling convention"; | 436 return "bad calling convention"; |
436 | 437 |
437 // Intrinsic calls can have multiple pointer arguments and | 438 // Intrinsic calls can have multiple pointer arguments and |
438 // metadata arguments, so handle them specially. | 439 // metadata arguments, so handle them specially. |
439 // TODO(kschimpf) How can we lift this to pnacl-bcdis. | 440 // TODO(kschimpf) How can we lift this to pnacl-bcdis. |
440 if (const IntrinsicInst *Call = dyn_cast<IntrinsicInst>(Inst)) { | 441 if (const IntrinsicInst *Call = dyn_cast<IntrinsicInst>(Inst)) { |
| 442 if (PNaClAllowedIntrinsics::isAllowedDebugInfoIntrinsic( |
| 443 Call->getIntrinsicID())) { |
| 444 // If debug metadata is allowed, always allow calling debug intrinsics |
| 445 // and assume they are correct. |
| 446 return nullptr; |
| 447 } |
441 for (unsigned ArgNum = 0, E = Call->getNumArgOperands(); | 448 for (unsigned ArgNum = 0, E = Call->getNumArgOperands(); |
442 ArgNum < E; ++ArgNum) { | 449 ArgNum < E; ++ArgNum) { |
443 const Value *Arg = Call->getArgOperand(ArgNum); | 450 const Value *Arg = Call->getArgOperand(ArgNum); |
444 if (!(isValidScalarOperand(Arg) || | 451 if (!(isValidScalarOperand(Arg) || |
445 isValidVectorOperand(Arg) || | 452 isValidVectorOperand(Arg) || |
446 isNormalizedPtr(Arg) || | 453 isNormalizedPtr(Arg))) |
447 isa<MDNode>(Arg))) | |
448 return "bad intrinsic operand"; | 454 return "bad intrinsic operand"; |
449 } | 455 } |
450 | 456 |
451 // Disallow alignments other than 1 on memcpy() etc., for the | 457 // Disallow alignments other than 1 on memcpy() etc., for the |
452 // same reason that we disallow them on integer loads and | 458 // same reason that we disallow them on integer loads and |
453 // stores. | 459 // stores. |
454 if (const MemIntrinsic *MemOp = dyn_cast<MemIntrinsic>(Call)) { | 460 if (const MemIntrinsic *MemOp = dyn_cast<MemIntrinsic>(Call)) { |
455 // Avoid the getAlignment() method here because it aborts if | 461 // Avoid the getAlignment() method here because it aborts if |
456 // the alignment argument is not a Constant. | 462 // the alignment argument is not a Constant. |
457 Value *AlignArg = MemOp->getArgOperand(3); | 463 Value *AlignArg = MemOp->getArgOperand(3); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 dyn_cast<PossiblyExactOperator>(Inst)) { | 560 dyn_cast<PossiblyExactOperator>(Inst)) { |
555 if (Op->isExact()) | 561 if (Op->isExact()) |
556 return "has \"exact\" attribute"; | 562 return "has \"exact\" attribute"; |
557 } | 563 } |
558 | 564 |
559 // Allow the instruction. | 565 // Allow the instruction. |
560 return NULL; | 566 return NULL; |
561 } | 567 } |
562 | 568 |
563 bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { | 569 bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { |
564 const DataLayout *DL = &getAnalysis<DataLayoutPass>().getDataLayout(); | 570 const DataLayout *DL = &F.getParent()->getDataLayout(); |
565 SmallVector<StringRef, 8> MDNames; | 571 SmallVector<StringRef, 8> MDNames; |
566 F.getContext().getMDKindNames(MDNames); | 572 F.getContext().getMDKindNames(MDNames); |
567 | 573 |
568 for (Function::const_iterator FI = F.begin(), FE = F.end(); | 574 for (Function::const_iterator FI = F.begin(), FE = F.end(); |
569 FI != FE; ++FI) { | 575 FI != FE; ++FI) { |
570 for (BasicBlock::const_iterator BBI = FI->begin(), BBE = FI->end(); | 576 for (BasicBlock::const_iterator BBI = FI->begin(), BBE = FI->end(); |
571 BBI != BBE; ++BBI) { | 577 BBI != BBE; ++BBI) { |
572 const Instruction *Inst = BBI; | 578 const Instruction *Inst = BBI; |
573 // Check the instruction opcode first. This simplifies testing, | 579 // Check the instruction opcode first. This simplifies testing, |
574 // because some instruction opcodes must be rejected out of hand | 580 // because some instruction opcodes must be rejected out of hand |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 } | 626 } |
621 | 627 |
622 char PNaClABIVerifyFunctions::ID = 0; | 628 char PNaClABIVerifyFunctions::ID = 0; |
623 INITIALIZE_PASS(PNaClABIVerifyFunctions, "verify-pnaclabi-functions", | 629 INITIALIZE_PASS(PNaClABIVerifyFunctions, "verify-pnaclabi-functions", |
624 "Verify functions for PNaCl", false, true) | 630 "Verify functions for PNaCl", false, true) |
625 | 631 |
626 FunctionPass *llvm::createPNaClABIVerifyFunctionsPass( | 632 FunctionPass *llvm::createPNaClABIVerifyFunctionsPass( |
627 PNaClABIErrorReporter *Reporter) { | 633 PNaClABIErrorReporter *Reporter) { |
628 return new PNaClABIVerifyFunctions(Reporter); | 634 return new PNaClABIVerifyFunctions(Reporter); |
629 } | 635 } |
OLD | NEW |