llvm.org GIT mirror llvm / 863dd88
Revert the premature portion of the last commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36542 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Spencer 13 years ago
1 changed file(s) with 76 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
138138 // GetForwardRefForGlobal - Check to see if there is a forward reference
139139 // for this global. If so, remove it from the GlobalRefs map and return it.
140140 // If not, just return null.
141 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ParamAttrsList *PAL,
142 ValID ID) {
141 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
143142 // Check to see if there is a forward reference to this global variable...
144143 // if there is, eliminate it and patch the reference to use the new def'n.
145144 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
146145 GlobalValue *Ret = 0;
147146 if (I != GlobalRefs.end()) {
148147 Ret = I->second;
149 if (PAL && isa(Ret))
150 Ret = cast(Ret)->getParamAttrs() == PAL ? Ret : 0;
151 if (Ret)
152 GlobalRefs.erase(I);
148 GlobalRefs.erase(I);
153149 }
154150 return Ret;
155151 }
747743 ID = ValID::createGlobalID(CurModule.Values.size());
748744 }
749745
750 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, 0, ID)) {
746 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
751747 // Move the global to the end of the list, from whereever it was
752748 // previously inserted.
753749 GlobalVariable *GV = cast(FWGV);
13271323 UR_OUT("New Upreference!\n");
13281324 CHECK_FOR_ERROR
13291325 }
1330 | Types '(' ArgTypeListI ')' {
1326 | Types '(' ArgTypeListI ')' OptFuncAttrs {
13311327 std::vector Params;
1328 ParamAttrsVector Attrs;
1329 if ($5 != ParamAttr::None) {
1330 ParamAttrsWithIndex X; X.index = 0; X.attrs = $5;
1331 Attrs.push_back(X);
1332 }
13321333 unsigned index = 1;
13331334 TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
13341335 for (; I != E; ++I, ++index) {
13351336 const Type *Ty = I->Ty->get();
13361337 Params.push_back(Ty);
1338 if (Ty != Type::VoidTy)
1339 if (I->Attrs != ParamAttr::None) {
1340 ParamAttrsWithIndex X; X.index = index; X.attrs = I->Attrs;
1341 Attrs.push_back(X);
1342 }
13371343 }
13381344 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
13391345 if (isVarArg) Params.pop_back();
13401346
1341 FunctionType *FT = FunctionType::get(*$1, Params, isVarArg);
1347 ParamAttrsList *ActualAttrs = 0;
1348 if (!Attrs.empty())
1349 ActualAttrs = ParamAttrsList::get(Attrs);
1350 FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, ActualAttrs);
13421351 delete $3; // Delete the argument list
13431352 delete $1; // Delete the return type handle
13441353 $$ = new PATypeHolder(HandleUpRefs(FT));
13451354 CHECK_FOR_ERROR
13461355 }
1347 | VOID '(' ArgTypeListI ')' {
1356 | VOID '(' ArgTypeListI ')' OptFuncAttrs {
13481357 std::vector Params;
1358 ParamAttrsVector Attrs;
1359 if ($5 != ParamAttr::None) {
1360 ParamAttrsWithIndex X; X.index = 0; X.attrs = $5;
1361 Attrs.push_back(X);
1362 }
13491363 TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
13501364 unsigned index = 1;
13511365 for ( ; I != E; ++I, ++index) {
13521366 const Type* Ty = I->Ty->get();
13531367 Params.push_back(Ty);
1368 if (Ty != Type::VoidTy)
1369 if (I->Attrs != ParamAttr::None) {
1370 ParamAttrsWithIndex X; X.index = index; X.attrs = I->Attrs;
1371 Attrs.push_back(X);
1372 }
13541373 }
13551374 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
13561375 if (isVarArg) Params.pop_back();
13571376
1358 FunctionType *FT = FunctionType::get($1, Params, isVarArg);
1377 ParamAttrsList *ActualAttrs = 0;
1378 if (!Attrs.empty())
1379 ActualAttrs = ParamAttrsList::get(Attrs);
1380
1381 FunctionType *FT = FunctionType::get($1, Params, isVarArg, ActualAttrs);
13591382 delete $3; // Delete the argument list
13601383 $$ = new PATypeHolder(HandleUpRefs(FT));
13611384 CHECK_FOR_ERROR
14091432 ;
14101433
14111434 ArgType
1412 : Types {
1435 : Types OptParamAttrs {
14131436 $$.Ty = $1;
1414 $$.Attrs = ParamAttr::None;
1437 $$.Attrs = $2;
14151438 }
14161439 ;
14171440
22162239 if (!Attrs.empty())
22172240 PAL = ParamAttrsList::get(Attrs);
22182241
2219 FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg);
2242 FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg, PAL);
22202243 const PointerType *PFT = PointerType::get(FT);
22212244 delete $2;
22222245
22292252
22302253 Function *Fn = 0;
22312254 // See if this function was forward referenced. If so, recycle the object.
2232 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, PAL, ID)) {
2255 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
22332256 // Move the function to the end of the list, from whereever it was
22342257 // previously inserted.
22352258 Fn = cast(FWRef);
22372260 CurModule.CurrentModule->getFunctionList().push_back(Fn);
22382261 } else if (!FunctionName.empty() && // Merge with an earlier prototype?
22392262 (Fn = CurModule.CurrentModule->getFunction(FunctionName))) {
2240 if (Fn->getFunctionType() != FT || PAL != Fn->getParamAttrs()) {
2263 if (Fn->getFunctionType() != FT) {
22412264 // The existing function doesn't have the same type. This is an overload
22422265 // error.
22432266 GEN_ERROR("Overload of function '" + FunctionName + "' not permitted.");
22542277 } else { // Not already defined?
22552278 Fn = new Function(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
22562279 CurModule.CurrentModule);
2257 Fn->setParamAttrs(PAL);
22582280
22592281 InsertValue(Fn, CurModule.Values);
22602282 }
25482570 !(Ty = dyn_cast(PFTy->getElementType()))) {
25492571 // Pull out the types of all of the arguments...
25502572 std::vector ParamTypes;
2573 ParamAttrsVector Attrs;
2574 if ($8 != ParamAttr::None) {
2575 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = 8;
2576 Attrs.push_back(PAWI);
2577 }
25512578 ValueRefList::iterator I = $6->begin(), E = $6->end();
2552 for (; I != E; ++I) {
2579 unsigned index = 1;
2580 for (; I != E; ++I, ++index) {
25532581 const Type *Ty = I->Val->getType();
25542582 if (Ty == Type::VoidTy)
25552583 GEN_ERROR("Short call syntax cannot be used with varargs");
25562584 ParamTypes.push_back(Ty);
2585 if (I->Attrs != ParamAttr::None) {
2586 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs;
2587 Attrs.push_back(PAWI);
2588 }
25572589 }
2558 Ty = FunctionType::get($3->get(), ParamTypes, false);
2590
2591 ParamAttrsList *PAL = 0;
2592 if (!Attrs.empty())
2593 PAL = ParamAttrsList::get(Attrs);
2594 Ty = FunctionType::get($3->get(), ParamTypes, false, PAL);
25592595 PFTy = PointerType::get(Ty);
25602596 }
25612597
25672603 CHECK_FOR_ERROR
25682604 BasicBlock *Except = getBBVal($14);
25692605 CHECK_FOR_ERROR
2570
2571 ParamAttrsVector Attrs;
2572 if ($8 != ParamAttr::None) {
2573 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = 8;
2574 Attrs.push_back(PAWI);
2575 }
25762606
25772607 // Check the arguments
25782608 ValueList Args;
25872617 FunctionType::param_iterator I = Ty->param_begin();
25882618 FunctionType::param_iterator E = Ty->param_end();
25892619 ValueRefList::iterator ArgI = $6->begin(), ArgE = $6->end();
2590 unsigned index = 1;
2620
25912621 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
25922622 if (ArgI->Val->getType() != *I)
25932623 GEN_ERROR("Parameter " + ArgI->Val->getName()+ " is not of type '" +
25942624 (*I)->getDescription() + "'");
25952625 Args.push_back(ArgI->Val);
2596 if (ArgI->Attrs != ParamAttr::None) {
2597 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = ArgI->Attrs;
2598 Attrs.push_back(PAWI);
2599 }
26002626 }
26012627
26022628 if (Ty->isVarArg()) {
26072633 GEN_ERROR("Invalid number of parameters detected");
26082634 }
26092635
2610 ParamAttrsList *PAL = 0;
2611 if (!Attrs.empty())
2612 PAL = ParamAttrsList::get(Attrs);
2613 if (isa(V))
2614 if (PAL != cast(V)->getParamAttrs())
2615 GEN_ERROR("Invalid parameter attributes for function invoked");
2616
26172636 // Create the InvokeInst
26182637 InvokeInst *II = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
26192638 II->setCallingConv($2);
2620 II->setParamAttrs(PAL);
26212639 $$ = II;
26222640 delete $6;
26232641 CHECK_FOR_ERROR
28622880 !(Ty = dyn_cast(PFTy->getElementType()))) {
28632881 // Pull out the types of all of the arguments...
28642882 std::vector ParamTypes;
2883 ParamAttrsVector Attrs;
2884 if ($8 != ParamAttr::None) {
2885 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = $8;
2886 Attrs.push_back(PAWI);
2887 }
2888 unsigned index = 1;
28652889 ValueRefList::iterator I = $6->begin(), E = $6->end();
2866 for (; I != E; ++I) {
2890 for (; I != E; ++I, ++index) {
28672891 const Type *Ty = I->Val->getType();
28682892 if (Ty == Type::VoidTy)
28692893 GEN_ERROR("Short call syntax cannot be used with varargs");
28702894 ParamTypes.push_back(Ty);
2895 if (I->Attrs != ParamAttr::None) {
2896 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs;
2897 Attrs.push_back(PAWI);
2898 }
28712899 }
2872 Ty = FunctionType::get($3->get(), ParamTypes, false);
2900
2901 ParamAttrsList *PAL = 0;
2902 if (!Attrs.empty())
2903 PAL = ParamAttrsList::get(Attrs);
2904
2905 Ty = FunctionType::get($3->get(), ParamTypes, false, PAL);
28732906 PFTy = PointerType::get(Ty);
28742907 }
28752908
28852918 theF->getName() + "'");
28862919 }
28872920
2888 // Set up the ParamAttrs for the function
2889 ParamAttrsVector Attrs;
2890 if ($8 != ParamAttr::None) {
2891 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = $8;
2892 Attrs.push_back(PAWI);
2893 }
28942921 // Check the arguments
28952922 ValueList Args;
28962923 if ($6->empty()) { // Has no arguments?
29002927 "expects arguments");
29012928 } else { // Has arguments?
29022929 // Loop through FunctionType's arguments and ensure they are specified
2903 // correctly. Also, gather any parameter attributes.
2930 // correctly!
2931 //
29042932 FunctionType::param_iterator I = Ty->param_begin();
29052933 FunctionType::param_iterator E = Ty->param_end();
29062934 ValueRefList::iterator ArgI = $6->begin(), ArgE = $6->end();
2907 unsigned index = 1;
2935
29082936 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
29092937 if (ArgI->Val->getType() != *I)
29102938 GEN_ERROR("Parameter " + ArgI->Val->getName()+ " is not of type '" +
29112939 (*I)->getDescription() + "'");
29122940 Args.push_back(ArgI->Val);
2913 if (ArgI->Attrs != ParamAttr::None) {
2914 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = ArgI->Attrs;
2915 Attrs.push_back(PAWI);
2916 }
29172941 }
29182942 if (Ty->isVarArg()) {
29192943 if (I == E)
29222946 } else if (I != E || ArgI != ArgE)
29232947 GEN_ERROR("Invalid number of parameters detected");
29242948 }
2925
2926 // Finish off the ParamAttrs and check them
2927 ParamAttrsList *PAL = 0;
2928 if (!Attrs.empty())
2929 PAL = ParamAttrsList::get(Attrs);
2930 if (isa(V))
2931 if (PAL != cast(V)->getParamAttrs())
2932 GEN_ERROR("Invalid parameter attributes for function called");
2933
29342949 // Create the call node
29352950 CallInst *CI = new CallInst(V, &Args[0], Args.size());
29362951 CI->setTailCall($1);
29372952 CI->setCallingConv($2);
2938 CI->setParamAttrs(PAL);
29392953 $$ = CI;
29402954 delete $6;
29412955 delete $3;