[llvm-commits] [llvm] r140823 - in /llvm/trunk/lib/Target/ARM: ARMConstantPoolValue.cpp ARMConstantPoolValue.h

Jim Grosbach grosbach at apple.com
Fri Sep 30 01:32:31 PDT 2011



On Sep 29, 2011, at 4:48 PM, Bill Wendling <isanbard at gmail.com> wrote:

> Author: void
> Date: Thu Sep 29 18:48:44 2011
> New Revision: 140823
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=140823&view=rev
> Log:
> Support creating a constant pool value for a machine basic block.
> 
> This is used when we want to take the address of a machine basic block, but it's
> not associated with a BB in LLVM IR.
> 
> Modified:
>    llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.cpp
>    llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h
> 
> Modified: llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.cpp?rev=140823&r1=140822&r2=140823&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.cpp Thu Sep 29 18:48:44 2011
> @@ -17,6 +17,7 @@
> #include "llvm/Constants.h"
> #include "llvm/GlobalValue.h"
> #include "llvm/Type.h"
> +#include "llvm/CodeGen/MachineBasicBlock.h"
> #include "llvm/Support/raw_ostream.h"
> #include <cstdlib>
> using namespace llvm;
> @@ -31,6 +32,17 @@
>     Modifier(Modif), AddCurrentAddress(AddCA) {}
> 
> ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
> +                                           const MachineBasicBlock *mbb,
> +                                           unsigned id,
> +                                           ARMCP::ARMCPKind K,
> +                                           unsigned char PCAdj,
> +                                           ARMCP::ARMCPModifier Modif,
> +                                           bool AddCA)
> +  : MachineConstantPoolValue((Type*)Type::getInt8PtrTy(C)),
> +    CVal(NULL), MBB(mbb), S(NULL), LabelId(id), Kind(K), PCAdjust(PCAdj),
> +    Modifier(Modif), AddCurrentAddress(AddCA) {}
> +
> +ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
>                                            const char *s, unsigned id,
>                                            unsigned char PCAdj,
>                                            ARMCP::ARMCPModifier Modif,
> @@ -53,6 +65,10 @@
>   return dyn_cast_or_null<BlockAddress>(CVal);
> }
> 
> +const MachineBasicBlock *ARMConstantPoolValue::getMBB() const {
> +  return MBB;
> +}

This perhaps should assert that the kind is mbb?

> +
> static bool CPV_streq(const char *S1, const char *S2) {
>   if (S1 == S2)
>     return true;
> @@ -119,6 +135,8 @@
> void ARMConstantPoolValue::print(raw_ostream &O) const {
>   if (CVal)
>     O << CVal->getName();
> +  else if (MBB)
> +    O << "";

Not original with your changes, I'll grant, but this should be checking the kind, not the values of the members to determine how to print.
>   else
>     O << S;
>   if (Modifier) O << "(" << getModifierText() << ")";
> 
> Modified: llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h?rev=140823&r1=140822&r2=140823&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h (original)
> +++ llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h Thu Sep 29 18:48:44 2011
> @@ -20,17 +20,19 @@
> 
> namespace llvm {
> 
> -class Constant;
> class BlockAddress;
> +class Constant;
> class GlobalValue;
> class LLVMContext;
> +class MachineBasicBlock;
> 
> namespace ARMCP {
>   enum ARMCPKind {
>     CPValue,
>     CPExtSymbol,
>     CPBlockAddress,
> -    CPLSDA
> +    CPLSDA,
> +    CPMachineBasicBlock
>   };
> 
>   enum ARMCPModifier {
> @@ -48,6 +50,7 @@
> /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
> class ARMConstantPoolValue : public MachineConstantPoolValue {
>   const Constant *CVal;    // Constant being loaded.
> +  const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
>   const char *S;           // ExtSymbol being loaded.
>   unsigned LabelId;        // Label id of the load.

Hmmm... These should probably be in a union since only one is valid at a time. For that matter, this could be represented as a set of classes and we check the kind via dyncast/isa checks.

Thats also a fair bit outside the scope of what you're looking to do, so unless you're in the mood for some unrelated refactoring, perhaps just add a fix me ?

>   ARMCP::ARMCPKind Kind;   // Kind of constant.
> @@ -62,6 +65,11 @@
>                        unsigned char PCAdj = 0,
>                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
>                        bool AddCurrentAddress = false);
> +  ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id,
> +                       ARMCP::ARMCPKind Kind = ARMCP::CPValue,
> +                       unsigned char PCAdj = 0,
> +                       ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
> +                       bool AddCurrentAddress = false);
>   ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
>                        unsigned char PCAdj = 0,
>                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
> @@ -73,6 +81,7 @@
>   const GlobalValue *getGV() const;
>   const char *getSymbol() const { return S; }
>   const BlockAddress *getBlockAddress() const;
> +  const MachineBasicBlock *getMBB() const;
>   ARMCP::ARMCPModifier getModifier() const { return Modifier; }
>   const char *getModifierText() const {
>     switch (Modifier) {
> @@ -95,6 +104,7 @@
>   bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
>   bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
>   bool isLSDA() { return Kind == ARMCP::CPLSDA; }
> +  bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
> 
>   virtual unsigned getRelocationInfo() const { return 2; }
> 
> 
> 
> _______________________________________________
> 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