[llvm] r191982 - [MC][AsmParser] Hook for post assembly file processing
Jack Carter
Jack.Carter at imgtec.com
Fri Oct 4 15:46:33 PDT 2013
No problem
________________________________________
From: Rafael EspĂndola [rafael.espindola at gmail.com]
Sent: Friday, October 04, 2013 3:41 PM
To: Jack Carter
Cc: llvm-commits
Subject: Re: [llvm] r191982 - [MC][AsmParser] Hook for post assembly file processing
This was committed before a final LGTM. Please revert.
On 4 October 2013 17:26, Jack Carter <jack.carter at imgtec.com> wrote:
> Author: jacksprat
> Date: Fri Oct 4 16:26:15 2013
> New Revision: 191982
>
> URL: http://llvm.org/viewvc/llvm-project?rev=191982&view=rev
> Log:
> [MC][AsmParser] Hook for post assembly file processing
>
> This patch handles LLVM standalone assembler (llvm-mc) ELF flag setting based on input file
> directive processing.
>
> Mips assembly requires processing inline directives that directly and
> indirectly affect the output ELF header flags. This patch handles one
> ".abicalls".
>
> To process these directives we are following the model the code generator
> uses by storing state in a container as we go through processing and when
> we detect the end of input file processing, AsmParser is notified and we
> update the ELF header flags through a MipsELFStreamer method with a call from
> MCTargetAsmParser::emitEndOfAsmFile(MCStreamer &OutStreamer).
>
> This patch will allow other targets the same functionality.
>
> Jack
>
> Added:
> llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmFlags.h
> Modified:
> llvm/trunk/include/llvm/MC/MCTargetAsmParser.h
> llvm/trunk/lib/MC/MCParser/AsmParser.cpp
> llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
> llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
> llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
> llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
> llvm/trunk/test/MC/Mips/mips_directives.s
>
> Modified: llvm/trunk/include/llvm/MC/MCTargetAsmParser.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCTargetAsmParser.h?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCTargetAsmParser.h (original)
> +++ llvm/trunk/include/llvm/MC/MCTargetAsmParser.h Fri Oct 4 16:26:15 2013
> @@ -176,6 +176,11 @@ public:
> virtual void convertToMapAndConstraints(unsigned Kind,
> const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
>
> + /// End of assembly processing.
> + /// This gets called when all assembly has been read and gives the local
> + /// Target AsmParsers an opportunity for any final data processing, etc..
> + virtual void emitEndOfAsmFile(MCStreamer &Out) {}
> +
> virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
> MCSymbolRefExpr::VariantKind,
> MCContext &Ctx) {
>
> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Oct 4 16:26:15 2013
> @@ -673,8 +673,10 @@ bool AsmParser::Run(bool NoInitialTextSe
>
> // Finalize the output stream if there are no errors and if the client wants
> // us to.
> - if (!HadError && !NoFinalize)
> + if (!HadError && !NoFinalize) {
> + getTargetParser().emitEndOfAsmFile(Out);
> Out.Finish();
> + }
>
> return HadError;
> }
> @@ -779,7 +781,8 @@ bool AsmParser::parsePrimaryExpr(const M
> // temporary label to the streamer and refer to it.
> MCSymbol *Sym = Ctx.CreateTempSymbol();
> Out.EmitLabel(Sym);
> - Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
> + Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None,
> + getContext());
> EndLoc = FirstTokenLoc;
> return false;
> } else
>
> Added: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmFlags.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmFlags.h?rev=191982&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmFlags.h (added)
> +++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmFlags.h Fri Oct 4 16:26:15 2013
> @@ -0,0 +1,53 @@
> +//=== MipsMCAsmFlags.h - MipsMCAsmFlags --------------------------------===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENCE.TXT for details.
> +//
> +//===-------------------------------------------------------------------===//
> +#ifndef MIPSMCASMFLAGS_H_
> +#define MIPSMCASMFLAGS_H_
> +
> +namespace llvm {
> +class MipsMCAsmFlags;
> +
> +// We have the flags apart from the ELF defines because state will determine
> +// the final values put into the ELF flag bits.
> +//
> +// Currently we have only Relocation Model, but will soon follow with ABI,
> +// Architecture, and ASE.
> +class MipsMCAsmFlags {
> +public:
> + // These act as bit flags because more that one can be
> + // active at the same time, sometimes ;-)
> + enum MAFRelocationModelTy {
> + MAF_RM_DEFAULT = 0,
> + MAF_RM_STATIC = 1,
> + MAF_RM_CPIC = 2,
> + MAF_RM_PIC = 4
> + } MAFRelocationModel;
> +
> +public:
> + MipsMCAsmFlags() : Model(MAF_RM_DEFAULT) {}
> +
> + ~MipsMCAsmFlags() {}
> +
> + // Setting a bit we can later translate to the ELF header flags.
> + void setRelocationModel(unsigned RM) { (Model |= RM); }
> +
> + bool isModelCpic() const { return (Model & MAF_RM_CPIC) == MAF_RM_CPIC; }
> + bool isModelPic() const { return (Model & MAF_RM_PIC) == MAF_RM_PIC; }
> + bool isModelStatic() const {
> + return (Model & MAF_RM_STATIC) == MAF_RM_STATIC;
> + }
> + bool isModelDefault() const {
> + return (Model & MAF_RM_DEFAULT) == MAF_RM_DEFAULT;
> + }
> +
> +private:
> + unsigned Model; // pic, cpic, etc.
> +};
> +}
> +
> +#endif /* MIPSMCASMFLAGS_H_ */
>
> Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Fri Oct 4 16:26:15 2013
> @@ -7,6 +7,8 @@
> //
> //===----------------------------------------------------------------------===//
>
> +#include "AsmParser/MipsAsmFlags.h"
> +#include "MCTargetDesc/MipsELFStreamer.h"
> #include "MCTargetDesc/MipsMCTargetDesc.h"
> #include "MipsRegisterInfo.h"
> #include "llvm/ADT/StringSwitch.h"
> @@ -59,6 +61,7 @@ class MipsAsmParser : public MCTargetAsm
> MCSubtargetInfo &STI;
> MCAsmParser &Parser;
> MipsAssemblerOptions Options;
> + MipsMCAsmFlags Flags;
> bool hasConsumedDollar;
>
> #define GET_ASSEMBLER_HEADER
> @@ -228,6 +231,8 @@ class MipsAsmParser : public MCTargetAsm
>
> bool processInstruction(MCInst &Inst, SMLoc IDLoc,
> SmallVectorImpl<MCInst> &Instructions);
> + void emitEndOfAsmFile(MCStreamer &Out);
> +
> public:
> MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
> const MCInstrInfo &MII)
> @@ -2172,9 +2177,23 @@ bool MipsAsmParser::ParseDirective(AsmTo
> return false;
> }
>
> + if (IDVal == ".abicalls") {
> + Flags.setRelocationModel(MipsMCAsmFlags::MAF_RM_CPIC);
> + if (Parser.getTok().isNot(AsmToken::EndOfStatement))
> + return Error(Parser.getTok().getLoc(), "unexpected token in directive");
> + return false;
> + }
> +
> return true;
> }
>
> +/// End of assembly processing such as updating ELF header flags.
> +void MipsAsmParser::emitEndOfAsmFile(MCStreamer &OutStreamer) {
> + if (MipsELFStreamer *MES = dyn_cast<MipsELFStreamer>(&OutStreamer))
> + MES->emitELFHeaderFlagsAsm(Flags);
> + MCTargetAsmParser::emitEndOfAsmFile(OutStreamer);
> +}
> +
> extern "C" void LLVMInitializeMipsAsmParser() {
> RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
> RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
>
> Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp Fri Oct 4 16:26:15 2013
> @@ -7,6 +7,7 @@
> //
> //===-------------------------------------------------------------------===//
> #include "MCTargetDesc/MipsELFStreamer.h"
> +#include "AsmParser/MipsAsmFlags.h"
> #include "MipsSubtarget.h"
> #include "llvm/MC/MCAssembler.h"
> #include "llvm/MC/MCELF.h"
> @@ -66,10 +67,26 @@ namespace llvm {
> Reloc::Model RM = Subtarget.getRelocationModel();
> if (RM == Reloc::PIC_ || RM == Reloc::Default)
> EFlags |= ELF::EF_MIPS_PIC;
> - else if (RM == Reloc::Static)
> +
> + MCA.setELFHeaderEFlags(EFlags);
> + }
> +
> + // For llvm-mc. Set a group of ELF header flags
> + void MipsELFStreamer::emitELFHeaderFlagsAsm(const MipsMCAsmFlags &Flags) {
> +
> + // Update e_header flags
> + MCAssembler &MCA = getAssembler();
> + unsigned EFlags = MCA.getELFHeaderEFlags();
> +
> + // Relocation Model
> + if (Flags.isModelCpic() || Flags.isModelDefault())
> + EFlags |= ELF::EF_MIPS_CPIC;
> + if (Flags.isModelStatic())
> ; // Do nothing for Reloc::Static
> + else if (Flags.isModelPic() || Flags.isModelDefault())
> + EFlags |= ELF::EF_MIPS_PIC;
> else
> - llvm_unreachable("Unsupported relocation model for e_flags");
> + assert(0 && "Unsupported relocation model for e_flags");
>
> MCA.setELFHeaderEFlags(EFlags);
> }
>
> Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h (original)
> +++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h Fri Oct 4 16:26:15 2013
> @@ -13,6 +13,7 @@
>
> namespace llvm {
> class MipsAsmPrinter;
> +class MipsMCAsmFlags;
> class MipsSubtarget;
> class MCSymbol;
>
> @@ -26,6 +27,7 @@ public:
>
> ~MipsELFStreamer() {}
> void emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget);
> + void emitELFHeaderFlagsAsm(const MipsMCAsmFlags &MAFlags);
> void emitMipsSTOCG(const MipsSubtarget &Subtarget,
> MCSymbol *Sym,
> unsigned Val);
>
> Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Fri Oct 4 16:26:15 2013
> @@ -594,8 +594,8 @@ void MipsAsmPrinter::EmitEndOfAsmFile(Mo
> // Emit Mips ELF register info
> Subtarget->getMReginfo().emitMipsReginfoSectionCG(
> OutStreamer, getObjFileLowering(), *Subtarget);
> - if (MipsELFStreamer *MES = dyn_cast<MipsELFStreamer>(&OutStreamer))
> - MES->emitELFHeaderFlagsCG(*Subtarget);
> + MipsELFStreamer *MES = cast<MipsELFStreamer>(&OutStreamer);
> + MES->emitELFHeaderFlagsCG(*Subtarget);
> }
>
> void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
>
> Modified: llvm/trunk/test/MC/Mips/mips_directives.s
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/mips_directives.s?rev=191982&r1=191981&r2=191982&view=diff
> ==============================================================================
> --- llvm/trunk/test/MC/Mips/mips_directives.s (original)
> +++ llvm/trunk/test/MC/Mips/mips_directives.s Fri Oct 4 16:26:15 2013
> @@ -1,9 +1,12 @@
> # RUN: llvm-mc -show-encoding -triple mips-unknown-unknown %s | FileCheck %s
> +# RUN: llvm-mc -filetype=obj -triple mips-unknown-unknown %s | \
> +# RUN: llvm-readobj -h | FileCheck -check-prefix=CHECK-ELF %s
> #
> # CHECK: .text
> # CHECK: $BB0_2:
> $BB0_2:
> - .ent directives_test
> + .ent directives_test
> + .abicalls
> .frame $sp,0,$ra
> .mask 0x00000000,0
> .fmask 0x00000000,0
> @@ -43,3 +46,5 @@ $JTI0_0:
> # CHECK: and $3, $15, $15 # encoding: [0x01,0xef,0x18,0x24]
> abs.s f6,FPU_MASK
> and r3,$t7,STORE_MASK
> +
> +# CHECK-ELF: Flags [ (0x6)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list