llvm.org GIT mirror llvm / ed1cb75
Revert "[WebAssemby] Support main functions with alternate signatures." This reverts commit 959e37e669b0c3cfad4cb9f1f7c9261ce9f5e9ae. That commit doesn't handle the case where main is declared rather than defined, in particular the even-more special case where main is a prototypeless declaration (which is of course the one actually used by musl currently). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320121 91177308-0d34-0410-b5e6-96231b3b80d8 Derek Schuff 2 years ago
2 changed file(s) with 1 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
141141 }
142142
143143 bool FixFunctionBitcasts::runOnModule(Module &M) {
144 Function *Main = nullptr;
145 CallInst *CallMain = nullptr;
146144 SmallVector, 0> Uses;
147145 SmallPtrSet ConstantBCs;
148146
149147 // Collect all the places that need wrappers.
150 for (Function &F : M) {
151 FindUses(&F, F, Uses, ConstantBCs);
152
153 // If we have a "main" function, and its type isn't
154 // "int main(int argc, char *argv[])", create an artificial call with it
155 // bitcasted to that type so that we generate a wrapper for it, so that
156 // the C runtime can call it.
157 if (F.getName() == "main") {
158 Main = &F;
159 LLVMContext &C = M.getContext();
160 Type *MainArgTys[] = {
161 PointerType::get(Type::getInt8PtrTy(C), 0),
162 Type::getInt32Ty(C)
163 };
164 FunctionType *MainTy = FunctionType::get(Type::getInt32Ty(C), MainArgTys,
165 /*isVarArg=*/false);
166 if (F.getFunctionType() != MainTy) {
167 Value *Args[] = {
168 UndefValue::get(MainArgTys[0]),
169 UndefValue::get(MainArgTys[1])
170 };
171 Value *Casted = ConstantExpr::getBitCast(Main,
172 PointerType::get(MainTy, 0));
173 CallMain = CallInst::Create(Casted, Args, "call_main");
174 Use *UseMain = &CallMain->getOperandUse(2);
175 Uses.push_back(std::make_pair(UseMain, &F));
176 }
177 }
178 }
148 for (Function &F : M) FindUses(&F, F, Uses, ConstantBCs);
179149
180150 DenseMap, Function *> Wrappers;
181151
210180 U->set(Wrapper);
211181 }
212182
213 // If we created a wrapper for main, rename the wrapper so that it's the
214 // one that gets called from startup.
215 if (CallMain) {
216 Main->setName("__original_main");
217 Function *MainWrapper =
218 cast(CallMain->getCalledValue()->stripPointerCasts());
219 MainWrapper->setName("main");
220 MainWrapper->setLinkage(Main->getLinkage());
221 MainWrapper->setVisibility(Main->getVisibility());
222 Main->setLinkage(Function::PrivateLinkage);
223 Main->setVisibility(Function::DefaultVisibility);
224 delete CallMain;
225 }
226
227183 return true;
228184 }
+0
-18
test/CodeGen/WebAssembly/main.ll less more
None ; RUN: llc < %s -asm-verbose=false | FileCheck %s
1
2 ; Test main functions with alternate signatures.
3
4 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
5 target triple = "wasm32-unknown-unknown-wasm"
6
7 define void @main() {
8 ret void
9 }
10
11 ; CHECK-LABEL: .L__original_main:
12 ; CHECK-NEXT: end_function
13
14 ; CHECK-LABEL: main:
15 ; CHECK-NEXT: .param i32, i32
16 ; CHECK-NEXT: .result i32
17 ; CHECK: call .L__original_main@FUNCTION