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

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

Powered by Google App Engine
This is Rietveld 408576698