llvm.org GIT mirror llvm / c559ba7
Add a new string member to the TargetOptions struct for the name of the abi we should be using. For targets that don't use the option there's no change, otherwise this allows external users to set the ABI via string and avoid some of the -backend-option pain in clang. Use this option to move the ABI for the ARM port from the Subtarget to the TargetMachine and update the testcases accordingly since it's no longer valid to set via -mattr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224492 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 5 years ago
13 changed file(s) with 108 addition(s) and 72 deletion(s). Raw diff Collapse all Expand all
176176 cl::opt
177177 TrapFuncName("trap-func", cl::Hidden,
178178 cl::desc("Emit a call to trap function rather than a trap instruction"),
179 cl::init(""));
180
181 cl::opt
182 ABIName("target-abi", cl::Hidden,
183 cl::desc("The name of the ABI to be targeted from the backend."),
179184 cl::init(""));
180185
181186 cl::opt
279284 Options.DisableTailCalls = DisableTailCalls;
280285 Options.StackAlignmentOverride = OverrideStackAlignment;
281286 Options.TrapFuncName = TrapFuncName;
287 Options.ABIName = ABIName;
282288 Options.PositionIndependentExecutable = EnablePIE;
283289 Options.UseInitArray = !UseCtors;
284290 Options.DataSections = DataSections;
7878 UseInitArray(false), DisableIntegratedAS(false),
7979 CompressDebugSections(false), FunctionSections(false),
8080 DataSections(false), TrapUnreachable(false), TrapFuncName(),
81 FloatABIType(FloatABI::Default),
81 ABIName(), FloatABIType(FloatABI::Default),
8282 AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single),
8383 FCFI(false), ThreadModel(ThreadModel::POSIX),
8484 CFIType(CFIntegrity::Sub), CFIEnforcing(false), CFIFuncName() {}
205205 /// name instead of an ISD::TRAP node.
206206 std::string TrapFuncName;
207207 StringRef getTrapFunctionName() const;
208
209 /// getABIName - If this returns a non-empty string this represents the
210 /// textual name of the ABI that we want the backend to use, e.g. o32, or
211 /// aapcs-linux.
212 std::string ABIName;
213 StringRef getABIName() const;
208214
209215 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
210216 /// on the command line. This setting may either be Default, Soft, or Hard.
285291 ARE_EQUAL(UseInitArray) &&
286292 ARE_EQUAL(TrapUnreachable) &&
287293 ARE_EQUAL(TrapFuncName) &&
294 ARE_EQUAL(ABIName) &&
288295 ARE_EQUAL(FloatABIType) &&
289296 ARE_EQUAL(AllowFPOpFusion) &&
290297 ARE_EQUAL(JTType) &&
5757 StringRef TargetOptions::getCFIFuncName() const {
5858 return CFIFuncName;
5959 }
60
61 /// getABIName - If this returns a non-empty string this represents the
62 /// textual name of the ABI that we want the backend to use, e.g. o32, or
63 /// aapcs-linux.
64 StringRef TargetOptions::getABIName() const {
65 return ABIName;
66 }
269269 FeatureHWDivARM]>;
270270
271271
272 def FeatureAPCS : SubtargetFeature<"apcs", "TargetABI", "ARM_ABI_APCS",
273 "Use the APCS ABI">;
274
275 def FeatureAAPCS : SubtargetFeature<"aapcs", "TargetABI", "ARM_ABI_AAPCS",
276 "Use the AAPCS ABI">;
277
278
279272 class ProcNoItin Features>
280273 : Processor;
281274
1717 #include "ARMSelectionDAGInfo.h"
1818 #include "ARMSubtarget.h"
1919 #include "ARMMachineFunctionInfo.h"
20 #include "ARMTargetMachine.h"
2021 #include "Thumb1FrameLowering.h"
2122 #include "Thumb1InstrInfo.h"
2223 #include "Thumb2InstrInfo.h"
146147 }
147148
148149 ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
149 const std::string &FS, const TargetMachine &TM,
150 const std::string &FS, const ARMBaseTargetMachine &TM,
150151 bool IsLittle)
151152 : ARMGenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
152153 ARMProcClass(None), stackAlignment(4), CPUString(CPU), IsLittle(IsLittle),
153 TargetTriple(TT), Options(TM.Options), TargetABI(ARM_ABI_UNKNOWN),
154 TargetTriple(TT), Options(TM.Options), TM(TM),
154155 DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS))),
155156 TSInfo(DL),
156157 InstrInfo(isThumb1Only()
244245 // Initialize scheduling itinerary for the specified CPU.
245246 InstrItins = getInstrItineraryForCPU(CPUString);
246247
247 if (TargetABI == ARM_ABI_UNKNOWN) {
248 // FIXME: This is duplicated code from the front end and should be unified.
249 if (TargetTriple.isOSBinFormatMachO()) {
250 if (TargetTriple.getEnvironment() == llvm::Triple::EABI ||
251 (TargetTriple.getOS() == llvm::Triple::UnknownOS &&
252 TargetTriple.getObjectFormat() == llvm::Triple::MachO) ||
253 CPU.startswith("cortex-m")) {
254 TargetABI = ARM_ABI_AAPCS;
255 } else {
256 TargetABI = ARM_ABI_APCS;
257 }
258 } else if (TargetTriple.isOSWindows()) {
259 // FIXME: this is invalid for WindowsCE
260 TargetABI = ARM_ABI_AAPCS;
261 } else {
262 // Select the default based on the platform.
263 switch (TargetTriple.getEnvironment()) {
264 case llvm::Triple::Android:
265 case llvm::Triple::GNUEABI:
266 case llvm::Triple::GNUEABIHF:
267 case llvm::Triple::EABIHF:
268 case llvm::Triple::EABI:
269 TargetABI = ARM_ABI_AAPCS;
270 break;
271 case llvm::Triple::GNU:
272 TargetABI = ARM_ABI_APCS;
273 break;
274 default:
275 if (TargetTriple.getOS() == llvm::Triple::NetBSD)
276 TargetABI = ARM_ABI_APCS;
277 else
278 TargetABI = ARM_ABI_AAPCS;
279 break;
280 }
281 }
282 }
283
284248 // FIXME: this is invalid for WindowsCE
285249 if (isTargetWindows())
286250 NoARM = true;
345309 UseNEONForSinglePrecisionFP = true;
346310 }
347311
312 bool ARMSubtarget::isAPCS_ABI() const {
313 assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN);
314 return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_APCS;
315 }
316 bool ARMSubtarget::isAAPCS_ABI() const {
317 assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN);
318 return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS;
319 }
320
348321 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
349322 bool
350323 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
3636 class GlobalValue;
3737 class StringRef;
3838 class TargetOptions;
39 class ARMBaseTargetMachine;
3940
4041 class ARMSubtarget : public ARMGenSubtargetInfo {
4142 protected:
224225 /// Options passed via command line that could influence the target
225226 const TargetOptions &Options;
226227
227 public:
228 enum {
229 ARM_ABI_UNKNOWN,
230 ARM_ABI_APCS,
231 ARM_ABI_AAPCS // ARM EABI
232 } TargetABI;
233
228 const ARMBaseTargetMachine &TM;
229
230 public:
234231 /// This constructor initializes the data members to match that
235232 /// of the specified triple.
236233 ///
237234 ARMSubtarget(const std::string &TT, const std::string &CPU,
238 const std::string &FS, const TargetMachine &TM, bool IsLittle);
235 const std::string &FS, const ARMBaseTargetMachine &TM, bool IsLittle);
239236
240237 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
241238 /// that still makes it profitable to inline the call.
387384 return TargetTriple.getEnvironment() == Triple::Android;
388385 }
389386
390 bool isAPCS_ABI() const {
391 assert(TargetABI != ARM_ABI_UNKNOWN);
392 return TargetABI == ARM_ABI_APCS;
393 }
394 bool isAAPCS_ABI() const {
395 assert(TargetABI != ARM_ABI_UNKNOWN);
396 return TargetABI == ARM_ABI_AAPCS;
397 }
387 bool isAPCS_ABI() const;
388 bool isAAPCS_ABI() const;
398389
399390 bool isThumb() const { return InThumbMode; }
400391 bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
5151 return make_unique();
5252 }
5353
54 static ARMBaseTargetMachine::ARMABI
55 computeTargetABI(const Triple &TT, StringRef CPU,
56 const TargetOptions &Options) {
57 if (Options.getABIName().startswith("aapcs"))
58 return ARMBaseTargetMachine::ARM_ABI_AAPCS;
59 else if (Options.getABIName().startswith("apcs"))
60 return ARMBaseTargetMachine::ARM_ABI_APCS;
61
62 assert(Options.getABIName().empty() && "Unknown target-abi option!");
63
64 ARMBaseTargetMachine::ARMABI TargetABI =
65 ARMBaseTargetMachine::ARM_ABI_UNKNOWN;
66
67 // FIXME: This is duplicated code from the front end and should be unified.
68 if (TT.isOSBinFormatMachO()) {
69 if (TT.getEnvironment() == llvm::Triple::EABI ||
70 (TT.getOS() == llvm::Triple::UnknownOS &&
71 TT.getObjectFormat() == llvm::Triple::MachO) ||
72 CPU.startswith("cortex-m")) {
73 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
74 } else {
75 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
76 }
77 } else if (TT.isOSWindows()) {
78 // FIXME: this is invalid for WindowsCE
79 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
80 } else {
81 // Select the default based on the platform.
82 switch (TT.getEnvironment()) {
83 case llvm::Triple::Android:
84 case llvm::Triple::GNUEABI:
85 case llvm::Triple::GNUEABIHF:
86 case llvm::Triple::EABIHF:
87 case llvm::Triple::EABI:
88 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
89 break;
90 case llvm::Triple::GNU:
91 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
92 break;
93 default:
94 if (TT.getOS() == llvm::Triple::NetBSD)
95 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
96 else
97 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
98 break;
99 }
100 }
101
102 return TargetABI;
103 }
104
54105 /// TargetMachine ctor - Create an ARM architecture model.
55106 ///
56107 ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, StringRef TT,
59110 Reloc::Model RM, CodeModel::Model CM,
60111 CodeGenOpt::Level OL, bool isLittle)
61112 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
113 TargetABI(computeTargetABI(Triple(TT), CPU, Options)),
62114 TLOF(createTLOF(Triple(getTargetTriple()))),
63115 Subtarget(TT, CPU, FS, *this, isLittle), isLittle(isLittle) {
64116
2121 namespace llvm {
2222
2323 class ARMBaseTargetMachine : public LLVMTargetMachine {
24 public:
25 enum ARMABI {
26 ARM_ABI_UNKNOWN,
27 ARM_ABI_APCS,
28 ARM_ABI_AAPCS // ARM EABI
29 } TargetABI;
30
2431 protected:
2532 std::unique_ptr TLOF;
2633 ARMSubtarget Subtarget;
0 ; RUN: llc -mtriple=arm-linux-gnu < %s | FileCheck %s --check-prefix=APCS
1 ; RUN: llc -mtriple=arm-linux-gnu -mattr=apcs < %s | \
1 ; RUN: llc -mtriple=arm-linux-gnu -target-abi=apcs < %s | \
22 ; RUN: FileCheck %s --check-prefix=APCS
3 ; RUN: llc -mtriple=arm-linux-gnueabi -mattr=apcs < %s | \
3 ; RUN: llc -mtriple=arm-linux-gnueabi -target-abi=apcs < %s | \
44 ; RUN: FileCheck %s --check-prefix=APCS
55
66 ; RUN: llc -mtriple=arm-linux-gnueabi < %s | FileCheck %s --check-prefix=AAPCS
7 ; RUN: llc -mtriple=arm-linux-gnueabi -mattr=aapcs < %s | \
7 ; RUN: llc -mtriple=arm-linux-gnueabi -target-abi=aapcs < %s | \
88 ; RUN: FileCheck %s --check-prefix=AAPCS
9 ; RUN: llc -mtriple=arm-linux-gnu -mattr=aapcs < %s | \
9 ; RUN: llc -mtriple=arm-linux-gnu -target-abi=aapcs < %s | \
1010 ; RUN: FileCheck %s --check-prefix=AAPCS
1111
1212 ; The stack is 8 byte aligned on AAPCS and 4 on APCS, so we should get a BIC
0 ; RUN: llc < %s -mtriple=armv7-apple-ios | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-LE
11 ; RUN: llc < %s -mtriple=thumbv7-none-linux-gnueabihf | FileCheck %s --check-prefix=CHECK-THUMB --check-prefix=CHECK-THUMB-LE
2 ; RUN: llc < %s -mtriple=armebv7 -mattr=apcs | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-BE
2 ; RUN: llc < %s -mtriple=armebv7 -target-abi apcs | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-BE
33 ; RUN: llc < %s -mtriple=thumbebv7-none-linux-gnueabihf | FileCheck %s --check-prefix=CHECK-THUMB --check-prefix=CHECK-THUMB-BE
44
55 define i64 @test1(i64* %ptr, i64 %val) {
0 ; RUN: llc < %s -mtriple=thumbv7s-apple-ios3.0.0 -mcpu=generic | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
1 ; RUN: llc < %s -mtriple=thumbeb -mattr=apcs -mattr=v7,neon | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
1 ; RUN: llc < %s -mtriple=thumbeb -target-abi apcs -mattr=v7,neon | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
22
33 ; PR15525
44 ; CHECK-LABEL: test1:
None ; RUN: llc -mtriple=thumbv7-unknown-unknown -mattr=apcs < %s | FileCheck %s
0 ; RUN: llc -mtriple=thumbv7-unknown-unknown -target-abi apcs < %s | FileCheck %s
11 ; Check assembly printing of odd constants.
22
33 ; CHECK: bigCst:
None ; RUN: llc -mtriple armv7 -mattr=apcs -O0 -o - < %s \
0 ; RUN: llc -mtriple armv7 -target-abi apcs -O0 -o - < %s \
11 ; RUN: | FileCheck %s -check-prefix CHECK-TAIL
2 ; RUN: llc -mtriple armv7 -mattr=apcs -O0 -disable-tail-calls -o - < %s \
2 ; RUN: llc -mtriple armv7 -target-abi apcs -O0 -disable-tail-calls -o - < %s \
33 ; RUN: | FileCheck %s -check-prefix CHECK-NO-TAIL
44
55 declare i32 @callee(i32 %i)