llvm.org GIT mirror llvm / 9980525
[Mips] TargetStreamer ELF flag Support for default and commandline options. This patch uses a common MipsTargetSteamer interface for both MipsAsmPrinter and MipsAsmParser for recording default and commandline driven directives that affect ELF header flags. It has been noted that the .ll tests affected by this patch belong in test/Codegen/Mips. I will move them in a separate patch. Also, a number of directives do not get expressed by AsmPrinter in the resultant .s assembly such as setting the correct ASI. I have noted this in the tests and they will be addressed in later patches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200051 91177308-0d34-0410-b5e6-96231b3b80d8 Jack Carter 6 years ago
8 changed file(s) with 162 addition(s) and 76 deletion(s). Raw diff Collapse all Expand all
2020 #include "llvm/MC/MCSubtargetInfo.h"
2121 #include "llvm/MC/MCSymbol.h"
2222 #include "llvm/MC/MCTargetAsmParser.h"
23 #include "llvm/Support/ELF.h"
24 #include "llvm/Support/TargetRegistry.h"
25 #include "llvm/ADT/APInt.h"
2326 #include "llvm/Support/MathExtras.h"
2427 #include "llvm/Support/TargetRegistry.h"
2528
193196
194197 bool isEvaluated(const MCExpr *Expr);
195198 bool parseDirectiveSet();
196 bool parseDirectiveMipsHackELFFlags();
197199 bool parseDirectiveOption();
198200
199201 bool parseSetAtDirective();
256258 // Example: INSERT.B $w0[n], $1 => 16 > n >= 0
257259 bool validateMSAIndex(int Val, int RegKind);
258260
261 // Set ELF flags based on defaults and commandline arguments.
262 void processInitialEFlags();
263
259264 public:
260265 MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
261266 const MCInstrInfo &MII)
263268 hasConsumedDollar(false) {
264269 // Initialize the set of available features.
265270 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
271 processInitialEFlags();
266272 }
267273
268274 MCAsmParser &getParser() const { return Parser; }
24282434 return true;
24292435 }
24302436
2431 bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
2432 int64_t Flags = 0;
2433 if (Parser.parseAbsoluteExpression(Flags)) {
2434 TokError("unexpected token");
2435 return false;
2436 }
2437
2438 getTargetStreamer().emitMipsHackELFFlags(Flags);
2439 return false;
2440 }
2441
24422437 /// parseDirectiveWord
24432438 /// ::= .word [ expression (, expression)* ]
24442439 bool MipsAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
25572552 return false;
25582553 }
25592554
2560 if (IDVal == ".mips_hack_elf_flags")
2561 return parseDirectiveMipsHackELFFlags();
2562
25632555 if (IDVal == ".option")
25642556 return parseDirectiveOption();
25652557
25762568 return true;
25772569 }
25782570
2571 void MipsAsmParser::processInitialEFlags() {
2572 // Start will a clean slate.
2573 unsigned EFlags = 0;
2574 unsigned FeatureBits = STI.getFeatureBits();
2575
2576 // Default settings
2577 EFlags |= ELF::EF_MIPS_NOREORDER | ELF::EF_MIPS_PIC | ELF::EF_MIPS_ABI_O32;
2578
2579 // ISA
2580 if (FeatureBits & Mips::FeatureMips64r2) {
2581 EFlags |= ELF::EF_MIPS_ARCH_64R2;
2582 EFlags &= ~ELF::EF_MIPS_ABI_O32;
2583 } else if (FeatureBits & Mips::FeatureMips64) {
2584 EFlags |= ELF::EF_MIPS_ARCH_64;
2585 EFlags &= ~ELF::EF_MIPS_ABI_O32;
2586 } else if (FeatureBits & Mips::FeatureMips32r2)
2587 EFlags |= ELF::EF_MIPS_ARCH_32R2;
2588 else if (FeatureBits & Mips::FeatureMips32)
2589 EFlags |= ELF::EF_MIPS_ARCH_32;
2590 else if (FeatureBits & Mips::FeatureO32)
2591 EFlags |= ELF::EF_MIPS_ABI_O32; // This is really a zero
2592
2593 // ASE
2594 if (FeatureBits & Mips::FeatureMicroMips)
2595 EFlags |= ELF::EF_MIPS_MICROMIPS;
2596 else if (FeatureBits & Mips::FeatureMips16)
2597 EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
2598
2599 // ABI
2600 // TODO: n32/eabi
2601
2602 // Linkage model
2603 // TODO: pic/cpic/static
2604
2605 getTargetStreamer().emitMipsELFFlags(EFlags);
2606 }
2607
25792608 extern "C" void LLVMInitializeMipsAsmParser() {
25802609 RegisterMCAsmParser X(TheMipsTarget);
25812610 RegisterMCAsmParser Y(TheMipselTarget);
2020
2121 using namespace llvm;
2222
23 static cl::opt PrintHackDirectives("print-hack-directives",
24 cl::init(false), cl::Hidden);
25
2623 // Pin vtable to this file.
2724 void MipsTargetStreamer::anchor() {}
2825
2926 MipsTargetAsmStreamer::MipsTargetAsmStreamer(formatted_raw_ostream &OS)
3027 : OS(OS) {}
3128
32 void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) {
33 if (!PrintHackDirectives)
34 return;
35
36 OS << "\t.mips_hack_elf_flags 0x";
37 OS.write_hex(Flags);
38 OS << '\n';
39 }
29 void MipsTargetAsmStreamer::emitMipsELFFlags(unsigned Flags) { return; }
4030
4131 void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
4232 OS << "\t.set\tmicromips\n";
8474 return static_cast(*Streamer);
8575 }
8676
87 void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) {
77 void MipsTargetELFStreamer::emitMipsELFFlags(unsigned Flags) {
8878 MCAssembler &MCA = getStreamer().getAssembler();
8979 MCA.setELFHeaderEFlags(Flags);
9080 }
106106 EmitGlobalConstant(MCPE.Val.ConstVal);
107107 return;
108108 }
109
110109
111110 MachineBasicBlock::const_instr_iterator I = MI;
112111 MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
633632
634633 }
635634
636 static void emitELFHeaderFlagsCG(MipsTargetStreamer &TargetStreamer,
637 const MipsSubtarget &Subtarget) {
635 void MipsAsmPrinter::processInitialEFlags() {
636 // Not having this check would work too, but would have us chew through
637 // code that it doesn't use for RawText.
638 if (OutStreamer.hasRawTextSupport())
639 return;
640
638641 // Update e_header flags
639642 unsigned EFlags = 0;
640643
642645 // Currently we assume that -mabicalls is the default.
643646 EFlags |= ELF::EF_MIPS_CPIC;
644647
645 if (Subtarget.inMips16Mode())
648 if (Subtarget->inMips16Mode())
646649 EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
647650 else
648651 EFlags |= ELF::EF_MIPS_NOREORDER;
649652
650653 // Architecture
651 if (Subtarget.hasMips64r2())
654 if (Subtarget->hasMips64r2())
652655 EFlags |= ELF::EF_MIPS_ARCH_64R2;
653 else if (Subtarget.hasMips64())
656 else if (Subtarget->hasMips64())
654657 EFlags |= ELF::EF_MIPS_ARCH_64;
655 else if (Subtarget.hasMips32r2())
658 else if (Subtarget->hasMips32r2())
656659 EFlags |= ELF::EF_MIPS_ARCH_32R2;
657660 else
658661 EFlags |= ELF::EF_MIPS_ARCH_32;
659662
660 if (Subtarget.inMicroMipsMode())
663 if (Subtarget->inMicroMipsMode())
661664 EFlags |= ELF::EF_MIPS_MICROMIPS;
662665
663666 // ABI
664 if (Subtarget.isABI_O32())
667 if (Subtarget->isABI_O32())
665668 EFlags |= ELF::EF_MIPS_ABI_O32;
666669
667670 // Relocation Model
668 Reloc::Model RM = Subtarget.getRelocationModel();
671 Reloc::Model RM = Subtarget->getRelocationModel();
669672 if (RM == Reloc::PIC_ || RM == Reloc::Default)
670673 EFlags |= ELF::EF_MIPS_PIC;
671674 else if (RM == Reloc::Static)
673676 else
674677 llvm_unreachable("Unsupported relocation model for e_flags");
675678
676 TargetStreamer.emitMipsHackELFFlags(EFlags);
679 getTargetStreamer().emitMipsELFFlags(EFlags);
677680 }
678681
679682 void MipsAsmPrinter::EmitEndOfAsmFile(Module &M) {
680683 // Emit Mips ELF register info
681684 Subtarget->getMReginfo().emitMipsReginfoSectionCG(
682685 OutStreamer, getObjFileLowering(), *Subtarget);
683 emitELFHeaderFlagsCG(getTargetStreamer(), *Subtarget);
684686 }
685687
686688 void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
4949 /// pool entries so we can properly mark them as data regions.
5050 bool InConstantPool;
5151
52 // If object output, set initial eflags.
53 // This includes both default and commandline flags that affect the output
54 // ELF header flags.
55 void processInitialEFlags();
5256
5357 public:
5458
6064 : AsmPrinter(TM, Streamer), MCP(0), InConstantPool(false),
6165 MCInstLowering(*this) {
6266 Subtarget = &TM.getSubtarget();
67 processInitialEFlags();
6368 }
6469
6570 virtual const char *getPassName() const {
102107 void EmitStartOfAsmFile(Module &M);
103108 void EmitEndOfAsmFile(Module &M);
104109 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
110
105111 };
106112 }
107113
1717 virtual void anchor();
1818
1919 public:
20 virtual void emitMipsHackELFFlags(unsigned Flags) = 0;
20 virtual void emitMipsELFFlags(unsigned Flags) = 0;
2121 virtual void emitDirectiveSetMicroMips() = 0;
2222 virtual void emitDirectiveSetNoMicroMips() = 0;
2323 virtual void emitDirectiveSetMips16() = 0;
3333
3434 public:
3535 MipsTargetAsmStreamer(formatted_raw_ostream &OS);
36 virtual void emitMipsHackELFFlags(unsigned Flags);
36 virtual void emitMipsELFFlags(unsigned Flags);
3737 virtual void emitDirectiveSetMicroMips();
3838 virtual void emitDirectiveSetNoMicroMips();
3939 virtual void emitDirectiveSetMips16();
5555 virtual void emitLabel(MCSymbol *Symbol) LLVM_OVERRIDE;
5656
5757 // FIXME: emitMipsHackELFFlags() will be removed from this class.
58 virtual void emitMipsHackELFFlags(unsigned Flags);
58 virtual void emitMipsELFFlags(unsigned Flags);
5959 virtual void emitDirectiveSetMicroMips();
6060 virtual void emitDirectiveSetNoMicroMips();
6161 virtual void emitDirectiveSetMips16();
None ; This tests ELF EFLAGS setting with direct object.
1 ; When the assembler is ready a .s file for it will
2 ; be created.
0 ; This tests for directives that will result in
1 ; ELF EFLAGS setting with direct object.
32
43 ; Non-shared (static) is the absence of pic and or cpic.
54
1514 ; Note that EF_MIPS_CPIC is set by -mabicalls which is the default on Linux
1615 ; TODO need to support -mno-abicalls
1716
18 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 -relocation-model=static %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE32 %s
19 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32_PIC %s
20 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -relocation-model=static %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE32R2 %s
21 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32R2_PIC %s
22 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -relocation-model=static -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS %s
23 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS_PIC %s
17 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 \
18 ; RUN: -relocation-model=static %s -o - | \
19 ; RUN: FileCheck -check-prefix=CHECK-BE32 %s
20 ;
21 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32 %s -o - | \
22 ; RUN: FileCheck -check-prefix=CHECK-BE32_PIC %s
23 ;
24 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 \
25 ; RUN: -relocation-model=static %s -o - | \
26 ; RUN: FileCheck -check-prefix=CHECK-BE32R2 %s
27 ;
28 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 %s -o - | \
29 ; RUN: FileCheck -check-prefix=CHECK-BE32R2_PIC %s
30 ;
31 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 \
32 ; RUN: -mattr=+micromips -relocation-model=static %s -o - | \
33 ; RUN: FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS %s
34 ;
35 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 \
36 ; RUN: -mattr=+micromips %s -o - | \
37 ; RUN: FileCheck -check-prefix=CHECK-BE32R2-MICROMIPS_PIC %s
2438
25 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 -relocation-model=static %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE64 %s
26 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 %s -print-hack-directives -o - | FileCheck -check-prefix=CHECK-BE64_PIC %s
27 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 -relocation-model=static -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE64R2 %s
28 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-BE64R2_PIC %s
39 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 \
40 ; RUN: -relocation-model=static %s -o - | \
41 ; RUN: FileCheck -check-prefix=CHECK-BE64 %s
42 ;
43 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64 %s -o - | \
44 ; RUN: FileCheck -check-prefix=CHECK-BE64_PIC %s
45 ;
46 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 \
47 ; RUN: -relocation-model=static %s -o - | \
48 ; RUN: FileCheck -check-prefix=CHECK-BE64R2 %s
49 ;
50 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips64r2 %s -o - | \
51 ; RUN: FileCheck -check-prefix=CHECK-BE64R2_PIC %s
2952
30 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+mips16 -relocation-model=pic -print-hack-directives %s -o - | FileCheck -check-prefix=CHECK-LE32R2-MIPS16 %s
53 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 \
54 ; RUN: -mattr=+mips16 -relocation-model=pic %s -o - | \
55 ; RUN: FileCheck -check-prefix=CHECK-LE32R2-MIPS16 %s
3156
3257 ; 32(R1) bit with NO_REORDER and static
33 ; CHECK-BE32: .mips_hack_elf_flags 0x50001005
58 ; CHECK-BE32: .abicalls
59 ; CHECK-BE32: .option pic0
60 ; CHECK-BE32: .set noreorder
61 ; TODO: Need .set mips32
3462 ;
3563 ; 32(R1) bit with NO_REORDER and PIC
36 ; CHECK-BE32_PIC: .mips_hack_elf_flags 0x50001007
64 ; CHECK-BE32_PIC: .abicalls
65 ; CHECK-BE32_PIC: .set noreorder
66 ; TODO: Need .set mips32 and check absence of .option pic0
3767 ;
3868 ; 32R2 bit with NO_REORDER and static
39 ; CHECK-BE32R2: .mips_hack_elf_flags 0x70001005
69 ; CHECK-BE32R2: .abicalls
70 ; CHECK-BE32R2: .option pic0
71 ; CHECK-BE32R2: .set noreorder
72 ; TODO: Need .set mips32r2
4073 ;
4174 ; 32R2 bit with NO_REORDER and PIC
42 ; CHECK-BE32R2_PIC: .mips_hack_elf_flags 0x70001007
75 ; CHECK-BE32R2_PIC:.abicalls
76 ; CHECK-BE32R2_PIC:.set noreorder
77 ; TODO: Need .set mips32r2 and check absence of .option pic0
4378 ;
4479 ; 32R2 bit MICROMIPS with NO_REORDER and static
45 ; CHECK-BE32R2-MICROMIPS: .mips_hack_elf_flags 0x72001005
80 ; CHECK-BE32R2-MICROMIPS: .abicalls
81 ; CHECK-BE32R2-MICROMIPS: .option pic0
82 ; CHECK-BE32R2-MICROMIPS: .set micromips
83 ; CHECK-BE32R2-MICROMIPS: .set noreorder
84 ; TODO: Need .set mips32r2
4685 ;
4786 ; 32R2 bit MICROMIPS with NO_REORDER and PIC
48 ; CHECK-BE32R2-MICROMIPS_PIC: .mips_hack_elf_flags 0x72001007
87 ; CHECK-BE32R2-MICROMIPS_PIC: .abicalls
88 ; CHECK-BE32R2-MICROMIPS_PIC: .set micromips
89 ; CHECK-BE32R2-MICROMIPS_PIC: .set noreorder
90 ; TODO: Need .set mips32r2 and check absence of .option pic0
4991 ;
5092 ; 64(R1) bit with NO_REORDER and static
51 ; CHECK-BE64: .mips_hack_elf_flags 0x60000005
93 ; CHECK-BE64: .abicalls
94 ; CHECK-BE64: .set noreorder
95 ; TODO: Need .set mips64 and .option pic0
5296 ;
5397 ; 64(R1) bit with NO_REORDER and PIC
54 ; CHECK-BE64_PIC: .mips_hack_elf_flags 0x60000007
98 ; CHECK-BE64_PIC: .abicalls
99 ; CHECK-BE64_PIC: .set noreorder
100 ; TODO: Need .set mips64 and check absence of .option pic0
55101 ;
56102 ; 64R2 bit with NO_REORDER and static
57 ; CHECK-BE64R2: .mips_hack_elf_flags 0x80000005
103 ; CHECK-BE64R2: .abicalls
104 ; CHECK-BE64R2: .set noreorder
105 ; TODO: Need .set mips64r2 and .option pic0
58106 ;
59107 ; 64R2 bit with NO_REORDER and PIC
60 ; CHECK-BE64R2_PIC: .mips_hack_elf_flags 0x80000007
108 ; CHECK-BE64R2_PIC: .abicalls
109 ; CHECK-BE64R2_PIC: .set noreorder
110 ; TODO: Need .set mips64r2 and check absence of .option pic0
61111 ;
62112 ; 32R2 bit MIPS16 with PIC
63 ; CHECK-LE32R2-MIPS16: .mips_hack_elf_flags 0x74001006
113 ; CHECK-LE32R2-MIPS16: .abicalls
114 ; CHECK-LE32R2-MIPS16: .set mips16
115 ; TODO: Need .set mips32r2 and check absence of .option pic0 and noreorder
64116
65117 define i32 @main() nounwind {
66118 entry:
None // RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o -| llvm-readobj -h | FileCheck %s
1 // The initial value will be set at 0x50001003 and
2 // we will override that with the negation of 0x2 (option pic0
3 // the addition of 0x4 (.abicalls)
0 // RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o - | \
1 // RUN: llvm-readobj -h | FileCheck %s
42
5 .mips_hack_elf_flags 0x50001003
3 // From the commandline and defaults the following should be set:
4 // EF_MIPS_ARCH_32 (0x50000000)
5 // EF_MIPS_ABI_O32 (0x00001000)
6 // EF_MIPS_NOREORDER (0x00000001)
7 // EF_MIPS_PIC (0x00000002)
8
9 // Inline directives should set or unset the following:
10 // EF_MIPS_CPIC (0x00000004) : .abicalls
11 // EF_MIPS_ARCH_ASE_M16 (0x04000000) : .set mips16
12 // The negation of EF_MIPS_PIC : .option pic0
613
714 // CHECK: Flags [ (0x54001005)
815
916 .abicalls
1017
1118 .option pic0
12
13 // Set EF_MIPS_ARCH_ASE_M16 (0x04000000)
19
1420 .set mips16
0 ; This tests value of ELF st_other field for function symbol table entries.
11 ; For microMIPS value should be equal to STO_MIPS_MICROMIPS.
22
3 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -print-hack-directives %s -o - | FileCheck %s
3 ; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips %s \
4 ; RUN: -o - | FileCheck %s
45
56 define i32 @main() nounwind {
67 entry:
78 ret i32 0
89 }
910
10 ; CHECK: .set micromips
11 ; CHECK: .set micromips
1112 ; CHECK: main: