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

Side by Side Diff: src/llvm2ice.cpp

Issue 321993002: Add a few Subzero intrinsics (not the atomic ones yet). (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: bitwise sideeffects Created 6 years, 6 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 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
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 // This file defines a driver that uses LLVM capabilities to parse a 10 // This file defines a driver that uses LLVM capabilities to parse a
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 519 }
520 return Switch; 520 return Switch;
521 } 521 }
522 522
523 Ice::Inst *convertCallInstruction(const CallInst *Inst) { 523 Ice::Inst *convertCallInstruction(const CallInst *Inst) {
524 Ice::Variable *Dest = mapValueToIceVar(Inst); 524 Ice::Variable *Dest = mapValueToIceVar(Inst);
525 Ice::Operand *CallTarget = convertValue(Inst->getCalledValue()); 525 Ice::Operand *CallTarget = convertValue(Inst->getCalledValue());
526 unsigned NumArgs = Inst->getNumArgOperands(); 526 unsigned NumArgs = Inst->getNumArgOperands();
527 // Note: Subzero doesn't (yet) do anything special with the Tail 527 // Note: Subzero doesn't (yet) do anything special with the Tail
528 // flag in the bitcode, i.e. CallInst::isTailCall(). 528 // flag in the bitcode, i.e. CallInst::isTailCall().
529 Ice::InstCall *NewInst = 529 Ice::InstCall *NewInst = NULL;
530 Ice::InstCall::create(Func, NumArgs, Dest, CallTarget); 530 const Ice::Intrinsics::FullIntrinsicInfo *Info = NULL;
531
532 if (Ice::ConstantRelocatable *Target =
533 llvm::dyn_cast<Ice::ConstantRelocatable>(CallTarget)) {
534 // Check if this direct call is to an Intrinsic (starts with "llvm.")
535 static const char LLVMPrefix[] = "llvm.";
536 const size_t LLVMPrefixLen = strlen(LLVMPrefix);
537 Ice::IceString Name = Target->getName();
538 if (Name.substr(0, LLVMPrefixLen) == LLVMPrefix) {
539 Ice::IceString NameSuffix = Name.substr(LLVMPrefixLen);
540 Info = Ctx->getIntrinsicsInfo().find(NameSuffix);
541 if (!Info) {
542 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") +
543 LLVMObjectAsString(Inst));
544 }
545 NewInst = Ice::InstIntrinsicCall::create(Func, NumArgs, Dest,
546 CallTarget, Info->Info);
547 }
548 }
549
550 // Not an intrinsic call.
551 if (NewInst == NULL) {
552 NewInst = Ice::InstCall::create(Func, NumArgs, Dest, CallTarget);
553 }
531 for (unsigned i = 0; i < NumArgs; ++i) { 554 for (unsigned i = 0; i < NumArgs; ++i) {
532 NewInst->addArg(convertOperand(Inst, i)); 555 NewInst->addArg(convertOperand(Inst, i));
533 } 556 }
557 if (Info) {
558 validateIntrinsicCall(NewInst, Info);
559 }
534 return NewInst; 560 return NewInst;
535 } 561 }
536 562
537 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) { 563 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) {
538 // PNaCl bitcode only contains allocas of byte-granular objects. 564 // PNaCl bitcode only contains allocas of byte-granular objects.
539 Ice::Operand *ByteCount = convertValue(Inst->getArraySize()); 565 Ice::Operand *ByteCount = convertValue(Inst->getArraySize());
540 uint32_t Align = Inst->getAlignment(); 566 uint32_t Align = Inst->getAlignment();
541 Ice::Variable *Dest = mapValueToIceVar(Inst, SubzeroPointerType); 567 Ice::Variable *Dest = mapValueToIceVar(Inst, SubzeroPointerType);
542 568
543 return Ice::InstAlloca::create(Func, ByteCount, Align, Dest); 569 return Ice::InstAlloca::create(Func, ByteCount, Align, Dest);
544 } 570 }
545 571
546 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) { 572 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) {
547 return Ice::InstUnreachable::create(Func); 573 return Ice::InstUnreachable::create(Func);
548 } 574 }
549 575
550 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { 576 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) {
551 Ice::CfgNode *Node = mapBasicBlockToNode(BB); 577 Ice::CfgNode *Node = mapBasicBlockToNode(BB);
552 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end(); 578 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end();
553 II != II_e; ++II) { 579 II != II_e; ++II) {
554 Ice::Inst *Inst = convertInstruction(II); 580 Ice::Inst *Inst = convertInstruction(II);
555 Node->appendInst(Inst); 581 Node->appendInst(Inst);
556 } 582 }
557 return Node; 583 return Node;
558 } 584 }
559 585
586 void validateIntrinsicCall(const Ice::InstCall *Call,
587 const Ice::Intrinsics::FullIntrinsicInfo *I) {
588 assert(I->NumTypes >= 1);
589 if (I->Signature[0] == Ice::IceType_void) {
590 if (Call->getDest() != NULL) {
591 report_fatal_error(
592 "Return value for intrinsic func w/ void return type.");
593 }
594 } else {
595 if (I->Signature[0] != Call->getDest()->getType()) {
596 report_fatal_error("Mismatched return types.");
597 }
598 }
599 if (Call->getNumArgs() + 1 != I->NumTypes) {
600 std::cerr << "Call->getNumArgs() " << (int)Call->getNumArgs()
601 << " I->NumTypes " << (int)I->NumTypes << "\n";
602 report_fatal_error("Mismatched # of args.");
603 }
604 for (size_t i = 1; i < I->NumTypes; ++i) {
605 if (Call->getArg(i - 1)->getType() != I->Signature[i]) {
606 report_fatal_error("Mismatched argument type.");
607 }
608 }
609 }
610
560 private: 611 private:
561 // Data 612 // Data
562 Ice::GlobalContext *Ctx; 613 Ice::GlobalContext *Ctx;
563 Ice::Cfg *Func; 614 Ice::Cfg *Func;
564 Ice::CfgNode *CurrentNode; 615 Ice::CfgNode *CurrentNode;
565 Ice::Type SubzeroPointerType; 616 Ice::Type SubzeroPointerType;
566 std::map<const Value *, Ice::Variable *> VarMap; 617 std::map<const Value *, Ice::Variable *> VarMap;
567 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; 618 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap;
568 }; 619 };
569 620
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 << " sec\n"; 776 << " sec\n";
726 } 777 }
727 } 778 }
728 } 779 }
729 780
730 if (!DisableTranslation && Func) 781 if (!DisableTranslation && Func)
731 Func->getTarget()->emitConstants(); 782 Func->getTarget()->emitConstants();
732 783
733 return ExitStatus; 784 return ExitStatus;
734 } 785 }
OLDNEW
« src/IceTargetLoweringX8632.cpp ('K') | « src/IceTargetLoweringX8632.cpp ('k') | szdiff.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698