[llvm-commits] CVS: reopt/lib/TraceCache/InstrUtils.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Mon Apr 26 14:48:12 PDT 2004


Changes in directory reopt/lib/TraceCache:

InstrUtils.cpp updated: 1.16 -> 1.17

---
Log message:

Add and/or edit a bunch of documentation, and rewrite the instructions
for identifying SPARCv9 branches to make them readable.

Move functions around in this file to match the logical organization of
the code:  get*Target functions are together, get*Inst functions are
together, and is*Jump functions are together.


---
Diffs of the changes:  (+64 -34)

Index: reopt/lib/TraceCache/InstrUtils.cpp
diff -u reopt/lib/TraceCache/InstrUtils.cpp:1.16 reopt/lib/TraceCache/InstrUtils.cpp:1.17
--- reopt/lib/TraceCache/InstrUtils.cpp:1.16	Fri Apr 23 15:10:35 2004
+++ reopt/lib/TraceCache/InstrUtils.cpp	Mon Apr 26 14:47:33 2004
@@ -11,6 +11,47 @@
 
 namespace llvm {
 
+//===----------------------------------------------------------------------===//
+//===-------------- Instructions for identifying SPARCv9 branches ---------===//
+
+// Terminology:
+//
+// A NonDepJump refers to a "non-deprecated jump", i.e., one with prediction and
+// annul bits and a 19-bit PC-relative branch-target field.
+//
+// A DepJump refers to a "deprecated jump", i.e., one *without* prediction or
+// annul bits, and having a 22-bit PC-relative branch-target field.
+
+/// isNonDepJump - Returns true iff instr encodes a BPcc or FBPfcc instruction
+/// (branch on integer or floating point condition codes, respectively, with
+/// prediction and annul bits, with a 19-bit PC-relative branch target field).
+/// See SPARCv9 manual sections A.5 and A.7.
+///
+bool isNonDepJump (unsigned int instr) {
+  instr &= 0xc1c00000;
+  return (instr == 0x00400000 /* BPcc */ || instr == 0x01400000 /* FBPfcc */);
+}
+
+/// isDepJump - Returns true iff instr encodes a Bicc or FBfcc instruction
+/// (branch on integer or floating point condition codes, respectively,
+/// *without* any prediction or annul bits, with a 22-bit PC-relative branch
+/// target field). See SPARCv9 manual sections A.4 and A.6.
+///
+bool isDepJump (unsigned int instr) {
+  instr &= 0xc1c00000;
+  return (instr == 0x00800000 /* Bicc */ || instr == 0x01800000 /* FBfcc */);
+}
+
+/// isBPR - Returns true iff instr encodes a BPr (branch on integer register
+/// with prediction) instruction. See SPARCv9 manual section A.3.
+///
+bool isBPR (unsigned int instr) {
+  return (instr & 0xd1c00000) == 0x00c00000;
+}
+
+//===----------------------------------------------------------------------===//
+//===----- Instructions for extracting SPARCv9 branch target addresses ----===//
+
 uint64_t getBranchTarget(unsigned br, uint64_t pc){
   if(isNonDepJump(br))
     return getNonDepJmpTarget(br, pc);
@@ -25,6 +66,25 @@
   }
 }
 
+uint64_t getNonDepJmpTarget(unsigned int y, uint64_t oldAdd){
+  return oldAdd + 4 * (((y&0x00040000)==0x00040000)
+                       ? ((y&0x0007ffff)|0xfffffffffff80000ULL)
+                       : (y&0x0007ffff));
+}
+
+uint64_t getDepJmpTarget(unsigned int y, uint64_t oldAdd){
+  return oldAdd + 4 * (((y&0x00200000U)==0x00200000U)
+                       ? ((y&0x003fffff)|0xffffffffffc00000ULL)
+                       : (y&0x003fffff));
+}
+
+uint64_t getBPRTarget(unsigned int b, uint64_t oldAdd){
+  return (oldAdd+4*(((b&2097152)==2097152)?(0xffffffffffff0000ULL|((b&3145728)>>6)|(b&16383)):(((b&3145728)>>6)|(b&16383))));
+}
+
+//===----------------------------------------------------------------------===//
+//===----- Instructions for extracting SPARCv9 branch target addresses ----===//
+
 unsigned getBranchInst(unsigned br, uint64_t to, uint64_t frm){
   if(isNonDepJump(br))
     return getUndepJumpInstr(br, to, frm);
@@ -39,26 +99,6 @@
   }
 } 
 
-bool isNonDepJump(unsigned int y){//int + floating point
-  return ((y & 0xc1c00000) == 4194304 || (y & 0xc1c00000) == 20971520);
-}
-
-bool isDepJump(unsigned int y){ //integer+floatingpoint
-  return ((y & 0xc1c00000) == 8388608 || (y & 0xc1c00000) == 25165824);
-}
-
-uint64_t getNonDepJmpTarget(unsigned int y, uint64_t oldAdd){
-  return oldAdd + 4 * (((y&0x00040000)==0x00040000)
-                       ? ((y&0x0007ffff)|0xfffffffffff80000ULL)
-                       : (y&0x0007ffff));
-}
-
-uint64_t getDepJmpTarget(unsigned int y, uint64_t oldAdd){
-  return oldAdd + 4 * (((y&0x00200000U)==0x00200000U)
-                       ? ((y&0x003fffff)|0xffffffffffc00000ULL)
-                       : (y&0x003fffff));
-}
-
 unsigned int getUndepJumpInstr(unsigned int a, uint64_t to, uint64_t pc){
   if(to>pc)
     assert((to-pc)/4<262144 && "Can't fit target!");
@@ -70,11 +110,10 @@
   return ((a&0xfff80000U)|diff|sgn);
 }
 
-/// getDepJumpInstr - Returns a PC-relative branch instruction from
-/// address FROM to address TO of the same conditionality (BA, BN, BNE, BE,
-/// BG...) as INSTR.  INSTR must be a Bicc instruction (branch on integer
-/// condition codes with no prediction), and FROM must be its address in
-/// memory.
+/// getDepJumpInstr - Returns a PC-relative branch instruction from address
+/// FROM to address TO of the same conditionality (BA, BN, BNE, BE, BG...) as
+/// INSTR.  INSTR must be a Bicc or FBfcc instruction (branch on integer
+/// condition codes with no prediction), and FROM must be its address in memory.
 ///
 unsigned int getDepJumpInstr(unsigned int instr, uint64_t to, uint64_t from) {
   if(to>from)
@@ -91,10 +130,6 @@
   return ((instr&0xffc00000)|diff|sgn);
 }
 
-uint64_t getBPRTarget(unsigned int b, uint64_t oldAdd){
-  return (oldAdd+4*(((b&2097152)==2097152)?(0xffffffffffff0000ULL|((b&3145728)>>6)|(b&16383)):(((b&3145728)>>6)|(b&16383))));
-}
-
 unsigned int getBPRInstr(unsigned int b, uint64_t to, uint64_t frm){
   if(to>frm)
     assert((to-frm)/4 < 32768 && "Target out of range!");
@@ -146,11 +181,6 @@
 
 bool isBranchNever(unsigned int b){
   return (((b & 0xc0000000) == 0) && (((b&0x1e000000)>>25) == 0) && (isDepJump(b) || isNonDepJump(b) || isBPR(b)));
-}
-
-//BPR: (b&(2^22+2^23+2^24) == (2^22+2^23)
-bool isBPR(unsigned int b){
-  return ( (b&0x01c00000) == 0x00c00000);
 }
 
 bool isBranchInstr(unsigned int y){





More information about the llvm-commits mailing list