llvm.org GIT mirror llvm / f144818
[IPO][AVR] Create new Functions in the default address space specified in the data layout This modifies the IPO pass so that it respects any explicit function address space specified in the data layout. In targets with nonzero program address spaces, all functions should, by default, be placed into the default program address space. This is required for Harvard architectures like AVR. Without this, the functions will be marked as residing in data space, and thus not be callable. This has no effect to any in-tree official backends, as none use an explicit program address space in their data layouts. Patch by Tim Neumann. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349469 91177308-0d34-0410-b5e6-96231b3b80d8 Dylan McKay 9 months ago
11 changed file(s) with 106 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
212212 FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
213213
214214 // Create the new function body and insert it into the module.
215 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
215 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getAddressSpace(),
216 F->getName());
216217 NF->copyAttributesFrom(F);
217218
218219 // Patch the pointer to LLVM function in debug info descriptor.
163163 unsigned NumArgs = Params.size();
164164
165165 // Create the new function body and insert it into the module...
166 Function *NF = Function::Create(NFTy, Fn.getLinkage());
166 Function *NF = Function::Create(NFTy, Fn.getLinkage(), Fn.getAddressSpace());
167167 NF->copyAttributesFrom(&Fn);
168168 NF->setComdat(Fn.getComdat());
169169 Fn.getParent()->getFunctionList().insert(Fn.getIterator(), NF);
862862 return false;
863863
864864 // Create the new function body and insert it into the module...
865 Function *NF = Function::Create(NFTy, F->getLinkage());
865 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getAddressSpace());
866866 NF->copyAttributesFrom(F);
867867 NF->setComdat(F->getComdat());
868868 NF->setAttributes(NewPAL);
134134 llvm::Value *Declaration;
135135 if (FunctionType *FTy = dyn_cast(Ty)) {
136136 Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage,
137 CurI->getAddressSpace(),
137138 CurI->getName(), &M);
138139
139140 } else {
910910 if (GV.getValueType()->isFunctionTy())
911911 NewGV =
912912 Function::Create(cast(GV.getValueType()),
913 GlobalValue::ExternalLinkage, "", GV.getParent());
913 GlobalValue::ExternalLinkage, GV.getAddressSpace(),
914 "", GV.getParent());
914915 else
915916 NewGV =
916917 new GlobalVariable(*GV.getParent(), GV.getValueType(),
988988 if (F->isDSOLocal()) {
989989 Function *RealF = Function::Create(F->getFunctionType(),
990990 GlobalValue::ExternalLinkage,
991 F->getAddressSpace(),
991992 Name + ".cfi", &M);
992993 RealF->setVisibility(GlobalVariable::HiddenVisibility);
993994 replaceDirectCalls(F, RealF);
9991000 if (F->isDeclarationForLinker() && !isDefinition) {
10001001 // Declaration of an external function.
10011002 FDecl = Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage,
1002 Name + ".cfi_jt", &M);
1003 F->getAddressSpace(), Name + ".cfi_jt", &M);
10031004 FDecl->setVisibility(GlobalValue::HiddenVisibility);
10041005 } else if (isDefinition) {
10051006 F->setName(Name + ".cfi");
10061007 F->setLinkage(GlobalValue::ExternalLinkage);
10071008 FDecl = Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage,
1008 Name, &M);
1009 F->getAddressSpace(), Name, &M);
10091010 FDecl->setVisibility(Visibility);
10101011 Visibility = GlobalValue::HiddenVisibility;
10111012
10151016 for (auto &U : F->uses()) {
10161017 if (auto *A = dyn_cast(U.getUser())) {
10171018 Function *AliasDecl = Function::Create(
1018 F->getFunctionType(), GlobalValue::ExternalLinkage, "", &M);
1019 F->getFunctionType(), GlobalValue::ExternalLinkage,
1020 F->getAddressSpace(), "", &M);
10191021 AliasDecl->takeName(A);
10201022 A->replaceAllUsesWith(AliasDecl);
10211023 ToErase.push_back(A);
11901192 WeakInitializerFn = Function::Create(
11911193 FunctionType::get(Type::getVoidTy(M.getContext()),
11921194 /* IsVarArg */ false),
1193 GlobalValue::InternalLinkage, "__cfi_global_var_init", &M);
1195 GlobalValue::InternalLinkage,
1196 M.getDataLayout().getProgramAddressSpace(),
1197 "__cfi_global_var_init", &M);
11941198 BasicBlock *BB =
11951199 BasicBlock::Create(M.getContext(), "entry", WeakInitializerFn);
11961200 ReturnInst::Create(M.getContext(), BB);
12331237 // placeholder first.
12341238 Function *PlaceholderFn =
12351239 Function::Create(cast(F->getValueType()),
1236 GlobalValue::ExternalWeakLinkage, "", &M);
1240 GlobalValue::ExternalWeakLinkage,
1241 F->getAddressSpace(), "", &M);
12371242 replaceCfiUses(F, PlaceholderFn, IsDefinition);
12381243
12391244 Constant *Target = ConstantExpr::getSelect(
14231428 Function *JumpTableFn =
14241429 Function::Create(FunctionType::get(Type::getVoidTy(M.getContext()),
14251430 /* IsVarArg */ false),
1426 GlobalValue::PrivateLinkage, ".cfi.jumptable", &M);
1431 GlobalValue::PrivateLinkage,
1432 M.getDataLayout().getProgramAddressSpace(),
1433 ".cfi.jumptable", &M);
14271434 ArrayType *JumpTableType =
14281435 ArrayType::get(getJumpTableEntryType(), Functions.size());
14291436 auto JumpTable =
18121819 if (!F)
18131820 F = Function::Create(
18141821 FunctionType::get(Type::getVoidTy(M.getContext()), false),
1815 GlobalVariable::ExternalLinkage, FunctionName, &M);
1822 GlobalVariable::ExternalLinkage,
1823 M.getDataLayout().getProgramAddressSpace(), FunctionName, &M);
18161824
18171825 // If the function is available_externally, remove its definition so
18181826 // that it is handled the same way as a declaration. Later we will try
692692 GEntryBlock->getTerminator()->eraseFromParent();
693693 BB = GEntryBlock;
694694 } else {
695 NewG = Function::Create(G->getFunctionType(), G->getLinkage(), "",
696 G->getParent());
695 NewG = Function::Create(G->getFunctionType(), G->getLinkage(),
696 G->getAddressSpace(), "", G->getParent());
697697 BB = BasicBlock::Create(F->getContext(), "", NewG);
698698 }
699699
806806 }
807807
808808 // Make them both thunks to the same internal function.
809 Function *NewF = Function::Create(F->getFunctionType(), F->getLinkage(), "",
810 F->getParent());
809 Function *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
810 F->getAddressSpace(), "", F->getParent());
811811 NewF->copyAttributesFrom(F);
812812 NewF->takeName(F);
813813 removeUsers(F);
153153 continue;
154154
155155 Function *NewF =
156 Function::Create(EmptyFT, GlobalValue::ExternalLinkage, "", &M);
156 Function::Create(EmptyFT, GlobalValue::ExternalLinkage,
157 F.getAddressSpace(), "", &M);
157158 NewF->setVisibility(F.getVisibility());
158159 NewF->takeName(&F);
159160 F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
863863 Function *JT;
864864 if (isa(Slot.TypeID)) {
865865 JT = Function::Create(FT, Function::ExternalLinkage,
866 M.getDataLayout().getProgramAddressSpace(),
866867 getGlobalName(Slot, {}, "branch_funnel"), &M);
867868 JT->setVisibility(GlobalValue::HiddenVisibility);
868869 } else {
869 JT = Function::Create(FT, Function::InternalLinkage, "branch_funnel", &M);
870 JT = Function::Create(FT, Function::InternalLinkage,
871 M.getDataLayout().getProgramAddressSpace(),
872 "branch_funnel", &M);
870873 }
871874 JT->addAttribute(1, Attribute::Nest);
872875
0 ; RUN: opt < %s -argpromotion -S | FileCheck %s
1
2 ; ArgumentPromotion should preserve the default function address space
3 ; from the data layout.
4
5 target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
6
7 @g = common global i32 0, align 4
8
9 define i32 @bar() {
10 entry:
11 %call = call i32 @foo(i32* @g)
12 ; CHECK: %call = call addrspace(1) i32 @foo()
13 ret i32 %call
14 }
15
16 ; CHECK: define internal i32 @foo() addrspace(1)
17 define internal i32 @foo(i32*) {
18 entry:
19 %retval = alloca i32, align 4
20 call void asm sideeffect "ldr r0, [r0] \0Abx lr \0A", ""()
21 unreachable
22 }
23
0 ; RUN: opt -S -deadargelim %s | FileCheck %s
1
2 ; DeadArgumentElimination should respect the function address space
3 ; in the data layout.
4
5 target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
6
7 ; CHECK: define internal i32 @foo() addrspace(1)
8 define internal i32 @foo(i32 %x) #0 {
9 tail call void asm sideeffect inteldialect "mov eax, [esp + $$4]\0A\09ret", "~{eax},~{dirflag},~{fpsr},~{flags}"()
10 unreachable
11 }
12
13 define i32 @f(i32 %x, i32 %y) {
14 ; CHECK: %r = call addrspace(1) i32 @foo()
15 %r = call i32 @foo(i32 %x)
16
17 ret i32 %r
18 }
19
0 ; RUN: opt -S -mergefunc < %s | FileCheck %s
1
2 ; MergeFunctions should respect the default function address
3 ; space specified in the data layout.
4
5 target datalayout = "e-P1-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
6
7 declare void @stuff()
8
9 ; CHECK-LABEL: @f0(
10 define void @f0(i64 %p0) {
11 entry:
12 call void @stuff()
13 call void @stuff()
14 call void @stuff()
15 ret void
16 }
17
18 ; CHECK-LABEL: @f1(
19 ; CHECK: ptrtoint i64*
20 ; CHECK: tail call addrspace(1) void @f0(i64
21
22 define void @f1(i64* %p0) {
23 entry:
24 call void @stuff()
25 call void @stuff()
26 call void @stuff()
27 ret void
28 }
29