llvm.org GIT mirror llvm / 40a0421
Add GetResultInst. First step for multiple return value support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47348 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 12 years ago
6 changed file(s) with 88 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
163163 HANDLE_OTHER_INST(48, ExtractElement, ExtractElementInst)// extract from vector.
164164 HANDLE_OTHER_INST(49, InsertElement, InsertElementInst) // insert into vector
165165 HANDLE_OTHER_INST(50, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
166 LAST_OTHER_INST(50)
166 HANDLE_OTHER_INST(51, GetResult, GetResultInst) // Extract individual value
167 //from aggregate result
168 LAST_OTHER_INST(51)
167169
168170 #undef FIRST_TERM_INST
169171 #undef HANDLE_TERM_INST
23392339 }
23402340 };
23412341
2342 //===----------------------------------------------------------------------===//
2343 // GetResultInst Class
2344 //===----------------------------------------------------------------------===//
2345
2346 /// GetResultInst - This instruction extracts individual result value from
2347 /// aggregate value, where aggregate value is returned by CallInst.
2348 ///
2349 class GetResultInst : public Instruction {
2350 Use Ops[2];
2351 GetResultInst(const GetResultInst &GRI) :
2352 Instruction(GRI.getType(), Instruction::GetResult, Ops, 2) {
2353 Ops[0].init(GRI.Ops[0], this);
2354 Ops[1].init(GRI.Ops[1], this);
2355 }
2356
2357 public:
2358 explicit GetResultInst(Value *Aggr, Value *Index,
2359 const std::string &Name = "",
2360 Instruction *InsertBefore = 0);
2361
2362 /// isValidOperands - Return true if an getresult instruction can be
2363 /// formed with the specified operands.
2364 static bool isValidOperands(const Value *Aggr, const Value *Idx);
2365
2366 virtual GetResultInst *clone() const;
2367
2368 // getType - Get aggregate value element type
2369 inline const Type *getType() const {
2370 return Ops[0]->getType();
2371 }
2372
2373 Value *getAggregateValue() {
2374 return getOperand(0);
2375 }
2376 const Value *geIndex() {
2377 return getOperand(1);
2378 }
2379
2380 unsigned getNumOperands() const { return 2; }
2381
2382 // Methods for support type inquiry through isa, cast, and dyn_cast:
2383 static inline bool classof(const GetResultInst *) { return true; }
2384 static inline bool classof(const Instruction *I) {
2385 return (I->getOpcode() == Instruction::GetResult);
2386 }
2387 static inline bool classof(const Value *V) {
2388 return isa(V) && classof(cast(V));
2389 }
2390 };
2391
23422392 } // End llvm namespace
23432393
23442394 #endif
193193 RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
194194 RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction); }
195195 RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction); }
196 RetTy visitGetResultInst(GetResultInst &I) { DELEGATE(Instruction); }
196197
197198 // Next level propagators... if the user does not overload a specific
198199 // instruction type, they can overload one of these to get the whole class
606606 void visitVACopy(CallInst &I);
607607
608608 void visitMemIntrinsic(CallInst &I, unsigned Op);
609
610 void visitGetResult(GetResultInst &I) {
611 // FIXME
612 }
609613
610614 void visitUserOp1(Instruction &I) {
611615 assert(0 && "UserOp1 should not exist at instruction selection time!");
26972697 setSuccessor(idx, B);
26982698 }
26992699
2700 //===----------------------------------------------------------------------===//
2701 // GetResultInst Implementation
2702 //===----------------------------------------------------------------------===//
2703
2704 GetResultInst::GetResultInst(Value *Aggr, Value *Index,
2705 const std::string &Name,
2706 Instruction *InsertBef)
2707 : Instruction(Aggr->getType(),
2708 GetResult, Ops, 2, InsertBef) {
2709 assert(isValidOperands(Aggr, Index) && "Invalid GetResultInst operands!");
2710 Ops[0].init(Aggr, this);
2711 Ops[1].init(Index, this);
2712 setName(Name);
2713 }
2714
2715 bool GetResultInst::isValidOperands(const Value *Aggr, const Value *Index) {
2716 if (!Aggr || !Index)
2717 return false;
2718 if (!isa(Aggr->getType()) || Index->getType() != Type::Int32Ty)
2719 return false;
2720 return true;
2721 }
2722
27002723
27012724 // Define these methods here so vtables don't get emitted into every translation
27022725 // unit that uses these classes.
27532776 InvokeInst *InvokeInst::clone() const { return new InvokeInst(*this); }
27542777 UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
27552778 UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
2779 GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); }
256256 void visitUserOp2(Instruction &I) { visitUserOp1(I); }
257257 void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI);
258258 void visitAllocationInst(AllocationInst &AI);
259 void visitGetResultInst(GetResultInst &GRI);
259260
260261 void VerifyCallSite(CallSite CS);
261262 void VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
10341035 Assert(Ptr->getAddressSpace() == 0,
10351036 "Allocation instruction pointer not in the generic address space!");
10361037 visitInstruction(AI);
1038 }
1039
1040 void Verifier::visitGetResultInst(GetResultInst &GRI) {
1041 // FIXME : Check operands.
1042 visitInstruction(GRI);
10371043 }
10381044
10391045